# HG changeset patch # User Brendan Cully # Date 1155666530 25200 # Node ID b70740aefa4df12bd0c86d7093c39c139171ba82 # Parent 68cea0b8f992b6ad275844277f35e21a5b5fed7c Unify mq and hg patch invocation. This makes patch a little less verbose by default, so the tests had to be updated. diff -r 68cea0b8f992 -r b70740aefa4d hgext/mq.py --- a/hgext/mq.py Tue Aug 15 11:43:31 2006 -0700 +++ b/hgext/mq.py Tue Aug 15 11:28:50 2006 -0700 @@ -400,39 +400,15 @@ '''Apply patchfile to the working directory. patchfile: file name of patch''' try: - pp = util.find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') - f = os.popen("%s -d %s -p1 --no-backup-if-mismatch < %s" % - (pp, util.shellquote(repo.root), util.shellquote(patchfile))) - except: - self.ui.warn("patch failed, unable to continue (try -v)\n") - return (None, [], False) - files = [] - fuzz = False - for l in f: - l = l.rstrip('\r\n'); - if self.ui.verbose: - self.ui.warn(l + "\n") - if l[:14] == 'patching file ': - pf = os.path.normpath(util.parse_patch_output(l)) - if pf not in files: - files.append(pf) - printed_file = False - file_str = l - elif l.find('with fuzz') >= 0: - if not printed_file: - self.ui.warn(file_str + '\n') - printed_file = True - self.ui.warn(l + '\n') - fuzz = True - elif l.find('saving rejects to file') >= 0: - self.ui.warn(l + '\n') - elif l.find('FAILED') >= 0: - if not printed_file: - self.ui.warn(file_str + '\n') - printed_file = True - self.ui.warn(l + '\n') + (files, fuzz) = patch.patch(patchfile, self.ui, strip=1, + cwd=repo.root) + 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 (not f.close(), files, fuzz) + return (True, files.keys(), fuzz) def apply(self, repo, series, list=False, update_status=True, strict=False, patchdir=None, merge=None, wlock=None): diff -r 68cea0b8f992 -r b70740aefa4d mercurial/commands.py --- a/mercurial/commands.py Tue Aug 15 11:43:31 2006 -0700 +++ b/mercurial/commands.py Tue Aug 15 11:28:50 2006 -0700 @@ -1681,7 +1681,7 @@ message = None ui.debug(_('message:\n%s\n') % message) - files = patch.patch(strip, tmpname, ui, cwd=repo.root) + files, fuzz = patch.patch(tmpname, ui, strip=strip, cwd=repo.root) removes = [] if len(files) > 0: cfiles = files.keys() diff -r 68cea0b8f992 -r b70740aefa4d mercurial/patch.py --- a/mercurial/patch.py Tue Aug 15 11:43:31 2006 -0700 +++ b/mercurial/patch.py Tue Aug 15 11:28:50 2006 -0700 @@ -215,13 +215,14 @@ tmpfp.close() return patchname -def patch(strip, patchname, ui, cwd=None): +def patch(patchname, ui, strip=1, cwd=None): """apply the patch to the working directory. a list of patched files is returned""" (dopatch, gitpatches) = readgitpatch(patchname) files = {} + fuzz = False if dopatch: if dopatch == 'filter': patchname = dogitpatch(patchname, gitpatches) @@ -237,10 +238,25 @@ for line in fp: line = line.rstrip() - ui.status("%s\n" % line) + ui.note(line + '\n') if line.startswith('patching file '): pf = util.parse_patch_output(line) + printed_file = False files.setdefault(pf, (None, None)) + elif line.find('with fuzz') >= 0: + fuzz = True + if not printed_file: + ui.warn(pf + '\n') + printed_file = True + ui.warn(line + '\n') + elif line.find('saving rejects to file') >= 0: + ui.warn(line + '\n') + elif line.find('FAILED') >= 0: + if not printed_file: + ui.warn(pf + '\n') + printed_file = True + ui.warn(line + '\n') + code = fp.close() if code: raise util.Abort(_("patch command failed: %s") % @@ -249,7 +265,7 @@ for gp in gitpatches: files[gp.path] = (gp.op, gp) - return files + return (files, fuzz) def diff(repo, node1=None, node2=None, files=None, match=util.always, fp=None, changes=None, opts=None): diff -r 68cea0b8f992 -r b70740aefa4d tests/test-git-import.out --- a/tests/test-git-import.out Tue Aug 15 11:43:31 2006 -0700 +++ b/tests/test-git-import.out Tue Aug 15 11:28:50 2006 -0700 @@ -1,6 +1,5 @@ % new file applying patch from stdin -patching file new % chmod +x applying patch from stdin % copy @@ -14,15 +13,12 @@ rename % delete applying patch from stdin -patching file copyx new rename % regular diff applying patch from stdin -patching file rename % copy and modify applying patch from stdin -patching file copy2 a a b @@ -30,7 +26,6 @@ a % rename and modify applying patch from stdin -patching file rename2 copy2: No such file or directory a a diff -r 68cea0b8f992 -r b70740aefa4d tests/test-import.out --- a/tests/test-import.out Tue Aug 15 11:43:31 2006 -0700 +++ b/tests/test-import.out Tue Aug 15 11:28:50 2006 -0700 @@ -8,7 +8,6 @@ added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying ../tip.patch -patching file a % message should be same summary: second change % committer should be same @@ -21,7 +20,6 @@ added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying ../tip.patch -patching file a transaction abort! rollback completed % import of plain diff should be ok with message @@ -32,7 +30,6 @@ added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying ../tip.patch -patching file a % import from stdin requesting all changes adding changesets @@ -41,7 +38,6 @@ added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying patch from stdin -patching file a % override commit message requesting all changes adding changesets @@ -50,7 +46,6 @@ added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying patch from stdin -patching file a summary: override % plain diff in email, subject, message body requesting all changes @@ -60,7 +55,6 @@ added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying ../msg.patch -patching file a user: email patcher summary: email patch % plain diff in email, no subject, message body @@ -71,7 +65,6 @@ added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying patch from stdin -patching file a % plain diff in email, subject, no message body requesting all changes adding changesets @@ -80,7 +73,6 @@ added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying patch from stdin -patching file a % plain diff in email, no subject, no message body, should fail requesting all changes adding changesets @@ -89,7 +81,6 @@ added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying patch from stdin -patching file a transaction abort! rollback completed % hg export in email, should use patch header @@ -100,7 +91,6 @@ added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying patch from stdin -patching file a summary: second change % hg import in a subdirectory requesting all changes @@ -110,7 +100,6 @@ added 1 changesets with 2 changes to 2 files 2 files updated, 0 files merged, 0 files removed, 0 files unresolved applying ../../../tip.patch -patching file a % message should be 'subdir change' summary: subdir change % committer should be 'someoneelse'