{"thread":{"id":"63801","subject":"[PATCH v3 1/2] git-gui: Replace null_sha1 with nullid","startedAt":"2025-07-16T07:32:36Z","lastAt":"2025-07-17T07:03:52Z","messageCount":5,"participants":["Takashi Iwai","Johannes Sixt"],"isPatch":true,"patchVersion":3,"patchTotal":2},"messages":[{"id":"522076","messageId":"20250716073227.11486-1-tiwai@suse.de","threadId":"63801","inReplyTo":null,"subject":"[PATCH v3 0/2] git-gui: Add support of SHA256 repo","fromName":"Takashi Iwai","fromEmail":"tiwai@suse.de","sentAt":"2025-07-16T07:32:23Z","receivedAt":"2025-07-16T07:32:36Z","isPatch":true,"sender":{"key":"tiwai@suse.de","avatar":"https://avatars.githubusercontent.com/u/306482?v=4"},"body":"Here is the v3 patch for git-gui to support SHA256 repos.\nI put a preliminary patch to clean up $null_sha1 in addition to the\ncorrection / update of v2 patch.\n\n\nTakashi\n\n===\n\nTakashi Iwai (2):\n  git-gui: Replace null_sha1 with nullid\n  git-gui: Add support of SHA256 repo\n\n git-gui/git-gui.sh                   | 22 ++++++++++++++++------\n git-gui/lib/blame.tcl                | 12 ++++++++----\n git-gui/lib/checkout_op.tcl          |  4 ++--\n git-gui/lib/choose_repository.tcl    |  7 ++++---\n git-gui/lib/commit.tcl               |  3 ++-\n git-gui/lib/remote_branch_delete.tcl |  4 +++-\n 6 files changed, 35 insertions(+), 17 deletions(-)\n\n-- \n2.50.1\n\n"},{"id":"522075","messageId":"20250716073227.11486-2-tiwai@suse.de","threadId":"63801","inReplyTo":"20250716073227.11486-1-tiwai@suse.de","subject":"[PATCH v3 1/2] git-gui: Replace null_sha1 with nullid","fromName":"Takashi Iwai","fromEmail":"tiwai@suse.de","sentAt":"2025-07-16T07:32:24Z","receivedAt":"2025-07-16T07:32:37Z","isPatch":true,"sender":{"key":"tiwai@suse.de","avatar":"https://avatars.githubusercontent.com/u/306482?v=4"},"body":"Both $nullid and $null_sha1 point to the same content.\nUse only $nullid consistently.\n\nThis is a preliminary cleanup for adding the support of SHA256 repo.\n\nSigned-off-by: Takashi Iwai <tiwai@suse.de>\n---\nv3: new patch\n\n git-gui/git-gui.sh          | 5 ++---\n git-gui/lib/checkout_op.tcl | 4 ++--\n 2 files changed, 4 insertions(+), 5 deletions(-)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex c77c05edde3b..413a8a9abc1f 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -1845,10 +1845,9 @@ proc short_path {path} {\n }\n \n set next_icon_id 0\n-set null_sha1 [string repeat 0 40]\n \n proc merge_state {path new_state {head_info {}} {index_info {}}} {\n-\tglobal file_states next_icon_id null_sha1\n+\tglobal file_states next_icon_id nullid\n \n \tset s0 [string index $new_state 0]\n \tset s1 [string index $new_state 1]\n@@ -1870,7 +1869,7 @@ proc merge_state {path new_state {head_info {}} {index_info {}}} {\n \telseif {$s1 eq {_}} {set s1 _}\n \n \tif {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {\n-\t\tset head_info [list 0 $null_sha1]\n+\t\tset head_info [list 0 $nullid]\n \t} elseif {$s0 ne {_} && [string index $state 0] eq {_}\n \t\t&& $head_info eq {}} {\n \t\tset head_info $index_info\ndiff --git a/git-gui/lib/checkout_op.tcl b/git-gui/lib/checkout_op.tcl\nindex 87ed0b48585e..987486a4b602 100644\n--- a/git-gui/lib/checkout_op.tcl\n+++ b/git-gui/lib/checkout_op.tcl\n@@ -151,7 +151,7 @@ method _finish_fetch {ok} {\n }\n \n method _update_ref {} {\n-\tglobal null_sha1 current_branch repo_config\n+\tglobal nullid current_branch repo_config\n \n \tset ref $new_ref\n \tset new $new_hash\n@@ -177,7 +177,7 @@ method _update_ref {} {\n \t\t}\n \n \t\tset reflog_msg \"branch: Created from $new_expr\"\n-\t\tset cur $null_sha1\n+\t\tset cur $nullid\n \n \t\tif {($repo_config(branch.autosetupmerge) eq {true}\n \t\t\t|| $repo_config(branch.autosetupmerge) eq {always})\n-- \n2.50.1\n\n"},{"id":"522077","messageId":"20250716073227.11486-3-tiwai@suse.de","threadId":"63801","inReplyTo":"20250716073227.11486-1-tiwai@suse.de","subject":"[PATCH v3 2/2] git-gui: Add support of SHA256 repo","fromName":"Takashi Iwai","fromEmail":"tiwai@suse.de","sentAt":"2025-07-16T07:32:25Z","receivedAt":"2025-07-16T07:32:47Z","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.\nMost of changes are idiomatic replacement of the hard-coded hash ID\nlength, but there are subtle things:\n\n* The hash length is determined on startup, and stored in $hashlength\n  global variable (either 40 or 64).\n* The hard-coded \"40\" are replaced with $hashlength;\n  for regexp patterns, the ugly string map is used.\n* Some code have the fixed numbers like 39 and 45, and those are\n  replaced with the $hashlength and the offset correction.\n* $nullid and $nullid2 are generated for the hash length.\n\nA caveat is that repository picker dialog is performed before\nevaluating the repo type, hence $hashlength isn't set there yet.\nSo the code dealing with the hard-coded \"40\" are handled differently;\nnamely, the regexp range is expanded, and the null id is generated\nfrom the HEAD id length locally.\n\nSigned-off-by: Takashi Iwai <tiwai@suse.de>\n---\nv2->v3:\n* add more texts to patch descriptions\n* fix $nullid and $nullid2, too\n* fix abbrev id check in blame\n* don't refer to $hashlength in repo picker code\n\n git-gui/git-gui.sh                   | 17 ++++++++++++++---\n git-gui/lib/blame.tcl                | 12 ++++++++----\n git-gui/lib/choose_repository.tcl    |  7 ++++---\n git-gui/lib/commit.tcl               |  3 ++-\n git-gui/lib/remote_branch_delete.tcl |  4 +++-\n 5 files changed, 31 insertions(+), 12 deletions(-)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex 413a8a9abc1f..c437980927fd 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -1298,6 +1298,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@@ -1391,8 +1402,8 @@ set is_conflict_diff 0\n set last_revert {}\n set last_revert_enc {}\n \n-set nullid \"0000000000000000000000000000000000000000\"\n-set nullid2 \"0000000000000000000000000000000000000001\"\n+set nullid [string repeat 0 $hashlength]\n+set nullid2 \"[string repeat 0 [expr $hashlength - 1]]1\"\n \n ######################################################################\n ##\n@@ -3202,7 +3213,7 @@ blame {\n \tif {$head eq {}} {\n \t\tload_current_branch\n \t} else {\n-\t\tif {[regexp {^[0-9a-f]{1,39}$} $head]} {\n+\t\tif {[regexp [string map \"@@ [expr $hashlength - 1]\" {^[0-9a-f]{1,@@}$}] $head]} {\n \t\t\tif {[catch {\n \t\t\t\t\tset head [git rev-parse --verify $head]\n \t\t\t\t} err]} {\ndiff --git a/git-gui/lib/blame.tcl b/git-gui/lib/blame.tcl\nindex d6fd8bea91ff..5507681da7ba 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 nullid\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 {$cmit eq $nullid} {\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 5b361cc424a6..877ca4888f7a 100644\n--- a/git-gui/lib/choose_repository.tcl\n+++ b/git-gui/lib/choose_repository.tcl\n@@ -879,7 +879,7 @@ method _do_clone_full_end {ok} {\n \t\tif {[file exists [gitdir FETCH_HEAD]]} {\n \t\t\tset fd [safe_open_file [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 \"^(.{40,64})\\t\\t\" $line line HEAD]} {\n \t\t\t\t\tbreak\n \t\t\t\t}\n \t\t\t}\n@@ -987,8 +987,9 @@ 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-\t\t[git rev-parse HEAD] 1]\n+\tset head_id [git rev-parse HEAD]\n+\tset fd_ph [githook_read post-checkout \\\n+\t\t[string repeat 0 [string length $head_id]] $head_id 1]\n \tif {$fd_ph ne {}} {\n \t\tglobal pch_error\n \t\tset pch_error {}\ndiff --git a/git-gui/lib/commit.tcl b/git-gui/lib/commit.tcl\nindex 60d66172a100..7c800a4bc37a 100644\n--- a/git-gui/lib/commit.tcl\n+++ b/git-gui/lib/commit.tcl\n@@ -348,6 +348,7 @@ proc commit_committree {fd_wt curHEAD msg_p} {\n \tglobal file_states selected_paths rescan_active\n \tglobal repo_config\n \tglobal env\n+\tglobal hashlength\n \n \tgets $fd_wt tree_id\n \tif {[catch {close $fd_wt} err]} {\n@@ -367,7 +368,7 @@ proc commit_committree {fd_wt curHEAD msg_p} {\n \t\tclose $fd_ot\n \n \t\tif {[string equal -length 5 {tree } $old_tree]\n-\t\t\t&& [string length $old_tree] == 45} {\n+\t\t\t&& [string length $old_tree] == [expr {$hashlength + 5}]} {\n \t\t\tset old_tree [string range $old_tree 5 end]\n \t\t} else {\n \t\t\terror [mc \"Commit %s appears to be corrupt\" $PARENT]\ndiff --git a/git-gui/lib/remote_branch_delete.tcl b/git-gui/lib/remote_branch_delete.tcl\nindex c8c99b17a8da..781980d66cc8 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.50.1\n\n"},{"id":"522123","messageId":"2a7f20ef-ad7b-47b5-9c3a-71fbdd11e756@kdbg.org","threadId":"63801","inReplyTo":"20250716073227.11486-1-tiwai@suse.de","subject":"Re: [PATCH v3 0/2] git-gui: Add support of SHA256 repo","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2025-07-16T17:38:34Z","receivedAt":"2025-07-16T17:38:44Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 16.07.25 um 09:32 schrieb Takashi Iwai:\n> Here is the v3 patch for git-gui to support SHA256 repos.\n> I put a preliminary patch to clean up $null_sha1 in addition to the\n> correction / update of v2 patch.\n\nThanks, queued.\n\nI applied the following fixups: an obvious typo-fix in a comment and use\nof our wrapper function `git` instead of plain Tcl `exec git`.\n\ndiff --git a/git-gui.sh b/git-gui.sh\nindex c437980927fd..523e4df8069a 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -1298,8 +1298,8 @@ 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+# Use object format as hash algorithm (either \"sha1\" or \"sha256\")\n+set hashalgorithm [git rev-parse --show-object-format]\n if {$hashalgorithm eq \"sha1\"} {\n \tset hashlength 40\n } elseif {$hashalgorithm eq \"sha256\"} {\n\n"},{"id":"522171","messageId":"87v7nr9u3t.wl-tiwai@suse.de","threadId":"63801","inReplyTo":"2a7f20ef-ad7b-47b5-9c3a-71fbdd11e756@kdbg.org","subject":"Re: [PATCH v3 0/2] git-gui: Add support of SHA256 repo","fromName":"Takashi Iwai","fromEmail":"tiwai@suse.de","sentAt":"2025-07-17T07:03:50Z","receivedAt":"2025-07-17T07:03:52Z","isPatch":true,"sender":{"key":"tiwai@suse.de","avatar":"https://avatars.githubusercontent.com/u/306482?v=4"},"body":"On Wed, 16 Jul 2025 19:38:34 +0200,\nJohannes Sixt wrote:\n> \n> Am 16.07.25 um 09:32 schrieb Takashi Iwai:\n> > Here is the v3 patch for git-gui to support SHA256 repos.\n> > I put a preliminary patch to clean up $null_sha1 in addition to the\n> > correction / update of v2 patch.\n> \n> Thanks, queued.\n> \n> I applied the following fixups: an obvious typo-fix in a comment and use\n> of our wrapper function `git` instead of plain Tcl `exec git`.\n> \n> diff --git a/git-gui.sh b/git-gui.sh\n> index c437980927fd..523e4df8069a 100755\n> --- a/git-gui.sh\n> +++ b/git-gui.sh\n> @@ -1298,8 +1298,8 @@ 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> +# Use object format as hash algorithm (either \"sha1\" or \"sha256\")\n> +set hashalgorithm [git rev-parse --show-object-format]\n>  if {$hashalgorithm eq \"sha1\"} {\n>  \tset hashlength 40\n>  } elseif {$hashalgorithm eq \"sha256\"} {\n\nThanks!\n\n\nTakashi\n"}]}