git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-svn: introduce --parents parameter for commands branch and tag
@ 2013-05-13 20:22 Tobias Schulte
  2013-05-15  2:35 ` Eric Wong
  2013-05-15 20:14 ` [PATCH v2] " Tobias Schulte
  0 siblings, 2 replies; 8+ messages in thread
From: Tobias Schulte @ 2013-05-13 20:22 UTC (permalink / raw)
  To: git; +Cc: Eric Wong, Tobias Schulte

This parameter is equivalent to the parameter --parents on svn cp commands
and is useful for non-standard repository layouts.

Signed-off-by: Tobias Schulte <tobias.schulte@gliderpilot.de>
---
 Documentation/git-svn.txt                |    5 ++++
 git-svn.perl                             |   22 +++++++++++++-
 t/t9167-git-svn-cmd-branch-subproject.sh |   46 ++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 1 deletion(-)
 create mode 100755 t/t9167-git-svn-cmd-branch-subproject.sh

diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt
index 58b6d54..4f2141d 100644
--- a/Documentation/git-svn.txt
+++ b/Documentation/git-svn.txt
@@ -298,6 +298,11 @@ where <name> is the name of the SVN repository as specified by the -R option to
 	git config --get-all svn-remote.<name>.commiturl
 +
 
+--parents;;
+	Create parent folders. This parameter is equivalent to the parameter 
+	--parents on svn cp commands and is useful for non-standard repository 
+	layouts.
+
 'tag'::
 	Create a tag in the SVN repository. This is a shorthand for
 	'branch -t'.
diff --git a/git-svn.perl b/git-svn.perl
index ccabe06..204313d 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -113,7 +113,7 @@ my ($_stdin, $_help, $_edit,
 	$_template, $_shared,
 	$_version, $_fetch_all, $_no_rebase, $_fetch_parent,
 	$_before, $_after,
-	$_merge, $_strategy, $_preserve_merges, $_dry_run, $_local,
+	$_merge, $_strategy, $_preserve_merges, $_dry_run, $_parents, $_local,
 	$_prefix, $_no_checkout, $_url, $_verbose,
 	$_commit_url, $_tag, $_merge_info, $_interactive);
 
@@ -203,6 +203,7 @@ my %cmd = (
 	            { 'message|m=s' => \$_message,
 	              'destination|d=s' => \$_branch_dest,
 	              'dry-run|n' => \$_dry_run,
+	              'parents' => \$_parents,
 	              'tag|t' => \$_tag,
 	              'username=s' => \$Git::SVN::Prompt::_username,
 	              'commit-url=s' => \$_commit_url } ],
@@ -211,6 +212,7 @@ my %cmd = (
 	         { 'message|m=s' => \$_message,
 	           'destination|d=s' => \$_branch_dest,
 	           'dry-run|n' => \$_dry_run,
+	           'parents' => \$_parents,
 	           'username=s' => \$Git::SVN::Prompt::_username,
 	           'commit-url=s' => \$_commit_url } ],
 	'set-tree' => [ \&cmd_set_tree,
@@ -1172,6 +1174,10 @@ sub cmd_branch {
 		$ctx->ls($dst, 'HEAD', 0);
 	} and die "branch ${branch_name} already exists\n";
 
+	if ($_parents) {
+		mk_parent_dirs($ctx, $dst);
+	}
+
 	print "Copying ${src} at r${rev} to ${dst}...\n";
 	$ctx->copy($src, $rev, $dst)
 		unless $_dry_run;
@@ -1179,6 +1185,20 @@ sub cmd_branch {
 	$gs->fetch_all;
 }
 
+sub mk_parent_dirs {
+	my $ctx = shift;
+	my $parent = shift;
+	$parent =~ s/\/[^\/]*$//;
+
+	if (!eval{$ctx->ls($parent, 'HEAD', 0)}) {
+		mk_parent_dirs($ctx, $parent);
+		print "Creating parent folder ${parent} ...\n";
+		$ctx->mkdir($parent)
+			unless $_dry_run;
+	}
+
+}
+
 sub cmd_find_rev {
 	my $revision_or_hash = shift or die "SVN or git revision required ",
 	                                    "as a command-line argument\n";
diff --git a/t/t9167-git-svn-cmd-branch-subproject.sh b/t/t9167-git-svn-cmd-branch-subproject.sh
new file mode 100755
index 0000000..9cb891b
--- /dev/null
+++ b/t/t9167-git-svn-cmd-branch-subproject.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+#
+# Copyright (c) 2013 Tobias Schulte
+#
+
+test_description='git svn branch for subproject clones'
+. ./lib-git-svn.sh
+
+test_expect_success 'initialize svnrepo' '
+    mkdir import &&
+    (
+        (cd import &&
+        mkdir -p trunk/project branches tags &&
+        (cd trunk/project &&
+        echo foo > foo
+        ) &&
+        svn_cmd import -m "import for git-svn" . "$svnrepo" >/dev/null
+        ) &&
+        rm -rf import &&
+        svn_cmd co "$svnrepo"/trunk/project trunk/project &&
+        (cd trunk/project &&
+        echo bar >> foo &&
+        svn_cmd ci -m "updated trunk"
+        ) &&
+        rm -rf trunk
+    )
+'
+
+test_expect_success 'import into git' '
+    git svn init --trunk=trunk/project --branches=branches/*/project --tags=tags/*/project "$svnrepo" &&
+    git svn fetch &&
+    git checkout remotes/trunk
+'
+
+test_expect_success 'git svn branch tests' '
+    test_must_fail git svn branch a &&
+    git svn branch --parents a &&
+    test_must_fail git svn branch -t tag1 &&
+    git svn branch --parents -t tag1 &&
+    test_must_fail git svn branch --tag tag2 &&
+    git svn branch --parents --tag tag2 &&
+    test_must_fail git svn tag tag3 &&
+    git svn tag --parents tag3
+'
+
+test_done
-- 
1.7.9.5

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

* Re: [PATCH] git-svn: introduce --parents parameter for commands branch and tag
  2013-05-13 20:22 [PATCH] git-svn: introduce --parents parameter for commands branch and tag Tobias Schulte
@ 2013-05-15  2:35 ` Eric Wong
  2013-05-15 19:51   ` Tobias Schulte
  2013-05-15 20:14 ` [PATCH v2] " Tobias Schulte
  1 sibling, 1 reply; 8+ messages in thread
From: Eric Wong @ 2013-05-15  2:35 UTC (permalink / raw)
  To: Tobias Schulte; +Cc: git

Tobias Schulte <tobias.schulte@gliderpilot.de> wrote:
> This parameter is equivalent to the parameter --parents on svn cp commands
> and is useful for non-standard repository layouts.

This looks useful.  A few minor cosmetic issues.

> +++ b/Documentation/git-svn.txt
> @@ -298,6 +298,11 @@ where <name> is the name of the SVN repository as specified by the -R option to
>  	git config --get-all svn-remote.<name>.commiturl
>  +
>  
> +--parents;;
> +	Create parent folders. This parameter is equivalent to the parameter 
> +	--parents on svn cp commands and is useful for non-standard repository 
> +	layouts.

Trailing whitespace.

> +sub mk_parent_dirs {
> +	my $ctx = shift;
> +	my $parent = shift;

I prefer declaring multiple variables from arguments as:

	my ($ctx, $parent) = @_;

> +	$parent =~ s/\/[^\/]*$//;

You can avoid leaning toothpick syndrome (escaping '/') by specifying
alternate delimiters:

	$parent =~ s{/[^/]*$}{};

ref: perlop(1)

> +	if (!eval{$ctx->ls($parent, 'HEAD', 0)}) {
> +		mk_parent_dirs($ctx, $parent);
> +		print "Creating parent folder ${parent} ...\n";
> +		$ctx->mkdir($parent)
> +			unless $_dry_run;

The newline is confusing, I prefer:

		$ctx->mkdir($parent) unless $_dry_run;

Howeve :

	if (!$_dry_run) {
		$ctx->mkdir($parent);
	}

May be preferred, too (especially for the non-Perl-fluent)

> +++ b/t/t9167-git-svn-cmd-branch-subproject.sh

> +test_expect_success 'initialize svnrepo' '
> +    mkdir import &&
> +    (
> +        (cd import &&
> +        mkdir -p trunk/project branches tags &&
> +        (cd trunk/project &&
> +        echo foo > foo
> +        ) &&

Tabs for all indentation, and indent consistently for subshells:

	mkdir import &&
	(
		cd import &&
		mkdir .. &&
		(
			cd .. &&
			..
		)
	)

We use subshells + cd like this so it's easier to read/maintain.

Thanks again, looking forward to applying v2.

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

* Re: [PATCH] git-svn: introduce --parents parameter for commands branch and tag
  2013-05-15  2:35 ` Eric Wong
@ 2013-05-15 19:51   ` Tobias Schulte
  0 siblings, 0 replies; 8+ messages in thread
From: Tobias Schulte @ 2013-05-15 19:51 UTC (permalink / raw)
  To: Eric Wong; +Cc: git

On 15.05.2013 04:35, Eric Wong wrote:
>> +	if (!eval{$ctx->ls($parent, 'HEAD', 0)}) {
>> +		mk_parent_dirs($ctx, $parent);
>> +		print "Creating parent folder ${parent} ...\n";
>> +		$ctx->mkdir($parent)
>> +			unless $_dry_run;
> 
> The newline is confusing, I prefer:
> 
> 		$ctx->mkdir($parent) unless $_dry_run;

In fact, this was a copy/paste from a few lines above

	print "Copying ${src} at r${rev} to ${dst}...\n";
	$ctx->copy($src, $rev, $dst)
		unless $_dry_run;

> Howeve :
> 
> 	if (!$_dry_run) {
> 		$ctx->mkdir($parent);
> 	}
> 
> May be preferred, too (especially for the non-Perl-fluent)

I am a non-Perl-fluent, as I come from the Java world with some
knowledge of C and C++. But to be able to create the patch I had to
gather some Perl knowledge, and by doing this, I learned enough to
understand, that there is more than one way, ... Especially the
constructs if (condition) foo(); vs foo() if (condition); and the same
for unless. And since the dry_run is the exception in this case, I think
unless is a valid choice -- and is used often in git-svn.perl. So I will
stick to it, but remove the newline.

> 
>> +++ b/t/t9167-git-svn-cmd-branch-subproject.sh
> 
>> +test_expect_success 'initialize svnrepo' '
>> +    mkdir import &&
>> +    (
>> +        (cd import &&
>> +        mkdir -p trunk/project branches tags &&
>> +        (cd trunk/project &&
>> +        echo foo > foo
>> +        ) &&
> 
> Tabs for all indentation, and indent consistently for subshells:
> 
> 	mkdir import &&
> 	(
> 		cd import &&
> 		mkdir .. &&
> 		(
> 			cd .. &&
> 			..
> 		)
> 	)
> 
> We use subshells + cd like this so it's easier to read/maintain.

Again, this was a copy/paste from t9128-git-svn-cmd-branch.sh. So this
file needs some cosmetics, too. And t9127... as well...

> 
> Thanks again, looking forward to applying v2.
> 

I will send v2 soon.

Tobias

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

* [PATCH v2] git-svn: introduce --parents parameter for commands branch and tag
  2013-05-13 20:22 [PATCH] git-svn: introduce --parents parameter for commands branch and tag Tobias Schulte
  2013-05-15  2:35 ` Eric Wong
@ 2013-05-15 20:14 ` Tobias Schulte
  2013-05-20 22:13   ` Eric Wong
  1 sibling, 1 reply; 8+ messages in thread
From: Tobias Schulte @ 2013-05-15 20:14 UTC (permalink / raw)
  To: git; +Cc: Eric Wong, Tobias Schulte

This parameter is equivalent to the parameter --parents on svn cp commands
and is useful for non-standard repository layouts.

Signed-off-by: Tobias Schulte <tobias.schulte@gliderpilot.de>
---
 Documentation/git-svn.txt                |    5 ++++
 git-svn.perl                             |   19 +++++++++++-
 t/t9167-git-svn-cmd-branch-subproject.sh |   48 ++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100755 t/t9167-git-svn-cmd-branch-subproject.sh

diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt
index 58b6d54..842ff83 100644
--- a/Documentation/git-svn.txt
+++ b/Documentation/git-svn.txt
@@ -298,6 +298,11 @@ where <name> is the name of the SVN repository as specified by the -R option to
 	git config --get-all svn-remote.<name>.commiturl
 +
 
+--parents;;
+	Create parent folders. This parameter is equivalent to the parameter
+	--parents on svn cp commands and is useful for non-standard repository
+	layouts.
+
 'tag'::
 	Create a tag in the SVN repository. This is a shorthand for
 	'branch -t'.
diff --git a/git-svn.perl b/git-svn.perl
index ccabe06..d070de0 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -113,7 +113,7 @@ my ($_stdin, $_help, $_edit,
 	$_template, $_shared,
 	$_version, $_fetch_all, $_no_rebase, $_fetch_parent,
 	$_before, $_after,
-	$_merge, $_strategy, $_preserve_merges, $_dry_run, $_local,
+	$_merge, $_strategy, $_preserve_merges, $_dry_run, $_parents, $_local,
 	$_prefix, $_no_checkout, $_url, $_verbose,
 	$_commit_url, $_tag, $_merge_info, $_interactive);
 
@@ -203,6 +203,7 @@ my %cmd = (
 	            { 'message|m=s' => \$_message,
 	              'destination|d=s' => \$_branch_dest,
 	              'dry-run|n' => \$_dry_run,
+	              'parents' => \$_parents,
 	              'tag|t' => \$_tag,
 	              'username=s' => \$Git::SVN::Prompt::_username,
 	              'commit-url=s' => \$_commit_url } ],
@@ -211,6 +212,7 @@ my %cmd = (
 	         { 'message|m=s' => \$_message,
 	           'destination|d=s' => \$_branch_dest,
 	           'dry-run|n' => \$_dry_run,
+	           'parents' => \$_parents,
 	           'username=s' => \$Git::SVN::Prompt::_username,
 	           'commit-url=s' => \$_commit_url } ],
 	'set-tree' => [ \&cmd_set_tree,
@@ -1172,6 +1174,10 @@ sub cmd_branch {
 		$ctx->ls($dst, 'HEAD', 0);
 	} and die "branch ${branch_name} already exists\n";
 
+	if ($_parents) {
+		mk_parent_dirs($ctx, $dst);
+	}
+
 	print "Copying ${src} at r${rev} to ${dst}...\n";
 	$ctx->copy($src, $rev, $dst)
 		unless $_dry_run;
@@ -1179,6 +1185,17 @@ sub cmd_branch {
 	$gs->fetch_all;
 }
 
+sub mk_parent_dirs {
+	my ($ctx, $parent) = @_;
+	$parent =~ s{/[^/]*$}{};
+
+	if (!eval{$ctx->ls($parent, 'HEAD', 0)}) {
+		mk_parent_dirs($ctx, $parent);
+		print "Creating parent folder ${parent} ...\n";
+		$ctx->mkdir($parent) unless $_dry_run;
+	}
+}
+
 sub cmd_find_rev {
 	my $revision_or_hash = shift or die "SVN or git revision required ",
 	                                    "as a command-line argument\n";
diff --git a/t/t9167-git-svn-cmd-branch-subproject.sh b/t/t9167-git-svn-cmd-branch-subproject.sh
new file mode 100755
index 0000000..53def87
--- /dev/null
+++ b/t/t9167-git-svn-cmd-branch-subproject.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# Copyright (c) 2013 Tobias Schulte
+#
+
+test_description='git svn branch for subproject clones'
+. ./lib-git-svn.sh
+
+test_expect_success 'initialize svnrepo' '
+	mkdir import &&
+	(
+		cd import &&
+		mkdir -p trunk/project branches tags &&
+		(
+			cd trunk/project &&
+			echo foo > foo
+		) &&
+		svn_cmd import -m "import for git-svn" . "$svnrepo" >/dev/null
+	) &&
+	rm -rf import &&
+	svn_cmd co "$svnrepo"/trunk/project trunk/project &&
+	(
+		cd trunk/project &&
+		echo bar >> foo &&
+		svn_cmd ci -m "updated trunk"
+	) &&
+	rm -rf trunk
+'
+
+test_expect_success 'import into git' '
+	git svn init --trunk=trunk/project --branches=branches/*/project \
+		--tags=tags/*/project "$svnrepo" &&
+	git svn fetch &&
+	git checkout remotes/trunk
+'
+
+test_expect_success 'git svn branch tests' '
+	test_must_fail git svn branch a &&
+	git svn branch --parents a &&
+	test_must_fail git svn branch -t tag1 &&
+	git svn branch --parents -t tag1 &&
+	test_must_fail git svn branch --tag tag2 &&
+	git svn branch --parents --tag tag2 &&
+	test_must_fail git svn tag tag3 &&
+	git svn tag --parents tag3
+'
+
+test_done
-- 
1.7.9.5

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

* Re: [PATCH v2] git-svn: introduce --parents parameter for commands branch and tag
  2013-05-15 20:14 ` [PATCH v2] " Tobias Schulte
@ 2013-05-20 22:13   ` Eric Wong
  2013-05-20 22:37     ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Wong @ 2013-05-20 22:13 UTC (permalink / raw)
  To: Tobias Schulte; +Cc: git

Tobias Schulte <tobias.schulte@gliderpilot.de> wrote:
> This parameter is equivalent to the parameter --parents on svn cp commands
> and is useful for non-standard repository layouts.
> 
> Signed-off-by: Tobias Schulte <tobias.schulte@gliderpilot.de>

Signed-off-by: Eric Wong <normalperson@yhbt.net>

Applied and pushed, thanks.

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

* Re: [PATCH v2] git-svn: introduce --parents parameter for commands branch and tag
  2013-05-20 22:13   ` Eric Wong
@ 2013-05-20 22:37     ` Junio C Hamano
  2013-05-20 22:46       ` Eric Wong
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2013-05-20 22:37 UTC (permalink / raw)
  To: Eric Wong; +Cc: Tobias Schulte, git

Eric Wong <normalperson@yhbt.net> writes:

> Tobias Schulte <tobias.schulte@gliderpilot.de> wrote:
>> This parameter is equivalent to the parameter --parents on svn cp commands
>> and is useful for non-standard repository layouts.
>> 
>> Signed-off-by: Tobias Schulte <tobias.schulte@gliderpilot.de>
>
> Signed-off-by: Eric Wong <normalperson@yhbt.net>
>
> Applied and pushed, thanks.

Thanks; is it a good time for me to pull?

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

* Re: [PATCH v2] git-svn: introduce --parents parameter for commands branch and tag
  2013-05-20 22:37     ` Junio C Hamano
@ 2013-05-20 22:46       ` Eric Wong
  2013-05-20 23:10         ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Wong @ 2013-05-20 22:46 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Tobias Schulte, git

Junio C Hamano <gitster@pobox.com> wrote:
> Thanks; is it a good time for me to pull?

Yes, I think so.  Thanks!

The following changes since commit de3a5c6da194928868b5eee4a9c4d538b4194727:

  Git 1.8.3-rc3 (2013-05-17 12:19:20 -0700)

are available in the git repository at:

  git://git.bogomips.org/git-svn.git master

for you to fetch changes up to f4f4c7fc00e8acf91150c717cf005fc36c1dd120:

  git-svn: introduce --parents parameter for commands branch and tag (2013-05-20 22:05:54 +0000)

----------------------------------------------------------------
Jonathan Nieder (1):
      git-svn: clarify explanation of --destination argument

Nathan Gray (1):
      git-svn: multiple fetch/branches/tags keys are supported

Tobias Schulte (1):
      git-svn: introduce --parents parameter for commands branch and tag

 Documentation/git-svn.txt                | 36 ++++++++++++++++++++----
 git-svn.perl                             | 19 ++++++++++++-
 t/t9167-git-svn-cmd-branch-subproject.sh | 48 ++++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+), 6 deletions(-)
 create mode 100755 t/t9167-git-svn-cmd-branch-subproject.sh

-- 
Eric Wong

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

* Re: [PATCH v2] git-svn: introduce --parents parameter for commands branch and tag
  2013-05-20 22:46       ` Eric Wong
@ 2013-05-20 23:10         ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2013-05-20 23:10 UTC (permalink / raw)
  To: Eric Wong; +Cc: Tobias Schulte, git

Eric Wong <normalperson@yhbt.net> writes:

> Junio C Hamano <gitster@pobox.com> wrote:
>> Thanks; is it a good time for me to pull?
>
> Yes, I think so.  Thanks!
>
> The following changes since commit de3a5c6da194928868b5eee4a9c4d538b4194727:
>
>   Git 1.8.3-rc3 (2013-05-17 12:19:20 -0700)
>
> are available in the git repository at:
>
>   git://git.bogomips.org/git-svn.git master
>
> for you to fetch changes up to f4f4c7fc00e8acf91150c717cf005fc36c1dd120:
>
>   git-svn: introduce --parents parameter for commands branch and tag (2013-05-20 22:05:54 +0000)

Will pull; it looked somewhat funny that the two commits from others
are both from Dec 2011, but I see Jonathan reminded us of them about
a week ago, so all look kosher ;-)

Thanks.

>
> ----------------------------------------------------------------
> Jonathan Nieder (1):
>       git-svn: clarify explanation of --destination argument
>
> Nathan Gray (1):
>       git-svn: multiple fetch/branches/tags keys are supported
>
> Tobias Schulte (1):
>       git-svn: introduce --parents parameter for commands branch and tag
>
>  Documentation/git-svn.txt                | 36 ++++++++++++++++++++----
>  git-svn.perl                             | 19 ++++++++++++-
>  t/t9167-git-svn-cmd-branch-subproject.sh | 48 ++++++++++++++++++++++++++++++++
>  3 files changed, 97 insertions(+), 6 deletions(-)

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

end of thread, other threads:[~2013-05-20 23:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-13 20:22 [PATCH] git-svn: introduce --parents parameter for commands branch and tag Tobias Schulte
2013-05-15  2:35 ` Eric Wong
2013-05-15 19:51   ` Tobias Schulte
2013-05-15 20:14 ` [PATCH v2] " Tobias Schulte
2013-05-20 22:13   ` Eric Wong
2013-05-20 22:37     ` Junio C Hamano
2013-05-20 22:46       ` Eric Wong
2013-05-20 23:10         ` Junio C Hamano

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 NNTP newsgroup(s).