@matheusbsbs / matheus-bagliano / commits / 7d5266a704
Fork 0

git-gui: Avoid unnecessary symbolic-ref call during checkout

If we are checking out the branch we are already on then there is no need to call symbolic-ref to update the HEAD pointer to the "new" branch name, it is already correct. Currently this situation does not happen very often, but it can be seen in some workflows where the user always recreates their local branch from a remote tracking branch and more-or-less ignores what branch he/she is on right now. As they say, ignorance is bliss. This case will however become a tad more common when we overload checkout_op to actually also perform all of our merges. In that case we will likely see that the branch we want to "checkout" is the current branch, as we are actually just merging into it. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jul 22, 2007 at 04:49 UTC 7d5266a704ea55b11799bf0431d1648282f53d54
1 file changed +16 -14
lib/checkout_op.tcl
+16 -14
@@ -385,22 +385,24 @@ method _after_readtree {} {
385 set rn [string length $rh]
386 if {[string equal -length $rn $rh $new_ref]} {
387 set new_branch [string range $new_ref $rn end]
388 - append log " to $new_branch"
389 -
390 - if {[catch {
391 - git symbolic-ref -m $log HEAD $new_ref
392 - } err]} {
393 - _fatal $this $err
388 + if {$is_detached || $current_branch ne $new_branch} {
389 + append log " to $new_branch"
390 + if {[catch {
391 + git symbolic-ref -m $log HEAD $new_ref
392 + } err]} {
393 + _fatal $this $err
394 + }
395 + set current_branch $new_branch
396 + set is_detached 0
397 }
395 - set current_branch $new_branch
396 - set is_detached 0
398 } else {
398 - append log " to $new_expr"
399 -
400 - if {[catch {
401 - _detach_HEAD $log $new_hash
402 - } err]} {
403 - _fatal $this $err
399 + if {$new_hash ne $HEAD} {
400 + append log " to $new_expr"
401 + if {[catch {
402 + _detach_HEAD $log $new_hash
403 + } err]} {
404 + _fatal $this $err
405 + }
406 }
407 set current_branch HEAD
408 set is_detached 1