@@ -425,6 +425,7 @@ proc parseviewargs {n arglist} {
425425
426426proc parseviewrevs {view revs} {
427427 global vposids vnegids
428+ global hashlength
428429
429430 if {$revs eq {}} {
430431 set revs HEAD
@@ -438,7 +439,7 @@ proc parseviewrevs {view revs} {
438439 set badrev {}
439440 for {set l 0} {$l < [ llength $errlines ] } {incr l} {
440441 set line [ lindex $errlines $l ]
441- if {!([ string length $line ] == 40 && [ string is xdigit $line ] )} {
442+ if {!([ string length $line ] == $hashlength && [ string is xdigit $line ] )} {
442443 if {[ string match " fatal:*" $line ] } {
443444 if {[ string match " fatal: ambiguous argument*" $line ]
444445 && $badrev ne {}} {
@@ -655,6 +656,7 @@ proc updatecommits {} {
655656 global hasworktree
656657 global varcid vposids vnegids vflags vrevs
657658 global show_notes
659+ global hashlength
658660
659661 set hasworktree [ hasworktree]
660662 rereadrefs
@@ -688,7 +690,7 @@ proc updatecommits {} {
688690 # take out positive refs that we asked for before or
689691 # that we have already seen
690692 foreach rev $revs {
691- if {[ string length $rev ] == 40 } {
693+ if {[ string length $rev ] == $hashlength } {
692694 if {[ lsearch -exact $oldpos $rev ] < 0
693695 && ![ info exists varcid($view ,$rev )] } {
694696 lappend newrevs $rev
@@ -1573,6 +1575,7 @@ proc getcommitlines {fd inst view updating} {
15731575 global parents children curview hlview
15741576 global idpending ordertok
15751577 global varccommits varcid varctok vtokmod vfilelimit vshortids
1578+ global hashlength
15761579
15771580 set stuff [ read $fd 500000]
15781581 # git log doesn't terminate the last commit with a null...
@@ -1655,7 +1658,7 @@ proc getcommitlines {fd inst view updating} {
16551658 }
16561659 set ok 1
16571660 foreach id $ids {
1658- if {[ string length $id ] != 40 } {
1661+ if {[ string length $id ] != $hashlength } {
16591662 set ok 0
16601663 break
16611664 }
@@ -1901,8 +1904,8 @@ proc getcommit {id} {
19011904 return 1
19021905}
19031906
1904- # Expand an abbreviated commit ID to a list of full 40-char IDs that match
1905- # and are present in the current view.
1907+ # Expand an abbreviated commit ID to a list of full 40-char (or 64-char
1908+ # for SHA256 repo) IDs that match and are present in the current view.
19061909# This is fairly slow...
19071910proc longid {prefix} {
19081911 global varcid curview vshortids
@@ -1935,6 +1938,7 @@ proc readrefs {} {
19351938 global selecthead selectheadid
19361939 global hideremotes
19371940 global tclencoding
1941+ global hashlength
19381942
19391943 foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
19401944 unset -nocomplain $v
@@ -1944,9 +1948,9 @@ proc readrefs {} {
19441948 fconfigure $refd -encoding $tclencoding
19451949 }
19461950 while {[ gets $refd line] >= 0} {
1947- if {[ string index $line 40 ] ne " " } continue
1948- set id [ string range $line 0 39 ]
1949- set ref [ string range $line 41 end]
1951+ if {[ string index $line $hashlength ] ne " " } continue
1952+ set id [ string range $line 0 [ expr { $hashlength - 1} ] ]
1953+ set ref [ string range $line [ expr { $hashlength + 1} ] end]
19501954 if {![ string match " refs/*" $ref ] } continue
19511955 set name [ string range $ref 5 end]
19521956 if {[ string match " remotes/*" $name ] } {
@@ -2241,6 +2245,7 @@ proc makewindow {} {
22412245 global have_tk85 have_tk86 use_ttk NS
22422246 global git_version
22432247 global worddiff
2248+ global hashlength
22442249
22452250 # The " mc" arguments here are purely so that xgettext
22462251 # sees the following string as needing to be translated
@@ -2366,7 +2371,7 @@ proc makewindow {} {
23662371 -command gotocommit -width 8
23672372 $sha1but conf -disabledforeground [ $sha1but cget -foreground]
23682373 pack .tf.bar.sha1label -side left
2369- ${NS} ::entry $sha1entry -width 40 -font textfont -textvariable sha1string
2374+ ${NS} ::entry $sha1entry -width $hashlength -font textfont -textvariable sha1string
23702375 trace add variable sha1string write sha1change
23712376 pack $sha1entry -side left -pady 2
23722377
@@ -4093,6 +4098,7 @@ proc stopblaming {} {
40934098
40944099proc read_line_source {fd inst} {
40954100 global blamestuff curview commfd blameinst nullid nullid2
4101+ global hashlength
40964102
40974103 while {[ gets $fd line] >= 0} {
40984104 lappend blamestuff($inst ) $line
@@ -4113,7 +4119,7 @@ proc read_line_source {fd inst} {
41134119 set line [ split [lindex $blamestuff($inst) 0] " " ]
41144120 set id [ lindex $line 0]
41154121 set lnum [ lindex $line 1]
4116- if {[ string length $id ] == 40 && [ string is xdigit $id ] &&
4122+ if {[ string length $id ] == $hashlength && [ string is xdigit $id ] &&
41174123 [ string is digit -strict $lnum ] } {
41184124 # look for " filename" line
41194125 foreach l $blamestuff($inst) {
@@ -5257,11 +5263,13 @@ proc askrelhighlight {row id} {
52575263# Graph layout functions
52585264
52595265proc shortids {ids} {
5266+ global hashlength
5267+
52605268 set res {}
52615269 foreach id $ids {
52625270 if {[ llength $id ] > 1} {
52635271 lappend res [ shortids $id ]
5264- } elseif {[ regexp {^[0-9a-f]{40 }$} $id ] } {
5272+ } elseif {[ regexp [string map "@@ $hashlength " {^[0-9a-f]{@@ }$}] $id ]} {
52655273 lappend res [ string range $id 0 7]
52665274 } else {
52675275 lappend res $id
@@ -5436,13 +5444,14 @@ proc get_viewmainhead {view} {
54365444# git rev-list should give us just 1 line to use as viewmainheadid($view )
54375445proc getviewhead {fd inst view} {
54385446 global viewmainheadid commfd curview viewinstances showlocalchanges
5447+ global hashlength
54395448
54405449 set id {}
54415450 if {[ gets $fd line] < 0} {
54425451 if {![ eof $fd ] } {
54435452 return 1
54445453 }
5445- } elseif {[ string length $line ] == 40 && [ string is xdigit $line ] } {
5454+ } elseif {[ string length $line ] == $hashlength && [ string is xdigit $line ] } {
54465455 set id $line
54475456 }
54485457 set viewmainheadid($view ) $id
@@ -7206,10 +7215,11 @@ proc commit_descriptor {p} {
72067215# Also look for URLs of the form " http[s]://..." and make them web links.
72077216proc appendwithlinks {text tags} {
72087217 global ctext linknum curview
7218+ global hashlength
72097219
72107220 set start [ $ctext index " end - 1c" ]
72117221 $ctext insert end $text $tags
7212- set links [ regexp -indices -all -inline {(?:\m|-g)[0-9a-f]{6,40 }\M} $text ]
7222+ set links [ regexp -indices -all -inline [string map "@@ $hashlength " {(?:\m|-g)[0-9a-f]{6,@@ }\M}] $text ]
72137223 foreach l $links {
72147224 set s [ lindex $l 0]
72157225 set e [ lindex $l 1]
@@ -7237,13 +7247,14 @@ proc appendwithlinks {text tags} {
72377247proc setlink {id lk} {
72387248 global curview ctext pendinglinks
72397249 global linkfgcolor
7250+ global hashlength
72407251
72417252 if {[ string range $id 0 1] eq " -g" } {
72427253 set id [ string range $id 2 end]
72437254 }
72447255
72457256 set known 0
7246- if {[ string length $id ] < 40 } {
7257+ if {[ string length $id ] < $hashlength } {
72477258 set matches [ longid $id ]
72487259 if {[ llength $matches ] > 0} {
72497260 if {[ llength $matches ] > 1} return
@@ -8888,13 +8899,16 @@ proc incrfont {inc} {
88888899
88898900proc clearsha1 {} {
88908901 global sha1entry sha1string
8891- if {[ string length $sha1string ] == 40} {
8902+ global hashlength
8903+
8904+ if {[ string length $sha1string ] == $hashlength } {
88928905 $sha1entry delete 0 end
88938906 }
88948907}
88958908
88968909proc sha1change {n1 n2 op} {
88978910 global sha1string currentid sha1but
8911+
88988912 if {$sha1string == {}
88998913 || ([ info exists currentid] && $sha1string == $currentid )} {
89008914 set state disabled
@@ -8911,6 +8925,7 @@ proc sha1change {n1 n2 op} {
89118925
89128926proc gotocommit {} {
89138927 global sha1string tagids headids curview varcid
8928+ global hashlength
89148929
89158930 if {$sha1string == {}
89168931 || ([ info exists currentid] && $sha1string == $currentid )} return
@@ -8920,7 +8935,7 @@ proc gotocommit {} {
89208935 set id $headids($sha1string)
89218936 } else {
89228937 set id [ string tolower $sha1string ]
8923- if {[ regexp {^[0-9a-f]{4,39 }$} $id ] } {
8938+ if {[ regexp {^[0-9a-f]{4,63 }$} $id ] } {
89248939 set matches [ longid $id ]
89258940 if {$matches ne {}} {
89268941 if {[ llength $matches ] > 1} {
@@ -9409,6 +9424,7 @@ proc doseldiff {oldid newid} {
94099424
94109425proc mkpatch {} {
94119426 global rowmenuid currentid commitinfo patchtop patchnum NS
9427+ global hashlength
94129428
94139429 if {![ info exists currentid] } return
94149430 set oldid $currentid
@@ -9423,7 +9439,7 @@ proc mkpatch {} {
94239439 ${NS} ::label $top .title -text [ mc " Generate patch" ]
94249440 grid $top .title - -pady 10
94259441 ${NS} ::label $top .from -text [ mc " From:" ]
9426- ${NS} ::entry $top .fromsha1 -width 40
9442+ ${NS} ::entry $top .fromsha1 -width $hashlength
94279443 $top .fromsha1 insert 0 $oldid
94289444 $top .fromsha1 conf -state readonly
94299445 grid $top .from $top .fromsha1 -sticky w
@@ -9432,7 +9448,7 @@ proc mkpatch {} {
94329448 $top .fromhead conf -state readonly
94339449 grid x $top .fromhead -sticky w
94349450 ${NS} ::label $top .to -text [ mc " To:" ]
9435- ${NS} ::entry $top .tosha1 -width 40
9451+ ${NS} ::entry $top .tosha1 -width $hashlength
94369452 $top .tosha1 insert 0 $newid
94379453 $top .tosha1 conf -state readonly
94389454 grid $top .to $top .tosha1 -sticky w
@@ -9501,6 +9517,7 @@ proc mkpatchcan {} {
95019517
95029518proc mktag {} {
95039519 global rowmenuid mktagtop commitinfo NS
9520+ global hashlength
95049521
95059522 set top .maketag
95069523 set mktagtop $top
@@ -9510,7 +9527,7 @@ proc mktag {} {
95109527 ${NS} ::label $top .title -text [ mc " Create tag" ]
95119528 grid $top .title - -pady 10
95129529 ${NS} ::label $top .id -text [ mc " ID:" ]
9513- ${NS} ::entry $top .sha1 -width 40
9530+ ${NS} ::entry $top .sha1 -width $hashlength
95149531 $top .sha1 insert 0 $rowmenuid
95159532 $top .sha1 conf -state readonly
95169533 grid $top .id $top .sha1 -sticky w
@@ -9618,10 +9635,11 @@ proc mktaggo {} {
96189635
96199636proc copyreference {} {
96209637 global rowmenuid autosellen
9638+ global hashlength
96219639
96229640 set format " %h (\" %s\" , %ad)"
96239641 set cmd [ list git show -s --pretty=format:$format --date=short]
9624- if {$autosellen < 40 } {
9642+ if {$autosellen < $hashlength } {
96259643 lappend cmd --abbrev=$autosellen
96269644 }
96279645 set reference [ eval exec $cmd $rowmenuid ]
@@ -9632,6 +9650,7 @@ proc copyreference {} {
96329650
96339651proc writecommit {} {
96349652 global rowmenuid wrcomtop commitinfo wrcomcmd NS
9653+ global hashlength
96359654
96369655 set top .writecommit
96379656 set wrcomtop $top
@@ -9641,7 +9660,7 @@ proc writecommit {} {
96419660 ${NS} ::label $top .title -text [ mc " Write commit to file" ]
96429661 grid $top .title - -pady 10
96439662 ${NS} ::label $top .id -text [ mc " ID:" ]
9644- ${NS} ::entry $top .sha1 -width 40
9663+ ${NS} ::entry $top .sha1 -width $hashlength
96459664 $top .sha1 insert 0 $rowmenuid
96469665 $top .sha1 conf -state readonly
96479666 grid $top .id $top .sha1 -sticky w
@@ -9721,6 +9740,7 @@ proc mvbranch {} {
97219740
97229741proc branchdia {top valvar uivar} {
97239742 global NS commitinfo
9743+ global hashlength
97249744 upvar $valvar val $uivar ui
97259745
97269746 catch {destroy $top }
@@ -9729,7 +9749,7 @@ proc branchdia {top valvar uivar} {
97299749 ${NS} ::label $top .title -text $ui(title)
97309750 grid $top .title - -pady 10
97319751 ${NS} ::label $top .id -text [ mc " ID:" ]
9732- ${NS} ::entry $top .sha1 -width 40
9752+ ${NS} ::entry $top .sha1 -width $hashlength
97339753 $top .sha1 insert 0 $val(id)
97349754 $top .sha1 conf -state readonly
97359755 grid $top .id $top .sha1 -sticky w
@@ -9739,7 +9759,7 @@ proc branchdia {top valvar uivar} {
97399759 grid x $top .head -sticky ew
97409760 grid columnconfigure $top 1 -weight 1
97419761 ${NS} ::label $top .nlab -text [ mc " Name:" ]
9742- ${NS} ::entry $top .name -width 40
9762+ ${NS} ::entry $top .name -width $hashlength
97439763 $top .name insert 0 $val(name)
97449764 grid $top .nlab $top .name -sticky w
97459765 ${NS} ::frame $top .buts
@@ -11728,6 +11748,7 @@ proc prefspage_general {notebook} {
1172811748 global tabstop wrapcomment wrapdefault limitdiffs
1172911749 global autocopy autoselect autosellen extdifftool perfile_attrs
1173011750 global hideremotes want_ttk have_ttk maxrefs web_browser
11751+ global hashlength
1173111752
1173211753 set page [ create_prefs_page $notebook .general]
1173311754
@@ -11756,7 +11777,8 @@ proc prefspage_general {notebook} {
1175611777 -variable autoselect
1175711778 grid x $page .autoselect -sticky w
1175811779 }
11759- spinbox $page .autosellen -from 1 -to 40 -width 4 -textvariable autosellen
11780+
11781+ spinbox $page .autosellen -from 1 -to $hashlength -width 4 -textvariable autosellen
1176011782 ${NS} ::label $page .autosellenl -text [ mc " Length of commit ID to copy" ]
1176111783 grid x $page .autosellenl $page .autosellen -sticky w
1176211784
@@ -12537,6 +12559,17 @@ catch {
1253712559 }
1253812560}
1253912561
12562+ # Use object format as hash algorightm (either " sha1" or " sha256" )
12563+ set hashalgorithm [ exec git rev-parse --show-object-format]
12564+ if {$hashalgorithm eq " sha1" } {
12565+ set hashlength 40
12566+ } elseif {$hashalgorithm eq " sha256" } {
12567+ set hashlength 64
12568+ } else {
12569+ puts stderr " Unknown hash algorithm: $hashalgorithm "
12570+ exit 1
12571+ }
12572+
1254012573set log_showroot true
1254112574catch {
1254212575 set log_showroot [ exec git config --bool --get log.showroot]
@@ -12578,7 +12611,7 @@ set limitdiffs 1
1257812611set datetimeformat " %Y-%m-%d %H:%M:%S"
1257912612set autocopy 0
1258012613set autoselect 1
12581- set autosellen 40
12614+ set autosellen $hashlength
1258212615set perfile_attrs 0
1258312616set want_ttk 1
1258412617
0 commit comments