{"thread":{"id":"63659","subject":"[PATCH] git-gui: Add support of SHA256 repo","startedAt":"2025-06-17T06:04:09Z","lastAt":"2025-06-17T06:04:09Z","messageCount":1,"participants":["Takashi Iwai"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"520309","messageId":"20250617060406.10159-1-tiwai@suse.de","threadId":"63659","inReplyTo":null,"subject":"[PATCH] git-gui: Add support of SHA256 repo","fromName":"Takashi Iwai","fromEmail":"tiwai@suse.de","sentAt":"2025-06-17T06:03:59Z","receivedAt":"2025-06-17T06:04:09Z","isPatch":true,"sender":{"key":"tiwai@suse.de","avatar":"https://avatars.githubusercontent.com/u/306482?v=4"},"body":"This patch adds the basic support of SHA256 Git repositories.\nThe needed changes were mostly about adjusting the fixed ID length of\nSHA1 (40) to be variable depending on the repo type.\n\nSigned-off-by: Takashi Iwai <tiwai@suse.de>\n---\n git-gui/git-gui.sh                   | 13 ++++++++++++-\n git-gui/lib/blame.tcl                | 12 ++++++++----\n git-gui/lib/choose_repository.tcl    |  8 ++++++--\n git-gui/lib/remote_branch_delete.tcl |  4 +++-\n 4 files changed, 29 insertions(+), 8 deletions(-)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex 28572c889c0e..206981190535 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -1275,6 +1275,17 @@ if {[catch {\n \tset picked 1\n }\n \n+# Use object format as hash algorightm (either \"sha1\" or \"sha256\")\n+set hashalgorithm [exec git rev-parse --show-object-format]\n+if {$hashalgorithm eq \"sha1\"} {\n+\tset hashlength 40\n+} elseif {$hashalgorithm eq \"sha256\"} {\n+\tset hashlength 64\n+} else {\n+\tputs stderr \"Unknown hash algorithm: $hashalgorithm\"\n+\texit 1\n+}\n+\n # we expand the _gitdir when it's just a single dot (i.e. when we're being\n # run from the .git dir itself) lest the routines to find the worktree\n # get confused\n@@ -1822,7 +1833,7 @@ proc short_path {path} {\n }\n \n set next_icon_id 0\n-set null_sha1 [string repeat 0 40]\n+set null_sha1 [string repeat 0 $hashlength]\n \n proc merge_state {path new_state {head_info {}} {index_info {}}} {\n \tglobal file_states next_icon_id null_sha1\ndiff --git a/git-gui/lib/blame.tcl b/git-gui/lib/blame.tcl\nindex 8441e109be32..1f0b8ea28504 100644\n--- a/git-gui/lib/blame.tcl\n+++ b/git-gui/lib/blame.tcl\n@@ -426,6 +426,7 @@ method _kill {} {\n \n method _load {jump} {\n \tvariable group_colors\n+\tglobal hashlength\n \n \t_hide_tooltip $this\n \n@@ -436,7 +437,7 @@ method _load {jump} {\n \t\t\t$i conf -state normal\n \t\t\t$i delete 0.0 end\n \t\t\tforeach g [$i tag names] {\n-\t\t\t\tif {[regexp {^g[0-9a-f]{40}$} $g]} {\n+\t\t\t\tif {[regexp [string map \"@@ $hashlength\" {^g[0-9a-f]{@@}$}] $g]} {\n \t\t\t\t\t$i tag delete $g\n \t\t\t\t}\n \t\t\t}\n@@ -500,6 +501,8 @@ method _load {jump} {\n }\n \n method _history_menu {} {\n+\tglobal hashlength\n+\n \tset m $w.backmenu\n \tif {[winfo exists $m]} {\n \t\t$m delete 0 end\n@@ -513,7 +516,7 @@ method _history_menu {} {\n \t\tset c [lindex $e 0]\n \t\tset f [lindex $e 1]\n \n-\t\tif {[regexp {^[0-9a-f]{40}$} $c]} {\n+\t\tif {[regexp [string map \"@@ $hashlength\" {^[0-9a-f]{@@}$}] $c]} {\n \t\t\tset t [string range $c 0 8]...\n \t\t} elseif {$c eq {}} {\n \t\t\tset t {Working Directory}\n@@ -627,6 +630,7 @@ method _exec_blame {cur_w cur_d options cur_s} {\n method _read_blame {fd cur_w cur_d} {\n \tupvar #0 $cur_d line_data\n \tvariable group_colors\n+\tglobal hashlength\n \n \tif {$fd ne $current_fd} {\n \t\tcatch {close $fd}\n@@ -635,7 +639,7 @@ method _read_blame {fd cur_w cur_d} {\n \n \t$cur_w conf -state normal\n \twhile {[gets $fd line] >= 0} {\n-\t\tif {[regexp {^([a-z0-9]{40}) (\\d+) (\\d+) (\\d+)$} $line line \\\n+\t\tif {[regexp [string map \"@@ $hashlength\" {^([a-z0-9]{@@}) (\\d+) (\\d+) (\\d+)$}] $line line \\\n \t\t\tcmit original_line final_line line_count]} {\n \t\t\tset r_commit     $cmit\n \t\t\tset r_orig_line  $original_line\n@@ -648,7 +652,7 @@ method _read_blame {fd cur_w cur_d} {\n \t\t\tset oln  $r_orig_line\n \t\t\tset cmit $r_commit\n \n-\t\t\tif {[regexp {^0{40}$} $cmit]} {\n+\t\t\tif {[regexp [string map \"@@ $hashlength\" {^0{@@}$}] $cmit]} {\n \t\t\t\tset commit_abbr work\n \t\t\t\tset commit_type curr_commit\n \t\t\t} elseif {$cmit eq $commit} {\ndiff --git a/git-gui/lib/choose_repository.tcl b/git-gui/lib/choose_repository.tcl\nindex d23abedcb36f..6078b1c7e2c4 100644\n--- a/git-gui/lib/choose_repository.tcl\n+++ b/git-gui/lib/choose_repository.tcl\n@@ -870,6 +870,8 @@ method _do_clone_HEAD {ok} {\n }\n \n method _do_clone_full_end {ok} {\n+\tglobal hashlength\n+\n \t$o_cons done $ok\n \n \tif {$ok} {\n@@ -879,7 +881,7 @@ method _do_clone_full_end {ok} {\n \t\tif {[file exists [gitdir FETCH_HEAD]]} {\n \t\t\tset fd [open [gitdir FETCH_HEAD] r]\n \t\t\twhile {[gets $fd line] >= 0} {\n-\t\t\t\tif {[regexp \"^(.{40})\\t\\t\" $line line HEAD]} {\n+\t\t\t\tif {[regexp [string map \"@@ $hashlength\" \"^(.{@@})\\t\\t\"] $line line HEAD]} {\n \t\t\t\t\tbreak\n \t\t\t\t}\n \t\t\t}\n@@ -965,6 +967,8 @@ method _do_clone_checkout {HEAD} {\n }\n \n method _readtree_wait {fd} {\n+\tglobal hashlength\n+\n \tset buf [read $fd]\n \t$o_status_op update_meter $buf\n \tappend readtree_err $buf\n@@ -986,7 +990,7 @@ method _readtree_wait {fd} {\n \n \t# -- Run the post-checkout hook.\n \t#\n-\tset fd_ph [githook_read post-checkout [string repeat 0 40] \\\n+\tset fd_ph [githook_read post-checkout [string repeat 0 $hashlength] \\\n \t\t[git rev-parse HEAD] 1]\n \tif {$fd_ph ne {}} {\n \t\tglobal pch_error\ndiff --git a/git-gui/lib/remote_branch_delete.tcl b/git-gui/lib/remote_branch_delete.tcl\nindex 5ba9fcadd17f..8ea672479306 100644\n--- a/git-gui/lib/remote_branch_delete.tcl\n+++ b/git-gui/lib/remote_branch_delete.tcl\n@@ -323,6 +323,8 @@ method _load {cache uri} {\n }\n \n method _read {cache fd} {\n+\tglobal hashlength\n+\n \tif {$fd ne $active_ls} {\n \t\tcatch {close $fd}\n \t\treturn\n@@ -330,7 +332,7 @@ method _read {cache fd} {\n \n \twhile {[gets $fd line] >= 0} {\n \t\tif {[string match {*^{}} $line]} continue\n-\t\tif {[regexp {^([0-9a-f]{40})\t(.*)$} $line _junk obj ref]} {\n+\t\tif {[regexp [string map \"@@ $hashlength\" {^([0-9a-f]{@@})\t(.*)$}] $line _junk obj ref]} {\n \t\t\tif {[regsub ^refs/heads/ $ref {} abr]} {\n \t\t\t\tlappend head_list $abr\n \t\t\t\tlappend head_cache($cache) $abr\n-- \n2.49.0\n\n"}]}