git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 3/4] expand regexp matching an oid to be hash agnostic

From
Carlo Marcelo Arenas Belón <carenas@gmail.com>
Date
Oct 11, 2021, 12:17 UTC
Message-ID
<20211011121757.627-4-carenas@gmail.com>
In-Reply-To
<20211011121757.627-1-carenas@gmail.com>

Before this change, listing or blame will fail as it couldn't find the OID in an SHA-256 repository.

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
 lib/blame.tcl                | 8 ++++----
 lib/choose_repository.tcl    | 2 +-
 lib/remote_branch_delete.tcl | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/lib/blame.tcl b/lib/blame.tcl
index e6d4302..ee7db9d 100644
--- a/lib/blame.tcl
+++ b/lib/blame.tcl
@@ -436,7 +436,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 {^g[0-9a-f]{40}(?:[0-9a-f]{24})?$} $g]} {
 					$i tag delete $g
 				}
 			}
@@ -513,7 +513,7 @@ method _history_menu {} {
 		set c [lindex $e 0]
 		set f [lindex $e 1]
 
-		if {[regexp {^[0-9a-f]{40}$} $c]} {
+		if {[regexp {^[0-9a-f]{40}(?:[0-9a-f]{24})?$} $c]} {
 			set t [string range $c 0 8]...
 		} elseif {$c eq {}} {
 			set t {Working Directory}
@@ -635,7 +635,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 {^([a-z0-9]{40}(?:[0-9a-f]{24})?) (\d+) (\d+) (\d+)$} $line line \
 			cmit original_line final_line line_count]} {
 			set r_commit     $cmit
 			set r_orig_line  $original_line
@@ -648,7 +648,7 @@ method _read_blame {fd cur_w cur_d} {
 			set oln  $r_orig_line
 			set cmit $r_commit
 
-			if {[regexp {^0{40}$} $cmit]} {
+			if {[regexp {^0{40}(?:0{24})?$} $cmit]} {
 				set commit_abbr work
 				set commit_type curr_commit
 			} elseif {$cmit eq $commit} {
diff --git a/lib/choose_repository.tcl b/lib/choose_repository.tcl
index af1fee7..e864f38 100644
--- a/lib/choose_repository.tcl
+++ b/lib/choose_repository.tcl
@@ -904,7 +904,7 @@ method _do_clone_full_end {ok} {
 		if {[file exists [gitdir FETCH_HEAD]]} {
 			set fd [open [gitdir FETCH_HEAD] r]
 			while {[gets $fd line] >= 0} {
-				if {[regexp "^(.{40})\t\t" $line line HEAD]} {
+				if {[regexp "^([0-9a-fA-F]{40}(?:[0-9a-fA-F]{24})?)\t\t" $line line HEAD]} {
 					break
 				}
 			}
diff --git a/lib/remote_branch_delete.tcl b/lib/remote_branch_delete.tcl
index 5ba9fca..57bae9c 100644
--- a/lib/remote_branch_delete.tcl
+++ b/lib/remote_branch_delete.tcl
@@ -330,7 +330,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 {^([0-9a-fA-F]{40}(?:[0-9a-fA-F]{24})?)	(.*)$} $line _junk obj ref]} {
 			if {[regsub ^refs/heads/ $ref {} abr]} {
 				lappend head_list $abr
 				lappend head_cache($cache) $abr
-- 
2.33.0.1081.g099423f5b7
Previous: Pratyush YadavNext: Pratyush Yadav
Message 7 of 14 in “git-gui: support SHA-256 repositories”
  1. 0/4 git-gui: support SHA-256 repositoriesCarlo Marcelo Arenas Belón, Oct 11, 2021
  2. 1/4 blame: prefer null_sha1 over nullid and retire laterCarlo Marcelo Arenas Belón, Oct 11, 2021
  3. Pratyush YadavOct 27, 2021
  4. 2/4 rename all *_sha1 variables and make null_oid hash awareCarlo Marcelo Arenas Belón, Oct 11, 2021
  5. Eric SunshineOct 11, 2021
  6. Pratyush YadavNov 13, 2021
  7. 3/4 expand regexp matching an oid to be hash agnosticCarlo Marcelo Arenas Belón, Oct 11, 2021
  8. Pratyush YadavNov 13, 2021
  9. 4/4 track oid_size to allow for checks that are hash agnosticCarlo Marcelo Arenas Belón, Oct 11, 2021
  10. Pratyush YadavNov 13, 2021
  11. Pratyush YadavNov 13, 2021
  12. Ævar Arnfjörð BjarmasonOct 11, 2021
  13. Carlo ArenasOct 11, 2021
  14. Pratyush YadavNov 13, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.