Submitting Patches by Email

Email a Single Patch

When a patch is ready for submission, we can send it on by email with ease. This is basically the same as the patchbomb extension (hg email), but for patch branches. In this script I don’t actually send the email, so I specify the --test option:

$ cd patches
hg pemail
$ hg pemail --test --from john@example.com --to jane@example.com patch-A
This patch series consists of 1 patches.


Displaying [PATCH] a nifty patch ...
Content-Type: text/plain; charset="us-ascii" 
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [PATCH] a nifty patch
X-Mercurial-Node:
Message-Id: <patchbomb.1262012973@sapient>
User-Agent: Mercurial-patchbomb/1.3.1+452-31ec469f9b55
Date: Mon, 28 Dec 2009 16:09:33 +0100
From: john@example.com
To: jane@example.com

# 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

Email Multiple Patches

When sending multiple patches, we need a subject and body for the introductory message for the series. This adds more clutter to the pemail command. To highlight the relevant parts of the command in the following samples, I have factored out the mail formatting and addressing options:

$ cat >maildesc <<-eof
    This is the patch series description.
eof
$ cat >mailopts <<-eof
    --test --from john@example.com --to jane@example.com --subject "Intro" --desc maildesc
eof

Patch Series

To send a patch series, we can specify just the head patches in the patch graph. Then pbranch will email them and all their dependencies in topological order, meaning base patches are sent before dependent patches:

hg pemail—with-deps
$ hg pemail $(cat mailopts) --with-deps patch-B
This patch series consists of 2 patches.


Displaying [PATCH 0 of 2] "Intro" ...
Content-Type: text/plain; charset="us-ascii" 
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [PATCH 0 of 2] "Intro" 
Message-Id: <patchbomb.1262012973@sapient>
User-Agent: Mercurial-patchbomb/1.3.1+452-31ec469f9b55
Date: Mon, 28 Dec 2009 16:09:33 +0100
From: john@example.com
To: jane@example.com

This is the patch series description.

Displaying [PATCH 1 of 2] a nifty patch ...
Content-Type: text/plain; charset="us-ascii" 
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [PATCH 1 of 2] a nifty patch
X-Mercurial-Node:
Message-Id: <patchbomb.1262012974@sapient>
In-Reply-To: <patchbomb.1262012973@sapient>
References: <patchbomb.1262012973@sapient>
User-Agent: Mercurial-patchbomb/1.3.1+452-31ec469f9b55
Date: Mon, 28 Dec 2009 16:09:34 +0100
From: john@example.com
To: jane@example.com

# 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
Displaying [PATCH 2 of 2] another patch ...
Content-Type: text/plain; charset="us-ascii" 
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [PATCH 2 of 2] another patch
X-Mercurial-Node:
Message-Id: <patchbomb.1262012975@sapient>
In-Reply-To: <patchbomb.1262012973@sapient>
References: <patchbomb.1262012973@sapient>
User-Agent: Mercurial-patchbomb/1.3.1+452-31ec469f9b55
Date: Mon, 28 Dec 2009 16:09:35 +0100
From: john@example.com
To: jane@example.com

# 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

Specified Patches In Specified Order

Finally, we can send multiple patches in arbitrary order by naming them all explicitly:

$ hg pemail $(cat mailopts) patch-A patch-B patch-C
This patch series consists of 3 patches.


Displaying [PATCH 0 of 3] "Intro" ...
Content-Type: text/plain; charset="us-ascii" 
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [PATCH 0 of 3] "Intro" 
Message-Id: <patchbomb.1262012973@sapient>
User-Agent: Mercurial-patchbomb/1.3.1+452-31ec469f9b55
Date: Mon, 28 Dec 2009 16:09:33 +0100
From: john@example.com
To: jane@example.com

This is the patch series description.

Displaying [PATCH 1 of 3] a nifty patch ...
Content-Type: text/plain; charset="us-ascii" 
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [PATCH 1 of 3] a nifty patch
X-Mercurial-Node:
Message-Id: <patchbomb.1262012974@sapient>
In-Reply-To: <patchbomb.1262012973@sapient>
References: <patchbomb.1262012973@sapient>
User-Agent: Mercurial-patchbomb/1.3.1+452-31ec469f9b55
Date: Mon, 28 Dec 2009 16:09:34 +0100
From: john@example.com
To: jane@example.com

# 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
Displaying [PATCH 2 of 3] another patch ...
Content-Type: text/plain; charset="us-ascii" 
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [PATCH 2 of 3] another patch
X-Mercurial-Node:
Message-Id: <patchbomb.1262012975@sapient>
In-Reply-To: <patchbomb.1262012973@sapient>
References: <patchbomb.1262012973@sapient>
User-Agent: Mercurial-patchbomb/1.3.1+452-31ec469f9b55
Date: Mon, 28 Dec 2009 16:09:35 +0100
From: john@example.com
To: jane@example.com

# 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
Displaying [PATCH 3 of 3] yet another patch ...
Content-Type: text/plain; charset="us-ascii" 
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [PATCH 3 of 3] yet another patch
X-Mercurial-Node:
Message-Id: <patchbomb.1262012976@sapient>
In-Reply-To: <patchbomb.1262012973@sapient>
References: <patchbomb.1262012973@sapient>
User-Agent: Mercurial-patchbomb/1.3.1+452-31ec469f9b55
Date: Mon, 28 Dec 2009 16:09:36 +0100
From: john@example.com
To: jane@example.com

# 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