Skip to content

Commit 9ab3315

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Acked-by: Eric Wong <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 148f193 commit 9ab3315

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

git-svn.perl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
use warnings;
66
use strict;
77
use vars qw/ $AUTHOR $VERSION
8-
$sha1 $sha1_short $_revision $_repository
8+
$oid $oid_short $oid_length
9+
$_revision $_repository
910
$_q $_authors $_authors_prog %users/;
1011
$AUTHOR = 'Eric Wong <[email protected]>';
1112
$VERSION = '@@GIT_VERSION@@';
@@ -103,8 +104,9 @@ sub _req_svn {
103104
}
104105
}
105106

106-
$sha1 = qr/[a-f\d]{40}/;
107-
$sha1_short = qr/[a-f\d]{4,40}/;
107+
$oid = qr/(?:[a-f\d]{40}(?:[a-f\d]{24})?)/;
108+
$oid_short = qr/[a-f\d]{4,64}/;
109+
$oid_length = 40;
108110
my ($_stdin, $_help, $_edit,
109111
$_message, $_file, $_branch_dest,
110112
$_template, $_shared,
@@ -582,7 +584,7 @@ sub cmd_set_tree {
582584
print "Reading from stdin...\n";
583585
@commits = ();
584586
while (<STDIN>) {
585-
if (/\b($sha1_short)\b/o) {
587+
if (/\b($oid_short)\b/o) {
586588
unshift @commits, $1;
587589
}
588590
}
@@ -1831,7 +1833,7 @@ sub get_tree_from_treeish {
18311833
if ($type eq 'commit') {
18321834
$expected = (grep /^tree /, command(qw/cat-file commit/,
18331835
$treeish))[0];
1834-
($expected) = ($expected =~ /^tree ($sha1)$/o);
1836+
($expected) = ($expected =~ /^tree ($oid)$/o);
18351837
die "Unable to get tree from $treeish\n" unless $expected;
18361838
} elsif ($type eq 'tree') {
18371839
$expected = $treeish;
@@ -2036,7 +2038,7 @@ sub working_head_info {
20362038
my $hash;
20372039
my %max;
20382040
while (<$fh>) {
2039-
if ( m{^commit ($::sha1)$} ) {
2041+
if ( m{^commit ($::oid)$} ) {
20402042
unshift @$refs, $hash if $hash and $refs;
20412043
$hash = $1;
20422044
next;

perl/Git/SVN.pm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ sub assert_index_clean {
874874
command_noisy('read-tree', $treeish) unless -e $self->{index};
875875
my $x = command_oneline('write-tree');
876876
my ($y) = (command(qw/cat-file commit/, $treeish) =~
877-
/^tree ($::sha1)/mo);
877+
/^tree ($::oid)/mo);
878878
return if $y eq $x;
879879

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

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

10551055
$self->rev_map_set($log_entry->{revision}, $commit, 1);
@@ -2150,7 +2150,7 @@ sub rebuild {
21502150
my $svn_uuid = $self->rewrite_uuid || $self->ra_uuid;
21512151
my $c;
21522152
while (<$log>) {
2153-
if ( m{^commit ($::sha1)$} ) {
2153+
if ( m{^commit ($::oid)$} ) {
21542154
$c = $1;
21552155
next;
21562156
}

perl/Git/SVN/Editor.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ sub generate_diff {
6363
my @mods;
6464
while (defined($_ = get_record($diff_fh, "\0"))) {
6565
if ($state eq 'meta' && /^:(\d{6})\s(\d{6})\s
66-
($::sha1)\s($::sha1)\s
66+
($::oid)\s($::oid)\s
6767
([MTCRAD])\d*$/xo) {
6868
push @mods, { mode_a => $1, mode_b => $2,
6969
sha1_a => $3, sha1_b => $4,

perl/Git/SVN/Log.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ sub cmd_show_log {
285285
my (@k, $c, $d, $stat);
286286
my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
287287
while (<$log>) {
288-
if (/^${esc_color}commit (?:- )?($::sha1_short)/o) {
288+
if (/^${esc_color}commit (?:- )?($::oid_short)/o) {
289289
my $cmt = $1;
290290
if ($c && cmt_showable($c) && $c->{r} != $r_last) {
291291
$r_last = $c->{r};

0 commit comments

Comments
 (0)