Teach fmt-patch about --numbered
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:

committed by
Junio C Hamano

parent
2448482b3d
commit
596524b33d
@ -137,6 +137,7 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
|
|||||||
struct rev_info rev;
|
struct rev_info rev;
|
||||||
int nr = 0, total, i, j;
|
int nr = 0, total, i, j;
|
||||||
int use_stdout = 0;
|
int use_stdout = 0;
|
||||||
|
int numbered = 0;
|
||||||
|
|
||||||
init_revisions(&rev);
|
init_revisions(&rev);
|
||||||
rev.commit_format = CMIT_FMT_EMAIL;
|
rev.commit_format = CMIT_FMT_EMAIL;
|
||||||
@ -156,6 +157,9 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
|
|||||||
for (i = 1, j = 1; i < argc; i++) {
|
for (i = 1, j = 1; i < argc; i++) {
|
||||||
if (!strcmp(argv[i], "--stdout"))
|
if (!strcmp(argv[i], "--stdout"))
|
||||||
use_stdout = 1;
|
use_stdout = 1;
|
||||||
|
else if (!strcmp(argv[i], "-n") ||
|
||||||
|
!strcmp(argv[i], "--numbered"))
|
||||||
|
numbered = 1;
|
||||||
else if (!strcmp(argv[i], "-o")) {
|
else if (!strcmp(argv[i], "-o")) {
|
||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
die ("Which directory?");
|
die ("Which directory?");
|
||||||
@ -186,11 +190,14 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
|
|||||||
list[nr - 1] = commit;
|
list[nr - 1] = commit;
|
||||||
}
|
}
|
||||||
total = nr;
|
total = nr;
|
||||||
|
if (numbered)
|
||||||
|
rev.total = total;
|
||||||
while (0 <= --nr) {
|
while (0 <= --nr) {
|
||||||
int shown;
|
int shown;
|
||||||
commit = list[nr];
|
commit = list[nr];
|
||||||
|
rev.nr = total - nr;
|
||||||
if (!use_stdout)
|
if (!use_stdout)
|
||||||
reopen_stdout(commit, total - nr);
|
reopen_stdout(commit, rev.nr);
|
||||||
shown = log_tree_commit(&rev, commit);
|
shown = log_tree_commit(&rev, commit);
|
||||||
free(commit->buffer);
|
free(commit->buffer);
|
||||||
commit->buffer = NULL;
|
commit->buffer = NULL;
|
||||||
|
5
commit.c
5
commit.c
@ -489,17 +489,14 @@ static int add_merge_info(enum cmit_fmt fmt, char *buf, const struct commit *com
|
|||||||
return offset;
|
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)
|
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)
|
||||||
{
|
{
|
||||||
int hdr = 1, body = 0;
|
int hdr = 1, body = 0;
|
||||||
unsigned long offset = 0;
|
unsigned long offset = 0;
|
||||||
int indent = 4;
|
int indent = 4;
|
||||||
int parents_shown = 0;
|
int parents_shown = 0;
|
||||||
const char *msg = commit->buffer;
|
const char *msg = commit->buffer;
|
||||||
const char *subject = NULL;
|
|
||||||
|
|
||||||
if (fmt == CMIT_FMT_EMAIL)
|
|
||||||
subject = "Subject: [PATCH] ";
|
|
||||||
if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)
|
if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)
|
||||||
indent = 0;
|
indent = 0;
|
||||||
|
|
||||||
|
2
commit.h
2
commit.h
@ -51,7 +51,7 @@ enum cmit_fmt {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern enum cmit_fmt get_commit_format(const char *arg);
|
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);
|
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);
|
||||||
|
|
||||||
/** Removes the first commit from a list sorted by date, and adds all
|
/** Removes the first commit from a list sorted by date, and adds all
|
||||||
* of its parents.
|
* of its parents.
|
||||||
|
15
log-tree.c
15
log-tree.c
@ -11,6 +11,7 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep)
|
|||||||
int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
|
int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
|
||||||
const char *extra;
|
const char *extra;
|
||||||
int len;
|
int len;
|
||||||
|
char* subject = NULL;
|
||||||
|
|
||||||
opt->loginfo = NULL;
|
opt->loginfo = NULL;
|
||||||
if (!opt->verbose_header) {
|
if (!opt->verbose_header) {
|
||||||
@ -38,10 +39,18 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep)
|
|||||||
* Print header line of header..
|
* Print header line of header..
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (opt->commit_format == CMIT_FMT_EMAIL)
|
if (opt->commit_format == CMIT_FMT_EMAIL) {
|
||||||
|
if (opt->total > 0) {
|
||||||
|
static char buffer[64];
|
||||||
|
snprintf(buffer, sizeof(buffer),
|
||||||
|
"Subject: [PATCH %d/%d] ",
|
||||||
|
opt->nr, opt->total);
|
||||||
|
subject = buffer;
|
||||||
|
} else
|
||||||
|
subject = "Subject: [PATCH] ";
|
||||||
printf("From %s Thu Apr 7 15:13:13 2005\n",
|
printf("From %s Thu Apr 7 15:13:13 2005\n",
|
||||||
sha1_to_hex(commit->object.sha1));
|
sha1_to_hex(commit->object.sha1));
|
||||||
else {
|
} else {
|
||||||
printf("%s%s",
|
printf("%s%s",
|
||||||
opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ",
|
opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ",
|
||||||
diff_unique_abbrev(commit->object.sha1, abbrev_commit));
|
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)
|
|||||||
/*
|
/*
|
||||||
* And then the pretty-printed message itself
|
* And then the pretty-printed message itself
|
||||||
*/
|
*/
|
||||||
len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev);
|
len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject);
|
||||||
printf("%s%s%s", this_header, extra, sep);
|
printf("%s%s%s", this_header, extra, sep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ static void show_commit(struct commit *commit)
|
|||||||
static char pretty_header[16384];
|
static char pretty_header[16384];
|
||||||
pretty_print_commit(revs.commit_format, commit, ~0,
|
pretty_print_commit(revs.commit_format, commit, ~0,
|
||||||
pretty_header, sizeof(pretty_header),
|
pretty_header, sizeof(pretty_header),
|
||||||
revs.abbrev);
|
revs.abbrev, NULL);
|
||||||
printf("%s%c", pretty_header, hdr_termination);
|
printf("%s%c", pretty_header, hdr_termination);
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
@ -58,6 +58,7 @@ struct rev_info {
|
|||||||
unsigned int abbrev;
|
unsigned int abbrev;
|
||||||
enum cmit_fmt commit_format;
|
enum cmit_fmt commit_format;
|
||||||
struct log_info *loginfo;
|
struct log_info *loginfo;
|
||||||
|
int nr, total;
|
||||||
|
|
||||||
/* special limits */
|
/* special limits */
|
||||||
int max_count;
|
int max_count;
|
||||||
|
@ -259,7 +259,7 @@ static void show_one_commit(struct commit *commit, int no_name)
|
|||||||
struct commit_name *name = commit->object.util;
|
struct commit_name *name = commit->object.util;
|
||||||
if (commit->object.parsed)
|
if (commit->object.parsed)
|
||||||
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
|
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
|
||||||
pretty, sizeof(pretty), 0);
|
pretty, sizeof(pretty), 0, NULL);
|
||||||
else
|
else
|
||||||
strcpy(pretty, "(unavailable)");
|
strcpy(pretty, "(unavailable)");
|
||||||
if (!strncmp(pretty, "[PATCH] ", 8))
|
if (!strncmp(pretty, "[PATCH] ", 8))
|
||||||
|
Reference in New Issue
Block a user