@matheusbsbs / matheus-bagliano / commits / 9ab33150a0
Fork 0

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 <sandals@crustytoothpaste.net> Acked-by: Eric Wong <e@80x24.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Jun 22, 2020 at 18:04 UTC 9ab33150a0d14089d0496dd8354d4a969e849571
4 files changed +15 -13
git-svn.perl
+8 -6
@@ -5,7 +5,8 @@ use 5.008;
5 use warnings;
6 use strict;
7 use vars qw/ $AUTHOR $VERSION
8 - $sha1 $sha1_short $_revision $_repository
8 + $oid $oid_short $oid_length
9 + $_revision $_repository
10 $_q $_authors $_authors_prog %users/;
11 $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
12 $VERSION = '@@GIT_VERSION@@';
@@ -103,8 +104,9 @@ sub _req_svn {
104 }
105 }
106
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;
110 my ($_stdin, $_help, $_edit,
111 $_message, $_file, $_branch_dest,
112 $_template, $_shared,
@@ -582,7 +584,7 @@ sub cmd_set_tree {
584 print "Reading from stdin...\n";
585 @commits = ();
586 while (<STDIN>) {
585 - if (/\b($sha1_short)\b/o) {
587 + if (/\b($oid_short)\b/o) {
588 unshift @commits, $1;
589 }
590 }
@@ -1831,7 +1833,7 @@ sub get_tree_from_treeish {
1833 if ($type eq 'commit') {
1834 $expected = (grep /^tree /, command(qw/cat-file commit/,
1835 $treeish))[0];
1834 - ($expected) = ($expected =~ /^tree ($sha1)$/o);
1836 + ($expected) = ($expected =~ /^tree ($oid)$/o);
1837 die "Unable to get tree from $treeish\n" unless $expected;
1838 } elsif ($type eq 'tree') {
1839 $expected = $treeish;
@@ -2036,7 +2038,7 @@ sub working_head_info {
2038 my $hash;
2039 my %max;
2040 while (<$fh>) {
2039 - if ( m{^commit ($::sha1)$} ) {
2041 + if ( m{^commit ($::oid)$} ) {
2042 unshift @$refs, $hash if $hash and $refs;
2043 $hash = $1;
2044 next;
perl/Git/SVN.pm
+5 -5
@@ -874,7 +874,7 @@ sub assert_index_clean {
874 command_noisy('read-tree', $treeish) unless -e $self->{index};
875 my $x = command_oneline('write-tree');
876 my ($y) = (command(qw/cat-file commit/, $treeish) =~
877 - /^tree ($::sha1)/mo);
877 + /^tree ($::oid)/mo);
878 return if $y eq $x;
879
880 warn "Index mismatch: $y != $x\nrereading $treeish\n";
@@ -1020,7 +1020,7 @@ sub do_git_commit {
1020 $tree = $self->tmp_index_do(sub {
1021 command_oneline('write-tree') });
1022 }
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;
1024
1025 my @exec = ('git', 'commit-tree', $tree);
1026 foreach ($self->get_commit_parents($log_entry)) {
@@ -1048,8 +1048,8 @@ sub do_git_commit {
1048 close $out_fh or croak $!;
1049 waitpid $pid, 0;
1050 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";
1053 }
1054
1055 $self->rev_map_set($log_entry->{revision}, $commit, 1);
@@ -2150,7 +2150,7 @@ sub rebuild {
2150 my $svn_uuid = $self->rewrite_uuid || $self->ra_uuid;
2151 my $c;
2152 while (<$log>) {
2153 - if ( m{^commit ($::sha1)$} ) {
2153 + if ( m{^commit ($::oid)$} ) {
2154 $c = $1;
2155 next;
2156 }
perl/Git/SVN/Editor.pm
+1 -1
@@ -63,7 +63,7 @@ sub generate_diff {
63 my @mods;
64 while (defined($_ = get_record($diff_fh, "\0"))) {
65 if ($state eq 'meta' && /^:(\d{6})\s(\d{6})\s
66 - ($::sha1)\s($::sha1)\s
66 + ($::oid)\s($::oid)\s
67 ([MTCRAD])\d*$/xo) {
68 push @mods, { mode_a => $1, mode_b => $2,
69 sha1_a => $3, sha1_b => $4,
perl/Git/SVN/Log.pm
+1 -1
@@ -285,7 +285,7 @@ sub cmd_show_log {
285 my (@k, $c, $d, $stat);
286 my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
287 while (<$log>) {
288 - if (/^${esc_color}commit (?:- )?($::sha1_short)/o) {
288 + if (/^${esc_color}commit (?:- )?($::oid_short)/o) {
289 my $cmt = $1;
290 if ($c && cmt_showable($c) && $c->{r} != $r_last) {
291 $r_last = $c->{r};