git-svn: use git-log rather than rev-list | xargs cat-file
This saves a bit of time when rebuilding the git-svn index. Signed-off-by: Sam Vilain <sam.vilain@catalyst.net.nz> Acked-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Sam Vilain committed
Jun 30, 2007 at 20:56 UTC
3dfab993c8c9a30450635e4d660f26bb508ae3af
1 file changed
+22
-14
git-svn.perl
+22
-14
@@ -787,12 +787,12 @@ sub read_repo_config {
787
788
sub extract_metadata {
789
my $id = shift or return (undef, undef, undef);
790
- my ($url, $rev, $uuid) = ($id =~ /^git-svn-id:\s(\S+?)\@(\d+)
790
+ my ($url, $rev, $uuid) = ($id =~ /^\s*git-svn-id:\s+(.*)\@(\d+)
791
\s([a-f\d\-]+)$/x);
792
if (!defined $rev || !$uuid || !$url) {
793
# some of the original repositories I made had
794
# identifiers like this:
795
- ($rev, $uuid) = ($id =~/^git-svn-id:\s(\d+)\@([a-f\d\-]+)/);
795
+ ($rev, $uuid) = ($id =~/^\s*git-svn-id:\s(\d+)\@([a-f\d\-]+)/);
796
}
797
return ($url, $rev, $uuid);
798
}
@@ -804,10 +804,16 @@ sub cmt_metadata {
804
805
sub working_head_info {
806
my ($head, $refs) = @_;
807
- my ($fh, $ctx) = command_output_pipe('rev-list', $head);
808
- while (my $hash = <$fh>) {
809
- chomp($hash);
810
- my ($url, $rev, $uuid) = cmt_metadata($hash);
807
+ my ($fh, $ctx) = command_output_pipe('log', $head);
808
+ my $hash;
809
+ while (<$fh>) {
810
+ if ( m{^commit ($::sha1)$} ) {
811
+ unshift @$refs, $hash if $hash and $refs;
812
+ $hash = $1;
813
+ next;
814
+ }
815
+ next unless s{^\s*(git-svn-id:)}{$1};
816
+ my ($url, $rev, $uuid) = extract_metadata($_);
817
if (defined $url && defined $rev) {
818
if (my $gs = Git::SVN->find_by_url($url)) {
819
my $c = $gs->rev_db_get($rev);
@@ -817,7 +823,6 @@ sub working_head_info {
823
}
824
}
825
}
820
- unshift @$refs, $hash if $refs;
826
}
827
command_close_pipe($fh, $ctx);
828
(undef, undef, undef, undef);
@@ -1966,16 +1971,19 @@ sub rebuild {
1971
return;
1972
}
1973
print "Rebuilding $db_path ...\n";
1969
- my ($rev_list, $ctx) = command_output_pipe("rev-list", $self->refname);
1974
+ my ($log, $ctx) = command_output_pipe("log", $self->refname);
1975
my $latest;
1976
my $full_url = $self->full_url;
1977
remove_username($full_url);
1978
my $svn_uuid;
1974
- while (<$rev_list>) {
1975
- chomp;
1976
- my $c = $_;
1977
- die "Non-SHA1: $c\n" unless $c =~ /^$::sha1$/o;
1978
- my ($url, $rev, $uuid) = ::cmt_metadata($c);
1979
+ my $c;
1980
+ while (<$log>) {
1981
+ if ( m{^commit ($::sha1)$} ) {
1982
+ $c = $1;
1983
+ next;
1984
+ }
1985
+ next unless s{^\s*(git-svn-id:)}{$1};
1986
+ my ($url, $rev, $uuid) = ::extract_metadata($_);
1987
remove_username($url);
1988
1989
# ignore merges (from set-tree)
@@ -1993,7 +2001,7 @@ sub rebuild {
2001
$self->rev_db_set($rev, $c);
2002
print "r$rev = $c\n";
2003
}
1996
- command_close_pipe($rev_list, $ctx);
2004
+ command_close_pipe($log, $ctx);
2005
print "Done rebuilding $db_path\n";
2006
}
2007