# HG changeset patch # User Vadim Gelfer # Date 1154472673 25200 # Node ID e6bef16b6cec49a8c475a21fad3df6024edca502 # Parent 19436facb073450e8836ec35dea67a8b2d6a3bcc import: make patch apply if run in subdir fix is same as for mq patch. patch apply code should be merged. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1832,9 +1832,13 @@ def import_(ui, repo, patch1, *patches, if not diffs_seen: raise util.Abort(_('no diffs found')) - files = util.patch(strip, tmpname, ui) + files = util.patch(strip, tmpname, ui, cwd=repo.root) if len(files) > 0: - addremove_lock(ui, repo, files, {}) + cfiles = files + cwd = repo.getcwd() + if cwd: + cfiles = [util.pathto(cwd, f) for f in files] + addremove_lock(ui, repo, cfiles, {}) repo.commit(files, message, user, date) finally: os.unlink(tmpname) diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -93,11 +93,15 @@ def find_in_path(name, path, default=Non return p_name return default -def patch(strip, patchname, ui): +def patch(strip, patchname, ui, cwd=None): """apply the patch to the working directory. a list of patched files is returned""" patcher = find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') - fp = os.popen('%s -p%d < "%s"' % (patcher, strip, patchname)) + args = [] + if cwd: + args.append('-d "%s"' % cwd) + fp = os.popen('%s %s -p%d < "%s"' % (patcher, ' '.join(args), strip, + patchname)) files = {} for line in fp: line = line.rstrip()