git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/5] Add a generic tree traversal to fetch SVN properties.
@ 2007-10-15 15:35 Benoit Sigoure
  2007-10-15 15:35 ` [PATCH 2/5] Implement git svn create-ignore Benoit Sigoure
  2007-10-16  7:43 ` [PATCH 1/5] Add a generic tree traversal to fetch SVN properties Eric Wong
  0 siblings, 2 replies; 8+ messages in thread
From: Benoit Sigoure @ 2007-10-15 15:35 UTC (permalink / raw)
  To: git; +Cc: normalperson, Benoit Sigoure

	* git-svn.perl (&traverse_ignore): Remove.
	(&prop_walk): New.
	(&cmd_show_ignore): Use prop_walk.

Signed-off-by: Benoit Sigoure <tsuna@lrde.epita.fr>
---
 git-svn.perl |   66 ++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 46 insertions(+), 20 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index 777e436..abc83ec 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -488,7 +488,15 @@ sub cmd_show_ignore {
 	my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
 	$gs ||= Git::SVN->new;
 	my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
-	$gs->traverse_ignore(\*STDOUT, $gs->{path}, $r);
+	$gs->prop_walk($gs->{path}, $r, sub {
+		my ($gs, $path, $props) = @_;
+		print STDOUT "\n# $path\n";
+		my $s = $props->{'svn:ignore'} or return;
+		$s =~ s/[\r\n]+/\n/g;
+		chomp $s;
+		$s =~ s#^#$path#gm;
+		print STDOUT "$s\n";
+	});
 }
 
 sub cmd_multi_init {
@@ -1480,28 +1488,46 @@ sub rel_path {
 	$url;
 }
 
-sub traverse_ignore {
-	my ($self, $fh, $path, $r) = @_;
-	$path =~ s#^/+##g;
-	my $ra = $self->ra;
-	my ($dirent, undef, $props) = $ra->get_dir($path, $r);
+# prop_walk(PATH, REV, SUB)
+# -------------------------
+# Recursively traverse PATH at revision REV and invoke SUB for each
+# directory that contains a SVN property.  SUB will be invoked as
+# follows:  &SUB(gs, path, props);  where `gs' is this instance of
+# Git::SVN, `path' the path to the directory where the properties
+# `props' were found.  The `path' will be relative to point of checkout,
+# that is, if url://repo/trunk is the current Git branch, and that
+# directory contains a sub-directory `d', SUB will be invoked with `/d/'
+# as `path' (note the trailing `/').
+sub prop_walk {
+	my ($self, $path, $rev, $sub) = @_;
+
+	my ($dirent, undef, $props) = $self->ra->get_dir($path, $rev);
+	$path =~ s#^/*#/#g;
 	my $p = $path;
-	$p =~ s#^\Q$self->{path}\E(/|$)##;
-	print $fh length $p ? "\n# $p\n" : "\n# /\n";
-	if (my $s = $props->{'svn:ignore'}) {
-		$s =~ s/[\r\n]+/\n/g;
-		chomp $s;
-		if (length $p == 0) {
-			$s =~ s#\n#\n/$p#g;
-			print $fh "/$s\n";
-		} else {
-			$s =~ s#\n#\n/$p/#g;
-			print $fh "/$p/$s\n";
-		}
-	}
+	# Strip the irrelevant part of the path.
+	$p =~ s#^/+\Q$self->{path}\E(/|$)#/#;
+	# Ensure the path is terminated by a `/'.
+	$p =~ s#/*$#/#;
+
+	# The properties contain all the internal SVN stuff nobody
+	# (usually) cares about.
+	my $interesting_props = 0;
+	foreach(keys %{$props})
+	{
+		# If it doesn't start with `svn:', it must be a
+		# user-defined property.
+		++$interesting_props and next if $_ !~ /^svn:/;
+		# FIXME: Fragile, if SVN adds new public properties,
+		# this needs to be updated.
+		++$interesting_props if /^svn:(?:ignore|keywords|executable
+		                                 |eol-style|mime-type
+						 |externals|needs-lock)$/x;
+	}
+	&$sub($self, $p, $props) if $interesting_props;
+
 	foreach (sort keys %$dirent) {
 		next if $dirent->{$_}->{kind} != $SVN::Node::dir;
-		$self->traverse_ignore($fh, "$path/$_", $r);
+		$self->prop_walk($path . '/' . $_, $rev, $sub);
 	}
 }
 
-- 
1.5.3.4.214.g6f43

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/5] Implement git svn create-ignore.
  2007-10-15 15:35 [PATCH 1/5] Add a generic tree traversal to fetch SVN properties Benoit Sigoure
@ 2007-10-15 15:35 ` Benoit Sigoure
  2007-10-15 15:35   ` [PATCH 3/5] Add git svn propget Benoit Sigoure
  2007-10-16  7:43 ` [PATCH 1/5] Add a generic tree traversal to fetch SVN properties Eric Wong
  1 sibling, 1 reply; 8+ messages in thread
From: Benoit Sigoure @ 2007-10-15 15:35 UTC (permalink / raw)
  To: git; +Cc: normalperson, Benoit Sigoure

	* git-svn.perl (%cmd): Add the new command `create-ignore'.
	(&cmd_create_ignore): New.
	* t/t9101-git-svn-props.sh: Adjust the test-case for show-ignore and
	add a test case for create-ignore.

Signed-off-by: Benoit Sigoure <tsuna@lrde.epita.fr>
---
 git-svn.perl             |   27 +++++++++++++++++++++++++++
 t/t9101-git-svn-props.sh |   28 +++++++++++++++++++++++++---
 2 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index abc83ec..94091ea 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -123,6 +123,10 @@ my %cmd = (
 	'set-tree' => [ \&cmd_set_tree,
 	                "Set an SVN repository to a git tree-ish",
 			{ 'stdin|' => \$_stdin, %cmt_opts, %fc_opts, } ],
+	'create-ignore' => [ \&cmd_create_ignore,
+			     'Create a .gitignore per svn:ignore',
+			     { 'revision|r=i' => \$_revision
+			     } ],
 	'show-ignore' => [ \&cmd_show_ignore, "Show svn:ignore listings",
 			{ 'revision|r=i' => \$_revision
 			} ],
@@ -499,6 +503,29 @@ sub cmd_show_ignore {
 	});
 }
 
+sub cmd_create_ignore {
+	my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
+	$gs ||= Git::SVN->new;
+	my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
+	$gs->prop_walk($gs->{path}, $r, sub {
+		my ($gs, $path, $props) = @_;
+		# $path is of the form /path/to/dir/
+		my $ignore = '.' . $path . '.gitignore';
+		my $s = $props->{'svn:ignore'} or return;
+		open(GITIGNORE, '>', $ignore)
+		  or fatal("Failed to open `$ignore' for writing: $!\n");
+		$s =~ s/[\r\n]+/\n/g;
+		chomp $s;
+		# Prefix all patterns so that the ignore doesn't apply
+		# to sub-directories.
+		$s =~ s#^#/#gm;
+		print GITIGNORE "$s\n";
+		close(GITIGNORE)
+		  or fatal("Failed to close `$ignore': $!\n");
+		command_noisy('add', $ignore);
+	});
+}
+
 sub cmd_multi_init {
 	my $url = shift;
 	unless (defined $_trunk || defined $_branches || defined $_tags) {
diff --git a/t/t9101-git-svn-props.sh b/t/t9101-git-svn-props.sh
index 5aac644..796d80e 100755
--- a/t/t9101-git-svn-props.sh
+++ b/t/t9101-git-svn-props.sh
@@ -126,19 +126,20 @@ cat > show-ignore.expect <<\EOF
 # /
 /no-such-file*
 
-# deeply
+# /deeply/
 /deeply/no-such-file*
 
-# deeply/nested
+# /deeply/nested/
 /deeply/nested/no-such-file*
 
-# deeply/nested/directory
+# /deeply/nested/directory/
 /deeply/nested/directory/no-such-file*
 EOF
 
 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*' .
@@ -148,4 +149,25 @@ test_expect_success 'test show-ignore' "
 	cmp show-ignore.expect show-ignore.got
 	"
 
+cat >create-ignore.expect <<\EOF
+/no-such-file*
+EOF
+
+cat >create-ignore-index.expect <<\EOF
+100644 8c52e5dfcd0a8b6b6bcfe6b41b89bcbf493718a5 0	.gitignore
+100644 8c52e5dfcd0a8b6b6bcfe6b41b89bcbf493718a5 0	deeply/.gitignore
+100644 8c52e5dfcd0a8b6b6bcfe6b41b89bcbf493718a5 0	deeply/nested/.gitignore
+100644 8c52e5dfcd0a8b6b6bcfe6b41b89bcbf493718a5 0	deeply/nested/directory/.gitignore
+EOF
+
+test_expect_success 'test create-ignore' "
+	git-svn fetch && git pull . remotes/git-svn &&
+	git-svn create-ignore &&
+	cmp ./.gitignore create-ignore.expect &&
+	cmp ./deeply/.gitignore create-ignore.expect &&
+	cmp ./deeply/nested/.gitignore create-ignore.expect &&
+	cmp ./deeply/nested/directory/.gitignore create-ignore.expect &&
+	git ls-files -s | grep gitignore | cmp - create-ignore-index.expect
+	"
+
 test_done
-- 
1.5.3.4.214.g6f43

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/5] Add git svn propget.
  2007-10-15 15:35 ` [PATCH 2/5] Implement git svn create-ignore Benoit Sigoure
@ 2007-10-15 15:35   ` Benoit Sigoure
  2007-10-15 15:35     ` [PATCH 4/5] Add git svn proplist Benoit Sigoure
  0 siblings, 1 reply; 8+ messages in thread
From: Benoit Sigoure @ 2007-10-15 15:35 UTC (permalink / raw)
  To: git; +Cc: normalperson, Benoit Sigoure

	* git-svn.perl (%cmd): Add the new command `propget'.
	($cmd_dir_prefix): New global.
	(&get_svnprops): New helper.
	(&cmd_propget): New.  Use &get_svnprops.
	* t/t9101-git-svn-props.sh: Add a test case for propget.

Signed-off-by: Benoit Sigoure <tsuna@lrde.epita.fr>
---
 git-svn.perl             |   57 ++++++++++++++++++++++++++++++++++++++++++++++
 t/t9101-git-svn-props.sh |   23 ++++++++++++++++++
 2 files changed, 80 insertions(+), 0 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index 94091ea..e58ff38 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -9,6 +9,8 @@ use vars qw/	$AUTHOR $VERSION
 $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
 $VERSION = '@@GIT_VERSION@@';
 
+# From which subdir have we been invoked?
+my $cmd_dir_prefix = command_oneline(qw/rev-parse --show-prefix/) || '';
 my $git_dir_user_set = 1 if defined $ENV{GIT_DIR};
 $ENV{GIT_DIR} ||= '.git';
 $Git::SVN::default_repo_id = 'svn';
@@ -127,6 +129,9 @@ my %cmd = (
 			     'Create a .gitignore per svn:ignore',
 			     { 'revision|r=i' => \$_revision
 			     } ],
+        'propget' => [ \&cmd_propget,
+		       'Print the value of a property on a file or directory',
+		       { 'revision|r=i' => \$_revision } ],
 	'show-ignore' => [ \&cmd_show_ignore, "Show svn:ignore listings",
 			{ 'revision|r=i' => \$_revision
 			} ],
@@ -526,6 +531,58 @@ sub cmd_create_ignore {
 	});
 }
 
+# get_svnprops(PATH)
+# ------------------
+# Helper for cmd_propget below.
+sub get_svnprops {
+	my $path = shift;
+	my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
+	$gs ||= Git::SVN->new;
+
+	# prefix THE PATH by the sub-directory from which the user
+	# invoked us.
+	$path = $cmd_dir_prefix . $path;
+	fatal("No such file or directory: $path\n") unless -e $path;
+	my $is_dir = -d $path ? 1 : 0;
+	$path = $gs->{path} . '/' . $path;
+
+	# canonicalize the path (otherwise libsvn will abort or fail to
+	# find the file)
+	# File::Spec->canonpath doesn't collapse x/../y into y (for a
+	# good reason), so let's do this manually.
+	$path =~ s#/+#/#g;
+	$path =~ s#/\.(?:/|$)#/#g;
+	$path =~ s#/[^/]+/\.\.##g;
+	$path =~ s#/$##g;
+
+	my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
+	my $props;
+	if ($is_dir)
+	{
+		(undef, undef, $props) = $gs->ra->get_dir($path, $r);
+	}
+	else
+	{
+		(undef, $props) = $gs->ra->get_file($path, $r, undef);
+	}
+	return $props;
+}
+
+# cmd_propget (PROP, PATH)
+# ------------------------
+# Print the SVN property PROP for PATH.
+sub cmd_propget {
+	my ($prop, $path) = @_;
+	$path = '.' if not defined $path;
+	usage(1) if not defined $prop;
+	my $props = get_svnprops($path);
+	if (not defined $props->{$prop})
+	{
+		fatal("`$path' does not have a `$prop' SVN property.\n");
+	}
+	print $props->{$prop} . "\n";
+}
+
 sub cmd_multi_init {
 	my $url = shift;
 	unless (defined $_trunk || defined $_branches || defined $_tags) {
diff --git a/t/t9101-git-svn-props.sh b/t/t9101-git-svn-props.sh
index 796d80e..61c8799 100755
--- a/t/t9101-git-svn-props.sh
+++ b/t/t9101-git-svn-props.sh
@@ -170,4 +170,27 @@ test_expect_success 'test create-ignore' "
 	git ls-files -s | grep gitignore | cmp - create-ignore-index.expect
 	"
 
+cat >prop.expect <<\EOF
+no-such-file*
+
+EOF
+cat >prop2.expect <<\EOF
+8
+EOF
+
+# This test can be improved: since all the svn:ignore contain the same
+# pattern, it can pass even though the propget did not execute on the
+# right directory.
+test_expect_success 'test propget' "
+	git-svn propget svn:ignore . | cmp - prop.expect &&
+	cd deeply &&
+	git-svn propget svn:ignore . | cmp - ../prop.expect &&
+	git-svn propget svn:entry:committed-rev nested/directory/.keep \
+	  | cmp - ../prop2.expect &&
+	git-svn propget svn:ignore .. | cmp - ../prop.expect &&
+	git-svn propget svn:ignore nested/ | cmp - ../prop.expect &&
+	git-svn propget svn:ignore ./nested | cmp - ../prop.expect &&
+	git-svn propget svn:ignore .././deeply/nested | cmp - ../prop.expect
+	"
+
 test_done
-- 
1.5.3.4.214.g6f43

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/5] Add git svn proplist.
  2007-10-15 15:35   ` [PATCH 3/5] Add git svn propget Benoit Sigoure
@ 2007-10-15 15:35     ` Benoit Sigoure
  2007-10-15 15:35       ` [PATCH 5/5] Simplify the handling of fatal errors Benoit Sigoure
  0 siblings, 1 reply; 8+ messages in thread
From: Benoit Sigoure @ 2007-10-15 15:35 UTC (permalink / raw)
  To: git; +Cc: normalperson, Benoit Sigoure

	* git-svn.perl (%cmd): Add the command `proplist'.
	(&cmd_proplist): New.
	* t/t9101-git-svn-props.sh: Test git svn proplist.

Signed-off-by: Benoit Sigoure <tsuna@lrde.epita.fr>
---
 git-svn.perl             |   17 +++++++++++++++++
 t/t9101-git-svn-props.sh |   21 +++++++++++++++++++++
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index e58ff38..466fdd3 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -132,6 +132,9 @@ my %cmd = (
         'propget' => [ \&cmd_propget,
 		       'Print the value of a property on a file or directory',
 		       { 'revision|r=i' => \$_revision } ],
+        'proplist' => [ \&cmd_proplist,
+		       'List all properties of a file or directory',
+		       { 'revision|r=i' => \$_revision } ],
 	'show-ignore' => [ \&cmd_show_ignore, "Show svn:ignore listings",
 			{ 'revision|r=i' => \$_revision
 			} ],
@@ -583,6 +586,20 @@ sub cmd_propget {
 	print $props->{$prop} . "\n";
 }
 
+# cmd_proplist (PATH)
+# -------------------
+# Print the list of SVN properties for PATH.
+sub cmd_proplist {
+	my $path = shift;
+	$path = '.' if not defined $path;
+	my $props = get_svnprops($path);
+	print "Properties on '$path':\n";
+	foreach (sort keys %{$props})
+	{
+		print "  $_\n";
+	}
+}
+
 sub cmd_multi_init {
 	my $url = shift;
 	unless (defined $_trunk || defined $_branches || defined $_tags) {
diff --git a/t/t9101-git-svn-props.sh b/t/t9101-git-svn-props.sh
index 61c8799..3c83127 100755
--- a/t/t9101-git-svn-props.sh
+++ b/t/t9101-git-svn-props.sh
@@ -193,4 +193,25 @@ test_expect_success 'test propget' "
 	git-svn propget svn:ignore .././deeply/nested | cmp - ../prop.expect
 	"
 
+cat >prop.expect <<\EOF
+Properties on '.':
+  svn:entry:committed-date
+  svn:entry:committed-rev
+  svn:entry:last-author
+  svn:entry:uuid
+  svn:ignore
+EOF
+cat >prop2.expect <<\EOF
+Properties on 'nested/directory/.keep':
+  svn:entry:committed-date
+  svn:entry:committed-rev
+  svn:entry:last-author
+  svn:entry:uuid
+EOF
+
+test_expect_success 'test proplist' "
+	git-svn proplist . | cmp - prop.expect &&
+	git-svn proplist nested/directory/.keep | cmp - prop2.expect
+	"
+
 test_done
-- 
1.5.3.4.214.g6f43

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/5] Simplify the handling of fatal errors.
  2007-10-15 15:35     ` [PATCH 4/5] Add git svn proplist Benoit Sigoure
@ 2007-10-15 15:35       ` Benoit Sigoure
  0 siblings, 0 replies; 8+ messages in thread
From: Benoit Sigoure @ 2007-10-15 15:35 UTC (permalink / raw)
  To: git; +Cc: normalperson, Benoit Sigoure

	* git-svn.perl (&fatal): Append the newline at the end of the error
	message.
	Adjust all callers.

Signed-off-by: Benoit Sigoure <tsuna@lrde.epita.fr>
---
 git-svn.perl |   42 +++++++++++++++++++++---------------------
 1 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index 466fdd3..1a6aa14 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -21,12 +21,12 @@ $Git::SVN::Log::TZ = $ENV{TZ};
 $ENV{TZ} = 'UTC';
 $| = 1; # unbuffer STDOUT
 
-sub fatal (@) { print STDERR @_; exit 1 }
+sub fatal (@) { print STDERR "@_\n"; exit 1 }
 require SVN::Core; # use()-ing this causes segfaults for me... *shrug*
 require SVN::Ra;
 require SVN::Delta;
 if ($SVN::Core::VERSION lt '1.1.0') {
-	fatal "Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)\n";
+	fatal "Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)";
 }
 push @Git::SVN::Ra::ISA, 'SVN::Ra';
 push @SVN::Git::Editor::ISA, 'SVN::Delta::Editor';
@@ -369,7 +369,7 @@ sub cmd_set_tree {
 		} elsif (scalar @tmp > 1) {
 			push @revs, reverse(command('rev-list',@tmp));
 		} else {
-			fatal "Failed to rev-parse $c\n";
+			fatal "Failed to rev-parse $c";
 		}
 	}
 	my $gs = Git::SVN->new;
@@ -379,7 +379,7 @@ sub cmd_set_tree {
 		fatal "There are new revisions that were fetched ",
 		      "and need to be merged (or acknowledged) ",
 		      "before committing.\nlast rev: $r_last\n",
-		      " current: $gs->{last_rev}\n";
+		      " current: $gs->{last_rev}";
 	}
 	$gs->set_tree($_) foreach @revs;
 	print "Done committing ",scalar @revs," revisions to SVN\n";
@@ -408,7 +408,7 @@ sub cmd_dcommit {
 			(undef, $last_rev, undef) = cmt_metadata("$d~1");
 			unless (defined $last_rev) {
 				fatal "Unable to extract revision information ",
-				      "from commit $d~1\n";
+				      "from commit $d~1";
 			}
 		}
 		if ($_dry_run) {
@@ -521,7 +521,7 @@ sub cmd_create_ignore {
 		my $ignore = '.' . $path . '.gitignore';
 		my $s = $props->{'svn:ignore'} or return;
 		open(GITIGNORE, '>', $ignore)
-		  or fatal("Failed to open `$ignore' for writing: $!\n");
+		  or fatal("Failed to open `$ignore' for writing: $!");
 		$s =~ s/[\r\n]+/\n/g;
 		chomp $s;
 		# Prefix all patterns so that the ignore doesn't apply
@@ -529,7 +529,7 @@ sub cmd_create_ignore {
 		$s =~ s#^#/#gm;
 		print GITIGNORE "$s\n";
 		close(GITIGNORE)
-		  or fatal("Failed to close `$ignore': $!\n");
+		  or fatal("Failed to close `$ignore': $!");
 		command_noisy('add', $ignore);
 	});
 }
@@ -545,7 +545,7 @@ sub get_svnprops {
 	# prefix THE PATH by the sub-directory from which the user
 	# invoked us.
 	$path = $cmd_dir_prefix . $path;
-	fatal("No such file or directory: $path\n") unless -e $path;
+	fatal("No such file or directory: $path") unless -e $path;
 	my $is_dir = -d $path ? 1 : 0;
 	$path = $gs->{path} . '/' . $path;
 
@@ -581,7 +581,7 @@ sub cmd_propget {
 	my $props = get_svnprops($path);
 	if (not defined $props->{$prop})
 	{
-		fatal("`$path' does not have a `$prop' SVN property.\n");
+		fatal("`$path' does not have a `$prop' SVN property.");
 	}
 	print $props->{$prop} . "\n";
 }
@@ -646,7 +646,7 @@ sub cmd_multi_fetch {
 sub cmd_commit_diff {
 	my ($ta, $tb, $url) = @_;
 	my $usage = "Usage: $0 commit-diff -r<revision> ".
-	            "<tree-ish> <tree-ish> [<URL>]\n";
+	            "<tree-ish> <tree-ish> [<URL>]";
 	fatal($usage) if (!defined $ta || !defined $tb);
 	my $svn_path;
 	if (!defined $url) {
@@ -664,7 +664,7 @@ sub cmd_commit_diff {
 	if (defined $_message && defined $_file) {
 		fatal("Both --message/-m and --file/-F specified ",
 		      "for the commit message.\n",
-		      "I have no idea what you mean\n");
+		      "I have no idea what you mean");
 	}
 	if (defined $_file) {
 		$_message = file_to_s($_file);
@@ -727,7 +727,7 @@ sub complete_svn_url {
 	if ($path !~ m#^[a-z\+]+://#) {
 		if (!defined $url || $url !~ m#^[a-z\+]+://#) {
 			fatal("E: '$path' is not a complete URL ",
-			      "and a separate URL is not specified\n");
+			      "and a separate URL is not specified");
 		}
 		return ($url, $path);
 	}
@@ -748,7 +748,7 @@ sub complete_url_ls_init {
 		$repo_path =~ s#^/+##;
 		unless ($ra) {
 			fatal("E: '$repo_path' is not a complete URL ",
-			      "and a separate URL is not specified\n");
+			      "and a separate URL is not specified");
 		}
 	}
 	my $url = $ra->{url};
@@ -1755,7 +1755,7 @@ sub assert_index_clean {
 		$x = command_oneline('write-tree');
 		if ($y ne $x) {
 			::fatal "trees ($treeish) $y != $x\n",
-			        "Something is seriously wrong...\n";
+			        "Something is seriously wrong...";
 		}
 	});
 }
@@ -2181,7 +2181,7 @@ sub set_tree {
 	my ($self, $tree) = (shift, shift);
 	my $log_entry = ::get_commit_entry($tree);
 	unless ($self->{last_rev}) {
-		fatal("Must have an existing revision to commit\n");
+		fatal("Must have an existing revision to commit");
 	}
 	my %ed_opts = ( r => $self->{last_rev},
 	                log => $log_entry->{log},
@@ -3131,7 +3131,7 @@ sub apply_diff {
 		if (defined $o{$f}) {
 			$self->$f($m);
 		} else {
-			fatal("Invalid change type: $f\n");
+			fatal("Invalid change type: $f");
 		}
 	}
 	$self->rmdirs if $_rmdir;
@@ -3739,15 +3739,15 @@ sub config_pager {
 sub run_pager {
 	return unless -t *STDOUT && defined $pager;
 	pipe my $rfd, my $wfd or return;
-	defined(my $pid = fork) or ::fatal "Can't fork: $!\n";
+	defined(my $pid = fork) or ::fatal "Can't fork: $!";
 	if (!$pid) {
 		open STDOUT, '>&', $wfd or
-		                     ::fatal "Can't redirect to stdout: $!\n";
+		                     ::fatal "Can't redirect to stdout: $!";
 		return;
 	}
-	open STDIN, '<&', $rfd or ::fatal "Can't redirect stdin: $!\n";
+	open STDIN, '<&', $rfd or ::fatal "Can't redirect stdin: $!";
 	$ENV{LESS} ||= 'FRSX';
-	exec $pager or ::fatal "Can't run pager: $! ($pager)\n";
+	exec $pager or ::fatal "Can't run pager: $! ($pager)";
 }
 
 sub tz_to_s_offset {
@@ -3883,7 +3883,7 @@ sub cmd_show_log {
 			$r_min = $r_max = $::_revision;
 		} else {
 			::fatal "-r$::_revision is not supported, use ",
-				"standard \'git log\' arguments instead\n";
+				"standard 'git log' arguments instead";
 		}
 	}
 
-- 
1.5.3.4.214.g6f43

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/5] Add a generic tree traversal to fetch SVN properties.
  2007-10-15 15:35 [PATCH 1/5] Add a generic tree traversal to fetch SVN properties Benoit Sigoure
  2007-10-15 15:35 ` [PATCH 2/5] Implement git svn create-ignore Benoit Sigoure
@ 2007-10-16  7:43 ` Eric Wong
  2007-10-16  9:35   ` Benoit SIGOURE
  1 sibling, 1 reply; 8+ messages in thread
From: Eric Wong @ 2007-10-16  7:43 UTC (permalink / raw)
  To: Benoit Sigoure; +Cc: git

Benoit Sigoure <tsuna@lrde.epita.fr> wrote:
> 	* git-svn.perl (&traverse_ignore): Remove.
> 	(&prop_walk): New.
> 	(&cmd_show_ignore): Use prop_walk.
> 
> Signed-off-by: Benoit Sigoure <tsuna@lrde.epita.fr>

Although I myself have never needed this functionality, this series
looks pretty good in general.

Thanks.

One comment below about property selection (whitelist vs blacklist).


It would be possible to get identical information out of unhandled.log,
but older repositories may not have complete information...  Maybe some
local option would be good for people with complete unhandled.log files;
but it could be really incomplete/insufficient.


I'm not sure about 5/5, it's purely a style issue, however I don't
really feel strongly about a trailing "\n" either way...  Nevertheless,
it is definitely not part of this series and should be treated
independently.


Coding style

Other than that, I prefer to keep braces on the same line as foreach,
if, else statements.  I generally follow the git and Linux coding
style for C in my Perl code.

One exception that I make for Perl (but not C) is that I keep the "{"
for subs on the same line (since subs can be nested and anonymous ones
passed as arguments and such); unlike their C counterparts[1]

[1] - well, nesting functions is allowed in C99 or GNU C, I can't
      remember which or both...

> ---
>  git-svn.perl |   66 ++++++++++++++++++++++++++++++++++++++++-----------------
>  1 files changed, 46 insertions(+), 20 deletions(-)
> 
> diff --git a/git-svn.perl b/git-svn.perl
> index 777e436..abc83ec 100755
> --- a/git-svn.perl
> +++ b/git-svn.perl
> @@ -488,7 +488,15 @@ sub cmd_show_ignore {
>  	my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
>  	$gs ||= Git::SVN->new;
>  	my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
> -	$gs->traverse_ignore(\*STDOUT, $gs->{path}, $r);
> +	$gs->prop_walk($gs->{path}, $r, sub {
> +		my ($gs, $path, $props) = @_;
> +		print STDOUT "\n# $path\n";
> +		my $s = $props->{'svn:ignore'} or return;
> +		$s =~ s/[\r\n]+/\n/g;
> +		chomp $s;
> +		$s =~ s#^#$path#gm;
> +		print STDOUT "$s\n";
> +	});
>  }
>  
>  sub cmd_multi_init {
> @@ -1480,28 +1488,46 @@ sub rel_path {
>  	$url;
>  }
>  
> -sub traverse_ignore {
> -	my ($self, $fh, $path, $r) = @_;
> -	$path =~ s#^/+##g;
> -	my $ra = $self->ra;
> -	my ($dirent, undef, $props) = $ra->get_dir($path, $r);
> +# prop_walk(PATH, REV, SUB)
> +# -------------------------
> +# Recursively traverse PATH at revision REV and invoke SUB for each
> +# directory that contains a SVN property.  SUB will be invoked as
> +# follows:  &SUB(gs, path, props);  where `gs' is this instance of
> +# Git::SVN, `path' the path to the directory where the properties
> +# `props' were found.  The `path' will be relative to point of checkout,
> +# that is, if url://repo/trunk is the current Git branch, and that
> +# directory contains a sub-directory `d', SUB will be invoked with `/d/'
> +# as `path' (note the trailing `/').
> +sub prop_walk {
> +	my ($self, $path, $rev, $sub) = @_;
> +
> +	my ($dirent, undef, $props) = $self->ra->get_dir($path, $rev);
> +	$path =~ s#^/*#/#g;
>  	my $p = $path;
> -	$p =~ s#^\Q$self->{path}\E(/|$)##;
> -	print $fh length $p ? "\n# $p\n" : "\n# /\n";
> -	if (my $s = $props->{'svn:ignore'}) {
> -		$s =~ s/[\r\n]+/\n/g;
> -		chomp $s;
> -		if (length $p == 0) {
> -			$s =~ s#\n#\n/$p#g;
> -			print $fh "/$s\n";
> -		} else {
> -			$s =~ s#\n#\n/$p/#g;
> -			print $fh "/$p/$s\n";
> -		}
> -	}
> +	# Strip the irrelevant part of the path.
> +	$p =~ s#^/+\Q$self->{path}\E(/|$)#/#;
> +	# Ensure the path is terminated by a `/'.
> +	$p =~ s#/*$#/#;
> +
> +	# The properties contain all the internal SVN stuff nobody
> +	# (usually) cares about.

How about having a blacklist (for the author, date, log, uuid?) instead
of a whitelist?  I can't remember all of them that should be blacklisted,
 but maybe it's just author, date and log)..

> +	my $interesting_props = 0;
> +	foreach(keys %{$props})
> +	{
> +		# If it doesn't start with `svn:', it must be a
> +		# user-defined property.
> +		++$interesting_props and next if $_ !~ /^svn:/;
> +		# FIXME: Fragile, if SVN adds new public properties,
> +		# this needs to be updated.
> +		++$interesting_props if /^svn:(?:ignore|keywords|executable
> +		                                 |eol-style|mime-type
> +						 |externals|needs-lock)$/x;
> +	}
> +	&$sub($self, $p, $props) if $interesting_props;
> +
>  	foreach (sort keys %$dirent) {
>  		next if $dirent->{$_}->{kind} != $SVN::Node::dir;
> -		$self->traverse_ignore($fh, "$path/$_", $r);
> +		$self->prop_walk($path . '/' . $_, $rev, $sub);
>  	}
>  }

-- 
Eric Wong

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/5] Add a generic tree traversal to fetch SVN properties.
  2007-10-16  7:43 ` [PATCH 1/5] Add a generic tree traversal to fetch SVN properties Eric Wong
@ 2007-10-16  9:35   ` Benoit SIGOURE
  2007-10-16  9:55     ` Eric Wong
  0 siblings, 1 reply; 8+ messages in thread
From: Benoit SIGOURE @ 2007-10-16  9:35 UTC (permalink / raw)
  To: Eric Wong; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 3576 bytes --]

On Oct 16, 2007, at 9:43 AM, Eric Wong wrote:

> Benoit Sigoure <tsuna@lrde.epita.fr> wrote:
>> 	* git-svn.perl (&traverse_ignore): Remove.
>> 	(&prop_walk): New.
>> 	(&cmd_show_ignore): Use prop_walk.
>>
>> Signed-off-by: Benoit Sigoure <tsuna@lrde.epita.fr>
>
> Although I myself have never needed this functionality, this series
> looks pretty good in general.

I heavily script Git with my own wrappers and having this sort if  
functionality does enhance the scriptability of git-svn.

>
> Thanks.

You're welcome :)

>
> One comment below about property selection (whitelist vs blacklist).
>
>
> It would be possible to get identical information out of  
> unhandled.log,
> but older repositories may not have complete information...  Maybe  
> some
> local option would be good for people with complete unhandled.log  
> files;
> but it could be really incomplete/insufficient.
>

In order to avoid using SVN::Ra and avoid access to the SVN repo?   
Hmm, clever, I didn't think about this.  Maybe we can provide both,  
the default would check unhandled.log and an option would enable  
direct access to the SVN repo?

>
> I'm not sure about 5/5, it's purely a style issue, however I don't
> really feel strongly about a trailing "\n" either way...   
> Nevertheless,
> it is definitely not part of this series and should be treated
> independently.
>

Indeed.

>
> Coding style
>
> Other than that, I prefer to keep braces on the same line as foreach,
> if, else statements.  I generally follow the git and Linux coding
> style for C in my Perl code.
>
> One exception that I make for Perl (but not C) is that I keep the "{"
> for subs on the same line (since subs can be nested and anonymous ones
> passed as arguments and such); unlike their C counterparts[1]

Indeed, sorry, I started correctly but then completely forgot to  
follow the existing Coding Style.  The CS I use daily is totally  
different, sorry ;)
Shall I resend the patch series with corrected CS?

>
> [1] - well, nesting functions is allowed in C99 or GNU C, I can't
>       remember which or both...
>

GNU C, AFAIR.

>> ---
>>  git-svn.perl |   66 +++++++++++++++++++++++++++++++++++++++ 
>> +-----------------
>>  1 files changed, 46 insertions(+), 20 deletions(-)
>>
>> diff --git a/git-svn.perl b/git-svn.perl
>> index 777e436..abc83ec 100755
>> --- a/git-svn.perl
>> +++ b/git-svn.perl
[...]
>
> How about having a blacklist (for the author, date, log, uuid?)  
> instead
> of a whitelist?  I can't remember all of them that should be  
> blacklisted,
>  but maybe it's just author, date and log)..
>
>> +	my $interesting_props = 0;
>> +	foreach(keys %{$props})
>> +	{
>> +		# If it doesn't start with `svn:', it must be a
>> +		# user-defined property.
>> +		++$interesting_props and next if $_ !~ /^svn:/;
>> +		# FIXME: Fragile, if SVN adds new public properties,
>> +		# this needs to be updated.
>> +		++$interesting_props if /^svn:(?:ignore|keywords|executable
>> +		                                 |eol-style|mime-type
>> +						 |externals|needs-lock)$/x;
>> +	}

Why not.  I thought that the SVN internals were more subject to  
change than the public "interface", hence the check.

>> +	&$sub($self, $p, $props) if $interesting_props;
>> +

PS: For some reason, the introduction message didn't make its way to  
the ML.  I made a mistake when sending it because I first ran git  
send-email --compose, then noticed that it sent only one mail, and  
ran git send-email *.patch afterwards.  Weird.

Cheers,

-- 
Benoit Sigoure aka Tsuna
EPITA Research and Development Laboratory



[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 186 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/5] Add a generic tree traversal to fetch SVN properties.
  2007-10-16  9:35   ` Benoit SIGOURE
@ 2007-10-16  9:55     ` Eric Wong
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2007-10-16  9:55 UTC (permalink / raw)
  To: Benoit SIGOURE; +Cc: git

Benoit SIGOURE <tsuna@lrde.epita.fr> wrote:
> On Oct 16, 2007, at 9:43 AM, Eric Wong wrote:
> 
> >Benoit Sigoure <tsuna@lrde.epita.fr> wrote:
> >>	* git-svn.perl (&traverse_ignore): Remove.
> >>	(&prop_walk): New.
> >>	(&cmd_show_ignore): Use prop_walk.
> >>
> >>Signed-off-by: Benoit Sigoure <tsuna@lrde.epita.fr>
> >
> >Although I myself have never needed this functionality, this series
> >looks pretty good in general.
> 
> I heavily script Git with my own wrappers and having this sort if  
> functionality does enhance the scriptability of git-svn.

Ah.  I've actually wanted something like `svn info` or `git-svn
rev-parse` myself for a while, but haven't gotten to implementing it
myself, either.  Something that could easily give me the current URL of
a repo, or the URL of any path in a repo

	$ git svn info --remote-url local/path.c
	=> https://example.com/svn/trunk/local/path.c

	$ git svn info --url
	=> https://example.com/svn/trunk

I think there was other functionality that I've wanted in the past
but have forgotten at the moment.  I need to sleep, badly :x

> >Thanks.
> 
> You're welcome :)
> 
> >
> >One comment below about property selection (whitelist vs blacklist).
> >
> >
> >It would be possible to get identical information out of  
> >unhandled.log,
> >but older repositories may not have complete information...  Maybe  
> >some
> >local option would be good for people with complete unhandled.log  
> >files;
> >but it could be really incomplete/insufficient.
> >
> 
> In order to avoid using SVN::Ra and avoid access to the SVN repo?   
> Hmm, clever, I didn't think about this.  Maybe we can provide both,  
> the default would check unhandled.log and an option would enable  
> direct access to the SVN repo?

Yes.  I'm alright with the direct SVN repo code for now, and we can do
unhandled.log later since it's more things to do.

> >Coding style
> >
> >Other than that, I prefer to keep braces on the same line as foreach,
> >if, else statements.  I generally follow the git and Linux coding
> >style for C in my Perl code.
> >
> >One exception that I make for Perl (but not C) is that I keep the "{"
> >for subs on the same line (since subs can be nested and anonymous ones
> >passed as arguments and such); unlike their C counterparts[1]
> 
> Indeed, sorry, I started correctly but then completely forgot to  
> follow the existing Coding Style.  The CS I use daily is totally  
> different, sorry ;)
> Shall I resend the patch series with corrected CS?

Yes, please.  Thanks.

-- 
Eric Wong

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-10-16 14:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-15 15:35 [PATCH 1/5] Add a generic tree traversal to fetch SVN properties Benoit Sigoure
2007-10-15 15:35 ` [PATCH 2/5] Implement git svn create-ignore Benoit Sigoure
2007-10-15 15:35   ` [PATCH 3/5] Add git svn propget Benoit Sigoure
2007-10-15 15:35     ` [PATCH 4/5] Add git svn proplist Benoit Sigoure
2007-10-15 15:35       ` [PATCH 5/5] Simplify the handling of fatal errors Benoit Sigoure
2007-10-16  7:43 ` [PATCH 1/5] Add a generic tree traversal to fetch SVN properties Eric Wong
2007-10-16  9:35   ` Benoit SIGOURE
2007-10-16  9:55     ` Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).