chiark / gitweb /
Convert "stg commit" to new infrastructure
authorKarl Hasselström <kha@treskal.com>
Wed, 12 Dec 2007 21:59:13 +0000 (22:59 +0100)
committerKarl Hasselström <kha@treskal.com>
Wed, 9 Jan 2008 23:37:13 +0000 (00:37 +0100)
Signed-off-by: Karl Hasselström <kha@treskal.com>
stgit/commands/commit.py
stgit/lib/transaction.py

index e56f5a056d9c0d3b313aa59edd48d2906d48179d..f82218176aa9667eb9ff17a7316f79f3eb439af9 100644 (file)
@@ -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
 """
 
 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.out import *
-from stgit import stack, git
 
 help = 'permanently store the applied patches into stack base'
 usage = """%prog [options]
 
 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."""
 
 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 = []
 
 
 options = []
 
 
@@ -43,25 +39,15 @@ def func(parser, options, args):
     if len(args) != 0:
         parser.error('incorrect number of arguments')
 
     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()
     out.done()
index 0ca647eb228b2950a4a9e2f85426a68c6e4cf9f0..a7c4f7e890aaa4d85023b5e1a3e17c8f360e8781 100644 (file)
@@ -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.__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):
     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_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(
     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:
         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:
     def abort(self, iw = None):
         # The only state we need to restore is index+worktree.
         if iw: