@@ -1504,7 +1504,7 @@ proc donefilediff {} {
1504
1504
}
1505
1505
1506
1506
proc findcont {ids} {
1507
- global findids treediffs parents nparents treepending
1507
+ global findids treediffs parents nparents
1508
1508
global ffileline findstartline finddidsel
1509
1509
global lineid numcommits matchinglines findinprogress
1510
1510
global findmergefiles
@@ -1692,27 +1692,121 @@ proc selectline {l} {
1692
1692
1693
1693
$cflist delete 0 end
1694
1694
$cflist insert end " Comments"
1695
- startdiff $id $parents($id)
1695
+ if {$nparents($id) == 1} {
1696
+ startdiff [concat $id $parents($id) ]
1697
+ } elseif {$nparents($id) > 1} {
1698
+ mergediff $id
1699
+ }
1700
+ }
1701
+
1702
+ proc selnextline {dir} {
1703
+ global selectedline
1704
+ if {![info exists selectedline]} return
1705
+ set l [expr $selectedline + $dir ]
1706
+ unmarkmatches
1707
+ selectline $l
1696
1708
}
1697
1709
1698
- proc startdiff {id vs} {
1699
- global diffpending diffpindex
1700
- global diffindex difffilestart
1701
- global curdifftag curtagstart
1710
+ proc mergediff {id} {
1711
+ global parents diffmergeid diffmergegca mergefilelist diffpindex
1702
1712
1703
- set diffpending $vs
1704
- set diffpindex 0
1705
- set diffindex 0
1706
- catch {unset difffilestart}
1707
- set curdifftag Comments
1708
- set curtagstart 0.0
1709
- contdiff [list $id [lindex $vs 0]]
1713
+ set diffmergeid $id
1714
+ set diffpindex -1
1715
+ set diffmergegca [findgca $parents($id) ]
1716
+ if {[info exists mergefilelist($id )]} {
1717
+ showmergediff
1718
+ } else {
1719
+ contmergediff {}
1720
+ }
1721
+ }
1722
+
1723
+ proc findgca {ids} {
1724
+ set gca {}
1725
+ foreach id $ids {
1726
+ if {$gca eq {}} {
1727
+ set gca $id
1728
+ } else {
1729
+ if {[catch {
1730
+ set gca [exec git-merge-base $gca $id ]
1731
+ } err]} {
1732
+ return {}
1733
+ }
1734
+ }
1735
+ }
1736
+ return $gca
1737
+ }
1738
+
1739
+ proc contmergediff {ids} {
1740
+ global diffmergeid diffpindex parents nparents diffmergegca
1741
+ global treediffs mergefilelist diffids
1742
+
1743
+ # diff the child against each of the parents, and diff
1744
+ # each of the parents against the GCA.
1745
+ while 1 {
1746
+ if {[lindex $ids 0] == $diffmergeid && $diffmergegca ne {}} {
1747
+ set ids [list [lindex $ids 1] $diffmergegca ]
1748
+ } else {
1749
+ if {[incr diffpindex] >= $nparents($diffmergeid) } break
1750
+ set p [lindex $parents($diffmergeid) $diffpindex ]
1751
+ set ids [list $diffmergeid $p ]
1752
+ }
1753
+ if {![info exists treediffs($ids )]} {
1754
+ set diffids $ids
1755
+ gettreediffs $ids
1756
+ return
1757
+ }
1758
+ }
1759
+
1760
+ # If a file in some parent is different from the child and also
1761
+ # different from the GCA, then it's interesting.
1762
+ # If we don't have a GCA, then a file is interesting if it is
1763
+ # different from the child in all the parents.
1764
+ if {$diffmergegca ne {}} {
1765
+ set files {}
1766
+ foreach p $parents($diffmergeid) {
1767
+ set gcadiffs $treediffs([list $p $diffmergegca])
1768
+ foreach f $treediffs([list $diffmergeid $p]) {
1769
+ if {[lsearch -exact $files $f ] < 0
1770
+ && [lsearch -exact $gcadiffs $f ] >= 0} {
1771
+ lappend files $f
1772
+ }
1773
+ }
1774
+ }
1775
+ set files [lsort $files ]
1776
+ } else {
1777
+ set p [lindex $parents($diffmergeid) 0]
1778
+ set files $treediffs([list $diffmergeid $p])
1779
+ for {set i 1} {$i < $nparents($diffmergeid) && $files ne {}} {incr i} {
1780
+ set p [lindex $parents($diffmergeid) $i ]
1781
+ set df $treediffs([list $diffmergeid $p])
1782
+ set nf {}
1783
+ foreach f $files {
1784
+ if {[lsearch -exact $df $f ] >= 0} {
1785
+ lappend nf $f
1786
+ }
1787
+ }
1788
+ set files $nf
1789
+ }
1790
+ }
1791
+
1792
+ set mergefilelist($diffmergeid ) $files
1793
+ showmergediff
1794
+ }
1795
+
1796
+ proc showmergediff {} {
1797
+ global cflist diffmergeid mergefilelist
1798
+
1799
+ set files $mergefilelist($diffmergeid)
1800
+ foreach f $files {
1801
+ $cflist insert end $f
1802
+ }
1710
1803
}
1711
1804
1712
- proc contdiff {ids} {
1713
- global treediffs diffids treepending
1805
+ proc startdiff {ids} {
1806
+ global treediffs diffids treepending diffmergeid
1714
1807
1715
1808
set diffids $ids
1809
+ catch {unset diffmergeid}
1716
1810
if {![info exists treediffs($ids )]} {
1717
1811
if {![info exists treepending]} {
1718
1812
gettreediffs $ids
@@ -1722,79 +1816,76 @@ proc contdiff {ids} {
1722
1816
}
1723
1817
}
1724
1818
1725
- proc selnextline {dir} {
1726
- global selectedline
1727
- if {![info exists selectedline]} return
1728
- set l [expr $selectedline + $dir ]
1729
- unmarkmatches
1730
- selectline $l
1731
- }
1732
-
1733
1819
proc addtocflist {ids} {
1734
- global treediffs cflist diffpindex
1735
-
1736
- set colors {black blue green red cyan magenta}
1737
- set color [lindex $colors [expr {$diffpindex % [llength $colors ]}]]
1820
+ global treediffs cflist
1738
1821
foreach f $treediffs($ids) {
1739
1822
$cflist insert end $f
1740
- $cflist itemconf end -foreground $color
1741
1823
}
1742
1824
getblobdiffs $ids
1743
1825
}
1744
1826
1745
1827
proc gettreediffs {ids} {
1746
- global treediffs parents treepending
1828
+ global treediff parents treepending
1747
1829
set treepending $ids
1748
- set treediffs( $ids ) {}
1830
+ set treediff {}
1749
1831
set id [lindex $ids 0]
1750
1832
set p [lindex $ids 1]
1751
1833
if [catch {set gdtf [open " |git-diff-tree -r $p $id " r]}] return
1752
1834
fconfigure $gdtf -blocking 0
1753
- fileevent $gdtf readable " gettreediffline $gdtf { $ids } "
1835
+ fileevent $gdtf readable [ list gettreediffline $gdtf $ids ]
1754
1836
}
1755
1837
1756
1838
proc gettreediffline {gdtf ids} {
1757
- global treediffs treepending diffids
1839
+ global treediff treediffs treepending diffids diffmergeid
1840
+
1758
1841
set n [gets $gdtf line]
1759
1842
if {$n < 0} {
1760
1843
if {![eof $gdtf ]} return
1761
1844
close $gdtf
1845
+ set treediffs($ids ) $treediff
1762
1846
unset treepending
1763
- if {[info exists diffids]} {
1764
- if {$ids != $diffids } {
1765
- gettreediffs $diffids
1847
+ if {$ids != $diffids } {
1848
+ gettreediffs $diffids
1849
+ } else {
1850
+ if {[info exists diffmergeid]} {
1851
+ contmergediff $ids
1766
1852
} else {
1767
1853
addtocflist $ids
1768
1854
}
1769
1855
}
1770
1856
return
1771
1857
}
1772
1858
set file [lindex $line 5]
1773
- lappend treediffs( $ids ) $file
1859
+ lappend treediff $file
1774
1860
}
1775
1861
1776
1862
proc getblobdiffs {ids} {
1777
- global diffopts blobdifffd diffids env
1778
- global nextupdate diffinhdr
1863
+ global diffopts blobdifffd diffids env curdifftag curtagstart
1864
+ global diffindex difffilestart nextupdate diffinhdr
1779
1865
1780
1866
set id [lindex $ids 0]
1781
1867
set p [lindex $ids 1]
1782
1868
set env(GIT_DIFF_OPTS) $diffopts
1783
- if [catch {set bdf [open " |git-diff-tree -r -p $p $id " r]} err] {
1869
+ set cmd [list | git-diff-tree -r -p -C $p $id ]
1870
+ if {[catch {set bdf [open $cmd r]} err]} {
1784
1871
puts " error getting diffs: $err "
1785
1872
return
1786
1873
}
1787
1874
set diffinhdr 0
1788
1875
fconfigure $bdf -blocking 0
1789
1876
set blobdifffd($ids ) $bdf
1790
- fileevent $bdf readable [list getblobdiffline $bdf $ids ]
1877
+ set curdifftag Comments
1878
+ set curtagstart 0.0
1879
+ set diffindex 0
1880
+ catch {unset difffilestart}
1881
+ fileevent $bdf readable [list getblobdiffline $bdf $diffids ]
1791
1882
set nextupdate [expr {[clock clicks -milliseconds] + 100}]
1792
1883
}
1793
1884
1794
1885
proc getblobdiffline {bdf ids} {
1795
1886
global diffids blobdifffd ctext curdifftag curtagstart
1796
1887
global diffnexthead diffnextnote diffindex difffilestart
1797
- global nextupdate diffpending diffpindex diffinhdr
1888
+ global nextupdate diffinhdr
1798
1889
global gaudydiff
1799
1890
1800
1891
set n [gets $bdf line]
@@ -1803,11 +1894,6 @@ proc getblobdiffline {bdf ids} {
1803
1894
close $bdf
1804
1895
if {$ids == $diffids && $bdf == $blobdifffd($ids) } {
1805
1896
$ctext tag add $curdifftag $curtagstart end
1806
- if {[incr diffpindex] < [llength $diffpending ]} {
1807
- set id [lindex $ids 0]
1808
- set p [lindex $diffpending $diffpindex ]
1809
- contdiff [list $id $p ]
1810
- }
1811
1897
}
1812
1898
}
1813
1899
return
@@ -2157,7 +2243,7 @@ proc diffvssel {dirn} {
2157
2243
$ctext conf -state disabled
2158
2244
$ctext tag delete Comments
2159
2245
$ctext tag remove found 1.0 end
2160
- startdiff [ list $newid $oldid ]
2246
+ startdiff $newid [ list $oldid ]
2161
2247
}
2162
2248
2163
2249
proc mkpatch {} {
0 commit comments