diff mercurial/commands.py @ 1190:737f9b90c571

Make import command reject patches that resemble email messages. See changeset 120aa5fc7ced1bf765b4f025f5a3a138cd87f49e for an example of why this is a good idea.
author bos@serpentine.internal.keyresearch.com
date Thu, 01 Sep 2005 09:04:18 -0700
parents 4cbcc54695b2
children 77a0c7528c2f
line wrap: on
line diff
--- a/mercurial/commands.py	Thu Sep 01 08:01:10 2005 -0700
+++ b/mercurial/commands.py	Thu Sep 01 09:04:18 2005 -0700
@@ -1009,6 +1009,8 @@
     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 @@
         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 @@
         (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')],