# HG changeset patch # User bos@serpentine.internal.keyresearch.com # Date 1125590658 25200 # Node ID 737f9b90c571b3991f7e35dc846e7ef38a475cfe # Parent 4cbcc54695b201c06e140e22cbc5b00850af6811 Make import command reject patches that resemble email messages. See changeset 120aa5fc7ced1bf765b4f025f5a3a138cd87f49e for an example of why this is a good idea. diff --git a/doc/hg.1.txt b/doc/hg.1.txt --- a/doc/hg.1.txt +++ b/doc/hg.1.txt @@ -251,11 +251,18 @@ identify:: import [-p -b -f] :: Import a list of patches and commit them individually. + If a patch looks like a mail message (its first line starts with + "From " or looks like an RFC822 header), it will not be applied + unless the -m option is used. The importer neither parses nor + discards mail headers, so use -m only to override the "mailness" + safety check, not to import a real mail message. + options: -p, --strip directory strip option for patch. This has the same meaning as the corresponding patch option -b base directory to read patches from -f, --force skip check for outstanding uncommitted changes + -m, --mail-like apply a patch that appears to be a mail message aliases: patch diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1009,6 +1009,8 @@ def import_(ui, repo, patch1, *patches, d = opts["base"] strip = opts["strip"] + mailre = re.compile(r'(From |[\w-]+:)') + for patch in patches: ui.status("applying %s\n" % patch) pf = os.path.join(d, patch) @@ -1018,6 +1020,10 @@ def import_(ui, repo, patch1, *patches, hgpatch = False for line in file(pf): line = line.rstrip() + if not message and mailre.match(line) and not opts['mail_like']: + if len(line) > 35: line = line[:32] + '...' + raise util.Abort('first line looks like a ' + 'mail header: ' + line) if line.startswith("--- ") or line.startswith("diff -r"): break elif hgpatch: @@ -1662,7 +1668,8 @@ table = { (import_, [('p', 'strip', 1, 'path strip'), ('f', 'force', None, 'skip check for outstanding changes'), - ('b', 'base', "", 'base path')], + ('b', 'base', "", 'base path'), + ('m', 'mail-like', None, 'apply a patch that looks like email')], "hg import [-f] [-p NUM] [-b BASE] PATCH..."), "incoming|in": (incoming, [('p', 'patch', None, 'show patch')],