git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] git-svn: add --authors-prog option
@ 2009-05-08  1:11 Mark Lodato
  2009-05-08  7:43 ` Michael J Gruber
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Lodato @ 2009-05-08  1:11 UTC (permalink / raw)
  To: git; +Cc: Mark Lodato, Eric Wong, Junio C Hamano

Add a new option, --authors-prog, to git-svn that allows a more flexible
alternative (or supplement) to --authors-file.  This allows more
advanced username operations than the authors file will allow.  For
example, one may look up Subversion users via LDAP, or may generate the
name and email address from the Subversion username.

Notes:

* If both --authors-name and --authors-prog are given, the former is
  tried first, falling back to the later.

* The program is called once per unique SVN username and the result is
  cached.

* The command-line argument must be the path to a program, not a generic
  shell command line.  The absolute path to this program is taken at
  startup since the git-svn script changes directory during operation.

* The option is not enabled for `git log'.

Signed-off-by: Mark Lodato <lodatom@gmail.com>
---

This is my second attempt at a patch.  I received no feedback from the
first attempt, so I suppose I made a mistake.  I cleaned up my commit
message, added a Signed-off-by, CC'd the appropriate maintainers, and
put the additional message (this paragraph) in the correct location.
The contents of the patch have not changed.  Sorry for the resend; I'm
still learning.

 Documentation/git-svn.txt       |    8 ++++
 git-svn.perl                    |   30 +++++++++++++++--
 t/t9138-git-svn-authors-prog.sh |   69 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 104 insertions(+), 3 deletions(-)
 create mode 100755 t/t9138-git-svn-authors-prog.sh

diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt
index 1c40894..78582ad 100644
--- a/Documentation/git-svn.txt
+++ b/Documentation/git-svn.txt
@@ -398,6 +398,14 @@ after the authors-file is modified should continue operation.
 
 config key: svn.authorsfile
 
+--authors-prog=<filename>::
+
+If this option is specified, for each SVN committer name that does not
+exist in the authors file, the given file is executed with the commiter
+name as the first argument.  The program is expected to return a single
+line of the form "Name <email>", which will be logically inserted into the
+authors file.
+
 -q::
 --quiet::
 	Make 'git-svn' less verbose. Specify a second time to make it
diff --git a/git-svn.perl b/git-svn.perl
index ef1d30d..f9c9567 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -5,7 +5,7 @@ use warnings;
 use strict;
 use vars qw/	$AUTHOR $VERSION
 		$sha1 $sha1_short $_revision $_repository
-		$_q $_authors %users/;
+		$_q $_authors $_authors_prog %users/;
 $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
 $VERSION = '@@GIT_VERSION@@';
 
@@ -39,6 +39,7 @@ use Digest::MD5;
 use IO::File qw//;
 use File::Basename qw/dirname basename/;
 use File::Path qw/mkpath/;
+use File::Spec;
 use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
 use IPC::Open3;
 use Git;
@@ -76,6 +77,7 @@ my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username,
                     'ignore-paths=s' => \$SVN::Git::Fetcher::_ignore_regex );
 my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent,
 		'authors-file|A=s' => \$_authors,
+		'authors-prog=s' => \$_authors_prog,
 		'repack:i' => \$Git::SVN::_repack,
 		'noMetadata' => \$Git::SVN::_no_metadata,
 		'useSvmProps' => \$Git::SVN::_use_svm_props,
@@ -263,6 +265,7 @@ usage(0) if $_help;
 version() if $_version;
 usage(1) unless defined $cmd;
 load_authors() if $_authors;
+$_authors_prog = "'" . File::Spec->rel2abs($_authors_prog) . "'";
 
 unless ($cmd =~ /^(?:clone|init|multi-init|commit-diff)$/) {
 	Git::SVN::Migration::migration_check();
@@ -2663,12 +2666,33 @@ sub other_gs {
 	$gs
 }
 
+sub call_authors_prog {
+	my ($orig_author) = @_;
+	my $author = `$::_authors_prog $orig_author`;
+	if ($? != 0) {
+		die "$::_authors_prog failed with exit code $?\n"
+	}
+	if ($author =~ /^\s*(.+?)\s*<(.*)>\s*$/) {
+		my ($name, $email) = ($1, $2);
+		$email = undef if length $2 == 0;
+		return [$name, $email];
+	} else {
+		die "Author: $orig_author: $::_authors_prog returned "
+			. "invalid author format: $author\n";
+	}
+}
+
 sub check_author {
 	my ($author) = @_;
 	if (!defined $author || length $author == 0) {
 		$author = '(no author)';
-	} elsif (defined $::_authors && ! defined $::users{$author}) {
-		die "Author: $author not defined in $::_authors file\n";
+	}
+	if (!defined $::users{$author}) {
+		if (defined $::_authors_prog) {
+			$::users{$author} = call_authors_prog($author);
+		} elsif (defined $::_authors) {
+			die "Author: $author not defined in $::_authors file\n";
+		}
 	}
 	$author;
 }
diff --git a/t/t9138-git-svn-authors-prog.sh b/t/t9138-git-svn-authors-prog.sh
new file mode 100755
index 0000000..a4b00f2
--- /dev/null
+++ b/t/t9138-git-svn-authors-prog.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+#
+# Copyright (c) 2009 Eric Wong, Mark Lodato
+#
+
+test_description='git svn authors prog tests'
+
+. ./lib-git-svn.sh
+
+cat > svn-authors-prog <<'EOF'
+#!/usr/bin/perl
+$_ = shift;
+if (s/-sub$//)  {
+	print "$_ <$_\@sub.example.com>\n";
+}
+else {
+	print "$_ <$_\@example.com>\n";
+}
+EOF
+chmod +x svn-authors-prog
+
+cat > svn-authors <<'EOF'
+ff = FFFFFFF FFFFFFF <fFf@other.example.com>
+EOF
+
+test_expect_success 'setup svnrepo' '
+	for i in aa bb cc-sub dd-sub ee-foo ff
+	do
+		svn mkdir -m $i --username $i "$svnrepo"/$i
+	done
+	'
+
+test_expect_success 'import authors with prog and file' '
+	git svn clone --authors-prog=./svn-authors-prog \
+	    --authors-file=svn-authors "$svnrepo" x
+	'
+
+test_expect_success 'imported 6 revisions successfully' '
+	(
+		cd x
+		test "`git rev-list refs/remotes/git-svn | wc -l`" -eq 6
+	)
+	'
+
+test_expect_success 'authors-prog ran correctly' '
+	(
+		cd x
+		git rev-list -1 --pretty=raw refs/remotes/git-svn~1 | \
+		  grep "^author ee-foo <ee-foo@example\.com> " &&
+		git rev-list -1 --pretty=raw refs/remotes/git-svn~2 | \
+		  grep "^author dd <dd@sub\.example\.com> " &&
+		git rev-list -1 --pretty=raw refs/remotes/git-svn~3 | \
+		  grep "^author cc <cc@sub\.example\.com> " &&
+		git rev-list -1 --pretty=raw refs/remotes/git-svn~4 | \
+		  grep "^author bb <bb@example\.com> " &&
+		git rev-list -1 --pretty=raw refs/remotes/git-svn~5 | \
+		  grep "^author aa <aa@example\.com> "
+	)
+	'
+
+test_expect_success 'authors-file overrode authors-prog' '
+	(
+		cd x
+		git rev-list -1 --pretty=raw refs/remotes/git-svn | \
+		  grep "^author FFFFFFF FFFFFFF <fFf@other\.example\.com> "
+	)
+	'
+
+test_done
-- 
1.6.3

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

* Re: [PATCH v2] git-svn: add --authors-prog option
  2009-05-08  1:11 [PATCH v2] git-svn: add --authors-prog option Mark Lodato
@ 2009-05-08  7:43 ` Michael J Gruber
  2009-05-09  3:48   ` Mark Lodato
  0 siblings, 1 reply; 7+ messages in thread
From: Michael J Gruber @ 2009-05-08  7:43 UTC (permalink / raw)
  To: Mark Lodato; +Cc: git, Eric Wong, Junio C Hamano

Mark Lodato venit, vidit, dixit 08.05.2009 03:11:
> Add a new option, --authors-prog, to git-svn that allows a more flexible
> alternative (or supplement) to --authors-file.  This allows more
> advanced username operations than the authors file will allow.  For
> example, one may look up Subversion users via LDAP, or may generate the
> name and email address from the Subversion username.
> 
> Notes:
> 
> * If both --authors-name and --authors-prog are given, the former is
>   tried first, falling back to the later.
> 
> * The program is called once per unique SVN username and the result is
>   cached.
> 
> * The command-line argument must be the path to a program, not a generic
>   shell command line.  The absolute path to this program is taken at
>   startup since the git-svn script changes directory during operation.
> 
> * The option is not enabled for `git log'.
> 
> Signed-off-by: Mark Lodato <lodatom@gmail.com>
> ---
> 
> This is my second attempt at a patch.  I received no feedback from the
> first attempt, so I suppose I made a mistake.  I cleaned up my commit
> message, added a Signed-off-by, CC'd the appropriate maintainers, and
> put the additional message (this paragraph) in the correct location.
> The contents of the patch have not changed.  Sorry for the resend; I'm
> still learning.

Thanks for willing to learn and rewriting according to the list's
requirements!

> 
>  Documentation/git-svn.txt       |    8 ++++
>  git-svn.perl                    |   30 +++++++++++++++--
>  t/t9138-git-svn-authors-prog.sh |   69 +++++++++++++++++++++++++++++++++++++++
>  3 files changed, 104 insertions(+), 3 deletions(-)
>  create mode 100755 t/t9138-git-svn-authors-prog.sh
> 
> diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt
> index 1c40894..78582ad 100644
> --- a/Documentation/git-svn.txt
> +++ b/Documentation/git-svn.txt
> @@ -398,6 +398,14 @@ after the authors-file is modified should continue operation.
>  
>  config key: svn.authorsfile
>  
> +--authors-prog=<filename>::
> +
> +If this option is specified, for each SVN committer name that does not
> +exist in the authors file, the given file is executed with the commiter

s/commiter/committer/

Also, "If..., the given... for each..." may be easier to read.

> +name as the first argument.  The program is expected to return a single
> +line of the form "Name <email>", which will be logically inserted into the

"be treated as if included in the..."

> +authors file.
> +

Maybe we want a config key also, just like for the authors file.

The feature itself looks useful for large user databases. For smaller
ones one could just as well update the authors file before each fetch by
dumping the whole db in there (or even conditionally on git svn fetch
erroring out due to encountering an unknown name).

>  -q::
>  --quiet::
>  	Make 'git-svn' less verbose. Specify a second time to make it
> diff --git a/git-svn.perl b/git-svn.perl
> index ef1d30d..f9c9567 100755
> --- a/git-svn.perl
> +++ b/git-svn.perl
> @@ -5,7 +5,7 @@ use warnings;
>  use strict;
>  use vars qw/	$AUTHOR $VERSION
>  		$sha1 $sha1_short $_revision $_repository
> -		$_q $_authors %users/;
> +		$_q $_authors $_authors_prog %users/;
>  $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
>  $VERSION = '@@GIT_VERSION@@';
>  
> @@ -39,6 +39,7 @@ use Digest::MD5;
>  use IO::File qw//;
>  use File::Basename qw/dirname basename/;
>  use File::Path qw/mkpath/;
> +use File::Spec;
>  use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
>  use IPC::Open3;
>  use Git;
> @@ -76,6 +77,7 @@ my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username,
>                      'ignore-paths=s' => \$SVN::Git::Fetcher::_ignore_regex );
>  my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent,
>  		'authors-file|A=s' => \$_authors,
> +		'authors-prog=s' => \$_authors_prog,
>  		'repack:i' => \$Git::SVN::_repack,
>  		'noMetadata' => \$Git::SVN::_no_metadata,
>  		'useSvmProps' => \$Git::SVN::_use_svm_props,
> @@ -263,6 +265,7 @@ usage(0) if $_help;
>  version() if $_version;
>  usage(1) unless defined $cmd;
>  load_authors() if $_authors;
> +$_authors_prog = "'" . File::Spec->rel2abs($_authors_prog) . "'";
>  
>  unless ($cmd =~ /^(?:clone|init|multi-init|commit-diff)$/) {
>  	Git::SVN::Migration::migration_check();
> @@ -2663,12 +2666,33 @@ sub other_gs {
>  	$gs
>  }
>  
> +sub call_authors_prog {
> +	my ($orig_author) = @_;
> +	my $author = `$::_authors_prog $orig_author`;
> +	if ($? != 0) {
> +		die "$::_authors_prog failed with exit code $?\n"
> +	}
> +	if ($author =~ /^\s*(.+?)\s*<(.*)>\s*$/) {
> +		my ($name, $email) = ($1, $2);
> +		$email = undef if length $2 == 0;
> +		return [$name, $email];
> +	} else {
> +		die "Author: $orig_author: $::_authors_prog returned "
> +			. "invalid author format: $author\n";
> +	}
> +}
> +
>  sub check_author {
>  	my ($author) = @_;
>  	if (!defined $author || length $author == 0) {
>  		$author = '(no author)';
> -	} elsif (defined $::_authors && ! defined $::users{$author}) {
> -		die "Author: $author not defined in $::_authors file\n";
> +	}
> +	if (!defined $::users{$author}) {
> +		if (defined $::_authors_prog) {
> +			$::users{$author} = call_authors_prog($author);
> +		} elsif (defined $::_authors) {
> +			die "Author: $author not defined in $::_authors file\n";
> +		}
>  	}
>  	$author;
>  }
> diff --git a/t/t9138-git-svn-authors-prog.sh b/t/t9138-git-svn-authors-prog.sh
> new file mode 100755
> index 0000000..a4b00f2
> --- /dev/null
> +++ b/t/t9138-git-svn-authors-prog.sh
> @@ -0,0 +1,69 @@
> +#!/bin/sh
> +#
> +# Copyright (c) 2009 Eric Wong, Mark Lodato
> +#
> +
> +test_description='git svn authors prog tests'
> +
> +. ./lib-git-svn.sh
> +
> +cat > svn-authors-prog <<'EOF'
> +#!/usr/bin/perl
> +$_ = shift;
> +if (s/-sub$//)  {
> +	print "$_ <$_\@sub.example.com>\n";
> +}
> +else {
> +	print "$_ <$_\@example.com>\n";
> +}
> +EOF
> +chmod +x svn-authors-prog
> +
> +cat > svn-authors <<'EOF'
> +ff = FFFFFFF FFFFFFF <fFf@other.example.com>
> +EOF
> +
> +test_expect_success 'setup svnrepo' '
> +	for i in aa bb cc-sub dd-sub ee-foo ff
> +	do
> +		svn mkdir -m $i --username $i "$svnrepo"/$i
> +	done
> +	'
> +
> +test_expect_success 'import authors with prog and file' '
> +	git svn clone --authors-prog=./svn-authors-prog \
> +	    --authors-file=svn-authors "$svnrepo" x
> +	'
> +
> +test_expect_success 'imported 6 revisions successfully' '
> +	(
> +		cd x
> +		test "`git rev-list refs/remotes/git-svn | wc -l`" -eq 6
> +	)
> +	'
> +
> +test_expect_success 'authors-prog ran correctly' '
> +	(
> +		cd x
> +		git rev-list -1 --pretty=raw refs/remotes/git-svn~1 | \
> +		  grep "^author ee-foo <ee-foo@example\.com> " &&
> +		git rev-list -1 --pretty=raw refs/remotes/git-svn~2 | \
> +		  grep "^author dd <dd@sub\.example\.com> " &&
> +		git rev-list -1 --pretty=raw refs/remotes/git-svn~3 | \
> +		  grep "^author cc <cc@sub\.example\.com> " &&
> +		git rev-list -1 --pretty=raw refs/remotes/git-svn~4 | \
> +		  grep "^author bb <bb@example\.com> " &&
> +		git rev-list -1 --pretty=raw refs/remotes/git-svn~5 | \
> +		  grep "^author aa <aa@example\.com> "
> +	)
> +	'
> +
> +test_expect_success 'authors-file overrode authors-prog' '
> +	(
> +		cd x
> +		git rev-list -1 --pretty=raw refs/remotes/git-svn | \
> +		  grep "^author FFFFFFF FFFFFFF <fFf@other\.example\.com> "
> +	)
> +	'
> +
> +test_done

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

* Re: [PATCH v2] git-svn: add --authors-prog option
  2009-05-08  7:43 ` Michael J Gruber
@ 2009-05-09  3:48   ` Mark Lodato
  2009-05-10  0:35     ` Eric Wong
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Lodato @ 2009-05-09  3:48 UTC (permalink / raw)
  To: Michael J Gruber; +Cc: git, Eric Wong, Junio C Hamano

On Fri, May 8, 2009 at 3:43 AM, Michael J Gruber
<git@drmicha.warpmail.net> wrote:
> Mark Lodato venit, vidit, dixit 08.05.2009 03:11:
>>  config key: svn.authorsfile
>>
>> +--authors-prog=<filename>::
>> +
>> +If this option is specified, for each SVN committer name that does not
>> +exist in the authors file, the given file is executed with the commiter
>
> s/commiter/committer/
>
> Also, "If..., the given... for each..." may be easier to read.
>
>> +name as the first argument.  The program is expected to return a single
>> +line of the form "Name <email>", which will be logically inserted into the
>
> "be treated as if included in the..."

Will do.

>
> Maybe we want a config key also, just like for the authors file.

Yes, this is a very good idea.  I will figure out how to do this.

> The feature itself looks useful for large user databases. For smaller
> ones one could just as well update the authors file before each fetch by
> dumping the whole db in there (or even conditionally on git svn fetch
> erroring out due to encountering an unknown name).

Right.  This feature will most likely be useful in corporate
environments.  In my case, it is not possible to dump the entire user
database to a file, so this patch is the only solution.  Another
possible use case is where SVN usernames are standardized, e.g. "jdoe"
-> "J Doe <jdoe@example.com>".  Also, using --authors-prog solves the
problem of keeping the authors file up-to-date, if users are regularly
added or deleted.

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

* Re: [PATCH v2] git-svn: add --authors-prog option
  2009-05-09  3:48   ` Mark Lodato
@ 2009-05-10  0:35     ` Eric Wong
  2009-05-15  1:27       ` [PATCH v3] " Mark Lodato
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Wong @ 2009-05-10  0:35 UTC (permalink / raw)
  To: Mark Lodato; +Cc: Michael J Gruber, git, Junio C Hamano

Mark Lodato <lodatom@gmail.com> wrote:
> On Fri, May 8, 2009 at 3:43 AM, Michael J Gruber
> <git@drmicha.warpmail.net> wrote:
> > Mark Lodato venit, vidit, dixit 08.05.2009 03:11:
> > Maybe we want a config key also, just like for the authors file.
> 
> Yes, this is a very good idea.  I will figure out how to do this.

It already works :)  Command-line options taken by git svn have always
been automatically converted to config keys.

> > The feature itself looks useful for large user databases. For smaller
> > ones one could just as well update the authors file before each fetch by
> > dumping the whole db in there (or even conditionally on git svn fetch
> > erroring out due to encountering an unknown name).
> 
> Right.  This feature will most likely be useful in corporate
> environments.  In my case, it is not possible to dump the entire user
> database to a file, so this patch is the only solution.  Another
> possible use case is where SVN usernames are standardized, e.g. "jdoe"
> -> "J Doe <jdoe@example.com>".  Also, using --authors-prog solves the
> problem of keeping the authors file up-to-date, if users are regularly
> added or deleted.

Thanks Mark.  Your patch looks good and I'll apply the next one after
the grammar fixes.  I've actually thought about implementing this myself
back when I (briefly) worked in a corporate environment, but never
got around to it.

Sorry for the late response and not following the mailing list more
closely these days.

-- 
Eric Wong

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

* [PATCH v3] git-svn: add --authors-prog option
  2009-05-10  0:35     ` Eric Wong
@ 2009-05-15  1:27       ` Mark Lodato
  2009-05-21  8:43         ` Eric Wong
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Lodato @ 2009-05-15  1:27 UTC (permalink / raw)
  To: git; +Cc: Eric Wong, Junio C Hamano, Michael J Gruber, Mark Lodato

Add a new option, --authors-prog, to git-svn that allows a more flexible
alternative (or supplement) to --authors-file.  This allows more
advanced username operations than the authors file will allow.  For
example, one may look up Subversion users via LDAP, or may generate the
name and email address from the Subversion username.

Notes:

* If both --authors-name and --authors-prog are given, the former is
  tried first, falling back to the later.

* The program is called once per unique SVN username, and the result is
  cached.

* The command-line argument must be the path to a program, not a generic
  shell command line.  The absolute path to this program is taken at
  startup since the git-svn script changes directory during operation.

* The option is not enabled for `git svn log'.

Signed-off-by: Mark Lodato <lodatom@gmail.com>
---

Third attempt at the patch.  I fixed a typo and reworded the documentation
(thanks to Michael Gruber), and I fixed a small mistake in the commit message.
Other than rebasing onto master, nothing else was changed.

 Documentation/git-svn.txt       |    8 ++++
 git-svn.perl                    |   30 +++++++++++++++--
 t/t9138-git-svn-authors-prog.sh |   69 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 104 insertions(+), 3 deletions(-)
 create mode 100755 t/t9138-git-svn-authors-prog.sh

diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt
index 1c40894..ca3fc3d 100644
--- a/Documentation/git-svn.txt
+++ b/Documentation/git-svn.txt
@@ -398,6 +398,14 @@ after the authors-file is modified should continue operation.
 
 config key: svn.authorsfile
 
+--authors-prog=<filename>::
+
+If this option is specified, for each SVN committer name that does not
+exist in the authors file, the given file is executed with the committer
+name as the first argument.  The program is expected to return a single
+line of the form "Name <email>", which will be treated as if included in
+the authors file.
+
 -q::
 --quiet::
 	Make 'git-svn' less verbose. Specify a second time to make it
diff --git a/git-svn.perl b/git-svn.perl
index ef1d30d..f9c9567 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -5,7 +5,7 @@ use warnings;
 use strict;
 use vars qw/	$AUTHOR $VERSION
 		$sha1 $sha1_short $_revision $_repository
-		$_q $_authors %users/;
+		$_q $_authors $_authors_prog %users/;
 $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
 $VERSION = '@@GIT_VERSION@@';
 
@@ -39,6 +39,7 @@ use Digest::MD5;
 use IO::File qw//;
 use File::Basename qw/dirname basename/;
 use File::Path qw/mkpath/;
+use File::Spec;
 use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
 use IPC::Open3;
 use Git;
@@ -76,6 +77,7 @@ my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username,
                     'ignore-paths=s' => \$SVN::Git::Fetcher::_ignore_regex );
 my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent,
 		'authors-file|A=s' => \$_authors,
+		'authors-prog=s' => \$_authors_prog,
 		'repack:i' => \$Git::SVN::_repack,
 		'noMetadata' => \$Git::SVN::_no_metadata,
 		'useSvmProps' => \$Git::SVN::_use_svm_props,
@@ -263,6 +265,7 @@ usage(0) if $_help;
 version() if $_version;
 usage(1) unless defined $cmd;
 load_authors() if $_authors;
+$_authors_prog = "'" . File::Spec->rel2abs($_authors_prog) . "'";
 
 unless ($cmd =~ /^(?:clone|init|multi-init|commit-diff)$/) {
 	Git::SVN::Migration::migration_check();
@@ -2663,12 +2666,33 @@ sub other_gs {
 	$gs
 }
 
+sub call_authors_prog {
+	my ($orig_author) = @_;
+	my $author = `$::_authors_prog $orig_author`;
+	if ($? != 0) {
+		die "$::_authors_prog failed with exit code $?\n"
+	}
+	if ($author =~ /^\s*(.+?)\s*<(.*)>\s*$/) {
+		my ($name, $email) = ($1, $2);
+		$email = undef if length $2 == 0;
+		return [$name, $email];
+	} else {
+		die "Author: $orig_author: $::_authors_prog returned "
+			. "invalid author format: $author\n";
+	}
+}
+
 sub check_author {
 	my ($author) = @_;
 	if (!defined $author || length $author == 0) {
 		$author = '(no author)';
-	} elsif (defined $::_authors && ! defined $::users{$author}) {
-		die "Author: $author not defined in $::_authors file\n";
+	}
+	if (!defined $::users{$author}) {
+		if (defined $::_authors_prog) {
+			$::users{$author} = call_authors_prog($author);
+		} elsif (defined $::_authors) {
+			die "Author: $author not defined in $::_authors file\n";
+		}
 	}
 	$author;
 }
diff --git a/t/t9138-git-svn-authors-prog.sh b/t/t9138-git-svn-authors-prog.sh
new file mode 100755
index 0000000..a4b00f2
--- /dev/null
+++ b/t/t9138-git-svn-authors-prog.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+#
+# Copyright (c) 2009 Eric Wong, Mark Lodato
+#
+
+test_description='git svn authors prog tests'
+
+. ./lib-git-svn.sh
+
+cat > svn-authors-prog <<'EOF'
+#!/usr/bin/perl
+$_ = shift;
+if (s/-sub$//)  {
+	print "$_ <$_\@sub.example.com>\n";
+}
+else {
+	print "$_ <$_\@example.com>\n";
+}
+EOF
+chmod +x svn-authors-prog
+
+cat > svn-authors <<'EOF'
+ff = FFFFFFF FFFFFFF <fFf@other.example.com>
+EOF
+
+test_expect_success 'setup svnrepo' '
+	for i in aa bb cc-sub dd-sub ee-foo ff
+	do
+		svn mkdir -m $i --username $i "$svnrepo"/$i
+	done
+	'
+
+test_expect_success 'import authors with prog and file' '
+	git svn clone --authors-prog=./svn-authors-prog \
+	    --authors-file=svn-authors "$svnrepo" x
+	'
+
+test_expect_success 'imported 6 revisions successfully' '
+	(
+		cd x
+		test "`git rev-list refs/remotes/git-svn | wc -l`" -eq 6
+	)
+	'
+
+test_expect_success 'authors-prog ran correctly' '
+	(
+		cd x
+		git rev-list -1 --pretty=raw refs/remotes/git-svn~1 | \
+		  grep "^author ee-foo <ee-foo@example\.com> " &&
+		git rev-list -1 --pretty=raw refs/remotes/git-svn~2 | \
+		  grep "^author dd <dd@sub\.example\.com> " &&
+		git rev-list -1 --pretty=raw refs/remotes/git-svn~3 | \
+		  grep "^author cc <cc@sub\.example\.com> " &&
+		git rev-list -1 --pretty=raw refs/remotes/git-svn~4 | \
+		  grep "^author bb <bb@example\.com> " &&
+		git rev-list -1 --pretty=raw refs/remotes/git-svn~5 | \
+		  grep "^author aa <aa@example\.com> "
+	)
+	'
+
+test_expect_success 'authors-file overrode authors-prog' '
+	(
+		cd x
+		git rev-list -1 --pretty=raw refs/remotes/git-svn | \
+		  grep "^author FFFFFFF FFFFFFF <fFf@other\.example\.com> "
+	)
+	'
+
+test_done
-- 
1.6.3.1

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

* Re: [PATCH v3] git-svn: add --authors-prog option
  2009-05-15  1:27       ` [PATCH v3] " Mark Lodato
@ 2009-05-21  8:43         ` Eric Wong
  2009-05-21 14:30           ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Wong @ 2009-05-21  8:43 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Michael J Gruber, Mark Lodato

Mark Lodato <lodatom@gmail.com> wrote:
> Signed-off-by: Mark Lodato <lodatom@gmail.com>

Thanks again Mark, sorry again for the late response, it's been
a long few weeks for me.

Acked-by: Eric Wong <normalperson@yhbt.net>

And pushed out to git://git.bogomips.org/git-svn along with
a few others that I had acked:

Alex Vandiver (3):
      git-svn: Fix for svn paths removed > log-window-size revisions ago
      git-svn: Correctly report max revision when following deleted paths
      git-svn: Set svn.authorsfile if it is passed to git svn clone

Eygene Ryabinkin (1):
      git-svn testsuite: use standard configuration for Subversion tools

Mark Lodato (1):
      git-svn: add --authors-prog option

> ---
> 
> Third attempt at the patch.  I fixed a typo and reworded the documentation
> (thanks to Michael Gruber), and I fixed a small mistake in the commit message.
> Other than rebasing onto master, nothing else was changed.

A bunch of tests got broken but I squished this on top to fix them:

diff --git a/git-svn.perl b/git-svn.perl
index af80e24..a70c7d7 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -265,7 +265,9 @@ usage(0) if $_help;
 version() if $_version;
 usage(1) unless defined $cmd;
 load_authors() if $_authors;
-$_authors_prog = "'" . File::Spec->rel2abs($_authors_prog) . "'";
+if (defined $_authors_prog) {
+	$_authors_prog = "'" . File::Spec->rel2abs($_authors_prog) . "'";
+}
 
 unless ($cmd =~ /^(?:clone|init|multi-init|commit-diff)$/) {
 	Git::SVN::Migration::migration_check();

-- 
Eric Wong

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

* Re: [PATCH v3] git-svn: add --authors-prog option
  2009-05-21  8:43         ` Eric Wong
@ 2009-05-21 14:30           ` Junio C Hamano
  0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2009-05-21 14:30 UTC (permalink / raw)
  To: Eric Wong
  Cc: git, Alex Vandiver, Eygene Ryabinkin, Michael J Gruber, Mark Lodato

Eric Wong <normalperson@yhbt.net> writes:

> Mark Lodato <lodatom@gmail.com> wrote:
>> Signed-off-by: Mark Lodato <lodatom@gmail.com>
>
> Thanks again Mark, sorry again for the late response, it's been
> a long few weeks for me.
>
> Acked-by: Eric Wong <normalperson@yhbt.net>
>
> And pushed out to git://git.bogomips.org/git-svn along with
> a few others that I had acked:
>
> Alex Vandiver (3):
>       git-svn: Fix for svn paths removed > log-window-size revisions ago
>       git-svn: Correctly report max revision when following deleted paths
>       git-svn: Set svn.authorsfile if it is passed to git svn clone
>
> Eygene Ryabinkin (1):
>       git-svn testsuite: use standard configuration for Subversion tools
>
> Mark Lodato (1):
>       git-svn: add --authors-prog option

Thanks, pulled.

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

end of thread, other threads:[~2009-05-21 14:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-08  1:11 [PATCH v2] git-svn: add --authors-prog option Mark Lodato
2009-05-08  7:43 ` Michael J Gruber
2009-05-09  3:48   ` Mark Lodato
2009-05-10  0:35     ` Eric Wong
2009-05-15  1:27       ` [PATCH v3] " Mark Lodato
2009-05-21  8:43         ` Eric Wong
2009-05-21 14:30           ` Junio C Hamano

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).