git-cvsserver: port to SHA-256
The code of git-cvsserver currently has several hard-coded 20 and 40 constants that are the length of SHA-1. When parsing the configuration file, read the extensions.objectformat configuration setting as well as CVS-related ones and adjust the hash sizes accordingly. Use these computed values in all the places we match object IDs. 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
05ea93d6b2bfb9a45a9019a5cfaba82dc81dc2f3
1 file changed
+20
-17
git-cvsserver.perl
+20
-17
@@ -365,7 +365,7 @@ sub req_Root
365
}
366
foreach my $line ( @gitvars )
367
{
368
- next unless ( $line =~ /^(gitcvs)\.(?:(ext|pserver)\.)?([\w-]+)=(.*)$/ );
368
+ next unless ( $line =~ /^(gitcvs|extensions)\.(?:(ext|pserver)\.)?([\w-]+)=(.*)$/ );
369
unless ($2) {
370
$cfg->{$1}{$3} = $4;
371
} else {
@@ -392,6 +392,9 @@ sub req_Root
392
$log->nofile();
393
}
394
395
+ $state->{rawsz} = ($cfg->{'extensions'}{'objectformat'} || 'sha1') eq 'sha256' ? 32 : 20;
396
+ $state->{hexsz} = $state->{rawsz} * 2;
397
+
398
return 1;
399
}
400
@@ -1581,7 +1584,7 @@ sub req_ci
1584
1585
$parenthash = safe_pipe_capture('git', 'show-ref', '-s', $branchRef);
1586
chomp $parenthash;
1584
- if ($parenthash !~ /^[0-9a-f]{40}$/)
1587
+ if ($parenthash !~ /^[0-9a-f]{$state->{hexsz}}$/)
1588
{
1589
if ( defined($stickyInfo) && defined($stickyInfo->{tag}) )
1590
{
@@ -1708,7 +1711,7 @@ sub req_ci
1711
chomp($commithash);
1712
$log->info("Commit hash : $commithash");
1713
1711
- unless ( $commithash =~ /[a-zA-Z0-9]{40}/ )
1714
+ unless ( $commithash =~ /[a-zA-Z0-9]{$state->{hexsz}}/ )
1715
{
1716
$log->warn("Commit failed (Invalid commit hash)");
1717
print "error 1 Commit failed (unknown reason)\n";
@@ -2375,7 +2378,7 @@ sub req_annotate
2378
print "E ***************\n";
2379
while ( <ANNOTATE> )
2380
{
2378
- if (m/^([a-zA-Z0-9]{40})\t\([^\)]*\)(.*)$/i)
2381
+ if (m/^([a-zA-Z0-9]{$state->{hexsz}})\t\([^\)]*\)(.*)$/i)
2382
{
2383
my $commithash = $1;
2384
my $data = $2;
@@ -2852,7 +2855,7 @@ sub transmitfile
2855
return;
2856
}
2857
2855
- die "Need filehash" unless ( defined ( $filehash ) and $filehash =~ /^[a-zA-Z0-9]{40}$/ );
2858
+ die "Need filehash" unless ( defined ( $filehash ) and $filehash =~ /^[a-zA-Z0-9]{$state->{hexsz}}$/ );
2859
2860
my $type = safe_pipe_capture('git', 'cat-file', '-t', $filehash);
2861
chomp $type;
@@ -3042,7 +3045,7 @@ sub ensureWorkTree
3045
3046
my $ver = safe_pipe_capture('git', 'show-ref', '-s', "refs/heads/$state->{module}");
3047
chomp $ver;
3045
- if ($ver !~ /^[0-9a-f]{40}$/)
3048
+ if ($ver !~ /^[0-9a-f]{$state->{hexsz}}$/)
3049
{
3050
$log->warn("Error from git show-ref -s refs/head$state->{module}");
3051
print "error 1 cannot find the current HEAD of module";
@@ -3281,7 +3284,7 @@ sub open_blob_or_die
3284
}
3285
elsif( $srcType eq "sha1" )
3286
{
3284
- unless ( defined ( $name ) and $name =~ /^[a-zA-Z0-9]{40}$/ )
3287
+ unless ( defined ( $name ) and $name =~ /^[a-zA-Z0-9]{$state->{hexsz}}$/ )
3288
{
3289
$log->warn("Need filehash");
3290
die "Need filehash\n";
@@ -3817,7 +3820,7 @@ sub update
3820
chomp $commitsha1;
3821
3822
my $commitinfo = ::safe_pipe_capture('git', 'cat-file', 'commit', $self->{module});
3820
- unless ( $commitinfo =~ /tree\s+[a-zA-Z0-9]{40}/ )
3823
+ unless ( $commitinfo =~ /tree\s+[a-zA-Z0-9]{$state->{hexsz}}/ )
3824
{
3825
die("Invalid module '$self->{module}'");
3826
}
@@ -3957,7 +3960,7 @@ sub update
3960
while ( <FILELIST> )
3961
{
3962
chomp;
3960
- unless ( /^:\d{6}\s+([0-7]{6})\s+[a-f0-9]{40}\s+([a-f0-9]{40})\s+(\w)$/o )
3963
+ unless ( /^:\d{6}\s+([0-7]{6})\s+[a-f0-9]{$state->{hexsz}}\s+([a-f0-9]{$state->{hexsz}})\s+(\w)$/o )
3964
{
3965
die("Couldn't process git-diff-tree line : $_");
3966
}
@@ -4625,11 +4628,11 @@ sub getmeta
4628
$db_query->execute($filename, $intRev);
4629
$meta = $db_query->fetchrow_hashref;
4630
}
4628
- elsif ( $revision =~ /^2\.1\.1\.2000(\.[1-3][0-9][0-9]){20}$/ )
4631
+ elsif ( $revision =~ /^2\.1\.1\.2000(\.[1-3][0-9][0-9]){$state->{rawsz}}$/ )
4632
{
4633
my ($commitHash)=($revision=~/^2\.1\.1\.2000(.*)$/);
4634
$commitHash=~s/\.([0-9]+)/sprintf("%02x",$1-100)/eg;
4632
- if($commitHash=~/^[0-9a-f]{40}$/)
4635
+ if($commitHash=~/^[0-9a-f]{$state->{hexsz}}$/)
4636
{
4637
return $self->getMetaFromCommithash($filename,$commitHash);
4638
}
@@ -4639,7 +4642,7 @@ sub getmeta
4642
$log->warning("failed get $revision with commithash=$commitHash");
4643
undef $revision;
4644
}
4642
- elsif ( $revision =~ /^[0-9a-f]{40}$/ )
4645
+ elsif ( $revision =~ /^[0-9a-f]{$state->{hexsz}}$/ )
4646
{
4647
# Try DB first. This is mostly only useful for req_annotate(),
4648
# which only calls this for stuff that should already be in
@@ -4658,7 +4661,7 @@ sub getmeta
4661
if(! $meta)
4662
{
4663
my($revCommit)=$self->lookupCommitRef($revision);
4661
- if($revCommit=~/^[0-9a-f]{40}$/)
4664
+ if($revCommit=~/^[0-9a-f]{$state->{hexsz}}$/)
4665
{
4666
return $self->getMetaFromCommithash($filename,$revCommit);
4667
}
@@ -4672,7 +4675,7 @@ sub getmeta
4675
else
4676
{
4677
my($revCommit)=$self->lookupCommitRef($revision);
4675
- if($revCommit=~/^[0-9a-f]{40}$/)
4678
+ if($revCommit=~/^[0-9a-f]{$state->{hexsz}}$/)
4679
{
4680
return $self->getMetaFromCommithash($filename,$revCommit);
4681
}
@@ -4767,7 +4770,7 @@ sub getMetaFromCommithash
4770
4771
my($fileHash) = ::safe_pipe_capture("git","rev-parse","$revCommit:$filename");
4772
chomp $fileHash;
4770
- if(!($fileHash=~/^[0-9a-f]{40}$/))
4773
+ if(!($fileHash=~/^[0-9a-f]{$state->{hexsz}}$/))
4774
{
4775
die "Invalid fileHash '$fileHash' looking up"
4776
." '$revCommit:$filename'\n";
@@ -4863,7 +4866,7 @@ sub lookupCommitRef
4866
$commitHash = ::safe_pipe_capture("git","rev-parse","--verify","--quiet",
4867
$self->unescapeRefName($ref));
4868
$commitHash=~s/\s*$//;
4866
- if(!($commitHash=~/^[0-9a-f]{40}$/))
4869
+ if(!($commitHash=~/^[0-9a-f]{$state->{hexsz}}$/))
4870
{
4871
$commitHash=undef;
4872
}
@@ -4909,7 +4912,7 @@ sub commitmessage
4912
my $commithash = shift;
4913
my $tablename = $self->tablename("commitmsgs");
4914
4912
- die("Need commithash") unless ( defined($commithash) and $commithash =~ /^[a-zA-Z0-9]{40}$/ );
4915
+ die("Need commithash") unless ( defined($commithash) and $commithash =~ /^[a-zA-Z0-9]{$state->{hexsz}}$/ );
4916
4917
my $db_query;
4918
$db_query = $self->{dbh}->prepare_cached("SELECT value FROM $tablename WHERE key=?",{},1);