{"thread":{"id":"8647","subject":"[PATCH 1/3] Accept root <tree-ish> in 'git-svn commit-diff'","startedAt":"2007-06-19T06:54:35Z","lastAt":"2007-06-19T06:54:37Z","messageCount":3,"participants":["Sergey Yanovich"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"45318","messageId":"11822360772759-git-send-email-ynvich@gmail.com","threadId":"8647","inReplyTo":null,"subject":"[PATCH 1/3] Accept root <tree-ish> in 'git-svn commit-diff'","fromName":"Sergey Yanovich","fromEmail":"ynvich@gmail.com","sentAt":"2007-06-19T06:54:35Z","receivedAt":"2007-06-19T06:54:35Z","isPatch":true,"sender":{"key":"ynvich@gmail.com","avatar":null},"body":"Experiments with Subversion (my version is 1.4.2) show that it is\nnot necessary to call 'svn import' before the first commit. Contrarily\nto the Subversion documentation, first commit may be done even when\nSubversion repository is at revision 0.\n\nThis allow export the whole git branch to a Subversion repo using only\n'git-svn commit-diff'. Before this patch, however, 'git-svn' had\nno means to operate on root commits.\n\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":"45320","messageId":"11822360772830-git-send-email-ynvich@gmail.com","threadId":"8647","inReplyTo":"11822360772759-git-send-email-ynvich@gmail.com","subject":"[PATCH 2/3] 'git-svndump'","fromName":"Sergey Yanovich","fromEmail":"ynvich@gmail.com","sentAt":"2007-06-19T06:54:36Z","receivedAt":"2007-06-19T06:54:36Z","isPatch":true,"sender":{"key":"ynvich@gmail.com","avatar":null},"body":"A git tool to keep a subversion mirror\n\ngit-svndump is essentially a wrapper around 'git-svn commit-diff'. It\nwill work only when it is the sole method of committing to the\nSubversion repository.\n\nIt 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\nconditions. For example, when branches are switched or merged.\n\ngit-svndump provides a solution when you need to export your source code\nin Subversion format (who would need this with git :), but do not want\nto have all the shackles that 'git-svn init' puts on your repository.\n\nSigned-off-by: Sergey Yanovich <ynvich@gmail.com>\n---\n Documentation/git-svndump.txt |   97 ++++++++++++++++++++++++++++++++++++++++\n Makefile                      |    1 +\n git-svndump-init.sh           |   85 +++++++++++++++++++++++++++++++++++\n git-svndump-sync.sh           |   98 +++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 281 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..11e7e79\n--- /dev/null\n+++ b/Documentation/git-svndump.txt\n@@ -0,0 +1,97 @@\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 your 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+'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+--\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/Makefile b/Makefile\nindex c09dfaf..ecf2803 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -211,6 +211,7 @@ SCRIPT_SH = \\\n \tgit-am.sh \\\n \tgit-merge.sh git-merge-stupid.sh git-merge-octopus.sh \\\n \tgit-merge-resolve.sh git-merge-ours.sh \\\n+\tgit-svndump-init.sh git-svndump-sync.sh \\\n \tgit-lost-found.sh git-quiltimport.sh git-submodule.sh\n \n SCRIPT_PERL = \\\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..602af72\n--- /dev/null\n+++ b/git-svndump-sync.sh\n@@ -0,0 +1,98 @@\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+while true ; do\n+\n+list=`GIT_DIR=$GIT_DIR git-rev-list --topo-order $commit $start | tail -n 8`\n+\n+if test -z \"$list\" ; then\n+\texit 0\n+fi\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+\tif test $? -ne 0 ; then\n+\t\texit $?\n+\tfi\n+\techo \"$c\" > $GIT_DIR/svndump/last\n+\tlast=$c\n+\tlet rev++\n+done\n+\n+start=^$last\n+\n+done\n-- \n1.5.2.1\n"},{"id":"45319","messageId":"11822360772924-git-send-email-ynvich@gmail.com","threadId":"8647","inReplyTo":"11822360772830-git-send-email-ynvich@gmail.com","subject":"[PATCH 3/3] Fix large-scale exports by 'git-svndump'","fromName":"Sergey Yanovich","fromEmail":"ynvich@gmail.com","sentAt":"2007-06-19T06:54:37Z","receivedAt":"2007-06-19T06:54:37Z","isPatch":true,"sender":{"key":"ynvich@gmail.com","avatar":null},"body":"This is an empty patch. It is generated only to preserve headers\n([PATCH x/y] ...) for two previous patches. May/should be ignored.\n\nThanks to Johannes Sixt <J.Sixt@eudaptics.com> for comments.\n\nSigned-off-by: Sergey Yanovich <ynvich@gmail.com>\n---\n git-svndump-sync.sh |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\ndiff --git a/git-svndump-sync.sh b/git-svndump-sync.sh\nindex 602af72..b3e47f9 100755\n--- a/git-svndump-sync.sh\n+++ b/git-svndump-sync.sh\n@@ -96,3 +96,4 @@ done\n start=^$last\n \n done\n+\n-- \n1.5.2.1\n"}]}