summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ba1964b)
raw | patch | inline | side by side (parent: ba1964b)
author | Shawn O. Pearce <spearce@spearce.org> | |
Thu, 5 Jul 2007 23:19:37 +0000 (19:19 -0400) | ||
committer | Shawn O. Pearce <spearce@spearce.org> | |
Mon, 9 Jul 2007 01:12:56 +0000 (21:12 -0400) |
If the current branch is not a symbolic-ref that points to a
name in the refs/heads/ namespace we now just assume that the
head is a detached head. In this case we return the special
branch name of HEAD rather than empty string, as HEAD is a
valid revision specification and the empty string is not.
I have also slightly improved the current-branch function by
using string functions to parse the symbolic-ref data. This
should be slightly faster than using a regsub. I think the
code is clearer too.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
name in the refs/heads/ namespace we now just assume that the
head is a detached head. In this case we return the special
branch name of HEAD rather than empty string, as HEAD is a
valid revision specification and the empty string is not.
I have also slightly improved the current-branch function by
using string functions to parse the symbolic-ref data. This
should be slightly faster than using a regsub. I think the
code is clearer too.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
git-gui.sh | patch | blob | history |
diff --git a/git-gui.sh b/git-gui.sh
index 99df2d94804609d4cff3c1e6e586b262752aaf93..516bd972ec111ecb8a323efa43f0473ab503b1fb 100755 (executable)
--- a/git-gui.sh
+++ b/git-gui.sh
}
proc current-branch {} {
- set ref {}
set fd [open [gitdir HEAD] r]
- if {[gets $fd ref] <16
- || ![regsub {^ref: refs/heads/} $ref {} ref]} {
+ if {[gets $fd ref] < 1} {
set ref {}
}
close $fd
- return $ref
+
+ set pfx {ref: refs/heads/}
+ set len [string length $pfx]
+ if {[string equal -length $len $pfx $ref]} {
+ # We're on a branch. It might not exist. But
+ # HEAD looks good enough to be a branch.
+ #
+ return [string range $ref $len end]
+ } else {
+ # Assume this is a detached head.
+ #
+ return HEAD
+ }
}
auto_load tk_optionMenu