contrib/hgk
changeset 3097 fe9b13e35e46
parent 3093 edefbb3a3b08
child 3940 a33ddd20105c
equal deleted inserted replaced
2981:1b738357bba9 3097:fe9b13e35e46
    28     set commits {}
    28     set commits {}
    29     set phase getcommits
    29     set phase getcommits
    30     set startmsecs [clock clicks -milliseconds]
    30     set startmsecs [clock clicks -milliseconds]
    31     set nextupdate [expr $startmsecs + 100]
    31     set nextupdate [expr $startmsecs + 100]
    32     set ncmupdate 1
    32     set ncmupdate 1
       
    33     set limit 0
       
    34     set revargs {}
       
    35     for {set i 0} {$i < [llength $rargs]} {incr i} {
       
    36 	set opt [lindex $rargs $i]
       
    37 	if {$opt == "--limit"} {
       
    38 	    incr i
       
    39 	    set limit [lindex $rargs $i]
       
    40 	} else {
       
    41 	    lappend revargs $opt
       
    42 	}
       
    43     }
    33     if [catch {
    44     if [catch {
    34 	set parse_args [concat --default HEAD $rargs]
    45 	set parse_args [concat --default HEAD $revargs]
    35 	set parsed_args [split [eval exec hg debug-rev-parse $parse_args] "\n"]
    46 	set parsed_args [split [eval exec hg debug-rev-parse $parse_args] "\n"]
    36     }] {
    47     } err] {
    37 	# if git-rev-parse failed for some reason...
    48 	# if git-rev-parse failed for some reason...
    38 	if {$rargs == {}} {
    49 	if {$rargs == {}} {
    39 	    set rargs HEAD
    50 	    set revargs HEAD
    40 	}
    51 	}
    41 	set parsed_args $rargs
    52 	set parsed_args $revargs
       
    53     }
       
    54     if {$limit > 0} {
       
    55 	set parsed_args [concat -n $limit $parsed_args]
    42     }
    56     }
    43     if [catch {
    57     if [catch {
    44 	set commfd [open "|hg debug-rev-list --header --topo-order --parents $parsed_args" r]
    58 	set commfd [open "|hg debug-rev-list --header --topo-order --parents $parsed_args" r]
    45     } err] {
    59     } err] {
    46 	puts stderr "Error executing hg debug-rev-list: $err"
    60 	puts stderr "Error executing hg debug-rev-list: $err"
    98 	set ok 0
   112 	set ok 0
    99 	if {$j >= 0} {
   113 	if {$j >= 0} {
   100 	    set ids [string range $cmit 0 [expr {$j - 1}]]
   114 	    set ids [string range $cmit 0 [expr {$j - 1}]]
   101 	    set ok 1
   115 	    set ok 1
   102 	    foreach id $ids {
   116 	    foreach id $ids {
   103 		if {![regexp {^[0-9a-f]{40}$} $id]} {
   117 		if {![regexp {^[0-9a-f]{12}$} $id]} {
   104 		    set ok 0
   118 		    set ok 0
   105 		    break
   119 		    break
   106 		}
   120 		}
   107 	    }
   121 	    }
   108 	}
   122 	}
   174     set headline {}
   188     set headline {}
   175     set auname {}
   189     set auname {}
   176     set audate {}
   190     set audate {}
   177     set comname {}
   191     set comname {}
   178     set comdate {}
   192     set comdate {}
       
   193     set rev {}
   179     if {![info exists nchildren($id)]} {
   194     if {![info exists nchildren($id)]} {
   180 	set children($id) {}
   195 	set children($id) {}
   181 	set nchildren($id) 0
   196 	set nchildren($id) 0
   182 	set ncleft($id) 0
   197 	set ncleft($id) 0
   183     }
   198     }
   207 		    set auname [join [lrange $line 1 [expr {$x - 1}]]]
   222 		    set auname [join [lrange $line 1 [expr {$x - 1}]]]
   208 		} elseif {$tag == "committer"} {
   223 		} elseif {$tag == "committer"} {
   209 		    set x [expr {[llength $line] - 2}]
   224 		    set x [expr {[llength $line] - 2}]
   210 		    set comdate [lindex $line $x]
   225 		    set comdate [lindex $line $x]
   211 		    set comname [join [lrange $line 1 [expr {$x - 1}]]]
   226 		    set comname [join [lrange $line 1 [expr {$x - 1}]]]
       
   227 		} elseif {$tag == "revision"} {
       
   228 		    set rev [lindex $line 1]
   212 		}
   229 		}
   213 	    }
   230 	    }
   214 	} else {
   231 	} else {
   215 	    if {$comment == {}} {
   232 	    if {$comment == {}} {
   216 		set headline [string trim $line]
   233 		set headline [string trim $line]
   231     if {$comdate != {}} {
   248     if {$comdate != {}} {
   232 	set cdate($id) $comdate
   249 	set cdate($id) $comdate
   233 	set comdate [clock format $comdate -format "%Y-%m-%d %H:%M:%S"]
   250 	set comdate [clock format $comdate -format "%Y-%m-%d %H:%M:%S"]
   234     }
   251     }
   235     set commitinfo($id) [list $headline $auname $audate \
   252     set commitinfo($id) [list $headline $auname $audate \
   236 			     $comname $comdate $comment]
   253 			     $comname $comdate $comment $rev]
   237 }
   254 }
   238 
   255 
   239 proc readrefs {} {
   256 proc readrefs {} {
   240     global tagids idtags headids idheads tagcontents
   257     global tagids idtags headids idheads tagcontents
   241 
   258 
   259     set files [glob -nocomplain -types f [file join $git $base *]]
   276     set files [glob -nocomplain -types f [file join $git $base *]]
   260     foreach f $files {
   277     foreach f $files {
   261 	catch {
   278 	catch {
   262 	    set fd [open $f r]
   279 	    set fd [open $f r]
   263 	    set line [read $fd 40]
   280 	    set line [read $fd 40]
   264 	    if {[regexp {^[0-9a-f]{40}} $line id]} {
   281 	    if {[regexp {^[0-9a-f]{12}} $line id]} {
   265 		set name "$dname[file tail $f]"
   282 		set name "$dname[file tail $f]"
   266 		set otherrefids($name) $id
   283 		set otherrefids($name) $id
   267 		lappend idotherrefs($id) $name
   284 		lappend idotherrefs($id) $name
   268 	    }
   285 	    }
   269 	    close $fd
   286 	    close $fd
  1741 		bell
  1758 		bell
  1742 	    }
  1759 	    }
  1743 	}
  1760 	}
  1744 	return
  1761 	return
  1745     }
  1762     }
  1746     if {![regexp {^[0-9a-f]{40}} $line id]} {
  1763     if {![regexp {^[0-9a-f]{12}} $line id]} {
  1747 	error_popup "Can't parse git-diff-tree output: $line"
  1764 	error_popup "Can't parse git-diff-tree output: $line"
  1748 	stopfindproc
  1765 	stopfindproc
  1749 	return
  1766 	return
  1750     }
  1767     }
  1751     if {![info exists idline($id)]} {
  1768     if {![info exists idline($id)]} {
  1854 		error_popup "Couldn't find diffs for {$ids}"
  1871 		error_popup "Couldn't find diffs for {$ids}"
  1855 	    }
  1872 	    }
  1856 	}
  1873 	}
  1857 	return
  1874 	return
  1858     }
  1875     }
  1859     if {[regexp {^([0-9a-f]{40}) \(from ([0-9a-f]{40})\)} $line match id p]} {
  1876     if {[regexp {^([0-9a-f]{12}) \(from ([0-9a-f]{12})\)} $line match id p]} {
  1860 	# start of a new string of diffs
  1877 	# start of a new string of diffs
  1861 	donefilediff
  1878 	donefilediff
  1862 	set fdiffids [list $id $p]
  1879 	set fdiffids [list $id $p]
  1863 	set fdiffs {}
  1880 	set fdiffs {}
  1864     } elseif {[string match ":*" $line]} {
  1881     } elseif {[string match ":*" $line]} {
  2000 proc commit_descriptor {p} {
  2017 proc commit_descriptor {p} {
  2001     global commitinfo
  2018     global commitinfo
  2002     set l "..."
  2019     set l "..."
  2003     if {[info exists commitinfo($p)]} {
  2020     if {[info exists commitinfo($p)]} {
  2004 	set l [lindex $commitinfo($p) 0]
  2021 	set l [lindex $commitinfo($p) 0]
  2005     }
  2022 	set r [lindex $commitinfo($p) 6]
  2006     return "$p ($l)"
  2023     }
       
  2024     return "$r:$p ($l)"
  2007 }
  2025 }
  2008 
  2026 
  2009 # append some text to the ctext widget, and make any SHA1 ID
  2027 # append some text to the ctext widget, and make any SHA1 ID
  2010 # that we know about be a clickable link.
  2028 # that we know about be a clickable link.
  2011 proc appendwithlinks {text} {
  2029 proc appendwithlinks {text} {
  2012     global ctext idline linknum
  2030     global ctext idline linknum
  2013 
  2031 
  2014     set start [$ctext index "end - 1c"]
  2032     set start [$ctext index "end - 1c"]
  2015     $ctext insert end $text
  2033     $ctext insert end $text
  2016     $ctext insert end "\n"
  2034     $ctext insert end "\n"
  2017     set links [regexp -indices -all -inline {[0-9a-f]{40}} $text]
  2035     set links [regexp -indices -all -inline {[0-9a-f]{12}} $text]
  2018     foreach l $links {
  2036     foreach l $links {
  2019 	set s [lindex $l 0]
  2037 	set s [lindex $l 0]
  2020 	set e [lindex $l 1]
  2038 	set e [lindex $l 1]
  2021 	set linkid [string range $text $s $e]
  2039 	set linkid [string range $text $s $e]
  2022 	if {![info exists idline($linkid)]} continue
  2040 	if {![info exists idline($linkid)]} continue
  2105     $ctext delete 0.0 end
  2123     $ctext delete 0.0 end
  2106     set linknum 0
  2124     set linknum 0
  2107     $ctext mark set fmark.0 0.0
  2125     $ctext mark set fmark.0 0.0
  2108     $ctext mark gravity fmark.0 left
  2126     $ctext mark gravity fmark.0 left
  2109     set info $commitinfo($id)
  2127     set info $commitinfo($id)
       
  2128     $ctext insert end "Revision: [lindex $info 6]\n"
  2110     $ctext insert end "Author: [lindex $info 1]  [lindex $info 2]\n"
  2129     $ctext insert end "Author: [lindex $info 1]  [lindex $info 2]\n"
  2111     $ctext insert end "Committer: [lindex $info 3]  [lindex $info 4]\n"
  2130     $ctext insert end "Committer: [lindex $info 3]  [lindex $info 4]\n"
  2112     if {[info exists idtags($id)]} {
  2131     if {[info exists idtags($id)]} {
  2113 	$ctext insert end "Tags:"
  2132 	$ctext insert end "Tags:"
  2114 	foreach tag $idtags($id) {
  2133 	foreach tag $idtags($id) {