format-patch: add --inline option and make --attach a true attachment
The existing --attach option did not create a true "attachment" but multipart/mixed with Content-Disposition: inline. It should have been with Content-Disposition: attachment. Introduce --inline to add multipart/mixed that is inlined, and make --attach to create an attachement. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Mar 4, 2007 at 00:12 UTC
c112f689c2c4dfbf2e4dca0e91aa527dd96ab333
11 files changed
+386
-13
Documentation/git-format-patch.txt
+11
-3
@@ -9,7 +9,8 @@ git-format-patch - Prepare patches for e-mail submission
9
SYNOPSIS
10
--------
11
[verse]
12
-'git-format-patch' [-n | -k] [-o <dir> | --stdout] [--attach] [--thread]
12
+'git-format-patch' [-n | -k] [-o <dir> | --stdout] [--thread]
13
+ [--attach[=<boundary>] | --inline[=<boundary>]]
14
[-s | --signoff] [--diff-options] [--start-number <n>]
15
[--in-reply-to=Message-Id] [--suffix=.<sfx>]
16
[--ignore-if-in-upstream]
@@ -68,8 +69,15 @@ OPTIONS
69
Print all commits to the standard output in mbox format,
70
instead of creating a file for each one.
71
71
---attach::
72
- Create attachments instead of inlining patches.
72
+--attach[=<boundary>]::
73
+ Create multipart/mixed attachment, the first part of
74
+ which is the commit message and the patch itself in the
75
+ second part, with "Content-Disposition: attachment".
76
+
77
+--inline[=<boundary>]::
78
+ Create multipart/mixed attachment, the first part of
79
+ which is the commit message and the patch itself in the
80
+ second part, with "Content-Disposition: inline".
81
82
--thread::
83
Add In-Reply-To and References headers to make the second and
builtin-log.c
+14
-2
@@ -482,10 +482,22 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
482
memcpy(add_signoff, committer, endpos - committer + 1);
483
add_signoff[endpos - committer + 1] = 0;
484
}
485
- else if (!strcmp(argv[i], "--attach"))
485
+ else if (!strcmp(argv[i], "--attach")) {
486
rev.mime_boundary = git_version_string;
487
- else if (!prefixcmp(argv[i], "--attach="))
487
+ rev.no_inline = 1;
488
+ }
489
+ else if (!prefixcmp(argv[i], "--attach=")) {
490
+ rev.mime_boundary = argv[i] + 9;
491
+ rev.no_inline = 1;
492
+ }
493
+ else if (!strcmp(argv[i], "--inline")) {
494
+ rev.mime_boundary = git_version_string;
495
+ rev.no_inline = 0;
496
+ }
497
+ else if (!prefixcmp(argv[i], "--inline=")) {
498
rev.mime_boundary = argv[i] + 9;
499
+ rev.no_inline = 0;
500
+ }
501
else if (!strcmp(argv[i], "--ignore-if-in-upstream"))
502
ignore_if_in_upstream = 1;
503
else if (!strcmp(argv[i], "--thread"))
log-tree.c
+4
-2
@@ -205,10 +205,12 @@ void show_log(struct rev_info *opt, const char *sep)
205
"Content-Type: text/x-patch;\n"
206
" name=\"%s.diff\"\n"
207
"Content-Transfer-Encoding: 8bit\n"
208
- "Content-Disposition: inline;\n"
208
+ "Content-Disposition: %s;\n"
209
" filename=\"%s.diff\"\n\n",
210
mime_boundary_leader, opt->mime_boundary,
211
- sha1, sha1);
211
+ sha1,
212
+ opt->no_inline ? "attachment" : "inline",
213
+ sha1);
214
opt->diffopt.stat_sep = buffer;
215
}
216
} else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
revision.h
+1
@@ -74,6 +74,7 @@ struct rev_info {
74
const char *add_signoff;
75
const char *extra_headers;
76
const char *log_reencode;
77
+ int no_inline;
78
79
/* Filter by commit log message */
80
struct grep_opt *grep_filter;
t/t4013-diff-various.sh
+3
@@ -238,6 +238,9 @@ format-patch --stdout initial..master
238
format-patch --attach --stdout initial..side
239
format-patch --attach --stdout initial..master^
240
format-patch --attach --stdout initial..master
241
+format-patch --inline --stdout initial..side
242
+format-patch --inline --stdout initial..master^
243
+format-patch --inline --stdout initial..master
244
245
diff --abbrev initial..side
246
diff -r initial..side
t/t4013/diff.format-patch_--attach_--stdout_initial..master
+3
-3
@@ -24,7 +24,7 @@ This is the second commit.
24
Content-Type: text/x-patch;
25
name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
26
Content-Transfer-Encoding: 8bit
27
-Content-Disposition: inline;
27
+Content-Disposition: attachment;
28
filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
29
30
diff --git a/dir/sub b/dir/sub
@@ -83,7 +83,7 @@ Content-Transfer-Encoding: 8bit
83
Content-Type: text/x-patch;
84
name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
85
Content-Transfer-Encoding: 8bit
86
-Content-Disposition: inline;
86
+Content-Disposition: attachment;
87
filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
88
89
diff --git a/dir/sub b/dir/sub
@@ -133,7 +133,7 @@ Content-Transfer-Encoding: 8bit
133
Content-Type: text/x-patch;
134
name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
135
Content-Transfer-Encoding: 8bit
136
-Content-Disposition: inline;
136
+Content-Disposition: attachment;
137
filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
138
139
diff --git a/dir/sub b/dir/sub
t/t4013/diff.format-patch_--attach_--stdout_initial..master^
+2
-2
@@ -24,7 +24,7 @@ This is the second commit.
24
Content-Type: text/x-patch;
25
name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
26
Content-Transfer-Encoding: 8bit
27
-Content-Disposition: inline;
27
+Content-Disposition: attachment;
28
filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
29
30
diff --git a/dir/sub b/dir/sub
@@ -83,7 +83,7 @@ Content-Transfer-Encoding: 8bit
83
Content-Type: text/x-patch;
84
name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
85
Content-Transfer-Encoding: 8bit
86
-Content-Disposition: inline;
86
+Content-Disposition: attachment;
87
filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
88
89
diff --git a/dir/sub b/dir/sub
t/t4013/diff.format-patch_--attach_--stdout_initial..side
+1
-1
@@ -22,7 +22,7 @@ Content-Transfer-Encoding: 8bit
22
Content-Type: text/x-patch;
23
name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
24
Content-Transfer-Encoding: 8bit
25
-Content-Disposition: inline;
25
+Content-Disposition: attachment;
26
filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
27
28
diff --git a/dir/sub b/dir/sub
t/t4013/diff.format-patch_--inline_--stdout_initial..master
new
+173
@@ -0,0 +1,173 @@
1
+$ git format-patch --inline --stdout initial..master
2
+From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001
3
+From: A U Thor <author@example.com>
4
+Date: Mon, 26 Jun 2006 00:01:00 +0000
5
+Subject: [PATCH] Second
6
+MIME-Version: 1.0
7
+Content-Type: multipart/mixed;
8
+ boundary="------------g-i-t--v-e-r-s-i-o-n"
9
+
10
+This is a multi-part message in MIME format.
11
+--------------g-i-t--v-e-r-s-i-o-n
12
+Content-Type: text/plain; charset=UTF-8; format=fixed
13
+Content-Transfer-Encoding: 8bit
14
+
15
+
16
+This is the second commit.
17
+---
18
+ dir/sub | 2 ++
19
+ file0 | 3 +++
20
+ file2 | 3 ---
21
+ 3 files changed, 5 insertions(+), 3 deletions(-)
22
+ delete mode 100644 file2
23
+--------------g-i-t--v-e-r-s-i-o-n
24
+Content-Type: text/x-patch;
25
+ name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
26
+Content-Transfer-Encoding: 8bit
27
+Content-Disposition: inline;
28
+ filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
29
+
30
+diff --git a/dir/sub b/dir/sub
31
+index 35d242b..8422d40 100644
32
+--- a/dir/sub
33
++++ b/dir/sub
34
+@@ -1,2 +1,4 @@
35
+ A
36
+ B
37
++C
38
++D
39
+diff --git a/file0 b/file0
40
+index 01e79c3..b414108 100644
41
+--- a/file0
42
++++ b/file0
43
+@@ -1,3 +1,6 @@
44
+ 1
45
+ 2
46
+ 3
47
++4
48
++5
49
++6
50
+diff --git a/file2 b/file2
51
+deleted file mode 100644
52
+index 01e79c3..0000000
53
+--- a/file2
54
++++ /dev/null
55
+@@ -1,3 +0,0 @@
56
+-1
57
+-2
58
+-3
59
+
60
+--------------g-i-t--v-e-r-s-i-o-n--
61
+
62
+
63
+
64
+From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001
65
+From: A U Thor <author@example.com>
66
+Date: Mon, 26 Jun 2006 00:02:00 +0000
67
+Subject: [PATCH] Third
68
+MIME-Version: 1.0
69
+Content-Type: multipart/mixed;
70
+ boundary="------------g-i-t--v-e-r-s-i-o-n"
71
+
72
+This is a multi-part message in MIME format.
73
+--------------g-i-t--v-e-r-s-i-o-n
74
+Content-Type: text/plain; charset=UTF-8; format=fixed
75
+Content-Transfer-Encoding: 8bit
76
+
77
+---
78
+ dir/sub | 2 ++
79
+ file1 | 3 +++
80
+ 2 files changed, 5 insertions(+), 0 deletions(-)
81
+ create mode 100644 file1
82
+--------------g-i-t--v-e-r-s-i-o-n
83
+Content-Type: text/x-patch;
84
+ name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
85
+Content-Transfer-Encoding: 8bit
86
+Content-Disposition: inline;
87
+ filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
88
+
89
+diff --git a/dir/sub b/dir/sub
90
+index 8422d40..cead32e 100644
91
+--- a/dir/sub
92
++++ b/dir/sub
93
+@@ -2,3 +2,5 @@ A
94
+ B
95
+ C
96
+ D
97
++E
98
++F
99
+diff --git a/file1 b/file1
100
+new file mode 100644
101
+index 0000000..b1e6722
102
+--- /dev/null
103
++++ b/file1
104
+@@ -0,0 +1,3 @@
105
++A
106
++B
107
++C
108
+
109
+--------------g-i-t--v-e-r-s-i-o-n--
110
+
111
+
112
+
113
+From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001
114
+From: A U Thor <author@example.com>
115
+Date: Mon, 26 Jun 2006 00:03:00 +0000
116
+Subject: [PATCH] Side
117
+MIME-Version: 1.0
118
+Content-Type: multipart/mixed;
119
+ boundary="------------g-i-t--v-e-r-s-i-o-n"
120
+
121
+This is a multi-part message in MIME format.
122
+--------------g-i-t--v-e-r-s-i-o-n
123
+Content-Type: text/plain; charset=UTF-8; format=fixed
124
+Content-Transfer-Encoding: 8bit
125
+
126
+---
127
+ dir/sub | 2 ++
128
+ file0 | 3 +++
129
+ file3 | 4 ++++
130
+ 3 files changed, 9 insertions(+), 0 deletions(-)
131
+ create mode 100644 file3
132
+--------------g-i-t--v-e-r-s-i-o-n
133
+Content-Type: text/x-patch;
134
+ name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
135
+Content-Transfer-Encoding: 8bit
136
+Content-Disposition: inline;
137
+ filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
138
+
139
+diff --git a/dir/sub b/dir/sub
140
+index 35d242b..7289e35 100644
141
+--- a/dir/sub
142
++++ b/dir/sub
143
+@@ -1,2 +1,4 @@
144
+ A
145
+ B
146
++1
147
++2
148
+diff --git a/file0 b/file0
149
+index 01e79c3..f4615da 100644
150
+--- a/file0
151
++++ b/file0
152
+@@ -1,3 +1,6 @@
153
+ 1
154
+ 2
155
+ 3
156
++A
157
++B
158
++C
159
+diff --git a/file3 b/file3
160
+new file mode 100644
161
+index 0000000..7289e35
162
+--- /dev/null
163
++++ b/file3
164
+@@ -0,0 +1,4 @@
165
++A
166
++B
167
++1
168
++2
169
+
170
+--------------g-i-t--v-e-r-s-i-o-n--
171
+
172
+
173
+$
t/t4013/diff.format-patch_--inline_--stdout_initial..master^
new
+112
@@ -0,0 +1,112 @@
1
+$ git format-patch --inline --stdout initial..master^
2
+From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001
3
+From: A U Thor <author@example.com>
4
+Date: Mon, 26 Jun 2006 00:01:00 +0000
5
+Subject: [PATCH] Second
6
+MIME-Version: 1.0
7
+Content-Type: multipart/mixed;
8
+ boundary="------------g-i-t--v-e-r-s-i-o-n"
9
+
10
+This is a multi-part message in MIME format.
11
+--------------g-i-t--v-e-r-s-i-o-n
12
+Content-Type: text/plain; charset=UTF-8; format=fixed
13
+Content-Transfer-Encoding: 8bit
14
+
15
+
16
+This is the second commit.
17
+---
18
+ dir/sub | 2 ++
19
+ file0 | 3 +++
20
+ file2 | 3 ---
21
+ 3 files changed, 5 insertions(+), 3 deletions(-)
22
+ delete mode 100644 file2
23
+--------------g-i-t--v-e-r-s-i-o-n
24
+Content-Type: text/x-patch;
25
+ name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
26
+Content-Transfer-Encoding: 8bit
27
+Content-Disposition: inline;
28
+ filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
29
+
30
+diff --git a/dir/sub b/dir/sub
31
+index 35d242b..8422d40 100644
32
+--- a/dir/sub
33
++++ b/dir/sub
34
+@@ -1,2 +1,4 @@
35
+ A
36
+ B
37
++C
38
++D
39
+diff --git a/file0 b/file0
40
+index 01e79c3..b414108 100644
41
+--- a/file0
42
++++ b/file0
43
+@@ -1,3 +1,6 @@
44
+ 1
45
+ 2
46
+ 3
47
++4
48
++5
49
++6
50
+diff --git a/file2 b/file2
51
+deleted file mode 100644
52
+index 01e79c3..0000000
53
+--- a/file2
54
++++ /dev/null
55
+@@ -1,3 +0,0 @@
56
+-1
57
+-2
58
+-3
59
+
60
+--------------g-i-t--v-e-r-s-i-o-n--
61
+
62
+
63
+
64
+From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001
65
+From: A U Thor <author@example.com>
66
+Date: Mon, 26 Jun 2006 00:02:00 +0000
67
+Subject: [PATCH] Third
68
+MIME-Version: 1.0
69
+Content-Type: multipart/mixed;
70
+ boundary="------------g-i-t--v-e-r-s-i-o-n"
71
+
72
+This is a multi-part message in MIME format.
73
+--------------g-i-t--v-e-r-s-i-o-n
74
+Content-Type: text/plain; charset=UTF-8; format=fixed
75
+Content-Transfer-Encoding: 8bit
76
+
77
+---
78
+ dir/sub | 2 ++
79
+ file1 | 3 +++
80
+ 2 files changed, 5 insertions(+), 0 deletions(-)
81
+ create mode 100644 file1
82
+--------------g-i-t--v-e-r-s-i-o-n
83
+Content-Type: text/x-patch;
84
+ name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
85
+Content-Transfer-Encoding: 8bit
86
+Content-Disposition: inline;
87
+ filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
88
+
89
+diff --git a/dir/sub b/dir/sub
90
+index 8422d40..cead32e 100644
91
+--- a/dir/sub
92
++++ b/dir/sub
93
+@@ -2,3 +2,5 @@ A
94
+ B
95
+ C
96
+ D
97
++E
98
++F
99
+diff --git a/file1 b/file1
100
+new file mode 100644
101
+index 0000000..b1e6722
102
+--- /dev/null
103
++++ b/file1
104
+@@ -0,0 +1,3 @@
105
++A
106
++B
107
++C
108
+
109
+--------------g-i-t--v-e-r-s-i-o-n--
110
+
111
+
112
+$
t/t4013/diff.format-patch_--inline_--stdout_initial..side
new
+62
@@ -0,0 +1,62 @@
1
+$ git format-patch --inline --stdout 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;
8
+ boundary="------------g-i-t--v-e-r-s-i-o-n"
9
+
10
+This is a multi-part message in MIME format.
11
+--------------g-i-t--v-e-r-s-i-o-n
12
+Content-Type: text/plain; charset=UTF-8; format=fixed
13
+Content-Transfer-Encoding: 8bit
14
+
15
+---
16
+ dir/sub | 2 ++
17
+ file0 | 3 +++
18
+ file3 | 4 ++++
19
+ 3 files changed, 9 insertions(+), 0 deletions(-)
20
+ create mode 100644 file3
21
+--------------g-i-t--v-e-r-s-i-o-n
22
+Content-Type: text/x-patch;
23
+ name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
24
+Content-Transfer-Encoding: 8bit
25
+Content-Disposition: inline;
26
+ filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
27
+
28
+diff --git a/dir/sub b/dir/sub
29
+index 35d242b..7289e35 100644
30
+--- a/dir/sub
31
++++ b/dir/sub
32
+@@ -1,2 +1,4 @@
33
+ A
34
+ B
35
++1
36
++2
37
+diff --git a/file0 b/file0
38
+index 01e79c3..f4615da 100644
39
+--- a/file0
40
++++ b/file0
41
+@@ -1,3 +1,6 @@
42
+ 1
43
+ 2
44
+ 3
45
++A
46
++B
47
++C
48
+diff --git a/file3 b/file3
49
+new file mode 100644
50
+index 0000000..7289e35
51
+--- /dev/null
52
++++ b/file3
53
+@@ -0,0 +1,4 @@
54
++A
55
++B
56
++1
57
++2
58
+
59
+--------------g-i-t--v-e-r-s-i-o-n--
60
+
61
+
62
+$