-
- if {$diffinhunk($ids) != 0} {
- set fi $currentfile($ids)
- if {$n > 0 && [regexp {^[-+ \\]} $line match]} {
- # continuing an existing hunk
- set line [string range $line 1 end]
- set p [lindex $ids 1]
- if {$match eq "-" || $match eq " "} {
- set filelines($p,$fi,$diffoldlno($ids)) $line
- incr diffoldlno($ids)
- }
- if {$match eq "+" || $match eq " "} {
- set filelines($id,$fi,$diffnewlno($ids)) $line
- incr diffnewlno($ids)
- }
- if {$match eq " "} {
- if {$diffinhunk($ids) == 2} {
- lappend difflcounts($ids) \
- [list $noldlines($ids) $nnewlines($ids)]
- set noldlines($ids) 0
- set diffinhunk($ids) 1
- }
- incr noldlines($ids)
- } elseif {$match eq "-" || $match eq "+"} {
- if {$diffinhunk($ids) == 1} {
- lappend difflcounts($ids) [list $noldlines($ids)]
- set noldlines($ids) 0
- set nnewlines($ids) 0
- set diffinhunk($ids) 2
- }
- if {$match eq "-"} {
- incr noldlines($ids)
- } else {
- incr nnewlines($ids)
- }
- }
- # and if it's \ No newline at end of line, then what?
- return
- }
- # end of a hunk
- if {$diffinhunk($ids) == 1 && $noldlines($ids) != 0} {
- lappend difflcounts($ids) [list $noldlines($ids)]
- } elseif {$diffinhunk($ids) == 2
- && ($noldlines($ids) != 0 || $nnewlines($ids) != 0)} {
- lappend difflcounts($ids) [list $noldlines($ids) $nnewlines($ids)]
- }
- set currenthunk($ids) [list $currentfile($ids) \
- $diffoldstart($ids) $diffnewstart($ids) \
- $diffoldlno($ids) $diffnewlno($ids) \
- $difflcounts($ids)]
- set diffinhunk($ids) 0
- # -1 = need to block, 0 = unblocked, 1 = is blocked
- set diffblocked($ids) -1
- processhunks
- if {$diffblocked($ids) == -1} {
- fileevent $f readable {}
- set diffblocked($ids) 1
- }
- }
-
- if {$n < 0} {
- # eof
- if {!$diffblocked($ids)} {
- close $f
- set currentfile($ids) [llength $mergefilelist($diffmergeid)]
- set currenthunk($ids) [list $currentfile($ids) 0 0 0 0 {}]
- processhunks
- }
- } elseif {[regexp {^diff --git a/(.*) b/} $line match fname]} {
- # start of a new file
- set currentfile($ids) \
- [lsearch -exact $mergefilelist($diffmergeid) $fname]
- } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
- $line match f1l f1c f2l f2c rest]} {
- if {[info exists currentfile($ids)] && $currentfile($ids) >= 0} {
- # start of a new hunk
- if {$f1l == 0 && $f1c == 0} {
- set f1l 1
- }
- if {$f2l == 0 && $f2c == 0} {
- set f2l 1
- }
- set diffinhunk($ids) 1
- set diffoldstart($ids) $f1l
- set diffnewstart($ids) $f2l
- set diffoldlno($ids) $f1l
- set diffnewlno($ids) $f2l
- set difflcounts($ids) {}
- set noldlines($ids) 0
- set nnewlines($ids) 0
- }
- }
-}
-
-proc processhunks {} {
- global diffmergeid parents nparents currenthunk
- global mergefilelist diffblocked mergefds
- global grouphunks grouplinestart grouplineend groupfilenum
-
- set nfiles [llength $mergefilelist($diffmergeid)]
- while 1 {
- set fi $nfiles
- set lno 0
- # look for the earliest hunk
- foreach p $parents($diffmergeid) {
- set ids [list $diffmergeid $p]
- if {![info exists currenthunk($ids)]} return
- set i [lindex $currenthunk($ids) 0]
- set l [lindex $currenthunk($ids) 2]
- if {$i < $fi || ($i == $fi && $l < $lno)} {
- set fi $i
- set lno $l
- set pi $p
- }
- }
-
- if {$fi < $nfiles} {
- set ids [list $diffmergeid $pi]
- set hunk $currenthunk($ids)
- unset currenthunk($ids)
- if {$diffblocked($ids) > 0} {
- fileevent $mergefds($ids) readable \
- [list getmergediffline $mergefds($ids) $ids $diffmergeid]
- }
- set diffblocked($ids) 0
-
- if {[info exists groupfilenum] && $groupfilenum == $fi
- && $lno <= $grouplineend} {
- # add this hunk to the pending group
- lappend grouphunks($pi) $hunk
- set endln [lindex $hunk 4]
- if {$endln > $grouplineend} {
- set grouplineend $endln
- }
- continue
- }
- }
-
- # succeeding stuff doesn't belong in this group, so
- # process the group now
- if {[info exists groupfilenum]} {
- processgroup
- unset groupfilenum
- unset grouphunks
- }
-
- if {$fi >= $nfiles} break
-
- # start a new group
- set groupfilenum $fi
- set grouphunks($pi) [list $hunk]
- set grouplinestart $lno
- set grouplineend [lindex $hunk 4]