git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] Add an option to "stg branch" to convert the internal format

From
CLChuck Lever <cel@netapp.com>
Date
Jan 29, 2006, 18:14 UTC
Message-ID
<20060129181401.1919.90761.stgit@dexter.citi.umich.edu>
In-Reply-To
<20060129181004.1919.92166.stgit@dexter.citi.umich.edu>

Previous patch adds support for a separate patch directory in each branch. Let's give users an option to convert their old branches to new style ones and back.

Signed-off-by: Chuck Lever <cel@netapp.com>
---
 stgit/commands/branch.py |   11 +++++++++++
 stgit/stack.py           |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/stgit/commands/branch.py b/stgit/commands/branch.py
index 6a551e4..ef44349 100644
--- a/stgit/commands/branch.py
+++ b/stgit/commands/branch.py
@@ -45,6 +45,9 @@ options = [make_option('-c', '--create',
            make_option('--clone',
                        help = 'clone the contents of the current branch',
                        action = 'store_true'),
+           make_option('--convert',
+                       help = 'switch between old and new format branches',
+                       action = 'store_true'),
            make_option('--delete',
                        help = 'delete an existing development branch',
                        action = 'store_true'),
@@ -150,6 +153,14 @@ def func(parser, options, args):
 
         return
 
+    elif options.convert:
+
+        if len(args) != 0:
+            parser.error('incorrect number of arguments')
+
+        crt_series.convert()
+        return
+
     elif options.delete:
 
         if len(args) != 1:
diff --git a/stgit/stack.py b/stgit/stack.py
index 89a2413..145f93c 100644
--- a/stgit/stack.py
+++ b/stgit/stack.py
@@ -410,6 +410,42 @@ class Series:
         os.makedirs(os.path.join(self.__series_dir, 'patches'))
         self.__begin_stack_check()
 
+    def convert(self):
+        """Either convert to use a separate patch directory, or
+        unconvert to place the patches in the same directory with
+        series control files
+        """
+        if self.__patch_dir == self.__series_dir:
+            print 'Converting old-style to new-style... ',
+            sys.stdout.flush()
+
+            self.__patch_dir = os.path.join(self.__series_dir, 'patches')
+            os.makedirs(self.__patch_dir)
+
+            for p in self.get_applied() + self.get_unapplied():
+                src = os.path.join(self.__series_dir, p)
+                dest = os.path.join(self.__patch_dir, p)
+                os.rename(src, dest)
+
+            print 'done'
+
+        else:
+            print 'Converting new-style to old-style... ',
+            sys.stdout.flush()
+
+            for p in self.get_applied() + self.get_unapplied():
+                src = os.path.join(self.__patch_dir, p)
+                dest = os.path.join(self.__series_dir, p)
+                os.rename(src, dest)
+
+            if not os.listdir(self.__patch_dir):
+                os.rmdir(self.__patch_dir)
+                print 'done'
+            else:
+                print 'Patch directory %s is not empty.' % self.__name
+
+            self.__patch_dir = self.__series_dir
+
     def rename(self, to_name):
         """Renames a series
         """
Previous: Chuck Lever
Message 3 of 3 in “allow patches called "applied", "current", and so on”
  1. 0/2 allow patches called "applied", "current", and so onChuck Lever, Jan 29, 2006
  2. 1/2 Use a separate directory for patches under each branch subdirChuck Lever, Jan 29, 2006
  3. 2/2 Add an option to "stg branch" to convert the internal formatChuck Lever, Jan 29, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.