Eskil

Check-in [2795132d5b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improvements to 3-way merge.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2795132d5b269b1d8f01aacf3908d807552e15fc
User & Date: peter 2012-02-19 22:33:49.437
Context
2012-02-20
22:00
Examples adjustments. check-in: 52ea670136 user: peter tags: trunk
2012-02-19
22:33
Improvements to 3-way merge. check-in: 2795132d5b user: peter tags: trunk
21:58
Cleanup to get tests to run. check-in: 40e553d4d7 user: peter tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to eskil.vfs/lib/psballoon/psballoon.tcl.
91
92
93
94
95
96
97



98
99
100
101
102
103
104
                    set msg [$w cget -text]
		    set iw [font measure $font $msg]
                }
            }
            #Don't create a balloon if the text is fully visible.
            set create [expr {$iw > $ww - 8}]
        } else {



	    set iw [font measure $font $msg]
	}
	if {$create} {
            set x [expr {[winfo rootx $w] + $ix}]
            set y [expr {[winfo rooty $w] + $iy + $ih + 2}]
            if {$x + $iw + 8 > [winfo screenwidth $w]} {
                set x [expr {[winfo screenwidth $w] - $iw - 8}]







>
>
>







91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
                    set msg [$w cget -text]
		    set iw [font measure $font $msg]
                }
            }
            #Don't create a balloon if the text is fully visible.
            set create [expr {$iw > $ww - 8}]
        } else {
            if {[string index $msg 0] eq "\["} {
                set msg [subst -novariables -nobackslash $msg]
            }
	    set iw [font measure $font $msg]
	}
	if {$create} {
            set x [expr {[winfo rootx $w] + $ix}]
            set y [expr {[winfo rooty $w] + $iy + $ih + 2}]
            if {$x + $iw + 8 > [winfo screenwidth $w]} {
                set x [expr {[winfo screenwidth $w] - $iw - 8}]
Changes to src/merge.tcl.
67
68
69
70
71
72
73
74
75
76

77
78
79
80
81
82
83
            gets $ch2 apa
            append data2 $apa\n
            incr doingLine2
        }
        lappend eskil($top,leftMergeData) $data1
        lappend eskil($top,rightMergeData) $data2
        set eskil($top,mergeSelection,$changeNo) \
                [WhichSide $top $line1 $n1 $line2 $n2 conflict comment]
        set eskil($top,mergeSelection,Conflict,$changeNo) $conflict
        set eskil($top,mergeSelection,Comment,$changeNo) $comment

        if {$conflict} {
            set eskil($top,mergeSelection,AnyConflict) 1
        }
        incr changeNo
    }
    set data1 {}
    set data2 {}







|


>







67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
            gets $ch2 apa
            append data2 $apa\n
            incr doingLine2
        }
        lappend eskil($top,leftMergeData) $data1
        lappend eskil($top,rightMergeData) $data2
        set eskil($top,mergeSelection,$changeNo) \
                [WhichSide $top $line1 $n1 $line2 $n2 conflict comment ancLines]
        set eskil($top,mergeSelection,Conflict,$changeNo) $conflict
        set eskil($top,mergeSelection,Comment,$changeNo) $comment
        set eskil($top,mergeSelection,AncLines,$changeNo) "Lines from ancestor file:\n[join $ancLines \n]"
        if {$conflict} {
            set eskil($top,mergeSelection,AnyConflict) 1
        }
        incr changeNo
    }
    set data1 {}
    set data2 {}
151
152
153
154
155
156
157


158
159
160
161
162
163
164
    update
    # If there is any diff, show the first
    if {$t > 0} {
        seeText $w merges$showFirst mergee$showFirst
        # Show status for first chunk
        set eskil($top,mergeStatus) \
                $eskil($top,mergeSelection,Comment,$showFirst)


    }
}

# Move to and highlight another diff.
proc nextMerge {top delta} {
    global eskil








>
>







152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
    update
    # If there is any diff, show the first
    if {$t > 0} {
        seeText $w merges$showFirst mergee$showFirst
        # Show status for first chunk
        set eskil($top,mergeStatus) \
                $eskil($top,mergeSelection,Comment,$showFirst)
        set eskil($top,mergeAncLines) \
                $eskil($top,mergeSelection,AncLines,$showFirst)
    }
}

# Move to and highlight another diff.
proc nextMerge {top delta} {
    global eskil

193
194
195
196
197
198
199


200
201
202
203
204
205
206
    set eskil($top,curMergeSel) $eskil($top,mergeSelection,$eskil($top,curMerge))
    $w tag configure merge$eskil($top,curMerge) -foreground red
    showDiff $top $eskil($top,curMerge)
    seeText $w merges$eskil($top,curMerge) mergee$eskil($top,curMerge)

    set eskil($top,mergeStatus) \
            $eskil($top,mergeSelection,Comment,$eskil($top,curMerge))


}

# Select a merge setting for all diffs.
proc selectMergeAll {top new} {
    global eskil

    set end [expr {[llength $eskil($top,leftMergeData)] / 2}]







>
>







196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
    set eskil($top,curMergeSel) $eskil($top,mergeSelection,$eskil($top,curMerge))
    $w tag configure merge$eskil($top,curMerge) -foreground red
    showDiff $top $eskil($top,curMerge)
    seeText $w merges$eskil($top,curMerge) mergee$eskil($top,curMerge)

    set eskil($top,mergeStatus) \
            $eskil($top,mergeSelection,Comment,$eskil($top,curMerge))
    set eskil($top,mergeAncLines) \
            $eskil($top,mergeSelection,AncLines,$eskil($top,curMerge))
}

# Select a merge setting for all diffs.
proc selectMergeAll {top new} {
    global eskil

    set end [expr {[llength $eskil($top,leftMergeData)] / 2}]
461
462
463
464
465
466
467

468
469
470
471
472
473
474
            -yscrollcommand "$w.sby set" -font myfont
    scrollbar $w.sbx -orient horizontal -command "$w.t xview"
    scrollbar $w.sby -orient vertical   -command "$w.t yview"

    bind $w.t <Key-Escape> [list focus $w]

    ttk::label $w.ls -textvariable ::eskil($top,mergeStatus)


    # Prevent toplevel bindings on keys to fire while in the text widget.
    bindtags $w.t [list Text $w.t $w all]
    bind $w.t <Key-Left>  "break"
    bind $w.t <Key-Right> "break"
    bind $w.t <Key-Down>  "break"
    bind $w.t <Key-Up>    "break"







>







466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
            -yscrollcommand "$w.sby set" -font myfont
    scrollbar $w.sbx -orient horizontal -command "$w.t xview"
    scrollbar $w.sby -orient vertical   -command "$w.t yview"

    bind $w.t <Key-Escape> [list focus $w]

    ttk::label $w.ls -textvariable ::eskil($top,mergeStatus)
    addBalloon $w.ls \[[list set ::eskil($top,mergeAncLines)]\]

    # Prevent toplevel bindings on keys to fire while in the text widget.
    bindtags $w.t [list Text $w.t $w all]
    bind $w.t <Key-Left>  "break"
    bind $w.t <Key-Right> "break"
    bind $w.t <Key-Down>  "break"
    bind $w.t <Key-Up>    "break"
505
506
507
508
509
510
511








512
513
514
515
516
517
518
519
520
521
522
523
524




525
526

527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542




543
544

545
546
547
548
549
550
551
552
553
554
555
556

557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573


574
575

576

577
578







579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597


598
599

600

601
602







603
604
605
606
607
608
609
610
611
612
613
614
615



616
617
618
619
620
621
622
623
624
625
626
627
628
629
630



631
632
633
634
635
636
637
638
639
640
641
642

643
644
645
646
647
648
649
650
651
652
653
    set differrA2 [catch {DiffUtil::diffFiles {*}$opts \
            $::eskil($top,ancestorFile) $dFile2} diffresA2]
    if {$differrA1 != 0 || $differrA2 != 0} {
        puts $diffresA1
        puts $diffresA2
        return
    }








    foreach i $diffresA1 {
        lassign $i line1 n1 line2 n2
        if {$n1 == 0} {
            # Added lines
            for {set t $line2} {$t < $line2 + $n2} {incr t} {
                set ::eskil($top,ancestorLeft,$t) a
            }
        } elseif {$n2 == 0} {
            # Deleted lines
            # Mark the following line
            set ::eskil($top,ancestorLeft,d$line2) d
        } else {
            # Changed lines




            for {set t $line2} {$t < $line2 + $n2} {incr t} {
                set ::eskil($top,ancestorLeft,$t) c

            }
        }
    }            
    foreach i $diffresA2 {
        lassign $i line1 n1 line2 n2
        if {$n1 == 0} {
            # Added lines
            for {set t $line2} {$t < $line2 + $n2} {incr t} {
                set ::eskil($top,ancestorRight,$t) a
            }
        } elseif {$n2 == 0} {
            # Deleted lines
            # Mark the following line
            set ::eskil($top,ancestorRight,d$line2) d
        } else {
            # Changed lines




            for {set t $line2} {$t < $line2 + $n2} {incr t} {
                set ::eskil($top,ancestorRight,$t) c

            }
        }
    }
    #parray ::diff $top,ancestor*
}

# Use ancestor info to select which side to use in a merge chunk
##nagelfar syntax WhichSide x x x x x n n
proc WhichSide {top line1 n1 line2 n2 conflictName commentName} {
    upvar 1 $conflictName conflict $commentName comment
    set conflict 0
    set comment ""

    if {$::eskil($top,ancestorFile) eq ""} {
        # No ancestor info, just select right side
        return 2
    }
    if {$n1 == 0} {
        # Only to the right
        set delLeft [info exists ::eskil($top,ancestorLeft,d$line1)]
        # Inserted to right : Keep right side
        if {!$delLeft} {
            set comment "Right: Add"
            return 2
        }

        for {set t $line2} {$t < $line2 + $n2} {incr t} {
            if {[info exists ::eskil($top,ancestorRight,$t)]} {
                set right($::eskil($top,ancestorRight,$t)) 1
            }


        }
        # Deleted to left   : Keep left side

        if {[array size right] == 0} {

            set comment "Left: Delete"
            return 1







        }
        # Deleted to left and changed to the right : ?? (right for now)
        # FIXA
        set comment "*** Left: Delete, Right: Change"
        set conflict 1
        return 2
    } elseif {$n2 == 0} {
        # Only to the left, this can be:
        set delRight [info exists ::eskil($top,ancestorRight,d$line2)]
        # Inserted to left : Keep left side
        if {!$delRight} {
            set comment "Left: Add"
            return 1
        }

        for {set t $line1} {$t < $line1 + $n1} {incr t} {
            if {[info exists ::eskil($top,ancestorLeft,$t)]} {
                set left($::eskil($top,ancestorLeft,$t)) 1
            }


        }
        # Deleted to right : Keep right side

        if {[array size left] == 0} {

            set comment "Right: Delete"
            return 2







        }
        # Deleted to right and changed to the left : ?? (right for now)
        # FIXA
        set comment "*** Left: Change, Right: Delete"
        set conflict 1
        return 2
    } else {
        # Changed on both sides

        # Collect left side info
        for {set t $line1} {$t < $line1 + $n1} {incr t} {
            if {[info exists ::eskil($top,ancestorLeft,$t)]} {
                set left($::eskil($top,ancestorLeft,$t)) 1



            }
        }

        # No changes against ancestor on left side means it is just
        # changed to the right : Keep right
        if {[array size left] == 0} {
            set comment "Right: Change"
            return 2
        }

        # Collect right side info
        for {set t $line2} {$t < $line2 + $n2} {incr t} {
            if {[info exists ::eskil($top,ancestorRight,$t)]} {
                set right($::eskil($top,ancestorRight,$t)) 1
            }



        }

        # No changes against ancestor on right side means it is just
        # changed to the left : Keep left
        if {[array size right] == 0} {
            set comment "Left: Change"
            return 1
        }

        if {[info exists left(a)] && ![info exists left(c)] && \
                [info exists right(a)] && ![info exists right(c)]} {
            # Pure add on both sides, keep both

            set comment "*** Left: Add, Right: Add"
            set conflict 1
            return 12
        }
        # Changed in both, right for now
        # FIXA
        set comment "*** Left: Change, Right: Change"
        set conflict 1
        return 2
    }
}







>
>
>
>
>
>
>
>













>
>
>
>


>
















>
>
>
>


>







|
|
|


>





|
<
<
<
<
<
<
|




>
>
|
<
>

>


>
>
>
>
>
>
>







|
<
<
<
<
<
<
|




>
>
|
<
>

>


>
>
>
>
>
>
>













>
>
>















>
>
>











|
>











511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587






588
589
590
591
592
593
594
595

596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615






616
617
618
619
620
621
622
623

624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
    set differrA2 [catch {DiffUtil::diffFiles {*}$opts \
            $::eskil($top,ancestorFile) $dFile2} diffresA2]
    if {$differrA1 != 0 || $differrA2 != 0} {
        puts $diffresA1
        puts $diffresA2
        return
    }

    # We store ancestor data to provide it as popup info.
    # This is a bit ugly but it at least allows access to ancestor contents
    # at all, even if a nicer presentation could probably be made.
    set ch [open $::eskil($top,ancestorFile)]
    set ancestorLines [split [read $ch] \n]
    close $ch

    foreach i $diffresA1 {
        lassign $i line1 n1 line2 n2
        if {$n1 == 0} {
            # Added lines
            for {set t $line2} {$t < $line2 + $n2} {incr t} {
                set ::eskil($top,ancestorLeft,$t) a
            }
        } elseif {$n2 == 0} {
            # Deleted lines
            # Mark the following line
            set ::eskil($top,ancestorLeft,d$line2) d
        } else {
            # Changed lines
            set ancLines {}
            for {set t $line1} {$t < $line1 + $n1} {incr t} {
                lappend ancLines "$t: [lindex $ancestorLines [- $t 1]]"
            }
            for {set t $line2} {$t < $line2 + $n2} {incr t} {
                set ::eskil($top,ancestorLeft,$t) c
                set ::eskil($top,ancestorLeft,$t,lines) $ancLines
            }
        }
    }            
    foreach i $diffresA2 {
        lassign $i line1 n1 line2 n2
        if {$n1 == 0} {
            # Added lines
            for {set t $line2} {$t < $line2 + $n2} {incr t} {
                set ::eskil($top,ancestorRight,$t) a
            }
        } elseif {$n2 == 0} {
            # Deleted lines
            # Mark the following line
            set ::eskil($top,ancestorRight,d$line2) d
        } else {
            # Changed lines
            set ancLines {}
            for {set t $line1} {$t < $line1 + $n1} {incr t} {
                lappend ancLines "$t: [lindex $ancestorLines [- $t 1]]"
            }
            for {set t $line2} {$t < $line2 + $n2} {incr t} {
                set ::eskil($top,ancestorRight,$t) c
                set ::eskil($top,ancestorRight,$t,lines) $ancLines
            }
        }
    }
    #parray ::diff $top,ancestor*
}

# Use ancestor info to select which side to use in a merge chunk
##nagelfar syntax WhichSide x x x x x n n n
proc WhichSide {top line1 n1 line2 n2 conflictName commentName ancLinesName} {
    upvar 1 $conflictName conflict $commentName comment $ancLinesName ancLines
    set conflict 0
    set comment ""
    set ancLines {}
    if {$::eskil($top,ancestorFile) eq ""} {
        # No ancestor info, just select right side
        return 2
    }
    if {$n1 == 0} {
        # This chunk has lines only to the right






        # Look for changes on the right side
        for {set t $line2} {$t < $line2 + $n2} {incr t} {
            if {[info exists ::eskil($top,ancestorRight,$t)]} {
                set right($::eskil($top,ancestorRight,$t)) 1
            }
            if {[info exists ::eskil($top,ancestorRight,$t,lines)]} {
                set ancLines $::eskil($top,ancestorRight,$t,lines)
            }

        }
        if {[array size right] == 0} {
            # No changes to the right, so deleted to the left : Keep left side
            set comment "Left: Delete"
            return 1
        }
        # Is it deleted on the left side?
        set delLeft [info exists ::eskil($top,ancestorLeft,d$line1)]
        if {!$delLeft} {
            # It is inserted to the right : Keep right side
            set comment "Right: Add"
            return 2
        }
        # Deleted to left and changed to the right : ?? (right for now)
        # FIXA
        set comment "*** Left: Delete, Right: Change"
        set conflict 1
        return 2
    } elseif {$n2 == 0} {
        # This chunk has lines only to the left






        # Look for changes on the left side
        for {set t $line1} {$t < $line1 + $n1} {incr t} {
            if {[info exists ::eskil($top,ancestorLeft,$t)]} {
                set left($::eskil($top,ancestorLeft,$t)) 1
            }
            if {[info exists ::eskil($top,ancestorLeft,$t,lines)]} {
                set ancLines $::eskil($top,ancestorLeft,$t,lines)
            }

        }
        if {[array size left] == 0} {
            # No changes to the left, so deleted to the right : Keep right side
            set comment "Right: Delete"
            return 2
        }
        # Is it deleted on the right side?
        set delRight [info exists ::eskil($top,ancestorRight,d$line2)]
        if {!$delRight} {
            # It is inserted to the left : Keep left side
            set comment "Left: Add"
            return 1
        }
        # Deleted to right and changed to the left : ?? (right for now)
        # FIXA
        set comment "*** Left: Change, Right: Delete"
        set conflict 1
        return 2
    } else {
        # Changed on both sides

        # Collect left side info
        for {set t $line1} {$t < $line1 + $n1} {incr t} {
            if {[info exists ::eskil($top,ancestorLeft,$t)]} {
                set left($::eskil($top,ancestorLeft,$t)) 1
            }
            if {[info exists ::eskil($top,ancestorLeft,$t,lines)]} {
                set ancLines $::eskil($top,ancestorLeft,$t,lines)
            }
        }

        # No changes against ancestor on left side means it is just
        # changed to the right : Keep right
        if {[array size left] == 0} {
            set comment "Right: Change"
            return 2
        }

        # Collect right side info
        for {set t $line2} {$t < $line2 + $n2} {incr t} {
            if {[info exists ::eskil($top,ancestorRight,$t)]} {
                set right($::eskil($top,ancestorRight,$t)) 1
            }
            if {[info exists ::eskil($top,ancestorRight,$t,lines)]} {
                set ancLines $::eskil($top,ancestorRight,$t,lines)
            }
        }

        # No changes against ancestor on right side means it is just
        # changed to the left : Keep left
        if {[array size right] == 0} {
            set comment "Left: Change"
            return 1
        }

        if {[info exists left(a)] && ![info exists left(c)] && \
                [info exists right(a)] && ![info exists right(c)]} {
            # Pure add on both sides, keep both, but mark it as a conflict
            # to alert user
            set comment "*** Left: Add, Right: Add"
            set conflict 1
            return 12
        }
        # Changed in both, right for now
        # FIXA
        set comment "*** Left: Change, Right: Change"
        set conflict 1
        return 2
    }
}