From 995c45279e270811f53b7ff8bf44a07ed3457ddc Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 11 Feb 2008 10:48:55 -0800 Subject: builtin-log.c: guard config parser from value=NULL format.subjectprefix configuration expects a string value. Signed-off-by: Junio C Hamano --- builtin-log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index dcc9f81793..9458428a8b 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -219,7 +219,7 @@ static int git_log_config(const char *var, const char *value) { if (!strcmp(var, "format.subjectprefix")) { if (!value) - die("format.subjectprefix without value"); + config_error_nonbool(var); fmt_patch_subject_prefix = xstrdup(value); return 0; } -- cgit v1.2.3 From 90f5c1864caf40ac2a0fef6bc771eab3ecc561b6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 11 Feb 2008 13:09:16 -0800 Subject: builtin-log.c: guard config parser from value=NULL format.suffix expects a string value. format.numbered is bool plus "auto" Signed-off-by: Junio C Hamano --- builtin-log.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 9458428a8b..99d69f0791 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -432,7 +432,7 @@ static int git_format_config(const char *var, const char *value) } if (!strcmp(var, "format.suffix")) { if (!value) - die("format.suffix without value"); + return config_error_nonbool(var); fmt_patch_suffix = xstrdup(value); return 0; } @@ -440,11 +440,10 @@ static int git_format_config(const char *var, const char *value) return 0; } if (!strcmp(var, "format.numbered")) { - if (!strcasecmp(value, "auto")) { + if (value && !strcasecmp(value, "auto")) { auto_number = 1; return 0; } - numbered = git_config_bool(var, value); return 0; } -- cgit v1.2.3 From 3d51e1b5b84bde24f9a19e3cee603f0b57f62001 Mon Sep 17 00:00:00 2001 From: Martin Koegler Date: Mon, 18 Feb 2008 08:31:56 +0100 Subject: check return code of prepare_revision_walk A failure in prepare_revision_walk can be caused by a not parseable object. Signed-off-by: Martin Koegler Signed-off-by: Junio C Hamano --- builtin-log.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 99d69f0791..5fea64abad 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -197,7 +197,8 @@ static int cmd_log_walk(struct rev_info *rev) if (rev->early_output) setup_early_output(rev); - prepare_revision_walk(rev); + if (prepare_revision_walk(rev)) + die("revision walk setup failed"); if (rev->early_output) finish_early_output(rev); @@ -556,7 +557,8 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids, const cha o2->flags ^= UNINTERESTING; add_pending_object(&check_rev, o1, "o1"); add_pending_object(&check_rev, o2, "o2"); - prepare_revision_walk(&check_rev); + if (prepare_revision_walk(&check_rev)) + die("revision walk setup failed"); while ((commit = get_revision(&check_rev)) != NULL) { /* ignore merges */ @@ -781,7 +783,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) if (!use_stdout) realstdout = xfdopen(xdup(1), "w"); - prepare_revision_walk(&rev); + if (prepare_revision_walk(&rev)) + die("revision walk setup failed"); while ((commit = get_revision(&rev)) != NULL) { /* ignore merges */ if (commit->parents && commit->parents->next) @@ -923,7 +926,8 @@ int cmd_cherry(int argc, const char **argv, const char *prefix) die("Unknown commit %s", limit); /* reverse the list of commits */ - prepare_revision_walk(&revs); + if (prepare_revision_walk(&revs)) + die("revision walk setup failed"); while ((commit = get_revision(&revs)) != NULL) { /* ignore merges */ if (commit->parents && commit->parents->next) -- cgit v1.2.3 From 6b2f2d9805dd22c6f74957e0d76a1d2921b40c16 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Mon, 18 Feb 2008 08:26:03 +0100 Subject: Add color.ui variable which globally enables colorization if set Signed-off-by: Matthias Kestenholz Signed-off-by: Junio C Hamano --- builtin-log.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 99d69f0791..f2216d3187 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -5,6 +5,7 @@ * 2006 Junio Hamano */ #include "cache.h" +#include "color.h" #include "commit.h" #include "diff.h" #include "revision.h" @@ -235,6 +236,10 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix) struct rev_info rev; git_config(git_log_config); + + if (diff_use_color_default == -1) + diff_use_color_default = git_use_color_default; + init_revisions(&rev, prefix); rev.diff = 1; rev.simplify_history = 0; @@ -307,6 +312,10 @@ int cmd_show(int argc, const char **argv, const char *prefix) int i, count, ret = 0; git_config(git_log_config); + + if (diff_use_color_default == -1) + diff_use_color_default = git_use_color_default; + init_revisions(&rev, prefix); rev.diff = 1; rev.combine_merges = 1; @@ -367,6 +376,10 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix) struct rev_info rev; git_config(git_log_config); + + if (diff_use_color_default == -1) + diff_use_color_default = git_use_color_default; + init_revisions(&rev, prefix); init_reflog_walk(&rev.reflog_info); rev.abbrev_commit = 1; @@ -395,6 +408,10 @@ int cmd_log(int argc, const char **argv, const char *prefix) struct rev_info rev; git_config(git_log_config); + + if (diff_use_color_default == -1) + diff_use_color_default = git_use_color_default; + init_revisions(&rev, prefix); rev.always_show_header = 1; cmd_log_init(argc, argv, prefix, &rev); -- cgit v1.2.3 From e1a37346210da8b165037984e02f750a6a135480 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Mon, 18 Feb 2008 22:56:06 -0500 Subject: Improve message-id generation flow control for format-patch Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- builtin-log.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 99d69f0791..4f08ca40aa 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -575,16 +575,19 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids, const cha o2->flags = flags2; } -static void gen_message_id(char *dest, unsigned int length, char *base) +static void gen_message_id(struct rev_info *info, char *base) { const char *committer = git_committer_info(IDENT_WARN_ON_NO_NAME); const char *email_start = strrchr(committer, '<'); const char *email_end = strrchr(committer, '>'); - if(!email_start || !email_end || email_start > email_end - 1) + struct strbuf buf; + if (!email_start || !email_end || email_start > email_end - 1) die("Could not extract email from committer identity."); - snprintf(dest, length, "%s.%lu.git.%.*s", base, - (unsigned long) time(NULL), - (int)(email_end - email_start - 1), email_start + 1); + strbuf_init(&buf, 0); + strbuf_addf(&buf, "%s.%lu.git.%.*s", base, + (unsigned long) time(NULL), + (int)(email_end - email_start - 1), email_start + 1); + info->message_id = strbuf_detach(&buf, NULL); } static const char *clean_message_id(const char *msg_id) @@ -625,8 +628,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) const char *in_reply_to = NULL; struct patch_ids ids; char *add_signoff = NULL; - char message_id[1024]; - char ref_message_id[1024]; git_config(git_format_config); init_revisions(&rev, prefix); @@ -809,15 +810,13 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) rev.nr = total - nr + (start_number - 1); /* Make the second and subsequent mails replies to the first */ if (thread) { - if (nr == (total - 2)) { - strncpy(ref_message_id, message_id, - sizeof(ref_message_id)); - ref_message_id[sizeof(ref_message_id)-1]='\0'; - rev.ref_message_id = ref_message_id; + if (rev.message_id) { + if (rev.ref_message_id) + free(rev.message_id); + else + rev.ref_message_id = rev.message_id; } - gen_message_id(message_id, sizeof(message_id), - sha1_to_hex(commit->object.sha1)); - rev.message_id = message_id; + gen_message_id(&rev, sha1_to_hex(commit->object.sha1)); } if (!use_stdout) if (reopen_stdout(commit, rev.nr, keep_subject, -- cgit v1.2.3 From a5a27c79b7e77e28462b6d089e827391b67d3e5f Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Mon, 18 Feb 2008 22:56:13 -0500 Subject: Add a --cover-letter option to format-patch If --cover-letter is provided, generate a cover letter message before the patches, numbered 0. Original patch thanks to Johannes Schindelin Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- builtin-log.c | 232 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 174 insertions(+), 58 deletions(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 4f08ca40aa..3dc765011c 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -14,6 +14,7 @@ #include "reflog-walk.h" #include "patch-ids.h" #include "refs.h" +#include "run-command.h" static int default_show_root = 1; static const char *fmt_patch_subject_prefix = "PATCH"; @@ -452,74 +453,81 @@ static int git_format_config(const char *var, const char *value) } +static const char *get_oneline_for_filename(struct commit *commit, + int keep_subject) +{ + static char filename[PATH_MAX]; + char *sol; + int len = 0; + int suffix_len = strlen(fmt_patch_suffix) + 1; + + sol = strstr(commit->buffer, "\n\n"); + if (!sol) + filename[0] = '\0'; + else { + int j, space = 0; + + sol += 2; + /* strip [PATCH] or [PATCH blabla] */ + if (!keep_subject && !prefixcmp(sol, "[PATCH")) { + char *eos = strchr(sol + 6, ']'); + if (eos) { + while (isspace(*eos)) + eos++; + sol = eos; + } + } + + for (j = 0; + j < FORMAT_PATCH_NAME_MAX - suffix_len - 5 && + len < sizeof(filename) - suffix_len && + sol[j] && sol[j] != '\n'; + j++) { + if (istitlechar(sol[j])) { + if (space) { + filename[len++] = '-'; + space = 0; + } + filename[len++] = sol[j]; + if (sol[j] == '.') + while (sol[j + 1] == '.') + j++; + } else + space = 1; + } + while (filename[len - 1] == '.' + || filename[len - 1] == '-') + len--; + filename[len] = '\0'; + } + return filename; +} + static FILE *realstdout = NULL; static const char *output_directory = NULL; -static int reopen_stdout(struct commit *commit, int nr, int keep_subject, - int numbered_files) +static int reopen_stdout(const char *oneline, int nr, int total) { char filename[PATH_MAX]; - char *sol; int len = 0; int suffix_len = strlen(fmt_patch_suffix) + 1; if (output_directory) { - if (strlen(output_directory) >= + len = snprintf(filename, sizeof(filename), "%s", + output_directory); + if (len >= sizeof(filename) - FORMAT_PATCH_NAME_MAX - suffix_len) return error("name of output directory is too long"); - strlcpy(filename, output_directory, sizeof(filename) - suffix_len); - len = strlen(filename); if (filename[len - 1] != '/') filename[len++] = '/'; } - if (numbered_files) { - sprintf(filename + len, "%d", nr); - len = strlen(filename); - - } else { - sprintf(filename + len, "%04d", nr); - len = strlen(filename); - - sol = strstr(commit->buffer, "\n\n"); - if (sol) { - int j, space = 1; - - sol += 2; - /* strip [PATCH] or [PATCH blabla] */ - if (!keep_subject && !prefixcmp(sol, "[PATCH")) { - char *eos = strchr(sol + 6, ']'); - if (eos) { - while (isspace(*eos)) - eos++; - sol = eos; - } - } - - for (j = 0; - j < FORMAT_PATCH_NAME_MAX - suffix_len - 5 && - len < sizeof(filename) - suffix_len && - sol[j] && sol[j] != '\n'; - j++) { - if (istitlechar(sol[j])) { - if (space) { - filename[len++] = '-'; - space = 0; - } - filename[len++] = sol[j]; - if (sol[j] == '.') - while (sol[j + 1] == '.') - j++; - } else - space = 1; - } - while (filename[len - 1] == '.' - || filename[len - 1] == '-') - len--; - filename[len] = 0; - } - if (len + suffix_len >= sizeof(filename)) - return error("Patch pathname too long"); + if (!oneline) + len += sprintf(filename + len, "%d", nr); + else { + len += sprintf(filename + len, "%04d-", nr); + len += snprintf(filename + len, sizeof(filename) - len - 1 + - suffix_len, "%s", oneline); strcpy(filename + len, fmt_patch_suffix); } @@ -590,6 +598,76 @@ static void gen_message_id(struct rev_info *info, char *base) info->message_id = strbuf_detach(&buf, NULL); } +static void make_cover_letter(struct rev_info *rev, + int use_stdout, int numbered, int numbered_files, + struct commit *origin, struct commit *head) +{ + const char *committer; + const char *origin_sha1, *head_sha1; + const char *argv[7]; + const char *subject_start = NULL; + const char *body = "*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n"; + const char *msg; + const char *extra_headers = rev->extra_headers; + struct strbuf sb; + const char *encoding = "utf-8"; + + if (rev->commit_format != CMIT_FMT_EMAIL) + die("Cover letter needs email format"); + + if (!use_stdout && reopen_stdout(numbered_files ? + NULL : "cover-letter", 0, rev->total)) + return; + + origin_sha1 = sha1_to_hex(origin ? origin->object.sha1 : null_sha1); + head_sha1 = sha1_to_hex(head->object.sha1); + + log_write_email_headers(rev, head_sha1, &subject_start, &extra_headers); + + committer = git_committer_info(0); + + msg = body; + strbuf_init(&sb, 0); + pp_user_info(NULL, CMIT_FMT_EMAIL, &sb, committer, DATE_RFC2822, + encoding); + pp_title_line(CMIT_FMT_EMAIL, &msg, &sb, subject_start, extra_headers, + encoding, 0); + pp_remainder(CMIT_FMT_EMAIL, &msg, &sb, 0); + printf("%s\n", sb.buf); + + strbuf_release(&sb); + + /* + * We can only do diffstat with a unique reference point, and + * log is a bit tricky, so just skip it. + */ + if (!origin) + return; + + argv[0] = "shortlog"; + argv[1] = head_sha1; + argv[2] = "--not"; + argv[3] = origin_sha1; + argv[4] = "--"; + argv[5] = NULL; + fflush(stdout); + run_command_v_opt(argv, RUN_GIT_CMD); + + argv[0] = "diff"; + argv[1] = "--stat"; + argv[2] = "--summary"; + argv[3] = head_sha1; + argv[4] = "--not"; + argv[5] = origin_sha1; + argv[6] = "--"; + argv[7] = NULL; + fflush(stdout); + run_command_v_opt(argv, RUN_GIT_CMD); + + fflush(stdout); + printf("\n"); +} + static const char *clean_message_id(const char *msg_id) { char ch; @@ -625,6 +703,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) int subject_prefix = 0; int ignore_if_in_upstream = 0; int thread = 0; + int cover_letter = 0; + struct commit *origin = NULL, *head = NULL; const char *in_reply_to = NULL; struct patch_ids ids; char *add_signoff = NULL; @@ -724,6 +804,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) rev.subject_prefix = argv[i] + 17; } else if (!prefixcmp(argv[i], "--suffix=")) fmt_patch_suffix = argv[i] + 9; + else if (!strcmp(argv[i], "--cover-letter")) + cover_letter = 1; else argv[j++] = argv[i]; } @@ -775,6 +857,25 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) * get_revision() to do the usual traversal. */ } + if (cover_letter) { + /* remember the range */ + int negative_count = 0; + int i; + for (i = 0; i < rev.pending.nr; i++) { + struct object *o = rev.pending.objects[i].item; + if (o->flags & UNINTERESTING) { + origin = (struct commit *)o; + negative_count++; + } else + head = (struct commit *)o; + } + /* Multiple origins don't work for diffstat. */ + if (negative_count > 1) + origin = NULL; + /* We can't generate a cover letter without any patches */ + if (!head) + return 0; + } if (ignore_if_in_upstream) get_patch_ids(&rev, &ids, prefix); @@ -801,16 +902,31 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) numbered = 1; if (numbered) rev.total = total + start_number - 1; - rev.add_signoff = add_signoff; if (in_reply_to) rev.ref_message_id = clean_message_id(in_reply_to); + if (cover_letter) { + if (thread) + gen_message_id(&rev, "cover"); + make_cover_letter(&rev, use_stdout, numbered, numbered_files, + origin, head); + total++; + start_number--; + } + rev.add_signoff = add_signoff; while (0 <= --nr) { int shown; commit = list[nr]; rev.nr = total - nr + (start_number - 1); /* Make the second and subsequent mails replies to the first */ if (thread) { + /* Have we already had a message ID? */ if (rev.message_id) { + /* + * If we've got the ID to be a reply + * to, discard the current ID; + * otherwise, make everything a reply + * to that. + */ if (rev.ref_message_id) free(rev.message_id); else @@ -818,10 +934,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) } gen_message_id(&rev, sha1_to_hex(commit->object.sha1)); } - if (!use_stdout) - if (reopen_stdout(commit, rev.nr, keep_subject, - numbered_files)) - die("Failed to create output files"); + if (!use_stdout && reopen_stdout(numbered_files ? NULL : + get_oneline_for_filename(commit, keep_subject), + rev.nr, rev.total)) + die("Failed to create output files"); shown = log_tree_commit(&rev, commit); free(commit->buffer); commit->buffer = NULL; -- cgit v1.2.3 From 7d22708b254d4ec28cd865dc5489d175ee6d65c2 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Tue, 19 Feb 2008 02:40:31 -0500 Subject: Fix format.headers not ending with a newline Now each value of format.headers will always be treated as a single valid header, and newlines will be inserted between them as needed. Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- builtin-log.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 3dc765011c..fe1a2d78eb 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -425,10 +425,14 @@ static int git_format_config(const char *var, const char *value) if (!value) die("format.headers without value"); len = strlen(value); - extra_headers_size += len + 1; + while (value[len - 1] == '\n') + len--; + extra_headers_size += len + 2; extra_headers = xrealloc(extra_headers, extra_headers_size); - extra_headers[extra_headers_size - len - 1] = 0; + extra_headers[extra_headers_size - len - 2] = 0; strcat(extra_headers, value); + extra_headers[extra_headers_size - 2] = '\n'; + extra_headers[extra_headers_size - 1] = 0; return 0; } if (!strcmp(var, "format.suffix")) { -- cgit v1.2.3 From 3ee79d9f59684778151804c02cc6ad155b30efde Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Tue, 19 Feb 2008 02:40:33 -0500 Subject: Combine To: and Cc: headers RFC 2822 only permits a single To: header and a single Cc: header, so we need to turn multiple values of each of these into a list. This will be particularly significant with a command-line option to add Cc: headers, where the user can't make sure to configure valid header sets in any easy way. Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- builtin-log.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 14 deletions(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index fe1a2d78eb..71ae55b9eb 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -411,28 +411,47 @@ static int istitlechar(char c) (c >= '0' && c <= '9') || c == '.' || c == '_'; } -static char *extra_headers = NULL; -static int extra_headers_size = 0; static const char *fmt_patch_suffix = ".patch"; static int numbered = 0; static int auto_number = 0; +static char **extra_hdr; +static int extra_hdr_nr; +static int extra_hdr_alloc; + +static char **extra_to; +static int extra_to_nr; +static int extra_to_alloc; + +static char **extra_cc; +static int extra_cc_nr; +static int extra_cc_alloc; + +static void add_header(const char *value) +{ + int len = strlen(value); + while (value[len - 1] == '\n') + len--; + if (!strncasecmp(value, "to: ", 4)) { + ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc); + extra_to[extra_to_nr++] = xstrndup(value + 4, len - 4); + return; + } + if (!strncasecmp(value, "cc: ", 4)) { + ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc); + extra_cc[extra_cc_nr++] = xstrndup(value + 4, len - 4); + return; + } + ALLOC_GROW(extra_hdr, extra_hdr_nr + 1, extra_hdr_alloc); + extra_hdr[extra_hdr_nr++] = xstrndup(value, len); +} + static int git_format_config(const char *var, const char *value) { if (!strcmp(var, "format.headers")) { - int len; - if (!value) die("format.headers without value"); - len = strlen(value); - while (value[len - 1] == '\n') - len--; - extra_headers_size += len + 2; - extra_headers = xrealloc(extra_headers, extra_headers_size); - extra_headers[extra_headers_size - len - 2] = 0; - strcat(extra_headers, value); - extra_headers[extra_headers_size - 2] = '\n'; - extra_headers[extra_headers_size - 1] = 0; + add_header(value); return 0; } if (!strcmp(var, "format.suffix")) { @@ -712,6 +731,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) const char *in_reply_to = NULL; struct patch_ids ids; char *add_signoff = NULL; + struct strbuf buf; git_config(git_format_config); init_revisions(&rev, prefix); @@ -724,7 +744,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) DIFF_OPT_SET(&rev.diffopt, RECURSIVE); rev.subject_prefix = fmt_patch_subject_prefix; - rev.extra_headers = extra_headers; /* * Parse the arguments before setup_revisions(), or something @@ -815,6 +834,37 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) } argc = j; + strbuf_init(&buf, 0); + + for (i = 0; i < extra_hdr_nr; i++) { + strbuf_addstr(&buf, extra_hdr[i]); + strbuf_addch(&buf, '\n'); + } + + if (extra_to_nr) + strbuf_addstr(&buf, "To: "); + for (i = 0; i < extra_to_nr; i++) { + if (i) + strbuf_addstr(&buf, " "); + strbuf_addstr(&buf, extra_to[i]); + if (i + 1 < extra_to_nr) + strbuf_addch(&buf, ','); + strbuf_addch(&buf, '\n'); + } + + if (extra_cc_nr) + strbuf_addstr(&buf, "Cc: "); + for (i = 0; i < extra_cc_nr; i++) { + if (i) + strbuf_addstr(&buf, " "); + strbuf_addstr(&buf, extra_cc[i]); + if (i + 1 < extra_cc_nr) + strbuf_addch(&buf, ','); + strbuf_addch(&buf, '\n'); + } + + rev.extra_headers = strbuf_detach(&buf, 0); + if (start_number < 0) start_number = 1; if (numbered && keep_subject) -- cgit v1.2.3 From 736cc67dd7f4f8004215e24f876178e6f34c191d Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Tue, 19 Feb 2008 02:40:35 -0500 Subject: Support a --cc= option in format-patch When you have particular reviewers you want to sent particular series to, it's nice to be able to generate the whole series with them as additional recipients, without configuring them into your general headers or adding them by hand afterwards. Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- builtin-log.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 71ae55b9eb..0b348eb6b3 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -771,6 +771,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) die("Need a number for --start-number"); start_number = strtol(argv[i], NULL, 10); } + else if (!prefixcmp(argv[i], "--cc=")) { + ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc); + extra_cc[extra_cc_nr++] = xstrdup(argv[i] + 5); + } else if (!strcmp(argv[i], "-k") || !strcmp(argv[i], "--keep-subject")) { keep_subject = 1; -- cgit v1.2.3 From 2bda2cf4f966ae50d08a32a3839f930c1daac907 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Mon, 25 Feb 2008 18:24:17 -0500 Subject: Improve collection of information for format-patch --cover-letter Use the "boundary" feature to find the origin (or find that there are multiple origins), and use the actual list of commits to pass to shortlog. This makes all cover letter include shortlogs, and all cover letters for series with a single boundary commit include diffstats (if there are multiple boundary commits it's unclear what would be meaningful as a diffstat). Note that the single boundary test is empirical, not theoretical; even a -2 limiting condition will give a diffstat if there's only one boundary commit in this particular case. Signed-off-by: Daniel Barkalow --- builtin-log.c | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 0b348eb6b3..3112d96db0 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -15,6 +15,7 @@ #include "patch-ids.h" #include "refs.h" #include "run-command.h" +#include "shortlog.h" static int default_show_root = 1; static const char *fmt_patch_subject_prefix = "PATCH"; @@ -621,9 +622,10 @@ static void gen_message_id(struct rev_info *info, char *base) info->message_id = strbuf_detach(&buf, NULL); } -static void make_cover_letter(struct rev_info *rev, - int use_stdout, int numbered, int numbered_files, - struct commit *origin, struct commit *head) +static void make_cover_letter(struct rev_info *rev, int use_stdout, + int numbered, int numbered_files, + struct commit *origin, + int nr, struct commit **list, struct commit *head) { const char *committer; const char *origin_sha1, *head_sha1; @@ -632,7 +634,9 @@ static void make_cover_letter(struct rev_info *rev, const char *body = "*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n"; const char *msg; const char *extra_headers = rev->extra_headers; + struct shortlog log; struct strbuf sb; + int i; const char *encoding = "utf-8"; if (rev->commit_format != CMIT_FMT_EMAIL) @@ -642,7 +646,6 @@ static void make_cover_letter(struct rev_info *rev, NULL : "cover-letter", 0, rev->total)) return; - origin_sha1 = sha1_to_hex(origin ? origin->object.sha1 : null_sha1); head_sha1 = sha1_to_hex(head->object.sha1); log_write_email_headers(rev, head_sha1, &subject_start, &extra_headers); @@ -660,21 +663,19 @@ static void make_cover_letter(struct rev_info *rev, strbuf_release(&sb); + shortlog_init(&log); + for (i = 0; i < nr; i++) + shortlog_add_commit(&log, list[i]); + + shortlog_output(&log); + /* - * We can only do diffstat with a unique reference point, and - * log is a bit tricky, so just skip it. + * We can only do diffstat with a unique reference point */ if (!origin) return; - argv[0] = "shortlog"; - argv[1] = head_sha1; - argv[2] = "--not"; - argv[3] = origin_sha1; - argv[4] = "--"; - argv[5] = NULL; - fflush(stdout); - run_command_v_opt(argv, RUN_GIT_CMD); + origin_sha1 = sha1_to_hex(origin->object.sha1); argv[0] = "diff"; argv[1] = "--stat"; @@ -727,6 +728,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) int ignore_if_in_upstream = 0; int thread = 0; int cover_letter = 0; + int boundary_count = 0; struct commit *origin = NULL, *head = NULL; const char *in_reply_to = NULL; struct patch_ids ids; @@ -917,19 +919,12 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) } if (cover_letter) { /* remember the range */ - int negative_count = 0; int i; for (i = 0; i < rev.pending.nr; i++) { struct object *o = rev.pending.objects[i].item; - if (o->flags & UNINTERESTING) { - origin = (struct commit *)o; - negative_count++; - } else + if (!(o->flags & UNINTERESTING)) head = (struct commit *)o; } - /* Multiple origins don't work for diffstat. */ - if (negative_count > 1) - origin = NULL; /* We can't generate a cover letter without any patches */ if (!head) return 0; @@ -941,8 +936,17 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) if (!use_stdout) realstdout = xfdopen(xdup(1), "w"); - prepare_revision_walk(&rev); + if (prepare_revision_walk(&rev)) + die("revision walk setup failed"); + rev.boundary = 1; while ((commit = get_revision(&rev)) != NULL) { + if (commit->object.flags & BOUNDARY) { + fprintf(stderr, "Boundary %s\n", sha1_to_hex(commit->object.sha1)); + boundary_count++; + origin = (boundary_count == 1) ? commit : NULL; + continue; + } + /* ignore merges */ if (commit->parents && commit->parents->next) continue; @@ -966,7 +970,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) if (thread) gen_message_id(&rev, "cover"); make_cover_letter(&rev, use_stdout, numbered, numbered_files, - origin, head); + origin, nr, list, head); total++; start_number--; } -- cgit v1.2.3 From 42be5cc61202014d4f1df61f9791067191f9393d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 27 Feb 2008 22:08:57 -0800 Subject: format-patch: remove a leftover debugging message Signed-off-by: Junio C Hamano --- builtin-log.c | 1 - 1 file changed, 1 deletion(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 3209ea5c6d..836b61ec57 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -960,7 +960,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) rev.boundary = 1; while ((commit = get_revision(&rev)) != NULL) { if (commit->object.flags & BOUNDARY) { - fprintf(stderr, "Boundary %s\n", sha1_to_hex(commit->object.sha1)); boundary_count++; origin = (boundary_count == 1) ? commit : NULL; continue; -- cgit v1.2.3 From 39fe578bdcc318308bc5d75efa04bd4bfc3a4f23 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Thu, 28 Feb 2008 12:14:13 -0500 Subject: Use diff_tree() directly in making cover letter Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- builtin-log.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 836b61ec57..bbadbc0de2 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -647,8 +647,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, int nr, struct commit **list, struct commit *head) { const char *committer; - const char *origin_sha1, *head_sha1; - const char *argv[7]; + char *head_sha1; const char *subject_start = NULL; const char *body = "*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n"; const char *msg; @@ -657,6 +656,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, struct strbuf sb; int i; const char *encoding = "utf-8"; + struct diff_options opts; if (rev->commit_format != CMIT_FMT_EMAIL) die("Cover letter needs email format"); @@ -694,20 +694,17 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, if (!origin) return; - origin_sha1 = sha1_to_hex(origin->object.sha1); + diff_setup(&opts); + opts.output_format |= DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT; - argv[0] = "diff"; - argv[1] = "--stat"; - argv[2] = "--summary"; - argv[3] = head_sha1; - argv[4] = "--not"; - argv[5] = origin_sha1; - argv[6] = "--"; - argv[7] = NULL; - fflush(stdout); - run_command_v_opt(argv, RUN_GIT_CMD); + diff_setup_done(&opts); + + diff_tree_sha1(origin->tree->object.sha1, + head->tree->object.sha1, + "", &opts); + diffcore_std(&opts); + diff_flush(&opts); - fflush(stdout); printf("\n"); } -- cgit v1.2.3 From 5d02294c776c46f0d454470c66c16fe9f08fad3d Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 2 Mar 2008 15:53:04 +0000 Subject: format-patch: use the diff options for the cover letter, too Earlier, when you called "git format-patch --cover-letter -M", the diffstat in the cover letter would not inherit the "-M". Now it does. While at it, add a few "|| break" statements in the test's loops; otherwise, breakages inside the loops would not be caught. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-log.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index bbadbc0de2..fd9b3ae95e 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -694,8 +694,8 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, if (!origin) return; - diff_setup(&opts); - opts.output_format |= DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT; + memcpy(&opts, &rev->diffopt, sizeof(opts)); + opts.output_format = DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT; diff_setup_done(&opts); -- cgit v1.2.3 From 859c4fbef589841585f8f21cc567b7016681df7a Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 2 Mar 2008 15:53:39 +0000 Subject: format-patch: wrap cover-letter's shortlog sensibly Earlier, overly-long onelines would not be wrapped at all, and indented with 6 spaces. Instead, we now wrap around at 72 characters, with a first-line indent of 2 spaces, and the rest with 4 spaces. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-log.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index fd9b3ae95e..fe8fc6f22a 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -683,6 +683,10 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, strbuf_release(&sb); shortlog_init(&log); + log.wrap_lines = 1; + log.wrap = 72; + log.in1 = 2; + log.in2 = 4; for (i = 0; i < nr; i++) shortlog_add_commit(&log, list[i]); -- cgit v1.2.3 From 94c22a5e7b4247d7d6453272c4425d81071d2689 Mon Sep 17 00:00:00 2001 From: Denis Cheng Date: Sun, 2 Mar 2008 17:05:53 +0800 Subject: log/show/whatchanged: introduce format.pretty configuration When running log/show/whatchanged from the command line, the user may want to use a preferred format without having to pass --pretty= option every time from the command line. This teaches these three commands to honor a new configuration variable, format.pretty. The --pretty option given from the command line will override the configured format. The earlier patch fixed the in-tree callers that run these commands for purposes other than showing the output directly to the end user (the only other in-tree caller is "git bisect visualize", whose output directly goes to the end user and should be affected by this patch). Similar fixes will be needed for end-user scripts that parse the output from these commands and expect them to be in the default pretty format. Signed-off-by: Denis Cheng Signed-off-by: Junio C Hamano --- builtin-log.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index fe8fc6f22a..d983cbc7bc 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -20,6 +20,7 @@ static int default_show_root = 1; static const char *fmt_patch_subject_prefix = "PATCH"; +static const char *fmt_pretty; static void add_name_decoration(const char *prefix, const char *name, struct object *obj) { @@ -54,6 +55,8 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix, rev->abbrev = DEFAULT_ABBREV; rev->commit_format = CMIT_FMT_DEFAULT; + if (fmt_pretty) + rev->commit_format = get_commit_format(fmt_pretty); rev->verbose_header = 1; DIFF_OPT_SET(&rev->diffopt, RECURSIVE); rev->show_root_diff = default_show_root; @@ -221,6 +224,8 @@ static int cmd_log_walk(struct rev_info *rev) static int git_log_config(const char *var, const char *value) { + if (!strcmp(var, "format.pretty")) + return git_config_string(&fmt_pretty, var, value); if (!strcmp(var, "format.subjectprefix")) { if (!value) config_error_nonbool(var); -- cgit v1.2.3 From 4da45bef56e1547eb6525015ada0fdfc01d8295b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 7 Apr 2008 17:11:34 -0700 Subject: log: teach "terminator" vs "separator" mode to "--pretty=format" This attached patch introduces a single bit "use_terminator" in "struct rev_info", which is normally false (i.e. most formats use separator semantics) but by flipping it to true, you can ask for terminator semantics just like oneline format does. The function get_commit_format(), which is what parses "--pretty=" option, now takes a pointer to "struct rev_info" and updates its commit_format and use_terminator fields. It used to return the value of type "enum cmit_fmt", but all the callers assigned it to rev->commit_format. There are only two cases the code turns use_terminator on. Obviously, the traditional oneline format (--pretty=oneline) is one of them, and the new case is --pretty=tformat:... that acts like --pretty=format:... but flips the bit on. With this, "--pretty=tformat:%H %s" acts like --pretty=oneline. Signed-off-by: Junio C Hamano --- builtin-log.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 5c00725f03..1670d0b334 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -56,7 +56,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix, rev->abbrev = DEFAULT_ABBREV; rev->commit_format = CMIT_FMT_DEFAULT; if (fmt_pretty) - rev->commit_format = get_commit_format(fmt_pretty); + get_commit_format(fmt_pretty, rev); rev->verbose_header = 1; DIFF_OPT_SET(&rev->diffopt, RECURSIVE); rev->show_root_diff = default_show_root; @@ -400,6 +400,7 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix) * allow us to set a different default. */ rev.commit_format = CMIT_FMT_ONELINE; + rev.use_terminator = 1; rev.always_show_header = 1; /* -- cgit v1.2.3 From fe8928e6e802f8519e133f085783fb664f1a0d6b Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sat, 26 Apr 2008 23:19:06 +0200 Subject: git-format-patch: add a new format.cc configuration variable Some projects prefer to always CC patches to a given mailing list. In these cases, it's handy to configure that address once. Signed-off-by: Miklos Vajna Signed-off-by: Junio C Hamano --- builtin-log.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 1670d0b334..d7907c942f 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -485,6 +485,13 @@ static int git_format_config(const char *var, const char *value) fmt_patch_suffix = xstrdup(value); return 0; } + if (!strcmp(var, "format.cc")) { + if (!value) + return config_error_nonbool(var); + ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc); + extra_cc[extra_cc_nr++] = xstrdup(value); + return 0; + } if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) { return 0; } -- cgit v1.2.3 From 028656552bc758b192027c25a1143f1c6ca66d64 Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Tue, 29 Apr 2008 01:32:59 -0700 Subject: Remove dead code: show_log() sep argument and diff_options.msg_sep These variables were made unnecessary by commit 3969cf7db1a13a78f3b7a36d8c1084bbe0a53459. Signed-off-by: Adam Simpkins Signed-off-by: Junio C Hamano --- builtin-log.c | 1 - 1 file changed, 1 deletion(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 1670d0b334..256bbac93a 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -770,7 +770,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) rev.diff = 1; rev.combine_merges = 0; rev.ignore_merges = 1; - rev.diffopt.msg_sep = ""; DIFF_OPT_SET(&rev.diffopt, RECURSIVE); rev.subject_prefix = fmt_patch_subject_prefix; -- cgit v1.2.3 From 37c22a4bf801403f71a5e9674d8e314ce575945e Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Fri, 9 May 2008 19:55:43 -0300 Subject: git-format-patch: add --no-binary to omit binary changes in the patch. Add a new option --no-binary to git-format-patch so that no binary changes are included in the generated patches, only notices that those files changed. This generate patches that cannot be applied, but still is useful for generating mails for code review purposes. See also: commit e47f306d4bf964def1a0b29e8f7cea419471dffd, where --binary option was turned on by default. Signed-off-by: Caio Marcelo de Oliveira Filho Signed-off-by: Junio C Hamano --- builtin-log.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 256bbac93a..80a01f8d44 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -757,6 +757,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) int thread = 0; int cover_letter = 0; int boundary_count = 0; + int no_binary_diff = 0; struct commit *origin = NULL, *head = NULL; const char *in_reply_to = NULL; struct patch_ids ids; @@ -862,6 +863,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) fmt_patch_suffix = argv[i] + 9; else if (!strcmp(argv[i], "--cover-letter")) cover_letter = 1; + else if (!strcmp(argv[i], "--no-binary")) + no_binary_diff = 1; else argv[j++] = argv[i]; } @@ -914,7 +917,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) if (!rev.diffopt.output_format) rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH; - if (!DIFF_OPT_TST(&rev.diffopt, TEXT)) + if (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff) DIFF_OPT_SET(&rev.diffopt, BINARY); if (!output_directory && !use_stdout) -- cgit v1.2.3 From ef90d6d4208a5130185b04f06e5f90a5f9959fe3 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 14 May 2008 18:46:53 +0100 Subject: Provide git_config with a callback-data parameter git_config() only had a function parameter, but no callback data parameter. This assumes that all callback functions only modify global variables. With this patch, every callback gets a void * parameter, and it is hoped that this will help the libification effort. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-log.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 80a01f8d44..addc7098cf 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -222,7 +222,7 @@ static int cmd_log_walk(struct rev_info *rev) return 0; } -static int git_log_config(const char *var, const char *value) +static int git_log_config(const char *var, const char *value, void *cb) { if (!strcmp(var, "format.pretty")) return git_config_string(&fmt_pretty, var, value); @@ -236,14 +236,14 @@ static int git_log_config(const char *var, const char *value) default_show_root = git_config_bool(var, value); return 0; } - return git_diff_ui_config(var, value); + return git_diff_ui_config(var, value, cb); } int cmd_whatchanged(int argc, const char **argv, const char *prefix) { struct rev_info rev; - git_config(git_log_config); + git_config(git_log_config, NULL); if (diff_use_color_default == -1) diff_use_color_default = git_use_color_default; @@ -319,7 +319,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) struct object_array_entry *objects; int i, count, ret = 0; - git_config(git_log_config); + git_config(git_log_config, NULL); if (diff_use_color_default == -1) diff_use_color_default = git_use_color_default; @@ -383,7 +383,7 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix) { struct rev_info rev; - git_config(git_log_config); + git_config(git_log_config, NULL); if (diff_use_color_default == -1) diff_use_color_default = git_use_color_default; @@ -416,7 +416,7 @@ int cmd_log(int argc, const char **argv, const char *prefix) { struct rev_info rev; - git_config(git_log_config); + git_config(git_log_config, NULL); if (diff_use_color_default == -1) diff_use_color_default = git_use_color_default; @@ -471,7 +471,7 @@ static void add_header(const char *value) extra_hdr[extra_hdr_nr++] = xstrndup(value, len); } -static int git_format_config(const char *var, const char *value) +static int git_format_config(const char *var, const char *value, void *cb) { if (!strcmp(var, "format.headers")) { if (!value) @@ -497,7 +497,7 @@ static int git_format_config(const char *var, const char *value) return 0; } - return git_log_config(var, value); + return git_log_config(var, value, cb); } @@ -764,7 +764,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) char *add_signoff = NULL; struct strbuf buf; - git_config(git_format_config); + git_config(git_format_config, NULL); init_revisions(&rev, prefix); rev.commit_format = CMIT_FMT_EMAIL; rev.verbose_header = 1; -- cgit v1.2.3 From dd0ffd5b31a672db90d8b775988d55829e6f5f9f Mon Sep 17 00:00:00 2001 From: Heikki Orsila Date: Thu, 22 May 2008 18:24:07 +0300 Subject: Add log.date config variable log.date config variable sets the default date-time mode for the log command. Setting log.date value is similar to using git log's --date option. Signed-off-by: Heikki Orsila Signed-off-by: Junio C Hamano --- builtin-log.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 9d046b2e03..543855b7ad 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -18,6 +18,9 @@ #include "run-command.h" #include "shortlog.h" +/* Set a default date-time format for git log ("log.date" config variable) */ +static const char *default_date_mode = NULL; + static int default_show_root = 1; static const char *fmt_patch_subject_prefix = "PATCH"; static const char *fmt_pretty; @@ -61,7 +64,12 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix, DIFF_OPT_SET(&rev->diffopt, RECURSIVE); rev->show_root_diff = default_show_root; rev->subject_prefix = fmt_patch_subject_prefix; + + if (default_date_mode) + rev->date_mode = parse_date_format(default_date_mode); + argc = setup_revisions(argc, argv, rev, "HEAD"); + if (rev->diffopt.pickaxe || rev->diffopt.filter) rev->always_show_header = 0; if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) { @@ -232,6 +240,8 @@ static int git_log_config(const char *var, const char *value) fmt_patch_subject_prefix = xstrdup(value); return 0; } + if (!strcmp(var, "log.date")) + return git_config_string(&default_date_mode, var, value); if (!strcmp(var, "log.showroot")) { default_show_root = git_config_bool(var, value); return 0; -- cgit v1.2.3 From 4f3dcc2753ef6c244622334cef94a72682fcd850 Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Tue, 1 Jul 2008 11:47:04 +0200 Subject: Fix 'git show' on signed tag of signed tag of commit The cmd_show loop resolves tags by showing them, then pointing the object to the 'tagged' member. However, this object is not fully initialized; it only contains the SHA1. (This resulted in a segfault if there were two levels of tags.) We apply parse_object to get a full object. Noticed by Kalle Olavi Niemitalo on IRC. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- builtin-log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 9817d6fbeb..9979e37f38 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -360,7 +360,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) t->tag, diff_get_color_opt(&rev.diffopt, DIFF_RESET)); ret = show_object(o->sha1, 1, &rev); - objects[i].item = (struct object *)t->tagged; + objects[i].item = parse_object(t->tagged->sha1); i--; break; } -- cgit v1.2.3 From 70cff3ac16e842e465f304e7af3b588840899dc9 Mon Sep 17 00:00:00 2001 From: Brian Hetro Date: Sat, 5 Jul 2008 01:24:41 -0400 Subject: builtin-log.c: Use 'git_config_string' to get 'format.subjectprefix' and 'format.suffix' Signed-off-by: Brian Hetro Signed-off-by: Junio C Hamano --- builtin-log.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 9979e37f38..430d87661e 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -234,12 +234,8 @@ static int git_log_config(const char *var, const char *value, void *cb) { if (!strcmp(var, "format.pretty")) return git_config_string(&fmt_pretty, var, value); - if (!strcmp(var, "format.subjectprefix")) { - if (!value) - config_error_nonbool(var); - fmt_patch_subject_prefix = xstrdup(value); - return 0; - } + if (!strcmp(var, "format.subjectprefix")) + return git_config_string(&fmt_patch_subject_prefix, var, value); if (!strcmp(var, "log.date")) return git_config_string(&default_date_mode, var, value); if (!strcmp(var, "log.showroot")) { @@ -489,12 +485,8 @@ static int git_format_config(const char *var, const char *value, void *cb) add_header(value); return 0; } - if (!strcmp(var, "format.suffix")) { - if (!value) - return config_error_nonbool(var); - fmt_patch_suffix = xstrdup(value); - return 0; - } + if (!strcmp(var, "format.suffix")) + return git_config_string(&fmt_patch_suffix, var, value); if (!strcmp(var, "format.cc")) { if (!value) return config_error_nonbool(var); -- cgit v1.2.3 From 1b1dd23f2d6a707b7077cdf6bc6d4055bd0bfb7d Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Sun, 13 Jul 2008 15:36:15 +0200 Subject: Make usage strings dash-less When you misuse a git command, you are shown the usage string. But this is currently shown in the dashed form. So if you just copy what you see, it will not work, when the dashed form is no longer supported. This patch makes git commands show the dash-less version. For shell scripts that do not specify OPTIONS_SPEC, git-sh-setup.sh generates a dash-less usage string now. Signed-off-by: Stephan Beyer Signed-off-by: Junio C Hamano --- builtin-log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 430d87661e..cb3b33a4f2 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -1082,7 +1082,7 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags) } static const char cherry_usage[] = -"git-cherry [-v] [] []"; +"git cherry [-v] [] []"; int cmd_cherry(int argc, const char **argv, const char *prefix) { struct rev_info revs; -- cgit v1.2.3 From 671f0707212c929533dc6ec9e032faee328e4602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Mon, 14 Jul 2008 21:22:12 +0200 Subject: add context pointer to read_tree_recursive() Add a pointer parameter to read_tree_recursive(), which is passed to the callback function. This allows callers of read_tree_recursive() to share data with the callback without resorting to global variables. All current callers pass NULL. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin-log.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 430d87661e..617aa67f2b 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -313,7 +313,7 @@ static int show_object(const unsigned char *sha1, int show_tag_object, static int show_tree_object(const unsigned char *sha1, const char *base, int baselen, - const char *pathname, unsigned mode, int stage) + const char *pathname, unsigned mode, int stage, void *context) { printf("%s%s\n", pathname, S_ISDIR(mode) ? "/" : ""); return 0; @@ -366,7 +366,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) name, diff_get_color_opt(&rev.diffopt, DIFF_RESET)); read_tree_recursive((struct tree *)o, "", 0, 0, NULL, - show_tree_object); + show_tree_object, NULL); break; case OBJ_COMMIT: rev.pending.nr = rev.pending.alloc = 0; -- cgit v1.2.3