From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org, "David Kågedal" <davidk@lysator.liu.se>
Subject: [StGit PATCH 4/5] Convert "stg commit" to new infrastructure
Date: Fri, 14 Dec 2007 07:32:30 +0100 [thread overview]
Message-ID: <20071214063230.29290.22561.stgit@yoghurt> (raw)
In-Reply-To: <20071214062618.29290.70792.stgit@yoghurt>
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
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:
next prev parent reply other threads:[~2007-12-14 6:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-14 6:32 [StGit PATCH 0/5] More experimental patches Karl Hasselström
2007-12-14 6:32 ` [StGit PATCH 1/5] Expose transaction abort function Karl Hasselström
2007-12-14 6:32 ` [StGit PATCH 2/5] stg coalesce: Support --file and --save-template Karl Hasselström
2007-12-14 6:32 ` [StGit PATCH 3/5] Set exit code to 3 on merge conflict Karl Hasselström
2007-12-14 6:32 ` Karl Hasselström [this message]
2007-12-14 6:32 ` [StGit PATCH 5/5] Make "stg commit" fancier Karl Hasselström
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=20071214063230.29290.22561.stgit@yoghurt \
--to=kha@treskal.com \
--cc=catalin.marinas@gmail.com \
--cc=davidk@lysator.liu.se \
--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).