diff mbox series

[3/3] filter-branch: drop $_x40 glob

Message ID YEj82fOf+F4xJC8S@coredump.intra.peff.net (mailing list archive)
State Accepted
Commit 42efa1231aee85932058cc6d1571ab4ceb3e7eff
Headers show
Series sha256 fixes for filter-branch | expand

Commit Message

Jeff King March 10, 2021, 5:07 p.m. UTC
When checking whether a commit was rewritten to a single object id, we
use a glob that insists on a 40-hex result. This works for sha1, but
fails t7003 when run with GIT_TEST_DEFAULT_HASH=sha256.

Since the previous commit simplified the case statement here, we only
have two arms: an empty string or a single object id. We can just loosen
our glob to match anything, and still distinguish those cases (we lose
the ability to notice bogus input, but that's not a problem; we are the
one who wrote the map in the first place, and anyway update-ref will
complain loudly if the input isn't a valid hash).

Signed-off-by: Jeff King <peff@peff.net>
---
 git-filter-branch.sh | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

Comments

Junio C Hamano March 10, 2021, 10:23 p.m. UTC | #1
Jeff King <peff@peff.net> writes:

> When checking whether a commit was rewritten to a single object id, we
> use a glob that insists on a 40-hex result. This works for sha1, but
> fails t7003 when run with GIT_TEST_DEFAULT_HASH=sha256.
>
> Since the previous commit simplified the case statement here, we only
> have two arms: an empty string or a single object id. We can just loosen
> our glob to match anything, and still distinguish those cases (we lose
> the ability to notice bogus input, but that's not a problem; we are the
> one who wrote the map in the first place, and anyway update-ref will
> complain loudly if the input isn't a valid hash).

If the input is any valid extended sha-1 expression, it probably
would not barf, so we technically are losing a bit of internal
safety valve to notice bogus rewrite (if the map recorded output of
"git describe --always", this part would not notice and keep working
just fine, but other parts of the code may not be happy).

But if this were a new code that said "It is either empty of non-empty,
and non-empty ones are object names we write, so we do not have to
insist it is hex object names", it is very likely that we would
accept it without any extra checks, so I think this is perfectly OK.

Thanks.

> Signed-off-by: Jeff King <peff@peff.net>
> ---
>  git-filter-branch.sh | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/git-filter-branch.sh b/git-filter-branch.sh
> index a1e80bd552..cb89372813 100755
> --- a/git-filter-branch.sh
> +++ b/git-filter-branch.sh
> @@ -498,8 +498,6 @@ fi
>  
>  # Finally update the refs
>  
> -_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
> -_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
>  echo
>  while read ref
>  do
> @@ -519,7 +517,7 @@ do
>  		git update-ref -m "filter-branch: delete" -d "$ref" $sha1 ||
>  			die "Could not delete $ref"
>  	;;
> -	$_x40)
> +	*)
>  		echo "Ref '$ref' was rewritten"
>  		if ! git update-ref -m "filter-branch: rewrite" \
>  					"$ref" $rewritten $sha1 2>/dev/null; then
> @@ -533,9 +531,6 @@ do
>  			fi
>  		fi
>  	;;
> -	*)
> -		die "BUG: multiple ancestors in map file?"
> -	;;
>  	esac
>  	git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1 ||
>  		 exit
diff mbox series

Patch

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index a1e80bd552..cb89372813 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -498,8 +498,6 @@  fi
 
 # Finally update the refs
 
-_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
-_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
 echo
 while read ref
 do
@@ -519,7 +517,7 @@  do
 		git update-ref -m "filter-branch: delete" -d "$ref" $sha1 ||
 			die "Could not delete $ref"
 	;;
-	$_x40)
+	*)
 		echo "Ref '$ref' was rewritten"
 		if ! git update-ref -m "filter-branch: rewrite" \
 					"$ref" $rewritten $sha1 2>/dev/null; then
@@ -533,9 +531,6 @@  do
 			fi
 		fi
 	;;
-	*)
-		die "BUG: multiple ancestors in map file?"
-	;;
 	esac
 	git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1 ||
 		 exit