Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag support for detached branche in git_prompt_info #5304

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jtyr
Copy link

@jtyr jtyr commented Aug 14, 2016

If the HEAD is not a symbolic ref (e.g. refs/heads/master) but it points to a commit ID (branch is detached), the git_prompt_info shows commit ID even if the commit ID points has a tag. This patch allows to display the tag version if there is a tag for the HEAD commit ID.

@robbyrussell
Copy link
Member

Thanks @jtyr for this, I'd like to see some performance comparisons since it adds another lookup to the prompt info. Could you do a before/after comparison? (or can we find a volunteer?)

@robbyrussell robbyrussell added git Status: testers needed Pull Requests that are waiting for testers to merge Area: core Issue or PR related to core parts of the project labels Aug 15, 2016
@jtyr
Copy link
Author

jtyr commented Aug 15, 2016

The performance depends on the state of the branch. If the HEAD is a ref (e.g. git checkout master), there is only one command executed. If the branch is detached (e.g. git checkout 8462d64), there will be three commands executed. But if there is a tag pointing on the detached branch (e.g. git checkout v1.0), there will be only two commands executed. So the change affects performance of only detached branch which has no tag pointing on the commit. I believe this is an acceptable performance degradation.

Here is a simple performance assessment:

$ mkdir test
$ cd test
$ git init
$ touch README
$ git add -A
$ git commit -m "Initial commit"
[master (root-commit) 8462d64] Initial commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README
$ git tag v1.0
$ git checkout 8462d64
Note: checking out '8462d64'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 8462d64... Initial commit
$ time git symbolic-ref HEAD
fatal: ref HEAD is not a symbolic ref

real    0m0.003s
user    0m0.000s
sys 0m0.000s
$ time git describe --tags --exact-match HEAD
v1.0

real    0m0.003s
user    0m0.000s
sys 0m0.000s
$ time git rev-parse --short HEAD
8462d64

real    0m0.003s
user    0m0.000s
sys 0m0.000s
$ git checkout v1.0
HEAD is now at 8462d64... Initial commit
$ time git symbolic-ref HEAD
fatal: ref HEAD is not a symbolic ref

real    0m0.003s
user    0m0.000s
sys 0m0.003s
$ time git describe --tags --exact-match HEAD
v1.1

real    0m0.003s
user    0m0.000s
sys 0m0.000s
$ time git rev-parse --short HEAD
8462d64

real    0m0.002s
user    0m0.000s
sys 0m0.000s
$ git checkout master
Switched to branch 'master'
$ time git symbolic-ref HEAD
refs/heads/master

real    0m0.003s
user    0m0.000s
sys 0m0.000s
$ time git describe --tags --exact-match HEAD
v1.0

real    0m0.004s
user    0m0.000s
sys 0m0.000s
$ time git rev-parse --short HEAD
8462d64

real    0m0.003s
user    0m0.000s
sys 0m0.000s

All the commands are pretty fast and their execution is almost negligible.

@jtyr jtyr changed the title Adding tag support into the git_prompt_info Adding tag support for detached branches into the git_prompt_info Aug 15, 2016
If the HEAD is not a symbolic ref (e.g. refs/heads/master) but it points
to a commit ID (branch is detached), the git_prompt_info shows commit ID
even if the commit ID points has a tag. This patch allows to display the
tag version if there is a tag for the HEAD commit ID.
@jtyr jtyr changed the title Adding tag support for detached branches into the git_prompt_info Tag support for detached branche in git_prompt_info Aug 15, 2016
@jtyr
Copy link
Author

jtyr commented Aug 22, 2016

@robbyrussell Can I help with anything else to make this merged?

@jtyr
Copy link
Author

jtyr commented Jan 27, 2017

@robbyrussell Please could you review this?

@bromeara
Copy link

This could probably be closed since gitfast plugin implements this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: core Issue or PR related to core parts of the project Status: testers needed Pull Requests that are waiting for testers to merge
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

None yet

4 participants