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 08/14] perl: create and switch variables for hash constants
Date: Mon, 22 Jun 2020 18:04:12 +0000	[thread overview]
Message-ID: <20200622180418.2418483-9-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20200622180418.2418483-1-sandals@crustytoothpaste.net>

git-svn has several variables for SHA-1 constants, including short hash
values and full length hash values.  Since these are no longer SHA-1
specific, let's start them with "oid" instead of "sha1".  Add a
constant, oid_length, which is the length of the hash algorithm in use
in hex.  We use the hex version because overwhelmingly that's what's
used by git-svn.

We don't currently set oid_length based on the repository algorithm, but
we will in a future commit.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 git-svn.perl           | 14 ++++++++------
 perl/Git/SVN.pm        | 10 +++++-----
 perl/Git/SVN/Editor.pm |  2 +-
 perl/Git/SVN/Log.pm    |  2 +-
 4 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index 4aa208ff5f..7c735cebd3 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -5,7 +5,8 @@
 use warnings;
 use strict;
 use vars qw/	$AUTHOR $VERSION
-		$sha1 $sha1_short $_revision $_repository
+		$oid $oid_short $oid_length
+		$_revision $_repository
 		$_q $_authors $_authors_prog %users/;
 $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
 $VERSION = '@@GIT_VERSION@@';
@@ -103,8 +104,9 @@ sub _req_svn {
 	}
 }
 
-$sha1 = qr/[a-f\d]{40}/;
-$sha1_short = qr/[a-f\d]{4,40}/;
+$oid = qr/(?:[a-f\d]{40}(?:[a-f\d]{24})?)/;
+$oid_short = qr/[a-f\d]{4,64}/;
+$oid_length = 40;
 my ($_stdin, $_help, $_edit,
 	$_message, $_file, $_branch_dest,
 	$_template, $_shared,
@@ -582,7 +584,7 @@ sub cmd_set_tree {
 		print "Reading from stdin...\n";
 		@commits = ();
 		while (<STDIN>) {
-			if (/\b($sha1_short)\b/o) {
+			if (/\b($oid_short)\b/o) {
 				unshift @commits, $1;
 			}
 		}
@@ -1831,7 +1833,7 @@ sub get_tree_from_treeish {
 	if ($type eq 'commit') {
 		$expected = (grep /^tree /, command(qw/cat-file commit/,
 		                                    $treeish))[0];
-		($expected) = ($expected =~ /^tree ($sha1)$/o);
+		($expected) = ($expected =~ /^tree ($oid)$/o);
 		die "Unable to get tree from $treeish\n" unless $expected;
 	} elsif ($type eq 'tree') {
 		$expected = $treeish;
@@ -2036,7 +2038,7 @@ sub working_head_info {
 	my $hash;
 	my %max;
 	while (<$fh>) {
-		if ( m{^commit ($::sha1)$} ) {
+		if ( m{^commit ($::oid)$} ) {
 			unshift @$refs, $hash if $hash and $refs;
 			$hash = $1;
 			next;
diff --git a/perl/Git/SVN.pm b/perl/Git/SVN.pm
index 4b28b87784..fcf1e3bb5e 100644
--- a/perl/Git/SVN.pm
+++ b/perl/Git/SVN.pm
@@ -874,7 +874,7 @@ sub assert_index_clean {
 		command_noisy('read-tree', $treeish) unless -e $self->{index};
 		my $x = command_oneline('write-tree');
 		my ($y) = (command(qw/cat-file commit/, $treeish) =~
-		           /^tree ($::sha1)/mo);
+		           /^tree ($::oid)/mo);
 		return if $y eq $x;
 
 		warn "Index mismatch: $y != $x\nrereading $treeish\n";
@@ -1020,7 +1020,7 @@ sub do_git_commit {
 		$tree = $self->tmp_index_do(sub {
 		                            command_oneline('write-tree') });
 	}
-	die "Tree is not a valid sha1: $tree\n" if $tree !~ /^$::sha1$/o;
+	die "Tree is not a valid oid $tree\n" if $tree !~ /^$::oid$/o;
 
 	my @exec = ('git', 'commit-tree', $tree);
 	foreach ($self->get_commit_parents($log_entry)) {
@@ -1048,8 +1048,8 @@ sub do_git_commit {
 	close $out_fh or croak $!;
 	waitpid $pid, 0;
 	croak $? if $?;
-	if ($commit !~ /^$::sha1$/o) {
-		die "Failed to commit, invalid sha1: $commit\n";
+	if ($commit !~ /^$::oid$/o) {
+		die "Failed to commit, invalid oid: $commit\n";
 	}
 
 	$self->rev_map_set($log_entry->{revision}, $commit, 1);
@@ -2150,7 +2150,7 @@ sub rebuild {
 	my $svn_uuid = $self->rewrite_uuid || $self->ra_uuid;
 	my $c;
 	while (<$log>) {
-		if ( m{^commit ($::sha1)$} ) {
+		if ( m{^commit ($::oid)$} ) {
 			$c = $1;
 			next;
 		}
diff --git a/perl/Git/SVN/Editor.pm b/perl/Git/SVN/Editor.pm
index 0df16ed726..70b6d78cd9 100644
--- a/perl/Git/SVN/Editor.pm
+++ b/perl/Git/SVN/Editor.pm
@@ -63,7 +63,7 @@ sub generate_diff {
 	my @mods;
 	while (defined($_ = get_record($diff_fh, "\0"))) {
 		if ($state eq 'meta' && /^:(\d{6})\s(\d{6})\s
-					($::sha1)\s($::sha1)\s
+					($::oid)\s($::oid)\s
 					([MTCRAD])\d*$/xo) {
 			push @mods, {	mode_a => $1, mode_b => $2,
 					sha1_a => $3, sha1_b => $4,
diff --git a/perl/Git/SVN/Log.pm b/perl/Git/SVN/Log.pm
index 664105357c..3858fcf27d 100644
--- a/perl/Git/SVN/Log.pm
+++ b/perl/Git/SVN/Log.pm
@@ -285,7 +285,7 @@ sub cmd_show_log {
 	my (@k, $c, $d, $stat);
 	my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
 	while (<$log>) {
-		if (/^${esc_color}commit (?:- )?($::sha1_short)/o) {
+		if (/^${esc_color}commit (?:- )?($::oid_short)/o) {
 			my $cmt = $1;
 			if ($c && cmt_showable($c) && $c->{r} != $r_last) {
 				$r_last = $c->{r};

  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   ` brian m. carlson [this message]
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   ` [PATCH v2 12/14] git-cvsserver: port to SHA-256 brian m. carlson
2020-06-22 18:04   ` [PATCH v2 13/14] git-cvsimport: " 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-9-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).