@matheusbsbs / matheus-bagliano / commits / 596524b33d
Fork 0

Teach fmt-patch about --numbered

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed May 5, 2006 at 04:30 UTC 596524b33d50e47e2375cec9e00aff59f0e8278b
7 files changed +25 -11
builtin-log.c
+8 -1
@@ -137,6 +137,7 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
137 struct rev_info rev;
138 int nr = 0, total, i, j;
139 int use_stdout = 0;
140 + int numbered = 0;
141
142 init_revisions(&rev);
143 rev.commit_format = CMIT_FMT_EMAIL;
@@ -156,6 +157,9 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
157 for (i = 1, j = 1; i < argc; i++) {
158 if (!strcmp(argv[i], "--stdout"))
159 use_stdout = 1;
160 + else if (!strcmp(argv[i], "-n") ||
161 + !strcmp(argv[i], "--numbered"))
162 + numbered = 1;
163 else if (!strcmp(argv[i], "-o")) {
164 if (argc < 3)
165 die ("Which directory?");
@@ -186,11 +190,14 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
190 list[nr - 1] = commit;
191 }
192 total = nr;
193 + if (numbered)
194 + rev.total = total;
195 while (0 <= --nr) {
196 int shown;
197 commit = list[nr];
198 + rev.nr = total - nr;
199 if (!use_stdout)
193 - reopen_stdout(commit, total - nr);
200 + reopen_stdout(commit, rev.nr);
201 shown = log_tree_commit(&rev, commit);
202 free(commit->buffer);
203 commit->buffer = NULL;
commit.c
+1 -4
@@ -489,17 +489,14 @@ static int add_merge_info(enum cmit_fmt fmt, char *buf, const struct commit *com
489 return offset;
490 }
491
492 -unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, unsigned long len, char *buf, unsigned long space, int abbrev)
492 +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)
493 {
494 int hdr = 1, body = 0;
495 unsigned long offset = 0;
496 int indent = 4;
497 int parents_shown = 0;
498 const char *msg = commit->buffer;
499 - const char *subject = NULL;
499
501 - if (fmt == CMIT_FMT_EMAIL)
502 - subject = "Subject: [PATCH] ";
500 if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)
501 indent = 0;
502
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);
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);
55
56 /** Removes the first commit from a list sorted by date, and adds all
57 * of its parents.
log-tree.c
+12 -3
@@ -11,6 +11,7 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep)
11 int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
12 const char *extra;
13 int len;
14 + char* subject = NULL;
15
16 opt->loginfo = NULL;
17 if (!opt->verbose_header) {
@@ -38,10 +39,18 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep)
39 * Print header line of header..
40 */
41
41 - if (opt->commit_format == CMIT_FMT_EMAIL)
42 + if (opt->commit_format == CMIT_FMT_EMAIL) {
43 + if (opt->total > 0) {
44 + static char buffer[64];
45 + snprintf(buffer, sizeof(buffer),
46 + "Subject: [PATCH %d/%d] ",
47 + opt->nr, opt->total);
48 + subject = buffer;
49 + } else
50 + subject = "Subject: [PATCH] ";
51 printf("From %s Thu Apr 7 15:13:13 2005\n",
52 sha1_to_hex(commit->object.sha1));
44 - else {
53 + } else {
54 printf("%s%s",
55 opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ",
56 diff_unique_abbrev(commit->object.sha1, abbrev_commit));
@@ -55,7 +64,7 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep)
64 /*
65 * And then the pretty-printed message itself
66 */
58 - len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev);
67 + len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject);
68 printf("%s%s%s", this_header, extra, sep);
69 }
70
rev-list.c
+1 -1
@@ -84,7 +84,7 @@ static void show_commit(struct commit *commit)
84 static char pretty_header[16384];
85 pretty_print_commit(revs.commit_format, commit, ~0,
86 pretty_header, sizeof(pretty_header),
87 - revs.abbrev);
87 + revs.abbrev, NULL);
88 printf("%s%c", pretty_header, hdr_termination);
89 }
90 fflush(stdout);
revision.h
+1
@@ -58,6 +58,7 @@ struct rev_info {
58 unsigned int abbrev;
59 enum cmit_fmt commit_format;
60 struct log_info *loginfo;
61 + int nr, total;
62
63 /* special limits */
64 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);
262 + pretty, sizeof(pretty), 0, NULL);
263 else
264 strcpy(pretty, "(unavailable)");
265 if (!strncmp(pretty, "[PATCH] ", 8))