--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>
done a sequence of pushes and pops yourself."""
directory = common.DirectoryHasRepositoryLib()
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:]:
cd = trans.patches[patches[0]].data
cd = git.Commitdata(tree = cd.tree, parents = cd.parents)
for pn in patches[1:]:
msg = '\n\n'.join('%s\n\n%s' % (pn.ljust(70, '-'),
trans.patches[pn].data.message)
for pn in patches)
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
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):
# If a name was supplied on the command line, make sure it's OK.
def bad_name(pn):
trans = transaction.StackTransaction(stack, 'stg coalesce')
push_new_patch = bool(set(patches) & set(trans.applied))
trans = transaction.StackTransaction(stack, 'stg coalesce')
push_new_patch = bool(set(patches) & set(trans.applied))
- new_commit_data = _coalesce_patches(trans, patches, msg)
+ 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.
if new_commit_data:
# We were able to construct the coalesced commit
# automatically. So just delete its constituent patches.
to_push = trans.pop_patches(lambda pn: pn in patches)
for pn in patches:
trans.push_patch(pn, iw)
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)
assert not trans.delete_patches(lambda pn: pn in patches)
make_coalesced_patch(trans, new_commit_data)
trans.push_patch(get_name(new_commit_data), iw)
for pn in to_push:
trans.push_patch(pn, iw)
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)
except transaction.TransactionHalted:
pass
trans.run(iw)
if len(patches) < 2:
raise common.CmdException('Need at least two patches')
_coalesce(stack, stack.repository.default_iw(),
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)