Mercurial > public > mercurial-scm > hg-stable
diff mercurial/cmdutil.py @ 21553:bee0e1cffdd3
import: add --partial flag to create a changeset despite failed hunks
The `hg import` command gains a `--partial` flag. When specified, a commit will
always be created from a patch import. Any hunk that fails to apply will
create .rej file, same as what `hg qimport` would do. This change is mainly
aimed at preserving changeset metadata when applying a patch, something very
important for reviewers.
In case of failure with `--partial`, `hg import` returns 1 and the following
message is displayed:
patch applied partially
(fix the .rej files and run `hg commit --amend`)
When multiple patches are imported, we stop at the first one with failed hunks.
In the future, someone may feel brave enough to tackle a --continue flag to
import.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Thu, 08 May 2014 17:08:17 -0700 |
parents | 272785489ed3 |
children | 404ff404db79 |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Mon May 19 01:53:34 2014 +0200 +++ b/mercurial/cmdutil.py Thu May 08 17:08:17 2014 -0700 @@ -591,9 +591,11 @@ strip = opts["strip"] sim = float(opts.get('similarity') or 0) if not tmpname: - return (None, None) + return (None, None, False) msg = _('applied to working directory') + rejects = False + try: cmdline_message = logmessage(ui, opts) if cmdline_message: @@ -639,9 +641,17 @@ if opts.get('exact') or opts.get('import_branch'): repo.dirstate.setbranch(branch or 'default') + partial = opts.get('partial', False) files = set() - patch.patch(ui, repo, tmpname, strip=strip, files=files, - eolmode=None, similarity=sim / 100.0) + try: + patch.patch(ui, repo, tmpname, strip=strip, files=files, + eolmode=None, similarity=sim / 100.0) + except patch.PatchError, e: + if not partial: + raise util.Abort(str(e)) + if partial: + rejects = True + files = list(files) if opts.get('no_commit'): if message: @@ -656,7 +666,7 @@ m = scmutil.matchfiles(repo, files or []) n = repo.commit(message, opts.get('user') or user, opts.get('date') or date, match=m, - editor=editor) + editor=editor, force=partial) else: if opts.get('exact') or opts.get('import_branch'): branch = branch or 'default' @@ -684,7 +694,7 @@ if n: # i18n: refers to a short changeset id msg = _('created %s') % short(n) - return (msg, n) + return (msg, n, rejects) finally: os.unlink(tmpname)