starcraftman / zsh-git-prompt

[Active Fork] Informative git prompt for zsh
MIT License
58 stars 15 forks source link

Synchronize Haskell version to new changes #5

Open starcraftman opened 6 years ago

starcraftman commented 6 years ago

I will maintain a list here of things I need added to the Haskell version to achieve parity with Python. So far:

Madnight kindly offered. No rush until list a bit longer.

Current Support

Python will always support all positions. Haskell is missing 8-12.

Python master 0 0 0 0 0 0 0 0 origin/master 0 0

Haskell
master 0 0 0 0 0 0

Interface Explained

Interface explained in order shown above. All number positions are 0 by default. 1) The branch. If checked out on hash, should be :hash, that is a ':' followed by 7 chars of hash. Note, I've allowed the user to configure prefix hash for python, unless this difficult I'd like that on Haskell too. So you should read in prefix char from ENV and then spit it back out. 2) If branch is tracked upstream, number of commits behind. 3) If branch is tracked upstream, number of commits ahead. 4) The number of staged files. 5) The number of conflict files (i.e. unmerged). 6) The number of changed files (i.e. tracked and edited) 7) The number of untracked files (does not include ignored). 8) The number of stashes on the current repository. 9) 1 if and only if we are on a branch and that branch has no upstream tracking set. The branch may in fact be pushed without -u to the current tracked remote. 10) The name of the upstream remote/branch set to track. For example, origin/master. By default if is not set, show .., that is an invalid branch name. 11) 1 if and only if engaged in a merge operation. 0 otherwise. 12) If we are rebasing, then it will show format of type m/n, where n is the total number of commits to resolve and m is the current commit we are checked out on to resolve. 0 otherwise.

starcraftman commented 6 years ago

image

Saved for later, to demonstrate new feature.

starcraftman commented 6 years ago

I've updated the interface preemptively, will now merge support for rebasing/merging indicators onto the project. As with other features, these remain python only until someone makes a PR for support or I use some time to learn Haskell better.

I may make individual issues for the outstanding Haskell issues, this may provide better tracking than this large omnibus.

madnight commented 6 years ago

@starcraftman yup, i'll implement all of this features. Yesterday i implemented the feature that it is now possible to run the Haskell version without stdin pipe and i found a small haskell lib that provides basic such as findRepo to get the current git path https://github.com/madnight/zsh-git-prompt/commit/3f7252b0f519fb02aff5be0fea89826d1c95dd18 with is basically the same as your find_git_root Today i have a look at "8. The number of stashes on the current repository."

starcraftman commented 6 years ago

Great thanks for looking into this. I am somewhat disappointed by python's slow startup on an older machine of mine. I did expect it to be clear. Makes the prompt between invocations slow. People will probably be happiest when we get full parity with the faster gitstatus. Hope the tests are useful in the Haskell code, I don't know the status but test_gitstatus.py contains steps to reproduce all testing scenarios you might need.

If you hadn't offered to make the patches, I probably would have rewritten gitstatus.py in c++ or straight shell. Both likely get us to Haskell or better performance, the latter would be quite tedious to write the conditional logic in. I may still do one or the other, I'll think on it.

madnight commented 6 years ago

I think the greatest benefit regarding performance is that haskell compiles down to a small binary (direct executable assembly like c/c++) whereas python needs to invoke a full blown interpreter first and interpret the whole script on every run.

starcraftman commented 6 years ago

Oh yes, the majority of the time isn't even spent executing code in gitstatus.py.

Examples from my i7 dev box below.

$ time python -c ''
real    0m0.047s
user    0m0.030s
sys 0m0.020s

$ time git status --branch --porcelain | ./gitstatus.py 
master 0 0 0 0 0 0 0 0 origin/master 0 0
real    0m0.050s
user    0m0.035s
sys 0m0.022s

$ time git status --branch --porcelain | src/.bin/gitstatus 
master 0 0 0 0 0 0
real    0m0.009s
user    0m0.011s
sys 0m0.008s