gitk: Show changes in index and changes in working directory separately
This makes gitk show up to two fake commits when there are local changes in the repository; one to represent the state of the index and one to represent the state of the working directory. The commit representing the working directory is colored red as before; the commit representing the index state is colored magenta (as being between red and blue in some sense). Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras committed
Jul 13, 2007 at 19:49 UTC
8f4893639129acfc866c71583317090aa2a46eab
1 file changed
+138
-57
gitk
+138
-57
@@ -262,11 +262,11 @@ proc chewcommits {view} {
262
set tlimit [expr {[clock clicks -milliseconds] + 50}]
263
set more [layoutmore $tlimit $allread]
264
if {$allread && !$more} {
265
- global displayorder nullid commitidx phase
265
+ global displayorder commitidx phase
266
global numcommits startmsecs
267
268
if {[info exists pending_select]} {
269
- set row [expr {[lindex $displayorder 0] eq $nullid}]
269
+ set row [first_real_row]
270
selectline $row 1
271
}
272
if {$commitidx($curview) > 0} {
@@ -437,6 +437,19 @@ proc readrefs {} {
437
}
438
}
439
440
+# skip over fake commits
441
+proc first_real_row {} {
442
+ global nullid nullid2 displayorder numcommits
443
+
444
+ for {set row 0} {$row < $numcommits} {incr row} {
445
+ set id [lindex $displayorder $row]
446
+ if {$id ne $nullid && $id ne $nullid2} {
447
+ break
448
+ }
449
+ }
450
+ return $row
451
+}
452
+
453
# update things for a head moved to a child of its previous location
454
proc movehead {id name} {
455
global headids idheads
@@ -1871,7 +1884,7 @@ proc showview {n} {
1884
} elseif {$selid ne {}} {
1885
set pending_select $selid
1886
} else {
1874
- set row [expr {[lindex $displayorder 0] eq $nullid}]
1887
+ set row [first_real_row]
1888
if {$row < $numcommits} {
1889
selectline $row 0
1890
} else {
@@ -2643,7 +2656,7 @@ proc layoutmore {tmax allread} {
2656
2657
proc showstuff {canshow last} {
2658
global numcommits commitrow pending_select selectedline curview
2646
- global lookingforhead mainheadid displayorder nullid selectfirst
2659
+ global lookingforhead mainheadid displayorder selectfirst
2660
global lastscrollset
2661
2662
if {$numcommits == 0} {
@@ -2676,7 +2689,7 @@ proc showstuff {canshow last} {
2689
if {[info exists selectedline] || [info exists pending_select]} {
2690
set selectfirst 0
2691
} else {
2679
- set l [expr {[lindex $displayorder 0] eq $nullid}]
2692
+ set l [first_real_row]
2693
selectline $l 1
2694
set selectfirst 0
2695
}
@@ -2700,48 +2713,93 @@ proc doshowlocalchanges {} {
2713
}
2714
2715
proc dohidelocalchanges {} {
2703
- global lookingforhead localrow lserial
2716
+ global lookingforhead localfrow localirow lserial
2717
2718
set lookingforhead 0
2706
- if {$localrow >= 0} {
2707
- removerow $localrow
2708
- set localrow -1
2719
+ if {$localfrow >= 0} {
2720
+ removerow $localfrow
2721
+ set localfrow -1
2722
+ if {$localirow > 0} {
2723
+ incr localirow -1
2724
+ }
2725
+ }
2726
+ if {$localirow >= 0} {
2727
+ removerow $localirow
2728
+ set localirow -1
2729
}
2730
incr lserial
2731
}
2732
2713
-# spawn off a process to do git diff-index HEAD
2733
+# spawn off a process to do git diff-index --cached HEAD
2734
proc dodiffindex {} {
2715
- global localrow lserial
2735
+ global localirow localfrow lserial
2736
2737
incr lserial
2718
- set localrow -1
2719
- set fd [open "|git diff-index HEAD" r]
2738
+ set localfrow -1
2739
+ set localirow -1
2740
+ set fd [open "|git diff-index --cached HEAD" r]
2741
fconfigure $fd -blocking 0
2742
filerun $fd [list readdiffindex $fd $lserial]
2743
}
2744
2745
proc readdiffindex {fd serial} {
2725
- global localrow commitrow mainheadid nullid curview
2746
+ global localirow commitrow mainheadid nullid2 curview
2747
global commitinfo commitdata lserial
2748
2749
+ set isdiff 1
2750
if {[gets $fd line] < 0} {
2729
- if {[eof $fd]} {
2730
- close $fd
2731
- return 0
2751
+ if {![eof $fd]} {
2752
+ return 1
2753
}
2733
- return 1
2754
+ set isdiff 0
2755
}
2756
# we only need to see one line and we don't really care what it says...
2757
close $fd
2758
2738
- if {$serial == $lserial && $localrow == -1} {
2759
+ # now see if there are any local changes not checked in to the index
2760
+ if {$serial == $lserial} {
2761
+ set fd [open "|git diff-files" r]
2762
+ fconfigure $fd -blocking 0
2763
+ filerun $fd [list readdifffiles $fd $serial]
2764
+ }
2765
+
2766
+ if {$isdiff && $serial == $lserial && $localirow == -1} {
2767
+ # add the line for the changes in the index to the graph
2768
+ set localirow $commitrow($curview,$mainheadid)
2769
+ set hl "Local changes checked in to index but not committed"
2770
+ set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
2771
+ set commitdata($nullid2) "\n $hl\n"
2772
+ insertrow $localirow $nullid2
2773
+ }
2774
+ return 0
2775
+}
2776
+
2777
+proc readdifffiles {fd serial} {
2778
+ global localirow localfrow commitrow mainheadid nullid curview
2779
+ global commitinfo commitdata lserial
2780
+
2781
+ set isdiff 1
2782
+ if {[gets $fd line] < 0} {
2783
+ if {![eof $fd]} {
2784
+ return 1
2785
+ }
2786
+ set isdiff 0
2787
+ }
2788
+ # we only need to see one line and we don't really care what it says...
2789
+ close $fd
2790
+
2791
+ if {$isdiff && $serial == $lserial && $localfrow == -1} {
2792
# add the line for the local diff to the graph
2740
- set localrow $commitrow($curview,$mainheadid)
2741
- set hl "Local uncommitted changes"
2793
+ if {$localirow >= 0} {
2794
+ set localfrow $localirow
2795
+ incr localirow
2796
+ } else {
2797
+ set localfrow $commitrow($curview,$mainheadid)
2798
+ }
2799
+ set hl "Local uncommitted changes, not checked in to index"
2800
set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
2801
set commitdata($nullid) "\n $hl\n"
2744
- insertrow $localrow $nullid
2802
+ insertrow $localfrow $nullid
2803
}
2804
return 0
2805
}
@@ -3338,12 +3396,14 @@ proc drawcmittext {id row col} {
3396
global commitlisted commitinfo rowidlist parentlist
3397
global rowtextx idpos idtags idheads idotherrefs
3398
global linehtag linentag linedtag markingmatches
3341
- global mainfont canvxmax boldrows boldnamerows fgcolor nullid
3399
+ global mainfont canvxmax boldrows boldnamerows fgcolor nullid nullid2
3400
3401
# listed is 0 for boundary, 1 for normal, 2 for left, 3 for right
3402
set listed [lindex $commitlisted $row]
3403
if {$id eq $nullid} {
3404
set ofill red
3405
+ } elseif {$id eq $nullid2} {
3406
+ set ofill magenta
3407
} else {
3408
set ofill [expr {$listed != 0? "blue": "white"}]
3409
}
@@ -4582,16 +4642,19 @@ proc goforw {} {
4642
}
4643
4644
proc gettree {id} {
4585
- global treefilelist treeidlist diffids diffmergeid treepending nullid
4645
+ global treefilelist treeidlist diffids diffmergeid treepending
4646
+ global nullid nullid2
4647
4648
set diffids $id
4649
catch {unset diffmergeid}
4650
if {![info exists treefilelist($id)]} {
4651
if {![info exists treepending]} {
4591
- if {$id ne $nullid} {
4592
- set cmd [concat | git ls-tree -r $id]
4652
+ if {$id eq $nullid} {
4653
+ set cmd [list | git ls-files]
4654
+ } elseif {$id eq $nullid2} {
4655
+ set cmd [list | git ls-files --stage -t]
4656
} else {
4594
- set cmd [concat | git ls-files]
4657
+ set cmd [list | git ls-tree -r $id]
4658
}
4659
if {[catch {set gtf [open $cmd r]}]} {
4660
return
@@ -4608,12 +4671,14 @@ proc gettree {id} {
4671
}
4672
4673
proc gettreeline {gtf id} {
4611
- global treefilelist treeidlist treepending cmitmode diffids nullid
4674
+ global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
4675
4676
set nl 0
4677
while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
4615
- if {$diffids ne $nullid} {
4616
- if {[lindex $line 1] ne "blob"} continue
4678
+ if {$diffids eq $nullid} {
4679
+ set fname $line
4680
+ } else {
4681
+ if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
4682
set i [string first "\t" $line]
4683
if {$i < 0} continue
4684
set sha1 [lindex $line 2]
@@ -4622,8 +4687,6 @@ proc gettreeline {gtf id} {
4687
set fname [lindex $fname 0]
4688
}
4689
lappend treeidlist($id) $sha1
4625
- } else {
4626
- set fname $line
4690
}
4691
lappend treefilelist($id) $fname
4692
}
@@ -4645,7 +4708,7 @@ proc gettreeline {gtf id} {
4708
}
4709
4710
proc showfile {f} {
4648
- global treefilelist treeidlist diffids nullid
4711
+ global treefilelist treeidlist diffids nullid nullid2
4712
global ctext commentend
4713
4714
set i [lsearch -exact $treefilelist($diffids) $f]
@@ -4653,15 +4716,15 @@ proc showfile {f} {
4716
puts "oops, $f not in list for id $diffids"
4717
return
4718
}
4656
- if {$diffids ne $nullid} {
4657
- set blob [lindex $treeidlist($diffids) $i]
4658
- if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
4659
- puts "oops, error reading blob $blob: $err"
4719
+ if {$diffids eq $nullid} {
4720
+ if {[catch {set bf [open $f r]} err]} {
4721
+ puts "oops, can't read $f: $err"
4722
return
4723
}
4724
} else {
4663
- if {[catch {set bf [open $f r]} err]} {
4664
- puts "oops, can't read $f: $err"
4725
+ set blob [lindex $treeidlist($diffids) $i]
4726
+ if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
4727
+ puts "oops, error reading blob $blob: $err"
4728
return
4729
}
4730
}
@@ -4789,11 +4852,13 @@ proc getmergediffline {mdf id np} {
4852
}
4853
4854
proc startdiff {ids} {
4792
- global treediffs diffids treepending diffmergeid nullid
4855
+ global treediffs diffids treepending diffmergeid nullid nullid2
4856
4857
set diffids $ids
4858
catch {unset diffmergeid}
4796
- if {![info exists treediffs($ids)] || [lsearch -exact $ids $nullid] >= 0} {
4859
+ if {![info exists treediffs($ids)] ||
4860
+ [lsearch -exact $ids $nullid] >= 0 ||
4861
+ [lsearch -exact $ids $nullid2] >= 0} {
4862
if {![info exists treepending]} {
4863
gettreediffs $ids
4864
}
@@ -4809,22 +4874,41 @@ proc addtocflist {ids} {
4874
}
4875
4876
proc diffcmd {ids flags} {
4812
- global nullid
4877
+ global nullid nullid2
4878
4879
set i [lsearch -exact $ids $nullid]
4880
+ set j [lsearch -exact $ids $nullid2]
4881
if {$i >= 0} {
4816
- set cmd [concat | git diff-index $flags]
4882
+ if {[llength $ids] > 1 && $j < 0} {
4883
+ # comparing working directory with some specific revision
4884
+ set cmd [concat | git diff-index $flags]
4885
+ if {$i == 0} {
4886
+ lappend cmd -R [lindex $ids 1]
4887
+ } else {
4888
+ lappend cmd [lindex $ids 0]
4889
+ }
4890
+ } else {
4891
+ # comparing working directory with index
4892
+ set cmd [concat | git diff-files $flags]
4893
+ if {$j == 1} {
4894
+ lappend cmd -R
4895
+ }
4896
+ }
4897
+ } elseif {$j >= 0} {
4898
+ set cmd [concat | git diff-index --cached $flags]
4899
if {[llength $ids] > 1} {
4900
+ # comparing index with specific revision
4901
if {$i == 0} {
4902
lappend cmd -R [lindex $ids 1]
4903
} else {
4904
lappend cmd [lindex $ids 0]
4905
}
4906
} else {
4907
+ # comparing index with HEAD
4908
lappend cmd HEAD
4909
}
4910
} else {
4827
- set cmd [concat | git diff-tree --no-commit-id -r $flags $ids]
4911
+ set cmd [concat | git diff-tree -r $flags $ids]
4912
}
4913
return $cmd
4914
}
@@ -4834,7 +4918,7 @@ proc gettreediffs {ids} {
4918
4919
set treepending $ids
4920
set treediff {}
4837
- if {[catch {set gdtf [open [diffcmd $ids {}] r]}]} return
4921
+ if {[catch {set gdtf [open [diffcmd $ids {--no-commit-id}] r]}]} return
4922
fconfigure $gdtf -blocking 0
4923
filerun $gdtf [list gettreediffline $gdtf $ids]
4924
}
@@ -4877,7 +4961,7 @@ proc getblobdiffs {ids} {
4961
global diffinhdr treediffs
4962
4963
set env(GIT_DIFF_OPTS) $diffopts
4880
- if {[catch {set bdf [open [diffcmd $ids {-p -C}] r]} err]} {
4964
+ if {[catch {set bdf [open [diffcmd $ids {-p -C --no-commit-id}] r]} err]} {
4965
puts "error getting diffs: $err"
4966
return
4967
}
@@ -5468,7 +5552,7 @@ proc mstime {} {
5552
5553
proc rowmenu {x y id} {
5554
global rowctxmenu commitrow selectedline rowmenuid curview
5471
- global nullid fakerowmenu mainhead
5555
+ global nullid nullid2 fakerowmenu mainhead
5556
5557
set rowmenuid $id
5558
if {![info exists selectedline]
@@ -5477,7 +5561,7 @@ proc rowmenu {x y id} {
5561
} else {
5562
set state normal
5563
}
5480
- if {$id ne $nullid} {
5564
+ if {$id ne $nullid && $id ne $nullid2} {
5565
set menu $rowctxmenu
5566
$menu entryconfigure 7 -label "Reset $mainhead branch to here"
5567
} else {
@@ -5596,18 +5680,12 @@ proc mkpatchrev {} {
5680
}
5681
5682
proc mkpatchgo {} {
5599
- global patchtop nullid
5683
+ global patchtop nullid nullid2
5684
5685
set oldid [$patchtop.fromsha1 get]
5686
set newid [$patchtop.tosha1 get]
5687
set fname [$patchtop.fname get]
5604
- if {$newid eq $nullid} {
5605
- set cmd [list git diff-index -p $oldid]
5606
- } elseif {$oldid eq $nullid} {
5607
- set cmd [list git diff-index -p -R $newid]
5608
- } else {
5609
- set cmd [list git diff-tree -p $oldid $newid]
5610
- }
5688
+ set cmd [diffcmd [list $oldid $newid] -p]
5689
lappend cmd >$fname &
5690
if {[catch {eval exec $cmd} err]} {
5691
error_popup "Error creating patch: $err"
@@ -7522,6 +7600,8 @@ if {$i >= [llength $argv] && $revtreeargs ne {}} {
7600
}
7601
7602
set nullid "0000000000000000000000000000000000000000"
7603
+set nullid2 "0000000000000000000000000000000000000001"
7604
+
7605
7606
set runq {}
7607
set history {}
@@ -7550,7 +7630,8 @@ set stopped 0
7630
set stuffsaved 0
7631
set patchnum 0
7632
set lookingforhead 0
7553
-set localrow -1
7633
+set localirow -1
7634
+set localfrow -1
7635
set lserial 0
7636
setcoords
7637
makewindow