argv[i + 1]);
output_directory = strdup(argv[i + 1]);
i++;
- } else
+ }
+ else if (!strcmp(argv[i], "--attach"))
+ rev.mime_boundary = git_version_string;
+ else if (!strncmp(argv[i], "--attach=", 9))
+ rev.mime_boundary = argv[i] + 9;
+ else
argv[j++] = argv[i];
}
argc = j;
shown = log_tree_commit(&rev, commit);
free(commit->buffer);
commit->buffer = NULL;
- if (shown)
- printf("-- \n%s\n\n", git_version_string);
+ if (shown) {
+ if (rev.mime_boundary)
+ printf("\n--%s%s--\n\n\n",
+ mime_boundary_leader,
+ rev.mime_boundary);
+ else
+ printf("-- \n%s\n\n", git_version_string);
+ }
if (!use_stdout)
fclose(stdout);
}
static char pretty_header[16384];
pretty_print_commit(revs.commit_format, commit, ~0,
pretty_header, sizeof(pretty_header),
- revs.abbrev, NULL);
+ revs.abbrev, NULL, NULL);
printf("%s%c", pretty_header, hdr_termination);
}
fflush(stdout);
return offset;
}
-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)
+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)
{
int hdr = 1, body = 0;
unsigned long offset = 0;
buf[offset++] = '\n';
if (fmt == CMIT_FMT_ONELINE)
break;
+ if (after_subject) {
+ int slen = strlen(after_subject);
+ if (slen > space - offset - 1)
+ slen = space - offset - 1;
+ memcpy(buf + offset, after_subject, slen);
+ offset += slen;
+ after_subject = NULL;
+ }
subject = NULL;
}
while (offset && isspace(buf[offset-1]))
};
extern enum cmit_fmt get_commit_format(const char *arg);
-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);
+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);
/** Removes the first commit from a list sorted by date, and adds all
* of its parents.
static const char pluses[] = "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
static const char minuses[]= "----------------------------------------------------------------------";
+const char mime_boundary_leader[] = "------------";
static void show_stats(struct diffstat_t* data)
{
show_stats(diffstat);
free(diffstat);
diffstat = NULL;
- putchar(options->line_termination);
+ if (options->stat_sep)
+ fputs(options->stat_sep, stdout);
+ else
+ putchar(options->line_termination);
}
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
int rename_limit;
int setup;
int abbrev;
+ const char *stat_sep;
int nr_paths;
const char **paths;
add_remove_fn_t add_remove;
};
+extern const char mime_boundary_leader[];
+
extern void diff_tree_setup_paths(const char **paths, struct diff_options *);
extern void diff_tree_release_paths(struct diff_options *);
extern int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
const char *extra;
int len;
- char* subject = NULL;
+ char *subject = NULL, *after_subject = NULL;
opt->loginfo = NULL;
if (!opt->verbose_header) {
*/
if (opt->commit_format == CMIT_FMT_EMAIL) {
+ char *sha1 = sha1_to_hex(commit->object.sha1);
if (opt->total > 0) {
static char buffer[64];
snprintf(buffer, sizeof(buffer),
else
subject = "Subject: ";
- printf("From %s Thu Apr 7 15:13:13 2005\n",
- sha1_to_hex(commit->object.sha1));
+ printf("From %s Mon Sep 17 00:00:00 2001\n", sha1);
+ if (opt->mime_boundary) {
+ static char subject_buffer[1024];
+ static char buffer[1024];
+ snprintf(subject_buffer, sizeof(subject_buffer) - 1,
+ "MIME-Version: 1.0\n"
+ "Content-Type: multipart/mixed;\n"
+ " boundary=\"%s%s\"\n"
+ "\n"
+ "This is a multi-part message in MIME "
+ "format.\n"
+ "--%s%s\n"
+ "Content-Type: text/plain; "
+ "charset=UTF-8; format=fixed\n"
+ "Content-Transfer-Encoding: 8bit\n\n",
+ mime_boundary_leader, opt->mime_boundary,
+ mime_boundary_leader, opt->mime_boundary);
+ after_subject = subject_buffer;
+
+ snprintf(buffer, sizeof(buffer) - 1,
+ "--%s%s\n"
+ "Content-Type: text/x-patch;\n"
+ " name=\"%s.diff\"\n"
+ "Content-Transfer-Encoding: 8bit\n"
+ "Content-Disposition: inline;\n"
+ " filename=\"%s.diff\"\n\n",
+ mime_boundary_leader, opt->mime_boundary,
+ sha1, sha1);
+ opt->diffopt.stat_sep = buffer;
+ }
} else {
printf("%s%s",
opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ",
/*
* And then the pretty-printed message itself
*/
- len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject);
+ len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject, after_subject);
printf("%s%s%s", this_header, extra, sep);
}
enum cmit_fmt commit_format;
struct log_info *loginfo;
int nr, total;
+ const char *mime_boundary;
/* special limits */
int max_count;
struct commit_name *name = commit->object.util;
if (commit->object.parsed)
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
- pretty, sizeof(pretty), 0, NULL);
+ pretty, sizeof(pretty), 0, NULL, NULL);
else
strcpy(pretty, "(unavailable)");
if (!strncmp(pretty, "[PATCH] ", 8))