Commits

Patrick Mézard  committed e9e705b

Fix standalone patches parsing, add test

  • Participants
  • Parent commits b816dc9

Comments (0)

Files changed (5)

 class mboxerror(Exception):
     pass
 
-re_patch = re.compile(r'^\s*\[PATCH\s+(?:(\d+)\s+of\s+(\d+))\]\s*(.+)$')
+re_patch = re.compile(r'^\s*\[PATCH(?:\s+(\d+)\s+of\s+(\d+))?\]\s*(.+)$')
 
 def parsesubject(s):
     s = s.replace('\n\t', ' ')
     try:
         index = int(m.group(1))
         count = int(m.group(2)) + 1
-    except IndexError:
+    except (TypeError, IndexError):
         index = 0
         count = 1
     if count < 1:
+#!/bin/sh
+
+echo "[ui]"             >> $HGRCPATH
+echo "interactive=true" >> $HGRCPATH
+echo "[mbox]"           >> $HGRCPATH
+echo "paths=$TESTDIR/tests/test.mbx" >> $HGRCPATH
+echo "[extensions]"     >> $HGRCPATH
+echo "mbox="            >> $HGRCPATH
+
+echo "% help (no mq, so no mimport)"
+hg help mimport | grep "hg mimport"
+
+echo "mq="              >> $HGRCPATH
+
+echo "% help (mq present)"
+hg help mimport | grep "hg mimport"
+
+hg init repo
+cd repo
+
+echo % mimport everything
+hg mimport <<EOF
+i
+EOF
+

File test-mbox.out

+% help (no mq, so no mimport)
+hg: unknown command 'mimport'
+% help (mq present)
+hg mimport PATTERN...
+% mimport everything
+[PATCH] test diff
+skip this group [Yidq?]  adding test_diff to series file
+1 patches imported

File tests/makembox.py

+#!/usr/bin/env python
+#
+# Run this script to generate the mbox test sample
+#
+import email, mailbox
+
+mbox = mailbox.mbox('test.mbx')
+
+msg = """\
+Delivered-To: foobar@gmail.com
+Received: by 10.114.108.3 with SMTP id g3cs509927wac;
+        Mon, 29 Dec 2008 17:13:30 -0800 (PST)
+MIME-Version: 1.0
+Subject: [PATCH] test diff
+Message-Id: <5ab3c4562bd574dbd782.1230599538@localhost>
+Date: Tue, 30 Dec 2008 02:12:18 +0100
+From: Bar Baz <barbaz@gmail.com>
+To: mercurial-devel@selenic.com
+Content-Type: text/plain; charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+Sender: mercurial-devel-bounces@selenic.com
+
+# HG changeset patch
+# User Bar Baz <barbaz@gmail.com>
+# Date 1230599487 -3600
+# Node ID 5ab3c4562bd574dbd7820a662cdb6b06eae241e8
+# Parent  4949729ee9ee5f1e22d1212c557bed3ecc6ff5d3
+test diff
+
+diff --git a/a b/a
+new file mode 100644
+--- /dev/null
++++ b/a
+@@ -0,0 +1,1 @@
++a
+
+_______________________________________________
+Mercurial-devel mailing list
+Mercurial-devel@selenic.com
+http://selenic.com/mailman/listinfo/mercurial-devel
+"""
+
+mbox.add(email.message_from_string(msg))
+mbox.close()

File tests/test.mbx

+From MAILER-DAEMON Fri Jan  2 15:41:44 2009
+
+Delivered-To: foobar@gmail.com
+Received: by 10.114.108.3 with SMTP id g3cs509927wac;
+        Mon, 29 Dec 2008 17:13:30 -0800 (PST)
+MIME-Version: 1.0
+Subject: [PATCH] test diff
+Message-Id: <5ab3c4562bd574dbd782.1230599538@localhost>
+Date: Tue, 30 Dec 2008 02:12:18 +0100
+From: Bar Baz <barbaz@gmail.com>
+To: mercurial-devel@selenic.com
+Content-Type: text/plain; charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+Sender: mercurial-devel-bounces@selenic.com
+
+# HG changeset patch
+# User Bar Baz <barbaz@gmail.com>
+# Date 1230599487 -3600
+# Node ID 5ab3c4562bd574dbd7820a662cdb6b06eae241e8
+# Parent  4949729ee9ee5f1e22d1212c557bed3ecc6ff5d3
+test diff
+
+diff --git a/a b/a
+new file mode 100644
+--- /dev/null
++++ b/a
+@@ -0,0 +1,1 @@
++a
+
+_______________________________________________
+Mercurial-devel mailing list
+Mercurial-devel@selenic.com
+http://selenic.com/mailman/listinfo/mercurial-devel
+
+From MAILER-DAEMON Fri Jan  2 15:51:21 2009
+Delivered-To: foobar@gmail.com
+Received: by 10.114.108.3 with SMTP id g3cs509927wac;
+        Mon, 29 Dec 2008 17:13:30 -0800 (PST)
+MIME-Version: 1.0
+Subject: [PATCH] test diff
+Message-Id: <5ab3c4562bd574dbd782.1230599538@localhost>
+Date: Tue, 30 Dec 2008 02:12:18 +0100
+From: Bar Baz <barbaz@gmail.com>
+To: mercurial-devel@selenic.com
+Content-Type: text/plain; charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+Sender: mercurial-devel-bounces@selenic.com
+
+# HG changeset patch
+# User Bar Baz <barbaz@gmail.com>
+# Date 1230599487 -3600
+# Node ID 5ab3c4562bd574dbd7820a662cdb6b06eae241e8
+# Parent  4949729ee9ee5f1e22d1212c557bed3ecc6ff5d3
+test diff
+
+diff --git a/a b/a
+new file mode 100644
+--- /dev/null
++++ b/a
+@@ -0,0 +1,1 @@
++a
+
+_______________________________________________
+Mercurial-devel mailing list
+Mercurial-devel@selenic.com
+http://selenic.com/mailman/listinfo/mercurial-devel