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 2/5] stg coalesce: Support --file and --save-template
Date: Fri, 14 Dec 2007 07:32:19 +0100 [thread overview]
Message-ID: <20071214063219.29290.24743.stgit@yoghurt> (raw)
In-Reply-To: <20071214062618.29290.70792.stgit@yoghurt>
--save-template was a bit tricky, because we want that
* if we reached the stage where the message is needed without
conflicts, the message should be written and no other side effects
should occur; but
* if we run into conflicts before reaching that point, behave just
as if --save-template was not given.
This makes this script
stg coalesce --save-template <patches>
if template was saved:
let user edit template
if user didn't abort:
stg coalesce --file <patches>
equivalent to
stg coalesce <patches>
with the added benefit that the user can abort the whole thing without
visible side effects.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/commands/coalesce.py | 28 +++++++++++++++++++---------
1 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/stgit/commands/coalesce.py b/stgit/commands/coalesce.py
index e3e1629..2330231 100644
--- a/stgit/commands/coalesce.py
+++ b/stgit/commands/coalesce.py
@@ -34,11 +34,13 @@ you specify, you will have to resolve them manually just as if you had
done a sequence of pushes and pops yourself."""
directory = common.DirectoryHasRepositoryLib()
-options = [make_option('-n', '--name', help = 'name of coalesced patch'),
- make_option('-m', '--message',
- help = 'commit message of coalesced patch')]
+options = [make_option('-n', '--name', help = 'name of coalesced patch')
+ ] + utils.make_message_options()
-def _coalesce_patches(trans, patches, msg):
+class SaveTemplateDone(Exception):
+ pass
+
+def _coalesce_patches(trans, patches, msg, save_template):
cd = trans.patches[patches[0]].data
cd = git.Commitdata(tree = cd.tree, parents = cd.parents)
for pn in patches[1:]:
@@ -53,12 +55,16 @@ def _coalesce_patches(trans, patches, msg):
msg = '\n\n'.join('%s\n\n%s' % (pn.ljust(70, '-'),
trans.patches[pn].data.message)
for pn in patches)
- msg = utils.edit_string(msg, '.stgit-coalesce.txt').strip()
+ if save_template:
+ save_template(msg)
+ raise SaveTemplateDone()
+ else:
+ msg = utils.edit_string(msg, '.stgit-coalesce.txt').strip()
cd = cd.set_message(msg)
return cd
-def _coalesce(stack, iw, name, msg, patches):
+def _coalesce(stack, iw, name, msg, save_template, patches):
# If a name was supplied on the command line, make sure it's OK.
def bad_name(pn):
@@ -75,8 +81,8 @@ def _coalesce(stack, iw, name, msg, patches):
trans = transaction.StackTransaction(stack, 'stg coalesce')
push_new_patch = bool(set(patches) & set(trans.applied))
- new_commit_data = _coalesce_patches(trans, patches, msg)
try:
+ new_commit_data = _coalesce_patches(trans, patches, msg, save_template)
if new_commit_data:
# We were able to construct the coalesced commit
# automatically. So just delete its constituent patches.
@@ -88,7 +94,8 @@ def _coalesce(stack, iw, name, msg, patches):
to_push = trans.pop_patches(lambda pn: pn in patches)
for pn in patches:
trans.push_patch(pn, iw)
- new_commit_data = _coalesce_patches(trans, patches, msg)
+ new_commit_data = _coalesce_patches(trans, patches, msg,
+ save_template)
assert not trans.delete_patches(lambda pn: pn in patches)
make_coalesced_patch(trans, new_commit_data)
@@ -98,6 +105,9 @@ def _coalesce(stack, iw, name, msg, patches):
trans.push_patch(get_name(new_commit_data), iw)
for pn in to_push:
trans.push_patch(pn, iw)
+ except SaveTemplateDone:
+ trans.abort(iw)
+ return
except transaction.TransactionHalted:
pass
trans.run(iw)
@@ -109,4 +119,4 @@ def func(parser, options, args):
if len(patches) < 2:
raise common.CmdException('Need at least two patches')
_coalesce(stack, stack.repository.default_iw(),
- options.name, options.message, patches)
+ options.name, options.message, options.save_template, patches)
next prev parent reply other threads:[~2007-12-14 6:32 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 ` Karl Hasselström [this message]
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 ` [StGit PATCH 4/5] Convert "stg commit" to new infrastructure Karl Hasselström
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=20071214063219.29290.24743.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).