Commit 36db1edd authored by Mark Lodato's avatar Mark Lodato Committed by Eric Wong

git-svn: add --authors-prog option

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

[ew: fixed case where neither --authors-(name|prog) were defined]
Signed-off-by: Mark Lodato's avatarMark Lodato <lodatom@gmail.com>
Acked-by: default avatarEric Wong <normalperson@yhbt.net>
parent 42a5da18
......@@ -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
......
......@@ -5,7 +5,7 @@
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 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 @@ BEGIN
'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,9 @@ BEGIN
version() if $_version;
usage(1) unless defined $cmd;
load_authors() if $_authors;
if (defined $_authors_prog) {
$_authors_prog = "'" . File::Spec->rel2abs($_authors_prog) . "'";
}
unless ($cmd =~ /^(?:clone|init|multi-init|commit-diff)$/) {
Git::SVN::Migration::migration_check();
......@@ -2664,12 +2669,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;
}
......
#!/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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment