Skip to contentSkip to conversation

git-svn: add --authors-prog option

PATCH Superseded Mark Lodato 1 participant 1 message Jun 15, 2016 Documentation

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-svn: add --authors-prog option

Added a new option, --authors-prog, to git-svn that allows a more flexible alternative (or supplement) to --authors-file. 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.

The purpose of this option is to allow more advanced username operations than the authors file will allow, such as looking up users via LDAP as they are encountered, or automatically computing the name and email from the username.

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

Notes:

* I did not implement this option for the 'log' command, which should probably be done.

* The test could probably be a bit more extensive.

* The argument is assumed to be a path to a program; it does not allow any generic command line.

So, does this seem like something that could be included in the future? Such an option would be really handy for me, since I have many SVN users who are all in a database.

Documentation/git-svn.txt +8 -0
index 1c40894..78582ad 100644
@@ -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
git-svn.perl +27 -3
index c5965c9..472f575 100755
@@ -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 <[email protected]>';
 $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;
 }
t/t9138-git-svn-authors-prog.sh new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
1.6.2.4