Exporting Patches to Patch Queues (mq)

$ cd patches

Export to StdOut

Full Graph

By default, pexport lists all the diffs to stdout, base patches first:

hg pexport
$ hg pexport
# HG changeset patch
# User john
# Date 0 0
a nifty patch

diff --git a/file-from-A b/file-from-A
new file mode 100644
--- /dev/null
+++ b/file-from-A
@@ -0,0 +1,2 @@
+One
+Later
diff --git a/main-file-1 b/main-file-1
--- a/main-file-1
+++ b/main-file-1
@@ -1,1 +1,1 @@
-One
+Eins

# HG changeset patch
# User john
# Date 0 0
another patch

diff --git a/file-from-B b/file-from-B
new file mode 100644
--- /dev/null
+++ b/file-from-B
@@ -0,0 +1,1 @@
+Two
diff --git a/main-file-1 b/main-file-1
--- a/main-file-1
+++ b/main-file-1
@@ -3,1 +3,1 @@
-Two
+Zwei

# HG changeset patch
# User john
# Date 0 0
yet another patch

diff --git a/file-from-A b/file-from-A
--- a/file-from-A
+++ b/file-from-A
@@ -2,1 +2,1 @@
-Later
+EvenLater
diff --git a/file-from-C b/file-from-C
new file mode 100644
--- /dev/null
+++ b/file-from-C
@@ -0,0 +1,1 @@
+Three
diff --git a/main-file-1 b/main-file-1
--- a/main-file-1
+++ b/main-file-1
@@ -5,1 +5,1 @@
-Three
+Drei

Partial Graph

We can also export just patches plus their base patches:

$ hg pexport --with-deps patch-B
# HG changeset patch
# User john
# Date 0 0
a nifty patch

diff --git a/file-from-A b/file-from-A
new file mode 100644
--- /dev/null
+++ b/file-from-A
@@ -0,0 +1,2 @@
+One
+Later
diff --git a/main-file-1 b/main-file-1
--- a/main-file-1
+++ b/main-file-1
@@ -1,1 +1,1 @@
-One
+Eins

# HG changeset patch
# User john
# Date 0 0
another patch

diff --git a/file-from-B b/file-from-B
new file mode 100644
--- /dev/null
+++ b/file-from-B
@@ -0,0 +1,1 @@
+Two
diff --git a/main-file-1 b/main-file-1
--- a/main-file-1
+++ b/main-file-1
@@ -3,1 +3,1 @@
-Two
+Zwei

Individual Patches

Finally, we can export individial patches in the order given:

$ hg pexport patch-C patch-A
# HG changeset patch
# User john
# Date 0 0
yet another patch

diff --git a/file-from-A b/file-from-A
--- a/file-from-A
+++ b/file-from-A
@@ -2,1 +2,1 @@
-Later
+EvenLater
diff --git a/file-from-C b/file-from-C
new file mode 100644
--- /dev/null
+++ b/file-from-C
@@ -0,0 +1,1 @@
+Three
diff --git a/main-file-1 b/main-file-1
--- a/main-file-1
+++ b/main-file-1
@@ -5,1 +5,1 @@
-Three
+Drei

# HG changeset patch
# User john
# Date 0 0
a nifty patch

diff --git a/file-from-A b/file-from-A
new file mode 100644
--- /dev/null
+++ b/file-from-A
@@ -0,0 +1,2 @@
+One
+Later
diff --git a/main-file-1 b/main-file-1
--- a/main-file-1
+++ b/main-file-1
@@ -1,1 +1,1 @@
-One
+Eins

Specifying the Patch Graph

By default, pdiff, pexport, and pemail use the tip graph (--tips) to construct patch diffs. This means that for each patch branch foo, its patch diff is defined as the diff between the tip of branch foo and the revision identified by the node id recorded in .hgpatchinfo/foo.dep in foo’s tip (the last pmerge in foo put it there).

$ hg pexport patch-C
# HG changeset patch
# User john
# Date 0 0
yet another patch

diff --git a/file-from-A b/file-from-A
--- a/file-from-A
+++ b/file-from-A
@@ -2,1 +2,1 @@
-Later
+EvenLater
diff --git a/file-from-C b/file-from-C
new file mode 100644
--- /dev/null
+++ b/file-from-C
@@ -0,0 +1,1 @@
+Three
diff --git a/main-file-1 b/main-file-1
--- a/main-file-1
+++ b/main-file-1
@@ -5,1 +5,1 @@
-Three
+Drei

To see a patch or series precisely as it was at the time of a specific revision, use the --rev option. However, this may mean that a patch is not defined, because the given revision might not have any .dep files at all:

$ hg pexport --rev default patch-C
abort: branch patch-C is not in the patch graph (wrong --rev?)

Export to Patch Queues (mq)

A more useful way to export patches is to write patch queues. Each patch gets its own file, and there’s a series file listing the patches in the correct order (base patches first):

hg pexport—queue
$ hg pexport --queue --ext .diff
$ ls .hg/patches/
patch-A.diff
patch-B.diff
patch-C.diff
series
$ cat .hg/patches/series
patch-A.diff
patch-B.diff
patch-C.diff

We can use this to reimport them using mq:

$ cd ..
$ hg clone main import
updating to branch default
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cd import
$ cp -r ../patches/.hg/patches .hg/
$ hg qseries
patch-A.diff
patch-B.diff
patch-C.diff
$ hg qpush -a
applying patch-A.diff
applying patch-B.diff
applying patch-C.diff
now at: patch-C.diff
$ hg log
3    : yet another patch - john
2    : another patch - john
1    : a nifty patch - john
0    : base - john

Export From Outside Of Repo

Sometimes we wish to transfer patches from one repo to another, something like:

hg -R pexport the-patch | hg import -

So let’s quickly test out-of-repo exports:

$ cd ..
$ hg -R patches pexport patch-C
# HG changeset patch
# User john
# Date 0 0
yet another patch

diff --git a/file-from-A b/file-from-A
--- a/file-from-A
+++ b/file-from-A
@@ -2,1 +2,1 @@
-Later
+EvenLater
diff --git a/file-from-C b/file-from-C
new file mode 100644
--- /dev/null
+++ b/file-from-C
@@ -0,0 +1,1 @@
+Three
diff --git a/main-file-1 b/main-file-1
--- a/main-file-1
+++ b/main-file-1
@@ -5,1 +5,1 @@
-Three
+Drei
$ cd patches