@matheusbsbs / matheus-bagliano / commits / 6b2fbaaffc
Fork 0

format-patch: Produce better output with --inline or --attach

This patch makes two small changes to improve the output of --inline and --attach. The first is to write a newline preceding the boundary. This is needed because MIME defines the encapsulation boundary as including the preceding CRLF (or in this case, just LF), so we should be writing one. Without this, the last newline in the pre-diff content is consumed instead. The second change is to always write the line termination character (default: newline) even when using --inline or --attach. This is simply to improve the aesthetics of the resulting message. When using --inline an email client should render the resulting message identically to the non-inline version. And when using --attach this adds a blank line preceding the attachment in the email, which is visually attractive. Signed-off-by: Kevin Ballard <kevin@sb.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kevin Ballard committed Jul 29, 2008 at 22:49 UTC 6b2fbaaffc5ec762eae5d23b58b1dc0a88e2275e
10 files changed +34 -3
diff.c
+1 -2
@@ -3223,11 +3223,10 @@ void diff_flush(struct diff_options *options)
3223
3224 if (output_format & DIFF_FORMAT_PATCH) {
3225 if (separator) {
3226 + putc(options->line_termination, options->file);
3227 if (options->stat_sep) {
3228 /* attach patch instead of inline */
3229 fputs(options->stat_sep, options->file);
3229 - } else {
3230 - putc(options->line_termination, options->file);
3230 }
3231 }
3232
log-tree.c
+1 -1
@@ -198,7 +198,7 @@ void log_write_email_headers(struct rev_info *opt, const char *name,
198 extra_headers = subject_buffer;
199
200 snprintf(buffer, sizeof(buffer) - 1,
201 - "--%s%s\n"
201 + "\n--%s%s\n"
202 "Content-Type: text/x-patch;"
203 " name=\"%s.diff\"\n"
204 "Content-Transfer-Encoding: 8bit\n"
t/t4013/diff.format-patch_--attach_--stdout_initial..master
+6
@@ -19,6 +19,8 @@ This is the second commit.
19 file2 | 3 ---
20 3 files changed, 5 insertions(+), 3 deletions(-)
21 delete mode 100644 file2
22 +
23 +
24 --------------g-i-t--v-e-r-s-i-o-n
25 Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
26 Content-Transfer-Encoding: 8bit
@@ -75,6 +77,8 @@ Content-Transfer-Encoding: 8bit
77 file1 | 3 +++
78 2 files changed, 5 insertions(+), 0 deletions(-)
79 create mode 100644 file1
80 +
81 +
82 --------------g-i-t--v-e-r-s-i-o-n
83 Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
84 Content-Transfer-Encoding: 8bit
@@ -122,6 +126,8 @@ Content-Transfer-Encoding: 8bit
126 file3 | 4 ++++
127 3 files changed, 9 insertions(+), 0 deletions(-)
128 create mode 100644 file3
129 +
130 +
131 --------------g-i-t--v-e-r-s-i-o-n
132 Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
133 Content-Transfer-Encoding: 8bit
t/t4013/diff.format-patch_--attach_--stdout_initial..master^
+4
@@ -19,6 +19,8 @@ This is the second commit.
19 file2 | 3 ---
20 3 files changed, 5 insertions(+), 3 deletions(-)
21 delete mode 100644 file2
22 +
23 +
24 --------------g-i-t--v-e-r-s-i-o-n
25 Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
26 Content-Transfer-Encoding: 8bit
@@ -75,6 +77,8 @@ Content-Transfer-Encoding: 8bit
77 file1 | 3 +++
78 2 files changed, 5 insertions(+), 0 deletions(-)
79 create mode 100644 file1
80 +
81 +
82 --------------g-i-t--v-e-r-s-i-o-n
83 Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
84 Content-Transfer-Encoding: 8bit
t/t4013/diff.format-patch_--attach_--stdout_initial..side
+2
@@ -17,6 +17,8 @@ Content-Transfer-Encoding: 8bit
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="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
24 Content-Transfer-Encoding: 8bit
t/t4013/diff.format-patch_--inline_--stdout_--subject-prefix=TESTCASE_initial..master
+6
@@ -19,6 +19,8 @@ This is the second commit.
19 file2 | 3 ---
20 3 files changed, 5 insertions(+), 3 deletions(-)
21 delete mode 100644 file2
22 +
23 +
24 --------------g-i-t--v-e-r-s-i-o-n
25 Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
26 Content-Transfer-Encoding: 8bit
@@ -75,6 +77,8 @@ Content-Transfer-Encoding: 8bit
77 file1 | 3 +++
78 2 files changed, 5 insertions(+), 0 deletions(-)
79 create mode 100644 file1
80 +
81 +
82 --------------g-i-t--v-e-r-s-i-o-n
83 Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
84 Content-Transfer-Encoding: 8bit
@@ -122,6 +126,8 @@ Content-Transfer-Encoding: 8bit
126 file3 | 4 ++++
127 3 files changed, 9 insertions(+), 0 deletions(-)
128 create mode 100644 file3
129 +
130 +
131 --------------g-i-t--v-e-r-s-i-o-n
132 Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
133 Content-Transfer-Encoding: 8bit
t/t4013/diff.format-patch_--inline_--stdout_initial..master
+6
@@ -19,6 +19,8 @@ This is the second commit.
19 file2 | 3 ---
20 3 files changed, 5 insertions(+), 3 deletions(-)
21 delete mode 100644 file2
22 +
23 +
24 --------------g-i-t--v-e-r-s-i-o-n
25 Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
26 Content-Transfer-Encoding: 8bit
@@ -75,6 +77,8 @@ Content-Transfer-Encoding: 8bit
77 file1 | 3 +++
78 2 files changed, 5 insertions(+), 0 deletions(-)
79 create mode 100644 file1
80 +
81 +
82 --------------g-i-t--v-e-r-s-i-o-n
83 Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
84 Content-Transfer-Encoding: 8bit
@@ -122,6 +126,8 @@ Content-Transfer-Encoding: 8bit
126 file3 | 4 ++++
127 3 files changed, 9 insertions(+), 0 deletions(-)
128 create mode 100644 file3
129 +
130 +
131 --------------g-i-t--v-e-r-s-i-o-n
132 Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
133 Content-Transfer-Encoding: 8bit
t/t4013/diff.format-patch_--inline_--stdout_initial..master^
+4
@@ -19,6 +19,8 @@ This is the second commit.
19 file2 | 3 ---
20 3 files changed, 5 insertions(+), 3 deletions(-)
21 delete mode 100644 file2
22 +
23 +
24 --------------g-i-t--v-e-r-s-i-o-n
25 Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
26 Content-Transfer-Encoding: 8bit
@@ -75,6 +77,8 @@ Content-Transfer-Encoding: 8bit
77 file1 | 3 +++
78 2 files changed, 5 insertions(+), 0 deletions(-)
79 create mode 100644 file1
80 +
81 +
82 --------------g-i-t--v-e-r-s-i-o-n
83 Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
84 Content-Transfer-Encoding: 8bit
t/t4013/diff.format-patch_--inline_--stdout_initial..master^^
+2
@@ -19,6 +19,8 @@ This is the second commit.
19 file2 | 3 ---
20 3 files changed, 5 insertions(+), 3 deletions(-)
21 delete mode 100644 file2
22 +
23 +
24 --------------g-i-t--v-e-r-s-i-o-n
25 Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
26 Content-Transfer-Encoding: 8bit
t/t4013/diff.format-patch_--inline_--stdout_initial..side
+2
@@ -17,6 +17,8 @@ Content-Transfer-Encoding: 8bit
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="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
24 Content-Transfer-Encoding: 8bit