git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: <git@vger.kernel.org>
Cc: Andreas Schwab <schwab@linux-m68k.org>, Eric Wong <e@80x24.org>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2 12/14] git-cvsserver: port to SHA-256
Date: Mon, 22 Jun 2020 18:04:16 +0000	[thread overview]
Message-ID: <20200622180418.2418483-13-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20200622180418.2418483-1-sandals@crustytoothpaste.net>

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>
---
 git-cvsserver.perl | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/git-cvsserver.perl b/git-cvsserver.perl
index ae1044273d..f6f3fc192c 100755
--- a/git-cvsserver.perl
+++ b/git-cvsserver.perl
@@ -365,7 +365,7 @@ sub req_Root
     }
     foreach my $line ( @gitvars )
     {
-        next unless ( $line =~ /^(gitcvs)\.(?:(ext|pserver)\.)?([\w-]+)=(.*)$/ );
+        next unless ( $line =~ /^(gitcvs|extensions)\.(?:(ext|pserver)\.)?([\w-]+)=(.*)$/ );
         unless ($2) {
             $cfg->{$1}{$3} = $4;
         } else {
@@ -392,6 +392,9 @@ sub req_Root
         $log->nofile();
     }
 
+    $state->{rawsz} = ($cfg->{'extensions'}{'objectformat'} || 'sha1') eq 'sha256' ? 32 : 20;
+    $state->{hexsz} = $state->{rawsz} * 2;
+
     return 1;
 }
 
@@ -1581,7 +1584,7 @@ sub req_ci
 
             $parenthash = safe_pipe_capture('git', 'show-ref', '-s', $branchRef);
             chomp $parenthash;
-            if ($parenthash !~ /^[0-9a-f]{40}$/)
+            if ($parenthash !~ /^[0-9a-f]{$state->{hexsz}}$/)
             {
                 if ( defined($stickyInfo) && defined($stickyInfo->{tag}) )
                 {
@@ -1708,7 +1711,7 @@ sub req_ci
     chomp($commithash);
     $log->info("Commit hash : $commithash");
 
-    unless ( $commithash =~ /[a-zA-Z0-9]{40}/ )
+    unless ( $commithash =~ /[a-zA-Z0-9]{$state->{hexsz}}/ )
     {
         $log->warn("Commit failed (Invalid commit hash)");
         print "error 1 Commit failed (unknown reason)\n";
@@ -2375,7 +2378,7 @@ sub req_annotate
         print "E ***************\n";
         while ( <ANNOTATE> )
         {
-            if (m/^([a-zA-Z0-9]{40})\t\([^\)]*\)(.*)$/i)
+            if (m/^([a-zA-Z0-9]{$state->{hexsz}})\t\([^\)]*\)(.*)$/i)
             {
                 my $commithash = $1;
                 my $data = $2;
@@ -2852,7 +2855,7 @@ sub transmitfile
         return;
     }
 
-    die "Need filehash" unless ( defined ( $filehash ) and $filehash =~ /^[a-zA-Z0-9]{40}$/ );
+    die "Need filehash" unless ( defined ( $filehash ) and $filehash =~ /^[a-zA-Z0-9]{$state->{hexsz}}$/ );
 
     my $type = safe_pipe_capture('git', 'cat-file', '-t', $filehash);
     chomp $type;
@@ -3042,7 +3045,7 @@ sub ensureWorkTree
 
     my $ver = safe_pipe_capture('git', 'show-ref', '-s', "refs/heads/$state->{module}");
     chomp $ver;
-    if ($ver !~ /^[0-9a-f]{40}$/)
+    if ($ver !~ /^[0-9a-f]{$state->{hexsz}}$/)
     {
         $log->warn("Error from git show-ref -s refs/head$state->{module}");
         print "error 1 cannot find the current HEAD of module";
@@ -3281,7 +3284,7 @@ sub open_blob_or_die
     }
     elsif( $srcType eq "sha1" )
     {
-        unless ( defined ( $name ) and $name =~ /^[a-zA-Z0-9]{40}$/ )
+        unless ( defined ( $name ) and $name =~ /^[a-zA-Z0-9]{$state->{hexsz}}$/ )
         {
             $log->warn("Need filehash");
             die "Need filehash\n";
@@ -3817,7 +3820,7 @@ sub update
     chomp $commitsha1;
 
     my $commitinfo = ::safe_pipe_capture('git', 'cat-file', 'commit', $self->{module});
-    unless ( $commitinfo =~ /tree\s+[a-zA-Z0-9]{40}/ )
+    unless ( $commitinfo =~ /tree\s+[a-zA-Z0-9]{$state->{hexsz}}/ )
     {
         die("Invalid module '$self->{module}'");
     }
@@ -3957,7 +3960,7 @@ sub update
             while ( <FILELIST> )
             {
 		chomp;
-                unless ( /^:\d{6}\s+([0-7]{6})\s+[a-f0-9]{40}\s+([a-f0-9]{40})\s+(\w)$/o )
+                unless ( /^:\d{6}\s+([0-7]{6})\s+[a-f0-9]{$state->{hexsz}}\s+([a-f0-9]{$state->{hexsz}})\s+(\w)$/o )
                 {
                     die("Couldn't process git-diff-tree line : $_");
                 }
@@ -4625,11 +4628,11 @@ sub getmeta
             $db_query->execute($filename, $intRev);
             $meta = $db_query->fetchrow_hashref;
         }
-        elsif ( $revision =~ /^2\.1\.1\.2000(\.[1-3][0-9][0-9]){20}$/ )
+        elsif ( $revision =~ /^2\.1\.1\.2000(\.[1-3][0-9][0-9]){$state->{rawsz}}$/ )
         {
             my ($commitHash)=($revision=~/^2\.1\.1\.2000(.*)$/);
             $commitHash=~s/\.([0-9]+)/sprintf("%02x",$1-100)/eg;
-            if($commitHash=~/^[0-9a-f]{40}$/)
+            if($commitHash=~/^[0-9a-f]{$state->{hexsz}}$/)
             {
                 return $self->getMetaFromCommithash($filename,$commitHash);
             }
@@ -4639,7 +4642,7 @@ sub getmeta
             $log->warning("failed get $revision with commithash=$commitHash");
             undef $revision;
         }
-        elsif ( $revision =~ /^[0-9a-f]{40}$/ )
+        elsif ( $revision =~ /^[0-9a-f]{$state->{hexsz}}$/ )
         {
             # Try DB first.  This is mostly only useful for req_annotate(),
             # which only calls this for stuff that should already be in
@@ -4658,7 +4661,7 @@ sub getmeta
             if(! $meta)
             {
                 my($revCommit)=$self->lookupCommitRef($revision);
-                if($revCommit=~/^[0-9a-f]{40}$/)
+                if($revCommit=~/^[0-9a-f]{$state->{hexsz}}$/)
                 {
                     return $self->getMetaFromCommithash($filename,$revCommit);
                 }
@@ -4672,7 +4675,7 @@ sub getmeta
         else
         {
             my($revCommit)=$self->lookupCommitRef($revision);
-            if($revCommit=~/^[0-9a-f]{40}$/)
+            if($revCommit=~/^[0-9a-f]{$state->{hexsz}}$/)
             {
                 return $self->getMetaFromCommithash($filename,$revCommit);
             }
@@ -4767,7 +4770,7 @@ sub getMetaFromCommithash
 
     my($fileHash) = ::safe_pipe_capture("git","rev-parse","$revCommit:$filename");
     chomp $fileHash;
-    if(!($fileHash=~/^[0-9a-f]{40}$/))
+    if(!($fileHash=~/^[0-9a-f]{$state->{hexsz}}$/))
     {
         die "Invalid fileHash '$fileHash' looking up"
                     ." '$revCommit:$filename'\n";
@@ -4863,7 +4866,7 @@ sub lookupCommitRef
     $commitHash = ::safe_pipe_capture("git","rev-parse","--verify","--quiet",
 				      $self->unescapeRefName($ref));
     $commitHash=~s/\s*$//;
-    if(!($commitHash=~/^[0-9a-f]{40}$/))
+    if(!($commitHash=~/^[0-9a-f]{$state->{hexsz}}$/))
     {
         $commitHash=undef;
     }
@@ -4909,7 +4912,7 @@ sub commitmessage
     my $commithash = shift;
     my $tablename = $self->tablename("commitmsgs");
 
-    die("Need commithash") unless ( defined($commithash) and $commithash =~ /^[a-zA-Z0-9]{40}$/ );
+    die("Need commithash") unless ( defined($commithash) and $commithash =~ /^[a-zA-Z0-9]{$state->{hexsz}}$/ );
 
     my $db_query;
     $db_query = $self->{dbh}->prepare_cached("SELECT value FROM $tablename WHERE key=?",{},1);

  parent reply	other threads:[~2020-06-22 18:04 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-19 22:39 [PATCH 00/14] SHA-256 CVS and SVN patches brian m. carlson
2020-06-19 22:39 ` [PATCH 01/14] t9109: make test hash independent brian m. carlson
2020-06-19 22:39 ` [PATCH 02/14] t9168: " brian m. carlson
2020-06-19 22:39 ` [PATCH 03/14] t9108: " brian m. carlson
2020-06-19 22:39 ` [PATCH 04/14] t9100: make test work with SHA-256 brian m. carlson
2020-06-19 22:39 ` [PATCH 05/14] t9104: make hash size independent brian m. carlson
2020-06-19 22:39 ` [PATCH 06/14] t9101: make hash independent brian m. carlson
2020-06-19 22:39 ` [PATCH 07/14] t/lib-git-svn: make hash size independent brian m. carlson
2020-06-20  8:02   ` Andreas Schwab
2020-06-20 13:18     ` brian m. carlson
2020-06-19 22:39 ` [PATCH 08/14] perl: create and switch variables for hash constants brian m. carlson
2020-06-19 22:39 ` [PATCH 09/14] perl: make Git::IndexInfo work with SHA-256 brian m. carlson
2020-06-19 22:39 ` [PATCH 10/14] perl: make SVN code hash independent brian m. carlson
2020-06-19 22:39 ` [PATCH 11/14] git-svn: set the OID length based on hash algorithm brian m. carlson
2020-06-19 22:39 ` [PATCH 12/14] git-cvsserver: port to SHA-256 brian m. carlson
2020-06-19 22:39 ` [PATCH 13/14] git-cvsimport: " brian m. carlson
2020-06-19 22:39 ` [PATCH 14/14] git-cvsexportcommit: " brian m. carlson
2020-06-20  0:21 ` [PATCH 00/14] SHA-256 CVS and SVN patches Eric Wong
2020-06-22 16:50 ` Junio C Hamano
2020-06-22 17:46   ` brian m. carlson
2020-06-22 18:04 ` [PATCH v2 " brian m. carlson
2020-06-22 18:04   ` [PATCH v2 01/14] t9109: make test hash independent brian m. carlson
2020-06-22 18:04   ` [PATCH v2 02/14] t9168: " brian m. carlson
2020-06-22 18:04   ` [PATCH v2 03/14] t9108: " brian m. carlson
2020-06-22 18:04   ` [PATCH v2 04/14] t9100: make test work with SHA-256 brian m. carlson
2020-06-22 18:04   ` [PATCH v2 05/14] t9104: make hash size independent brian m. carlson
2020-06-22 18:04   ` [PATCH v2 06/14] t9101: make hash independent brian m. carlson
2020-06-22 18:04   ` [PATCH v2 07/14] t/lib-git-svn: make hash size independent brian m. carlson
2020-06-22 18:04   ` [PATCH v2 08/14] perl: create and switch variables for hash constants brian m. carlson
2020-06-22 18:04   ` [PATCH v2 09/14] perl: make Git::IndexInfo work with SHA-256 brian m. carlson
2020-06-22 18:04   ` [PATCH v2 10/14] perl: make SVN code hash independent brian m. carlson
2020-06-22 18:04   ` [PATCH v2 11/14] git-svn: set the OID length based on hash algorithm brian m. carlson
2020-06-22 18:04   ` brian m. carlson [this message]
2020-06-22 18:04   ` [PATCH v2 13/14] git-cvsimport: port to SHA-256 brian m. carlson
2020-06-22 18:04   ` [PATCH v2 14/14] git-cvsexportcommit: " brian m. carlson
2020-08-03 18:37     ` Andreas Schwab
2020-08-03 23:50       ` brian m. carlson
2020-08-04  0:13         ` Eric Wong
2020-08-04  0:44           ` brian m. carlson
2020-08-05 17:29         ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200622180418.2418483-13-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=e@80x24.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).