(int)(email_end - email_start - 1), email_start + 1);
}
+static const char *clean_message_id(const char *msg_id)
+{
+ char ch;
+ const char *a, *z, *m;
+ char *n;
+ size_t len;
+
+ m = msg_id;
+ while ((ch = *m) && (isspace(ch) || (ch == '<')))
+ m++;
+ a = m;
+ z = NULL;
+ while ((ch = *m)) {
+ if (!isspace(ch) && (ch != '>'))
+ z = m;
+ m++;
+ }
+ if (!z)
+ die("insane in-reply-to: %s", msg_id);
+ if (++z == m)
+ return a;
+ len = z - a;
+ n = xmalloc(len + 1);
+ memcpy(n, a, len);
+ n[len] = 0;
+ return n;
+}
+
int cmd_format_patch(int argc, const char **argv, const char *prefix)
{
struct commit *commit;
}
if (rev.pending.nr == 1) {
- if (rev.max_count < 0) {
+ if (rev.max_count < 0 && !rev.show_root_diff) {
+ /*
+ * This is traditional behaviour of "git format-patch
+ * origin" that prepares what the origin side still
+ * does not have.
+ */
rev.pending.objects[0].item->flags |= UNINTERESTING;
add_head(&rev);
}
- /* Otherwise, it is "format-patch -22 HEAD", and
- * get_revision() would return only the specified count.
+ /*
+ * Otherwise, it is "format-patch -22 HEAD", and/or
+ * "format-patch --root HEAD". The user wants
+ * get_revision() to do the usual traversal.
*/
}
if (numbered)
rev.total = total + start_number - 1;
rev.add_signoff = add_signoff;
- rev.ref_message_id = in_reply_to;
+ if (in_reply_to)
+ rev.ref_message_id = clean_message_id(in_reply_to);
while (0 <= --nr) {
int shown;
commit = list[nr];