{"thread":{"id":"3178","subject":"[PATCH 1/2] Use a separate directory for patches under each branch subdir","startedAt":"2006-01-29T18:10:04Z","lastAt":"2006-01-29T18:14:01Z","messageCount":3,"participants":["Chuck Lever"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"15209","messageId":"20060129181004.1919.92166.stgit@dexter.citi.umich.edu","threadId":"3178","inReplyTo":null,"subject":"[PATCH 0/2] allow patches called \"applied\", \"current\", and so on","fromName":"Chuck Lever","fromEmail":"cel@citi.umich.edu","sentAt":"2006-01-29T18:10:04Z","receivedAt":"2006-01-29T18:10:04Z","isPatch":true,"sender":{"key":"cel@citi.umich.edu","avatar":null},"body":"The following patches create a separate directory for patches so that patch\nnames like \"applied\" don't collide with the patch series control files.\n\nA new option on the \"stg branch\" command allows users to convert between the\nold-style (all in the same series directory) and the new-style (patches in a\nseparate directory).  \"stg\" should be good at detecting which type of\nrepository is in use and adapting to it, so this change should be entirely\ninvisible on legacy repositories.\n\n        -- Chuck Lever\n--\ncorporate:    <cel at netapp dot com>\npersonal:     <chucklever at bigfoot dot com>\n"},{"id":"15207","messageId":"20060129181358.1919.46348.stgit@dexter.citi.umich.edu","threadId":"3178","inReplyTo":"20060129181004.1919.92166.stgit@dexter.citi.umich.edu","subject":"[PATCH 1/2] Use a separate directory for patches under each branch subdir","fromName":"Chuck Lever","fromEmail":"cel@netapp.com","sentAt":"2006-01-29T18:13:59Z","receivedAt":"2006-01-29T18:13:59Z","isPatch":true,"sender":{"key":"cel@netapp.com","avatar":null},"body":"Currently you can't specify a patch name that matches the name of one of\nthe stgit special files under .git/patches/<branch-name>.  Let's use a\nnew subdirectory under .git/patches/<branch-name> to contain just the\npatch directories to remove this limitation.\n\nSigned-off-by: Chuck Lever <cel@netapp.com>\n---\n\n stgit/stack.py |   41 ++++++++++++++++++++++++++---------------\n 1 files changed, 26 insertions(+), 15 deletions(-)\n\ndiff --git a/stgit/stack.py b/stgit/stack.py\nindex b081c95..89a2413 100644\n--- a/stgit/stack.py\n+++ b/stgit/stack.py\n@@ -122,10 +122,10 @@ def edit_file(series, line, comment, sho\n class Patch:\n     \"\"\"Basic patch implementation\n     \"\"\"\n-    def __init__(self, name, patch_dir):\n-        self.__patch_dir = patch_dir\n+    def __init__(self, name, series_dir):\n+        self.__series_dir = series_dir\n         self.__name = name\n-        self.__dir = os.path.join(self.__patch_dir, self.__name)\n+        self.__dir = os.path.join(self.__series_dir, self.__name)\n \n     def create(self):\n         os.mkdir(self.__dir)\n@@ -143,7 +143,7 @@ class Patch:\n     def rename(self, newname):\n         olddir = self.__dir\n         self.__name = newname\n-        self.__dir = os.path.join(self.__patch_dir, self.__name)\n+        self.__dir = os.path.join(self.__series_dir, self.__name)\n \n         os.rename(olddir, self.__dir)\n \n@@ -266,14 +266,20 @@ class Series:\n         except git.GitException, ex:\n             raise StackException, 'GIT tree not initialised: %s' % ex\n \n-        self.__patch_dir = os.path.join(base_dir, 'patches',\n-                                        self.__name)\n+        self.__series_dir = os.path.join(base_dir, 'patches',\n+                                         self.__name)\n         self.__base_file = os.path.join(base_dir, 'refs', 'bases',\n                                         self.__name)\n-        self.__applied_file = os.path.join(self.__patch_dir, 'applied')\n-        self.__unapplied_file = os.path.join(self.__patch_dir, 'unapplied')\n-        self.__current_file = os.path.join(self.__patch_dir, 'current')\n-        self.__descr_file = os.path.join(self.__patch_dir, 'description')\n+\n+        self.__applied_file = os.path.join(self.__series_dir, 'applied')\n+        self.__unapplied_file = os.path.join(self.__series_dir, 'unapplied')\n+        self.__current_file = os.path.join(self.__series_dir, 'current')\n+        self.__descr_file = os.path.join(self.__series_dir, 'description')\n+\n+        # where this series keeps its patches\n+        self.__patch_dir = os.path.join(self.__series_dir, 'patches')\n+        if not os.path.isdir(self.__patch_dir):\n+            self.__patch_dir = self.__series_dir\n \n     def get_branch(self):\n         \"\"\"Return the branch name for the Series object\n@@ -325,15 +331,15 @@ class Series:\n         return self.__base_file\n \n     def get_protected(self):\n-        return os.path.isfile(os.path.join(self.__patch_dir, 'protected'))\n+        return os.path.isfile(os.path.join(self.__series_dir, 'protected'))\n \n     def protect(self):\n-        protect_file = os.path.join(self.__patch_dir, 'protected')\n+        protect_file = os.path.join(self.__series_dir, 'protected')\n         if not os.path.isfile(protect_file):\n             create_empty_file(protect_file)\n \n     def unprotect(self):\n-        protect_file = os.path.join(self.__patch_dir, 'protected')\n+        protect_file = os.path.join(self.__series_dir, 'protected')\n         if os.path.isfile(protect_file):\n             os.remove(protect_file)\n \n@@ -401,6 +407,7 @@ class Series:\n         create_empty_file(self.__applied_file)\n         create_empty_file(self.__unapplied_file)\n         create_empty_file(self.__descr_file)\n+        os.makedirs(os.path.join(self.__series_dir, 'patches'))\n         self.__begin_stack_check()\n \n     def rename(self, to_name):\n@@ -415,8 +422,8 @@ class Series:\n \n         git.rename_branch(self.__name, to_name)\n \n-        if os.path.isdir(self.__patch_dir):\n-            os.rename(self.__patch_dir, to_stack.__patch_dir)\n+        if os.path.isdir(self.__series_dir):\n+            os.rename(self.__series_dir, to_stack.__series_dir)\n         if os.path.exists(self.__base_file):\n             os.rename(self.__base_file, to_stack.__base_file)\n \n@@ -471,6 +478,10 @@ class Series:\n             if not os.listdir(self.__patch_dir):\n                 os.rmdir(self.__patch_dir)\n             else:\n+                print 'Patch directory %s is not empty.' % self.__name\n+            if not os.listdir(self.__series_dir):\n+                os.rmdir(self.__series_dir)\n+            else:\n                 print 'Series directory %s is not empty.' % self.__name\n \n         if os.path.exists(self.__base_file):\n"},{"id":"15208","messageId":"20060129181401.1919.90761.stgit@dexter.citi.umich.edu","threadId":"3178","inReplyTo":"20060129181004.1919.92166.stgit@dexter.citi.umich.edu","subject":"[PATCH 2/2] Add an option to \"stg branch\" to convert the internal format","fromName":"Chuck Lever","fromEmail":"cel@netapp.com","sentAt":"2006-01-29T18:14:01Z","receivedAt":"2006-01-29T18:14:01Z","isPatch":true,"sender":{"key":"cel@netapp.com","avatar":null},"body":"Previous patch adds support for a separate patch directory in each branch.\nLet's give users an option to convert their old branches to new style ones\nand back.\n\nSigned-off-by: Chuck Lever <cel@netapp.com>\n---\n\n stgit/commands/branch.py |   11 +++++++++++\n stgit/stack.py           |   36 ++++++++++++++++++++++++++++++++++++\n 2 files changed, 47 insertions(+), 0 deletions(-)\n\ndiff --git a/stgit/commands/branch.py b/stgit/commands/branch.py\nindex 6a551e4..ef44349 100644\n--- a/stgit/commands/branch.py\n+++ b/stgit/commands/branch.py\n@@ -45,6 +45,9 @@ options = [make_option('-c', '--create',\n            make_option('--clone',\n                        help = 'clone the contents of the current branch',\n                        action = 'store_true'),\n+           make_option('--convert',\n+                       help = 'switch between old and new format branches',\n+                       action = 'store_true'),\n            make_option('--delete',\n                        help = 'delete an existing development branch',\n                        action = 'store_true'),\n@@ -150,6 +153,14 @@ def func(parser, options, args):\n \n         return\n \n+    elif options.convert:\n+\n+        if len(args) != 0:\n+            parser.error('incorrect number of arguments')\n+\n+        crt_series.convert()\n+        return\n+\n     elif options.delete:\n \n         if len(args) != 1:\ndiff --git a/stgit/stack.py b/stgit/stack.py\nindex 89a2413..145f93c 100644\n--- a/stgit/stack.py\n+++ b/stgit/stack.py\n@@ -410,6 +410,42 @@ class Series:\n         os.makedirs(os.path.join(self.__series_dir, 'patches'))\n         self.__begin_stack_check()\n \n+    def convert(self):\n+        \"\"\"Either convert to use a separate patch directory, or\n+        unconvert to place the patches in the same directory with\n+        series control files\n+        \"\"\"\n+        if self.__patch_dir == self.__series_dir:\n+            print 'Converting old-style to new-style... ',\n+            sys.stdout.flush()\n+\n+            self.__patch_dir = os.path.join(self.__series_dir, 'patches')\n+            os.makedirs(self.__patch_dir)\n+\n+            for p in self.get_applied() + self.get_unapplied():\n+                src = os.path.join(self.__series_dir, p)\n+                dest = os.path.join(self.__patch_dir, p)\n+                os.rename(src, dest)\n+\n+            print 'done'\n+\n+        else:\n+            print 'Converting new-style to old-style... ',\n+            sys.stdout.flush()\n+\n+            for p in self.get_applied() + self.get_unapplied():\n+                src = os.path.join(self.__patch_dir, p)\n+                dest = os.path.join(self.__series_dir, p)\n+                os.rename(src, dest)\n+\n+            if not os.listdir(self.__patch_dir):\n+                os.rmdir(self.__patch_dir)\n+                print 'done'\n+            else:\n+                print 'Patch directory %s is not empty.' % self.__name\n+\n+            self.__patch_dir = self.__series_dir\n+\n     def rename(self, to_name):\n         \"\"\"Renames a series\n         \"\"\"\n"}]}