[PATCH] mq: recognize the context format diff header when importing

Jozef Hatala jh-mercurial at skrt.org
Mon Feb 15 01:10:07 CST 2010


Hello there.

mq.py's patchheader looks for the beginning of the actual patch and if
the patch is in the "context diff" format as opposed to the "unified
diff" format, patchheader does not find it and concludes that the patch
is empty when you qpush it.

The patch below makes patchheader recognize the '***'/'---' sequence in
addition to the usual '---'/'+++' sequence.

What do you think?

jh

Also pullable from http://bitbucket.org/jhatala/mercurial-temp/


# HG changeset patch
# User Jozef Hatala <jh-mercurial at skrt.org>
# Date 1266212559 28800
# Node ID 0898b9472dfe6121241de7ac3504423cf57d87e5
# Parent  ed4de30e16c5b6efb67a2a5edabb424cd4deda7d
mq: recognize the context format diff header when importing

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -103,10 +103,15 @@
             if diffstart:
                 if line.startswith('+++ '):
                     diffstart = 2
+                if line.startswith('--- '):
+                    diffstart = 2
                 break
             if line.startswith("--- "):
                 diffstart = 1
                 continue
+            elif line.startswith("*** "):
+                diffstart = 1
+                continue
             elif format == "hgpatch":
                 # parse values when importing the result of an hg export
                 if line.startswith("# User "):
diff --git a/tests/test-mq-qimport-contextdiff b/tests/test-mq-qimport-contextdiff
new file mode 100755
--- /dev/null
+++ b/tests/test-mq-qimport-contextdiff
@@ -0,0 +1,107 @@
+#!/bin/sh
+
+echo "[extensions]" >> $HGRCPATH
+echo "mq=" >> $HGRCPATH
+
+hg init repo
+cd repo
+
+# Source: http://en.wikipedia.org/wiki/Diff
+
+cat > text <<EOF
+This part of the
+document has stayed the
+same from version to
+version.  It shouldn't
+be shown if it doesn't
+change.  Otherwise, that
+would not be helping to
+compress the size of the
+changes.
+
+This paragraph contains
+text that is outdated.
+It will be deleted in the
+near future.
+
+It is important to spell
+check this dokument. On
+the other hand, a
+misspelled word isn't
+the end of the world.
+Nothing in the rest of
+this paragraph needs to
+be changed. Things can
+be added after it.
+EOF
+
+hg add text
+hg ci -u 'author1 at example.org' -d '0 0' -m 'Initial' text
+hg qinit
+
+cat > the.patch <<EOF
+From: Author2 <author2 at example.org>
+Date: Fri, 02 Jan 1970 00:00:00 +0000
+
+The description of the change
+
+*** a/text	2010-02-14 21:16:25.000000000 -0800
+--- b/text	2010-02-14 21:14:48.000000000 -0800
+***************
+*** 1,3 ****
+--- 1,9 ----
++ This is an important
++ notice! It should
++ therefore be located at
++ the beginning of this
++ document!
++ 
+  This part of the
+  document has stayed the
+  same from version to
+***************
+*** 5,20 ****
+  be shown if it doesn't
+  change.  Otherwise, that
+  would not be helping to
+! compress the size of the
+! changes.
+! 
+! This paragraph contains
+! text that is outdated.
+! It will be deleted in the
+! near future.
+  
+  It is important to spell
+! check this dokument. On
+  the other hand, a
+  misspelled word isn't
+  the end of the world.
+--- 11,20 ----
+  be shown if it doesn't
+  change.  Otherwise, that
+  would not be helping to
+! compress anything.
+  
+  It is important to spell
+! check this document. On
+  the other hand, a
+  misspelled word isn't
+  the end of the world.
+***************
+*** 22,24 ****
+--- 22,28 ----
+  this paragraph needs to
+  be changed. Things can
+  be added after it.
++ 
++ This paragraph contains
++ important new additions
++ to this document.
+EOF
+
+echo % qimport --push the.patch
+hg qimport --push the.patch
+
+echo % tip -p
+hg tip -p
diff --git a/tests/test-mq-qimport-contextdiff.out b/tests/test-mq-qimport-contextdiff.out
new file mode 100644
--- /dev/null
+++ b/tests/test-mq-qimport-contextdiff.out
@@ -0,0 +1,55 @@
+% qimport --push the.patch
+adding the.patch to series file
+applying the.patch
+now at: the.patch
+% tip -p
+changeset:   1:ddf319cf5261
+tag:         the.patch
+tag:         qtip
+tag:         tip
+tag:         qbase
+user:        Author2 <author2 at example.org>
+date:        Fri Jan 02 00:00:00 1970 +0000
+summary:     The description of the change
+
+diff -r c00f0610048a -r ddf319cf5261 text
+--- a/text	Thu Jan 01 00:00:00 1970 +0000
++++ b/text	Fri Jan 02 00:00:00 1970 +0000
+@@ -1,3 +1,9 @@
++This is an important
++notice! It should
++therefore be located at
++the beginning of this
++document!
++
+ This part of the
+ document has stayed the
+ same from version to
+@@ -5,16 +11,10 @@
+ be shown if it doesn't
+ change.  Otherwise, that
+ would not be helping to
+-compress the size of the
+-changes.
+-
+-This paragraph contains
+-text that is outdated.
+-It will be deleted in the
+-near future.
++compress anything.
+ 
+ It is important to spell
+-check this dokument. On
++check this document. On
+ the other hand, a
+ misspelled word isn't
+ the end of the world.
+@@ -22,3 +22,7 @@
+ this paragraph needs to
+ be changed. Things can
+ be added after it.
++
++This paragraph contains
++important new additions
++to this document.
+


More information about the Mercurial-devel mailing list