git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 12/14] git-cvsserver: port to SHA-256

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jun 22, 2020, 18:04 UTC
Message-ID
<20200622180418.2418483-13-sandals@crustytoothpaste.net>
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);
Previous: brian m. carlsonNext: brian m. carlson
Message 38 of 40 in “SHA-256 CVS and SVN patches”
  1. 00/14 SHA-256 CVS and SVN patchesbrian m. carlson, Jun 19, 2020
  2. 04/14 t9100: make test work with SHA-256brian m. carlson, Jun 19, 2020
  3. 05/14 t9104: make hash size independentbrian m. carlson, Jun 19, 2020
  4. 06/14 t9101: make hash independentbrian m. carlson, Jun 19, 2020
  5. 09/14 perl: make Git::IndexInfo work with SHA-256brian m. carlson, Jun 19, 2020
  6. 07/14 t/lib-git-svn: make hash size independentbrian m. carlson, Jun 19, 2020
  7. Andreas SchwabJun 20, 2020
  8. brian m. carlsonJun 20, 2020
  9. 13/14 git-cvsimport: port to SHA-256brian m. carlson, Jun 19, 2020
  10. 11/14 git-svn: set the OID length based on hash algorithmbrian m. carlson, Jun 19, 2020
  11. 14/14 git-cvsexportcommit: port to SHA-256brian m. carlson, Jun 19, 2020
  12. 12/14 git-cvsserver: port to SHA-256brian m. carlson, Jun 19, 2020
  13. 01/14 t9109: make test hash independentbrian m. carlson, Jun 19, 2020
  14. 03/14 t9108: make test hash independentbrian m. carlson, Jun 19, 2020
  15. 02/14 t9168: make test hash independentbrian m. carlson, Jun 19, 2020
  16. 10/14 perl: make SVN code hash independentbrian m. carlson, Jun 19, 2020
  17. 08/14 perl: create and switch variables for hash constantsbrian m. carlson, Jun 19, 2020
  18. Eric WongJun 20, 2020
  19. Junio C HamanoJun 22, 2020
  20. brian m. carlsonJun 22, 2020
  21. 00/14 SHA-256 CVS and SVN patchesbrian m. carlson, Jun 22, 2020
  22. 01/14 t9109: make test hash independentbrian m. carlson, Jun 22, 2020
  23. 02/14 t9168: make test hash independentbrian m. carlson, Jun 22, 2020
  24. 08/14 perl: create and switch variables for hash constantsbrian m. carlson, Jun 22, 2020
  25. 03/14 t9108: make test hash independentbrian m. carlson, Jun 22, 2020
  26. 04/14 t9100: make test work with SHA-256brian m. carlson, Jun 22, 2020
  27. 09/14 perl: make Git::IndexInfo work with SHA-256brian m. carlson, Jun 22, 2020
  28. 07/14 t/lib-git-svn: make hash size independentbrian m. carlson, Jun 22, 2020
  29. 14/14 git-cvsexportcommit: port to SHA-256brian m. carlson, Jun 22, 2020
  30. Andreas SchwabAug 3, 2020
  31. brian m. carlsonAug 3, 2020
  32. Eric WongAug 4, 2020
  33. brian m. carlsonAug 4, 2020
  34. Andreas SchwabAug 5, 2020
  35. 11/14 git-svn: set the OID length based on hash algorithmbrian m. carlson, Jun 22, 2020
  36. 13/14 git-cvsimport: port to SHA-256brian m. carlson, Jun 22, 2020
  37. 05/14 t9104: make hash size independentbrian m. carlson, Jun 22, 2020
  38. 12/14 git-cvsserver: port to SHA-256brian m. carlson, Jun 22, 2020
  39. 06/14 t9101: make hash independentbrian m. carlson, Jun 22, 2020
  40. 10/14 perl: make SVN code hash independentbrian m. carlson, Jun 22, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.