fmt-patch: Support --attach
This patch touches a couple of files, because it adds options to print a custom text just after the subject of a commit, and just after the diffstat. [jc: made "many dashes" used as the boundary leader into a single variable, to reduce the possibility of later tweaks to miscount the number of dashes to break it.] Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
May 20, 2006 at 15:40 UTC
698ce6f87e0d6db380f7306e190e8586da184577
9 files changed
+68
-12
builtin-log.c
+14
-3
@@ -183,7 +183,12 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
183
argv[i + 1]);
184
output_directory = strdup(argv[i + 1]);
185
i++;
186
- } else
186
+ }
187
+ else if (!strcmp(argv[i], "--attach"))
188
+ rev.mime_boundary = git_version_string;
189
+ else if (!strncmp(argv[i], "--attach=", 9))
190
+ rev.mime_boundary = argv[i] + 9;
191
+ else
192
argv[j++] = argv[i];
193
}
194
argc = j;
@@ -224,8 +229,14 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
229
shown = log_tree_commit(&rev, commit);
230
free(commit->buffer);
231
commit->buffer = NULL;
227
- if (shown)
228
- printf("-- \n%s\n\n", git_version_string);
232
+ if (shown) {
233
+ if (rev.mime_boundary)
234
+ printf("\n--%s%s--\n\n\n",
235
+ mime_boundary_leader,
236
+ rev.mime_boundary);
237
+ else
238
+ printf("-- \n%s\n\n", git_version_string);
239
+ }
240
if (!use_stdout)
241
fclose(stdout);
242
}
builtin-rev-list.c
+1
-1
@@ -85,7 +85,7 @@ static void show_commit(struct commit *commit)
85
static char pretty_header[16384];
86
pretty_print_commit(revs.commit_format, commit, ~0,
87
pretty_header, sizeof(pretty_header),
88
- revs.abbrev, NULL);
88
+ revs.abbrev, NULL, NULL);
89
printf("%s%c", pretty_header, hdr_termination);
90
}
91
fflush(stdout);
commit.c
+9
-1
@@ -498,7 +498,7 @@ static int add_merge_info(enum cmit_fmt fmt, char *buf, const struct commit *com
498
return offset;
499
}
500
501
-unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject)
501
+unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject, const char *after_subject)
502
{
503
int hdr = 1, body = 0;
504
unsigned long offset = 0;
@@ -591,6 +591,14 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
591
buf[offset++] = '\n';
592
if (fmt == CMIT_FMT_ONELINE)
593
break;
594
+ if (after_subject) {
595
+ int slen = strlen(after_subject);
596
+ if (slen > space - offset - 1)
597
+ slen = space - offset - 1;
598
+ memcpy(buf + offset, after_subject, slen);
599
+ offset += slen;
600
+ after_subject = NULL;
601
+ }
602
subject = NULL;
603
}
604
while (offset && isspace(buf[offset-1]))
commit.h
+1
-1
@@ -51,7 +51,7 @@ enum cmit_fmt {
51
};
52
53
extern enum cmit_fmt get_commit_format(const char *arg);
54
-extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject);
54
+extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject, const char *after_subject);
55
56
/** Removes the first commit from a list sorted by date, and adds all
57
* of its parents.
diff.c
+5
-1
@@ -299,6 +299,7 @@ static void diffstat_consume(void *priv, char *line, unsigned long len)
299
300
static const char pluses[] = "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
301
static const char minuses[]= "----------------------------------------------------------------------";
302
+const char mime_boundary_leader[] = "------------";
303
304
static void show_stats(struct diffstat_t* data)
305
{
@@ -1980,7 +1981,10 @@ void diff_flush(struct diff_options *options)
1981
show_stats(diffstat);
1982
free(diffstat);
1983
diffstat = NULL;
1983
- putchar(options->line_termination);
1984
+ if (options->stat_sep)
1985
+ fputs(options->stat_sep, stdout);
1986
+ else
1987
+ putchar(options->line_termination);
1988
}
1989
for (i = 0; i < q->nr; i++) {
1990
struct diff_filepair *p = q->queue[i];
diff.h
+3
@@ -44,6 +44,7 @@ struct diff_options {
44
int rename_limit;
45
int setup;
46
int abbrev;
47
+ const char *stat_sep;
48
49
int nr_paths;
50
const char **paths;
@@ -52,6 +53,8 @@ struct diff_options {
53
add_remove_fn_t add_remove;
54
};
55
56
+extern const char mime_boundary_leader[];
57
+
58
extern void diff_tree_setup_paths(const char **paths, struct diff_options *);
59
extern void diff_tree_release_paths(struct diff_options *);
60
extern int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
log-tree.c
+33
-4
@@ -20,7 +20,7 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep)
20
int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
21
const char *extra;
22
int len;
23
- char* subject = NULL;
23
+ char *subject = NULL, *after_subject = NULL;
24
25
opt->loginfo = NULL;
26
if (!opt->verbose_header) {
@@ -52,6 +52,7 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep)
52
*/
53
54
if (opt->commit_format == CMIT_FMT_EMAIL) {
55
+ char *sha1 = sha1_to_hex(commit->object.sha1);
56
if (opt->total > 0) {
57
static char buffer[64];
58
snprintf(buffer, sizeof(buffer),
@@ -63,8 +64,36 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep)
64
else
65
subject = "Subject: ";
66
66
- printf("From %s Thu Apr 7 15:13:13 2005\n",
67
- sha1_to_hex(commit->object.sha1));
67
+ printf("From %s Mon Sep 17 00:00:00 2001\n", sha1);
68
+ if (opt->mime_boundary) {
69
+ static char subject_buffer[1024];
70
+ static char buffer[1024];
71
+ snprintf(subject_buffer, sizeof(subject_buffer) - 1,
72
+ "MIME-Version: 1.0\n"
73
+ "Content-Type: multipart/mixed;\n"
74
+ " boundary=\"%s%s\"\n"
75
+ "\n"
76
+ "This is a multi-part message in MIME "
77
+ "format.\n"
78
+ "--%s%s\n"
79
+ "Content-Type: text/plain; "
80
+ "charset=UTF-8; format=fixed\n"
81
+ "Content-Transfer-Encoding: 8bit\n\n",
82
+ mime_boundary_leader, opt->mime_boundary,
83
+ mime_boundary_leader, opt->mime_boundary);
84
+ after_subject = subject_buffer;
85
+
86
+ snprintf(buffer, sizeof(buffer) - 1,
87
+ "--%s%s\n"
88
+ "Content-Type: text/x-patch;\n"
89
+ " name=\"%s.diff\"\n"
90
+ "Content-Transfer-Encoding: 8bit\n"
91
+ "Content-Disposition: inline;\n"
92
+ " filename=\"%s.diff\"\n\n",
93
+ mime_boundary_leader, opt->mime_boundary,
94
+ sha1, sha1);
95
+ opt->diffopt.stat_sep = buffer;
96
+ }
97
} else {
98
printf("%s%s",
99
opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ",
@@ -81,7 +110,7 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep)
110
/*
111
* And then the pretty-printed message itself
112
*/
84
- len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject);
113
+ len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject, after_subject);
114
printf("%s%s%s", this_header, extra, sep);
115
}
116
revision.h
+1
@@ -59,6 +59,7 @@ struct rev_info {
59
enum cmit_fmt commit_format;
60
struct log_info *loginfo;
61
int nr, total;
62
+ const char *mime_boundary;
63
64
/* special limits */
65
int max_count;
show-branch.c
+1
-1
@@ -259,7 +259,7 @@ static void show_one_commit(struct commit *commit, int no_name)
259
struct commit_name *name = commit->object.util;
260
if (commit->object.parsed)
261
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
262
- pretty, sizeof(pretty), 0, NULL);
262
+ pretty, sizeof(pretty), 0, NULL, NULL);
263
else
264
strcpy(pretty, "(unavailable)");
265
if (!strncmp(pretty, "[PATCH] ", 8))