Eskil

Changes On Branch 0f4c63dfb29becd2
Login

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

Changes In Branch table-list Through [0f4c63dfb2] Excluding Merge-Ins

This is equivalent to a diff from ab1da68c44 to 0f4c63dfb2

2010-11-07
20:19
Autodetect line endings in conflict file. Allow line ending selection in merge save. [FR 5160] Added menu bar to merge window. check-in: a2cdf2901b user: peter.spjuth@gmail.com tags: trunk
2010-06-23
22:34
Make sure Restart is only scheduled once. check-in: 07f2a54ef5 user: peter.spjuth@gmail.com tags: table-list
21:28
Removed Name columns from dir diff. check-in: 0f4c63dfb2 user: peter.spjuth@gmail.com tags: table-list
21:23
Remade hidden columns into row attributes. check-in: 79b9aabf5f user: peter.spjuth@gmail.com tags: table-list
20:34
Trying out to use tablelist instead of ttk::treeview for dir diff. check-in: 17bdab9a27 user: peter.spjuth@gmail.com tags: table-list
20:33
Support -noempty from DiffUtil. check-in: ab1da68c44 user: peter.spjuth@gmail.com tags: trunk
20:31
Get DiffUtil from new location. check-in: fab6204614 user: peter.spjuth@gmail.com tags: trunk

Changes to src/dirdiff.tcl.
1
2
3
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23


24
25
26
27
28
29
30
1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32



-
+



















+
+







#----------------------------------------------------------------------
#  Eskil, Directory diff section
#
#  Copyright (c) 1998-2007, Peter Spjuth  (peter.spjuth@gmail.com)
#  Copyright (c) 1998-2010, Peter Spjuth  (peter.spjuth@gmail.com)
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; see the file COPYING.  If not, write to
#  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
#  Boston, MA 02111-1307, USA.
#
#----------------------------------------------------------------------
# $Revision$
#----------------------------------------------------------------------

package require tablelist_tile

# Compare file names
proc FStrCmp {s1 s2} {
    # Equality is based on platform's standard
    # Order is dictionary order

    # Exact equal is equal regardless of platform.
234
235
236
237
238
239
240

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258

259

260
261

262
263

264
265
266
267
268
269
270
271
272

273
274
275
276
277
278
279
280
281
282
283
284
285





286
287
288
289
290
291
292






293

294
295
296
297







298
299
300
301
302
303
304
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262

263


264


265
266
267
268
269
270
271
272
273

274
275












276
277
278
279
280
281






282
283
284
285
286
287
288
289




290
291
292
293
294
295
296
297
298
299
300
301
302
303







+


















+
-
+
-
-
+
-
-
+








-
+

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+

+
-
-
-
-
+
+
+
+
+
+
+







    if {$newdir != ""} {
        set dir $newdir
        $entryW xview end
    }
}

snit::widget DirCompareTree {
    hulltype ttk::frame
    component tree
    component hsb
    component vsb

    option -leftdirvariable  -default "" -configuremethod SetDirOption
    option -rightdirvariable -default "" -configuremethod SetDirOption
    option -statusvar -default ""

    variable AfterId ""
    variable PauseBgProcessing 0
    variable IdleQueue {}
    variable IdleQueueArr
    variable leftMark ""
    variable rightMark ""
    variable leftDir ""
    variable rightDir ""

    constructor {args} {
        variable color
        install tree using ttk::treeview $win.tree -height 20 \
        install tree using tablelist::tablelist $win.tree -height 20 \
                -columns {type status leftfull leftname leftsize leftdate rightfull rightname rightsize rightdate} \
                -displaycolumns {leftsize leftdate rightsize rightdate}
                -movablecolumns no -setgrid no -showseparators yes \
# Experiment to show less. FIXA
#                -displaycolumns {leftname leftsize leftdate rightname rightsize rightdate}
                -columns {0 "Structure" 0 Size 0 Date 0 Size 0 Date}
        install vsb using scrollbar $win.vsb -orient vertical \
                -command "$tree yview"
        install hsb using scrollbar $win.hsb -orient horizontal \
                -command "$tree xview"

        set AfterId ""
        set IdleQueue {}

        $tree configure -yscroll "$vsb set" -xscroll "$hsb set"
        $tree configure -yscrollcommand "$vsb set" -xscrollcommand "$hsb set"

        $tree heading \#0 -text "Structure"
        $tree heading leftname -text "Name"
        $tree heading leftsize -text "Size"
        $tree heading leftdate -text "Date"
        $tree heading rightname -text "Name"
        $tree heading rightsize -text "Size"
        $tree heading rightdate -text "Date"

        $tree column leftsize  -stretch 0 -width 70 -anchor e
        $tree column rightsize -stretch 0 -width 70 -anchor e
        $tree column leftdate  -stretch 0 -width 120
        $tree column rightdate -stretch 0 -width 120
        $tree columnconfigure 0 -name structure
        $tree columnconfigure 1 -name leftsize -align right
        $tree columnconfigure 2 -name leftdate
        $tree columnconfigure 3 -name rightsize -align right
        $tree columnconfigure 4 -name rightdate

        $tree tag configure unknown -foreground grey
        $tree tag configure empty   -foreground grey
        $tree tag configure equal   -foreground {}
        $tree tag configure new     -foreground green
        $tree tag configure old     -foreground blue
        $tree tag configure change  -foreground red
        set color(unknown) grey
        set color(empty) grey
        set color(equal) {}
        set color(new) green
        set color(old) blue
        set color(change) red

        #-expandcommand expandCmd
        bind $tree <<TreeviewOpen>> "[mymethod UpdateDirNode] \[%W focus\]"
        bind $tree <Button-3> "[mymethod ContextMenu] %x %y %X %Y"
        bind $tree <Double-ButtonPress-1> "[mymethod DoubleClick] %x %y"
        bind $tree <Key-Return> [mymethod KeyReturn]
        #bind $tree <<TreeviewOpen>> "[mymethod UpdateDirNode] \[%W focus\]"
        set bodyTag [$tree bodytag]
        bind $bodyTag <<Button3>>  [bind TablelistBody <Button-1>]
        bind $bodyTag <<Button3>> +[bind TablelistBody <ButtonRelease-1>]
        bind $bodyTag <<Button3>> "+[mymethod ContextMenu] %W %x %y %X %Y"
        bind $bodyTag <Double-1>   "[mymethod DoubleClick] %W %x %y"
        bind $bodyTag <Key-Return> [mymethod KeyReturn]

        grid $tree $vsb -sticky nsew
        grid $hsb         -sticky nsew
        grid columnconfigure $win 0 -weight 1
        grid rowconfigure    $win 0 -weight 1

        $self configurelist $args
348
349
350
351
352
353
354
355
356
357
358












359
360

361
362
363

364
365
366
367
368
369
370
371
372
373

374
375
376
377
378

379
380
381
382

383
384
385
386
387
388
389

390

391
392
393

394
395

396
397
398
399
400
401
402
403
404
405
406
407
408
409


410
411
412


413
414
415
416
417
418
419
347
348
349
350
351
352
353




354
355
356
357
358
359
360
361
362
363
364
365


366

367

368
369
370
371
372
373
374
375
376
377

378
379
380
381
382

383
384
385
386

387
388
389
390
391
392
393
394
395

396



397


398





399
400
401
402
403
404
405


406
407
408


409
410
411
412
413
414
415
416
417







-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-

-
+









-
+




-
+



-
+







+
-
+
-
-
-
+
-
-
+
-
-
-
-
-







-
-
+
+

-
-
+
+







            after cancel $AfterId
        }
        set AfterId ""
        set IdleQueue {}
        array unset IdleQueueArr
        
        # Fill in clean root data
        $tree delete [$tree children {}]
        $tree set {} type directory
        $self SetNodeStatus {} empty
        $tree set {} leftfull   $leftDir
        $tree delete 0 end
        set topIndex [$tree insertchild root end {}]
        set d1 [file tail $leftDir]
        set d2 [file tail $rightDir]
        if {$d1 eq $d2} {
            $tree cellconfigure $topIndex,structure -text $d1
        } else {
            $tree cellconfigure $topIndex,structure -text "$d1 vs $d2"
        }
        $tree rowattrib $topIndex type directory
        $self SetNodeStatus $topIndex empty
        $tree rowattrib $topIndex leftfull $leftDir             
        $tree set {} leftname   [file tail $leftDir]
        $tree set {} rightfull  $rightDir
        $tree rowattrib $topIndex rightfull $rightDir            
        $tree set {} rightname  [file tail $rightDir]

        $self UpdateDirNode {}
        $self UpdateDirNode $topIndex
    }

    # Format a time stamp for display
    proc FormatDate {date} {
        clock format $date -format "%Y-%m-%d %H:%M:%S"
    }

    # Remove all equal nodes from tree
    method PruneEqual {} {
        set todo [$tree children {}]
        set todo [$tree childkeys root]
        while {[llength $todo] > 0} {
            set todoNow $todo
            set todo {}
            foreach node $todoNow {
                set status [$tree set $node status]
                set status [$tree rowattrib $node status]
                if {$status eq "equal"} {
                    $tree delete $node
                } else {
                    lappend todo {*}[$tree children $node]
                    lappend todo {*}[$tree childkeys $node]
                }
            }
        }
    }

    # Open or close all directories in the tree view
    method OpenAll {{state 1}} {
        if {$state} {
        set todo [$tree children {}]
            $tree expandall
        while {[llength $todo] > 0} {
            set todoNow $todo
            set todo {}
        } else {
            foreach node $todoNow {
                set children [$tree children $node]
            $tree collapseall
                if {[llength $children] > 0} {
                    $tree item $node -open $state
                    lappend todo {*}$children
                }
            }
        }
    }

    # Copy a file from one directory to the other
    method CopyFile {node from} {
        global dirdiff Pref

        set lf [$tree set $node leftfull]
        set rf [$tree set $node rightfull]
        set lf [$tree rowattrib $node leftfull]
        set rf [$tree rowattrib $node rightfull]
        set parent [$tree parent $node]
        set lp [$tree set $parent leftfull]
        set rp [$tree set $parent rightfull]
        set lp [$tree rowattrib $parent leftfull]
        set rp [$tree rowattrib $parent rightfull]

        if {$from eq "left"} {
            set src $lf
            if {$rf ne ""} {
                set dst $rf
            } elseif {$rp ne ""} {
                set dst [file join $rp [file tail $src]]
447
448
449
450
451
452
453
454
455



456
457
458
459



460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477



478
479
480
481
482
483
484
485
486
487
488
489
490
491


492
493
494
495



496
497
498
499



500
501
502
503
504
505
506

507
508
509

510
511
512
513
514
515
516
445
446
447
448
449
450
451


452
453
454
455



456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473



474
475
476
477
478
479
480
481
482
483
484
485
486
487
488


489
490
491



492
493
494
495



496
497
498
499
500
501
502
503
504

505
506
507

508
509
510
511
512
513
514
515







-
-
+
+
+

-
-
-
+
+
+















-
-
-
+
+
+












-
-
+
+

-
-
-
+
+
+

-
-
-
+
+
+






-
+


-
+







                # FIXA: update file info in tree too
                $self SetNodeStatus $node equal
            }
        }
    }

    # React on double-click
    method DoubleClick {x y} {
        set node [$tree identify row $x $y]
    method DoubleClick {W x y} {
        foreach {W x y} [tablelist::convEventFields $W $x $y] break
        set node [$tree index @$x,$y]

        set lf [$tree set $node leftfull]
        set rf [$tree set $node rightfull]
        set type [$tree set $node type]
        set lf [$tree rowattrib $node leftfull]
        set rf [$tree rowattrib $node rightfull]
        set type [$tree rowattrib $node type]

        # On a file that exists on both sides, start a file diff
        if {$type eq "file" && $lf ne "" && $rf ne ""} {
            set PauseBgProcessing 1
            newDiff $lf $rf
            set PauseBgProcessing 0
            # Stop the default bindings from running
            return -code break
        }
    }
    # React on Return key
    method KeyReturn {} {
        set node [$tree focus]
        if {$node eq ""} return

        set lf [$tree set $node leftfull]
        set rf [$tree set $node rightfull]
        set type [$tree set $node type]
        set lf [$tree rowattrib $node leftfull]
        set rf [$tree rowattrib $node rightfull]
        set type [$tree rowattrib $node type]

        # On a file that exists on both sides, start a file diff
        if {$type eq "file" && $lf ne "" && $rf ne ""} {
            set PauseBgProcessing 1
            newDiff $lf $rf
            set PauseBgProcessing 0
            # Stop the default bindings from running
            return -code break
        }
    }

    # Bring up a context menu on a file.
    method ContextMenu {x y X Y} {
        #global dirdiff Pref
    method ContextMenu {W x y X Y} {
        foreach {W x y} [tablelist::convEventFields $W $x $y] break

        set node [$tree identify row $x $y]
        set col [$tree identify column $x $y]
        set colname [$tree column $col -id]
        set node [$tree index @$x,$y]
        set col [$tree columnindex @$x,$y]
        set colname [$tree columncget $col -name]

        set lf [$tree set $node leftfull]
        set rf [$tree set $node rightfull]
        set type [$tree set $node type]
        set lf [$tree rowattrib $node leftfull]
        set rf [$tree rowattrib $node rightfull]
        set type [$tree rowattrib $node type]
        set oneside [expr {($lf ne "") ^ ($rf ne "")}]

        set m $win.popup
        destroy $m
        menu $m
        
        if {$col eq "#0"} {
        if {$colname eq "structure"} {
            $m add command -label "Prune equal" -command [mymethod PruneEqual]
            $m add command -label "Expand all" -command [mymethod OpenAll]
            $m add command -label "Collaps all" -command [mymethod OpenAll 0]
            $m add command -label "Collapse all" -command [mymethod OpenAll 0]
        }

        if {$type eq "file" && $lf ne "" && $rf ne ""} {
            # Files, both exist
            $m add command -label "Compare Files" -command [list \
                    newDiff $lf $rf]
        }
580
581
582
583
584
585
586
587

588
589
590
591
592
593
594
579
580
581
582
583
584
585

586
587
588
589
590
591
592
593







-
+







        set pre [clock clicks -milliseconds]
        set errors {}
        while {[llength $IdleQueue] > 0} {
            set node [lindex $IdleQueue 0]
            set IdleQueue [lrange $IdleQueue 1 end]
            unset IdleQueueArr($node)

            if {[$tree set $node type] ne "directory"} {
            if {[$tree rowattrib $node type] ne "directory"} {
                set sts [catch {$self UpdateFileNode $node} err]
            } else {
                set sts [catch {$self UpdateDirNode $node} err]
            }
            if {$sts} {
                lappend errors $err
            }
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
694
695
696
697
698
699
700
701
702
703
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
694
695







-
-
+
+














+
-
-
+
+
+



-
-
+
+


-
-
+
+



-
-
+
+



-



+



-




-
+


-
+



-
+

-
-
+
+




-
-
+
+






-
-
-
-
-
-
-
-







                set statusvar ""
                set AfterId ""
                return
            }
        }

        if {[llength $IdleQueue] > 0} {
            set leftfull [$tree set $node leftfull]
            set rightfull [$tree set $node rightfull]
            set leftfull [$tree rowattrib $node leftfull]
            set rightfull [$tree rowattrib $node rightfull]
            if {$leftfull ne ""} {
                set statusvar $leftfull
            } else {
                set statusvar $rightfull
            }

            set AfterId [after 1 [mymethod UpdateIdle]]
        } else {
            set statusvar ""
            set AfterId ""
        }
    }

    method SetNodeStatus {node status} {
        variable color
        $tree set $node status $status
        $tree item $node -tags $status
        $tree rowattrib $node status $status
        $tree rowconfigure $node -foreground $color($status) \
                -selectforeground $color($status)
        #puts "Set [$tree item $node -text] to $status"

        # Loop through children to update parent
        set parent [$tree parent $node]
        if {$parent eq ""} { return }
        set parent [$tree parentkey $node]
        if {$parent eq "" || $parent eq "root"} { return }

        # If this is only present on one side, there is no need to update
        set lf [$tree set $parent leftfull]
        set rf [$tree set $parent rightfull]
        set lf [$tree rowattrib $parent leftfull]
        set rf [$tree rowattrib $parent rightfull]
        if {$lf eq "" || $rf eq ""} { return }

        set pstatus equal
        foreach child [$tree children $parent] {
            set status [$tree set $child status]
        foreach child [$tree childkeys $parent] {
            set status [$tree rowattrib $child status]
            switch $status {
                unknown {
                    set pstatus unknown
                    break
                }
                new - old - change {
                    set pstatus change
                    break
                }
            }
        }
        #puts "Setting parent [$tree set $parent leftname] to $pstatus"
        $self SetNodeStatus $parent $pstatus
    }

    method UpdateDirNode {node} {
        if {[$tree set $node type] ne "directory"} {
        if {[$tree rowattrib $node type] ne "directory"} {
            return
        }
        if {[$tree set $node status] ne "empty"} {
        if {[$tree rowattrib $node status] ne "empty"} {
            #puts "Dir [$tree set $node leftfull] already done"
            return
        }
        $tree delete [$tree children $node]
        $tree delete [$tree childkeys $node]

        set leftfull [$tree set $node leftfull]
        set rightfull [$tree set $node rightfull]
        set leftfull [$tree rowattrib $node leftfull]
        set rightfull [$tree rowattrib $node rightfull]
        $self CompareDirs $leftfull $rightfull $node
    }

    method UpdateFileNode {node} {
        set leftfull [$tree set $node leftfull]
        set rightfull [$tree set $node rightfull]
        set leftfull [$tree rowattrib $node leftfull]
        set rightfull [$tree rowattrib $node rightfull]
        set equal [CompareFiles $leftfull $rightfull]
        if {$equal} {
            $self SetNodeStatus $node equal
        } else {
            $self SetNodeStatus $node change
        }
            
        #$self CompareDirs $leftfull $rightfull $node

        #$self SetNodeStatus $node unknown
        #$tree set $node leftfull
        #$tree set $node leftname
        #$tree set $node rightfull
        #$tree set $node rightname
    }

    # List files under a directory node
    # Returns status for the new node
    method ListFiles {df1 df2 node} {
        if {$df1 ne ""} {
            set type [file type $df1]
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735



736
737
738
739
740
741



742
743
744






745
746

747
748


749
750
751
752
753
754
755
756
757
758
759
760
761
762

763
764
765
766
767
768
769
709
710
711
712
713
714
715












716
717
718
719





720
721
722
723


724
725
726
727
728
729
730
731
732


733
734
735
736
737
738
739
740
741
742
743
744
745
746
747

748
749
750
751
752
753
754
755







-
-
-
-
-
-
-
-
-
-
-
-
+
+
+

-
-
-
-
-
+
+
+

-
-
+
+
+
+
+
+


+
-
-
+
+













-
+







            set size2 ""
            set time2 ""
        } else {
            set size2 $stat2(size)
            set time2 [FormatDate $stat2(mtime)]
        }
        if {$type eq "directory"} {
            # If a directory is present in only one side, make sure it shows
            # up in that side's listing
            set showleft ""
            set showright ""
            if {$df1 eq ""} {
                set showright $name/
            } elseif {$df2 eq ""} {
                set showleft $name/
            } 
            set values [list $type unknown \
                    $df1 $showleft "" "" \
                    $df2 $showright "" ""]
            set values [list $name \
                    "" "" \
                    "" ""]
        } else {
            set name1 [file tail $df1]
            set name2 [file tail $df2]
            set values [list $type unknown \
                    $df1 $name1 $size1 $time1 \
                    $df2 $name2 $size2 $time2]
            set values [list $name \
                    $size1 $time1 \
                    $size2 $time2]
        }
        set id [$tree insert $node end -text $name \
                -values $values]
        set id [$tree insertchild $node end $values]
        $tree rowattrib $id type $type
        $tree rowattrib $id status unknown
        $tree rowattrib $id leftfull $df1
        $tree rowattrib $id rightfull $df2

        if {$type eq "directory"} {
            ## Make it so that this node is openable
            $tree collapse $id
            $tree insert $id 0 -text dummy ;# a dummy
            $tree item $id -text $name/
            #$tree insertchild $id end dummy ;# a dummy
            $tree cellconfigure $id,structure -text $name/
            $self SetNodeStatus $id empty
            $self AddNodeToIdle $id
        } elseif {$size1 == $size2 && \
                $time1 == $time2} {
            $self SetNodeStatus $id equal
        } elseif {$size1 == ""} {
            $self SetNodeStatus $id new
        } elseif {$size2 == ""} {
            $self SetNodeStatus $id old
        } else {
            $self SetNodeStatus $id unknown
            $self AddNodeToIdle $id
        }
        return [$tree set $id status]
        return [$tree rowattrib $id status]
    }

    # Compare two directories.
    method CompareDirs {dir1 dir2 node} {
        global Pref
        if {$dir1 eq ""} {
            set files1 {}