{"thread":{"id":"15490","subject":"[PATCH] Add git-svn branch to allow branch creation in SVN repositories","startedAt":"2008-09-11T14:20:39Z","lastAt":"2008-09-18T06:55:16Z","messageCount":2,"participants":["Florian Ragwitz","Eric Wong"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"90439","messageId":"1221142839-29624-1-git-send-email-rafl@debian.org","threadId":"15490","inReplyTo":null,"subject":"[PATCH] Add git-svn branch to allow branch creation in SVN repositories","fromName":"Florian Ragwitz","fromEmail":"rafl@debian.org","sentAt":"2008-09-11T14:20:39Z","receivedAt":"2008-09-11T14:20:39Z","isPatch":true,"sender":{"key":"rafl@debian.org","avatar":"https://gravatar.com/avatar/87c13cf03f1d0ddb4777379622dc2e0a5224bc0321ce9622cfb4daad92e268ee?d=mp&s=160"},"body":"Signed-off-by: Florian Ragwitz <rafl@debian.org>\n---\n Documentation/git-svn.txt |   24 +++++++++++++++++++++++-\n git-svn.perl              |   43 ++++++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 65 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt\nindex 1e644ca..0fe4955 100644\n--- a/Documentation/git-svn.txt\n+++ b/Documentation/git-svn.txt\n@@ -149,6 +149,22 @@ and have no uncommitted changes.\n \tis very strongly discouraged.\n --\n \n+'branch'::\n+\tCreate a branch in the SVN repository.\n+\n+-m;;\n+--message;;\n+\tAllows to specify the commit message.\n+\n+-t;;\n+--tag;;\n+\tCreate a tag by using the tags_subdir instead of the branches_subdir\n+\tspecified during git svn init.\n+\n+'tag'::\n+\tCreate a tag in the SVN repository. This is a shorthand for\n+\t'branch -t'.\n+\n 'log'::\n \tThis should make it easy to look up svn log messages when svn\n \tusers refer to -r/--revision numbers.\n@@ -372,7 +388,8 @@ Passed directly to 'git-rebase' when using 'dcommit' if a\n -n::\n --dry-run::\n \n-This can be used with the 'dcommit' and 'rebase' commands.\n+This can be used with the 'dcommit', 'rebase', 'branch' and 'tag'\n+commands.\n \n For 'dcommit', print out the series of git arguments that would show\n which diffs would be committed to SVN.\n@@ -381,6 +398,9 @@ For 'rebase', display the local branch associated with the upstream svn\n repository associated with the current branch and the URL of svn\n repository that will be fetched from.\n \n+For 'branch' and 'tag', display the urls that will be used for copying when\n+creating the branch or tag.\n+\n --\n \n ADVANCED OPTIONS\n@@ -498,6 +518,8 @@ Tracking and contributing to an entire Subversion-managed project\n \tgit svn clone http://svn.foo.org/project -T trunk -b branches -t tags\n # View all branches and tags you have cloned:\n \tgit branch -r\n+# Create a new branch in SVN\n+    git svn branch waldo\n # Reset your master to trunk (or any other branch, replacing 'trunk'\n # with the appropriate name):\n \tgit reset --hard remotes/trunk\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 88066c9..54a785c 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -66,7 +66,7 @@ my ($_stdin, $_help, $_edit,\n \t$_version, $_fetch_all, $_no_rebase,\n \t$_merge, $_strategy, $_dry_run, $_local,\n \t$_prefix, $_no_checkout, $_url, $_verbose,\n-\t$_git_format, $_commit_url);\n+\t$_git_format, $_commit_url, $_tag);\n $Git::SVN::_follow_parent = 1;\n my %remote_opts = ( 'username=s' => \\$Git::SVN::Prompt::_username,\n                     'config-dir=s' => \\$Git::SVN::Ra::config_dir,\n@@ -131,6 +131,14 @@ my %cmd = (\n \t\t\t  'revision|r=i' => \\$_revision,\n \t\t\t  'no-rebase' => \\$_no_rebase,\n \t\t\t%cmt_opts, %fc_opts } ],\n+\tbranch => [ \\&cmd_branch,\n+\t            'Create a branch in the SVN repository',\n+\t            { 'message|m=s' => \\$_message,\n+\t              'dry-run|n' => \\$_dry_run } ],\n+\ttag => [ sub { $_tag = 1; cmd_branch(@_) },\n+\t         'Create a tag in the SVN repository',\n+\t         { 'message|m=s' => \\$_message,\n+\t           'dry-run|n' => \\$_dry_run } ],\n \t'set-tree' => [ \\&cmd_set_tree,\n \t                \"Set an SVN repository to a git tree-ish\",\n \t\t\t{ 'stdin|' => \\$_stdin, %cmt_opts, %fc_opts, } ],\n@@ -537,6 +545,39 @@ sub cmd_dcommit {\n \tunlink $gs->{index};\n }\n \n+sub cmd_branch {\n+\tmy ($branch_name, $head) = @_;\n+\n+\tdie \"branch name required\\n\" unless $branch_name;\n+\t$head ||= 'HEAD';\n+\n+\tmy ($src, $rev, undef, $gs) = working_head_info($head);\n+\n+\tmy $remote = Git::SVN::read_all_remotes()->{svn};\n+\tmy $glob = $remote->{ $_tag ? 'tags' : 'branches' };\n+\tmy ($lft, $rgt) = @{ $glob->{path} }{qw/left right/};\n+\tmy $dst = join '/', $remote->{url}, $lft, $branch_name, ($rgt || ());\n+\n+\tmy $ctx = SVN::Client->new(\n+\t\tauth    => Git::SVN::Ra::_auth_providers(),\n+\t\tlog_msg => sub {\n+\t\t\t${ $_[0] } = defined $_message\n+\t\t\t\t? $_message\n+\t\t\t\t: 'Create branch ' . $branch_name;\n+\t\t},\n+\t);\n+\n+\teval {\n+\t\t$ctx->ls($dst, 'HEAD', 0);\n+\t} and die \"branch ${branch_name} already exists\\n\";\n+\n+\tprint \"Copying ${src} at r${rev} to ${dst}...\\n\";\n+\t$ctx->copy($src, $rev, $dst)\n+\t\tunless $_dry_run;\n+\n+\t$gs->fetch_all;\n+}\n+\n sub cmd_find_rev {\n \tmy $revision_or_hash = shift or die \"SVN or git revision required \",\n \t                                    \"as a command-line argument\\n\";\n-- \n1.5.6.5\n"},{"id":"91002","messageId":"20080918065516.GA28905@untitled","threadId":"15490","inReplyTo":"1221142839-29624-1-git-send-email-rafl@debian.org","subject":"Re: [PATCH] Add git-svn branch to allow branch creation in SVN repositories","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2008-09-18T06:55:16Z","receivedAt":"2008-09-18T06:55:16Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Florian Ragwitz <rafl@debian.org> wrote:\n> Signed-off-by: Florian Ragwitz <rafl@debian.org>\n\nHi Florian, Sorry I haven't checked the list (nor a good chunk email) in\na bit.\n\nThe patch looks good, but can you add a test for this functionality?\nIt'll make maintenance easier when other people (myself included)\nintroduce changes that can potentially break something.  Thanks.\n\n> ---\n>  Documentation/git-svn.txt |   24 +++++++++++++++++++++++-\n>  git-svn.perl              |   43 ++++++++++++++++++++++++++++++++++++++++++-\n>  2 files changed, 65 insertions(+), 2 deletions(-)\n> \n\n-- \nEric Wong\n"}]}