Slightly older version of master from https://github.com/j6t/gitk

Merge branch 'ti/support-sha256'

* ti/support-sha256:
gitk: Add support of SHA256 repositories

+58 -25
+58 -25
gitk
··· 479 479 480 480 proc parseviewrevs {view revs} { 481 481 global vposids vnegids 482 + global hashlength 482 483 483 484 if {$revs eq {}} { 484 485 set revs HEAD ··· 492 493 set badrev {} 493 494 for {set l 0} {$l < [llength $errlines]} {incr l} { 494 495 set line [lindex $errlines $l] 495 - if {!([string length $line] == 40 && [string is xdigit $line])} { 496 + if {!([string length $line] == $hashlength && [string is xdigit $line])} { 496 497 if {[string match "fatal:*" $line]} { 497 498 if {[string match "fatal: ambiguous argument*" $line] 498 499 && $badrev ne {}} { ··· 698 699 global hasworktree 699 700 global varcid vposids vnegids vflags vrevs 700 701 global show_notes 702 + global hashlength 701 703 702 704 set hasworktree [hasworktree] 703 705 rereadrefs ··· 731 733 # take out positive refs that we asked for before or 732 734 # that we have already seen 733 735 foreach rev $revs { 734 - if {[string length $rev] == 40} { 736 + if {[string length $rev] == $hashlength} { 735 737 if {[lsearch -exact $oldpos $rev] < 0 736 738 && ![info exists varcid($view,$rev)]} { 737 739 lappend newrevs $rev ··· 1614 1616 global parents children curview hlview 1615 1617 global idpending ordertok 1616 1618 global varccommits varcid varctok vtokmod vfilelimit vshortids 1619 + global hashlength 1617 1620 1618 1621 set stuff [read $fd 500000] 1619 1622 # git log doesn't terminate the last commit with a null... ··· 1696 1699 } 1697 1700 set ok 1 1698 1701 foreach id $ids { 1699 - if {[string length $id] != 40} { 1702 + if {[string length $id] != $hashlength} { 1700 1703 set ok 0 1701 1704 break 1702 1705 } ··· 1942 1945 return 1 1943 1946 } 1944 1947 1945 - # Expand an abbreviated commit ID to a list of full 40-char IDs that match 1946 - # and are present in the current view. 1948 + # Expand an abbreviated commit ID to a list of full 40-char (or 64-char 1949 + # for SHA256 repo) IDs that match and are present in the current view. 1947 1950 # This is fairly slow... 1948 1951 proc longid {prefix} { 1949 1952 global varcid curview vshortids ··· 1976 1979 global selecthead selectheadid 1977 1980 global hideremotes 1978 1981 global tclencoding 1982 + global hashlength 1979 1983 1980 1984 foreach v {tagids idtags headids idheads otherrefids idotherrefs} { 1981 1985 unset -nocomplain $v ··· 1985 1989 fconfigure $refd -encoding $tclencoding 1986 1990 } 1987 1991 while {[gets $refd line] >= 0} { 1988 - if {[string index $line 40] ne " "} continue 1989 - set id [string range $line 0 39] 1990 - set ref [string range $line 41 end] 1992 + if {[string index $line $hashlength] ne " "} continue 1993 + set id [string range $line 0 [expr {$hashlength - 1}]] 1994 + set ref [string range $line [expr {$hashlength + 1}] end] 1991 1995 if {![string match "refs/*" $ref]} continue 1992 1996 set name [string range $ref 5 end] 1993 1997 if {[string match "remotes/*" $name]} { ··· 2282 2286 global have_tk85 have_tk86 use_ttk NS 2283 2287 global git_version 2284 2288 global worddiff 2289 + global hashlength 2285 2290 2286 2291 # The "mc" arguments here are purely so that xgettext 2287 2292 # sees the following string as needing to be translated ··· 2407 2412 -command gotocommit -width 8 2408 2413 $sha1but conf -disabledforeground [$sha1but cget -foreground] 2409 2414 pack .tf.bar.sha1label -side left 2410 - ${NS}::entry $sha1entry -width 40 -font textfont -textvariable sha1string 2415 + ${NS}::entry $sha1entry -width $hashlength -font textfont -textvariable sha1string 2411 2416 trace add variable sha1string write sha1change 2412 2417 pack $sha1entry -side left -pady 2 2413 2418 ··· 4132 4137 4133 4138 proc read_line_source {fd inst} { 4134 4139 global blamestuff curview commfd blameinst nullid nullid2 4140 + global hashlength 4135 4141 4136 4142 while {[gets $fd line] >= 0} { 4137 4143 lappend blamestuff($inst) $line ··· 4152 4158 set line [split [lindex $blamestuff($inst) 0] " "] 4153 4159 set id [lindex $line 0] 4154 4160 set lnum [lindex $line 1] 4155 - if {[string length $id] == 40 && [string is xdigit $id] && 4161 + if {[string length $id] == $hashlength && [string is xdigit $id] && 4156 4162 [string is digit -strict $lnum]} { 4157 4163 # look for "filename" line 4158 4164 foreach l $blamestuff($inst) { ··· 5296 5302 # Graph layout functions 5297 5303 5298 5304 proc shortids {ids} { 5305 + global hashlength 5306 + 5299 5307 set res {} 5300 5308 foreach id $ids { 5301 5309 if {[llength $id] > 1} { 5302 5310 lappend res [shortids $id] 5303 - } elseif {[regexp {^[0-9a-f]{40}$} $id]} { 5311 + } elseif {[regexp [string map "@@ $hashlength" {^[0-9a-f]{@@}$}] $id]} { 5304 5312 lappend res [string range $id 0 7] 5305 5313 } else { 5306 5314 lappend res $id ··· 5475 5483 # git rev-list should give us just 1 line to use as viewmainheadid($view) 5476 5484 proc getviewhead {fd inst view} { 5477 5485 global viewmainheadid commfd curview viewinstances showlocalchanges 5486 + global hashlength 5478 5487 5479 5488 set id {} 5480 5489 if {[gets $fd line] < 0} { 5481 5490 if {![eof $fd]} { 5482 5491 return 1 5483 5492 } 5484 - } elseif {[string length $line] == 40 && [string is xdigit $line]} { 5493 + } elseif {[string length $line] == $hashlength && [string is xdigit $line]} { 5485 5494 set id $line 5486 5495 } 5487 5496 set viewmainheadid($view) $id ··· 7245 7254 # Also look for URLs of the form "http[s]://..." and make them web links. 7246 7255 proc appendwithlinks {text tags} { 7247 7256 global ctext linknum curview 7257 + global hashlength 7248 7258 7249 7259 set start [$ctext index "end - 1c"] 7250 7260 $ctext insert end $text $tags 7251 - set links [regexp -indices -all -inline {(?:\m|-g)[0-9a-f]{6,40}\M} $text] 7261 + set links [regexp -indices -all -inline [string map "@@ $hashlength" {(?:\m|-g)[0-9a-f]{6,@@}\M}] $text] 7252 7262 foreach l $links { 7253 7263 set s [lindex $l 0] 7254 7264 set e [lindex $l 1] ··· 7276 7286 proc setlink {id lk} { 7277 7287 global curview ctext pendinglinks 7278 7288 global linkfgcolor 7289 + global hashlength 7279 7290 7280 7291 if {[string range $id 0 1] eq "-g"} { 7281 7292 set id [string range $id 2 end] 7282 7293 } 7283 7294 7284 7295 set known 0 7285 - if {[string length $id] < 40} { 7296 + if {[string length $id] < $hashlength} { 7286 7297 set matches [longid $id] 7287 7298 if {[llength $matches] > 0} { 7288 7299 if {[llength $matches] > 1} return ··· 8927 8938 8928 8939 proc clearsha1 {} { 8929 8940 global sha1entry sha1string 8930 - if {[string length $sha1string] == 40} { 8941 + global hashlength 8942 + 8943 + if {[string length $sha1string] == $hashlength} { 8931 8944 $sha1entry delete 0 end 8932 8945 } 8933 8946 } 8934 8947 8935 8948 proc sha1change {n1 n2 op} { 8936 8949 global sha1string currentid sha1but 8950 + 8937 8951 if {$sha1string == {} 8938 8952 || ([info exists currentid] && $sha1string == $currentid)} { 8939 8953 set state disabled ··· 8950 8964 8951 8965 proc gotocommit {} { 8952 8966 global sha1string tagids headids curview varcid 8967 + global hashlength 8953 8968 8954 8969 if {$sha1string == {} 8955 8970 || ([info exists currentid] && $sha1string == $currentid)} return ··· 8959 8974 set id $headids($sha1string) 8960 8975 } else { 8961 8976 set id [string tolower $sha1string] 8962 - if {[regexp {^[0-9a-f]{4,39}$} $id]} { 8977 + if {[regexp {^[0-9a-f]{4,63}$} $id]} { 8963 8978 set matches [longid $id] 8964 8979 if {$matches ne {}} { 8965 8980 if {[llength $matches] > 1} { ··· 9446 9461 9447 9462 proc mkpatch {} { 9448 9463 global rowmenuid currentid commitinfo patchtop patchnum NS 9464 + global hashlength 9449 9465 9450 9466 if {![info exists currentid]} return 9451 9467 set oldid $currentid ··· 9460 9476 ${NS}::label $top.title -text [mc "Generate patch"] 9461 9477 grid $top.title - -pady 10 9462 9478 ${NS}::label $top.from -text [mc "From:"] 9463 - ${NS}::entry $top.fromsha1 -width 40 9479 + ${NS}::entry $top.fromsha1 -width $hashlength 9464 9480 $top.fromsha1 insert 0 $oldid 9465 9481 $top.fromsha1 conf -state readonly 9466 9482 grid $top.from $top.fromsha1 -sticky w ··· 9469 9485 $top.fromhead conf -state readonly 9470 9486 grid x $top.fromhead -sticky w 9471 9487 ${NS}::label $top.to -text [mc "To:"] 9472 - ${NS}::entry $top.tosha1 -width 40 9488 + ${NS}::entry $top.tosha1 -width $hashlength 9473 9489 $top.tosha1 insert 0 $newid 9474 9490 $top.tosha1 conf -state readonly 9475 9491 grid $top.to $top.tosha1 -sticky w ··· 9535 9551 9536 9552 proc mktag {} { 9537 9553 global rowmenuid mktagtop commitinfo NS 9554 + global hashlength 9538 9555 9539 9556 set top .maketag 9540 9557 set mktagtop $top ··· 9544 9561 ${NS}::label $top.title -text [mc "Create tag"] 9545 9562 grid $top.title - -pady 10 9546 9563 ${NS}::label $top.id -text [mc "ID:"] 9547 - ${NS}::entry $top.sha1 -width 40 9564 + ${NS}::entry $top.sha1 -width $hashlength 9548 9565 $top.sha1 insert 0 $rowmenuid 9549 9566 $top.sha1 conf -state readonly 9550 9567 grid $top.id $top.sha1 -sticky w ··· 9652 9669 9653 9670 proc copyreference {} { 9654 9671 global rowmenuid autosellen 9672 + global hashlength 9655 9673 9656 9674 set format "%h (\"%s\", %ad)" 9657 9675 set cmd [list git show -s --pretty=format:$format --date=short] 9658 - if {$autosellen < 40} { 9676 + if {$autosellen < $hashlength} { 9659 9677 lappend cmd --abbrev=$autosellen 9660 9678 } 9661 9679 set reference [safe_exec [concat $cmd $rowmenuid]] ··· 9666 9684 9667 9685 proc writecommit {} { 9668 9686 global rowmenuid wrcomtop commitinfo wrcomcmd NS 9687 + global hashlength 9669 9688 9670 9689 set top .writecommit 9671 9690 set wrcomtop $top ··· 9675 9694 ${NS}::label $top.title -text [mc "Write commit to file"] 9676 9695 grid $top.title - -pady 10 9677 9696 ${NS}::label $top.id -text [mc "ID:"] 9678 - ${NS}::entry $top.sha1 -width 40 9697 + ${NS}::entry $top.sha1 -width $hashlength 9679 9698 $top.sha1 insert 0 $rowmenuid 9680 9699 $top.sha1 conf -state readonly 9681 9700 grid $top.id $top.sha1 -sticky w ··· 9755 9774 9756 9775 proc branchdia {top valvar uivar} { 9757 9776 global NS commitinfo 9777 + global hashlength 9758 9778 upvar $valvar val $uivar ui 9759 9779 9760 9780 catch {destroy $top} ··· 9763 9783 ${NS}::label $top.title -text $ui(title) 9764 9784 grid $top.title - -pady 10 9765 9785 ${NS}::label $top.id -text [mc "ID:"] 9766 - ${NS}::entry $top.sha1 -width 40 9786 + ${NS}::entry $top.sha1 -width $hashlength 9767 9787 $top.sha1 insert 0 $val(id) 9768 9788 $top.sha1 conf -state readonly 9769 9789 grid $top.id $top.sha1 -sticky w ··· 9773 9793 grid x $top.head -sticky ew 9774 9794 grid columnconfigure $top 1 -weight 1 9775 9795 ${NS}::label $top.nlab -text [mc "Name:"] 9776 - ${NS}::entry $top.name -width 40 9796 + ${NS}::entry $top.name -width $hashlength 9777 9797 $top.name insert 0 $val(name) 9778 9798 grid $top.nlab $top.name -sticky w 9779 9799 ${NS}::frame $top.buts ··· 11761 11781 global tabstop wrapcomment wrapdefault limitdiffs 11762 11782 global autocopy autoselect autosellen extdifftool perfile_attrs 11763 11783 global hideremotes want_ttk have_ttk maxrefs web_browser 11784 + global hashlength 11764 11785 11765 11786 set page [create_prefs_page $notebook.general] 11766 11787 ··· 11789 11810 -variable autoselect 11790 11811 grid x $page.autoselect -sticky w 11791 11812 } 11792 - spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen 11813 + 11814 + spinbox $page.autosellen -from 1 -to $hashlength -width 4 -textvariable autosellen 11793 11815 ${NS}::label $page.autosellenl -text [mc "Length of commit ID to copy"] 11794 11816 grid x $page.autosellenl $page.autosellen -sticky w 11795 11817 ··· 12568 12590 } 12569 12591 } 12570 12592 12593 + # Use object format as hash algorightm (either "sha1" or "sha256") 12594 + set hashalgorithm [exec git rev-parse --show-object-format] 12595 + if {$hashalgorithm eq "sha1"} { 12596 + set hashlength 40 12597 + } elseif {$hashalgorithm eq "sha256"} { 12598 + set hashlength 64 12599 + } else { 12600 + puts stderr "Unknown hash algorithm: $hashalgorithm" 12601 + exit 1 12602 + } 12603 + 12571 12604 set log_showroot true 12572 12605 catch { 12573 12606 set log_showroot [exec git config --bool --get log.showroot] ··· 12609 12642 set datetimeformat "%Y-%m-%d %H:%M:%S" 12610 12643 set autocopy 0 12611 12644 set autoselect 1 12612 - set autosellen 40 12645 + set autosellen $hashlength 12613 12646 set perfile_attrs 0 12614 12647 set want_ttk 1 12615 12648