Eskil

Check-in [0f4aef3537]
Login

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

Overview
Comment:Support branches in Subversion. [b71c8cf01b]
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0f4aef35372b04d88833cc9ccc68b62326191a02
User & Date: peter 2012-02-21 15:49:46.014
Context
2012-02-28
18:19
Corrected SVN branch detection check-in: 3d26b61b4d user: peter tags: trunk
2012-02-21
15:49
Support branches in Subversion. [b71c8cf01b] check-in: 0f4aef3537 user: peter tags: trunk
2012-02-20
22:02
Examples adjustments. check-in: e894b4ef77 user: peter tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to Changes.



1
2
3
4
5
6
7



2012-02-19
 Support regsub preprocessing controlled per side.

2012-02-18
 Improved PDF print dialog.

2012-02-17
>
>
>







1
2
3
4
5
6
7
8
9
10
2012-02-21
 Support branches in Subversion. [b71c8cf01b]

2012-02-19
 Support regsub preprocessing controlled per side.

2012-02-18
 Improved PDF print dialog.

2012-02-17
Changes to src/rev.tcl.
232
233
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
        set old [pwd]
        set outfile [file join [pwd] $outfile]
        cd $dir
        set filename [file tail $filename]
    }

    set cmd [list exec svn cat]




    if {$rev != ""} {
        lappend cmd -r $rev
    }
    lappend cmd [file nativename $filename] > $outfile


    if {[catch {eval $cmd} res]} {
        if {![string match "*Checking out*" $res]} {
            tk_messageBox -icon error -title "SVN error" -message $res
        }
    }

    if {$old != ""} {
        cd $old
    }
}

# Get a SVN patch
proc eskil::rev::SVN::getPatch {revs {files {}}} {
    set cmd [list exec svn diff]
    foreach rev $revs {





        lappend cmd -r $rev

    }
    lappend cmd {*}$files

    if {[catch {eval $cmd} res]} {
        tk_messageBox -icon error -title "SVN error" -message $res
        return ""
    }







>
>
>
>
|
|
|
|
>
>















>
>
>
>
>
|
>







232
233
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
        set old [pwd]
        set outfile [file join [pwd] $outfile]
        cd $dir
        set filename [file tail $filename]
    }

    set cmd [list exec svn cat]
    if {[string match "*://*" $rev]} {
        # Full URL
        lappend cmd $rev
    } else {
        if {$rev != ""} {
            lappend cmd -r $rev
        }
        lappend cmd [file nativename $filename]
    }
    lappend cmd > $outfile
    if {[catch {eval $cmd} res]} {
        if {![string match "*Checking out*" $res]} {
            tk_messageBox -icon error -title "SVN error" -message $res
        }
    }

    if {$old != ""} {
        cd $old
    }
}

# Get a SVN patch
proc eskil::rev::SVN::getPatch {revs {files {}}} {
    set cmd [list exec svn diff]
    foreach rev $revs {
        # TODO: What happens in strange combinations ?
        if {[string match "*://*" $rev]} {
            # Full URL
            lappend cmd $rev
        } else {
            lappend cmd -r $rev
        }
    }
    lappend cmd {*}$files

    if {[catch {eval $cmd} res]} {
        tk_messageBox -icon error -title "SVN error" -message $res
        return ""
    }
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
    if {$old != ""} {
        cd $old
    }
    return $rev
}

# Return current revision of a SVN file
proc eskil::rev::SVN::GetCurrent {filename} {
    set old ""
    if {$filename eq ""} {
        set cmd [list exec svn info]
    } else {
        set dir [file dirname $filename]
        if {$dir != "."} {
            set old [pwd]
            cd $dir
            set filename [file tail $filename]
        }

        set cmd [list exec svn info [file nativename $filename]]
    }
    if {[catch {eval $cmd} res]} {
        # What to do here?
        set rev "1"

    } else {
        if {![regexp {Last Changed Rev:\s+(\d+)} $res -> rev]} {
            set rev "1"
        }
    }

    if {$old != ""} {
        cd $old
    }



    return $rev
}

# Return revision list of a SVN file
proc eskil::rev::SVN::GetRevList {filename} {
    if {$filename eq ""} {
        set cmd [list exec svn log -q -l 50]



    } else {
        set cmd [list exec svn log -q -l 50 [file nativename $filename]]
    }
    if {[catch {eval $cmd} res]} {
        # What to do here?
        set revs [list 1]
    } else {







|
















>









>
>
>







>
>
>







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
    if {$old != ""} {
        cd $old
    }
    return $rev
}

# Return current revision of a SVN file
proc eskil::rev::SVN::GetCurrent {filename {fullInfo 0}} {
    set old ""
    if {$filename eq ""} {
        set cmd [list exec svn info]
    } else {
        set dir [file dirname $filename]
        if {$dir != "."} {
            set old [pwd]
            cd $dir
            set filename [file tail $filename]
        }

        set cmd [list exec svn info [file nativename $filename]]
    }
    if {[catch {eval $cmd} res]} {
        # What to do here?
        set rev "1"
        set res ""
    } else {
        if {![regexp {Last Changed Rev:\s+(\d+)} $res -> rev]} {
            set rev "1"
        }
    }

    if {$old != ""} {
        cd $old
    }
    if {$fullInfo} {
        return $res
    }
    return $rev
}

# Return revision list of a SVN file
proc eskil::rev::SVN::GetRevList {filename} {
    if {$filename eq ""} {
        set cmd [list exec svn log -q -l 50]
    } elseif {[string match "*://*" $filename]} {
        # Full URL
        set cmd [list exec svn log -q -l 50 $filename]
    } else {
        set cmd [list exec svn log -q -l 50 [file nativename $filename]]
    }
    if {[catch {eval $cmd} res]} {
        # What to do here?
        set revs [list 1]
    } else {
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
            if {$tail < 1} {set tail 1}
            set rev $head$tail
        }
        lappend result $rev
    }
    return $result
}













































# Figure out SVN revision from arguments
proc eskil::rev::SVN::ParseRevs {filename revs} {
    set result {}
    foreach rev $revs {




        # A negative integer rev is a relative rev









        if {[string is integer -strict $rev] && $rev < 0} {

            # Save a roundtrip to the server in the case where we
            # can start from current
            if {$rev == -1} {
                set curr [eskil::rev::SVN::GetCurrent $filename]
                set rev [expr {$curr + $rev}]
            } else {
                # Get a list from the log
                if {$filename eq ""} {
                    set filename "."
                }
                set cmd [list svn log -q [file nativename $filename]]


                set revs [eskil::rev::SVN::GetRevList $filename]

                set rev [lindex $revs [- $rev]]
                if {$rev eq ""} {
                    set rev [lindex $revs end]
                }
            }
        }






        lappend result $rev

    }
    return $result
}

# Figure out ClearCase revision from arguments
proc eskil::rev::CT::ParseRevs {filename revs} {
    if {$filename eq ""} {








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




>
>
>
>
|
>
>
>
>
>
>
>
>
>

>


|







|
>
>
|
>






>
>
>
>
>
>
|
>







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
704
705
706
707
708
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
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
            if {$tail < 1} {set tail 1}
            set rev $head$tail
        }
        lappend result $rev
    }
    return $result
}

# Look for alternative version in a branch
# Return value, if any, is a full URL to the file
proc eskil::rev::SVN::LookForBranch {filename rev} {
    set info [eskil::rev::SVN::GetCurrent $filename 1]
    if {![regexp {URL:\s+(.+)} $info -> URL]} {
        return
    }
    if {![regexp {Repository Root:\s+(.+)} $info -> Root]} {
        return
    }
    set tail [string range $URL [string length $Root] end]
    if {![string match "/*" $tail]} {
        return
    }
    set tail [string range $tail 1 end]
    set parts [file split $tail]
    set alt {}
    switch [lindex $parts 0] {
        trunk {
            if {$rev eq "trunk"} { 
                lappend alt [file join [lreplace $parts 0 0 trunk]]
            }
            lappend alt [file join [lreplace $parts 0 0 branches $rev]]
            lappend alt [file join [lreplace $parts 0 0 tags $rev]]
        }
        branches - tags {
            if {$rev eq "trunk"} { 
                lappend alt [file join [lreplace $parts 0 1 trunk]]
            }
            lappend alt [file join [lreplace $parts 0 1 branches $rev]]
            lappend alt [file join [lreplace $parts 0 1 tags $rev]]
        }
    }
    foreach tailAlt $alt {
        set urlAlt $Root/$tailAlt
        if {[catch {exec svn info $urlAlt} res]} {
            continue
        }
        # TODO: How to check Success? enough that svn info worked?
        return $urlAlt
    }
    return
}

# Figure out SVN revision from arguments
proc eskil::rev::SVN::ParseRevs {filename revs} {
    set result {}
    foreach rev $revs {
        set Url ""
        # Non-numeric could be a branch or tag. Look for it.
        if {![string is integer -strict $rev]} {
            if {[regexp {^([^@]+)@(.+)$} $rev -> pre post]} {
                set rev $pre
                set atRev $post
            } else {
                set atRev ""
            }
            set Url [eskil::rev::SVN::LookForBranch $filename $rev]
            if {$Url ne ""} {
                set rev $atRev
            }
        }
        if {[string is integer -strict $rev] && $rev < 0} {
            # A negative integer rev is a relative rev
            # Save a roundtrip to the server in the case where we
            # can start from current
            if {$Url eq "" && $rev == -1} {
                set curr [eskil::rev::SVN::GetCurrent $filename]
                set rev [expr {$curr + $rev}]
            } else {
                # Get a list from the log
                if {$filename eq ""} {
                    set filename "."
                }
                if {$Url ne ""} {
                    set revs [eskil::rev::SVN::GetRevList $Url]
                } else {
                    set revs [eskil::rev::SVN::GetRevList $filename]
                }
                set rev [lindex $revs [- $rev]]
                if {$rev eq ""} {
                    set rev [lindex $revs end]
                }
            }
        }
        if {$Url ne ""} {
            if {$rev ne ""} {
                append Url @$rev
            }
            lappend result $Url
        } else {
            lappend result $rev
        }
    }
    return $result
}

# Figure out ClearCase revision from arguments
proc eskil::rev::CT::ParseRevs {filename revs} {
    if {$filename eq ""} {