summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
d010528)
The -e/--edit flag to "stg refresh" was dropped between v0.13 and
v0.14, causing severe user dissatisfaction. This patch restores it,
along with -m/--message, -f/--file, --sign, --ack, --author,
--authname, --authemail, and --authdate.
I omitted the --committer options on purpose; I think they are a
mistake. Falsifying the committer info is not a common operation, and
if one wishes to do it for some reason, one can always set the
GIT_COMMITTER_* environment variables.
Signed-off-by: Karl Hasselström <kha@treskal.com>
short = 'Add "Acked-by:" line', long = """
Add an "Acked-by:" line to the end of the patch.""")]
short = 'Add "Acked-by:" line', long = """
Add an "Acked-by:" line to the end of the patch.""")]
+def message_options(save_template):
def no_dup(parser):
if parser.values.message != None:
raise optparse.OptionValueError(
'Cannot give more than one --message or --file')
def no_combine(parser):
def no_dup(parser):
if parser.values.message != None:
raise optparse.OptionValueError(
'Cannot give more than one --message or --file')
def no_combine(parser):
- if (parser.values.message != None
+ if (save_template and parser.values.message != None
and parser.values.save_template != None):
raise optparse.OptionValueError(
'Cannot give both --message/--file and --save-template')
and parser.values.save_template != None):
raise optparse.OptionValueError(
'Cannot give both --message/--file and --save-template')
f.close()
parser.values.save_template = w
no_combine(parser)
f.close()
parser.values.save_template = w
no_combine(parser)
opt('-m', '--message', action = 'callback',
callback = msg_callback, dest = 'message', type = 'string',
short = 'Use MESSAGE instead of invoking the editor'),
opt('-m', '--message', action = 'callback',
callback = msg_callback, dest = 'message', type = 'string',
short = 'Use MESSAGE instead of invoking the editor'),
dest = 'message', type = 'string',
short = 'Use FILE instead of invoking the editor', long = """
Use the contents of FILE instead of invoking the editor.
dest = 'message', type = 'string',
short = 'Use FILE instead of invoking the editor', long = """
Use the contents of FILE instead of invoking the editor.
- (If FILE is "-", write to stdout.)"""),
- opt('--save-template', action = 'callback', dest = 'save_template',
- callback = templ_callback, metavar = 'FILE', type = 'string',
- short = 'Save the message template to FILE and exit', long = """
- Instead of running the command, just write the message
- template to FILE, and exit. (If FILE is "-", write to
- stdout.)
+ (If FILE is "-", write to stdout.)""")]
+ if save_template:
+ opts.append(
+ opt('--save-template', action = 'callback', dest = 'save_template',
+ callback = templ_callback, metavar = 'FILE', type = 'string',
+ short = 'Save the message template to FILE and exit', long = """
+ Instead of running the command, just write the message
+ template to FILE, and exit. (If FILE is "-", write to
+ stdout.)
- When driving StGit from another program, it is often
- useful to first call a command with '--save-template',
- then let the user edit the message, and then call the same
- command with '--file'.""")]
+ When driving StGit from another program, it is often
+ useful to first call a command with '--save-template',
+ then let the user edit the message, and then call the
+ same command with '--file'."""))
+ return opts
def diff_opts_option():
def diff_opts_callback(option, opt_str, value, parser):
def diff_opts_option():
def diff_opts_callback(option, opt_str, value, parser):
callback_args = (f,), short = 'Set the %s %s' % (person, f))
for f in ['name', 'email', 'date']])
callback_args = (f,), short = 'Set the %s %s' % (person, f))
for f in ['name', 'email', 'date']])
+def author_options():
+ return _person_opts('author', 'auth')
+
def author_committer_options():
return _person_opts('author', 'auth') + _person_opts('committer', 'comm')
def author_committer_options():
return _person_opts('author', 'auth') + _person_opts('committer', 'comm')
done a sequence of pushes and pops yourself."""
options = [opt('-n', '--name', short = 'Name of coalesced patch')
done a sequence of pushes and pops yourself."""
options = [opt('-n', '--name', short = 'Name of coalesced patch')
- ] + argparse.message_options()
+ ] + argparse.message_options(save_template = True)
directory = common.DirectoryHasRepositoryLib()
directory = common.DirectoryHasRepositoryLib()
short = 'Edit the patch diff'),
opt('-e', '--edit', action = 'store_true',
short = 'Invoke interactive editor'),
short = 'Edit the patch diff'),
opt('-e', '--edit', action = 'store_true',
short = 'Invoke interactive editor'),
- ] + (argparse.sign_options() + argparse.message_options() +
+ ] + (argparse.sign_options() +
+ argparse.message_options(save_template = True) +
argparse.author_committer_options() + argparse.diff_opts_option())
directory = common.DirectoryHasRepositoryLib()
argparse.author_committer_options() + argparse.diff_opts_option())
directory = common.DirectoryHasRepositoryLib()
editor."""
options = (argparse.author_committer_options()
editor."""
options = (argparse.author_committer_options()
- + argparse.message_options()
+ + argparse.message_options(save_template = True)
+ argparse.sign_options())
directory = common.DirectoryHasRepositoryLib()
+ argparse.sign_options())
directory = common.DirectoryHasRepositoryLib()
from stgit.argparse import opt
from stgit.commands import common
from stgit.argparse import opt
from stgit.commands import common
-from stgit.lib import git, transaction
+from stgit.lib import git, transaction, edit
from stgit.out import out
from stgit.out import out
+from stgit import argparse, utils
help = 'Generate a new commit for the current patch'
kind = 'patch'
help = 'Generate a new commit for the current patch'
kind = 'patch'
Instead of setting the patch top to the current contents of
the worktree, set it to the current contents of the index."""),
opt('-p', '--patch',
Instead of setting the patch top to the current contents of
the worktree, set it to the current contents of the index."""),
opt('-p', '--patch',
- short = 'Refresh (applied) PATCH instead of the top patch')]
+ short = 'Refresh (applied) PATCH instead of the top patch'),
+ opt('-e', '--edit', action = 'store_true',
+ short = 'Invoke an editor for the patch description'),
+ ] + (argparse.message_options(save_template = False) +
+ argparse.sign_options() + argparse.author_options())
directory = common.DirectoryHasRepositoryLib()
directory = common.DirectoryHasRepositoryLib()
return trans.run(stack.repository.default_iw,
print_current_patch = False), temp_name
return trans.run(stack.repository.default_iw,
print_current_patch = False), temp_name
-def absorb_applied(trans, iw, patch_name, temp_name):
+def absorb_applied(trans, iw, patch_name, temp_name, edit_fun):
"""Absorb the temp patch (C{temp_name}) into the given patch
"""Absorb the temp patch (C{temp_name}) into the given patch
- (C{patch_name}), which must be applied.
+ (C{patch_name}), which must be applied. If the absorption
+ succeeds, call C{edit_fun} on the resulting
+ L{CommitData<stgit.lib.git.CommitData>} before committing it and
+ commit the return value.
@return: C{True} if we managed to absorb the temp patch, C{False}
if we had to leave it for the user to deal with."""
@return: C{True} if we managed to absorb the temp patch, C{False}
if we had to leave it for the user to deal with."""
temp_cd = trans.patches[temp_name].data
assert trans.patches[patch_name] == temp_cd.parent
trans.patches[patch_name] = trans.stack.repository.commit(
temp_cd = trans.patches[temp_name].data
assert trans.patches[patch_name] == temp_cd.parent
trans.patches[patch_name] = trans.stack.repository.commit(
- trans.patches[patch_name].data.set_tree(temp_cd.tree))
+ edit_fun(trans.patches[patch_name].data.set_tree(temp_cd.tree)))
popped = trans.delete_patches(lambda pn: pn == temp_name, quiet = True)
assert not popped # the temp patch was topmost
temp_absorbed = True
popped = trans.delete_patches(lambda pn: pn == temp_name, quiet = True)
assert not popped # the temp patch was topmost
temp_absorbed = True
pass
return temp_absorbed
pass
return temp_absorbed
-def absorb_unapplied(trans, iw, patch_name, temp_name):
+def absorb_unapplied(trans, iw, patch_name, temp_name, edit_fun):
"""Absorb the temp patch (C{temp_name}) into the given patch
"""Absorb the temp patch (C{temp_name}) into the given patch
- (C{patch_name}), which must be unapplied.
+ (C{patch_name}), which must be unapplied. If the absorption
+ succeeds, call C{edit_fun} on the resulting
+ L{CommitData<stgit.lib.git.CommitData>} before committing it and
+ commit the return value.
@param iw: Not used.
@return: C{True} if we managed to absorb the temp patch, C{False}
@param iw: Not used.
@return: C{True} if we managed to absorb the temp patch, C{False}
# It worked. Refresh the patch with the new tree, and delete
# the temp patch.
trans.patches[patch_name] = trans.stack.repository.commit(
# It worked. Refresh the patch with the new tree, and delete
# the temp patch.
trans.patches[patch_name] = trans.stack.repository.commit(
- patch_cd.set_tree(new_tree))
+ edit_fun(patch_cd.set_tree(new_tree)))
popped = trans.delete_patches(lambda pn: pn == temp_name, quiet = True)
assert not popped # the temp patch was not applied
return True
popped = trans.delete_patches(lambda pn: pn == temp_name, quiet = True)
assert not popped # the temp patch was not applied
return True
# leave the temp patch for the user.
return False
# leave the temp patch for the user.
return False
-def absorb(stack, patch_name, temp_name):
+def absorb(stack, patch_name, temp_name, edit_fun):
"""Absorb the temp patch into the target patch."""
trans = transaction.StackTransaction(stack, 'refresh')
iw = stack.repository.default_iw
f = { True: absorb_applied, False: absorb_unapplied
}[patch_name in trans.applied]
"""Absorb the temp patch into the target patch."""
trans = transaction.StackTransaction(stack, 'refresh')
iw = stack.repository.default_iw
f = { True: absorb_applied, False: absorb_unapplied
}[patch_name in trans.applied]
- if f(trans, iw, patch_name, temp_name):
+ if f(trans, iw, patch_name, temp_name, edit_fun):
def info_msg(): pass
else:
def info_msg():
def info_msg(): pass
else:
def info_msg():
stack, patch_name, paths, temp_index = path_limiting)
if retval != utils.STGIT_SUCCESS:
return retval
stack, patch_name, paths, temp_index = path_limiting)
if retval != utils.STGIT_SUCCESS:
return retval
- return absorb(stack, patch_name, temp_name)
+ def edit_fun(cd):
+ cd, failed_diff = edit.auto_edit_patch(
+ stack.repository, cd, msg = options.message, contains_diff = False,
+ author = options.author, committer = lambda p: p,
+ sign_str = options.sign_str)
+ assert not failed_diff
+ if options.edit:
+ cd, failed_diff = edit.interactive_edit_patch(
+ stack.repository, cd, edit_diff = False,
+ diff_flags = [], replacement_diff = None)
+ assert not failed_diff
+ return cd
+ return absorb(stack, patch_name, temp_name, edit_fun)