[PATCH 2 of 2] mq: import a unified or context diff that does not start with "diff -"

Jozef Hatala jh-mercurial at skrt.org
Sun Feb 28 02:39:17 CST 2010


# HG changeset patch
# User Jozef Hatala <jh-mercurial at skrt.org>
# Date 1267344626 28800
# Node ID 735c3205de25296fb9ecf00dbea2059adb763098
# Parent  75b027298f0588e698d6099f8588c1296e586f9d
mq: import a unified or context diff that does not start with "diff -"

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -98,6 +98,8 @@
         def notdiffline(s):
             return not (s.startswith("diff -") or
                         s.startswith("Index:") or
+                        s.startswith("--- ") or
+                        s.startswith("*** ") or
                         s.startswith("==========="))
         pf = file(pf)
         rawh = ''.join((itertools.takewhile(notdiffline, pf))).strip().splitlines()
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.
+
diff --git a/tests/test-mq-qimport-minheader b/tests/test-mq-qimport-minheader
new file mode 100755
--- /dev/null
+++ b/tests/test-mq-qimport-minheader
@@ -0,0 +1,94 @@
+#!/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	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.
+
+EOF
+
+echo % qimport --push the.patch
+hg qimport --push the.patch
+
+echo % tip -p
+hg tip -p
diff --git a/tests/test-mq-qimport-minheader.out b/tests/test-mq-qimport-minheader.out
new file mode 100644
--- /dev/null
+++ b/tests/test-mq-qimport-minheader.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