@matheusbsbs / matheus-bagliano / commits / 01bdab84e3
Fork 0

git-svn: add a generic tree traversal to fetch SVN properties

* git-svn.perl (&traverse_ignore): Remove. (&prop_walk): New. (&cmd_show_ignore): Use prop_walk. [ew: This will ease the implementation of the `create-ignore', `propget', and `proplist' commands] Signed-off-by: Benoit Sigoure <tsuna@lrde.epita.fr> Acked-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Benoit Sigoure committed Oct 16, 2007 at 16:36 UTC 01bdab84e31763a98206c31cf99b9dc3cb221356
1 file changed +45 -20
git-svn.perl
+45 -20
@@ -488,7 +488,15 @@ sub cmd_show_ignore {
488 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
489 $gs ||= Git::SVN->new;
490 my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
491 - $gs->traverse_ignore(\*STDOUT, $gs->{path}, $r);
491 + $gs->prop_walk($gs->{path}, $r, sub {
492 + my ($gs, $path, $props) = @_;
493 + print STDOUT "\n# $path\n";
494 + my $s = $props->{'svn:ignore'} or return;
495 + $s =~ s/[\r\n]+/\n/g;
496 + chomp $s;
497 + $s =~ s#^#$path#gm;
498 + print STDOUT "$s\n";
499 + });
500 }
501
502 sub cmd_multi_init {
@@ -1480,28 +1488,45 @@ sub rel_path {
1488 $url;
1489 }
1490
1483 -sub traverse_ignore {
1484 - my ($self, $fh, $path, $r) = @_;
1485 - $path =~ s#^/+##g;
1486 - my $ra = $self->ra;
1487 - my ($dirent, undef, $props) = $ra->get_dir($path, $r);
1491 +# prop_walk(PATH, REV, SUB)
1492 +# -------------------------
1493 +# Recursively traverse PATH at revision REV and invoke SUB for each
1494 +# directory that contains a SVN property. SUB will be invoked as
1495 +# follows: &SUB(gs, path, props); where `gs' is this instance of
1496 +# Git::SVN, `path' the path to the directory where the properties
1497 +# `props' were found. The `path' will be relative to point of checkout,
1498 +# that is, if url://repo/trunk is the current Git branch, and that
1499 +# directory contains a sub-directory `d', SUB will be invoked with `/d/'
1500 +# as `path' (note the trailing `/').
1501 +sub prop_walk {
1502 + my ($self, $path, $rev, $sub) = @_;
1503 +
1504 + my ($dirent, undef, $props) = $self->ra->get_dir($path, $rev);
1505 + $path =~ s#^/*#/#g;
1506 my $p = $path;
1489 - $p =~ s#^\Q$self->{path}\E(/|$)##;
1490 - print $fh length $p ? "\n# $p\n" : "\n# /\n";
1491 - if (my $s = $props->{'svn:ignore'}) {
1492 - $s =~ s/[\r\n]+/\n/g;
1493 - chomp $s;
1494 - if (length $p == 0) {
1495 - $s =~ s#\n#\n/$p#g;
1496 - print $fh "/$s\n";
1497 - } else {
1498 - $s =~ s#\n#\n/$p/#g;
1499 - print $fh "/$p/$s\n";
1500 - }
1501 - }
1507 + # Strip the irrelevant part of the path.
1508 + $p =~ s#^/+\Q$self->{path}\E(/|$)#/#;
1509 + # Ensure the path is terminated by a `/'.
1510 + $p =~ s#/*$#/#;
1511 +
1512 + # The properties contain all the internal SVN stuff nobody
1513 + # (usually) cares about.
1514 + my $interesting_props = 0;
1515 + foreach (keys %{$props}) {
1516 + # If it doesn't start with `svn:', it must be a
1517 + # user-defined property.
1518 + ++$interesting_props and next if $_ !~ /^svn:/;
1519 + # FIXME: Fragile, if SVN adds new public properties,
1520 + # this needs to be updated.
1521 + ++$interesting_props if /^svn:(?:ignore|keywords|executable
1522 + |eol-style|mime-type
1523 + |externals|needs-lock)$/x;
1524 + }
1525 + &$sub($self, $p, $props) if $interesting_props;
1526 +
1527 foreach (sort keys %$dirent) {
1528 next if $dirent->{$_}->{kind} != $SVN::Node::dir;
1504 - $self->traverse_ignore($fh, "$path/$_", $r);
1529 + $self->prop_walk($path . '/' . $_, $rev, $sub);
1530 }
1531 }
1532