Skip to content

Commit cf9d3c1

Browse files
committed
Merge branch 'ti/support-sha256'
* ti/support-sha256: gitk: Add support of SHA256 repositories
2 parents 8e34d8b + 59a3998 commit cf9d3c1

File tree

1 file changed

+58
-25
lines changed

1 file changed

+58
-25
lines changed

gitk

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ proc parseviewargs {n arglist} {
479479
480480
proc parseviewrevs {view revs} {
481481
global vposids vnegids
482+
global hashlength
482483
483484
if {$revs eq {}} {
484485
set revs HEAD
@@ -492,7 +493,7 @@ proc parseviewrevs {view revs} {
492493
set badrev {}
493494
for {set l 0} {$l < [llength $errlines]} {incr l} {
494495
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])} {
496497
if {[string match "fatal:*" $line]} {
497498
if {[string match "fatal: ambiguous argument*" $line]
498499
&& $badrev ne {}} {
@@ -698,6 +699,7 @@ proc updatecommits {} {
698699
global hasworktree
699700
global varcid vposids vnegids vflags vrevs
700701
global show_notes
702+
global hashlength
701703
702704
set hasworktree [hasworktree]
703705
rereadrefs
@@ -731,7 +733,7 @@ proc updatecommits {} {
731733
# take out positive refs that we asked for before or
732734
# that we have already seen
733735
foreach rev $revs {
734-
if {[string length $rev] == 40} {
736+
if {[string length $rev] == $hashlength} {
735737
if {[lsearch -exact $oldpos $rev] < 0
736738
&& ![info exists varcid($view,$rev)]} {
737739
lappend newrevs $rev
@@ -1614,6 +1616,7 @@ proc getcommitlines {fd inst view updating} {
16141616
global parents children curview hlview
16151617
global idpending ordertok
16161618
global varccommits varcid varctok vtokmod vfilelimit vshortids
1619+
global hashlength
16171620
16181621
set stuff [read $fd 500000]
16191622
# git log doesn't terminate the last commit with a null...
@@ -1696,7 +1699,7 @@ proc getcommitlines {fd inst view updating} {
16961699
}
16971700
set ok 1
16981701
foreach id $ids {
1699-
if {[string length $id] != 40} {
1702+
if {[string length $id] != $hashlength} {
17001703
set ok 0
17011704
break
17021705
}
@@ -1942,8 +1945,8 @@ proc getcommit {id} {
19421945
return 1
19431946
}
19441947
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.
19471950
# This is fairly slow...
19481951
proc longid {prefix} {
19491952
global varcid curview vshortids
@@ -1976,6 +1979,7 @@ proc readrefs {} {
19761979
global selecthead selectheadid
19771980
global hideremotes
19781981
global tclencoding
1982+
global hashlength
19791983
19801984
foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
19811985
unset -nocomplain $v
@@ -1985,9 +1989,9 @@ proc readrefs {} {
19851989
fconfigure $refd -encoding $tclencoding
19861990
}
19871991
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]
19911995
if {![string match "refs/*" $ref]} continue
19921996
set name [string range $ref 5 end]
19931997
if {[string match "remotes/*" $name]} {
@@ -2282,6 +2286,7 @@ proc makewindow {} {
22822286
global have_tk85 have_tk86 use_ttk NS
22832287
global git_version
22842288
global worddiff
2289+
global hashlength
22852290
22862291
# The "mc" arguments here are purely so that xgettext
22872292
# sees the following string as needing to be translated
@@ -2407,7 +2412,7 @@ proc makewindow {} {
24072412
-command gotocommit -width 8
24082413
$sha1but conf -disabledforeground [$sha1but cget -foreground]
24092414
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
24112416
trace add variable sha1string write sha1change
24122417
pack $sha1entry -side left -pady 2
24132418
@@ -4132,6 +4137,7 @@ proc stopblaming {} {
41324137
41334138
proc read_line_source {fd inst} {
41344139
global blamestuff curview commfd blameinst nullid nullid2
4140+
global hashlength
41354141
41364142
while {[gets $fd line] >= 0} {
41374143
lappend blamestuff($inst) $line
@@ -4152,7 +4158,7 @@ proc read_line_source {fd inst} {
41524158
set line [split [lindex $blamestuff($inst) 0] " "]
41534159
set id [lindex $line 0]
41544160
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] &&
41564162
[string is digit -strict $lnum]} {
41574163
# look for "filename" line
41584164
foreach l $blamestuff($inst) {
@@ -5296,11 +5302,13 @@ proc askrelhighlight {row id} {
52965302
# Graph layout functions
52975303
52985304
proc shortids {ids} {
5305+
global hashlength
5306+
52995307
set res {}
53005308
foreach id $ids {
53015309
if {[llength $id] > 1} {
53025310
lappend res [shortids $id]
5303-
} elseif {[regexp {^[0-9a-f]{40}$} $id]} {
5311+
} elseif {[regexp [string map "@@ $hashlength" {^[0-9a-f]{@@}$}] $id]} {
53045312
lappend res [string range $id 0 7]
53055313
} else {
53065314
lappend res $id
@@ -5475,13 +5483,14 @@ proc get_viewmainhead {view} {
54755483
# git rev-list should give us just 1 line to use as viewmainheadid($view)
54765484
proc getviewhead {fd inst view} {
54775485
global viewmainheadid commfd curview viewinstances showlocalchanges
5486+
global hashlength
54785487
54795488
set id {}
54805489
if {[gets $fd line] < 0} {
54815490
if {![eof $fd]} {
54825491
return 1
54835492
}
5484-
} elseif {[string length $line] == 40 && [string is xdigit $line]} {
5493+
} elseif {[string length $line] == $hashlength && [string is xdigit $line]} {
54855494
set id $line
54865495
}
54875496
set viewmainheadid($view) $id
@@ -7245,10 +7254,11 @@ proc commit_descriptor {p} {
72457254
# Also look for URLs of the form "http[s]://..." and make them web links.
72467255
proc appendwithlinks {text tags} {
72477256
global ctext linknum curview
7257+
global hashlength
72487258
72497259
set start [$ctext index "end - 1c"]
72507260
$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]
72527262
foreach l $links {
72537263
set s [lindex $l 0]
72547264
set e [lindex $l 1]
@@ -7276,13 +7286,14 @@ proc appendwithlinks {text tags} {
72767286
proc setlink {id lk} {
72777287
global curview ctext pendinglinks
72787288
global linkfgcolor
7289+
global hashlength
72797290
72807291
if {[string range $id 0 1] eq "-g"} {
72817292
set id [string range $id 2 end]
72827293
}
72837294
72847295
set known 0
7285-
if {[string length $id] < 40} {
7296+
if {[string length $id] < $hashlength} {
72867297
set matches [longid $id]
72877298
if {[llength $matches] > 0} {
72887299
if {[llength $matches] > 1} return
@@ -8927,13 +8938,16 @@ proc incrfont {inc} {
89278938
89288939
proc clearsha1 {} {
89298940
global sha1entry sha1string
8930-
if {[string length $sha1string] == 40} {
8941+
global hashlength
8942+
8943+
if {[string length $sha1string] == $hashlength} {
89318944
$sha1entry delete 0 end
89328945
}
89338946
}
89348947
89358948
proc sha1change {n1 n2 op} {
89368949
global sha1string currentid sha1but
8950+
89378951
if {$sha1string == {}
89388952
|| ([info exists currentid] && $sha1string == $currentid)} {
89398953
set state disabled
@@ -8950,6 +8964,7 @@ proc sha1change {n1 n2 op} {
89508964
89518965
proc gotocommit {} {
89528966
global sha1string tagids headids curview varcid
8967+
global hashlength
89538968
89548969
if {$sha1string == {}
89558970
|| ([info exists currentid] && $sha1string == $currentid)} return
@@ -8959,7 +8974,7 @@ proc gotocommit {} {
89598974
set id $headids($sha1string)
89608975
} else {
89618976
set id [string tolower $sha1string]
8962-
if {[regexp {^[0-9a-f]{4,39}$} $id]} {
8977+
if {[regexp {^[0-9a-f]{4,63}$} $id]} {
89638978
set matches [longid $id]
89648979
if {$matches ne {}} {
89658980
if {[llength $matches] > 1} {
@@ -9446,6 +9461,7 @@ proc doseldiff {oldid newid} {
94469461
94479462
proc mkpatch {} {
94489463
global rowmenuid currentid commitinfo patchtop patchnum NS
9464+
global hashlength
94499465
94509466
if {![info exists currentid]} return
94519467
set oldid $currentid
@@ -9460,7 +9476,7 @@ proc mkpatch {} {
94609476
${NS}::label $top.title -text [mc "Generate patch"]
94619477
grid $top.title - -pady 10
94629478
${NS}::label $top.from -text [mc "From:"]
9463-
${NS}::entry $top.fromsha1 -width 40
9479+
${NS}::entry $top.fromsha1 -width $hashlength
94649480
$top.fromsha1 insert 0 $oldid
94659481
$top.fromsha1 conf -state readonly
94669482
grid $top.from $top.fromsha1 -sticky w
@@ -9469,7 +9485,7 @@ proc mkpatch {} {
94699485
$top.fromhead conf -state readonly
94709486
grid x $top.fromhead -sticky w
94719487
${NS}::label $top.to -text [mc "To:"]
9472-
${NS}::entry $top.tosha1 -width 40
9488+
${NS}::entry $top.tosha1 -width $hashlength
94739489
$top.tosha1 insert 0 $newid
94749490
$top.tosha1 conf -state readonly
94759491
grid $top.to $top.tosha1 -sticky w
@@ -9535,6 +9551,7 @@ proc mkpatchcan {} {
95359551
95369552
proc mktag {} {
95379553
global rowmenuid mktagtop commitinfo NS
9554+
global hashlength
95389555
95399556
set top .maketag
95409557
set mktagtop $top
@@ -9544,7 +9561,7 @@ proc mktag {} {
95449561
${NS}::label $top.title -text [mc "Create tag"]
95459562
grid $top.title - -pady 10
95469563
${NS}::label $top.id -text [mc "ID:"]
9547-
${NS}::entry $top.sha1 -width 40
9564+
${NS}::entry $top.sha1 -width $hashlength
95489565
$top.sha1 insert 0 $rowmenuid
95499566
$top.sha1 conf -state readonly
95509567
grid $top.id $top.sha1 -sticky w
@@ -9652,10 +9669,11 @@ proc mktaggo {} {
96529669
96539670
proc copyreference {} {
96549671
global rowmenuid autosellen
9672+
global hashlength
96559673
96569674
set format "%h (\"%s\", %ad)"
96579675
set cmd [list git show -s --pretty=format:$format --date=short]
9658-
if {$autosellen < 40} {
9676+
if {$autosellen < $hashlength} {
96599677
lappend cmd --abbrev=$autosellen
96609678
}
96619679
set reference [safe_exec [concat $cmd $rowmenuid]]
@@ -9666,6 +9684,7 @@ proc copyreference {} {
96669684
96679685
proc writecommit {} {
96689686
global rowmenuid wrcomtop commitinfo wrcomcmd NS
9687+
global hashlength
96699688
96709689
set top .writecommit
96719690
set wrcomtop $top
@@ -9675,7 +9694,7 @@ proc writecommit {} {
96759694
${NS}::label $top.title -text [mc "Write commit to file"]
96769695
grid $top.title - -pady 10
96779696
${NS}::label $top.id -text [mc "ID:"]
9678-
${NS}::entry $top.sha1 -width 40
9697+
${NS}::entry $top.sha1 -width $hashlength
96799698
$top.sha1 insert 0 $rowmenuid
96809699
$top.sha1 conf -state readonly
96819700
grid $top.id $top.sha1 -sticky w
@@ -9755,6 +9774,7 @@ proc mvbranch {} {
97559774
97569775
proc branchdia {top valvar uivar} {
97579776
global NS commitinfo
9777+
global hashlength
97589778
upvar $valvar val $uivar ui
97599779
97609780
catch {destroy $top}
@@ -9763,7 +9783,7 @@ proc branchdia {top valvar uivar} {
97639783
${NS}::label $top.title -text $ui(title)
97649784
grid $top.title - -pady 10
97659785
${NS}::label $top.id -text [mc "ID:"]
9766-
${NS}::entry $top.sha1 -width 40
9786+
${NS}::entry $top.sha1 -width $hashlength
97679787
$top.sha1 insert 0 $val(id)
97689788
$top.sha1 conf -state readonly
97699789
grid $top.id $top.sha1 -sticky w
@@ -9773,7 +9793,7 @@ proc branchdia {top valvar uivar} {
97739793
grid x $top.head -sticky ew
97749794
grid columnconfigure $top 1 -weight 1
97759795
${NS}::label $top.nlab -text [mc "Name:"]
9776-
${NS}::entry $top.name -width 40
9796+
${NS}::entry $top.name -width $hashlength
97779797
$top.name insert 0 $val(name)
97789798
grid $top.nlab $top.name -sticky w
97799799
${NS}::frame $top.buts
@@ -11761,6 +11781,7 @@ proc prefspage_general {notebook} {
1176111781
global tabstop wrapcomment wrapdefault limitdiffs
1176211782
global autocopy autoselect autosellen extdifftool perfile_attrs
1176311783
global hideremotes want_ttk have_ttk maxrefs web_browser
11784+
global hashlength
1176411785
1176511786
set page [create_prefs_page $notebook.general]
1176611787
@@ -11789,7 +11810,8 @@ proc prefspage_general {notebook} {
1178911810
-variable autoselect
1179011811
grid x $page.autoselect -sticky w
1179111812
}
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
1179311815
${NS}::label $page.autosellenl -text [mc "Length of commit ID to copy"]
1179411816
grid x $page.autosellenl $page.autosellen -sticky w
1179511817
@@ -12568,6 +12590,17 @@ catch {
1256812590
}
1256912591
}
1257012592
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+
1257112604
set log_showroot true
1257212605
catch {
1257312606
set log_showroot [exec git config --bool --get log.showroot]
@@ -12609,7 +12642,7 @@ set limitdiffs 1
1260912642
set datetimeformat "%Y-%m-%d %H:%M:%S"
1261012643
set autocopy 0
1261112644
set autoselect 1
12612-
set autosellen 40
12645+
set autosellen $hashlength
1261312646
set perfile_attrs 0
1261412647
set want_ttk 1
1261512648

0 commit comments

Comments
 (0)