[PATCH 2 of 2] patch: return list of modified files even when an exception is raised
Brendan Cully
brendan at kublai.com
Tue Oct 17 18:41:30 UTC 2006
# HG changeset patch
# User Brendan Cully <brendan at kublai.com>
# Date 1161110385 25200
# Node ID 8f0f4be6b0419dcbf9269c7d518d4e67ab4748ed
# Parent 5b3eef875afe8469ba15168ea123c02faa96eef2
patch: return list of modified files even when an exception is raised
The file list is passed in as an argument and updated in place.
This fixes issue399.
diff -r 5b3eef875afe -r 8f0f4be6b041 hgext/mq.py
--- a/hgext/mq.py Tue Oct 17 11:36:20 2006 -0700
+++ b/hgext/mq.py Tue Oct 17 11:39:45 2006 -0700
@@ -408,14 +408,15 @@ class queue:
def patch(self, repo, patchfile):
'''Apply patchfile to the working directory.
patchfile: file name of patch'''
+ files = {}
try:
- (files, fuzz) = patch.patch(patchfile, self.ui, strip=1,
- cwd=repo.root)
+ fuzz = patch.patch(patchfile, self.ui, strip=1, cwd=repo.root,
+ files=files)
except Exception, inst:
self.ui.note(str(inst) + '\n')
if not self.ui.verbose:
self.ui.warn("patch failed, unable to continue (try -v)\n")
- return (False, [], False)
+ return (False, files, False)
return (True, files, fuzz)
diff -r 5b3eef875afe -r 8f0f4be6b041 mercurial/commands.py
--- a/mercurial/commands.py Tue Oct 17 11:36:20 2006 -0700
+++ b/mercurial/commands.py Tue Oct 17 11:39:45 2006 -0700
@@ -1640,8 +1640,12 @@ def import_(ui, repo, patch1, *patches,
message = None
ui.debug(_('message:\n%s\n') % message)
- files, fuzz = patch.patch(tmpname, ui, strip=strip, cwd=repo.root)
- files = patch.updatedir(ui, repo, files, wlock=wlock)
+ files = {}
+ try:
+ fuzz = patch.patch(tmpname, ui, strip=strip, cwd=repo.root,
+ files=files)
+ finally:
+ files = patch.updatedir(ui, repo, files, wlock=wlock)
repo.commit(files, message, user, date, wlock=wlock, lock=lock)
finally:
os.unlink(tmpname)
diff -r 5b3eef875afe -r 8f0f4be6b041 mercurial/patch.py
--- a/mercurial/patch.py Tue Oct 17 11:36:20 2006 -0700
+++ b/mercurial/patch.py Tue Oct 17 11:39:45 2006 -0700
@@ -266,14 +266,13 @@ def dogitpatch(patchname, gitpatches, cw
tmpfp.close()
return patchname
-def patch(patchname, ui, strip=1, cwd=None):
+def patch(patchname, ui, strip=1, cwd=None, files={}):
"""apply the patch <patchname> to the working directory.
a list of patched files is returned"""
# helper function
def __patch(patchname):
"""patch and updates the files and fuzz variables"""
- files = {}
fuzz = False
patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''),
@@ -308,25 +307,24 @@ def patch(patchname, ui, strip=1, cwd=No
if code:
raise util.Abort(_("patch command failed: %s") %
util.explain_exit(code)[0])
- return files, fuzz
+ return fuzz
(dopatch, gitpatches) = readgitpatch(patchname)
-
- files, fuzz = {}, False
+ for gp in gitpatches:
+ files[gp.path] = (gp.op, gp)
+
+ fuzz = False
if dopatch:
if dopatch in ('filter', 'binary'):
patchname = dogitpatch(patchname, gitpatches, cwd=cwd)
try:
if dopatch != 'binary':
- files, fuzz = __patch(patchname)
+ fuzz = __patch(patchname)
finally:
if dopatch == 'filter':
os.unlink(patchname)
- for gp in gitpatches:
- files[gp.path] = (gp.op, gp)
-
- return (files, fuzz)
+ return fuzz
def diffopts(ui, opts={}):
return mdiff.diffopts(
More information about the Mercurial-devel
mailing list