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

gitk: Show local changes properly when we have a path limit

Since gitk looks for the HEAD commit to attach the fake commits for local changes to, we can miss out on seeing the fake commits if we have a path limit and the HEAD commit doesn't alter any of the files in the path limit. This fixes it by running git rev-list -1 $head -- $paths if we have a path limit, and taking the result of that as the commit to attach the fake commits to. This means that we can be attaching the fake commits to a different commit in each view, so we use a new $viewmainhead($view) for that. This also fixes a buglet where updatecommits would only fix up the fake commits if the HEAD changed since the last call to updatecommits, whereas it should fix them up if the HEAD has changed since this view was last created or updated. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Nov 18, 2008 at 19:54 UTC cdc8429c94e43181ac0bd48225c2af85499d2f5a
1 file changed +88 -22
gitk
+88 -22
@@ -309,7 +309,7 @@ proc start_rev_list {view} {
309 global viewargs viewargscmd viewfiles vfilelimit
310 global showlocalchanges
311 global viewactive viewinstances vmergeonly
312 - global mainheadid
312 + global mainheadid viewmainheadid viewmainheadid_orig
313 global vcanopt vflags vrevs vorigargs
314
315 set startmsecs [clock clicks -milliseconds]
@@ -367,8 +367,13 @@ proc start_rev_list {view} {
367 }
368 set i [reg_instance $fd]
369 set viewinstances($view) [list $i]
370 - if {$showlocalchanges && $mainheadid ne {}} {
371 - interestedin $mainheadid dodiffindex
370 + set viewmainheadid($view) $mainheadid
371 + set viewmainheadid_orig($view) $mainheadid
372 + if {$files ne {} && $mainheadid ne {}} {
373 + get_viewmainhead $view
374 + }
375 + if {$showlocalchanges && $viewmainheadid($view) ne {}} {
376 + interestedin $viewmainheadid($view) dodiffindex
377 }
378 fconfigure $fd -blocking 0 -translation lf -eofchar {}
379 if {$tclencoding != {}} {
@@ -446,22 +451,26 @@ proc updatecommits {} {
451 global curview vcanopt vorigargs vfilelimit viewinstances
452 global viewactive viewcomplete tclencoding
453 global startmsecs showneartags showlocalchanges
449 - global mainheadid pending_select
454 + global mainheadid viewmainheadid viewmainheadid_orig pending_select
455 global isworktree
456 global varcid vposids vnegids vflags vrevs
457
458 set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
454 - set oldmainid $mainheadid
459 rereadrefs
456 - if {$showlocalchanges} {
457 - if {$mainheadid ne $oldmainid} {
460 + set view $curview
461 + if {$mainheadid ne $viewmainheadid_orig($view)} {
462 + if {$showlocalchanges} {
463 dohidelocalchanges
464 }
460 - if {[commitinview $mainheadid $curview]} {
461 - dodiffindex
465 + set viewmainheadid($view) $mainheadid
466 + set viewmainheadid_orig($view) $mainheadid
467 + if {$vfilelimit($view) ne {}} {
468 + get_viewmainhead $view
469 }
470 }
464 - set view $curview
471 + if {$showlocalchanges} {
472 + doshowlocalchanges
473 + }
474 if {$vcanopt($view)} {
475 set oldpos $vposids($view)
476 set oldneg $vnegids($view)
@@ -4643,14 +4652,56 @@ proc layoutmore {} {
4652 drawvisible
4653 }
4654
4655 +# With path limiting, we mightn't get the actual HEAD commit,
4656 +# so ask git rev-list what is the first ancestor of HEAD that
4657 +# touches a file in the path limit.
4658 +proc get_viewmainhead {view} {
4659 + global viewmainheadid vfilelimit viewinstances mainheadid
4660 +
4661 + catch {
4662 + set rfd [open [concat | git rev-list -1 $mainheadid \
4663 + -- $vfilelimit($view)] r]
4664 + set j [reg_instance $rfd]
4665 + lappend viewinstances($view) $j
4666 + fconfigure $rfd -blocking 0
4667 + filerun $rfd [list getviewhead $rfd $j $view]
4668 + set viewmainheadid($curview) {}
4669 + }
4670 +}
4671 +
4672 +# git rev-list should give us just 1 line to use as viewmainheadid($view)
4673 +proc getviewhead {fd inst view} {
4674 + global viewmainheadid commfd curview viewinstances showlocalchanges
4675 +
4676 + set id {}
4677 + if {[gets $fd line] < 0} {
4678 + if {![eof $fd]} {
4679 + return 1
4680 + }
4681 + } elseif {[string length $line] == 40 && [string is xdigit $line]} {
4682 + set id $line
4683 + }
4684 + set viewmainheadid($view) $id
4685 + close $fd
4686 + unset commfd($inst)
4687 + set i [lsearch -exact $viewinstances($view) $inst]
4688 + if {$i >= 0} {
4689 + set viewinstances($view) [lreplace $viewinstances($view) $i $i]
4690 + }
4691 + if {$showlocalchanges && $id ne {} && $view == $curview} {
4692 + doshowlocalchanges
4693 + }
4694 + return 0
4695 +}
4696 +
4697 proc doshowlocalchanges {} {
4647 - global curview mainheadid
4698 + global curview viewmainheadid
4699
4649 - if {$mainheadid eq {}} return
4650 - if {[commitinview $mainheadid $curview]} {
4700 + if {$viewmainheadid($curview) eq {}} return
4701 + if {[commitinview $viewmainheadid($curview) $curview]} {
4702 dodiffindex
4703 } else {
4653 - interestedin $mainheadid dodiffindex
4704 + interestedin $viewmainheadid($curview) dodiffindex
4705 }
4706 }
4707
@@ -4668,19 +4719,24 @@ proc dohidelocalchanges {} {
4719
4720 # spawn off a process to do git diff-index --cached HEAD
4721 proc dodiffindex {} {
4671 - global lserial showlocalchanges
4722 + global lserial showlocalchanges vfilelimit curview
4723 global isworktree
4724
4725 if {!$showlocalchanges || !$isworktree} return
4726 incr lserial
4676 - set fd [open "|git diff-index --cached HEAD" r]
4727 + set cmd "|git diff-index --cached HEAD"
4728 + if {$vfilelimit($curview) ne {}} {
4729 + set cmd [concat $cmd -- $vfilelimit($curview)]
4730 + }
4731 + set fd [open $cmd r]
4732 fconfigure $fd -blocking 0
4733 set i [reg_instance $fd]
4734 filerun $fd [list readdiffindex $fd $lserial $i]
4735 }
4736
4737 proc readdiffindex {fd serial inst} {
4683 - global mainheadid nullid nullid2 curview commitinfo commitdata lserial
4738 + global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
4739 + global vfilelimit
4740
4741 set isdiff 1
4742 if {[gets $fd line] < 0} {
@@ -4697,7 +4753,11 @@ proc readdiffindex {fd serial inst} {
4753 }
4754
4755 # now see if there are any local changes not checked in to the index
4700 - set fd [open "|git diff-files" r]
4756 + set cmd "|git diff-files"
4757 + if {$vfilelimit($curview) ne {}} {
4758 + set cmd [concat $cmd -- $vfilelimit($curview)]
4759 + }
4760 + set fd [open $cmd r]
4761 fconfigure $fd -blocking 0
4762 set i [reg_instance $fd]
4763 filerun $fd [list readdifffiles $fd $serial $i]
@@ -4710,15 +4770,18 @@ proc readdiffindex {fd serial inst} {
4770 if {[commitinview $nullid $curview]} {
4771 removefakerow $nullid
4772 }
4713 - insertfakerow $nullid2 $mainheadid
4773 + insertfakerow $nullid2 $viewmainheadid($curview)
4774 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
4775 + if {[commitinview $nullid $curview]} {
4776 + removefakerow $nullid
4777 + }
4778 removefakerow $nullid2
4779 }
4780 return 0
4781 }
4782
4783 proc readdifffiles {fd serial inst} {
4721 - global mainheadid nullid nullid2 curview
4784 + global viewmainheadid nullid nullid2 curview
4785 global commitinfo commitdata lserial
4786
4787 set isdiff 1
@@ -4743,7 +4806,7 @@ proc readdifffiles {fd serial inst} {
4806 if {[commitinview $nullid2 $curview]} {
4807 set p $nullid2
4808 } else {
4746 - set p $mainheadid
4809 + set p $viewmainheadid($curview)
4810 }
4811 insertfakerow $nullid $p
4812 } elseif {!$isdiff && [commitinview $nullid $curview]} {
@@ -8341,6 +8404,7 @@ proc cherrypick {} {
8404 }
8405 addnewchild $newhead $oldhead
8406 if {[commitinview $oldhead $curview]} {
8407 + # XXX this isn't right if we have a path limit...
8408 insertrow $newhead $oldhead $curview
8409 if {$mainhead ne {}} {
8410 movehead $newhead $mainhead
@@ -8448,7 +8512,7 @@ proc headmenu {x y id head} {
8512
8513 proc cobranch {} {
8514 global headmenuid headmenuhead headids
8451 - global showlocalchanges mainheadid
8515 + global showlocalchanges
8516
8517 # check the tree is clean first??
8518 nowbusy checkout [mc "Checking out"]
@@ -8469,6 +8533,7 @@ proc cobranch {} {
8533
8534 proc readcheckoutstat {fd newhead newheadid} {
8535 global mainhead mainheadid headids showlocalchanges progresscoords
8536 + global viewmainheadid curview
8537
8538 if {[gets $fd line] >= 0} {
8539 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
@@ -8486,6 +8551,7 @@ proc readcheckoutstat {fd newhead newheadid} {
8551 set oldmainid $mainheadid
8552 set mainhead $newhead
8553 set mainheadid $newheadid
8554 + set viewmainheadid($curview) $newheadid
8555 redrawtags $oldmainid
8556 redrawtags $newheadid
8557 selbyid $newheadid