From 9ab33150a0d14089d0496dd8354d4a969e849571 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 22 Jun 2020 18:04:12 +0000 Subject: perl: create and switch variables for hash constants git-svn has several variables for SHA-1 constants, including short hash values and full length hash values. Since these are no longer SHA-1 specific, let's start them with "oid" instead of "sha1". Add a constant, oid_length, which is the length of the hash algorithm in use in hex. We use the hex version because overwhelmingly that's what's used by git-svn. We don't currently set oid_length based on the repository algorithm, but we will in a future commit. Signed-off-by: brian m. carlson Acked-by: Eric Wong Signed-off-by: Junio C Hamano --- git-svn.perl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'git-svn.perl') diff --git a/git-svn.perl b/git-svn.perl index 4aa208ff5f..7c735cebd3 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -5,7 +5,8 @@ use 5.008; use warnings; use strict; use vars qw/ $AUTHOR $VERSION - $sha1 $sha1_short $_revision $_repository + $oid $oid_short $oid_length + $_revision $_repository $_q $_authors $_authors_prog %users/; $AUTHOR = 'Eric Wong '; $VERSION = '@@GIT_VERSION@@'; @@ -103,8 +104,9 @@ sub _req_svn { } } -$sha1 = qr/[a-f\d]{40}/; -$sha1_short = qr/[a-f\d]{4,40}/; +$oid = qr/(?:[a-f\d]{40}(?:[a-f\d]{24})?)/; +$oid_short = qr/[a-f\d]{4,64}/; +$oid_length = 40; my ($_stdin, $_help, $_edit, $_message, $_file, $_branch_dest, $_template, $_shared, @@ -582,7 +584,7 @@ sub cmd_set_tree { print "Reading from stdin...\n"; @commits = (); while () { - if (/\b($sha1_short)\b/o) { + if (/\b($oid_short)\b/o) { unshift @commits, $1; } } @@ -1831,7 +1833,7 @@ sub get_tree_from_treeish { if ($type eq 'commit') { $expected = (grep /^tree /, command(qw/cat-file commit/, $treeish))[0]; - ($expected) = ($expected =~ /^tree ($sha1)$/o); + ($expected) = ($expected =~ /^tree ($oid)$/o); die "Unable to get tree from $treeish\n" unless $expected; } elsif ($type eq 'tree') { $expected = $treeish; @@ -2036,7 +2038,7 @@ sub working_head_info { my $hash; my %max; while (<$fh>) { - if ( m{^commit ($::sha1)$} ) { + if ( m{^commit ($::oid)$} ) { unshift @$refs, $hash if $hash and $refs; $hash = $1; next; -- cgit v1.2.3