Skip to content

Commit

Permalink
Merge git://git.bogomips.org/git-svn
Browse files Browse the repository at this point in the history
* git://git.bogomips.org/git-svn:
  git-svn: add --authors-prog option
  git-svn: Set svn.authorsfile if it is passed to git svn clone
  git-svn: Correctly report max revision when following deleted paths
  git-svn: Fix for svn paths removed > log-window-size revisions ago
  git-svn testsuite: use standard configuration for Subversion tools
  • Loading branch information
Junio C Hamano committed May 21, 2009
2 parents fe87c92 + 36db1ed commit 581412c
Show file tree
Hide file tree
Showing 32 changed files with 334 additions and 211 deletions.
8 changes: 8 additions & 0 deletions Documentation/git-svn.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 36 additions & 5 deletions git-svn.perl
Original file line number Diff line number Diff line change
Expand Up @@ -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@@';

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -361,6 +366,7 @@ sub cmd_clone {
$path = basename($url) if !defined $path || !length $path;
cmd_init($url, $path);
Git::SVN::fetch_all($Git::SVN::default_repo_id);
command_oneline('config', 'svn.authorsfile', $_authors) if $_authors;
}

sub cmd_init {
Expand Down Expand Up @@ -2663,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;
}
Expand Down Expand Up @@ -4438,6 +4465,7 @@ sub gs_fetch_loop_common {
my ($min, $max) = ($base, $head < $base + $inc ? $head : $base + $inc);
my $longest_path = longest_common_path($gsv, $globs);
my $ra_url = $self->{url};
my $find_trailing_edge;
while (1) {
my %revs;
my $err;
Expand All @@ -4455,8 +4483,10 @@ sub gs_fetch_loop_common {
sub { $revs{$_[1]} = _cb(@_) });
if ($err) {
print "Checked through r$max\r";
} else {
$find_trailing_edge = 1;
}
if ($err && $max >= $head) {
if ($err and $find_trailing_edge) {
print STDERR "Path '$longest_path' ",
"was probably deleted:\n",
$err->expanded_message,
Expand All @@ -4468,13 +4498,14 @@ sub gs_fetch_loop_common {
my $ok;
$self->get_log([$longest_path], $min, $hi,
0, 1, 1, sub {
$ok ||= $_[1];
$ok = $_[1];
$revs{$_[1]} = _cb(@_) });
if ($ok) {
print STDERR "r$min .. r$ok OK\n";
last;
}
}
$find_trailing_edge = 0;
}
$SVN::Error::handler = $err_handler;

Expand Down
15 changes: 15 additions & 0 deletions t/lib-git-svn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ fi

svnrepo=$PWD/svnrepo
export svnrepo
svnconf=$PWD/svnconf
export svnconf

perl -w -e "
use SVN::Core;
Expand Down Expand Up @@ -54,6 +56,19 @@ poke() {
test-chmtime +1 "$1"
}

# We need this, because we should pass empty configuration directory to
# the 'svn commit' to avoid automated property changes and other stuff
# that could be set from user's configuration files in ~/.subversion.
svn_cmd () {
[ -d "$svnconf" ] || mkdir "$svnconf"
orig_svncmd="$1"; shift
if [ -z "$orig_svncmd" ]; then
svn
return
fi
svn "$orig_svncmd" --config-dir "$svnconf" "$@"
}

for d in \
"$SVN_HTTPD_PATH" \
/usr/sbin/apache2 \
Expand Down
14 changes: 7 additions & 7 deletions t/t9100-git-svn-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test_expect_success \
echo "zzz" > bar/zzz &&
echo "#!/bin/sh" > exec.sh &&
chmod +x exec.sh &&
svn import -m "import for git svn" . "$svnrepo" >/dev/null &&
svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null &&
cd .. &&
rm -rf import &&
git svn init "$svnrepo"'
Expand All @@ -51,7 +51,7 @@ test_expect_success "$name" '
git commit -m "$name" &&
git svn set-tree --find-copies-harder --rmdir \
${remotes_git_svn}..mybranch &&
svn up "$SVN_TREE" &&
svn_cmd up "$SVN_TREE" &&
test -d "$SVN_TREE"/dir && test ! -d "$SVN_TREE"/dir/a'


Expand Down Expand Up @@ -118,7 +118,7 @@ test_expect_success "$name" '
git commit -m "$name" &&
git svn set-tree --find-copies-harder --rmdir \
${remotes_git_svn}..mybranch5 &&
svn up "$SVN_TREE" &&
svn_cmd up "$SVN_TREE" &&
test ! -x "$SVN_TREE"/exec.sh'


Expand All @@ -129,7 +129,7 @@ test_expect_success "$name" '
git commit -m "$name" &&
git svn set-tree --find-copies-harder --rmdir \
${remotes_git_svn}..mybranch5 &&
svn up "$SVN_TREE" &&
svn_cmd up "$SVN_TREE" &&
test -x "$SVN_TREE"/exec.sh'


Expand All @@ -141,7 +141,7 @@ test_expect_success "$name" '
git commit -m "$name" &&
git svn set-tree --find-copies-harder --rmdir \
${remotes_git_svn}..mybranch5 &&
svn up "$SVN_TREE" &&
svn_cmd up "$SVN_TREE" &&
test -L "$SVN_TREE"/exec.sh'

name='new symlink is added to a file that was also just made executable'
Expand All @@ -153,7 +153,7 @@ test_expect_success "$name" '
git commit -m "$name" &&
git svn set-tree --find-copies-harder --rmdir \
${remotes_git_svn}..mybranch5 &&
svn up "$SVN_TREE" &&
svn_cmd up "$SVN_TREE" &&
test -x "$SVN_TREE"/bar/zzz &&
test -L "$SVN_TREE"/exec-2.sh'

Expand All @@ -166,7 +166,7 @@ test_expect_success "$name" '
git commit -m "$name" &&
git svn set-tree --find-copies-harder --rmdir \
${remotes_git_svn}..mybranch5 &&
svn up "$SVN_TREE" &&
svn_cmd up "$SVN_TREE" &&
test -f "$SVN_TREE"/exec-2.sh &&
test ! -L "$SVN_TREE"/exec-2.sh &&
test_cmp help "$SVN_TREE"/exec-2.sh'
Expand Down
38 changes: 19 additions & 19 deletions t/t9101-git-svn-props.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ EOF
printf "\r\n" > empty_crlf
a_empty_crlf=`git hash-object -w empty_crlf`

svn import --no-auto-props -m 'import for git svn' . "$svnrepo" >/dev/null
svn_cmd import --no-auto-props -m 'import for git svn' . "$svnrepo" >/dev/null
cd ..

rm -rf import
Expand All @@ -57,13 +57,13 @@ test_expect_success 'setup some commits to svn' \
'cd test_wc &&
echo Greetings >> kw.c &&
poke kw.c &&
svn commit -m "Not yet an Id" &&
svn_cmd commit -m "Not yet an Id" &&
echo Hello world >> kw.c &&
poke kw.c &&
svn commit -m "Modified file, but still not yet an Id" &&
svn propset svn:keywords Id kw.c &&
svn_cmd commit -m "Modified file, but still not yet an Id" &&
svn_cmd propset svn:keywords Id kw.c &&
poke kw.c &&
svn commit -m "Propset Id" &&
svn_cmd commit -m "Propset Id" &&
cd ..'

test_expect_success 'initialize git svn' 'git svn init "$svnrepo"'
Expand All @@ -83,16 +83,16 @@ test_expect_success 'raw $Id$ found in kw.c' "test '$expect' = '$got'"

test_expect_success "propset CR on crlf files" \
'cd test_wc &&
svn propset svn:eol-style CR empty &&
svn propset svn:eol-style CR crlf &&
svn propset svn:eol-style CR ne_crlf &&
svn commit -m "propset CR on crlf files" &&
svn_cmd propset svn:eol-style CR empty &&
svn_cmd propset svn:eol-style CR crlf &&
svn_cmd propset svn:eol-style CR ne_crlf &&
svn_cmd commit -m "propset CR on crlf files" &&
cd ..'

test_expect_success 'fetch and pull latest from svn and checkout a new wc' \
'git svn fetch &&
git pull . ${remotes_git_svn} &&
svn co "$svnrepo" new_wc'
svn_cmd co "$svnrepo" new_wc'

for i in crlf ne_crlf lf ne_lf cr ne_cr empty_cr empty_lf empty empty_crlf
do
Expand All @@ -106,11 +106,11 @@ cd test_wc
a_cr=`printf '$Id$\r\nHello\r\nWorld\r\n' | git hash-object --stdin`
a_ne_cr=`printf '$Id$\r\nHello\r\nWorld' | git hash-object --stdin`
test_expect_success 'Set CRLF on cr files' \
'svn propset svn:eol-style CRLF cr &&
svn propset svn:eol-style CRLF ne_cr &&
svn propset svn:keywords Id cr &&
svn propset svn:keywords Id ne_cr &&
svn commit -m "propset CRLF on cr files"'
'svn_cmd propset svn:eol-style CRLF cr &&
svn_cmd propset svn:eol-style CRLF ne_cr &&
svn_cmd propset svn:keywords Id cr &&
svn_cmd propset svn:keywords Id ne_cr &&
svn_cmd commit -m "propset CRLF on cr files"'
cd ..
test_expect_success 'fetch and pull latest from svn' \
'git svn fetch && git pull . ${remotes_git_svn}'
Expand Down Expand Up @@ -140,10 +140,10 @@ test_expect_success 'test show-ignore' "
cd test_wc &&
mkdir -p deeply/nested/directory &&
touch deeply/nested/directory/.keep &&
svn add deeply &&
svn up &&
svn propset -R svn:ignore 'no-such-file*' .
svn commit -m 'propset svn:ignore'
svn_cmd add deeply &&
svn_cmd up &&
svn_cmd propset -R svn:ignore 'no-such-file*' .
svn_cmd commit -m 'propset svn:ignore'
cd .. &&
git svn show-ignore > show-ignore.got &&
cmp show-ignore.expect show-ignore.got
Expand Down
4 changes: 2 additions & 2 deletions t/t9102-git-svn-deep-rmdir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test_expect_success 'initialize repo' '
mkdir -p deeply/nested/directory/number/2 &&
echo foo > deeply/nested/directory/number/1/file &&
echo foo > deeply/nested/directory/number/2/another &&
svn import -m "import for git svn" . "$svnrepo" &&
svn_cmd import -m "import for git svn" . "$svnrepo" &&
cd ..
'

Expand All @@ -23,7 +23,7 @@ test_expect_success 'Try a commit on rmdir' '
git rm -f deeply/nested/directory/number/2/another &&
git commit -a -m "remove another" &&
git svn set-tree --rmdir HEAD &&
svn ls -R "$svnrepo" | grep ^deeply/nested/directory/number/1
svn_cmd ls -R "$svnrepo" | grep ^deeply/nested/directory/number/1
'


Expand Down
8 changes: 4 additions & 4 deletions t/t9103-git-svn-tracked-directory-removed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ test_expect_success 'make history for tracking' '
mkdir import &&
mkdir import/trunk &&
echo hello >> import/trunk/README &&
svn import -m initial import "$svnrepo" &&
svn_cmd import -m initial import "$svnrepo" &&
rm -rf import &&
svn co "$svnrepo"/trunk trunk &&
svn_cmd co "$svnrepo"/trunk trunk &&
echo bye bye >> trunk/README &&
svn rm -m "gone" "$svnrepo"/trunk &&
svn_cmd rm -m "gone" "$svnrepo"/trunk &&
rm -rf trunk &&
mkdir trunk &&
echo "new" > trunk/FOLLOWME &&
svn import -m "new trunk" trunk "$svnrepo"/trunk
svn_cmd import -m "new trunk" trunk "$svnrepo"/trunk
'

test_expect_success 'clone repo with git' '
Expand Down
Loading

0 comments on commit 581412c

Please sign in to comment.