out.info('Ignoring already applied patch "%s"' % patch)
return
if options.replace and patch in crt_series.get_unapplied():
- crt_series.delete_patch(patch)
+ crt_series.delete_patch(patch, keep_log = True)
# refresh_patch() will invoke the editor in this case, with correct
# patch content
else:
out.start('Importing patch "%s"' % patch)
if options.base:
- git.apply_patch(diff = diff, base = git_id(options.base))
+ git.apply_patch(diff = diff,
+ base = git_id(crt_series, options.base))
else:
git.apply_patch(diff = diff)
crt_series.refresh_patch(edit = options.edit,
show_patch = options.showpatch,
- sign_str = options.sign_str)
+ sign_str = options.sign_str,
+ backup = False)
out.done()
+def __mkpatchname(name, suffix):
+ if name.lower().endswith(suffix.lower()):
+ return name[:-len(suffix)]
+ return name
+
+def __get_handle_and_name(filename):
+ """Return a file object and a patch name derived from filename
+ """
+ # see if it's a gzip'ed or bzip2'ed patch
+ import bz2, gzip
+ for copen, ext in [(gzip.open, '.gz'), (bz2.BZ2File, '.bz2')]:
+ try:
+ f = copen(filename)
+ f.read(1)
+ f.seek(0)
+ return (f, __mkpatchname(filename, ext))
+ except IOError, e:
+ pass
+
+ # plain old file...
+ return (open(filename), filename)
+
def __import_file(filename, options, patch = None):
"""Import a patch from a file or standard input
"""
+ pname = None
if filename:
- f = file(filename)
+ (f, pname) = __get_handle_and_name(filename)
else:
f = sys.stdin
+ if patch:
+ pname = patch
+ elif not pname:
+ pname = filename
+
if options.mail:
try:
msg = email.message_from_file(f)
parse_mail(msg)
else:
message, author_name, author_email, author_date, diff = \
- parse_patch(f)
+ parse_patch(f.read())
if filename:
f.close()
- if patch:
- pname = patch
- else:
- pname = filename
-
__create_patch(pname, message, author_name, author_email,
author_date, diff, options)
check_local_changes()
check_conflicts()
- check_head_top_equal()
+ check_head_top_equal(crt_series)
if len(args) == 1:
filename = args[0]
else:
__import_file(filename, options)
- print_crt_patch()
+ print_crt_patch(crt_series)