@matheusbsbs / matheus-bagliano / commits / fc4e8da727
Fork 0

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>

Shawn O. Pearce committed May 30, 2007 at 20:39 UTC fc4e8da727d5c1737322b14386282456fd3c99c9
1 file changed +15 -20
git-gui.sh
+15 -20
@@ -262,6 +262,17 @@ proc git {args} {
262 return [eval exec git $args]
263 }
264
265 +proc current-branch {} {
266 + set ref {}
267 + set fd [open [gitdir HEAD] r]
268 + if {[gets $fd ref] <16
269 + || ![regsub {^ref: refs/heads/} $ref {} ref]} {
270 + set ref {}
271 + }
272 + close $fd
273 + return $ref
274 +}
275 +
276 auto_load tk_optionMenu
277 rename tk_optionMenu real__tkOptionMenu
278 proc tk_optionMenu {w varName args} {
@@ -410,15 +421,7 @@ proc repository_state {ctvar hdvar mhvar} {
421
422 set mh [list]
423
413 - if {[catch {set current_branch [git symbolic-ref HEAD]}]} {
414 - set current_branch {}
415 - } else {
416 - regsub ^refs/((heads|tags|remotes)/)? \
417 - $current_branch \
418 - {} \
419 - current_branch
420 - }
421 -
424 + set current_branch [current-branch]
425 if {[catch {set hd [git rev-parse --verify HEAD]}]} {
426 set hd {}
427 set ct initial
@@ -1651,14 +1654,8 @@ switch -- $subcommand {
1654 browser {
1655 set subcommand_args {rev?}
1656 switch [llength $argv] {
1654 - 0 {
1655 - set current_branch [git symbolic-ref HEAD]
1656 - regsub ^refs/((heads|tags|remotes)/)? \
1657 - $current_branch {} current_branch
1658 - }
1659 - 1 {
1660 - set current_branch [lindex $argv 0]
1661 - }
1657 + 0 { set current_branch [current-branch] }
1658 + 1 { set current_branch [lindex $argv 0] }
1659 default usage
1660 }
1661 browser::new $current_branch
@@ -1691,9 +1688,7 @@ blame {
1688 unset is_path
1689
1690 if {$head eq {}} {
1694 - set current_branch [git symbolic-ref HEAD]
1695 - regsub ^refs/((heads|tags|remotes)/)? \
1696 - $current_branch {} current_branch
1691 + set current_branch [current-branch]
1692 } else {
1693 set current_branch $head
1694 }