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 patchB
# 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 patchC patchA
# 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 patchC
# 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 patchC
abort: branch patchC 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/
patchA.diff
patchB.diff
patchC.diff
series
$ cat .hg/patches/series
patchA.diff
patchB.diff
patchC.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
patchA.diff
patchB.diff
patchC.diff
$ hg qpush -a
applying patchA.diff
applying patchB.diff
applying patchC.diff
now at: patchC.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 patchC
# 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