@@ -425,6 +425,7 @@ proc parseviewargs {n arglist} {
proc parseviewrevs {view revs} {
global vposids vnegids
+ global hashlength
if {$revs eq {}} {
set revs HEAD
@@ -438,7 +439,7 @@ proc parseviewrevs {view revs} {
set badrev {}
for {set l 0} {$l < [llength $errlines]} {incr l} {
set line [lindex $errlines $l]
- if {!([string length $line] == 40 && [string is xdigit $line])} {
+ if {!([string length $line] == $hashlength && [string is xdigit $line])} {
if {[string match "fatal:*" $line]} {
if {[string match "fatal: ambiguous argument*" $line]
&& $badrev ne {}} {
@@ -655,6 +656,7 @@ proc updatecommits {} {
global hasworktree
global varcid vposids vnegids vflags vrevs
global show_notes
+ global hashlength
set hasworktree [hasworktree]
rereadrefs
@@ -688,7 +690,7 @@ proc updatecommits {} {
# take out positive refs that we asked for before or
# that we have already seen
foreach rev $revs {
- if {[string length $rev] == 40} {
+ if {[string length $rev] == $hashlength} {
if {[lsearch -exact $oldpos $rev] < 0
&& ![info exists varcid($view,$rev)]} {
lappend newrevs $rev
@@ -1573,6 +1575,7 @@ proc getcommitlines {fd inst view updating} {
global parents children curview hlview
global idpending ordertok
global varccommits varcid varctok vtokmod vfilelimit vshortids
+ global hashlength
set stuff [read $fd 500000]
# git log doesn't terminate the last commit with a null...
@@ -1655,7 +1658,7 @@ proc getcommitlines {fd inst view updating} {
}
set ok 1
foreach id $ids {
- if {[string length $id] != 40} {
+ if {[string length $id] != $hashlength} {
set ok 0
break
}
@@ -1935,6 +1938,7 @@ proc readrefs {} {
global selecthead selectheadid
global hideremotes
global tclencoding
+ global hashlength
foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
unset -nocomplain $v
@@ -1944,9 +1948,9 @@ proc readrefs {} {
fconfigure $refd -encoding $tclencoding
}
while {[gets $refd line] >= 0} {
- if {[string index $line 40] ne " "} continue
- set id [string range $line 0 39]
- set ref [string range $line 41 end]
+ if {[string index $line $hashlength] ne " "} continue
+ set id [string range $line 0 [expr {$hashlength - 1}]]
+ set ref [string range $line [expr {$hashlength + 1}] end]
if {![string match "refs/*" $ref]} continue
set name [string range $ref 5 end]
if {[string match "remotes/*" $name]} {
@@ -2241,6 +2245,7 @@ proc makewindow {} {
global have_tk85 have_tk86 use_ttk NS
global git_version
global worddiff
+ global hashlength
# The "mc" arguments here are purely so that xgettext
# sees the following string as needing to be translated
@@ -2366,7 +2371,7 @@ proc makewindow {} {
-command gotocommit -width 8
$sha1but conf -disabledforeground [$sha1but cget -foreground]
pack .tf.bar.sha1label -side left
- ${NS}::entry $sha1entry -width 40 -font textfont -textvariable sha1string
+ ${NS}::entry $sha1entry -width $hashlength -font textfont -textvariable sha1string
trace add variable sha1string write sha1change
pack $sha1entry -side left -pady 2
@@ -4093,6 +4098,7 @@ proc stopblaming {} {
proc read_line_source {fd inst} {
global blamestuff curview commfd blameinst nullid nullid2
+ global hashlength
while {[gets $fd line] >= 0} {
lappend blamestuff($inst) $line
@@ -4113,7 +4119,7 @@ proc read_line_source {fd inst} {
set line [split [lindex $blamestuff($inst) 0] " "]
set id [lindex $line 0]
set lnum [lindex $line 1]
- if {[string length $id] == 40 && [string is xdigit $id] &&
+ if {[string length $id] == $hashlength && [string is xdigit $id] &&
[string is digit -strict $lnum]} {
# look for "filename" line
foreach l $blamestuff($inst) {
@@ -5436,13 +5442,14 @@ proc get_viewmainhead {view} {
# git rev-list should give us just 1 line to use as viewmainheadid($view)
proc getviewhead {fd inst view} {
global viewmainheadid commfd curview viewinstances showlocalchanges
+ global hashlength
set id {}
if {[gets $fd line] < 0} {
if {![eof $fd]} {
return 1
}
- } elseif {[string length $line] == 40 && [string is xdigit $line]} {
+ } elseif {[string length $line] == $hashlength && [string is xdigit $line]} {
set id $line
}
set viewmainheadid($view) $id
@@ -7206,10 +7213,11 @@ proc commit_descriptor {p} {
# Also look for URLs of the form "http[s]://..." and make them web links.
proc appendwithlinks {text tags} {
global ctext linknum curview
+ global hashlength
set start [$ctext index "end - 1c"]
$ctext insert end $text $tags
- set links [regexp -indices -all -inline {(?:\m|-g)[0-9a-f]{6,40}\M} $text]
+ set links [regexp -indices -all -inline [string map "@@ $hashlength" {(?:\m|-g)[0-9a-f]{6,@@}\M}] $text]
foreach l $links {
set s [lindex $l 0]
set e [lindex $l 1]
@@ -8888,13 +8896,16 @@ proc incrfont {inc} {
proc clearsha1 {} {
global sha1entry sha1string
- if {[string length $sha1string] == 40} {
+ global hashlength
+
+ if {[string length $sha1string] == $hashlength} {
$sha1entry delete 0 end
}
}
proc sha1change {n1 n2 op} {
global sha1string currentid sha1but
+
if {$sha1string == {}
|| ([info exists currentid] && $sha1string == $currentid)} {
set state disabled
@@ -8911,6 +8922,7 @@ proc sha1change {n1 n2 op} {
proc gotocommit {} {
global sha1string tagids headids curview varcid
+ global hashlength
if {$sha1string == {}
|| ([info exists currentid] && $sha1string == $currentid)} return
@@ -8920,11 +8932,11 @@ proc gotocommit {} {
set id $headids($sha1string)
} else {
set id [string tolower $sha1string]
- if {[regexp {^[0-9a-f]{4,39}$} $id]} {
+ if {[regexp {^[0-9a-f]{4,63}$} $id]} {
set matches [longid $id]
if {$matches ne {}} {
if {[llength $matches] > 1} {
- error_popup [mc "Short commit ID %s is ambiguous" $id]
+ error_popup [mc "Short commit id %s is ambiguous" $id]
return
}
set id [lindex $matches 0]
@@ -9618,10 +9630,11 @@ proc mktaggo {} {
proc copyreference {} {
global rowmenuid autosellen
+ global hashlength
set format "%h (\"%s\", %ad)"
set cmd [list git show -s --pretty=format:$format --date=short]
- if {$autosellen < 40} {
+ if {$autosellen < $hashlength} {
lappend cmd --abbrev=$autosellen
}
set reference [eval exec $cmd $rowmenuid]
@@ -9632,6 +9645,7 @@ proc copyreference {} {
proc writecommit {} {
global rowmenuid wrcomtop commitinfo wrcomcmd NS
+ global hashlength
set top .writecommit
set wrcomtop $top
@@ -9641,7 +9655,7 @@ proc writecommit {} {
${NS}::label $top.title -text [mc "Write commit to file"]
grid $top.title - -pady 10
${NS}::label $top.id -text [mc "ID:"]
- ${NS}::entry $top.sha1 -width 40
+ ${NS}::entry $top.sha1 -width $hashlength
$top.sha1 insert 0 $rowmenuid
$top.sha1 conf -state readonly
grid $top.id $top.sha1 -sticky w
@@ -9721,6 +9735,7 @@ proc mvbranch {} {
proc branchdia {top valvar uivar} {
global NS commitinfo
+ global hashlength
upvar $valvar val $uivar ui
catch {destroy $top}
@@ -9729,7 +9744,7 @@ proc branchdia {top valvar uivar} {
${NS}::label $top.title -text $ui(title)
grid $top.title - -pady 10
${NS}::label $top.id -text [mc "ID:"]
- ${NS}::entry $top.sha1 -width 40
+ ${NS}::entry $top.sha1 -width $hashlength
$top.sha1 insert 0 $val(id)
$top.sha1 conf -state readonly
grid $top.id $top.sha1 -sticky w
@@ -12524,6 +12539,18 @@ if {$tclencoding == {}} {
puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
}
+set objformat [exec git rev-parse --show-object-format]
+if {$objformat eq "sha1"} {
+ set hashlength 40
+} elseif {$objformat eq "sha256"} {
+ set hashlength 64
+} else {
+ error_popup "[mc "Not supported hash algorithm:"] {$objformat}"
+ exit 1
+}
+set hashalgorithm [string toupper $objformat]
+unset objformat
+
set gui_encoding [encoding system]
catch {
set enc [exec git config --get gui.encoding]