Skip to content

Commit

Permalink
git-svn: remove the 'rebuild' command and make the functionality auto…
Browse files Browse the repository at this point in the history
…matic

Since refs/remotes/* are not automatically cloned, we expect the
user to be capable of copying those references themselves
anyways.

Also removed the documentation for --ignore-nodate while we're
at it; it has also been made automatic.

Signed-off-by: Eric Wong <normalperson@yhbt.net>
  • Loading branch information
Eric Wong committed Feb 23, 2007
1 parent 2893705 commit f0ecca1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 94 deletions.
41 changes: 3 additions & 38 deletions Documentation/git-svn.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,6 @@ remotes/git-svn.
commit. All merging is assumed to have taken place
independently of git-svn functions.

'rebuild'::
Not a part of daily usage, but this is a useful command if
you've just cloned a repository (using gitlink:git-clone[1]) that was
tracked with git-svn. Unfortunately, git-clone does not clone
git-svn metadata and the svn working tree that git-svn uses for
its operations. This rebuilds the metadata so git-svn can
resume fetch operations. A Subversion URL may be optionally
specified at the command-line if the directory/repository you're
tracking has moved or changed protocols.

'show-ignore'::
Recursively finds and lists the svn:ignore property on
directories. The output is suitable for appending to
Expand Down Expand Up @@ -322,9 +312,9 @@ config key: svn.followparent
--no-metadata::
This gets rid of the git-svn-id: lines at the end of every commit.

With this, you lose the ability to use the rebuild command. If
you ever lose your .git/svn/git-svn/.rev_db file, you won't be
able to fetch again, either. This is fine for one-shot imports.
If you lose your .git/svn/git-svn/.rev_db file, git-svn will not
be able to rebuild it and you won't be able to fetch again,
either. This is fine for one-shot imports.

The 'git-svn log' command will not work on repositories using this,
either.
Expand All @@ -333,31 +323,6 @@ config key: svn.nometadata

--

COMPATIBILITY OPTIONS
---------------------
--

--upgrade::
Only used with the 'rebuild' command.

Run this if you used an old version of git-svn that used
"git-svn-HEAD" instead of "remotes/git-svn" as the branch
for tracking the remote.

--ignore-nodate::
Only used with the 'fetch' command.

By default git-svn will crash if it tries to import a revision
from SVN which has '(no date)' listed as the date of the revision.
This is repository corruption on SVN's part, plain and simple.
But sometimes you really need those revisions anyway.

If supplied git-svn will convert '(no date)' entries to the UNIX
epoch (midnight on Jan. 1, 1970). Yes, that's probably very wrong.
SVN was very wrong.

--

Basic Examples
~~~~~~~~~~~~~~

Expand Down
92 changes: 36 additions & 56 deletions git-svn.perl
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ BEGIN
{ 'stdin|' => \$_stdin, %cmt_opts, %fc_opts, } ],
'show-ignore' => [ \&cmd_show_ignore, "Show svn:ignore listings",
{ 'revision|r=i' => \$_revision } ],
rebuild => [ \&cmd_rebuild, "Rebuild git-svn metadata (after git clone)",
{ 'copy-remote|remote=s' => \$_cp_remote,
'upgrade' => \$_upgrade } ],
'multi-init' => [ \&cmd_multi_init,
'Initialize multiple trees (like git-svnimport)',
{ %multi_opts, %init_opts, %remote_opts,
Expand Down Expand Up @@ -166,7 +163,7 @@ BEGIN
version() if $_version;
usage(1) unless defined $cmd;
load_authors() if $_authors;
unless ($cmd =~ /^(?:init|rebuild|multi-init|commit-diff)$/) {
unless ($cmd =~ /^(?:init|multi-init|commit-diff)$/) {
Git::SVN::Migration::migration_check();
}
eval {
Expand Down Expand Up @@ -211,47 +208,6 @@ sub version {
exit 0;
}
sub cmd_rebuild {
my $url = shift;
my $gs = $url ? Git::SVN->init($url)
: eval { Git::SVN->new };
$gs ||= Git::SVN->_new;
if (!verify_ref($gs->refname.'^0')) {
$gs->copy_remote_ref;
}
my ($rev_list, $ctx) = command_output_pipe("rev-list", $gs->refname);
my $latest;
my $svn_uuid;
while (<$rev_list>) {
chomp;
my $c = $_;
fatal "Non-SHA1: $c\n" unless $c =~ /^$sha1$/o;
my ($url, $rev, $uuid) = cmt_metadata($c);

# ignore merges (from set-tree)
next if (!defined $rev || !$uuid);

# if we merged or otherwise started elsewhere, this is
# how we break out of it
if ((defined $svn_uuid && ($uuid ne $svn_uuid)) ||
($gs->{url} && $url && ($url ne $gs->{url}))) {
next;
}

unless (defined $latest) {
if (!$gs->{url} && !$url) {
fatal "SVN repository location required\n";
}
$gs = Git::SVN->init($url);
$latest = $rev;
}
$gs->rev_db_set($rev, $c);
print "r$rev = $c\n";
}
command_close_pipe($rev_list, $ctx);
}

sub do_git_init_db {
unless (-d $ENV{GIT_DIR}) {
my @init_db = ('init');
Expand Down Expand Up @@ -863,6 +819,9 @@ sub new {
$self->{url} = command_oneline('config', '--get',
"svn-remote.$repo_id.url") or
die "Failed to read \"svn-remote.$repo_id.url\" in config\n";
if (-z $self->{db_path} && ::verify_ref($self->refname.'^0')) {
$self->rebuild;
}
$self;
}

Expand All @@ -883,17 +842,6 @@ sub rel_path {
$url;
}

sub copy_remote_ref {
my ($self) = @_;
my $origin = $::_cp_remote ? $::_cp_remote : 'origin';
my $ref = $self->refname;
if (command('ls-remote', $origin, $ref)) {
command_noisy('fetch', $origin, "$ref:$ref");
} elsif ($::_cp_remote && !$::_upgrade) {
die "Unable to find remote reference: $ref on $origin\n";
}
}

sub traverse_ignore {
my ($self, $fh, $path, $r) = @_;
$path =~ s#^/+##g;
Expand Down Expand Up @@ -1359,6 +1307,38 @@ sub set_tree {
}
}

sub rebuild {
my ($self) = @_;
print "Rebuilding $self->{db_path} ...\n";
my ($rev_list, $ctx) = command_output_pipe("rev-list", $self->refname);
my $latest;
my $full_url = $self->full_url;
my $svn_uuid;
while (<$rev_list>) {
chomp;
my $c = $_;
die "Non-SHA1: $c\n" unless $c =~ /^$::sha1$/o;
my ($url, $rev, $uuid) = ::cmt_metadata($c);

# ignore merges (from set-tree)
next if (!defined $rev || !$uuid);

# if we merged or otherwise started elsewhere, this is
# how we break out of it
if ((defined $svn_uuid && ($uuid ne $svn_uuid)) ||
($full_url && $url && ($url ne $full_url))) {
next;
}
$latest ||= $rev;
$svn_uuid ||= $uuid;

$self->rev_db_set($rev, $c);
print "r$rev = $c\n";
}
command_close_pipe($rev_list, $ctx);
print "Done rebuilding $self->{db_path}\n";
}

# rev_db:
# Tie::File seems to be prone to offset errors if revisions get sparse,
# it's not that fast, either. Tie::File is also not in Perl 5.6. So
Expand Down

0 comments on commit f0ecca1

Please sign in to comment.