git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] git-gui: Add support of SHA256 repo
@ 2025-07-16  7:32 Takashi Iwai
  2025-07-16  7:32 ` [PATCH v3 1/2] git-gui: Replace null_sha1 with nullid Takashi Iwai
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Takashi Iwai @ 2025-07-16  7:32 UTC (permalink / raw)
  To: git; +Cc: Johannes Sixt

Here is the v3 patch for git-gui to support SHA256 repos.
I put a preliminary patch to clean up $null_sha1 in addition to the
correction / update of v2 patch.


Takashi

===

Takashi Iwai (2):
  git-gui: Replace null_sha1 with nullid
  git-gui: Add support of SHA256 repo

 git-gui/git-gui.sh                   | 22 ++++++++++++++++------
 git-gui/lib/blame.tcl                | 12 ++++++++----
 git-gui/lib/checkout_op.tcl          |  4 ++--
 git-gui/lib/choose_repository.tcl    |  7 ++++---
 git-gui/lib/commit.tcl               |  3 ++-
 git-gui/lib/remote_branch_delete.tcl |  4 +++-
 6 files changed, 35 insertions(+), 17 deletions(-)

-- 
2.50.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/2] git-gui: Replace null_sha1 with nullid
  2025-07-16  7:32 [PATCH v3 0/2] git-gui: Add support of SHA256 repo Takashi Iwai
@ 2025-07-16  7:32 ` Takashi Iwai
  2025-07-16  7:32 ` [PATCH v3 2/2] git-gui: Add support of SHA256 repo Takashi Iwai
  2025-07-16 17:38 ` [PATCH v3 0/2] " Johannes Sixt
  2 siblings, 0 replies; 5+ messages in thread
From: Takashi Iwai @ 2025-07-16  7:32 UTC (permalink / raw)
  To: git; +Cc: Johannes Sixt

Both $nullid and $null_sha1 point to the same content.
Use only $nullid consistently.

This is a preliminary cleanup for adding the support of SHA256 repo.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
v3: new patch

 git-gui/git-gui.sh          | 5 ++---
 git-gui/lib/checkout_op.tcl | 4 ++--
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index c77c05edde3b..413a8a9abc1f 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -1845,10 +1845,9 @@ proc short_path {path} {
 }
 
 set next_icon_id 0
-set null_sha1 [string repeat 0 40]
 
 proc merge_state {path new_state {head_info {}} {index_info {}}} {
-	global file_states next_icon_id null_sha1
+	global file_states next_icon_id nullid
 
 	set s0 [string index $new_state 0]
 	set s1 [string index $new_state 1]
@@ -1870,7 +1869,7 @@ proc merge_state {path new_state {head_info {}} {index_info {}}} {
 	elseif {$s1 eq {_}} {set s1 _}
 
 	if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
-		set head_info [list 0 $null_sha1]
+		set head_info [list 0 $nullid]
 	} elseif {$s0 ne {_} && [string index $state 0] eq {_}
 		&& $head_info eq {}} {
 		set head_info $index_info
diff --git a/git-gui/lib/checkout_op.tcl b/git-gui/lib/checkout_op.tcl
index 87ed0b48585e..987486a4b602 100644
--- a/git-gui/lib/checkout_op.tcl
+++ b/git-gui/lib/checkout_op.tcl
@@ -151,7 +151,7 @@ method _finish_fetch {ok} {
 }
 
 method _update_ref {} {
-	global null_sha1 current_branch repo_config
+	global nullid current_branch repo_config
 
 	set ref $new_ref
 	set new $new_hash
@@ -177,7 +177,7 @@ method _update_ref {} {
 		}
 
 		set reflog_msg "branch: Created from $new_expr"
-		set cur $null_sha1
+		set cur $nullid
 
 		if {($repo_config(branch.autosetupmerge) eq {true}
 			|| $repo_config(branch.autosetupmerge) eq {always})
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/2] git-gui: Add support of SHA256 repo
  2025-07-16  7:32 [PATCH v3 0/2] git-gui: Add support of SHA256 repo Takashi Iwai
  2025-07-16  7:32 ` [PATCH v3 1/2] git-gui: Replace null_sha1 with nullid Takashi Iwai
@ 2025-07-16  7:32 ` Takashi Iwai
  2025-07-16 17:38 ` [PATCH v3 0/2] " Johannes Sixt
  2 siblings, 0 replies; 5+ messages in thread
From: Takashi Iwai @ 2025-07-16  7:32 UTC (permalink / raw)
  To: git; +Cc: Johannes Sixt

This patch adds the basic support of SHA256 Git repositories.
Most of changes are idiomatic replacement of the hard-coded hash ID
length, but there are subtle things:

* The hash length is determined on startup, and stored in $hashlength
  global variable (either 40 or 64).
* The hard-coded "40" are replaced with $hashlength;
  for regexp patterns, the ugly string map is used.
* Some code have the fixed numbers like 39 and 45, and those are
  replaced with the $hashlength and the offset correction.
* $nullid and $nullid2 are generated for the hash length.

A caveat is that repository picker dialog is performed before
evaluating the repo type, hence $hashlength isn't set there yet.
So the code dealing with the hard-coded "40" are handled differently;
namely, the regexp range is expanded, and the null id is generated
from the HEAD id length locally.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
v2->v3:
* add more texts to patch descriptions
* fix $nullid and $nullid2, too
* fix abbrev id check in blame
* don't refer to $hashlength in repo picker code

 git-gui/git-gui.sh                   | 17 ++++++++++++++---
 git-gui/lib/blame.tcl                | 12 ++++++++----
 git-gui/lib/choose_repository.tcl    |  7 ++++---
 git-gui/lib/commit.tcl               |  3 ++-
 git-gui/lib/remote_branch_delete.tcl |  4 +++-
 5 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index 413a8a9abc1f..c437980927fd 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -1298,6 +1298,17 @@ if {[catch {
 	set picked 1
 }
 
+# Use object format as hash algorightm (either "sha1" or "sha256")
+set hashalgorithm [exec git rev-parse --show-object-format]
+if {$hashalgorithm eq "sha1"} {
+	set hashlength 40
+} elseif {$hashalgorithm eq "sha256"} {
+	set hashlength 64
+} else {
+	puts stderr "Unknown hash algorithm: $hashalgorithm"
+	exit 1
+}
+
 # we expand the _gitdir when it's just a single dot (i.e. when we're being
 # run from the .git dir itself) lest the routines to find the worktree
 # get confused
@@ -1391,8 +1402,8 @@ set is_conflict_diff 0
 set last_revert {}
 set last_revert_enc {}
 
-set nullid "0000000000000000000000000000000000000000"
-set nullid2 "0000000000000000000000000000000000000001"
+set nullid [string repeat 0 $hashlength]
+set nullid2 "[string repeat 0 [expr $hashlength - 1]]1"
 
 ######################################################################
 ##
@@ -3202,7 +3213,7 @@ blame {
 	if {$head eq {}} {
 		load_current_branch
 	} else {
-		if {[regexp {^[0-9a-f]{1,39}$} $head]} {
+		if {[regexp [string map "@@ [expr $hashlength - 1]" {^[0-9a-f]{1,@@}$}] $head]} {
 			if {[catch {
 					set head [git rev-parse --verify $head]
 				} err]} {
diff --git a/git-gui/lib/blame.tcl b/git-gui/lib/blame.tcl
index d6fd8bea91ff..5507681da7ba 100644
--- a/git-gui/lib/blame.tcl
+++ b/git-gui/lib/blame.tcl
@@ -426,6 +426,7 @@ method _kill {} {
 
 method _load {jump} {
 	variable group_colors
+	global hashlength
 
 	_hide_tooltip $this
 
@@ -436,7 +437,7 @@ method _load {jump} {
 			$i conf -state normal
 			$i delete 0.0 end
 			foreach g [$i tag names] {
-				if {[regexp {^g[0-9a-f]{40}$} $g]} {
+				if {[regexp [string map "@@ $hashlength" {^g[0-9a-f]{@@}$}] $g]} {
 					$i tag delete $g
 				}
 			}
@@ -500,6 +501,8 @@ method _load {jump} {
 }
 
 method _history_menu {} {
+	global hashlength
+
 	set m $w.backmenu
 	if {[winfo exists $m]} {
 		$m delete 0 end
@@ -513,7 +516,7 @@ method _history_menu {} {
 		set c [lindex $e 0]
 		set f [lindex $e 1]
 
-		if {[regexp {^[0-9a-f]{40}$} $c]} {
+		if {[regexp [string map "@@ $hashlength" {^[0-9a-f]{@@}$}] $c]} {
 			set t [string range $c 0 8]...
 		} elseif {$c eq {}} {
 			set t {Working Directory}
@@ -627,6 +630,7 @@ method _exec_blame {cur_w cur_d options cur_s} {
 method _read_blame {fd cur_w cur_d} {
 	upvar #0 $cur_d line_data
 	variable group_colors
+	global hashlength nullid
 
 	if {$fd ne $current_fd} {
 		catch {close $fd}
@@ -635,7 +639,7 @@ method _read_blame {fd cur_w cur_d} {
 
 	$cur_w conf -state normal
 	while {[gets $fd line] >= 0} {
-		if {[regexp {^([a-z0-9]{40}) (\d+) (\d+) (\d+)$} $line line \
+		if {[regexp [string map "@@ $hashlength" {^([a-z0-9]{@@}) (\d+) (\d+) (\d+)$}] $line line \
 			cmit original_line final_line line_count]} {
 			set r_commit     $cmit
 			set r_orig_line  $original_line
@@ -648,7 +652,7 @@ method _read_blame {fd cur_w cur_d} {
 			set oln  $r_orig_line
 			set cmit $r_commit
 
-			if {[regexp {^0{40}$} $cmit]} {
+			if {$cmit eq $nullid} {
 				set commit_abbr work
 				set commit_type curr_commit
 			} elseif {$cmit eq $commit} {
diff --git a/git-gui/lib/choose_repository.tcl b/git-gui/lib/choose_repository.tcl
index 5b361cc424a6..877ca4888f7a 100644
--- a/git-gui/lib/choose_repository.tcl
+++ b/git-gui/lib/choose_repository.tcl
@@ -879,7 +879,7 @@ method _do_clone_full_end {ok} {
 		if {[file exists [gitdir FETCH_HEAD]]} {
 			set fd [safe_open_file [gitdir FETCH_HEAD] r]
 			while {[gets $fd line] >= 0} {
-				if {[regexp "^(.{40})\t\t" $line line HEAD]} {
+				if {[regexp "^(.{40,64})\t\t" $line line HEAD]} {
 					break
 				}
 			}
@@ -987,8 +987,9 @@ method _readtree_wait {fd} {
 
 	# -- Run the post-checkout hook.
 	#
-	set fd_ph [githook_read post-checkout [string repeat 0 40] \
-		[git rev-parse HEAD] 1]
+	set head_id [git rev-parse HEAD]
+	set fd_ph [githook_read post-checkout \
+		[string repeat 0 [string length $head_id]] $head_id 1]
 	if {$fd_ph ne {}} {
 		global pch_error
 		set pch_error {}
diff --git a/git-gui/lib/commit.tcl b/git-gui/lib/commit.tcl
index 60d66172a100..7c800a4bc37a 100644
--- a/git-gui/lib/commit.tcl
+++ b/git-gui/lib/commit.tcl
@@ -348,6 +348,7 @@ proc commit_committree {fd_wt curHEAD msg_p} {
 	global file_states selected_paths rescan_active
 	global repo_config
 	global env
+	global hashlength
 
 	gets $fd_wt tree_id
 	if {[catch {close $fd_wt} err]} {
@@ -367,7 +368,7 @@ proc commit_committree {fd_wt curHEAD msg_p} {
 		close $fd_ot
 
 		if {[string equal -length 5 {tree } $old_tree]
-			&& [string length $old_tree] == 45} {
+			&& [string length $old_tree] == [expr {$hashlength + 5}]} {
 			set old_tree [string range $old_tree 5 end]
 		} else {
 			error [mc "Commit %s appears to be corrupt" $PARENT]
diff --git a/git-gui/lib/remote_branch_delete.tcl b/git-gui/lib/remote_branch_delete.tcl
index c8c99b17a8da..781980d66cc8 100644
--- a/git-gui/lib/remote_branch_delete.tcl
+++ b/git-gui/lib/remote_branch_delete.tcl
@@ -323,6 +323,8 @@ method _load {cache uri} {
 }
 
 method _read {cache fd} {
+	global hashlength
+
 	if {$fd ne $active_ls} {
 		catch {close $fd}
 		return
@@ -330,7 +332,7 @@ method _read {cache fd} {
 
 	while {[gets $fd line] >= 0} {
 		if {[string match {*^{}} $line]} continue
-		if {[regexp {^([0-9a-f]{40})	(.*)$} $line _junk obj ref]} {
+		if {[regexp [string map "@@ $hashlength" {^([0-9a-f]{@@})	(.*)$}] $line _junk obj ref]} {
 			if {[regsub ^refs/heads/ $ref {} abr]} {
 				lappend head_list $abr
 				lappend head_cache($cache) $abr
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 0/2] git-gui: Add support of SHA256 repo
  2025-07-16  7:32 [PATCH v3 0/2] git-gui: Add support of SHA256 repo Takashi Iwai
  2025-07-16  7:32 ` [PATCH v3 1/2] git-gui: Replace null_sha1 with nullid Takashi Iwai
  2025-07-16  7:32 ` [PATCH v3 2/2] git-gui: Add support of SHA256 repo Takashi Iwai
@ 2025-07-16 17:38 ` Johannes Sixt
  2025-07-17  7:03   ` Takashi Iwai
  2 siblings, 1 reply; 5+ messages in thread
From: Johannes Sixt @ 2025-07-16 17:38 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: git

Am 16.07.25 um 09:32 schrieb Takashi Iwai:
> Here is the v3 patch for git-gui to support SHA256 repos.
> I put a preliminary patch to clean up $null_sha1 in addition to the
> correction / update of v2 patch.

Thanks, queued.

I applied the following fixups: an obvious typo-fix in a comment and use
of our wrapper function `git` instead of plain Tcl `exec git`.

diff --git a/git-gui.sh b/git-gui.sh
index c437980927fd..523e4df8069a 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -1298,8 +1298,8 @@ if {[catch {
 	set picked 1
 }
 
-# Use object format as hash algorightm (either "sha1" or "sha256")
-set hashalgorithm [exec git rev-parse --show-object-format]
+# Use object format as hash algorithm (either "sha1" or "sha256")
+set hashalgorithm [git rev-parse --show-object-format]
 if {$hashalgorithm eq "sha1"} {
 	set hashlength 40
 } elseif {$hashalgorithm eq "sha256"} {


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 0/2] git-gui: Add support of SHA256 repo
  2025-07-16 17:38 ` [PATCH v3 0/2] " Johannes Sixt
@ 2025-07-17  7:03   ` Takashi Iwai
  0 siblings, 0 replies; 5+ messages in thread
From: Takashi Iwai @ 2025-07-17  7:03 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Takashi Iwai, git

On Wed, 16 Jul 2025 19:38:34 +0200,
Johannes Sixt wrote:
> 
> Am 16.07.25 um 09:32 schrieb Takashi Iwai:
> > Here is the v3 patch for git-gui to support SHA256 repos.
> > I put a preliminary patch to clean up $null_sha1 in addition to the
> > correction / update of v2 patch.
> 
> Thanks, queued.
> 
> I applied the following fixups: an obvious typo-fix in a comment and use
> of our wrapper function `git` instead of plain Tcl `exec git`.
> 
> diff --git a/git-gui.sh b/git-gui.sh
> index c437980927fd..523e4df8069a 100755
> --- a/git-gui.sh
> +++ b/git-gui.sh
> @@ -1298,8 +1298,8 @@ if {[catch {
>  	set picked 1
>  }
>  
> -# Use object format as hash algorightm (either "sha1" or "sha256")
> -set hashalgorithm [exec git rev-parse --show-object-format]
> +# Use object format as hash algorithm (either "sha1" or "sha256")
> +set hashalgorithm [git rev-parse --show-object-format]
>  if {$hashalgorithm eq "sha1"} {
>  	set hashlength 40
>  } elseif {$hashalgorithm eq "sha256"} {

Thanks!


Takashi

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-07-17  7:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-16  7:32 [PATCH v3 0/2] git-gui: Add support of SHA256 repo Takashi Iwai
2025-07-16  7:32 ` [PATCH v3 1/2] git-gui: Replace null_sha1 with nullid Takashi Iwai
2025-07-16  7:32 ` [PATCH v3 2/2] git-gui: Add support of SHA256 repo Takashi Iwai
2025-07-16 17:38 ` [PATCH v3 0/2] " Johannes Sixt
2025-07-17  7:03   ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).