aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2007-05-30 20:39:46 -0400
committerShawn O. Pearce <spearce@spearce.org>2007-05-31 23:37:34 -0400
commitfc4e8da727d5c1737322b14386282456fd3c99c9 (patch)
treea61de33163a574aa7d5c05c7d2021fd0c424fb2a
parent71a9db534a6bb4a6e9824c01b557a96ccaae0e89 (diff)
downloadgit-fc4e8da727d5c1737322b14386282456fd3c99c9.tar.gz
git-fc4e8da727d5c1737322b14386282456fd3c99c9.tar.xz
git-gui: Internalize symbolic-ref HEAD reading logic
To improve performance on fork+exec impoverished systems (such as Windows) we want to avoid running git-symbolic-ref on every rescan if we can do so. A quick way to implement such an avoidance is to just read the HEAD ref ourselves; we'll either see it as a symref (starts with "ref: ") or we'll see it as a detached head (40 hex digits). In either case we can treat that as our current branch. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rwxr-xr-xgit-gui.sh35
1 files changed, 15 insertions, 20 deletions
diff --git a/git-gui.sh b/git-gui.sh
index 3bd12d20b..5dc2c675a 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -262,6 +262,17 @@ proc git {args} {
return [eval exec git $args]
}
+proc current-branch {} {
+ set ref {}
+ set fd [open [gitdir HEAD] r]
+ if {[gets $fd ref] <16
+ || ![regsub {^ref: refs/heads/} $ref {} ref]} {
+ set ref {}
+ }
+ close $fd
+ return $ref
+}
+
auto_load tk_optionMenu
rename tk_optionMenu real__tkOptionMenu
proc tk_optionMenu {w varName args} {
@@ -410,15 +421,7 @@ proc repository_state {ctvar hdvar mhvar} {
set mh [list]
- if {[catch {set current_branch [git symbolic-ref HEAD]}]} {
- set current_branch {}
- } else {
- regsub ^refs/((heads|tags|remotes)/)? \
- $current_branch \
- {} \
- current_branch
- }
-
+ set current_branch [current-branch]
if {[catch {set hd [git rev-parse --verify HEAD]}]} {
set hd {}
set ct initial
@@ -1651,14 +1654,8 @@ switch -- $subcommand {
browser {
set subcommand_args {rev?}
switch [llength $argv] {
- 0 {
- set current_branch [git symbolic-ref HEAD]
- regsub ^refs/((heads|tags|remotes)/)? \
- $current_branch {} current_branch
- }
- 1 {
- set current_branch [lindex $argv 0]
- }
+ 0 { set current_branch [current-branch] }
+ 1 { set current_branch [lindex $argv 0] }
default usage
}
browser::new $current_branch
@@ -1691,9 +1688,7 @@ blame {
unset is_path
if {$head eq {}} {
- set current_branch [git symbolic-ref HEAD]
- regsub ^refs/((heads|tags|remotes)/)? \
- $current_branch {} current_branch
+ set current_branch [current-branch]
} else {
set current_branch $head
}