{"thread":{"id":"8632","subject":"[PATCH 1/2] Accept root <tree-ish> in 'git-svn commit-diff'","startedAt":"2007-06-17T19:38:55Z","lastAt":"2007-06-17T19:38:57Z","messageCount":3,"participants":["Sergey Yanovich"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"45242","messageId":"11821091373273-git-send-email-ynvich@gmail.com","threadId":"8632","inReplyTo":null,"subject":"git tool to keep a subversion mirror","fromName":"Sergey Yanovich","fromEmail":"ynvich@gmail.com","sentAt":"2007-06-17T19:38:55Z","receivedAt":"2007-06-17T19:38:55Z","isPatch":false,"sender":{"key":"ynvich@gmail.com","avatar":null},"body":"Oops, failed to attach patches last time\n"},{"id":"45240","messageId":"11821091373927-git-send-email-ynvich@gmail.com","threadId":"8632","inReplyTo":"11821091373273-git-send-email-ynvich@gmail.com","subject":"[PATCH 1/2] Accept root <tree-ish> in 'git-svn commit-diff'","fromName":"Sergey Yanovich","fromEmail":"ynvich@gmail.com","sentAt":"2007-06-17T19:38:56Z","receivedAt":"2007-06-17T19:38:56Z","isPatch":true,"sender":{"key":"ynvich@gmail.com","avatar":null},"body":"\nSigned-off-by: Sergey Yanovich <ynvich@gmail.com>\n---\n git-svn.perl |    9 ++++++++-\n 1 files changed, 8 insertions(+), 1 deletions(-)\n\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 50128d7..8ad291b 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -2572,7 +2572,12 @@ sub generate_diff {\n \t}\n \tpush @diff_tree, '--find-copies-harder' if $_find_copies_harder;\n \tpush @diff_tree, \"-l$_rename_limit\" if defined $_rename_limit;\n-\tpush @diff_tree, $tree_a, $tree_b;\n+\tif ($tree_a eq '0000000000000000000000000000000000000000') {\n+\t\tpush @diff_tree, '--root';\n+\t} else {\n+\t\tpush @diff_tree, $tree_a;\n+\t}\n+\tpush @diff_tree, $tree_b;\n \tmy ($diff_fh, $ctx) = command_output_pipe(@diff_tree);\n \tlocal $/ = \"\\0\";\n \tmy $state = 'meta';\n@@ -2606,6 +2611,8 @@ sub generate_diff {\n \t\t\t}\n \t\t\t$x->{file_b} = $_;\n \t\t\t$state = 'meta';\n+\t\t} elsif ($state eq 'meta' && $_ eq $tree_b &&\n+\t\t\t$tree_a eq '0000000000000000000000000000000000000000') {\n \t\t} else {\n \t\t\tcroak \"Error parsing $_\\n\";\n \t\t}\n-- \n1.5.2.1\n"},{"id":"45241","messageId":"11821091382770-git-send-email-ynvich@gmail.com","threadId":"8632","inReplyTo":"11821091373927-git-send-email-ynvich@gmail.com","subject":"[PATCH 2/2] 'git-svndump'","fromName":"Sergey Yanovich","fromEmail":"ynvich@gmail.com","sentAt":"2007-06-17T19:38:57Z","receivedAt":"2007-06-17T19:38:57Z","isPatch":true,"sender":{"key":"ynvich@gmail.com","avatar":null},"body":"\nSigned-off-by: Sergey Yanovich <ynvich@gmail.com>\n---\n Documentation/git-svndump.txt |  106 +++++++++++++++++++++++++++++++++++++++++\n git-svndump-init.sh           |   85 +++++++++++++++++++++++++++++++++\n git-svndump-sync.sh           |   85 +++++++++++++++++++++++++++++++++\n 3 files changed, 276 insertions(+), 0 deletions(-)\n create mode 100644 Documentation/git-svndump.txt\n create mode 100755 git-svndump-init.sh\n create mode 100755 git-svndump-sync.sh\n\ndiff --git a/Documentation/git-svndump.txt b/Documentation/git-svndump.txt\nnew file mode 100644\nindex 0000000..9caf02b\n--- /dev/null\n+++ b/Documentation/git-svndump.txt\n@@ -0,0 +1,106 @@\n+git-svndump(1)\n+==========\n+\n+NAME\n+----\n+git-svndump - Exporting from git to a single Subversion branch\n+\n+SYNOPSIS\n+--------\n+'git-svndump' <command> [options] [arguments]\n+\n+DESCRIPTION\n+-----------\n+git-svndump is essentially a wrapper around 'git-svn commit-diff'. It\n+will work only when it is the sole method of committing to the\n+Subversion repository.\n+\n+It is designed to export a linear git branch. However, thanks to the way\n+'git' handles source code, 'git-svndump' seems to work in other\n+conditions. For example, when branches are switched or merged.\n+\n+git-svndump provides a solution when you need to export you source code\n+in Subversion format (who would need this with git :), but do not want\n+to have all the shackles that 'git-svn init' puts on your repository.\n+\n+COMMANDS\n+--------\n+--\n+\n+'init'::\n+\tInitialize an existing git repository with additional\n+\tmetadata directories for git-svndump.  The Subversion URL\n+\tmust be specified as the first non-optional command-line\n+\targument. 'git' tree-ish that correspond to the HEAD of\n+\tthat Subversion URL may be specified as the second optional\n+\tcommand-line argument.\n+\n+-f;;\n+\tgit-svndump normally declines to reinitialize the same git\n+\trepository. With the '-f' option that behavior is overridden.\n+\n+-A<filename>;;\n+--authors-file=<filename>;;\n+\tThe filename is stored, and provided as an argument to 'git-svn'\n+\ton calls of 'git-svndump sync'.\n+\n+'sync'::\n+\tCommit git revisions to the Subversion repository. If a git\n+\t<tree-ish> is specified as an optional command-line argument,\n+\tthan all commits between the last 'sync' and that <tree-ish> are\n+\tsend. If the argument is omitted, the HEAD of the active branch\n+\tis used.\n+\n+-A<filename>;;\n+--authors-file=<filename>;;\n+\tThe filename is provided as an argument to 'git-svn'.\n+\n+--\n+\n+BASIC EXAMPLE\n+--------------\n+\n+Contributing to a Subversion repository:\n+\n+------------------------------------------------------------------------\n+# Create your git repository, do some work and commit your  changes\n+# You are working on a computer A (git.foo.org)\n+# Prepare your git repository for export (you are in the top dir)\n+\tgit-svndump-init -A .auth http://svn.foo.org/project\n+# Commit the whole branch:\n+\tgit-svndump-sync\n+# Now you go a different computer B\n+# Clone a git repo:\n+\tgit clone git.foo.org:/path/to/project.git\n+# Enter the newly cloned directory:\n+\tcd project\n+# Immediately prepare the new repository for export\n+\tgit-svndump-init -A .auth http://svn.foo.org/project HEAD\n+# Do some work and commit both locally and to A:\n+\tgit commit ...\n+\tgit push\n+# Commit the new work:\n+\tgit-svndump-sync\n+# Now you return to the computer A\n+# Reinit your repository for export!\n+\tgit-svndump-init -f -A .auth http://svn.foo.org/project HEAD\n+------------------------------------------------------------------------\n+\n+BUGS\n+----\n+\n+The HEAD of the Subversion repository is not tracked. If your\n+git-svndump repository goes out-of-sync with the Subversion mirror,\n+the latter will most probably be corrupted.\n+\n+SEE ALSO\n+--------\n+gitlink:git-svn[1]\n+\n+Author\n+------\n+Written by Sergey Yanovich <ynvich@gmail.com>.\n+\n+Documentation\n+-------------\n+Written by Sergey Yanovich <ynvich@gmail.com>.\ndiff --git a/git-svndump-init.sh b/git-svndump-init.sh\nnew file mode 100755\nindex 0000000..4cf61b8\n--- /dev/null\n+++ b/git-svndump-init.sh\n@@ -0,0 +1,85 @@\n+#!/bin/sh\n+\n+usage()\n+{\n+\tcat << EOF\n+Usage: git-svndump-init [-f] subversion-url [<commit>]\n+  subversion-url -- URL of the subversion repository to which you want\n+                    to dump the current git repository\n+  <commit>       -- git <commit> that correspond to the latest revision\n+                    in the subversion repository\n+OPTIONS\n+  -f\n+  \t\t do not stop, if the git repository is already initialized.\n+EOF\n+\texit 1\n+}\n+\n+if test x$GIT_DIR = x ; then\n+\tif test -d ./.git ; then\n+\t\tGIT_DIR=`pwd`/.git\n+\tfi\n+fi\n+\n+if test ! -d $GIT_DIR ; then\n+\tusage\n+fi\n+\n+if test x$1 = x ; then\n+\tusage \n+fi\n+\n+if test x$1 = x-f; then\n+\tshift\n+\trm -rf $GIT_DIR/svndump\n+fi\n+\n+if test -d $GIT_DIR/svndump ; then\n+\techo git-svndump-init: error: This git repository is already initialized\n+\texit 1\n+fi\n+\n+mkdir $GIT_DIR/svndump\n+if test ! -d $GIT_DIR/svndump ; then\n+\techo git-svndump-init: error: Failed to create $GIT_DIR/svndump\n+\texit 1\n+fi\n+\n+rev=`svn info $1 >$GIT_DIR/svndump/error.log`\n+if test $? -ne 0 ; then\n+\techo git-svndump-init: error: While quering $1\n+\trm -rf $GIT_DIR/svndump\n+\texit 1\n+fi\n+\n+rev=`cat $GIT_DIR/svndump/error.log | sed -ne \"/Revision/s/.* //p\"`\n+rm $GIT_DIR/svndump/error.log\n+\n+if test x$rev = x ; then\n+\techo \"git-svndump-init: error: Cannot determine the latest revision\"\n+\techo \"                         at $1\"\n+\trm -rf $GIT_DIR/svndump\n+\texit 1\n+fi\n+\n+if test $rev -eq 0 ; then\n+\tmkdir -p $GIT_DIR/svndump/import && cd $GIT_DIR/svndump/import &&\n+\tsvn import . $1 -m \"Initial import by git-svndump\"\n+\tif test $? -ne 0 ; then\n+\t\techo \"git-svndump-init: error: Failed to init $1\"\n+\t\trm -rf $GIT_DIR/svndump\n+\t\texit 1\n+\tfi\n+\trmdir $GIT_DIR/svndump/import\n+fi\n+\n+echo \"$1\" > $GIT_DIR/svndump/url\n+\n+if test x$2 != x ; then\n+\tcommit=`GIT_DIR=$GIT_DIR git-rev-list --max-count=1 $2`\n+\tif test $? -ne 0 ; then\n+\t\techo \"git-svndump-init: warning: Bad commit $2 ignored\"\n+\telse\n+\t\techo $commit >> $GIT_DIR/svndump/last\n+\tfi\n+fi\ndiff --git a/git-svndump-sync.sh b/git-svndump-sync.sh\nnew file mode 100755\nindex 0000000..e1c04e1\n--- /dev/null\n+++ b/git-svndump-sync.sh\n@@ -0,0 +1,85 @@\n+#!/bin/sh\n+\n+usage()\n+{\n+\tcat << EOF\n+Usage: git-svndump-sync [<commit>]\n+  <commit>       -- git <commit> that correspond to the latest revision\n+                    to be dumped to the subversion repository\n+EOF\n+\texit 1\n+}\n+\n+if test x$GIT_DIR = x ; then\n+\tif test -d ./.git ; then\n+\t\tGIT_DIR=`pwd`/.git\n+\tfi\n+fi\n+\n+if test ! -d $GIT_DIR ; then\n+\tusage\n+fi\n+\n+if test ! -d $GIT_DIR/svndump ; then\n+\techo \"git-svndump-sync: error: This git repository is not initialized\"\n+\techo \"                         Run git-svndump-init first\"\n+\texit 1\n+fi\n+\n+if test ! -f $GIT_DIR/svndump/url ; then\n+\techo \"git-svndump-sync: error: Cannot read url\"\n+\texit 1\n+fi\n+\n+url=`cat $GIT_DIR/svndump/url`\n+rev=`svn info $url >$GIT_DIR/svndump/error.log`\n+if test $? -ne 0 ; then\n+\techo git-svndump-sync: error: While quering $url\n+\trm -rf $GIT_DIR/svndump/error.log\n+\texit 1\n+fi\n+\n+rev=`cat $GIT_DIR/svndump/error.log | sed -ne \"/Revision/s/.* //p\"`\n+rm $GIT_DIR/svndump/error.log\n+\n+if test x$rev = x ; then\n+\techo \"git-svndump-init: error: Cannot determine the latest revision\"\n+\techo \"                         at $url\"\n+\texit 1\n+fi\n+\n+if test x$1 = x ; then\n+\tcommit=HEAD\n+else\n+\tcommit=`GIT_DIR=$GIT_DIR git-rev-list --max-count=1 $1`\n+\tif test $? -ne 0 ; then\n+\t\techo \"git-svndump-sync: error: Bad commit '$1'\"\n+\t\texit 1\n+\tfi\n+fi\n+\n+start=\"\"\n+last=0000000000000000000000000000000000000000\n+if test -f $GIT_DIR/svndump/last ; then\n+\tlast=`cat $GIT_DIR/svndump/last`\n+\tstart=^`GIT_DIR=$GIT_DIR git-rev-list --max-count=1 $last`\n+\tif test $? -ne 0 ; then\n+\t\techo \"git-svndump-sync: warning: Ignoring bad commit '$last'\"\n+\t\tstart=\"\"\n+\t\tlast=0000000000000000000000000000000000000000\n+\tfi\n+fi\n+\n+list=`GIT_DIR=$GIT_DIR git-rev-list $commit $start`\n+\n+diffs=\"\"\n+for c in $list ; do\n+\tdiffs=\"$c $diffs\"\n+done\n+\n+for c in $diffs ; do\n+\tGIT_DIR=$GIT_DIR git-svn commit-diff -r$rev $last $c $url\n+\techo \"$c\" > $GIT_DIR/svndump/last\n+\tlast=$c\n+\tlet rev++\n+done\n-- \n1.5.2.1\n"}]}