{"thread":{"id":"55927","subject":"[PATCH] Add a basic support of SHA256 repositories into Gitk","startedAt":"2021-06-14T16:19:57Z","lastAt":"2022-05-02T14:24:35Z","messageCount":5,"participants":["Rostislav Krasny via GitGitGadget","Junio C Hamano","Ævar Arnfjörð Bjarmason","Felipe Contreras","Rostislav Krasny"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"427363","messageId":"pull.979.git.1623687519832.gitgitgadget@gmail.com","threadId":"55927","inReplyTo":null,"subject":"[PATCH] Add a basic support of SHA256 repositories into Gitk","fromName":"Rostislav Krasny via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2021-06-14T16:18:39Z","receivedAt":"2021-06-14T16:19:57Z","isPatch":true,"sender":{"key":"rosti.bsd@gmail.com","avatar":null},"body":"From: Rostislav Krasny <rosti.bsd@gmail.com>\n\nSigned-off-by: Rostislav Krasny <rosti.bsd@gmail.com>\n---\n    gitk: Add a basic support of SHA256 repositories into Gitk\n    \n    This PR makes Gitk working on both SHA256 and SHA1 repositories without\n    errors/crashes. I made it by changing and testing the gitk script of Git\n    for Windows [https://gitforwindows.org/] version 2.32.0.windows.1 that\n    is a little bit different than the mainstream 2.32.0 version.\n    \n    Still not fixed functionality: [1] There is the \"Auto-select SHA1\n    (length)\" configuration preference that affects \"Copy commit reference\"\n    on both SHA1 and SHA256 repositories.\n    \n    A new \"Auto-select SHA256 (length)\" configuration preference should be\n    added and used on SHA256 repositories instead of the old one. Since I'm\n    not familiar with Tcl/Tk and this issue isn't critical I didn't\n    implement it.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-979%2Frosti-il%2Fgitk-sha256-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-979/rosti-il/gitk-sha256-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/979\n\n gitk-git/gitk | 66 ++++++++++++++++++++++++++++++++++++---------------\n 1 file changed, 47 insertions(+), 19 deletions(-)\n\ndiff --git a/gitk-git/gitk b/gitk-git/gitk\nindex 23d9dd1fe0d0..2da53604cdc8 100755\n--- a/gitk-git/gitk\n+++ b/gitk-git/gitk\n@@ -290,6 +290,7 @@ proc parseviewargs {n arglist} {\n \n proc parseviewrevs {view revs} {\n     global vposids vnegids\n+    global hashlength\n \n     if {$revs eq {}} {\n         set revs HEAD\n@@ -303,7 +304,7 @@ proc parseviewrevs {view revs} {\n         set badrev {}\n         for {set l 0} {$l < [llength $errlines]} {incr l} {\n             set line [lindex $errlines $l]\n-            if {!([string length $line] == 40 && [string is xdigit $line])} {\n+            if {!([string length $line] == $hashlength && [string is xdigit $line])} {\n                 if {[string match \"fatal:*\" $line]} {\n                     if {[string match \"fatal: ambiguous argument*\" $line]\n                         && $badrev ne {}} {\n@@ -507,6 +508,7 @@ proc updatecommits {} {\n     global hasworktree\n     global varcid vposids vnegids vflags vrevs\n     global show_notes\n+    global hashlength\n \n     set hasworktree [hasworktree]\n     rereadrefs\n@@ -540,7 +542,7 @@ proc updatecommits {} {\n             # take out positive refs that we asked for before or\n             # that we have already seen\n             foreach rev $revs {\n-                if {[string length $rev] == 40} {\n+                if {[string length $rev] == $hashlength} {\n                     if {[lsearch -exact $oldpos $rev] < 0\n                         && ![info exists varcid($view,$rev)]} {\n                         lappend newrevs $rev\n@@ -1418,6 +1420,7 @@ proc getcommitlines {fd inst view updating}  {\n     global parents children curview hlview\n     global idpending ordertok\n     global varccommits varcid varctok vtokmod vfilelimit vshortids\n+    global hashlength\n \n     set stuff [read $fd 500000]\n     # git log doesn't terminate the last commit with a null...\n@@ -1500,7 +1503,7 @@ proc getcommitlines {fd inst view updating}  {\n             }\n             set ok 1\n             foreach id $ids {\n-                if {[string length $id] != 40} {\n+                if {[string length $id] != $hashlength} {\n                     set ok 0\n                     break\n                 }\n@@ -1780,6 +1783,7 @@ proc readrefs {} {\n     global selecthead selectheadid\n     global hideremotes\n     global tclencoding\n+    global hashlength\n \n     foreach v {tagids idtags headids idheads otherrefids idotherrefs} {\n         unset -nocomplain $v\n@@ -1789,9 +1793,9 @@ proc readrefs {} {\n         fconfigure $refd -encoding $tclencoding\n     }\n     while {[gets $refd line] >= 0} {\n-        if {[string index $line 40] ne \" \"} continue\n-        set id [string range $line 0 39]\n-        set ref [string range $line 41 end]\n+        if {[string index $line $hashlength] ne \" \"} continue\n+        set id [string range $line 0 [expr {$hashlength - 1}]]\n+        set ref [string range $line [expr {$hashlength + 1}] end]\n         if {![string match \"refs/*\" $ref]} continue\n         set name [string range $ref 5 end]\n         if {[string match \"remotes/*\" $name]} {\n@@ -2082,6 +2086,7 @@ proc makewindow {} {\n     global have_tk85 use_ttk NS\n     global git_version\n     global worddiff\n+    global hashlength hashalgorithm\n \n     # The \"mc\" arguments here are purely so that xgettext\n     # sees the following string as needing to be translated\n@@ -2203,11 +2208,11 @@ proc makewindow {} {\n     set sha1entry .tf.bar.sha1\n     set entries $sha1entry\n     set sha1but .tf.bar.sha1label\n-    button $sha1but -text \"[mc \"SHA1 ID:\"] \" -state disabled -relief flat \\\n+    button $sha1but -text \"[mc \"$hashalgorithm ID:\"] \" -state disabled -relief flat \\\n         -command gotocommit -width 8\n     $sha1but conf -disabledforeground [$sha1but cget -foreground]\n     pack .tf.bar.sha1label -side left\n-    ${NS}::entry $sha1entry -width 40 -font textfont -textvariable sha1string\n+    ${NS}::entry $sha1entry -width $hashlength -font textfont -textvariable sha1string\n     trace add variable sha1string write sha1change\n     pack $sha1entry -side left -pady 2\n \n@@ -3926,6 +3931,7 @@ proc stopblaming {} {\n \n proc read_line_source {fd inst} {\n     global blamestuff curview commfd blameinst nullid nullid2\n+    global hashlength\n \n     while {[gets $fd line] >= 0} {\n         lappend blamestuff($inst) $line\n@@ -3946,7 +3952,7 @@ proc read_line_source {fd inst} {\n     set line [split [lindex $blamestuff($inst) 0] \" \"]\n     set id [lindex $line 0]\n     set lnum [lindex $line 1]\n-    if {[string length $id] == 40 && [string is xdigit $id] &&\n+    if {[string length $id] == $hashlength && [string is xdigit $id] &&\n         [string is digit -strict $lnum]} {\n         # look for \"filename\" line\n         foreach l $blamestuff($inst) {\n@@ -5269,13 +5275,14 @@ proc get_viewmainhead {view} {\n # git rev-list should give us just 1 line to use as viewmainheadid($view)\n proc getviewhead {fd inst view} {\n     global viewmainheadid commfd curview viewinstances showlocalchanges\n+    global hashlength\n \n     set id {}\n     if {[gets $fd line] < 0} {\n         if {![eof $fd]} {\n             return 1\n         }\n-    } elseif {[string length $line] == 40 && [string is xdigit $line]} {\n+    } elseif {[string length $line] == $hashlength && [string is xdigit $line]} {\n         set id $line\n     }\n     set viewmainheadid($view) $id\n@@ -7039,10 +7046,11 @@ proc commit_descriptor {p} {\n # Also look for URLs of the form \"http[s]://...\" and make them web links.\n proc appendwithlinks {text tags} {\n     global ctext linknum curview\n+    global hashlength\n \n     set start [$ctext index \"end - 1c\"]\n     $ctext insert end $text $tags\n-    set links [regexp -indices -all -inline {(?:\\m|-g)[0-9a-f]{6,40}\\M} $text]\n+    set links [regexp -indices -all -inline [string map \"@@ $hashlength\" {(?:\\m|-g)[0-9a-f]{6,@@}\\M}] $text]\n     foreach l $links {\n         set s [lindex $l 0]\n         set e [lindex $l 1]\n@@ -8716,13 +8724,17 @@ proc incrfont {inc} {\n \n proc clearsha1 {} {\n     global sha1entry sha1string\n-    if {[string length $sha1string] == 40} {\n+    global hashlength\n+\n+    if {[string length $sha1string] == $hashlength} {\n         $sha1entry delete 0 end\n     }\n }\n \n proc sha1change {n1 n2 op} {\n     global sha1string currentid sha1but\n+    global hashalgorithm\n+\n     if {$sha1string == {}\n         || ([info exists currentid] && $sha1string == $currentid)} {\n         set state disabled\n@@ -8733,12 +8745,13 @@ proc sha1change {n1 n2 op} {\n     if {$state == \"normal\"} {\n         $sha1but conf -state normal -relief raised -text \"[mc \"Goto:\"] \"\n     } else {\n-        $sha1but conf -state disabled -relief flat -text \"[mc \"SHA1 ID:\"] \"\n+        $sha1but conf -state disabled -relief flat -text \"[mc \"$hashalgorithm ID:\"] \"\n     }\n }\n \n proc gotocommit {} {\n     global sha1string tagids headids curview varcid\n+    global hashlength hashalgorithm\n \n     if {$sha1string == {}\n         || ([info exists currentid] && $sha1string == $currentid)} return\n@@ -8748,11 +8761,11 @@ proc gotocommit {} {\n         set id $headids($sha1string)\n     } else {\n         set id [string tolower $sha1string]\n-        if {[regexp {^[0-9a-f]{4,39}$} $id]} {\n+        if {[regexp [string map \"@@ [expr $hashlength - 1]\" {^[0-9a-f]{4,@@}$}] $id]} {\n             set matches [longid $id]\n             if {$matches ne {}} {\n                 if {[llength $matches] > 1} {\n-                    error_popup [mc \"Short SHA1 id %s is ambiguous\" $id]\n+                    error_popup [mc \"Short $hashalgorithm id %s is ambiguous\" $id]\n                     return\n                 }\n                 set id [lindex $matches 0]\n@@ -8769,7 +8782,7 @@ proc gotocommit {} {\n         return\n     }\n     if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {\n-        set msg [mc \"SHA1 id %s is not known\" $sha1string]\n+        set msg [mc \"$hashalgorithm id %s is not known\" $sha1string]\n     } else {\n         set msg [mc \"Revision %s is not in the current view\" $sha1string]\n     }\n@@ -9446,10 +9459,11 @@ proc mktaggo {} {\n \n proc copyreference {} {\n     global rowmenuid autosellen\n+    global hashlength\n \n     set format \"%h (\\\"%s\\\", %ad)\"\n     set cmd [list git show -s --pretty=format:$format --date=short]\n-    if {$autosellen < 40} {\n+    if {$autosellen < $hashlength} {\n         lappend cmd --abbrev=$autosellen\n     }\n     set reference [eval exec $cmd $rowmenuid]\n@@ -9460,6 +9474,7 @@ proc copyreference {} {\n \n proc writecommit {} {\n     global rowmenuid wrcomtop commitinfo wrcomcmd NS\n+    global hashlength\n \n     set top .writecommit\n     set wrcomtop $top\n@@ -9469,7 +9484,7 @@ proc writecommit {} {\n     ${NS}::label $top.title -text [mc \"Write commit to file\"]\n     grid $top.title - -pady 10\n     ${NS}::label $top.id -text [mc \"ID:\"]\n-    ${NS}::entry $top.sha1 -width 40\n+    ${NS}::entry $top.sha1 -width $hashlength\n     $top.sha1 insert 0 $rowmenuid\n     $top.sha1 conf -state readonly\n     grid $top.id $top.sha1 -sticky w\n@@ -9549,6 +9564,7 @@ proc mvbranch {} {\n \n proc branchdia {top valvar uivar} {\n     global NS commitinfo\n+    global hashlength\n     upvar $valvar val $uivar ui\n \n     catch {destroy $top}\n@@ -9557,7 +9573,7 @@ proc branchdia {top valvar uivar} {\n     ${NS}::label $top.title -text $ui(title)\n     grid $top.title - -pady 10\n     ${NS}::label $top.id -text [mc \"ID:\"]\n-    ${NS}::entry $top.sha1 -width 40\n+    ${NS}::entry $top.sha1 -width $hashlength\n     $top.sha1 insert 0 $val(id)\n     $top.sha1 conf -state readonly\n     grid $top.id $top.sha1 -sticky w\n@@ -12320,6 +12336,18 @@ if {$tclencoding == {}} {\n     puts stderr \"Warning: encoding $gitencoding is not supported by Tcl/Tk\"\n }\n \n+set objformat [exec git rev-parse --show-object-format]\n+if {$objformat eq \"sha1\"} {\n+    set hashlength 40\n+} elseif {$objformat eq \"sha256\"} {\n+    set hashlength 64\n+} else {\n+    error_popup \"[mc \"Not supported hash algorithm:\"] {$objformat}\"\n+    exit 1\n+}\n+set hashalgorithm [string toupper $objformat]\n+unset objformat\n+\n set gui_encoding [encoding system]\n catch {\n     set enc [exec git config --get gui.encoding]\n\nbase-commit: ebf3c04b262aa27fbb97f8a0156c2347fecafafb\n-- \ngitgitgadget\n"},{"id":"427560","messageId":"xmqqwnqutx6o.fsf@gitster.g","threadId":"55927","inReplyTo":"pull.979.git.1623687519832.gitgitgadget@gmail.com","subject":"Re: [PATCH] Add a basic support of SHA256 repositories into Gitk","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-06-16T01:28:31Z","receivedAt":"2021-06-16T01:28:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Rostislav Krasny via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Rostislav Krasny <rosti.bsd@gmail.com>\n>\n> Signed-off-by: Rostislav Krasny <rosti.bsd@gmail.com>\n> ---\n>     gitk: Add a basic support of SHA256 repositories into Gitk\n\nLooping-in the gitk maintainer.\n\n>     This PR makes Gitk working on both SHA256 and SHA1 repositories without\n>     errors/crashes. I made it by changing and testing the gitk script of Git\n>     for Windows [https://gitforwindows.org/] version 2.32.0.windows.1 that\n>     is a little bit different than the mainstream 2.32.0 version.\n>     \n>     Still not fixed functionality: [1] There is the \"Auto-select SHA1\n>     (length)\" configuration preference that affects \"Copy commit reference\"\n>     on both SHA1 and SHA256 repositories.\n>     \n>     A new \"Auto-select SHA256 (length)\" configuration preference should be\n>     added and used on SHA256 repositories instead of the old one. Since I'm\n>     not familiar with Tcl/Tk and this issue isn't critical I didn't\n>     implement it.\n\nThanks, Rostislav; please follow Documentation/SubmittingPatches\nnext time you touch gitk (or git-gui), as they have their own\nrepositories and maintainers.\n\n>\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-979%2Frosti-il%2Fgitk-sha256-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-979/rosti-il/gitk-sha256-v1\n> Pull-Request: https://github.com/gitgitgadget/git/pull/979\n>\n>  gitk-git/gitk | 66 ++++++++++++++++++++++++++++++++++++---------------\n>  1 file changed, 47 insertions(+), 19 deletions(-)\n>\n> diff --git a/gitk-git/gitk b/gitk-git/gitk\n> index 23d9dd1fe0d0..2da53604cdc8 100755\n> --- a/gitk-git/gitk\n> +++ b/gitk-git/gitk\n> @@ -290,6 +290,7 @@ proc parseviewargs {n arglist} {\n>  \n>  proc parseviewrevs {view revs} {\n>      global vposids vnegids\n> +    global hashlength\n>  \n>      if {$revs eq {}} {\n>          set revs HEAD\n> @@ -303,7 +304,7 @@ proc parseviewrevs {view revs} {\n>          set badrev {}\n>          for {set l 0} {$l < [llength $errlines]} {incr l} {\n>              set line [lindex $errlines $l]\n> -            if {!([string length $line] == 40 && [string is xdigit $line])} {\n> +            if {!([string length $line] == $hashlength && [string is xdigit $line])} {\n>                  if {[string match \"fatal:*\" $line]} {\n>                      if {[string match \"fatal: ambiguous argument*\" $line]\n>                          && $badrev ne {}} {\n> @@ -507,6 +508,7 @@ proc updatecommits {} {\n>      global hasworktree\n>      global varcid vposids vnegids vflags vrevs\n>      global show_notes\n> +    global hashlength\n>  \n>      set hasworktree [hasworktree]\n>      rereadrefs\n> @@ -540,7 +542,7 @@ proc updatecommits {} {\n>              # take out positive refs that we asked for before or\n>              # that we have already seen\n>              foreach rev $revs {\n> -                if {[string length $rev] == 40} {\n> +                if {[string length $rev] == $hashlength} {\n>                      if {[lsearch -exact $oldpos $rev] < 0\n>                          && ![info exists varcid($view,$rev)]} {\n>                          lappend newrevs $rev\n> @@ -1418,6 +1420,7 @@ proc getcommitlines {fd inst view updating}  {\n>      global parents children curview hlview\n>      global idpending ordertok\n>      global varccommits varcid varctok vtokmod vfilelimit vshortids\n> +    global hashlength\n>  \n>      set stuff [read $fd 500000]\n>      # git log doesn't terminate the last commit with a null...\n> @@ -1500,7 +1503,7 @@ proc getcommitlines {fd inst view updating}  {\n>              }\n>              set ok 1\n>              foreach id $ids {\n> -                if {[string length $id] != 40} {\n> +                if {[string length $id] != $hashlength} {\n>                      set ok 0\n>                      break\n>                  }\n> @@ -1780,6 +1783,7 @@ proc readrefs {} {\n>      global selecthead selectheadid\n>      global hideremotes\n>      global tclencoding\n> +    global hashlength\n>  \n>      foreach v {tagids idtags headids idheads otherrefids idotherrefs} {\n>          unset -nocomplain $v\n> @@ -1789,9 +1793,9 @@ proc readrefs {} {\n>          fconfigure $refd -encoding $tclencoding\n>      }\n>      while {[gets $refd line] >= 0} {\n> -        if {[string index $line 40] ne \" \"} continue\n> -        set id [string range $line 0 39]\n> -        set ref [string range $line 41 end]\n> +        if {[string index $line $hashlength] ne \" \"} continue\n> +        set id [string range $line 0 [expr {$hashlength - 1}]]\n> +        set ref [string range $line [expr {$hashlength + 1}] end]\n>          if {![string match \"refs/*\" $ref]} continue\n>          set name [string range $ref 5 end]\n>          if {[string match \"remotes/*\" $name]} {\n> @@ -2082,6 +2086,7 @@ proc makewindow {} {\n>      global have_tk85 use_ttk NS\n>      global git_version\n>      global worddiff\n> +    global hashlength hashalgorithm\n>  \n>      # The \"mc\" arguments here are purely so that xgettext\n>      # sees the following string as needing to be translated\n> @@ -2203,11 +2208,11 @@ proc makewindow {} {\n>      set sha1entry .tf.bar.sha1\n>      set entries $sha1entry\n>      set sha1but .tf.bar.sha1label\n> -    button $sha1but -text \"[mc \"SHA1 ID:\"] \" -state disabled -relief flat \\\n> +    button $sha1but -text \"[mc \"$hashalgorithm ID:\"] \" -state disabled -relief flat \\\n>          -command gotocommit -width 8\n>      $sha1but conf -disabledforeground [$sha1but cget -foreground]\n>      pack .tf.bar.sha1label -side left\n> -    ${NS}::entry $sha1entry -width 40 -font textfont -textvariable sha1string\n> +    ${NS}::entry $sha1entry -width $hashlength -font textfont -textvariable sha1string\n>      trace add variable sha1string write sha1change\n>      pack $sha1entry -side left -pady 2\n>  \n> @@ -3926,6 +3931,7 @@ proc stopblaming {} {\n>  \n>  proc read_line_source {fd inst} {\n>      global blamestuff curview commfd blameinst nullid nullid2\n> +    global hashlength\n>  \n>      while {[gets $fd line] >= 0} {\n>          lappend blamestuff($inst) $line\n> @@ -3946,7 +3952,7 @@ proc read_line_source {fd inst} {\n>      set line [split [lindex $blamestuff($inst) 0] \" \"]\n>      set id [lindex $line 0]\n>      set lnum [lindex $line 1]\n> -    if {[string length $id] == 40 && [string is xdigit $id] &&\n> +    if {[string length $id] == $hashlength && [string is xdigit $id] &&\n>          [string is digit -strict $lnum]} {\n>          # look for \"filename\" line\n>          foreach l $blamestuff($inst) {\n> @@ -5269,13 +5275,14 @@ proc get_viewmainhead {view} {\n>  # git rev-list should give us just 1 line to use as viewmainheadid($view)\n>  proc getviewhead {fd inst view} {\n>      global viewmainheadid commfd curview viewinstances showlocalchanges\n> +    global hashlength\n>  \n>      set id {}\n>      if {[gets $fd line] < 0} {\n>          if {![eof $fd]} {\n>              return 1\n>          }\n> -    } elseif {[string length $line] == 40 && [string is xdigit $line]} {\n> +    } elseif {[string length $line] == $hashlength && [string is xdigit $line]} {\n>          set id $line\n>      }\n>      set viewmainheadid($view) $id\n> @@ -7039,10 +7046,11 @@ proc commit_descriptor {p} {\n>  # Also look for URLs of the form \"http[s]://...\" and make them web links.\n>  proc appendwithlinks {text tags} {\n>      global ctext linknum curview\n> +    global hashlength\n>  \n>      set start [$ctext index \"end - 1c\"]\n>      $ctext insert end $text $tags\n> -    set links [regexp -indices -all -inline {(?:\\m|-g)[0-9a-f]{6,40}\\M} $text]\n> +    set links [regexp -indices -all -inline [string map \"@@ $hashlength\" {(?:\\m|-g)[0-9a-f]{6,@@}\\M}] $text]\n>      foreach l $links {\n>          set s [lindex $l 0]\n>          set e [lindex $l 1]\n> @@ -8716,13 +8724,17 @@ proc incrfont {inc} {\n>  \n>  proc clearsha1 {} {\n>      global sha1entry sha1string\n> -    if {[string length $sha1string] == 40} {\n> +    global hashlength\n> +\n> +    if {[string length $sha1string] == $hashlength} {\n>          $sha1entry delete 0 end\n>      }\n>  }\n>  \n>  proc sha1change {n1 n2 op} {\n>      global sha1string currentid sha1but\n> +    global hashalgorithm\n> +\n>      if {$sha1string == {}\n>          || ([info exists currentid] && $sha1string == $currentid)} {\n>          set state disabled\n> @@ -8733,12 +8745,13 @@ proc sha1change {n1 n2 op} {\n>      if {$state == \"normal\"} {\n>          $sha1but conf -state normal -relief raised -text \"[mc \"Goto:\"] \"\n>      } else {\n> -        $sha1but conf -state disabled -relief flat -text \"[mc \"SHA1 ID:\"] \"\n> +        $sha1but conf -state disabled -relief flat -text \"[mc \"$hashalgorithm ID:\"] \"\n>      }\n>  }\n>  \n>  proc gotocommit {} {\n>      global sha1string tagids headids curview varcid\n> +    global hashlength hashalgorithm\n>  \n>      if {$sha1string == {}\n>          || ([info exists currentid] && $sha1string == $currentid)} return\n> @@ -8748,11 +8761,11 @@ proc gotocommit {} {\n>          set id $headids($sha1string)\n>      } else {\n>          set id [string tolower $sha1string]\n> -        if {[regexp {^[0-9a-f]{4,39}$} $id]} {\n> +        if {[regexp [string map \"@@ [expr $hashlength - 1]\" {^[0-9a-f]{4,@@}$}] $id]} {\n>              set matches [longid $id]\n>              if {$matches ne {}} {\n>                  if {[llength $matches] > 1} {\n> -                    error_popup [mc \"Short SHA1 id %s is ambiguous\" $id]\n> +                    error_popup [mc \"Short $hashalgorithm id %s is ambiguous\" $id]\n>                      return\n>                  }\n>                  set id [lindex $matches 0]\n> @@ -8769,7 +8782,7 @@ proc gotocommit {} {\n>          return\n>      }\n>      if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {\n> -        set msg [mc \"SHA1 id %s is not known\" $sha1string]\n> +        set msg [mc \"$hashalgorithm id %s is not known\" $sha1string]\n>      } else {\n>          set msg [mc \"Revision %s is not in the current view\" $sha1string]\n>      }\n> @@ -9446,10 +9459,11 @@ proc mktaggo {} {\n>  \n>  proc copyreference {} {\n>      global rowmenuid autosellen\n> +    global hashlength\n>  \n>      set format \"%h (\\\"%s\\\", %ad)\"\n>      set cmd [list git show -s --pretty=format:$format --date=short]\n> -    if {$autosellen < 40} {\n> +    if {$autosellen < $hashlength} {\n>          lappend cmd --abbrev=$autosellen\n>      }\n>      set reference [eval exec $cmd $rowmenuid]\n> @@ -9460,6 +9474,7 @@ proc copyreference {} {\n>  \n>  proc writecommit {} {\n>      global rowmenuid wrcomtop commitinfo wrcomcmd NS\n> +    global hashlength\n>  \n>      set top .writecommit\n>      set wrcomtop $top\n> @@ -9469,7 +9484,7 @@ proc writecommit {} {\n>      ${NS}::label $top.title -text [mc \"Write commit to file\"]\n>      grid $top.title - -pady 10\n>      ${NS}::label $top.id -text [mc \"ID:\"]\n> -    ${NS}::entry $top.sha1 -width 40\n> +    ${NS}::entry $top.sha1 -width $hashlength\n>      $top.sha1 insert 0 $rowmenuid\n>      $top.sha1 conf -state readonly\n>      grid $top.id $top.sha1 -sticky w\n> @@ -9549,6 +9564,7 @@ proc mvbranch {} {\n>  \n>  proc branchdia {top valvar uivar} {\n>      global NS commitinfo\n> +    global hashlength\n>      upvar $valvar val $uivar ui\n>  \n>      catch {destroy $top}\n> @@ -9557,7 +9573,7 @@ proc branchdia {top valvar uivar} {\n>      ${NS}::label $top.title -text $ui(title)\n>      grid $top.title - -pady 10\n>      ${NS}::label $top.id -text [mc \"ID:\"]\n> -    ${NS}::entry $top.sha1 -width 40\n> +    ${NS}::entry $top.sha1 -width $hashlength\n>      $top.sha1 insert 0 $val(id)\n>      $top.sha1 conf -state readonly\n>      grid $top.id $top.sha1 -sticky w\n> @@ -12320,6 +12336,18 @@ if {$tclencoding == {}} {\n>      puts stderr \"Warning: encoding $gitencoding is not supported by Tcl/Tk\"\n>  }\n>  \n> +set objformat [exec git rev-parse --show-object-format]\n> +if {$objformat eq \"sha1\"} {\n> +    set hashlength 40\n> +} elseif {$objformat eq \"sha256\"} {\n> +    set hashlength 64\n> +} else {\n> +    error_popup \"[mc \"Not supported hash algorithm:\"] {$objformat}\"\n> +    exit 1\n> +}\n> +set hashalgorithm [string toupper $objformat]\n> +unset objformat\n> +\n>  set gui_encoding [encoding system]\n>  catch {\n>      set enc [exec git config --get gui.encoding]\n>\n> base-commit: ebf3c04b262aa27fbb97f8a0156c2347fecafafb\n"},{"id":"427617","messageId":"87h7hxyjkv.fsf@evledraar.gmail.com","threadId":"55927","inReplyTo":"xmqqwnqutx6o.fsf@gitster.g","subject":"Re: [PATCH] Add a basic support of SHA256 repositories into Gitk","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-06-16T14:19:57Z","receivedAt":"2021-06-16T14:23:33Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Wed, Jun 16 2021, Junio C Hamano wrote:\n\n> \"Rostislav Krasny via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n>\n>> From: Rostislav Krasny <rosti.bsd@gmail.com>\n>>\n>> Signed-off-by: Rostislav Krasny <rosti.bsd@gmail.com>\n>> ---\n>>     gitk: Add a basic support of SHA256 repositories into Gitk\n>\n> Looping-in the gitk maintainer.\n>\n>>     This PR makes Gitk working on both SHA256 and SHA1 repositories without\n>>     errors/crashes. I made it by changing and testing the gitk script of Git\n>>     for Windows [https://gitforwindows.org/] version 2.32.0.windows.1 that\n>>     is a little bit different than the mainstream 2.32.0 version.\n>>     \n>>     Still not fixed functionality: [1] There is the \"Auto-select SHA1\n>>     (length)\" configuration preference that affects \"Copy commit reference\"\n>>     on both SHA1 and SHA256 repositories.\n>>     \n>>     A new \"Auto-select SHA256 (length)\" configuration preference should be\n>>     added and used on SHA256 repositories instead of the old one. Since I'm\n>>     not familiar with Tcl/Tk and this issue isn't critical I didn't\n>>     implement it.\n>\n> Thanks, Rostislav; please follow Documentation/SubmittingPatches\n> next time you touch gitk (or git-gui), as they have their own\n> repositories and maintainers.\n\nA comment on the patch at large: I realize that the author isn't\nfamiliar with Tcl, and this is a minimal & immediate fix, so maybe we\nshould just take it.\n\nBut I wonder if this == 40 or == 64 shouldn't just be \"accept either\" in\nthis case, these all seem like cases where we disambiguate a hash from\nsome other name.\n\nDoing so would be nicely forward-compatible in case gitk and others ever\nneed to deal with viewing a mixed set of hashes, or maybe I'm again\nmisrecalling the transition plan and that'll never happen (they'll\nalways be translated?).\n\nEspecially stuff like this (grabbing a bit to quote from the patch):\n\n>> -        if {[regexp {^[0-9a-f]{4,39}$} $id]} {\n>> +        if {[regexp [string map \"@@ [expr $hashlength - 1]\" {^[0-9a-f]{4,@@}$}] $id]} {\n\nWould be simpler as just:\n\n    if {[regexp {^[0-9a-f]{4,63}$} $id]} {\n"},{"id":"427928","messageId":"60cd40c1990a6_ca73a208b@natae.notmuch","threadId":"55927","inReplyTo":"87h7hxyjkv.fsf@evledraar.gmail.com","subject":"Re: [PATCH] Add a basic support of SHA256 repositories into Gitk","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-06-19T00:56:33Z","receivedAt":"2021-06-19T00:56:39Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Ævar Arnfjörð Bjarmason wrote:\n> \n> On Wed, Jun 16 2021, Junio C Hamano wrote:\n> \n> > \"Rostislav Krasny via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n> >\n> >> From: Rostislav Krasny <rosti.bsd@gmail.com>\n> >>\n> >> Signed-off-by: Rostislav Krasny <rosti.bsd@gmail.com>\n> >> ---\n> >>     gitk: Add a basic support of SHA256 repositories into Gitk\n> >\n> > Looping-in the gitk maintainer.\n> >\n> >>     This PR makes Gitk working on both SHA256 and SHA1 repositories without\n> >>     errors/crashes. I made it by changing and testing the gitk script of Git\n> >>     for Windows [https://gitforwindows.org/] version 2.32.0.windows.1 that\n> >>     is a little bit different than the mainstream 2.32.0 version.\n> >>     \n> >>     Still not fixed functionality: [1] There is the \"Auto-select SHA1\n> >>     (length)\" configuration preference that affects \"Copy commit reference\"\n> >>     on both SHA1 and SHA256 repositories.\n> >>     \n> >>     A new \"Auto-select SHA256 (length)\" configuration preference should be\n> >>     added and used on SHA256 repositories instead of the old one. Since I'm\n> >>     not familiar with Tcl/Tk and this issue isn't critical I didn't\n> >>     implement it.\n> >\n> > Thanks, Rostislav; please follow Documentation/SubmittingPatches\n> > next time you touch gitk (or git-gui), as they have their own\n> > repositories and maintainers.\n> \n> A comment on the patch at large: I realize that the author isn't\n> familiar with Tcl, and this is a minimal & immediate fix, so maybe we\n> should just take it.\n\nPlus it takes a huge while for any patch to be merged. There's 0 commits\nin 2021 on the gitk repository, and in 2020 there were only 6.\n\nMy last simple patch from May [1] is still waiting for any kind of\nfeedback.\n\n[1] https://lore.kernel.org/git/20210505211846.1842824-1-felipe.contreras@gmail.com/\n\n-- \nFelipe Contreras"},{"id":"454718","messageId":"CANt7McGs_pNZsjursu4Ef4NjJV_kG-31xS2SfpFfYyeNtyfW4A@mail.gmail.com","threadId":"55927","inReplyTo":"pull.979.git.1623687519832.gitgitgadget@gmail.com","subject":"Re: [PATCH] Add a basic support of SHA256 repositories into Gitk","fromName":"Rostislav Krasny","fromEmail":"rosti.bsd@gmail.com","sentAt":"2022-05-02T14:24:17Z","receivedAt":"2022-05-02T14:24:35Z","isPatch":true,"sender":{"key":"rosti.bsd@gmail.com","avatar":null},"body":"Hello everybody,\n\nI created this PR almost a year ago, is there any general progress\nwith supporting SHA256 in gitk? Even some other's patch/PR?\n\nOn Mon, Jun 14, 2021 at 7:18 PM Rostislav Krasny via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n>\n> From: Rostislav Krasny <rosti.bsd@gmail.com>\n>\n> Signed-off-by: Rostislav Krasny <rosti.bsd@gmail.com>\n> ---\n>     gitk: Add a basic support of SHA256 repositories into Gitk\n>\n>     This PR makes Gitk working on both SHA256 and SHA1 repositories without\n>     errors/crashes. I made it by changing and testing the gitk script of Git\n>     for Windows [https://gitforwindows.org/] version 2.32.0.windows.1 that\n>     is a little bit different than the mainstream 2.32.0 version.\n>\n>     Still not fixed functionality: [1] There is the \"Auto-select SHA1\n>     (length)\" configuration preference that affects \"Copy commit reference\"\n>     on both SHA1 and SHA256 repositories.\n>\n>     A new \"Auto-select SHA256 (length)\" configuration preference should be\n>     added and used on SHA256 repositories instead of the old one. Since I'm\n>     not familiar with Tcl/Tk and this issue isn't critical I didn't\n>     implement it.\n>\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-979%2Frosti-il%2Fgitk-sha256-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-979/rosti-il/gitk-sha256-v1\n> Pull-Request: https://github.com/gitgitgadget/git/pull/979\n>\n>  gitk-git/gitk | 66 ++++++++++++++++++++++++++++++++++++---------------\n>  1 file changed, 47 insertions(+), 19 deletions(-)\n>\n> diff --git a/gitk-git/gitk b/gitk-git/gitk\n> index 23d9dd1fe0d0..2da53604cdc8 100755\n> --- a/gitk-git/gitk\n> +++ b/gitk-git/gitk\n> @@ -290,6 +290,7 @@ proc parseviewargs {n arglist} {\n>\n>  proc parseviewrevs {view revs} {\n>      global vposids vnegids\n> +    global hashlength\n>\n>      if {$revs eq {}} {\n>          set revs HEAD\n> @@ -303,7 +304,7 @@ proc parseviewrevs {view revs} {\n>          set badrev {}\n>          for {set l 0} {$l < [llength $errlines]} {incr l} {\n>              set line [lindex $errlines $l]\n> -            if {!([string length $line] == 40 && [string is xdigit $line])} {\n> +            if {!([string length $line] == $hashlength && [string is xdigit $line])} {\n>                  if {[string match \"fatal:*\" $line]} {\n>                      if {[string match \"fatal: ambiguous argument*\" $line]\n>                          && $badrev ne {}} {\n> @@ -507,6 +508,7 @@ proc updatecommits {} {\n>      global hasworktree\n>      global varcid vposids vnegids vflags vrevs\n>      global show_notes\n> +    global hashlength\n>\n>      set hasworktree [hasworktree]\n>      rereadrefs\n> @@ -540,7 +542,7 @@ proc updatecommits {} {\n>              # take out positive refs that we asked for before or\n>              # that we have already seen\n>              foreach rev $revs {\n> -                if {[string length $rev] == 40} {\n> +                if {[string length $rev] == $hashlength} {\n>                      if {[lsearch -exact $oldpos $rev] < 0\n>                          && ![info exists varcid($view,$rev)]} {\n>                          lappend newrevs $rev\n> @@ -1418,6 +1420,7 @@ proc getcommitlines {fd inst view updating}  {\n>      global parents children curview hlview\n>      global idpending ordertok\n>      global varccommits varcid varctok vtokmod vfilelimit vshortids\n> +    global hashlength\n>\n>      set stuff [read $fd 500000]\n>      # git log doesn't terminate the last commit with a null...\n> @@ -1500,7 +1503,7 @@ proc getcommitlines {fd inst view updating}  {\n>              }\n>              set ok 1\n>              foreach id $ids {\n> -                if {[string length $id] != 40} {\n> +                if {[string length $id] != $hashlength} {\n>                      set ok 0\n>                      break\n>                  }\n> @@ -1780,6 +1783,7 @@ proc readrefs {} {\n>      global selecthead selectheadid\n>      global hideremotes\n>      global tclencoding\n> +    global hashlength\n>\n>      foreach v {tagids idtags headids idheads otherrefids idotherrefs} {\n>          unset -nocomplain $v\n> @@ -1789,9 +1793,9 @@ proc readrefs {} {\n>          fconfigure $refd -encoding $tclencoding\n>      }\n>      while {[gets $refd line] >= 0} {\n> -        if {[string index $line 40] ne \" \"} continue\n> -        set id [string range $line 0 39]\n> -        set ref [string range $line 41 end]\n> +        if {[string index $line $hashlength] ne \" \"} continue\n> +        set id [string range $line 0 [expr {$hashlength - 1}]]\n> +        set ref [string range $line [expr {$hashlength + 1}] end]\n>          if {![string match \"refs/*\" $ref]} continue\n>          set name [string range $ref 5 end]\n>          if {[string match \"remotes/*\" $name]} {\n> @@ -2082,6 +2086,7 @@ proc makewindow {} {\n>      global have_tk85 use_ttk NS\n>      global git_version\n>      global worddiff\n> +    global hashlength hashalgorithm\n>\n>      # The \"mc\" arguments here are purely so that xgettext\n>      # sees the following string as needing to be translated\n> @@ -2203,11 +2208,11 @@ proc makewindow {} {\n>      set sha1entry .tf.bar.sha1\n>      set entries $sha1entry\n>      set sha1but .tf.bar.sha1label\n> -    button $sha1but -text \"[mc \"SHA1 ID:\"] \" -state disabled -relief flat \\\n> +    button $sha1but -text \"[mc \"$hashalgorithm ID:\"] \" -state disabled -relief flat \\\n>          -command gotocommit -width 8\n>      $sha1but conf -disabledforeground [$sha1but cget -foreground]\n>      pack .tf.bar.sha1label -side left\n> -    ${NS}::entry $sha1entry -width 40 -font textfont -textvariable sha1string\n> +    ${NS}::entry $sha1entry -width $hashlength -font textfont -textvariable sha1string\n>      trace add variable sha1string write sha1change\n>      pack $sha1entry -side left -pady 2\n>\n> @@ -3926,6 +3931,7 @@ proc stopblaming {} {\n>\n>  proc read_line_source {fd inst} {\n>      global blamestuff curview commfd blameinst nullid nullid2\n> +    global hashlength\n>\n>      while {[gets $fd line] >= 0} {\n>          lappend blamestuff($inst) $line\n> @@ -3946,7 +3952,7 @@ proc read_line_source {fd inst} {\n>      set line [split [lindex $blamestuff($inst) 0] \" \"]\n>      set id [lindex $line 0]\n>      set lnum [lindex $line 1]\n> -    if {[string length $id] == 40 && [string is xdigit $id] &&\n> +    if {[string length $id] == $hashlength && [string is xdigit $id] &&\n>          [string is digit -strict $lnum]} {\n>          # look for \"filename\" line\n>          foreach l $blamestuff($inst) {\n> @@ -5269,13 +5275,14 @@ proc get_viewmainhead {view} {\n>  # git rev-list should give us just 1 line to use as viewmainheadid($view)\n>  proc getviewhead {fd inst view} {\n>      global viewmainheadid commfd curview viewinstances showlocalchanges\n> +    global hashlength\n>\n>      set id {}\n>      if {[gets $fd line] < 0} {\n>          if {![eof $fd]} {\n>              return 1\n>          }\n> -    } elseif {[string length $line] == 40 && [string is xdigit $line]} {\n> +    } elseif {[string length $line] == $hashlength && [string is xdigit $line]} {\n>          set id $line\n>      }\n>      set viewmainheadid($view) $id\n> @@ -7039,10 +7046,11 @@ proc commit_descriptor {p} {\n>  # Also look for URLs of the form \"http[s]://...\" and make them web links.\n>  proc appendwithlinks {text tags} {\n>      global ctext linknum curview\n> +    global hashlength\n>\n>      set start [$ctext index \"end - 1c\"]\n>      $ctext insert end $text $tags\n> -    set links [regexp -indices -all -inline {(?:\\m|-g)[0-9a-f]{6,40}\\M} $text]\n> +    set links [regexp -indices -all -inline [string map \"@@ $hashlength\" {(?:\\m|-g)[0-9a-f]{6,@@}\\M}] $text]\n>      foreach l $links {\n>          set s [lindex $l 0]\n>          set e [lindex $l 1]\n> @@ -8716,13 +8724,17 @@ proc incrfont {inc} {\n>\n>  proc clearsha1 {} {\n>      global sha1entry sha1string\n> -    if {[string length $sha1string] == 40} {\n> +    global hashlength\n> +\n> +    if {[string length $sha1string] == $hashlength} {\n>          $sha1entry delete 0 end\n>      }\n>  }\n>\n>  proc sha1change {n1 n2 op} {\n>      global sha1string currentid sha1but\n> +    global hashalgorithm\n> +\n>      if {$sha1string == {}\n>          || ([info exists currentid] && $sha1string == $currentid)} {\n>          set state disabled\n> @@ -8733,12 +8745,13 @@ proc sha1change {n1 n2 op} {\n>      if {$state == \"normal\"} {\n>          $sha1but conf -state normal -relief raised -text \"[mc \"Goto:\"] \"\n>      } else {\n> -        $sha1but conf -state disabled -relief flat -text \"[mc \"SHA1 ID:\"] \"\n> +        $sha1but conf -state disabled -relief flat -text \"[mc \"$hashalgorithm ID:\"] \"\n>      }\n>  }\n>\n>  proc gotocommit {} {\n>      global sha1string tagids headids curview varcid\n> +    global hashlength hashalgorithm\n>\n>      if {$sha1string == {}\n>          || ([info exists currentid] && $sha1string == $currentid)} return\n> @@ -8748,11 +8761,11 @@ proc gotocommit {} {\n>          set id $headids($sha1string)\n>      } else {\n>          set id [string tolower $sha1string]\n> -        if {[regexp {^[0-9a-f]{4,39}$} $id]} {\n> +        if {[regexp [string map \"@@ [expr $hashlength - 1]\" {^[0-9a-f]{4,@@}$}] $id]} {\n>              set matches [longid $id]\n>              if {$matches ne {}} {\n>                  if {[llength $matches] > 1} {\n> -                    error_popup [mc \"Short SHA1 id %s is ambiguous\" $id]\n> +                    error_popup [mc \"Short $hashalgorithm id %s is ambiguous\" $id]\n>                      return\n>                  }\n>                  set id [lindex $matches 0]\n> @@ -8769,7 +8782,7 @@ proc gotocommit {} {\n>          return\n>      }\n>      if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {\n> -        set msg [mc \"SHA1 id %s is not known\" $sha1string]\n> +        set msg [mc \"$hashalgorithm id %s is not known\" $sha1string]\n>      } else {\n>          set msg [mc \"Revision %s is not in the current view\" $sha1string]\n>      }\n> @@ -9446,10 +9459,11 @@ proc mktaggo {} {\n>\n>  proc copyreference {} {\n>      global rowmenuid autosellen\n> +    global hashlength\n>\n>      set format \"%h (\\\"%s\\\", %ad)\"\n>      set cmd [list git show -s --pretty=format:$format --date=short]\n> -    if {$autosellen < 40} {\n> +    if {$autosellen < $hashlength} {\n>          lappend cmd --abbrev=$autosellen\n>      }\n>      set reference [eval exec $cmd $rowmenuid]\n> @@ -9460,6 +9474,7 @@ proc copyreference {} {\n>\n>  proc writecommit {} {\n>      global rowmenuid wrcomtop commitinfo wrcomcmd NS\n> +    global hashlength\n>\n>      set top .writecommit\n>      set wrcomtop $top\n> @@ -9469,7 +9484,7 @@ proc writecommit {} {\n>      ${NS}::label $top.title -text [mc \"Write commit to file\"]\n>      grid $top.title - -pady 10\n>      ${NS}::label $top.id -text [mc \"ID:\"]\n> -    ${NS}::entry $top.sha1 -width 40\n> +    ${NS}::entry $top.sha1 -width $hashlength\n>      $top.sha1 insert 0 $rowmenuid\n>      $top.sha1 conf -state readonly\n>      grid $top.id $top.sha1 -sticky w\n> @@ -9549,6 +9564,7 @@ proc mvbranch {} {\n>\n>  proc branchdia {top valvar uivar} {\n>      global NS commitinfo\n> +    global hashlength\n>      upvar $valvar val $uivar ui\n>\n>      catch {destroy $top}\n> @@ -9557,7 +9573,7 @@ proc branchdia {top valvar uivar} {\n>      ${NS}::label $top.title -text $ui(title)\n>      grid $top.title - -pady 10\n>      ${NS}::label $top.id -text [mc \"ID:\"]\n> -    ${NS}::entry $top.sha1 -width 40\n> +    ${NS}::entry $top.sha1 -width $hashlength\n>      $top.sha1 insert 0 $val(id)\n>      $top.sha1 conf -state readonly\n>      grid $top.id $top.sha1 -sticky w\n> @@ -12320,6 +12336,18 @@ if {$tclencoding == {}} {\n>      puts stderr \"Warning: encoding $gitencoding is not supported by Tcl/Tk\"\n>  }\n>\n> +set objformat [exec git rev-parse --show-object-format]\n> +if {$objformat eq \"sha1\"} {\n> +    set hashlength 40\n> +} elseif {$objformat eq \"sha256\"} {\n> +    set hashlength 64\n> +} else {\n> +    error_popup \"[mc \"Not supported hash algorithm:\"] {$objformat}\"\n> +    exit 1\n> +}\n> +set hashalgorithm [string toupper $objformat]\n> +unset objformat\n> +\n>  set gui_encoding [encoding system]\n>  catch {\n>      set enc [exec git config --get gui.encoding]\n>\n> base-commit: ebf3c04b262aa27fbb97f8a0156c2347fecafafb\n> --\n> gitgitgadget\n"}]}