[StGit PATCH 4/5] Convert "stg commit" to new infrastructure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Karl Hasselström <kha@xxxxxxxxxxx>

---

 stgit/commands/commit.py |   42 ++++++++++++++----------------------------
 stgit/lib/transaction.py |    7 ++++++-
 2 files changed, 20 insertions(+), 29 deletions(-)


diff --git a/stgit/commands/commit.py b/stgit/commands/commit.py
index e56f5a0..f822181 100644
--- a/stgit/commands/commit.py
+++ b/stgit/commands/commit.py
@@ -15,13 +15,9 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-import sys, os
-from optparse import OptionParser, make_option
-
-from stgit.commands.common import *
-from stgit.utils import *
+from stgit.commands import common
+from stgit.lib import transaction
 from stgit.out import *
-from stgit import stack, git
 
 help = 'permanently store the applied patches into stack base'
 usage = """%prog [options]
@@ -32,7 +28,7 @@ remove them from the series while advancing the base.
 Use this command only if you want to permanently store the applied
 patches and no longer manage them with StGIT."""
 
-directory = DirectoryGotoToplevel()
+directory = common.DirectoryHasRepositoryLib()
 options = []
 
 
@@ -43,25 +39,15 @@ def func(parser, options, args):
     if len(args) != 0:
         parser.error('incorrect number of arguments')
 
-    check_local_changes()
-    check_conflicts()
-    check_head_top_equal(crt_series)
-
-    applied = crt_series.get_applied()
-    if not applied:
-        raise CmdException, 'No patches applied'
-
-    if crt_series.get_protected():
-        raise CmdException, 'This branch is protected.  Commit is not permitted'
-
-    crt_head = git.get_head()
-
-    out.start('Committing %d patches' % len(applied))
-
-    crt_series.pop_patch(applied[0])
-    git.switch(crt_head)
-
-    for patch in applied:
-        crt_series.delete_patch(patch)
-
+    stack = directory.repository.current_stack
+    patches = stack.patchorder.applied
+    if not patches:
+        raise CmdException('No patches to commit')
+    out.start('Committing %d patches' % len(patches))
+    trans = transaction.StackTransaction(stack, 'stg commit')
+    for pn in patches:
+        trans.patches[pn] = None
+    trans.applied = []
+    trans.base = stack.head
+    trans.run()
     out.done()
diff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py
index 0ca647e..a7c4f7e 100644
--- a/stgit/lib/transaction.py
+++ b/stgit/lib/transaction.py
@@ -41,6 +41,7 @@ class StackTransaction(object):
         self.__unapplied = list(self.__stack.patchorder.unapplied)
         self.__error = None
         self.__current_tree = self.__stack.head.data.tree
+        self.__base = self.__stack.base
     stack = property(lambda self: self.__stack)
     patches = property(lambda self: self.__patches)
     def __set_applied(self, val):
@@ -49,6 +50,10 @@ class StackTransaction(object):
     def __set_unapplied(self, val):
         self.__unapplied = list(val)
     unapplied = property(lambda self: self.__unapplied, __set_unapplied)
+    def __set_base(self, val):
+        assert not self.__applied
+        self.__base = val
+    base = property(lambda self: self.__base, __set_base)
     def __checkout(self, tree, iw):
         if not self.__stack.head_top_equal():
             out.error(
@@ -76,7 +81,7 @@ class StackTransaction(object):
         if self.__applied:
             return self.__patches[self.__applied[-1]]
         else:
-            return self.__stack.base
+            return self.__base
     def abort(self, iw = None):
         # The only state we need to restore is index+worktree.
         if iw:

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux