format-patch: --attach/inline uses filename instead of SHA1
Currently when format-patch is used with --attach or --inline the patch attachment has the SHA1 of the commit for its filename. This replaces the SHA1 with the filename used by format-patch when outputting to files. Fix tests relying on the SHA1 output and add a test showing how the --suffix option affects the attachment filename output. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stephen Boyd committed
Mar 22, 2009 at 19:14 UTC
108dab2811701c20d6d6e8d9fe8af88e41d65d77
14 files changed
+112
-44
builtin-log.c
+4
-4
@@ -607,7 +607,6 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
607
int nr, struct commit **list, struct commit *head)
608
{
609
const char *committer;
610
- char *head_sha1;
610
const char *subject_start = NULL;
611
const char *body = "*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n";
612
const char *msg;
@@ -624,7 +623,6 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
623
die("Cover letter needs email format");
624
625
committer = git_committer_info(0);
627
- head_sha1 = sha1_to_hex(head->object.sha1);
626
627
if (!numbered_files) {
628
/*
@@ -639,7 +637,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
637
"author %s\n"
638
"committer %s\n\n"
639
"cover letter\n",
642
- head_sha1, committer, committer);
640
+ sha1_to_hex(head->object.sha1), committer, committer);
641
}
642
643
if (!use_stdout && reopen_stdout(commit, rev))
@@ -651,7 +649,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
649
free(commit);
650
}
651
654
- log_write_email_headers(rev, head_sha1, &subject_start, &extra_headers,
652
+ log_write_email_headers(rev, head, &subject_start, &extra_headers,
653
&need_8bit_cte);
654
655
msg = body;
@@ -1011,6 +1009,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1009
const char *msgid = clean_message_id(in_reply_to);
1010
string_list_append(msgid, rev.ref_message_ids);
1011
}
1012
+ rev.numbered_files = numbered_files;
1013
+ rev.patch_suffix = fmt_patch_suffix;
1014
if (cover_letter) {
1015
if (thread)
1016
gen_message_id(&rev, "cover");
log-tree.c
+11
-7
@@ -201,13 +201,14 @@ void get_patch_filename(struct commit *commit, int nr, const char *suffix,
201
}
202
}
203
204
-void log_write_email_headers(struct rev_info *opt, const char *name,
204
+void log_write_email_headers(struct rev_info *opt, struct commit *commit,
205
const char **subject_p,
206
const char **extra_headers_p,
207
int *need_8bit_cte_p)
208
{
209
const char *subject = NULL;
210
const char *extra_headers = opt->extra_headers;
211
+ const char *name = sha1_to_hex(commit->object.sha1);
212
213
*need_8bit_cte_p = 0; /* unknown */
214
if (opt->total > 0) {
@@ -246,6 +247,7 @@ void log_write_email_headers(struct rev_info *opt, const char *name,
247
if (opt->mime_boundary) {
248
static char subject_buffer[1024];
249
static char buffer[1024];
250
+ struct strbuf filename = STRBUF_INIT;
251
*need_8bit_cte_p = -1; /* NEVER */
252
snprintf(subject_buffer, sizeof(subject_buffer) - 1,
253
"%s"
@@ -264,18 +266,21 @@ void log_write_email_headers(struct rev_info *opt, const char *name,
266
mime_boundary_leader, opt->mime_boundary);
267
extra_headers = subject_buffer;
268
269
+ get_patch_filename(opt->numbered_files ? NULL : commit, opt->nr,
270
+ opt->patch_suffix, &filename);
271
snprintf(buffer, sizeof(buffer) - 1,
272
"\n--%s%s\n"
273
"Content-Type: text/x-patch;"
270
- " name=\"%s.diff\"\n"
274
+ " name=\"%s\"\n"
275
"Content-Transfer-Encoding: 8bit\n"
276
"Content-Disposition: %s;"
273
- " filename=\"%s.diff\"\n\n",
277
+ " filename=\"%s\"\n\n",
278
mime_boundary_leader, opt->mime_boundary,
275
- name,
279
+ filename.buf,
280
opt->no_inline ? "attachment" : "inline",
277
- name);
281
+ filename.buf);
282
opt->diffopt.stat_sep = buffer;
283
+ strbuf_release(&filename);
284
}
285
*subject_p = subject;
286
*extra_headers_p = extra_headers;
@@ -355,8 +360,7 @@ void show_log(struct rev_info *opt)
360
*/
361
362
if (opt->commit_format == CMIT_FMT_EMAIL) {
358
- log_write_email_headers(opt, sha1_to_hex(commit->object.sha1),
359
- &subject, &extra_headers,
363
+ log_write_email_headers(opt, commit, &subject, &extra_headers,
364
&need_8bit_cte);
365
} else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
366
fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout);
log-tree.h
+1
-1
@@ -13,7 +13,7 @@ int log_tree_commit(struct rev_info *, struct commit *);
13
int log_tree_opt_parse(struct rev_info *, const char **, int);
14
void show_log(struct rev_info *opt);
15
void show_decorations(struct rev_info *opt, struct commit *commit);
16
-void log_write_email_headers(struct rev_info *opt, const char *name,
16
+void log_write_email_headers(struct rev_info *opt, struct commit *commit,
17
const char **subject_p,
18
const char **extra_headers_p,
19
int *need_8bit_cte_p);
revision.h
+2
@@ -86,6 +86,8 @@ struct rev_info {
86
struct log_info *loginfo;
87
int nr, total;
88
const char *mime_boundary;
89
+ const char *patch_suffix;
90
+ int numbered_files;
91
char *message_id;
92
struct string_list *ref_message_ids;
93
const char *add_signoff;
t/t4013-diff-various.sh
+1
@@ -246,6 +246,7 @@ format-patch --stdout initial..master
246
format-patch --stdout --no-numbered initial..master
247
format-patch --stdout --numbered initial..master
248
format-patch --attach --stdout initial..side
249
+format-patch --attach --stdout --suffix=.diff initial..side
250
format-patch --attach --stdout initial..master^
251
format-patch --attach --stdout initial..master
252
format-patch --inline --stdout initial..side
t/t4013/diff.format-patch_--attach_--stdout_--suffix=.diff_initial..side
new
+61
@@ -0,0 +1,61 @@
1
+$ git format-patch --attach --stdout --suffix=.diff initial..side
2
+From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001
3
+From: A U Thor <author@example.com>
4
+Date: Mon, 26 Jun 2006 00:03:00 +0000
5
+Subject: [PATCH] Side
6
+MIME-Version: 1.0
7
+Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
8
+
9
+This is a multi-part message in MIME format.
10
+--------------g-i-t--v-e-r-s-i-o-n
11
+Content-Type: text/plain; charset=UTF-8; format=fixed
12
+Content-Transfer-Encoding: 8bit
13
+
14
+---
15
+ dir/sub | 2 ++
16
+ file0 | 3 +++
17
+ file3 | 4 ++++
18
+ 3 files changed, 9 insertions(+), 0 deletions(-)
19
+ create mode 100644 file3
20
+
21
+
22
+--------------g-i-t--v-e-r-s-i-o-n
23
+Content-Type: text/x-patch; name="0001-Side.diff"
24
+Content-Transfer-Encoding: 8bit
25
+Content-Disposition: attachment; filename="0001-Side.diff"
26
+
27
+diff --git a/dir/sub b/dir/sub
28
+index 35d242b..7289e35 100644
29
+--- a/dir/sub
30
++++ b/dir/sub
31
+@@ -1,2 +1,4 @@
32
+ A
33
+ B
34
++1
35
++2
36
+diff --git a/file0 b/file0
37
+index 01e79c3..f4615da 100644
38
+--- a/file0
39
++++ b/file0
40
+@@ -1,3 +1,6 @@
41
+ 1
42
+ 2
43
+ 3
44
++A
45
++B
46
++C
47
+diff --git a/file3 b/file3
48
+new file mode 100644
49
+index 0000000..7289e35
50
+--- /dev/null
51
++++ b/file3
52
+@@ -0,0 +1,4 @@
53
++A
54
++B
55
++1
56
++2
57
+
58
+--------------g-i-t--v-e-r-s-i-o-n--
59
+
60
+
61
+$
t/t4013/diff.format-patch_--attach_--stdout_initial..master
+6
-6
@@ -22,9 +22,9 @@ This is the second commit.
22
23
24
--------------g-i-t--v-e-r-s-i-o-n
25
-Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
25
+Content-Type: text/x-patch; name="0001-Second.patch"
26
Content-Transfer-Encoding: 8bit
27
-Content-Disposition: attachment; filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
27
+Content-Disposition: attachment; filename="0001-Second.patch"
28
29
diff --git a/dir/sub b/dir/sub
30
index 35d242b..8422d40 100644
@@ -80,9 +80,9 @@ Content-Transfer-Encoding: 8bit
80
81
82
--------------g-i-t--v-e-r-s-i-o-n
83
-Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
83
+Content-Type: text/x-patch; name="0002-Third.patch"
84
Content-Transfer-Encoding: 8bit
85
-Content-Disposition: attachment; filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
85
+Content-Disposition: attachment; filename="0002-Third.patch"
86
87
diff --git a/dir/sub b/dir/sub
88
index 8422d40..cead32e 100644
@@ -129,9 +129,9 @@ Content-Transfer-Encoding: 8bit
129
130
131
--------------g-i-t--v-e-r-s-i-o-n
132
-Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
132
+Content-Type: text/x-patch; name="0003-Side.patch"
133
Content-Transfer-Encoding: 8bit
134
-Content-Disposition: attachment; filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
134
+Content-Disposition: attachment; filename="0003-Side.patch"
135
136
diff --git a/dir/sub b/dir/sub
137
index 35d242b..7289e35 100644
t/t4013/diff.format-patch_--attach_--stdout_initial..master^
+4
-4
@@ -22,9 +22,9 @@ This is the second commit.
22
23
24
--------------g-i-t--v-e-r-s-i-o-n
25
-Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
25
+Content-Type: text/x-patch; name="0001-Second.patch"
26
Content-Transfer-Encoding: 8bit
27
-Content-Disposition: attachment; filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
27
+Content-Disposition: attachment; filename="0001-Second.patch"
28
29
diff --git a/dir/sub b/dir/sub
30
index 35d242b..8422d40 100644
@@ -80,9 +80,9 @@ Content-Transfer-Encoding: 8bit
80
81
82
--------------g-i-t--v-e-r-s-i-o-n
83
-Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
83
+Content-Type: text/x-patch; name="0002-Third.patch"
84
Content-Transfer-Encoding: 8bit
85
-Content-Disposition: attachment; filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
85
+Content-Disposition: attachment; filename="0002-Third.patch"
86
87
diff --git a/dir/sub b/dir/sub
88
index 8422d40..cead32e 100644
t/t4013/diff.format-patch_--attach_--stdout_initial..side
+2
-2
@@ -20,9 +20,9 @@ Content-Transfer-Encoding: 8bit
20
21
22
--------------g-i-t--v-e-r-s-i-o-n
23
-Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
23
+Content-Type: text/x-patch; name="0001-Side.patch"
24
Content-Transfer-Encoding: 8bit
25
-Content-Disposition: attachment; filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
25
+Content-Disposition: attachment; filename="0001-Side.patch"
26
27
diff --git a/dir/sub b/dir/sub
28
index 35d242b..7289e35 100644
t/t4013/diff.format-patch_--inline_--stdout_--subject-prefix=TESTCASE_initial..master
+6
-6
@@ -22,9 +22,9 @@ This is the second commit.
22
23
24
--------------g-i-t--v-e-r-s-i-o-n
25
-Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
25
+Content-Type: text/x-patch; name="0001-Second.patch"
26
Content-Transfer-Encoding: 8bit
27
-Content-Disposition: inline; filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
27
+Content-Disposition: inline; filename="0001-Second.patch"
28
29
diff --git a/dir/sub b/dir/sub
30
index 35d242b..8422d40 100644
@@ -80,9 +80,9 @@ Content-Transfer-Encoding: 8bit
80
81
82
--------------g-i-t--v-e-r-s-i-o-n
83
-Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
83
+Content-Type: text/x-patch; name="0002-Third.patch"
84
Content-Transfer-Encoding: 8bit
85
-Content-Disposition: inline; filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
85
+Content-Disposition: inline; filename="0002-Third.patch"
86
87
diff --git a/dir/sub b/dir/sub
88
index 8422d40..cead32e 100644
@@ -129,9 +129,9 @@ Content-Transfer-Encoding: 8bit
129
130
131
--------------g-i-t--v-e-r-s-i-o-n
132
-Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
132
+Content-Type: text/x-patch; name="0003-Side.patch"
133
Content-Transfer-Encoding: 8bit
134
-Content-Disposition: inline; filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
134
+Content-Disposition: inline; filename="0003-Side.patch"
135
136
diff --git a/dir/sub b/dir/sub
137
index 35d242b..7289e35 100644
t/t4013/diff.format-patch_--inline_--stdout_initial..master
+6
-6
@@ -22,9 +22,9 @@ This is the second commit.
22
23
24
--------------g-i-t--v-e-r-s-i-o-n
25
-Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
25
+Content-Type: text/x-patch; name="0001-Second.patch"
26
Content-Transfer-Encoding: 8bit
27
-Content-Disposition: inline; filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
27
+Content-Disposition: inline; filename="0001-Second.patch"
28
29
diff --git a/dir/sub b/dir/sub
30
index 35d242b..8422d40 100644
@@ -80,9 +80,9 @@ Content-Transfer-Encoding: 8bit
80
81
82
--------------g-i-t--v-e-r-s-i-o-n
83
-Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
83
+Content-Type: text/x-patch; name="0002-Third.patch"
84
Content-Transfer-Encoding: 8bit
85
-Content-Disposition: inline; filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
85
+Content-Disposition: inline; filename="0002-Third.patch"
86
87
diff --git a/dir/sub b/dir/sub
88
index 8422d40..cead32e 100644
@@ -129,9 +129,9 @@ Content-Transfer-Encoding: 8bit
129
130
131
--------------g-i-t--v-e-r-s-i-o-n
132
-Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
132
+Content-Type: text/x-patch; name="0003-Side.patch"
133
Content-Transfer-Encoding: 8bit
134
-Content-Disposition: inline; filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
134
+Content-Disposition: inline; filename="0003-Side.patch"
135
136
diff --git a/dir/sub b/dir/sub
137
index 35d242b..7289e35 100644
t/t4013/diff.format-patch_--inline_--stdout_initial..master^
+4
-4
@@ -22,9 +22,9 @@ This is the second commit.
22
23
24
--------------g-i-t--v-e-r-s-i-o-n
25
-Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
25
+Content-Type: text/x-patch; name="0001-Second.patch"
26
Content-Transfer-Encoding: 8bit
27
-Content-Disposition: inline; filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
27
+Content-Disposition: inline; filename="0001-Second.patch"
28
29
diff --git a/dir/sub b/dir/sub
30
index 35d242b..8422d40 100644
@@ -80,9 +80,9 @@ Content-Transfer-Encoding: 8bit
80
81
82
--------------g-i-t--v-e-r-s-i-o-n
83
-Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
83
+Content-Type: text/x-patch; name="0002-Third.patch"
84
Content-Transfer-Encoding: 8bit
85
-Content-Disposition: inline; filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
85
+Content-Disposition: inline; filename="0002-Third.patch"
86
87
diff --git a/dir/sub b/dir/sub
88
index 8422d40..cead32e 100644
t/t4013/diff.format-patch_--inline_--stdout_initial..master^^
+2
-2
@@ -22,9 +22,9 @@ This is the second commit.
22
23
24
--------------g-i-t--v-e-r-s-i-o-n
25
-Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
25
+Content-Type: text/x-patch; name="0001-Second.patch"
26
Content-Transfer-Encoding: 8bit
27
-Content-Disposition: inline; filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
27
+Content-Disposition: inline; filename="0001-Second.patch"
28
29
diff --git a/dir/sub b/dir/sub
30
index 35d242b..8422d40 100644
t/t4013/diff.format-patch_--inline_--stdout_initial..side
+2
-2
@@ -20,9 +20,9 @@ Content-Transfer-Encoding: 8bit
20
21
22
--------------g-i-t--v-e-r-s-i-o-n
23
-Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
23
+Content-Type: text/x-patch; name="0001-Side.patch"
24
Content-Transfer-Encoding: 8bit
25
-Content-Disposition: inline; filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
25
+Content-Disposition: inline; filename="0001-Side.patch"
26
27
diff --git a/dir/sub b/dir/sub
28
index 35d242b..7289e35 100644