Skip to content

Commit 05ea93d

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Acked-by: Eric Wong <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 66eadd1 commit 05ea93d

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

git-cvsserver.perl

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ sub req_Root
365365
}
366366
foreach my $line ( @gitvars )
367367
{
368-
next unless ( $line =~ /^(gitcvs)\.(?:(ext|pserver)\.)?([\w-]+)=(.*)$/ );
368+
next unless ( $line =~ /^(gitcvs|extensions)\.(?:(ext|pserver)\.)?([\w-]+)=(.*)$/ );
369369
unless ($2) {
370370
$cfg->{$1}{$3} = $4;
371371
} else {
@@ -392,6 +392,9 @@ sub req_Root
392392
$log->nofile();
393393
}
394394

395+
$state->{rawsz} = ($cfg->{'extensions'}{'objectformat'} || 'sha1') eq 'sha256' ? 32 : 20;
396+
$state->{hexsz} = $state->{rawsz} * 2;
397+
395398
return 1;
396399
}
397400

@@ -1581,7 +1584,7 @@ sub req_ci
15811584

15821585
$parenthash = safe_pipe_capture('git', 'show-ref', '-s', $branchRef);
15831586
chomp $parenthash;
1584-
if ($parenthash !~ /^[0-9a-f]{40}$/)
1587+
if ($parenthash !~ /^[0-9a-f]{$state->{hexsz}}$/)
15851588
{
15861589
if ( defined($stickyInfo) && defined($stickyInfo->{tag}) )
15871590
{
@@ -1708,7 +1711,7 @@ sub req_ci
17081711
chomp($commithash);
17091712
$log->info("Commit hash : $commithash");
17101713

1711-
unless ( $commithash =~ /[a-zA-Z0-9]{40}/ )
1714+
unless ( $commithash =~ /[a-zA-Z0-9]{$state->{hexsz}}/ )
17121715
{
17131716
$log->warn("Commit failed (Invalid commit hash)");
17141717
print "error 1 Commit failed (unknown reason)\n";
@@ -2375,7 +2378,7 @@ sub req_annotate
23752378
print "E ***************\n";
23762379
while ( <ANNOTATE> )
23772380
{
2378-
if (m/^([a-zA-Z0-9]{40})\t\([^\)]*\)(.*)$/i)
2381+
if (m/^([a-zA-Z0-9]{$state->{hexsz}})\t\([^\)]*\)(.*)$/i)
23792382
{
23802383
my $commithash = $1;
23812384
my $data = $2;
@@ -2852,7 +2855,7 @@ sub transmitfile
28522855
return;
28532856
}
28542857

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}}$/ );
28562859

28572860
my $type = safe_pipe_capture('git', 'cat-file', '-t', $filehash);
28582861
chomp $type;
@@ -3042,7 +3045,7 @@ sub ensureWorkTree
30423045

30433046
my $ver = safe_pipe_capture('git', 'show-ref', '-s', "refs/heads/$state->{module}");
30443047
chomp $ver;
3045-
if ($ver !~ /^[0-9a-f]{40}$/)
3048+
if ($ver !~ /^[0-9a-f]{$state->{hexsz}}$/)
30463049
{
30473050
$log->warn("Error from git show-ref -s refs/head$state->{module}");
30483051
print "error 1 cannot find the current HEAD of module";
@@ -3281,7 +3284,7 @@ sub open_blob_or_die
32813284
}
32823285
elsif( $srcType eq "sha1" )
32833286
{
3284-
unless ( defined ( $name ) and $name =~ /^[a-zA-Z0-9]{40}$/ )
3287+
unless ( defined ( $name ) and $name =~ /^[a-zA-Z0-9]{$state->{hexsz}}$/ )
32853288
{
32863289
$log->warn("Need filehash");
32873290
die "Need filehash\n";
@@ -3817,7 +3820,7 @@ sub update
38173820
chomp $commitsha1;
38183821

38193822
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}}/ )
38213824
{
38223825
die("Invalid module '$self->{module}'");
38233826
}
@@ -3957,7 +3960,7 @@ sub update
39573960
while ( <FILELIST> )
39583961
{
39593962
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 )
39613964
{
39623965
die("Couldn't process git-diff-tree line : $_");
39633966
}
@@ -4625,11 +4628,11 @@ sub getmeta
46254628
$db_query->execute($filename, $intRev);
46264629
$meta = $db_query->fetchrow_hashref;
46274630
}
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}}$/ )
46294632
{
46304633
my ($commitHash)=($revision=~/^2\.1\.1\.2000(.*)$/);
46314634
$commitHash=~s/\.([0-9]+)/sprintf("%02x",$1-100)/eg;
4632-
if($commitHash=~/^[0-9a-f]{40}$/)
4635+
if($commitHash=~/^[0-9a-f]{$state->{hexsz}}$/)
46334636
{
46344637
return $self->getMetaFromCommithash($filename,$commitHash);
46354638
}
@@ -4639,7 +4642,7 @@ sub getmeta
46394642
$log->warning("failed get $revision with commithash=$commitHash");
46404643
undef $revision;
46414644
}
4642-
elsif ( $revision =~ /^[0-9a-f]{40}$/ )
4645+
elsif ( $revision =~ /^[0-9a-f]{$state->{hexsz}}$/ )
46434646
{
46444647
# Try DB first. This is mostly only useful for req_annotate(),
46454648
# which only calls this for stuff that should already be in
@@ -4658,7 +4661,7 @@ sub getmeta
46584661
if(! $meta)
46594662
{
46604663
my($revCommit)=$self->lookupCommitRef($revision);
4661-
if($revCommit=~/^[0-9a-f]{40}$/)
4664+
if($revCommit=~/^[0-9a-f]{$state->{hexsz}}$/)
46624665
{
46634666
return $self->getMetaFromCommithash($filename,$revCommit);
46644667
}
@@ -4672,7 +4675,7 @@ sub getmeta
46724675
else
46734676
{
46744677
my($revCommit)=$self->lookupCommitRef($revision);
4675-
if($revCommit=~/^[0-9a-f]{40}$/)
4678+
if($revCommit=~/^[0-9a-f]{$state->{hexsz}}$/)
46764679
{
46774680
return $self->getMetaFromCommithash($filename,$revCommit);
46784681
}
@@ -4767,7 +4770,7 @@ sub getMetaFromCommithash
47674770

47684771
my($fileHash) = ::safe_pipe_capture("git","rev-parse","$revCommit:$filename");
47694772
chomp $fileHash;
4770-
if(!($fileHash=~/^[0-9a-f]{40}$/))
4773+
if(!($fileHash=~/^[0-9a-f]{$state->{hexsz}}$/))
47714774
{
47724775
die "Invalid fileHash '$fileHash' looking up"
47734776
." '$revCommit:$filename'\n";
@@ -4863,7 +4866,7 @@ sub lookupCommitRef
48634866
$commitHash = ::safe_pipe_capture("git","rev-parse","--verify","--quiet",
48644867
$self->unescapeRefName($ref));
48654868
$commitHash=~s/\s*$//;
4866-
if(!($commitHash=~/^[0-9a-f]{40}$/))
4869+
if(!($commitHash=~/^[0-9a-f]{$state->{hexsz}}$/))
48674870
{
48684871
$commitHash=undef;
48694872
}
@@ -4909,7 +4912,7 @@ sub commitmessage
49094912
my $commithash = shift;
49104913
my $tablename = $self->tablename("commitmsgs");
49114914

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}}$/ );
49134916

49144917
my $db_query;
49154918
$db_query = $self->{dbh}->prepare_cached("SELECT value FROM $tablename WHERE key=?",{},1);

0 commit comments

Comments
 (0)