{"thread":{"id":"4067","subject":"[PATCH] Teach fmt-patch about --numbered","startedAt":"2006-05-05T02:30:52Z","lastAt":"2006-05-05T02:30:52Z","messageCount":1,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"19541","messageId":"Pine.LNX.4.63.0605050430070.26082@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"4067","inReplyTo":null,"subject":"[PATCH] Teach fmt-patch about --numbered","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-05-05T02:30:52Z","receivedAt":"2006-05-05T02:30:52Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n builtin-log.c |    9 ++++++++-\n commit.c      |    5 +----\n commit.h      |    2 +-\n log-tree.c    |   15 ++++++++++++---\n rev-list.c    |    2 +-\n revision.h    |    1 +\n show-branch.c |    2 +-\n 7 files changed, 25 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 53a47c9..43c7ecd 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -137,6 +137,7 @@ int cmd_format_patch(int argc, const cha\n \tstruct rev_info rev;\n \tint nr = 0, total, i, j;\n \tint use_stdout = 0;\n+\tint numbered = 0;\n \n \tinit_revisions(&rev);\n \trev.commit_format = CMIT_FMT_EMAIL;\n@@ -156,6 +157,9 @@ int cmd_format_patch(int argc, const cha\n \tfor (i = 1, j = 1; i < argc; i++) {\n \t\tif (!strcmp(argv[i], \"--stdout\"))\n \t\t\tuse_stdout = 1;\n+\t\telse if (!strcmp(argv[i], \"-n\") ||\n+\t\t\t\t!strcmp(argv[i], \"--numbered\"))\n+\t\t\tnumbered = 1;\n \t\telse if (!strcmp(argv[i], \"-o\")) {\n \t\t\tif (argc < 3)\n \t\t\t\tdie (\"Which directory?\");\n@@ -186,11 +190,14 @@ int cmd_format_patch(int argc, const cha\n \t\tlist[nr - 1] = commit;\n \t}\n \ttotal = nr;\n+\tif (numbered)\n+\t\trev.total = total;\n \twhile (0 <= --nr) {\n \t\tint shown;\n \t\tcommit = list[nr];\n+\t\trev.nr = total - nr;\n \t\tif (!use_stdout)\n-\t\t\treopen_stdout(commit, total - nr);\n+\t\t\treopen_stdout(commit, rev.nr);\n \t\tshown = log_tree_commit(&rev, commit);\n \t\tfree(commit->buffer);\n \t\tcommit->buffer = NULL;\ndiff --git a/commit.c b/commit.c\nindex 42b44bb..93b3903 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -489,17 +489,14 @@ static int add_merge_info(enum cmit_fmt \n \treturn offset;\n }\n \n-unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, unsigned long len, char *buf, unsigned long space, int abbrev)\n+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)\n {\n \tint hdr = 1, body = 0;\n \tunsigned long offset = 0;\n \tint indent = 4;\n \tint parents_shown = 0;\n \tconst char *msg = commit->buffer;\n-\tconst char *subject = NULL;\n \n-\tif (fmt == CMIT_FMT_EMAIL)\n-\t\tsubject = \"Subject: [PATCH] \";\n \tif (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)\n \t\tindent = 0;\n \ndiff --git a/commit.h b/commit.h\nindex 01eec60..8d7514c 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -51,7 +51,7 @@ enum cmit_fmt {\n };\n \n extern enum cmit_fmt get_commit_format(const char *arg);\n-extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char *buf, unsigned long space, int abbrev);\n+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);\n \n /** Removes the first commit from a list sorted by date, and adds all\n  * of its parents.\ndiff --git a/log-tree.c b/log-tree.c\nindex d92abaf..cec7068 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -20,6 +20,7 @@ void show_log(struct rev_info *opt, stru\n \tint abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;\n \tconst char *extra;\n \tint len;\n+\tchar* subject = NULL;\n \n \topt->loginfo = NULL;\n \tif (!opt->verbose_header) {\n@@ -50,10 +51,18 @@ void show_log(struct rev_info *opt, stru\n \t * Print header line of header..\n \t */\n \n-\tif (opt->commit_format == CMIT_FMT_EMAIL)\n+\tif (opt->commit_format == CMIT_FMT_EMAIL) {\n+\t\tif (opt->total > 0) {\n+\t\t\tstatic char buffer[64];\n+\t\t\tsnprintf(buffer, sizeof(buffer),\n+\t\t\t\t\t\"Subject: [PATCH %d/%d] \",\n+\t\t\t\t\topt->nr, opt->total);\n+\t\t\tsubject = buffer;\n+\t\t} else\n+\t\t\tsubject = \"Subject: [PATCH] \";\n \t\tprintf(\"From %s  Thu Apr 7 15:13:13 2005\\n\",\n \t\t       sha1_to_hex(commit->object.sha1));\n-\telse {\n+\t} else {\n \t\tprintf(\"%s%s\",\n \t\t       opt->commit_format == CMIT_FMT_ONELINE ? \"\" : \"commit \",\n \t\t       diff_unique_abbrev(commit->object.sha1, abbrev_commit));\n@@ -69,7 +78,7 @@ void show_log(struct rev_info *opt, stru\n \t/*\n \t * And then the pretty-printed message itself\n \t */\n-\tlen = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev);\n+\tlen = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject);\n \tprintf(\"%s%s%s\", this_header, extra, sep);\n }\n \ndiff --git a/rev-list.c b/rev-list.c\nindex 89b3343..347f627 100644\n--- a/rev-list.c\n+++ b/rev-list.c\n@@ -83,7 +83,7 @@ static void show_commit(struct commit *c\n \t\tstatic char pretty_header[16384];\n \t\tpretty_print_commit(revs.commit_format, commit, ~0,\n \t\t\t\t    pretty_header, sizeof(pretty_header),\n-\t\t\t\t    revs.abbrev);\n+\t\t\t\t    revs.abbrev, NULL);\n \t\tprintf(\"%s%c\", pretty_header, hdr_termination);\n \t}\n \tfflush(stdout);\ndiff --git a/revision.h b/revision.h\nindex 48d7b4c..62759f7 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -58,6 +58,7 @@ struct rev_info {\n \tunsigned int\tabbrev;\n \tenum cmit_fmt\tcommit_format;\n \tstruct log_info *loginfo;\n+\tint\t\tnr, total;\n \n \t/* special limits */\n \tint max_count;\ndiff --git a/show-branch.c b/show-branch.c\nindex 268c57b..bbe26c2 100644\n--- a/show-branch.c\n+++ b/show-branch.c\n@@ -259,7 +259,7 @@ static void show_one_commit(struct commi\n \tstruct commit_name *name = commit->object.util;\n \tif (commit->object.parsed)\n \t\tpretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,\n-\t\t\t\t    pretty, sizeof(pretty), 0);\n+\t\t\t\t    pretty, sizeof(pretty), 0, NULL);\n \telse\n \t\tstrcpy(pretty, \"(unavailable)\");\n \tif (!strncmp(pretty, \"[PATCH] \", 8))\n-- \n1.3.1.g5f039\n"}]}