git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chuck Lever <cel@netapp.com>
To: catalin.marinas@gmail.com
Cc: git@vger.kernel.org
Subject: [PATCH 2/2] Add an option to "stg branch" to convert the internal format
Date: Sun, 29 Jan 2006 13:14:01 -0500	[thread overview]
Message-ID: <20060129181401.1919.90761.stgit@dexter.citi.umich.edu> (raw)
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
         """

      parent reply	other threads:[~2006-01-29 18:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-29 18:10 [PATCH 0/2] allow patches called "applied", "current", and so on Chuck Lever
2006-01-29 18:13 ` [PATCH 1/2] Use a separate directory for patches under each branch subdir Chuck Lever
2006-01-29 18:14 ` Chuck Lever [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060129181401.1919.90761.stgit@dexter.citi.umich.edu \
    --to=cel@netapp.com \
    --cc=catalin.marinas@gmail.com \
    --cc=cel@citi.umich.edu \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).