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

[PATCH 07/14] t/lib-git-svn: make hash size independent

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jun 19, 2020, 22:39 UTC
Message-ID
<20200619223947.947067-8-sandals@crustytoothpaste.net>
In-Reply-To
<20200619223947.947067-1-sandals@crustytoothpaste.net>

The record size used in the git svn storage is four bytes plus the length of the binary hash. Pass the hash length into our Perl invocation and use it to compute the size of the records.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/lib-git-svn.sh | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh
index 7d248e6588..4780b45337 100644
--- a/t/lib-git-svn.sh
+++ b/t/lib-git-svn.sh
@@ -78,29 +78,30 @@ maybe_start_httpd () {
 }
 
 convert_to_rev_db () {
-	perl -w -- - "$@" <<\EOF
-use strict;
+	perl -w -e "use strict; my \$oidlen = $(test_oid rawsz);" -e '
 @ARGV == 2 or die "usage: convert_to_rev_db <input> <output>";
-open my $wr, '+>', $ARGV[1] or die "$!: couldn't open: $ARGV[1]";
-open my $rd, '<', $ARGV[0] or die "$!: couldn't open: $ARGV[0]";
+my $record_size = $oidlen + 4;
+my $hexlen = $oidlen * 2;
+open my $wr, "+>", $ARGV[1] or die "$!: couldn'\''t open: $ARGV[1]";
+open my $rd, "<", $ARGV[0] or die "$!: couldn'\''t open: $ARGV[0]";
 my $size = (stat($rd))[7];
-($size % 24) == 0 or die "Inconsistent size: $size";
-while (sysread($rd, my $buf, 24) == 24) {
-	my ($r, $c) = unpack('NH40', $buf);
-	my $offset = $r * 41;
+($size % $record_size) == 0 or die "Inconsistent size: $size";
+while (sysread($rd, my $buf, $record_size) == $record_size) {
+	my ($r, $c) = unpack("NH$hexlen", $buf);
+	my $offset = $r * ($hexlen + 1);
 	seek $wr, 0, 2 or die $!;
 	my $pos = tell $wr;
 	if ($pos < $offset) {
-		for (1 .. (($offset - $pos) / 41)) {
-			print $wr (('0' x 40),"\n") or die $!;
+		for (1 .. (($offset - $pos) / ($hexlen + 1))) {
+			print $wr (('0' x $hexlen),"\n") or die $!;
 		}
 	}
 	seek $wr, $offset, 0 or die $!;
 	print $wr $c,"\n" or die $!;
 }
 close $wr or die $!;
-close $rd or die $!;
-EOF
+close $rd or die $!;' \
+	-- "$@"
 }
 
 require_svnserve () {
Previous: brian m. carlsonNext: Andreas Schwab
Message 6 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.