{"thread":{"id":"4389","subject":"[PATCH] Preliminary branch-import support for git in tailor","startedAt":"2006-06-04T14:59:01Z","lastAt":"2006-06-04T14:59:01Z","messageCount":1,"participants":["Yann Dirson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"21208","messageId":"20060604145901.GQ6535@nowhere.earth","threadId":"4389","inReplyTo":null,"subject":"[PATCH] Preliminary branch-import support for git in tailor","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2006-06-04T14:59:01Z","receivedAt":"2006-06-04T14:59:01Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"Here is my first try at working with branches with tailor.\nThis patch applies to current tailor from the darcs repo.\n\nAttached: the patch, and the sample config I used to test it against a\npublic repo.\n\nPossible improvements:\n\n- the parent-repo parameter is probably generic enough to be useful\nfor other targets, but it is currently a git-target parameter only\n\n- the change to tailor.py to avoid loosing the initial commit log on\nthe imported branch probably breaks all other targets because of the\nprevious issue\n\n- autodetection of the branchpoint would be great, but that surely\ndeserves to be done in core tailor\n\n- I'll have a try next to add support for pushing git branches to cvs\nones: that will give us a real 2-way sync between cvs and git\n\n\nGeneric problems noticed:\n\n- not all tags from the cvs repo I tested against were imported\n(problem specific to the cvs source ?)\n\n- I could not make the cvsps source work to verify it fetches tags\nbetter than the cvs one\n\n- the \"projects\" parameter has to be specified explicitely to force\nthe ordering of branch imports - I would have expected the declaration\norder to be used.\n\n- it would probably be cleaner to have the *Repository classes in\nrepository.py moved into their own files: currently we have to modify\na generic file to add backend-specific options, that's not really\ngeneric.  What about loading the necessary class when it is found\nmentionned in the config ?\n\n\nComparison with git-cvsimport\n\n- tailor can give strange results in some cases, but I believe it is\nmore correct than git-cvsimport.  An example is when the cvs branch\nyou import does not exist in some files for any reason (I had a branch\nonly for the src/ dir - corrected that now): in that case tailor\ncorrectly shows deletions for those files in the branch initial\ncommit, whereas git-cvsimport only works on changes, and does not do\nanything special (this may be cvsps doing magic behind his back).\n\n- run against a local copy of the repository, tailor is orders of\nmagnitude slower than git-cvsimport (git-cvsimport returned instantly\non my repo), some profiling has to be done.\n\n-- \nYann Dirson    <ydirson@altern.org> |\nDebian-related: <dirson@debian.org> |   Support Debian GNU/Linux:\n                                    |  Freedom, Power, Stability, Gratis\n     http://ydirson.free.fr/        | Check <http://www.debian.org/>\n\n\ndiff -rN -u old-tailor/README new-tailor/README\n--- old-tailor/README\t2006-06-04 16:42:52.000000000 +0200\n+++ new-tailor/README\t2006-06-04 16:42:52.000000000 +0200\n@@ -661,7 +661,21 @@\n git\n %%%\n \n-.. no specific options\n+parent-repo : string\n+  Relative path to a git directory to use as a parent.  This is useful\n+  to import repository branches.  If this parameter is empty, the\n+  branch has no parent (default behaviour).\n+\n+parent-rev : string\n+  A reference to the git commit which is the parent for the first\n+  revision on the branch to be imported (ie, the branch point).  It\n+  can be a tag name or any syntax acceptable by git (eg. something\n+  like \"tag~2\", if you want to correct the idea of where the\n+  branchpoint is.\n+\n+  Since tailor generates mostly-stable SHA1 revisions, you can also\n+  use a SHA1 as branchpoint.  Just import your trunk first, find the\n+  correct SHA1, and setup and import your branch.\n \n hg\n %%\ndiff -rN -u old-tailor/vcpx/git.py new-tailor/vcpx/git.py\n--- old-tailor/vcpx/git.py\t2006-06-04 16:42:52.000000000 +0200\n+++ new-tailor/vcpx/git.py\t2006-06-04 16:42:52.000000000 +0200\n@@ -298,19 +298,39 @@\n \n     def _prepareTargetRepository(self):\n         \"\"\"\n-        Execute ``git init-db``.\n+        Initialize .git through ``git init-db`` or ``git-clone``.\n         \"\"\"\n \n+        from os import renames\n         from os.path import join, exists\n \n         if not exists(join(self.basedir, self.repository.METADIR)):\n-            init = ExternalCommand(cwd=self.basedir,\n-                                   command=self.repository.command(\"init-db\"))\n-            init.execute()\n-\n-            if init.exit_status:\n-                raise TargetInitializationFailure(\n-                    \"%s returned status %s\" % (str(init), init.exit_status))\n+            if self.repository.PARENT_REPO == '':\n+                cmd = self.repository.command(\"init-db\")\n+                init = ExternalCommand(cwd=self.basedir, command=cmd)\n+                init.execute()\n+                if init.exit_status:\n+                    raise TargetInitializationFailure(\n+                        \"%s returned status %s\" % (str(init), init.exit_status))\n+            else:\n+                cmd = self.repository.command(\"clone\", \"--shared\", \"-n\",\n+                                              self.repository.PARENT_REPO, 'tmp')\n+                clone = ExternalCommand(cwd=self.basedir, command=cmd)\n+                clone.execute()\n+                if clone.exit_status:\n+                    raise TargetInitializationFailure(\n+                        \"%s returned status %s\" % (str(clone), clone.exit_status))\n+\n+                renames('%s/%s/tmp/.git' % (self.repository.rootdir, self.repository.subdir),\n+                        '%s/%s/.git' % (self.repository.rootdir, self.repository.subdir))\n+                \n+                cmd = self.repository.command(\"reset\", \"--soft\", self.repository.PARENT_REV)\n+                reset = ExternalCommand(cwd=self.basedir, command=cmd)\n+                reset.execute()\n+                if reset.exit_status:\n+                    raise TargetInitializationFailure(\n+                        \"%s returned status %s\" % (str(reset), reset.exit_status))\n+\n \n     def _prepareWorkingDirectory(self, source_repo):\n         \"\"\"\ndiff -rN -u old-tailor/vcpx/repository.py new-tailor/vcpx/repository.py\n--- old-tailor/vcpx/repository.py\t2006-06-04 16:42:52.000000000 +0200\n+++ new-tailor/vcpx/repository.py\t2006-06-04 16:42:52.000000000 +0200\n@@ -287,6 +287,8 @@\n     def _load(self, project):\n         Repository._load(self, project)\n         self.EXECUTABLE = project.config.get(self.name, 'git-command', 'git')\n+        self.PARENT_REPO = project.config.get(self.name, 'parent-repo', '')\n+        self.PARENT_REV = project.config.get(self.name, 'parent-rev', 'HEAD')\n \n \n class HgRepository(Repository):\ndiff -rN -u old-tailor/vcpx/tailor.py new-tailor/vcpx/tailor.py\n--- old-tailor/vcpx/tailor.py\t2006-06-04 16:42:52.000000000 +0200\n+++ new-tailor/vcpx/tailor.py\t2006-06-04 16:42:52.000000000 +0200\n@@ -74,7 +74,9 @@\n             raise\n \n         try:\n-            dwd.importFirstRevision(self.source, actual, 'INITIAL'==revision)\n+            dwd.importFirstRevision(self.source, actual,\n+                                    self.target.PARENT_REPO != '' or\n+                                    'INITIAL'==revision)\n         except:\n             self.log.critical('Could not import checked out tree in \"%s\"!',\n                               self.rootdir)\n\n\n\n[DEFAULT]\n#verbose=yes\npatch-name-format=%(firstlogline)s\nremove-first-log-line=True\n# that one seems necessary to force ordering\nprojects = trunk-pull, branch-pull\n\n[trunk-pull]\nroot-directory = /export/work/yann/tailor/test/root\nsource = cvs:bigdiesel\ntarget = git:bigdiesel\nstart-revision = INITIAL\nstate-file = trunk-pull.state\nsubdir = trunk\n\n[branch-pull]\nroot-directory = /export/work/yann/tailor/test/root\nsource = cvs:bigdiesel\ntarget = git:bigdiesel-branch\nstart-revision = bigloo-parser INITIAL\nstate-file = branch-pull.state\nsubdir = bigloo-parser\n\n[cvs:bigdiesel]\nrepository = :pserver:anonymous@cvs.savannah.nongnu.org:/sources/dsssl-utils\n#repository = /export/work/yann/tailor/test/cvsroot\nmodule = dsssl-utils/bigdiesel\n\n[git:bigdiesel]\n\n[git:bigdiesel-branch]\nparent-repo = ../trunk\n#parent-rev = 0bbd4b84fce498793db7fdf01388dcb5ed9ada88\nparent-rev = bigloo-parser_branchpoint\n"}]}