Add an option (-s/--showpatch) to show the patch content when editing the
patch description, by appending it to the edit buffer, for more accurate
patch comment editing and to check its correctness before committing it.
It's how one works with quilt, and it's very important when the patch is
non-trivial to re-read it.
It's done for import, new and refresh, I left fold out.
Additionally, set the buffer filetype to "diff" for correct highlighting in
Vi.
Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
make_option('-e', '--edit',
help = 'invoke an editor for the patch description',
action = 'store_true'),
make_option('-e', '--edit',
help = 'invoke an editor for the patch description',
action = 'store_true'),
+ make_option('-s', '--showpatch',
+ help = 'show the patch content in the editor buffer',
+ action = 'store_true'),
make_option('-a', '--author', metavar = '"NAME <EMAIL>"',
help = 'use "NAME <EMAIL>" as the author details'),
make_option('--authname',
make_option('-a', '--author', metavar = '"NAME <EMAIL>"',
help = 'use "NAME <EMAIL>" as the author details'),
make_option('--authname',
sys.stdout.flush()
git.apply_patch(filename)
sys.stdout.flush()
git.apply_patch(filename)
- crt_series.refresh_patch(edit = options.edit)
+ crt_series.refresh_patch(edit = options.edit,
+ show_patch = options.showpatch)
print 'done'
print_crt_patch()
print 'done'
print_crt_patch()
make_option('--force',
help = 'proceed even if there are local changes',
action = 'store_true'),
make_option('--force',
help = 'proceed even if there are local changes',
action = 'store_true'),
+ make_option('-s', '--showpatch',
+ help = 'show the patch content in the editor buffer',
+ action = 'store_true'),
make_option('-a', '--author', metavar = '"NAME <EMAIL>"',
help = 'use "NAME <EMAIL>" as the author details'),
make_option('--authname',
make_option('-a', '--author', metavar = '"NAME <EMAIL>"',
help = 'use "NAME <EMAIL>" as the author details'),
make_option('--authname',
check_local_changes()
check_conflicts()
check_head_top_equal()
check_local_changes()
check_conflicts()
check_head_top_equal()
+ # No local changes -> no patch to show
+ options.showpatch = False
if options.author:
options.authname, options.authemail = name_email(options.author)
crt_series.new_patch(args[0], message = options.message,
if options.author:
options.authname, options.authemail = name_email(options.author)
crt_series.new_patch(args[0], message = options.message,
+ show_patch = options.showpatch,
author_name = options.authname,
author_email = options.authemail,
author_date = options.authdate,
author_name = options.authname,
author_email = options.authemail,
author_date = options.authdate,
help = 'invoke an editor for the patch '\
'description',
action = 'store_true'),
help = 'invoke an editor for the patch '\
'description',
action = 'store_true'),
+ make_option('-s', '--showpatch',
+ help = 'show the patch content in the editor buffer',
+ action = 'store_true'),
make_option('-m', '--message',
help = 'use MESSAGE as the patch ' \
'description'),
make_option('-m', '--message',
help = 'use MESSAGE as the patch ' \
'description'),
resolved_all()
crt_series.refresh_patch(message = options.message,
edit = options.edit,
resolved_all()
crt_series.refresh_patch(message = options.message,
edit = options.edit,
+ show_patch = options.showpatch,
author_name = options.authname,
author_email = options.authemail,
author_date = options.authdate,
author_name = options.authname,
author_email = options.authemail,
author_date = options.authdate,
class StackException(Exception):
pass
class StackException(Exception):
pass
+class FilterUntil:
+ def __init__(self):
+ self.should_print = True
+ def __call__(self, x, until_test, prefix):
+ if until_test(x):
+ self.should_print = False
+ if self.should_print:
+ return x[0:len(prefix)] != prefix
+ return False
+
#
# Functions
#
__comment_prefix = 'STG:'
#
# Functions
#
__comment_prefix = 'STG:'
+__patch_prefix = 'STG_PATCH:'
def __clean_comments(f):
"""Removes lines marked for status in a commit file
def __clean_comments(f):
"""Removes lines marked for status in a commit file
f.seek(0)
# remove status-prefixed lines
f.seek(0)
# remove status-prefixed lines
- lines = filter(lambda x: x[0:len(__comment_prefix)] != __comment_prefix,
- f.readlines())
+ lines = f.readlines()
+
+ patch_filter = FilterUntil()
+ until_test = lambda t: t == (__patch_prefix + '\n')
+ lines = [l for l in lines if patch_filter(l, until_test, __comment_prefix)]
+
# remove empty lines at the end
while len(lines) != 0 and lines[-1] == '\n':
del lines[-1]
# remove empty lines at the end
while len(lines) != 0 and lines[-1] == '\n':
del lines[-1]
f.seek(0); f.truncate()
f.writelines(lines)
f.seek(0); f.truncate()
f.writelines(lines)
-def edit_file(string, comment):
+def edit_file(series, string, comment, show_patch = True):
fname = '.stgit.msg'
tmpl = os.path.join(git.base_dir, 'patchdescr.tmpl')
fname = '.stgit.msg'
tmpl = os.path.join(git.base_dir, 'patchdescr.tmpl')
% __comment_prefix
print >> f, __comment_prefix, \
'Trailing empty lines will be automatically removed.'
% __comment_prefix
print >> f, __comment_prefix, \
'Trailing empty lines will be automatically removed.'
+
+ if show_patch:
+ print >> f, __patch_prefix
+ # series.get_patch(series.get_current()).get_top()
+ git.diff([], series.get_patch(series.get_current()).get_bottom(), None, f)
+
+ #Vim modeline must be near the end.
+ print >> f, __comment_prefix, 'vi: set textwidth=75 filetype=diff:'
create_empty_file(self.__unapplied_file)
self.__begin_stack_check()
create_empty_file(self.__unapplied_file)
self.__begin_stack_check()
- def refresh_patch(self, message = None, edit = False, cache_update = True,
+ def refresh_patch(self, message = None, edit = False, show_patch = False,
+ cache_update = True,
author_name = None, author_email = None,
author_date = None,
committer_name = None, committer_email = None,
author_name = None, author_email = None,
author_date = None,
committer_name = None, committer_email = None,
descr = message
if not message and edit:
descr = message
if not message and edit:
- descr = edit_file(descr.rstrip(), \
+ descr = edit_file(self, descr.rstrip(), \
'Please edit the description for patch "%s" ' \
'Please edit the description for patch "%s" ' \
+ 'above.' % name, show_patch)
if not author_name:
author_name = patch.get_authname()
if not author_name:
author_name = patch.get_authname()
- def new_patch(self, name, message = None, edit = False,
+ def new_patch(self, name, message = None, edit = False, show_patch = False,
author_name = None, author_email = None, author_date = None,
committer_name = None, committer_email = None):
"""Creates a new patch
author_name = None, author_email = None, author_date = None,
committer_name = None, committer_email = None):
"""Creates a new patch
raise StackException, 'Patch "%s" already exists' % name
if not message:
raise StackException, 'Patch "%s" already exists' % name
if not message:
- descr = edit_file(None, \
+ descr = edit_file(self, None, \
'Please enter the description for patch "%s" ' \
'Please enter the description for patch "%s" ' \
+ 'above.' % name, show_patch)