Skip to content

Commit

Permalink
perl: create and switch variables for hash constants
Browse files Browse the repository at this point in the history
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 <sandals@crustytoothpaste.net>
Acked-by: Eric Wong <e@80x24.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
bk2204 authored and gitster committed Jun 22, 2020
1 parent 148f193 commit 9ab3315
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
14 changes: 8 additions & 6 deletions git-svn.perl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
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 <normalperson@yhbt.net>';
$VERSION = '@@GIT_VERSION@@';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -582,7 +584,7 @@ sub cmd_set_tree {
print "Reading from stdin...\n";
@commits = ();
while (<STDIN>) {
if (/\b($sha1_short)\b/o) {
if (/\b($oid_short)\b/o) {
unshift @commits, $1;
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions perl/Git/SVN.pm
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ sub assert_index_clean {
command_noisy('read-tree', $treeish) unless -e $self->{index};
my $x = command_oneline('write-tree');
my ($y) = (command(qw/cat-file commit/, $treeish) =~
/^tree ($::sha1)/mo);
/^tree ($::oid)/mo);
return if $y eq $x;

warn "Index mismatch: $y != $x\nrereading $treeish\n";
Expand Down Expand Up @@ -1020,7 +1020,7 @@ sub do_git_commit {
$tree = $self->tmp_index_do(sub {
command_oneline('write-tree') });
}
die "Tree is not a valid sha1: $tree\n" if $tree !~ /^$::sha1$/o;
die "Tree is not a valid oid $tree\n" if $tree !~ /^$::oid$/o;

my @exec = ('git', 'commit-tree', $tree);
foreach ($self->get_commit_parents($log_entry)) {
Expand Down Expand Up @@ -1048,8 +1048,8 @@ sub do_git_commit {
close $out_fh or croak $!;
waitpid $pid, 0;
croak $? if $?;
if ($commit !~ /^$::sha1$/o) {
die "Failed to commit, invalid sha1: $commit\n";
if ($commit !~ /^$::oid$/o) {
die "Failed to commit, invalid oid: $commit\n";
}

$self->rev_map_set($log_entry->{revision}, $commit, 1);
Expand Down Expand Up @@ -2150,7 +2150,7 @@ sub rebuild {
my $svn_uuid = $self->rewrite_uuid || $self->ra_uuid;
my $c;
while (<$log>) {
if ( m{^commit ($::sha1)$} ) {
if ( m{^commit ($::oid)$} ) {
$c = $1;
next;
}
Expand Down
2 changes: 1 addition & 1 deletion perl/Git/SVN/Editor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ sub generate_diff {
my @mods;
while (defined($_ = get_record($diff_fh, "\0"))) {
if ($state eq 'meta' && /^:(\d{6})\s(\d{6})\s
($::sha1)\s($::sha1)\s
($::oid)\s($::oid)\s
([MTCRAD])\d*$/xo) {
push @mods, { mode_a => $1, mode_b => $2,
sha1_a => $3, sha1_b => $4,
Expand Down
2 changes: 1 addition & 1 deletion perl/Git/SVN/Log.pm
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ sub cmd_show_log {
my (@k, $c, $d, $stat);
my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
while (<$log>) {
if (/^${esc_color}commit (?:- )?($::sha1_short)/o) {
if (/^${esc_color}commit (?:- )?($::oid_short)/o) {
my $cmt = $1;
if ($c && cmt_showable($c) && $c->{r} != $r_last) {
$r_last = $c->{r};
Expand Down

0 comments on commit 9ab3315

Please sign in to comment.