git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cvsimport: ease migration from CVSROOT/users format
@ 2006-01-15 11:30 Junio C Hamano
  2006-01-15 20:50 ` Andreas Ericsson
  0 siblings, 1 reply; 2+ messages in thread
From: Junio C Hamano @ 2006-01-15 11:30 UTC (permalink / raw)
  To: Andreas Ericsson; +Cc: git

This fixes a minor bug, which caused the author email to be
doubly enclosed in a <> pair (the code gave enclosing <> to
GIT_AUTHOR_EMAIL and GIT_COMMITTER_EMAIL environment variable).

The read_author_info() subroutine is taught to also understand
the user list in CVSROOT/users format.  This is primarily done
to ease migration for CVS users, who can use the -A option
to read from existing CVSROOT/users file.  write_author_info()
always writes in the git-cvsimport's native format ('='
delimited and value without quotes).

Signed-off-by: Junio C Hamano <junkio@cox.net>

---

 * Andreas, I also tweaked the regexp to parse the native format
   from /^([^ \t=]*)[ \t=]*([^<]*)(<.*$)\s*/
   to /^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*$/.  I think this tweak is
   correct, but I would appreciate if you can proofread and ACK
   on it.  The differences are:

   - We did not require '=' anywhere, but accepted "= = =".
   - We had funny '$' in the middle; probably a typo. 
   - We first slurped author name with trailing whitespaces, only 
     to strip that separately in later steps.
   - We grabbed <> pairs and stored in author_email (this is a
     bugfix).

 git-cvsimport.perl |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)

1b23ed3d1f9f3d83ea8b94ebc37c99e0ca32a09b
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 8d493c2..3ddbdfa 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -48,16 +48,28 @@ sub read_author_info($) {
 	open my $f, '<', "$file" or die("Failed to open $file: $!\n");
 
 	while (<$f>) {
-		chomp;
-		# Expected format is this;
+		# Expected format is this:
 		#   exon=Andreas Ericsson <ae@op5.se>
-		if (m/^([^ \t=]*)[ \t=]*([^<]*)(<.*$)\s*/) {
+		if (m/^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*$/) {
 			$user = $1;
-			$conv_author_name{$1} = $2;
-			$conv_author_email{$1} = $3;
-			# strip trailing whitespace from author name
-			$conv_author_name{$1} =~ s/\s*$//;
+			$conv_author_name{$user} = $2;
+			$conv_author_email{$user} = $3;
 		}
+		# However, we also read from CVSROOT/users format
+		# to ease migration.
+		elsif (/^(\w+):(['"]?)(.+?)\2\s*$/) {
+			my $mapped;
+			($user, $mapped) = ($1, $3);
+			if ($mapped =~ /^\s*(.*?)\s*<(.*)>\s*$/) {
+				$conv_author_name{$user} = $1;
+				$conv_author_email{$user} = $2;
+			}
+			elsif ($mapped =~ /^<?(.*)>?$/) {
+				$conv_author_name{$user} = $user;
+				$conv_author_email{$user} = $1;
+			}
+		}
+		# NEEDSWORK: Maybe warn on unrecognized lines?
 	}
 	close ($f);
 }
@@ -68,8 +80,7 @@ sub write_author_info($) {
 	  die("Failed to open $file for writing: $!");
 
 	foreach (keys %conv_author_name) {
-		print $f "$_=" . $conv_author_name{$_} .
-		  " " . $conv_author_email{$_} . "\n";
+		print $f "$_=$conv_author_name{$_} <$conv_author_email{$_}>\n";
 	}
 	close ($f);
 }
-- 
1.1.2-gd425

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] cvsimport: ease migration from CVSROOT/users format
  2006-01-15 11:30 [PATCH] cvsimport: ease migration from CVSROOT/users format Junio C Hamano
@ 2006-01-15 20:50 ` Andreas Ericsson
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Ericsson @ 2006-01-15 20:50 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Junio C Hamano wrote:
> 
>  * Andreas, I also tweaked the regexp to parse the native format
>    from /^([^ \t=]*)[ \t=]*([^<]*)(<.*$)\s*/
>    to /^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*$/.  I think this tweak is
>    correct, but I would appreciate if you can proofread and ACK
>    on it.  The differences are:
> 

It looks correct and seems to do the trick.


>    - We grabbed <> pairs and stored in author_email (this is a
>      bugfix).
> 

gitk showed them as a single such even though theye were passed double. 
Perhaps some other tool stripped it along the way? Good catch anyways.

> +		}
> +		# NEEDSWORK: Maybe warn on unrecognized lines?
>  	}

I don't think so. I think it's safe to assume that people will check and 
double-check that everything's correct before removing the CVS repo, so 
it should be easy enough to redo the import (although possibly 
time-consuming).

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-01-15 20:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-15 11:30 [PATCH] cvsimport: ease migration from CVSROOT/users format Junio C Hamano
2006-01-15 20:50 ` Andreas Ericsson

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 NNTP newsgroup(s).