From 5f1c3f07b7f4a8436c7773b8e7a04998190c125e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 9 Apr 2006 01:11:11 -0700 Subject: log-tree: separate major part of diff-tree. This separates out the part that deals with one-commit diff-tree (and --stdin form) into a separate log-tree module. There are two goals with this. The more important one is to be able to make this part available to "git log --diff", so that we can have a native "git whatchanged" command. Another is to simplify the commit log generation part simpler. Signed-off-by: Junio C Hamano --- log-tree.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 log-tree.c (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c new file mode 100644 index 0000000000..3d404824a1 --- /dev/null +++ b/log-tree.c @@ -0,0 +1,175 @@ +#include "cache.h" +#include "diff.h" +#include "commit.h" +#include "log-tree.h" + +void init_log_tree_opt(struct log_tree_opt *opt) +{ + memset(opt, 0, sizeof *opt); + opt->ignore_merges = 1; + opt->header_prefix = ""; + opt->commit_format = CMIT_FMT_RAW; + diff_setup(&opt->diffopt); +} + +int log_tree_opt_parse(struct log_tree_opt *opt, const char **av, int ac) +{ + const char *arg; + int cnt = diff_opt_parse(&opt->diffopt, av, ac); + if (0 < cnt) + return cnt; + arg = *av; + if (!strcmp(arg, "-r")) + opt->diffopt.recursive = 1; + else if (!strcmp(arg, "-t")) { + opt->diffopt.recursive = 1; + opt->diffopt.tree_in_recursive = 1; + } + else if (!strcmp(arg, "-m")) + opt->ignore_merges = 0; + else if (!strcmp(arg, "-c")) + opt->combine_merges = 1; + else if (!strcmp(arg, "--cc")) { + opt->dense_combined_merges = 1; + opt->combine_merges = 1; + } + else if (!strcmp(arg, "-v")) { + opt->verbose_header = 1; + opt->header_prefix = "diff-tree "; + } + else if (!strncmp(arg, "--pretty", 8)) { + opt->verbose_header = 1; + opt->header_prefix = "diff-tree "; + opt->commit_format = get_commit_format(arg+8); + } + else if (!strcmp(arg, "--root")) + opt->show_root_diff = 1; + else if (!strcmp(arg, "--no-commit-id")) + opt->no_commit_id = 1; + else if (!strcmp(arg, "--always")) + opt->always_show_header = 1; + else + return 0; + return 1; +} + +int log_tree_diff_flush(struct log_tree_opt *opt) +{ + diffcore_std(&opt->diffopt); + if (diff_queue_is_empty()) { + int saved_fmt = opt->diffopt.output_format; + opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT; + diff_flush(&opt->diffopt); + opt->diffopt.output_format = saved_fmt; + return 0; + } + if (opt->header) { + if (!opt->no_commit_id) + printf("%s%c", opt->header, + opt->diffopt.line_termination); + opt->header = NULL; + } + diff_flush(&opt->diffopt); + return 1; +} + +static int diff_root_tree(struct log_tree_opt *opt, + const unsigned char *new, const char *base) +{ + int retval; + void *tree; + struct tree_desc empty, real; + + tree = read_object_with_reference(new, tree_type, &real.size, NULL); + if (!tree) + die("unable to read root tree (%s)", sha1_to_hex(new)); + real.buf = tree; + + empty.buf = ""; + empty.size = 0; + retval = diff_tree(&empty, &real, base, &opt->diffopt); + free(tree); + log_tree_diff_flush(opt); + return retval; +} + +static const char *generate_header(struct log_tree_opt *opt, + const unsigned char *commit_sha1, + const unsigned char *parent_sha1, + const struct commit *commit) +{ + static char this_header[16384]; + int offset; + unsigned long len; + int abbrev = opt->diffopt.abbrev; + const char *msg = commit->buffer; + + if (!opt->verbose_header) + return sha1_to_hex(commit_sha1); + + len = strlen(msg); + + offset = sprintf(this_header, "%s%s ", + opt->header_prefix, + diff_unique_abbrev(commit_sha1, abbrev)); + if (commit_sha1 != parent_sha1) + offset += sprintf(this_header + offset, "(from %s)\n", + parent_sha1 + ? diff_unique_abbrev(parent_sha1, abbrev) + : "root"); + else + offset += sprintf(this_header + offset, "(from parents)\n"); + offset += pretty_print_commit(opt->commit_format, commit, len, + this_header + offset, + sizeof(this_header) - offset, abbrev); + if (opt->always_show_header) { + puts(this_header); + return NULL; + } + return this_header; +} + +static int do_diff_combined(struct log_tree_opt *opt, struct commit *commit) +{ + unsigned const char *sha1 = commit->object.sha1; + + opt->header = generate_header(opt, sha1, sha1, commit); + opt->header = diff_tree_combined_merge(sha1, opt->header, + opt->dense_combined_merges, + &opt->diffopt); + if (!opt->header && opt->verbose_header) + opt->header_prefix = "\ndiff-tree "; + return 0; +} + +int log_tree_commit(struct log_tree_opt *opt, struct commit *commit) +{ + struct commit_list *parents; + unsigned const char *sha1 = commit->object.sha1; + + /* Root commit? */ + if (opt->show_root_diff && !commit->parents) { + opt->header = generate_header(opt, sha1, NULL, commit); + diff_root_tree(opt, sha1, ""); + } + + /* More than one parent? */ + if (commit->parents && commit->parents->next) { + if (opt->ignore_merges) + return 0; + else if (opt->combine_merges) + return do_diff_combined(opt, commit); + } + + for (parents = commit->parents; parents; parents = parents->next) { + struct commit *parent = parents->item; + unsigned const char *psha1 = parent->object.sha1; + opt->header = generate_header(opt, sha1, psha1, commit); + diff_tree_sha1(psha1, sha1, "", &opt->diffopt); + log_tree_diff_flush(opt); + + if (!opt->header && opt->verbose_header) + opt->header_prefix = "\ndiff-tree "; + } + return 0; +} -- cgit v1.2.3 From cd2bdc5309461034e5cc58e1d3e87535ed9e093b Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 14 Apr 2006 16:52:13 -0700 Subject: Common option parsing for "git log --diff" and friends This basically does a few things that are sadly somewhat interdependent, and nontrivial to split out - get rid of "struct log_tree_opt" The fields in "log_tree_opt" are moved into "struct rev_info", and all users of log_tree_opt are changed to use the rev_info struct instead. - add the parsing for the log_tree_opt arguments to "setup_revision()" - make setup_revision set a flag (revs->diff) if the diff-related arguments were used. This allows "git log" to decide whether it wants to show diffs or not. - make setup_revision() also initialize the diffopt part of rev_info (which we had from before, but we just didn't initialize it) - make setup_revision() do all the "finishing touches" on it all (it will do the proper flag combination logic, and call "diff_setup_done()") Now, that was the easy and straightforward part. The slightly more involved part is that some of the programs that want to use the new-and-improved rev_info parsing don't actually want _commits_, they may want tree'ish arguments instead. That meant that I had to change setup_revision() to parse the arguments not into the "revs->commits" list, but into the "revs->pending_objects" list. Then, when we do "prepare_revision_walk()", we walk that list, and create the sorted commit list from there. This actually cleaned some stuff up, but it's the less obvious part of the patch, and re-organized the "revision.c" logic somewhat. It actually paves the way for splitting argument parsing _entirely_ out of "revision.c", since now the argument parsing really is totally independent of the commit walking: that didn't use to be true, since there was lots of overlap with get_commit_reference() handling etc, now the _only_ overlap is the shared (and trivial) "add_pending_object()" thing. However, I didn't do that file split, just because I wanted the diff itself to be smaller, and show the actual changes more clearly. If this gets accepted, I'll do further cleanups then - that includes the file split, but also using the new infrastructure to do a nicer "git diff" etc. Even in this form, it actually ends up removing more lines than it adds. It's nice to note how simple and straightforward this makes the built-in "git log" command, even though it continues to support all the diff flags too. It doesn't get much simpler that this. I think this is worth merging soonish, because it does allow for future cleanup and even more sharing of code. However, it obviously touches "revision.c", which is subtle. I've tested that it passes all the tests we have, and it passes my "looks sane" detector, but somebody else should also give it a good look-over. [jc: squashed the original and three "oops this too" updates, with another fix-up.] Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- log-tree.c | 60 +++++------------------------------------------------------- 1 file changed, 5 insertions(+), 55 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 3d404824a1..04a68e0f57 100644 --- a/log-tree.c +++ b/log-tree.c @@ -3,57 +3,7 @@ #include "commit.h" #include "log-tree.h" -void init_log_tree_opt(struct log_tree_opt *opt) -{ - memset(opt, 0, sizeof *opt); - opt->ignore_merges = 1; - opt->header_prefix = ""; - opt->commit_format = CMIT_FMT_RAW; - diff_setup(&opt->diffopt); -} - -int log_tree_opt_parse(struct log_tree_opt *opt, const char **av, int ac) -{ - const char *arg; - int cnt = diff_opt_parse(&opt->diffopt, av, ac); - if (0 < cnt) - return cnt; - arg = *av; - if (!strcmp(arg, "-r")) - opt->diffopt.recursive = 1; - else if (!strcmp(arg, "-t")) { - opt->diffopt.recursive = 1; - opt->diffopt.tree_in_recursive = 1; - } - else if (!strcmp(arg, "-m")) - opt->ignore_merges = 0; - else if (!strcmp(arg, "-c")) - opt->combine_merges = 1; - else if (!strcmp(arg, "--cc")) { - opt->dense_combined_merges = 1; - opt->combine_merges = 1; - } - else if (!strcmp(arg, "-v")) { - opt->verbose_header = 1; - opt->header_prefix = "diff-tree "; - } - else if (!strncmp(arg, "--pretty", 8)) { - opt->verbose_header = 1; - opt->header_prefix = "diff-tree "; - opt->commit_format = get_commit_format(arg+8); - } - else if (!strcmp(arg, "--root")) - opt->show_root_diff = 1; - else if (!strcmp(arg, "--no-commit-id")) - opt->no_commit_id = 1; - else if (!strcmp(arg, "--always")) - opt->always_show_header = 1; - else - return 0; - return 1; -} - -int log_tree_diff_flush(struct log_tree_opt *opt) +int log_tree_diff_flush(struct rev_info *opt) { diffcore_std(&opt->diffopt); if (diff_queue_is_empty()) { @@ -73,7 +23,7 @@ int log_tree_diff_flush(struct log_tree_opt *opt) return 1; } -static int diff_root_tree(struct log_tree_opt *opt, +static int diff_root_tree(struct rev_info *opt, const unsigned char *new, const char *base) { int retval; @@ -93,7 +43,7 @@ static int diff_root_tree(struct log_tree_opt *opt, return retval; } -static const char *generate_header(struct log_tree_opt *opt, +static const char *generate_header(struct rev_info *opt, const unsigned char *commit_sha1, const unsigned char *parent_sha1, const struct commit *commit) @@ -129,7 +79,7 @@ static const char *generate_header(struct log_tree_opt *opt, return this_header; } -static int do_diff_combined(struct log_tree_opt *opt, struct commit *commit) +static int do_diff_combined(struct rev_info *opt, struct commit *commit) { unsigned const char *sha1 = commit->object.sha1; @@ -142,7 +92,7 @@ static int do_diff_combined(struct log_tree_opt *opt, struct commit *commit) return 0; } -int log_tree_commit(struct log_tree_opt *opt, struct commit *commit) +int log_tree_commit(struct rev_info *opt, struct commit *commit) { struct commit_list *parents; unsigned const char *sha1 = commit->object.sha1; -- cgit v1.2.3 From cb8f64b4e3f263c113b7a2f156af74b810e969ff Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 16 Apr 2006 03:29:10 -0700 Subject: log/whatchanged/show - log formatting cleanup. This moves the decision to print the log message, while diff options are in effect, to log-tree. It gives behaviour closer to the traditional one. Signed-off-by: Junio C Hamano --- log-tree.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 04a68e0f57..7d9f41ede1 100644 --- a/log-tree.c +++ b/log-tree.c @@ -54,6 +54,9 @@ static const char *generate_header(struct rev_info *opt, int abbrev = opt->diffopt.abbrev; const char *msg = commit->buffer; + if (opt->use_precomputed_header) + return opt->use_precomputed_header; + if (!opt->verbose_header) return sha1_to_hex(commit_sha1); -- cgit v1.2.3 From 78fff6ebbafe2d23464a2b059104954bfe8732c7 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sun, 16 Apr 2006 15:17:23 -0700 Subject: Fixes for option parsing Make sure "git show" always show the header, regardless of whether there is a diff or not. Also, make sure "always_show_header" actually works, since generate_header only tested it in one out of three return paths. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- log-tree.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 7d9f41ede1..af36f702e1 100644 --- a/log-tree.c +++ b/log-tree.c @@ -43,7 +43,7 @@ static int diff_root_tree(struct rev_info *opt, return retval; } -static const char *generate_header(struct rev_info *opt, +static const char *get_header(struct rev_info *opt, const unsigned char *commit_sha1, const unsigned char *parent_sha1, const struct commit *commit) @@ -75,11 +75,21 @@ static const char *generate_header(struct rev_info *opt, offset += pretty_print_commit(opt->commit_format, commit, len, this_header + offset, sizeof(this_header) - offset, abbrev); + return this_header; +} + +static const char *generate_header(struct rev_info *opt, + const unsigned char *commit_sha1, + const unsigned char *parent_sha1, + const struct commit *commit) +{ + const char *header = get_header(opt, commit_sha1, parent_sha1, commit); + if (opt->always_show_header) { - puts(this_header); - return NULL; + puts(header); + header = NULL; } - return this_header; + return header; } static int do_diff_combined(struct rev_info *opt, struct commit *commit) -- cgit v1.2.3 From 9153983310a169a340bd1023dccafd80b70b05bc Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 17 Apr 2006 11:59:32 -0700 Subject: Log message printout cleanups On Sun, 16 Apr 2006, Junio C Hamano wrote: > > In the mid-term, I am hoping we can drop the generate_header() > callchain _and_ the custom code that formats commit log in-core, > found in cmd_log_wc(). Ok, this was nastier than expected, just because the dependencies between the different log-printing stuff were absolutely _everywhere_, but here's a patch that does exactly that. The patch is not very easy to read, and the "--patch-with-stat" thing is still broken (it does not call the "show_log()" thing properly for merges). That's not a new bug. In the new world order it _should_ do something like if (rev->logopt) show_log(rev, rev->logopt, "---\n"); but it doesn't. I haven't looked at the --with-stat logic, so I left it alone. That said, this patch removes more lines than it adds, and in particular, the "cmd_log_wc()" loop is now a very clean: while ((commit = get_revision(rev)) != NULL) { log_tree_commit(rev, commit); free(commit->buffer); commit->buffer = NULL; } so it doesn't get much prettier than this. All the complexity is entirely hidden in log-tree.c, and any code that needs to flush the log literally just needs to do the "if (rev->logopt) show_log(...)" incantation. I had to make the combined_diff() logic take a "struct rev_info" instead of just a "struct diff_options", but that part is pretty clean. This does change "git whatchanged" from using "diff-tree" as the commit descriptor to "commit", and I changed one of the tests to reflect that new reality. Otherwise everything still passes, and my other tests look fine too. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- log-tree.c | 167 ++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 93 insertions(+), 74 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index af36f702e1..c0a4432022 100644 --- a/log-tree.c +++ b/log-tree.c @@ -1,11 +1,51 @@ + #include "cache.h" #include "diff.h" #include "commit.h" #include "log-tree.h" +void show_log(struct rev_info *opt, struct log_info *log, const char *sep) +{ + static char this_header[16384]; + struct commit *commit = log->commit, *parent = log->parent; + int abbrev = opt->diffopt.abbrev; + int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40; + int len; + + opt->loginfo = NULL; + if (!opt->verbose_header) { + puts(sha1_to_hex(commit->object.sha1)); + return; + } + + /* + * Whitespace between commit messages, unless we are oneline + */ + if (opt->shown_one && opt->commit_format != CMIT_FMT_ONELINE) + putchar('\n'); + opt->shown_one = 1; + + /* + * Print header line of header.. + */ + printf("%s%s", + opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ", + diff_unique_abbrev(commit->object.sha1, abbrev_commit)); + if (parent) + printf(" (from %s)", diff_unique_abbrev(parent->object.sha1, abbrev_commit)); + putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); + + /* + * And then the pretty-printed message itself + */ + len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev); + printf("%s%s", this_header, sep); +} + int log_tree_diff_flush(struct rev_info *opt) { diffcore_std(&opt->diffopt); + if (diff_queue_is_empty()) { int saved_fmt = opt->diffopt.output_format; opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT; @@ -13,12 +53,9 @@ int log_tree_diff_flush(struct rev_info *opt) opt->diffopt.output_format = saved_fmt; return 0; } - if (opt->header) { - if (!opt->no_commit_id) - printf("%s%c", opt->header, - opt->diffopt.line_termination); - opt->header = NULL; - } + + if (opt->loginfo && !opt->no_commit_id) + show_log(opt, opt->loginfo, "\n"); diff_flush(&opt->diffopt); return 1; } @@ -43,96 +80,78 @@ static int diff_root_tree(struct rev_info *opt, return retval; } -static const char *get_header(struct rev_info *opt, - const unsigned char *commit_sha1, - const unsigned char *parent_sha1, - const struct commit *commit) -{ - static char this_header[16384]; - int offset; - unsigned long len; - int abbrev = opt->diffopt.abbrev; - const char *msg = commit->buffer; - - if (opt->use_precomputed_header) - return opt->use_precomputed_header; - - if (!opt->verbose_header) - return sha1_to_hex(commit_sha1); - - len = strlen(msg); - - offset = sprintf(this_header, "%s%s ", - opt->header_prefix, - diff_unique_abbrev(commit_sha1, abbrev)); - if (commit_sha1 != parent_sha1) - offset += sprintf(this_header + offset, "(from %s)\n", - parent_sha1 - ? diff_unique_abbrev(parent_sha1, abbrev) - : "root"); - else - offset += sprintf(this_header + offset, "(from parents)\n"); - offset += pretty_print_commit(opt->commit_format, commit, len, - this_header + offset, - sizeof(this_header) - offset, abbrev); - return this_header; -} - -static const char *generate_header(struct rev_info *opt, - const unsigned char *commit_sha1, - const unsigned char *parent_sha1, - const struct commit *commit) -{ - const char *header = get_header(opt, commit_sha1, parent_sha1, commit); - - if (opt->always_show_header) { - puts(header); - header = NULL; - } - return header; -} - static int do_diff_combined(struct rev_info *opt, struct commit *commit) { unsigned const char *sha1 = commit->object.sha1; - opt->header = generate_header(opt, sha1, sha1, commit); - opt->header = diff_tree_combined_merge(sha1, opt->header, - opt->dense_combined_merges, - &opt->diffopt); - if (!opt->header && opt->verbose_header) - opt->header_prefix = "\ndiff-tree "; - return 0; + diff_tree_combined_merge(sha1, opt->dense_combined_merges, opt); + return !opt->loginfo; } -int log_tree_commit(struct rev_info *opt, struct commit *commit) +/* + * Show the diff of a commit. + * + * Return true if we printed any log info messages + */ +static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log) { + int showed_log; struct commit_list *parents; unsigned const char *sha1 = commit->object.sha1; + if (!opt->diff) + return 0; + /* Root commit? */ - if (opt->show_root_diff && !commit->parents) { - opt->header = generate_header(opt, sha1, NULL, commit); - diff_root_tree(opt, sha1, ""); + parents = commit->parents; + if (!parents) { + if (opt->show_root_diff) + diff_root_tree(opt, sha1, ""); + return !opt->loginfo; } /* More than one parent? */ - if (commit->parents && commit->parents->next) { + if (parents && parents->next) { if (opt->ignore_merges) return 0; else if (opt->combine_merges) return do_diff_combined(opt, commit); + + /* If we show individual diffs, show the parent info */ + log->parent = parents->item; } - for (parents = commit->parents; parents; parents = parents->next) { + showed_log = 0; + for (;;) { struct commit *parent = parents->item; - unsigned const char *psha1 = parent->object.sha1; - opt->header = generate_header(opt, sha1, psha1, commit); - diff_tree_sha1(psha1, sha1, "", &opt->diffopt); - log_tree_diff_flush(opt); - if (!opt->header && opt->verbose_header) - opt->header_prefix = "\ndiff-tree "; + diff_tree_sha1(parent->object.sha1, sha1, "", &opt->diffopt); + log_tree_diff_flush(opt); + + showed_log |= !opt->loginfo; + + /* Set up the log info for the next parent, if any.. */ + parents = parents->next; + if (!parents) + break; + log->parent = parents->item; + opt->loginfo = log; + } + return showed_log; +} + +int log_tree_commit(struct rev_info *opt, struct commit *commit) +{ + struct log_info log; + + log.commit = commit; + log.parent = NULL; + opt->loginfo = &log; + + if (!log_tree_diff(opt, commit, &log) && opt->loginfo && opt->always_show_header) { + log.parent = NULL; + show_log(opt, opt->loginfo, ""); } + opt->loginfo = NULL; return 0; } -- cgit v1.2.3 From eab144ac49c18d981261c2d0ba964d6380d9f1da Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 17 Apr 2006 16:59:42 -0700 Subject: Log message printout cleanups (#2) Here's a further patch on top of the previous one with cosmetic improvements (no "real" code changes, just trivial updates): - it gets the "---" before a diffstat right, including for the combined merge case. Righ now the logic is that we always use "---" when we have a diffstat, and an empty line otherwise. That's how I visually prefer it, but hey, it can be tweaked later. - I made "diff --cc/combined" add the "---/+++" header lines too. The thing won't be mistaken for a valid diff, since the "@@" lines have too many "@" characters (three or more), but it just makes it visually match a real diff, which at least to me makes a big difference in readability. Without them, it just looks very "wrong". I guess I should have taken the filename from each individual entry (and had one "---" file per parent), but I didn't even bother to try to see how that works, so this was the simple thing. With this, doing a git log --cc --patch-with-stat looks quite readable, I think. The only nagging issue - as far as I'm concerned - is that diffstats for merges are pretty questionable the way they are done now. I suspect it would be better to just have the _first_ diffstat, and always make the merge diffstat be the one for "result against first parent". Signed-off-by: Junio C Hamano --- log-tree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index c0a4432022..9e5416427a 100644 --- a/log-tree.c +++ b/log-tree.c @@ -1,4 +1,3 @@ - #include "cache.h" #include "diff.h" #include "commit.h" @@ -55,7 +54,7 @@ int log_tree_diff_flush(struct rev_info *opt) } if (opt->loginfo && !opt->no_commit_id) - show_log(opt, opt->loginfo, "\n"); + show_log(opt, opt->loginfo, opt->diffopt.with_stat ? "---\n" : "\n"); diff_flush(&opt->diffopt); return 1; } -- cgit v1.2.3 From a4d34e2db5565e6b75f79f9d3938aa9151e72e44 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 17 Apr 2006 17:43:40 -0700 Subject: Log message printout cleanups (#3): fix --pretty=oneline This option is very special, since pretty_print_commit() will _remove_ the newline at the end of it, so we want to have an extra separator between the things. I added a honking big comment this time, so that (a) I don't forget this _again_ (I broke "oneline" several times during this printout cleanup), and so that people can understand _why_ the code does what it does. Now, arguably the alternate fix is to always have the '\n' at the end in pretty-print-commit, but git-rev-list depends on the current behaviour (but we could have git-rev-list remove it, whatever). With the big comment, the code hopefully doesn't get broken again. And now things like git log --pretty=oneline --cc --patch-with-stat works (even if that is admittedly a totally insane combination: if you want the patch, having the "oneline" log format is just crazy, but hey, it _works_. Even insane people are people). Signed-off-by: Junio C Hamano --- log-tree.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 9e5416427a..9634c4677f 100644 --- a/log-tree.c +++ b/log-tree.c @@ -9,6 +9,7 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) struct commit *commit = log->commit, *parent = log->parent; int abbrev = opt->diffopt.abbrev; int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40; + const char *extra; int len; opt->loginfo = NULL; @@ -18,8 +19,17 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) } /* - * Whitespace between commit messages, unless we are oneline + * The "oneline" format has several special cases: + * - The pretty-printed commit lacks a newline at the end + * of the buffer, but we do want to make sure that we + * have a newline there. If the separator isn't already + * a newline, add an extra one. + * - unlike other log messages, the one-line format does + * not have an empty line between entries. */ + extra = ""; + if (*sep != '\n' && opt->commit_format == CMIT_FMT_ONELINE) + extra = "\n"; if (opt->shown_one && opt->commit_format != CMIT_FMT_ONELINE) putchar('\n'); opt->shown_one = 1; @@ -38,7 +48,7 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) * And then the pretty-printed message itself */ len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev); - printf("%s%s", this_header, sep); + printf("%s%s%s", this_header, extra, sep); } int log_tree_diff_flush(struct rev_info *opt) -- cgit v1.2.3 From 3eefc189172b88dece6fb6d479b3ed13cc483dbc Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 18 Apr 2006 16:45:27 -0700 Subject: Tentative built-in format-patch. This only does --stdout right now. To write into separate files with pretty-printed filenames like the real thing does, it needs a bit mroe work. Signed-off-by: Junio C Hamano --- log-tree.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 9634c4677f..aaf2b9423f 100644 --- a/log-tree.c +++ b/log-tree.c @@ -37,12 +37,20 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) /* * Print header line of header.. */ - printf("%s%s", - opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ", - diff_unique_abbrev(commit->object.sha1, abbrev_commit)); - if (parent) - printf(" (from %s)", diff_unique_abbrev(parent->object.sha1, abbrev_commit)); - putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); + + if (opt->commit_format == CMIT_FMT_EMAIL) + printf("From %s Thu Apr 7 15:13:13 2005\n", + sha1_to_hex(commit->object.sha1)); + else { + printf("%s%s", + opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ", + diff_unique_abbrev(commit->object.sha1, abbrev_commit)); + if (parent) + printf(" (from %s)", + diff_unique_abbrev(parent->object.sha1, + abbrev_commit)); + putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); + } /* * And then the pretty-printed message itself @@ -152,15 +160,18 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log int log_tree_commit(struct rev_info *opt, struct commit *commit) { struct log_info log; + int shown; log.commit = commit; log.parent = NULL; opt->loginfo = &log; - if (!log_tree_diff(opt, commit, &log) && opt->loginfo && opt->always_show_header) { + shown = log_tree_diff(opt, commit, &log); + if (!shown && opt->loginfo && opt->always_show_header) { log.parent = NULL; show_log(opt, opt->loginfo, ""); + shown = 1; } opt->loginfo = NULL; - return 0; + return shown; } -- cgit v1.2.3 From c8c893c62b0d9997e7dfe7bd5f636ddbf29ef619 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 3 May 2006 07:59:00 -0700 Subject: Fix "git-log --parents" breakage post v1.3.0 Post 1.3.0 "git log" forgets to list parent commits on the first line when --parents is given. git-cvsserver relied on it. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- log-tree.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 9634c4677f..b90ba6762a 100644 --- a/log-tree.c +++ b/log-tree.c @@ -3,6 +3,15 @@ #include "commit.h" #include "log-tree.h" +static void show_parents(struct commit *commit, int abbrev) +{ + struct commit_list *p; + for (p = commit->parents; p ; p = p->next) { + struct commit *parent = p->item; + printf(" %s", diff_unique_abbrev(parent->object.sha1, abbrev)); + } +} + void show_log(struct rev_info *opt, struct log_info *log, const char *sep) { static char this_header[16384]; @@ -14,7 +23,10 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) opt->loginfo = NULL; if (!opt->verbose_header) { - puts(sha1_to_hex(commit->object.sha1)); + fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); + if (opt->parents) + show_parents(commit, abbrev_commit); + putchar('\n'); return; } @@ -40,7 +52,9 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) printf("%s%s", opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ", diff_unique_abbrev(commit->object.sha1, abbrev_commit)); - if (parent) + if (opt->parents) + show_parents(commit, abbrev_commit); + if (parent) printf(" (from %s)", diff_unique_abbrev(parent->object.sha1, abbrev_commit)); putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); -- cgit v1.2.3 From 596524b33d50e47e2375cec9e00aff59f0e8278b Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 5 May 2006 04:30:52 +0200 Subject: Teach fmt-patch about --numbered Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- log-tree.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index aaf2b9423f..1ca529d9fe 100644 --- a/log-tree.c +++ b/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; const char *extra; int len; + char* subject = NULL; opt->loginfo = NULL; 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.. */ - 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", sha1_to_hex(commit->object.sha1)); - else { + } else { printf("%s%s", opt->commit_format == CMIT_FMT_ONELINE ? "" : "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 */ - 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); } -- cgit v1.2.3 From 8ac80a5701780547404523a84f4b1ae67bfa6823 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 5 May 2006 04:31:29 +0200 Subject: Teach fmt-patch about --keep-subject Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- log-tree.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 1ca529d9fe..4a3cd6791b 100644 --- a/log-tree.c +++ b/log-tree.c @@ -46,8 +46,11 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) "Subject: [PATCH %d/%d] ", opt->nr, opt->total); subject = buffer; - } else + } else if (opt->total == 0) subject = "Subject: [PATCH] "; + else + subject = "Subject: "; + printf("From %s Thu Apr 7 15:13:13 2005\n", sha1_to_hex(commit->object.sha1)); } else { -- cgit v1.2.3 From 698ce6f87e0d6db380f7306e190e8586da184577 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 20 May 2006 15:40:29 +0200 Subject: fmt-patch: Support --attach This patch touches a couple of files, because it adds options to print a custom text just after the subject of a commit, and just after the diffstat. [jc: made "many dashes" used as the boundary leader into a single variable, to reduce the possibility of later tweaks to miscount the number of dashes to break it.] Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- log-tree.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 526d578e98..7e23e42788 100644 --- a/log-tree.c +++ b/log-tree.c @@ -20,7 +20,7 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) 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) { @@ -52,6 +52,7 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) */ 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), @@ -63,8 +64,36 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) 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 ", @@ -81,7 +110,7 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) /* * 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); } -- cgit v1.2.3 From cf2251b60460e651a5e00afe9ef7c427ad296711 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 31 May 2006 15:11:49 -0700 Subject: format-patch --signoff This resurrects --signoff option to format-patch. Signed-off-by: Junio C Hamano --- log-tree.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 58b016378c..e86e16bcad 100644 --- a/log-tree.c +++ b/log-tree.c @@ -12,6 +12,37 @@ static void show_parents(struct commit *commit, int abbrev) } } +static int append_signoff(char *buf, int buf_sz, int at, const char *signoff) +{ + int signoff_len = strlen(signoff); + static const char signed_off_by[] = "Signed-off-by: "; + char *cp = buf; + + /* Do we have enough space to add it? */ + if (buf_sz - at <= strlen(signed_off_by) + signoff_len + 2) + return at; + + /* First see if we already have the sign-off by the signer */ + while (1) { + cp = strstr(cp, signed_off_by); + if (!cp) + break; + cp += strlen(signed_off_by); + if ((cp + signoff_len < buf + at) && + !strncmp(cp, signoff, signoff_len) && + isspace(cp[signoff_len])) + return at; /* we already have him */ + } + + strcpy(buf + at, signed_off_by); + at += strlen(signed_off_by); + strcpy(buf + at, signoff); + at += signoff_len; + buf[at++] = '\n'; + buf[at] = 0; + return at; +} + void show_log(struct rev_info *opt, struct log_info *log, const char *sep) { static char this_header[16384]; @@ -111,6 +142,10 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) * And then the pretty-printed message itself */ len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject, after_subject); + + if (opt->add_signoff) + len = append_signoff(this_header, sizeof(this_header), len, + opt->add_signoff); printf("%s%s%s", this_header, extra, sep); } -- cgit v1.2.3 From 20ff06805c66826404b154b9309a8581449af2b0 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 2 Jun 2006 15:21:17 +0200 Subject: format-patch: resurrect extra headers from config Once again, if you have [format] headers = "Origamization: EvilEmpire\n" format-patch will add these headers just after the "Subject:" line. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- log-tree.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index e86e16bcad..ebb49f2970 100644 --- a/log-tree.c +++ b/log-tree.c @@ -51,7 +51,7 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40; const char *extra; int len; - char *subject = NULL, *after_subject = NULL; + const char *subject = NULL, *extra_headers = opt->extra_headers; opt->loginfo = NULL; if (!opt->verbose_header) { @@ -100,6 +100,7 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) static char subject_buffer[1024]; static char buffer[1024]; snprintf(subject_buffer, sizeof(subject_buffer) - 1, + "%s" "MIME-Version: 1.0\n" "Content-Type: multipart/mixed;\n" " boundary=\"%s%s\"\n" @@ -110,9 +111,10 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) "Content-Type: text/plain; " "charset=UTF-8; format=fixed\n" "Content-Transfer-Encoding: 8bit\n\n", + extra_headers ? extra_headers : "", mime_boundary_leader, opt->mime_boundary, mime_boundary_leader, opt->mime_boundary); - after_subject = subject_buffer; + extra_headers = subject_buffer; snprintf(buffer, sizeof(buffer) - 1, "--%s%s\n" @@ -141,7 +143,7 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) /* * And then the pretty-printed message itself */ - len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject, after_subject); + len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject, extra_headers); if (opt->add_signoff) len = append_signoff(this_header, sizeof(this_header), len, -- cgit v1.2.3 From c6744349df5089133b7662e67aba28282b6a963f Mon Sep 17 00:00:00 2001 From: Timo Hirvonen Date: Sat, 24 Jun 2006 20:21:53 +0300 Subject: Merge with_raw, with_stat and summary variables to output_format DIFF_FORMAT_* are now bit-flags instead of enumerated values. Signed-off-by: Timo Hirvonen Signed-off-by: Junio C Hamano --- log-tree.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index ebb49f2970..7d4c51f954 100644 --- a/log-tree.c +++ b/log-tree.c @@ -163,8 +163,13 @@ int log_tree_diff_flush(struct rev_info *opt) return 0; } - if (opt->loginfo && !opt->no_commit_id) - show_log(opt, opt->loginfo, opt->diffopt.with_stat ? "---\n" : "\n"); + if (opt->loginfo && !opt->no_commit_id) { + if (opt->diffopt.output_format & DIFF_FORMAT_DIFFSTAT) { + show_log(opt, opt->loginfo, "---\n"); + } else { + show_log(opt, opt->loginfo, "\n"); + } + } diff_flush(&opt->diffopt); return 1; } -- cgit v1.2.3 From 39bc9a6c2051a9fc31dc9b34b40bdd3dd94a8afb Mon Sep 17 00:00:00 2001 From: Timo Hirvonen Date: Sun, 25 Jun 2006 13:54:14 +0300 Subject: Add msg_sep to diff_options Add msg_sep variable to struct diff_options. msg_sep is printed after commit message. Default is "\n", format-patch sets it to "---\n". This also removes the second argument from show_log() because all callers derived it from the first argument: show_log(rev, rev->loginfo, ... Signed-off-by: Timo Hirvonen Signed-off-by: Junio C Hamano --- log-tree.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 7d4c51f954..ab6b682223 100644 --- a/log-tree.c +++ b/log-tree.c @@ -43,9 +43,10 @@ static int append_signoff(char *buf, int buf_sz, int at, const char *signoff) return at; } -void show_log(struct rev_info *opt, struct log_info *log, const char *sep) +void show_log(struct rev_info *opt, const char *sep) { static char this_header[16384]; + struct log_info *log = opt->loginfo; struct commit *commit = log->commit, *parent = log->parent; int abbrev = opt->diffopt.abbrev; int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40; @@ -163,13 +164,9 @@ int log_tree_diff_flush(struct rev_info *opt) return 0; } - if (opt->loginfo && !opt->no_commit_id) { - if (opt->diffopt.output_format & DIFF_FORMAT_DIFFSTAT) { - show_log(opt, opt->loginfo, "---\n"); - } else { - show_log(opt, opt->loginfo, "\n"); - } - } + if (opt->loginfo && !opt->no_commit_id) + show_log(opt, opt->diffopt.msg_sep); + diff_flush(&opt->diffopt); return 1; } @@ -266,7 +263,7 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit) shown = log_tree_diff(opt, commit, &log); if (!shown && opt->loginfo && opt->always_show_header) { log.parent = NULL; - show_log(opt, opt->loginfo, ""); + show_log(opt, ""); shown = 1; } opt->loginfo = NULL; -- cgit v1.2.3 From 3969cf7db1a13a78f3b7a36d8c1084bbe0a53459 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 27 Jun 2006 15:08:19 -0700 Subject: Fix some more diff options changes. This fixes various problems in the new diff options code. - Fix --cc/-c --patch; it showed two-tree diff used internally. - Use "---\n" only where it matters -- that is, use it immediately after the commit log text when we show a commit log and something else before the patch text. - Do not output spurious extra "\n"; have an extra newline after the commit log text always when we have diff output and we are not doing oneline. - When running a pickaxe you need to go recursive. Signed-off-by: Junio C Hamano --- log-tree.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index ab6b682223..9d8d46fa00 100644 --- a/log-tree.c +++ b/log-tree.c @@ -164,9 +164,22 @@ int log_tree_diff_flush(struct rev_info *opt) return 0; } - if (opt->loginfo && !opt->no_commit_id) + if (opt->loginfo && !opt->no_commit_id) { + /* When showing a verbose header (i.e. log message), + * and not in --pretty=oneline format, we would want + * an extra newline between the end of log and the + * output for readability. + */ show_log(opt, opt->diffopt.msg_sep); - + if (opt->verbose_header && + opt->commit_format != CMIT_FMT_ONELINE) { + int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH; + if ((pch & opt->diffopt.output_format) == pch) + printf("---%c", opt->diffopt.line_termination); + else + putchar(opt->diffopt.line_termination); + } + } diff_flush(&opt->diffopt); return 1; } -- cgit v1.2.3 From d1566f7883f727f38bf442af3fdb69d36e6fcea2 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 14 Jul 2006 17:48:51 -0700 Subject: git-format-patch: Make the second and subsequent mails replies to the first Add message_id and ref_message_id fields to struct rev_info, used in show_log with CMIT_FMT_EMAIL to set Message-Id and In-Reply-To/References respectively. Use these in git-format-patch to make the second and subsequent patch mails replies to the first patch mail. Signed-off-by: Josh Triplett Signed-off-by: Junio C Hamano --- log-tree.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 9d8d46fa00..4971988417 100644 --- a/log-tree.c +++ b/log-tree.c @@ -97,6 +97,11 @@ void show_log(struct rev_info *opt, const char *sep) subject = "Subject: "; printf("From %s Mon Sep 17 00:00:00 2001\n", sha1); + if (opt->message_id) + printf("Message-Id: <%s>\n", opt->message_id); + if (opt->ref_message_id) + printf("In-Reply-To: <%s>\nReferences: <%s>\n", + opt->ref_message_id, opt->ref_message_id); if (opt->mime_boundary) { static char subject_buffer[1024]; static char buffer[1024]; -- cgit v1.2.3 From ce43697379ad8ffcaf061a4709489728c1dbe911 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 23 Jul 2006 05:24:18 -0400 Subject: Colorize 'commit' lines in log ui When paging through the output of git-whatchanged, the color cues help to visually navigate within a diff. However, it is difficult to notice when a new commit starts, because the commit and log are shown in the "normal" color. This patch colorizes the 'commit' line, customizable through diff.colors.commit and defaulting to yellow. As a side effect, some of the diff color engine (slot enum, get_color) has become accessible outside of diff.c. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- log-tree.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 9d8d46fa00..b71cf9ba41 100644 --- a/log-tree.c +++ b/log-tree.c @@ -129,7 +129,8 @@ void show_log(struct rev_info *opt, const char *sep) opt->diffopt.stat_sep = buffer; } } else { - printf("%s%s", + printf("%s%s%s", + diff_get_color(opt->diffopt.color_diff, DIFF_COMMIT), opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ", diff_unique_abbrev(commit->object.sha1, abbrev_commit)); if (opt->parents) @@ -139,6 +140,8 @@ void show_log(struct rev_info *opt, const char *sep) diff_unique_abbrev(parent->object.sha1, abbrev_commit)); putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); + printf("%s", + diff_get_color(opt->diffopt.color_diff, DIFF_RESET)); } /* -- cgit v1.2.3 From e557667e2d0439451f404794cb308affbc0acfb1 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 24 Jul 2006 14:41:41 +0200 Subject: Always reset the color _before_ printing out the newline This patch brings the benefits of part of v1.4.1-rc2~37 to the "commit" colorizing patch. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- log-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index b71cf9ba41..3a6c84dab5 100644 --- a/log-tree.c +++ b/log-tree.c @@ -139,9 +139,9 @@ void show_log(struct rev_info *opt, const char *sep) printf(" (from %s)", diff_unique_abbrev(parent->object.sha1, abbrev_commit)); - putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); printf("%s", diff_get_color(opt->diffopt.color_diff, DIFF_RESET)); + putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); } /* -- cgit v1.2.3 From 1dcb69224ca4da3d97c502de88de73ec4b362082 Mon Sep 17 00:00:00 2001 From: Ryan Anderson Date: Mon, 7 Aug 2006 05:11:23 -0700 Subject: log-tree: show_log() should respect the setting of diffopt->line_termination Signed-off-by: Ryan Anderson Signed-off-by: Junio C Hamano --- log-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index b67b8dd17a..05ede0c175 100644 --- a/log-tree.c +++ b/log-tree.c @@ -59,7 +59,7 @@ void show_log(struct rev_info *opt, const char *sep) fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); if (opt->parents) show_parents(commit, abbrev_commit); - putchar('\n'); + putchar(opt->diffopt.line_termination); return; } -- cgit v1.2.3 From c35f4c371ac12f4d29b08e46c519ddc0a6494f6e Mon Sep 17 00:00:00 2001 From: Franck Bui-Huu Date: Sun, 13 Aug 2006 11:30:27 -0700 Subject: Add a newline before appending "Signed-off-by: " line Whef the last line of the commit log message does not end with "^[-A-Za-z]+: [^@]+@", append a newline after it to separate the body of the commit log message from the run of sign-off and ack lines. e.g. "Signed-off-by: A U Thor " or "Acked-by: Me ". Signed-off-by: Junio C Hamano --- log-tree.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 05ede0c175..031af88933 100644 --- a/log-tree.c +++ b/log-tree.c @@ -19,7 +19,7 @@ static int append_signoff(char *buf, int buf_sz, int at, const char *signoff) char *cp = buf; /* Do we have enough space to add it? */ - if (buf_sz - at <= strlen(signed_off_by) + signoff_len + 2) + if (buf_sz - at <= strlen(signed_off_by) + signoff_len + 3) return at; /* First see if we already have the sign-off by the signer */ @@ -34,6 +34,48 @@ static int append_signoff(char *buf, int buf_sz, int at, const char *signoff) return at; /* we already have him */ } + /* Does the last line already end with "^[-A-Za-z]+: [^@]+@"? + * If not, add a blank line to separate the message from + * the run of Signed-off-by: and Acked-by: lines. + */ + { + char ch; + int seen_colon, seen_at, seen_name, seen_head, not_signoff; + seen_colon = 0; + seen_at = 0; + seen_name = 0; + seen_head = 0; + not_signoff = 0; + cp = buf + at; + while (buf <= --cp && (ch = *cp) == '\n') + ; + while (!not_signoff && buf <= cp && (ch = *cp--) != '\n') { + if (!seen_at) { + if (ch == '@') + seen_at = 1; + continue; + } + if (!seen_colon) { + if (ch == '@') + not_signoff = 1; + else if (ch == ':') + seen_colon = 1; + else + seen_name = 1; + continue; + } + if (('A' <= ch && ch <= 'Z') || + ('a' <= ch && ch <= 'z') || + ch == '-') { + seen_head = 1; + continue; + } + not_signoff = 1; + } + if (not_signoff || !seen_head || !seen_name) + buf[at++] = '\n'; + } + strcpy(buf + at, signed_off_by); at += strlen(signed_off_by); strcpy(buf + at, signoff); -- cgit v1.2.3 From 3dfb9278dff6d81fcc062e9a56edab9ece38ea7d Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Mon, 28 Aug 2006 15:52:13 +0200 Subject: Add --relative-date option to the revision interface Exposes the infrastructure from 9a8e35e98793af086f05d1ca9643052df9b44a74. Signed-off-by: Jonas Fonseca Signed-off-by: Junio C Hamano --- log-tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 031af88933..54cdaa4d81 100644 --- a/log-tree.c +++ b/log-tree.c @@ -194,7 +194,9 @@ void show_log(struct rev_info *opt, const char *sep) /* * And then the pretty-printed message itself */ - len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject, extra_headers); + len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, + sizeof(this_header), abbrev, subject, + extra_headers, opt->relative_date); if (opt->add_signoff) len = append_signoff(this_header, sizeof(this_header), len, -- cgit v1.2.3 From fc1c75ec74c372670f01f22c68193156a445728a Mon Sep 17 00:00:00 2001 From: Franck Bui-Huu Date: Tue, 29 Aug 2006 13:37:06 +0200 Subject: log-tree.c: cleanup a bit append_signoff() This patch clean up append_signoff() by moving specific code that looks up for "^[-A-Za-z]+: [^@]+@" pattern into a function. It also stops the primary search when the cursor oversteps 'buf + at' limit. This patch changes slightly append_signoff() behaviour too. If we detect any Signed-off-by pattern during the primary search, we needn't to do a pattern research after. Signed-off-by: Franck Bui-Huu Signed-off-by: Junio C Hamano --- log-tree.c | 116 +++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 66 insertions(+), 50 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 54cdaa4d81..fbe139920a 100644 --- a/log-tree.c +++ b/log-tree.c @@ -12,10 +12,58 @@ static void show_parents(struct commit *commit, int abbrev) } } +/* + * Search for "^[-A-Za-z]+: [^@]+@" pattern. It usually matches + * Signed-off-by: and Acked-by: lines. + */ +static int detect_any_signoff(char *letter, int size) +{ + char ch, *cp; + int seen_colon = 0; + int seen_at = 0; + int seen_name = 0; + int seen_head = 0; + + cp = letter + size; + while (letter <= --cp && (ch = *cp) == '\n') + continue; + + while (letter <= cp) { + ch = *cp--; + if (ch == '\n') + break; + + if (!seen_at) { + if (ch == '@') + seen_at = 1; + continue; + } + if (!seen_colon) { + if (ch == '@') + return 0; + else if (ch == ':') + seen_colon = 1; + else + seen_name = 1; + continue; + } + if (('A' <= ch && ch <= 'Z') || + ('a' <= ch && ch <= 'z') || + ch == '-') { + seen_head = 1; + continue; + } + /* no empty last line doesn't match */ + return 0; + } + return seen_head && seen_name; +} + static int append_signoff(char *buf, int buf_sz, int at, const char *signoff) { - int signoff_len = strlen(signoff); static const char signed_off_by[] = "Signed-off-by: "; + int signoff_len = strlen(signoff); + int has_signoff = 0; char *cp = buf; /* Do we have enough space to add it? */ @@ -23,58 +71,26 @@ static int append_signoff(char *buf, int buf_sz, int at, const char *signoff) return at; /* First see if we already have the sign-off by the signer */ - while (1) { - cp = strstr(cp, signed_off_by); - if (!cp) - break; + while ((cp = strstr(cp, signed_off_by))) { + + has_signoff = 1; + cp += strlen(signed_off_by); - if ((cp + signoff_len < buf + at) && - !strncmp(cp, signoff, signoff_len) && - isspace(cp[signoff_len])) - return at; /* we already have him */ + if (cp + signoff_len >= buf + at) + break; + if (strncmp(cp, signoff, signoff_len)) + continue; + if (!isspace(cp[signoff_len])) + continue; + /* we already have him */ + return at; } - /* Does the last line already end with "^[-A-Za-z]+: [^@]+@"? - * If not, add a blank line to separate the message from - * the run of Signed-off-by: and Acked-by: lines. - */ - { - char ch; - int seen_colon, seen_at, seen_name, seen_head, not_signoff; - seen_colon = 0; - seen_at = 0; - seen_name = 0; - seen_head = 0; - not_signoff = 0; - cp = buf + at; - while (buf <= --cp && (ch = *cp) == '\n') - ; - while (!not_signoff && buf <= cp && (ch = *cp--) != '\n') { - if (!seen_at) { - if (ch == '@') - seen_at = 1; - continue; - } - if (!seen_colon) { - if (ch == '@') - not_signoff = 1; - else if (ch == ':') - seen_colon = 1; - else - seen_name = 1; - continue; - } - if (('A' <= ch && ch <= 'Z') || - ('a' <= ch && ch <= 'z') || - ch == '-') { - seen_head = 1; - continue; - } - not_signoff = 1; - } - if (not_signoff || !seen_head || !seen_name) - buf[at++] = '\n'; - } + if (!has_signoff) + has_signoff = detect_any_signoff(buf, at); + + if (!has_signoff) + buf[at++] = '\n'; strcpy(buf + at, signed_off_by); at += strlen(signed_off_by); -- cgit v1.2.3 From 2b60356da5369dd60ab26eabaa91d95b6badf209 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Thu, 26 Oct 2006 18:52:39 +0200 Subject: Make git-cherry handle root trees This patch on top of 'next' makes built-in git-cherry handle root commits. It moves the static function log-tree.c::diff_root_tree() to tree-diff.c and makes it more similar to diff_tree_sha1() by shuffling around arguments and factoring out the call to log_tree_diff_flush(). Consequently the name is changed to diff_root_tree_sha1(). It is a version of diff_tree_sha1() that compares the empty tree (= root tree) against a single 'real' tree. This function is then used in get_patch_id() to compute patch IDs for initial commits instead of SEGFAULTing, as the current code does if confronted with parentless commits. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- log-tree.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index fbe139920a..8787df5cc6 100644 --- a/log-tree.c +++ b/log-tree.c @@ -252,26 +252,6 @@ int log_tree_diff_flush(struct rev_info *opt) return 1; } -static int diff_root_tree(struct rev_info *opt, - const unsigned char *new, const char *base) -{ - int retval; - void *tree; - struct tree_desc empty, real; - - tree = read_object_with_reference(new, tree_type, &real.size, NULL); - if (!tree) - die("unable to read root tree (%s)", sha1_to_hex(new)); - real.buf = tree; - - empty.buf = ""; - empty.size = 0; - retval = diff_tree(&empty, &real, base, &opt->diffopt); - free(tree); - log_tree_diff_flush(opt); - return retval; -} - static int do_diff_combined(struct rev_info *opt, struct commit *commit) { unsigned const char *sha1 = commit->object.sha1; @@ -297,8 +277,10 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log /* Root commit? */ parents = commit->parents; if (!parents) { - if (opt->show_root_diff) - diff_root_tree(opt, sha1, ""); + if (opt->show_root_diff) { + diff_root_tree_sha1(sha1, "", &opt->diffopt); + log_tree_diff_flush(opt); + } return !opt->loginfo; } -- cgit v1.2.3 From 74bd9029732db28b2fff50de0a190229c6033e02 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 16 Dec 2006 15:31:25 -0800 Subject: Teach all of log family --left-right output. This makes reviewing git log --left-right --merge --no-merges -p a lot more pleasant. Signed-off-by: Junio C Hamano --- log-tree.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 8787df5cc6..35be33aaf7 100644 --- a/log-tree.c +++ b/log-tree.c @@ -114,6 +114,14 @@ void show_log(struct rev_info *opt, const char *sep) opt->loginfo = NULL; if (!opt->verbose_header) { + if (opt->left_right) { + if (commit->object.flags & BOUNDARY) + putchar('-'); + else if (commit->object.flags & SYMMETRIC_LEFT) + putchar('<'); + else + putchar('>'); + } fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); if (opt->parents) show_parents(commit, abbrev_commit); @@ -192,10 +200,20 @@ void show_log(struct rev_info *opt, const char *sep) opt->diffopt.stat_sep = buffer; } } else { - printf("%s%s%s", - diff_get_color(opt->diffopt.color_diff, DIFF_COMMIT), - opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ", - diff_unique_abbrev(commit->object.sha1, abbrev_commit)); + fputs(diff_get_color(opt->diffopt.color_diff, DIFF_COMMIT), + stdout); + if (opt->commit_format != CMIT_FMT_ONELINE) + fputs("commit ", stdout); + if (opt->left_right) { + if (commit->object.flags & BOUNDARY) + putchar('-'); + else if (commit->object.flags & SYMMETRIC_LEFT) + putchar('<'); + else + putchar('>'); + } + fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), + stdout); if (opt->parents) show_parents(commit, abbrev_commit); if (parent) -- cgit v1.2.3 From 8860fd42fcf5a7853f7d7c2198793183320293ff Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 11 Jan 2007 11:47:48 +0100 Subject: Teach the revision walker to walk by reflogs with --walk-reflogs When called with "--walk-reflogs", as long as there are reflogs available, the walker will take this information into account, rather than the parent information in the commit object. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- log-tree.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 35be33aaf7..f043ad3723 100644 --- a/log-tree.c +++ b/log-tree.c @@ -2,6 +2,7 @@ #include "diff.h" #include "commit.h" #include "log-tree.h" +#include "reflog-walk.h" static void show_parents(struct commit *commit, int abbrev) { @@ -223,6 +224,8 @@ void show_log(struct rev_info *opt, const char *sep) printf("%s", diff_get_color(opt->diffopt.color_diff, DIFF_RESET)); putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); + if (opt->reflog_info) + show_reflog_message(opt->reflog_info); } /* -- cgit v1.2.3 From 4d12a471230625da73be464f5a20b7480a6b8ecb Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 20 Jan 2007 00:51:41 -0800 Subject: Fix --walk-reflog with --pretty=oneline Now, "git log --abbrev-commit --pretty=o --walk-reflogs HEAD" is reasonably pleasant to use. Signed-off-by: Junio C Hamano --- log-tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index f043ad3723..c0fa096327 100644 --- a/log-tree.c +++ b/log-tree.c @@ -225,7 +225,8 @@ void show_log(struct rev_info *opt, const char *sep) diff_get_color(opt->diffopt.color_diff, DIFF_RESET)); putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); if (opt->reflog_info) - show_reflog_message(opt->reflog_info); + show_reflog_message(opt->reflog_info, + opt->commit_format == CMIT_FMT_ONELINE);; } /* -- cgit v1.2.3 From 903b45fe1808f72e712a118bf115b9dc07d02420 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Sat, 27 Jan 2007 22:40:36 -0500 Subject: git-log -g --pretty=oneline should display the reflog message In the context of reflog output the reflog message is more useful than the commit message's first line. When relevant the reflog message will contain that line anyway. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- log-tree.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index c0fa096327..d8ca36bbdd 100644 --- a/log-tree.c +++ b/log-tree.c @@ -224,9 +224,14 @@ void show_log(struct rev_info *opt, const char *sep) printf("%s", diff_get_color(opt->diffopt.color_diff, DIFF_RESET)); putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); - if (opt->reflog_info) + if (opt->reflog_info) { show_reflog_message(opt->reflog_info, opt->commit_format == CMIT_FMT_ONELINE);; + if (opt->commit_format == CMIT_FMT_ONELINE) { + printf("%s", sep); + return; + } + } } /* -- cgit v1.2.3 From abd4e22269e97f3d650277335a111e9bae32f8cb Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 7 Feb 2007 11:49:56 -0800 Subject: Fix "git log -z" behaviour For commit messages, we should really put the "line_termination" when we output the character in between different commits, *not* between the commit and the diff. The diff goes hand-in-hand with the commit, it shouldn't be separated from it with the termination character. So this: - uses the termination character for true inter-commit spacing - uses a regular newline between the commit log and the diff We had it the other way around. For the normal case where the termination character is '\n', this obviously doesn't change anything at all, since we just switched two identical characters around. So it's very safe - it doesn't change any normal usage, but it definitely fixes "git log -z". By fixing "git log -z", you can now also do insane things like git log -p -z | grep -z "some patch expression" | tr '\0' '\n' | less -S and you will see only those commits that have the "some patch expression" in their commit message _or_ their patches. (This is slightly different from 'git log -S"some patch expression"', since the latter requires the expression to literally *change* in the patch, while the "git log -p -z | grep .." approach will see it if it's just an unchanged _part_ of the patch context) Of course, if you actually do something like the above, you're probably insane, but hey, it works! Try the above command line for a demonstration (of course, you need to change the "some patch expression" to be something relevant). The old behaviour of "git log -p -z" was useless (and got things completely wrong for log entries without patches). Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- log-tree.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index d8ca36bbdd..85acd66df7 100644 --- a/log-tree.c +++ b/log-tree.c @@ -143,7 +143,7 @@ void show_log(struct rev_info *opt, const char *sep) if (*sep != '\n' && opt->commit_format == CMIT_FMT_ONELINE) extra = "\n"; if (opt->shown_one && opt->commit_format != CMIT_FMT_ONELINE) - putchar('\n'); + putchar(opt->diffopt.line_termination); opt->shown_one = 1; /* @@ -270,9 +270,8 @@ int log_tree_diff_flush(struct rev_info *opt) opt->commit_format != CMIT_FMT_ONELINE) { int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH; if ((pch & opt->diffopt.output_format) == pch) - printf("---%c", opt->diffopt.line_termination); - else - putchar(opt->diffopt.line_termination); + printf("---"); + putchar('\n'); } } diff_flush(&opt->diffopt); -- cgit v1.2.3 From 4e244cbc5cc4c8a43982d4023bc0d9fb0b0c7d43 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 8 Feb 2007 21:58:33 +0100 Subject: log --reflog: honour --relative-date If you say "git log -g --relative-date", it is very likely that you want to see the reflog names in terms of a relative date. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- log-tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 85acd66df7..4e3c7fd6fb 100644 --- a/log-tree.c +++ b/log-tree.c @@ -226,7 +226,8 @@ void show_log(struct rev_info *opt, const char *sep) putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); if (opt->reflog_info) { show_reflog_message(opt->reflog_info, - opt->commit_format == CMIT_FMT_ONELINE);; + opt->commit_format == CMIT_FMT_ONELINE, + opt->relative_date); if (opt->commit_format == CMIT_FMT_ONELINE) { printf("%s", sep); return; -- cgit v1.2.3 From e00de24b102da647485aeeeff278c21ab31420a2 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 9 Feb 2007 01:43:54 +0100 Subject: format-patch -n: make sorting easier by padding number Now, when format-patch outputs more than 9 patches, the numbers are padded accordingly. Example: [PATCH 009/167] The 9th patch of a series of 167 Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- log-tree.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 4e3c7fd6fb..ac86194047 100644 --- a/log-tree.c +++ b/log-tree.c @@ -102,6 +102,16 @@ static int append_signoff(char *buf, int buf_sz, int at, const char *signoff) return at; } +static unsigned int digits_in_number(unsigned int number) +{ + unsigned int i = 10, result = 1; + while (i <= number) { + i *= 10; + result++; + } + return result; +} + void show_log(struct rev_info *opt, const char *sep) { static char this_header[16384]; @@ -155,7 +165,8 @@ void show_log(struct rev_info *opt, const char *sep) if (opt->total > 0) { static char buffer[64]; snprintf(buffer, sizeof(buffer), - "Subject: [PATCH %d/%d] ", + "Subject: [PATCH %0*d/%d] ", + digits_in_number(opt->total), opt->nr, opt->total); subject = buffer; } else if (opt->total == 0) -- cgit v1.2.3 From e52a5de45ab8b61bdddf48a466cb3388b38ad7a4 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 23 Feb 2007 01:35:03 +0100 Subject: pretty-formats: add 'format:' With this patch, $ git show -s \ --pretty=format:' Ze komit %h woss%n dunn buy ze great %an' shows something like Ze komit 04c5c88 woss dunn buy ze great Junio C Hamano The supported placeholders are: '%H': commit hash '%h': abbreviated commit hash '%T': tree hash '%t': abbreviated tree hash '%P': parent hashes '%p': abbreviated parent hashes '%an': author name '%ae': author email '%ad': author date '%aD': author date, RFC2822 style '%ar': author date, relative '%at': author date, UNIX timestamp '%cn': committer name '%ce': committer email '%cd': committer date '%cD': committer date, RFC2822 style '%cr': committer date, relative '%ct': committer date, UNIX timestamp '%e': encoding '%s': subject '%b': body '%Cred': switch color to red '%Cgreen': switch color to green '%Cblue': switch color to blue '%Creset': reset color '%n': newline Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- log-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index ac86194047..6ce239d8f9 100644 --- a/log-tree.c +++ b/log-tree.c @@ -211,7 +211,7 @@ void show_log(struct rev_info *opt, const char *sep) sha1, sha1); opt->diffopt.stat_sep = buffer; } - } else { + } else if (opt->commit_format != CMIT_FMT_USERFORMAT) { fputs(diff_get_color(opt->diffopt.color_diff, DIFF_COMMIT), stdout); if (opt->commit_format != CMIT_FMT_ONELINE) -- cgit v1.2.3 From c112f689c2c4dfbf2e4dca0e91aa527dd96ab333 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 4 Mar 2007 00:12:06 +0100 Subject: format-patch: add --inline option and make --attach a true attachment The existing --attach option did not create a true "attachment" but multipart/mixed with Content-Disposition: inline. It should have been with Content-Disposition: attachment. Introduce --inline to add multipart/mixed that is inlined, and make --attach to create an attachement. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- log-tree.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 6ce239d8f9..7b3ad7d5f0 100644 --- a/log-tree.c +++ b/log-tree.c @@ -205,10 +205,12 @@ void show_log(struct rev_info *opt, const char *sep) "Content-Type: text/x-patch;\n" " name=\"%s.diff\"\n" "Content-Transfer-Encoding: 8bit\n" - "Content-Disposition: inline;\n" + "Content-Disposition: %s;\n" " filename=\"%s.diff\"\n\n", mime_boundary_leader, opt->mime_boundary, - sha1, sha1); + sha1, + opt->no_inline ? "attachment" : "inline", + sha1); opt->diffopt.stat_sep = buffer; } } else if (opt->commit_format != CMIT_FMT_USERFORMAT) { -- cgit v1.2.3 From 33ee4cfb6929c77307887bc2124eaeaf011892dc Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 4 Mar 2007 16:08:04 -0800 Subject: format-patch --attach: not folding some long headers. Panagiotis Issaris reports that some MUAs seem not to like folded "content-type" and "content-disposition" headers, so this makes format-patch --attach output to avoid them. Signed-off-by: Junio C Hamano --- log-tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 7b3ad7d5f0..8797aa14c4 100644 --- a/log-tree.c +++ b/log-tree.c @@ -186,7 +186,7 @@ void show_log(struct rev_info *opt, const char *sep) snprintf(subject_buffer, sizeof(subject_buffer) - 1, "%s" "MIME-Version: 1.0\n" - "Content-Type: multipart/mixed;\n" + "Content-Type: multipart/mixed;" " boundary=\"%s%s\"\n" "\n" "This is a multi-part message in MIME " @@ -202,10 +202,10 @@ void show_log(struct rev_info *opt, const char *sep) snprintf(buffer, sizeof(buffer) - 1, "--%s%s\n" - "Content-Type: text/x-patch;\n" + "Content-Type: text/x-patch;" " name=\"%s.diff\"\n" "Content-Transfer-Encoding: 8bit\n" - "Content-Disposition: %s;\n" + "Content-Disposition: %s;" " filename=\"%s.diff\"\n\n", mime_boundary_leader, opt->mime_boundary, sha1, -- cgit v1.2.3 From 2d9e4a47d16e9d2100cc88ef6126aa7619be51ed Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Wed, 11 Apr 2007 16:58:07 -0700 Subject: Add custom subject prefix support to format-patch (take 3) Add a new option to git-format-patch, entitled --subject-prefix that allows control of the subject prefix '[PATCH]'. Using this option, the text 'PATCH' is replaced with whatever input is provided to the option. This allows easily generating patches like '[PATCH 2.6.21-rc3]' or properly numbered series like '[-mm3 PATCH N/M]'. This patch provides the implementation and documentation. Signed-off-by: Robin H. Johnson Signed-off-by: Junio C Hamano --- log-tree.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 8797aa14c4..dad5513230 100644 --- a/log-tree.c +++ b/log-tree.c @@ -165,14 +165,20 @@ void show_log(struct rev_info *opt, const char *sep) if (opt->total > 0) { static char buffer[64]; snprintf(buffer, sizeof(buffer), - "Subject: [PATCH %0*d/%d] ", + "Subject: [%s %0*d/%d] ", + opt->subject_prefix, digits_in_number(opt->total), opt->nr, opt->total); subject = buffer; - } else if (opt->total == 0) - subject = "Subject: [PATCH] "; - else + } else if (opt->total == 0) { + static char buffer[256]; + snprintf(buffer, sizeof(buffer), + "Subject: [%s] ", + opt->subject_prefix); + subject = buffer; + } else { subject = "Subject: "; + } printf("From %s Mon Sep 17 00:00:00 2001\n", sha1); if (opt->message_id) -- cgit v1.2.3 From ca135e7acc06f7d24ead732d2a1a531428da7135 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 16 Apr 2007 16:05:10 -0700 Subject: Add support for "commit name decorations" to log family of commands This adds "--decorate" as a log option, which prints out the ref names of any commits that are shown. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- log-tree.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index dad5513230..300b733560 100644 --- a/log-tree.c +++ b/log-tree.c @@ -4,6 +4,8 @@ #include "log-tree.h" #include "reflog-walk.h" +struct decoration name_decoration = { "object names" }; + static void show_parents(struct commit *commit, int abbrev) { struct commit_list *p; @@ -13,6 +15,23 @@ static void show_parents(struct commit *commit, int abbrev) } } +static void show_decorations(struct commit *commit) +{ + const char *prefix; + struct name_decoration *decoration; + + decoration = lookup_decoration(&name_decoration, &commit->object); + if (!decoration) + return; + prefix = " ("; + while (decoration) { + printf("%s%s", prefix, decoration->name); + prefix = ", "; + decoration = decoration->next; + } + putchar(')'); +} + /* * Search for "^[-A-Za-z]+: [^@]+@" pattern. It usually matches * Signed-off-by: and Acked-by: lines. @@ -136,6 +155,7 @@ void show_log(struct rev_info *opt, const char *sep) fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); if (opt->parents) show_parents(commit, abbrev_commit); + show_decorations(commit); putchar(opt->diffopt.line_termination); return; } @@ -240,6 +260,7 @@ void show_log(struct rev_info *opt, const char *sep) printf(" (from %s)", diff_unique_abbrev(parent->object.sha1, abbrev_commit)); + show_decorations(commit); printf("%s", diff_get_color(opt->diffopt.color_diff, DIFF_RESET)); putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); -- cgit v1.2.3 From a7b02ccf9a682fa0c2b28df6ca20f9199cdca4de Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 24 Apr 2007 23:36:22 -0700 Subject: Add --date={local,relative,default} This adds --date={local,relative,default} option to log family of commands, to allow displaying timestamps in user's local timezone, relative time, or the default format. Existing --relative-date option is a synonym of --date=relative; we could probably deprecate it in the long run. Signed-off-by: Junio C Hamano --- log-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 300b733560..c679324c07 100644 --- a/log-tree.c +++ b/log-tree.c @@ -267,7 +267,7 @@ void show_log(struct rev_info *opt, const char *sep) if (opt->reflog_info) { show_reflog_message(opt->reflog_info, opt->commit_format == CMIT_FMT_ONELINE, - opt->relative_date); + opt->date_mode); if (opt->commit_format == CMIT_FMT_ONELINE) { printf("%s", sep); return; @@ -280,7 +280,7 @@ void show_log(struct rev_info *opt, const char *sep) */ len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject, - extra_headers, opt->relative_date); + extra_headers, opt->date_mode); if (opt->add_signoff) len = append_signoff(this_header, sizeof(this_header), len, -- cgit v1.2.3 From e330a406cd20cf45a6816929155181c37678bc47 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 5 May 2007 15:18:03 -0700 Subject: Fix --boundary output "git log --boundary" incorrectly honoured the option only when "left-right" was enabled. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- log-tree.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 8797aa14c4..dbd06490f9 100644 --- a/log-tree.c +++ b/log-tree.c @@ -218,10 +218,10 @@ void show_log(struct rev_info *opt, const char *sep) stdout); if (opt->commit_format != CMIT_FMT_ONELINE) fputs("commit ", stdout); - if (opt->left_right) { - if (commit->object.flags & BOUNDARY) - putchar('-'); - else if (commit->object.flags & SYMMETRIC_LEFT) + if (commit->object.flags & BOUNDARY) + putchar('-'); + else if (opt->left_right) { + if (commit->object.flags & SYMMETRIC_LEFT) putchar('<'); else putchar('>'); -- cgit v1.2.3 From 80583c0ef61cc966c7eee79cf3623a83197e19b8 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 11 Jun 2007 00:34:54 -0700 Subject: Lift 16kB limit of log message output Traditionally we had 16kB limit when formatting log messages for output, because it was easier to arrange for the caller to have a reasonably big buffer and pass it down without ever worrying about reallocating. This changes the calling convention of pretty_print_commit() to lift this limit. Instead of the buffer and remaining length, it now takes a pointer to the pointer that points at the allocated buffer, and another pointer to the location that stores the allocated length, and reallocates the buffer as necessary. To support the user format, the error return of interpolate() needed to be changed. It used to return a bool telling "Ok the result fits", or "Sorry, I had to truncate it". Now it returns 0 on success, and returns the size of the buffer it wants in order to fit the whole result. Signed-off-by: Junio C Hamano --- log-tree.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 4bef909144..0cf21bc051 100644 --- a/log-tree.c +++ b/log-tree.c @@ -79,16 +79,25 @@ static int detect_any_signoff(char *letter, int size) return seen_head && seen_name; } -static int append_signoff(char *buf, int buf_sz, int at, const char *signoff) +static unsigned long append_signoff(char **buf_p, unsigned long *buf_sz_p, + unsigned long at, const char *signoff) { static const char signed_off_by[] = "Signed-off-by: "; - int signoff_len = strlen(signoff); + size_t signoff_len = strlen(signoff); int has_signoff = 0; - char *cp = buf; - - /* Do we have enough space to add it? */ - if (buf_sz - at <= strlen(signed_off_by) + signoff_len + 3) - return at; + char *cp; + char *buf; + unsigned long buf_sz; + + buf = *buf_p; + buf_sz = *buf_sz_p; + if (buf_sz <= at + strlen(signed_off_by) + signoff_len + 3) { + buf_sz += strlen(signed_off_by) + signoff_len + 3; + buf = xrealloc(buf, buf_sz); + *buf_p = buf; + *buf_sz_p = buf_sz; + } + cp = buf; /* First see if we already have the sign-off by the signer */ while ((cp = strstr(cp, signed_off_by))) { @@ -133,7 +142,8 @@ static unsigned int digits_in_number(unsigned int number) void show_log(struct rev_info *opt, const char *sep) { - static char this_header[16384]; + char *msgbuf = NULL; + unsigned long msgbuf_len = 0; struct log_info *log = opt->loginfo; struct commit *commit = log->commit, *parent = log->parent; int abbrev = opt->diffopt.abbrev; @@ -278,14 +288,15 @@ void show_log(struct rev_info *opt, const char *sep) /* * 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, + &msgbuf, &msgbuf_len, abbrev, subject, extra_headers, opt->date_mode); if (opt->add_signoff) - len = append_signoff(this_header, sizeof(this_header), len, + len = append_signoff(&msgbuf, &msgbuf_len, len, opt->add_signoff); - printf("%s%s%s", this_header, extra, sep); + printf("%s%s%s", msgbuf, extra, sep); + free(msgbuf); } int log_tree_diff_flush(struct rev_info *opt) -- cgit v1.2.3 From 06f59e9f5daa06fc4bd51cf4c508b3edd3ed514a Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 29 Jun 2007 13:40:46 -0400 Subject: Don't fflush(stdout) when it's not helpful This patch arose from a discussion started by Jim Meyering's patch whose intention was to provide better diagnostics for failed writes. Linus proposed a better way to do things, which also had the added benefit that adding a fflush() to git-log-* operations and incremental git-blame operations could improve interactive respose time feel, at the cost of making things a bit slower when we aren't piping the output to a downstream program. This patch skips the fflush() calls when stdout is a regular file, or if the environment variable GIT_FLUSH is set to "0". This latter can speed up a command such as: GIT_FLUSH=0 strace -c -f -e write time git-rev-list HEAD | wc -l a tiny amount. Signed-off-by: "Theodore Ts'o" Acked-by: Linus Torvalds Signed-off-by: Junio C Hamano --- log-tree.c | 1 + 1 file changed, 1 insertion(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 0cf21bc051..ced3f332ef 100644 --- a/log-tree.c +++ b/log-tree.c @@ -408,5 +408,6 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit) shown = 1; } opt->loginfo = NULL; + maybe_flush_or_die(stdout, "stdout"); return shown; } -- cgit v1.2.3 From 88c447e8f467c6b2ca09ad91f3fa1d1d662dd04d Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Wed, 4 Jul 2007 12:33:46 +0200 Subject: Handle missing prefix for "Subject:" as if no prefix given Signed-off-by: Junio C Hamano --- log-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index ced3f332ef..8624d5a39c 100644 --- a/log-tree.c +++ b/log-tree.c @@ -200,7 +200,7 @@ void show_log(struct rev_info *opt, const char *sep) digits_in_number(opt->total), opt->nr, opt->total); subject = buffer; - } else if (opt->total == 0) { + } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) { static char buffer[256]; snprintf(buffer, sizeof(buffer), "Subject: [%s] ", -- cgit v1.2.3 From 9fa3465d6be83c08ed24762c82eb33cb005729f3 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Fri, 20 Jul 2007 20:15:13 +0200 Subject: Add --log-size to git log to print message size With this option git-log prints log message size just before the corresponding message. Porcelain tools could use this to speedup parsing of git-log output. Note that size refers to log message only. If also patch content is shown its size is not included. In case it is not possible to know the size upfront size value is set to zero. Signed-off-by: Marco Costalba Signed-off-by: Junio C Hamano --- log-tree.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 8624d5a39c..a6423718e7 100644 --- a/log-tree.c +++ b/log-tree.c @@ -295,6 +295,9 @@ void show_log(struct rev_info *opt, const char *sep) if (opt->add_signoff) len = append_signoff(&msgbuf, &msgbuf_len, len, opt->add_signoff); + if (opt->show_log_size) + printf("log size %i\n", len); + printf("%s%s%s", msgbuf, extra, sep); free(msgbuf); } -- cgit v1.2.3 From 674d1727305211f7ade4ade70440220f74f55162 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Mon, 10 Sep 2007 12:35:06 +0200 Subject: Rework pretty_print_commit to use strbufs instead of custom buffers. Also remove the "len" parameter, as: (1) it was used as a max boundary, and every caller used ~0u (2) we check for final NUL no matter what, so it doesn't help for speed. As a result most of the pp_* function takes 3 arguments less, and we need a lot less local variables, this makes the code way more readable, and easier to extend if needed. This patch also fixes some spacing and cosmetic issues. This patch also fixes (as a side effect) a memory leak intoruced in builtin-archive.c at commit df4a394f (fmt was xmalloc'ed and not free'd) Signed-off-by: Pierre Habouzit Signed-off-by: Junio C Hamano --- log-tree.c | 56 +++++++++++++++++++------------------------------------- 1 file changed, 19 insertions(+), 37 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index a6423718e7..3e5e6acfaf 100644 --- a/log-tree.c +++ b/log-tree.c @@ -79,25 +79,14 @@ static int detect_any_signoff(char *letter, int size) return seen_head && seen_name; } -static unsigned long append_signoff(char **buf_p, unsigned long *buf_sz_p, - unsigned long at, const char *signoff) +static void append_signoff(struct strbuf *sb, const char *signoff) { static const char signed_off_by[] = "Signed-off-by: "; size_t signoff_len = strlen(signoff); int has_signoff = 0; char *cp; - char *buf; - unsigned long buf_sz; - - buf = *buf_p; - buf_sz = *buf_sz_p; - if (buf_sz <= at + strlen(signed_off_by) + signoff_len + 3) { - buf_sz += strlen(signed_off_by) + signoff_len + 3; - buf = xrealloc(buf, buf_sz); - *buf_p = buf; - *buf_sz_p = buf_sz; - } - cp = buf; + + cp = sb->buf; /* First see if we already have the sign-off by the signer */ while ((cp = strstr(cp, signed_off_by))) { @@ -105,29 +94,25 @@ static unsigned long append_signoff(char **buf_p, unsigned long *buf_sz_p, has_signoff = 1; cp += strlen(signed_off_by); - if (cp + signoff_len >= buf + at) + if (cp + signoff_len >= sb->buf + sb->len) break; if (strncmp(cp, signoff, signoff_len)) continue; if (!isspace(cp[signoff_len])) continue; /* we already have him */ - return at; + return; } if (!has_signoff) - has_signoff = detect_any_signoff(buf, at); + has_signoff = detect_any_signoff(sb->buf, sb->len); if (!has_signoff) - buf[at++] = '\n'; - - strcpy(buf + at, signed_off_by); - at += strlen(signed_off_by); - strcpy(buf + at, signoff); - at += signoff_len; - buf[at++] = '\n'; - buf[at] = 0; - return at; + strbuf_addch(sb, '\n'); + + strbuf_addstr(sb, signed_off_by); + strbuf_add(sb, signoff, signoff_len); + strbuf_addch(sb, '\n'); } static unsigned int digits_in_number(unsigned int number) @@ -142,14 +127,12 @@ static unsigned int digits_in_number(unsigned int number) void show_log(struct rev_info *opt, const char *sep) { - char *msgbuf = NULL; - unsigned long msgbuf_len = 0; + struct strbuf msgbuf; struct log_info *log = opt->loginfo; struct commit *commit = log->commit, *parent = log->parent; int abbrev = opt->diffopt.abbrev; int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40; const char *extra; - int len; const char *subject = NULL, *extra_headers = opt->extra_headers; opt->loginfo = NULL; @@ -288,18 +271,17 @@ void show_log(struct rev_info *opt, const char *sep) /* * And then the pretty-printed message itself */ - len = pretty_print_commit(opt->commit_format, commit, ~0u, - &msgbuf, &msgbuf_len, abbrev, subject, - extra_headers, opt->date_mode); + strbuf_init(&msgbuf, 0); + pretty_print_commit(opt->commit_format, commit, &msgbuf, + abbrev, subject, extra_headers, opt->date_mode); if (opt->add_signoff) - len = append_signoff(&msgbuf, &msgbuf_len, len, - opt->add_signoff); + append_signoff(&msgbuf, opt->add_signoff); if (opt->show_log_size) - printf("log size %i\n", len); + printf("log size %i\n", (int)msgbuf.len); - printf("%s%s%s", msgbuf, extra, sep); - free(msgbuf); + printf("%s%s%s", msgbuf.buf, extra, sep); + strbuf_release(&msgbuf); } int log_tree_diff_flush(struct rev_info *opt) -- cgit v1.2.3 From 55246aac6717e86c14f31391ac903ed810d1a9a0 Mon Sep 17 00:00:00 2001 From: Michal Vitecek Date: Tue, 25 Sep 2007 16:38:46 +0200 Subject: Don't use "" for placeholders and suppress printing of empty user formats. This changes the interporate() to replace entries with NULL values by the empty string, and uses it to interpolate missing fields in custom format output used in git-log and friends. It is most useful to avoid output from %b format for a commit log message that lack any body text. Signed-off-by: Junio C Hamano --- log-tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index a6423718e7..79e3dee276 100644 --- a/log-tree.c +++ b/log-tree.c @@ -298,7 +298,8 @@ void show_log(struct rev_info *opt, const char *sep) if (opt->show_log_size) printf("log size %i\n", len); - printf("%s%s%s", msgbuf, extra, sep); + if (*msgbuf) + printf("%s%s%s", msgbuf, extra, sep); free(msgbuf); } -- cgit v1.2.3 From 304b5af64f9b5a6b5e9455e2dcab381c568452b6 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 9 Oct 2007 09:35:22 -0700 Subject: Clean up "git log" format with DIFF_FORMAT_NO_OUTPUT This fixes an unnecessary empty line that we add to the log message when we generate diffs, but don't actually end up printing any due to having DIFF_FORMAT_NO_OUTPUT set. This can happen with pickaxe or with rename following. The reason is that we normally add an empty line between the commit and the diff, but we do that even for the case where we've then suppressed the actual printing of the diff. This also updates a couple of tests that assumed the extraneous empty line would exist at the end of output. Signed-off-by: Linus Torvalds Signed-off-by: Lars Hjemli Signed-off-by: Shawn O. Pearce --- log-tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index a6423718e7..b509c0c7ec 100644 --- a/log-tree.c +++ b/log-tree.c @@ -321,7 +321,8 @@ int log_tree_diff_flush(struct rev_info *opt) * output for readability. */ show_log(opt, opt->diffopt.msg_sep); - if (opt->verbose_header && + if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) && + opt->verbose_header && opt->commit_format != CMIT_FMT_ONELINE) { int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH; if ((pch & opt->diffopt.output_format) == pch) -- cgit v1.2.3 From 50e62a8e703b78fbe59d5f98b1bb36464570a815 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Mon, 22 Oct 2007 07:47:56 +0200 Subject: rev-list: implement --bisect-all This is Junio's patch with some stuff to make --bisect-all compatible with --bisect-vars. This option makes it possible to see all the potential bisection points. The best ones are displayed first. Signed-off-by: Christian Couder Signed-off-by: Shawn O. Pearce --- log-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 62edd34455..3763ce94fc 100644 --- a/log-tree.c +++ b/log-tree.c @@ -15,7 +15,7 @@ static void show_parents(struct commit *commit, int abbrev) } } -static void show_decorations(struct commit *commit) +void show_decorations(struct commit *commit) { const char *prefix; struct name_decoration *decoration; -- cgit v1.2.3 From 4593fb84051d39f65cec81958e91056986e4682f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 31 Oct 2007 14:55:17 -0700 Subject: format-patch -s: add MIME encoding header if signer's name requires so When the body of the commit log message contains a non-ASCII character, format-patch correctly emitted the encoding header to mark the resulting message as such. However, if the original message was fully ASCII, the command line switch "-s" was given to add a new sign-off, and the signer's name was not ASCII only, the resulting message would have contained non-ASCII character but was not marked as such. Signed-off-by: Junio C Hamano --- log-tree.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 3763ce94fc..a34beb0b02 100644 --- a/log-tree.c +++ b/log-tree.c @@ -125,6 +125,18 @@ static unsigned int digits_in_number(unsigned int number) return result; } +static int has_non_ascii(const char *s) +{ + int ch; + if (!s) + return 0; + while ((ch = *s++) != '\0') { + if (non_ascii(ch)) + return 1; + } + return 0; +} + void show_log(struct rev_info *opt, const char *sep) { struct strbuf msgbuf; @@ -273,7 +285,8 @@ void show_log(struct rev_info *opt, const char *sep) */ strbuf_init(&msgbuf, 0); pretty_print_commit(opt->commit_format, commit, &msgbuf, - abbrev, subject, extra_headers, opt->date_mode); + abbrev, subject, extra_headers, opt->date_mode, + has_non_ascii(opt->add_signoff)); if (opt->add_signoff) append_signoff(&msgbuf, opt->add_signoff); -- cgit v1.2.3 From 8f67f8aefb1b751073f8b36fae8be8f72eb93f4a Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sat, 10 Nov 2007 20:05:14 +0100 Subject: Make the diff_options bitfields be an unsigned with explicit masks. reverse_diff was a bit-value in disguise, it's merged in the flags now. Signed-off-by: Pierre Habouzit Signed-off-by: Junio C Hamano --- log-tree.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index a34beb0b02..1f3fcf16ad 100644 --- a/log-tree.c +++ b/log-tree.c @@ -245,8 +245,7 @@ void show_log(struct rev_info *opt, const char *sep) opt->diffopt.stat_sep = buffer; } } else if (opt->commit_format != CMIT_FMT_USERFORMAT) { - fputs(diff_get_color(opt->diffopt.color_diff, DIFF_COMMIT), - stdout); + fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout); if (opt->commit_format != CMIT_FMT_ONELINE) fputs("commit ", stdout); if (commit->object.flags & BOUNDARY) @@ -266,8 +265,7 @@ void show_log(struct rev_info *opt, const char *sep) diff_unique_abbrev(parent->object.sha1, abbrev_commit)); show_decorations(commit); - printf("%s", - diff_get_color(opt->diffopt.color_diff, DIFF_RESET)); + printf("%s", diff_get_color_opt(&opt->diffopt, DIFF_RESET)); putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); if (opt->reflog_info) { show_reflog_message(opt->reflog_info, -- cgit v1.2.3 From 3131b713013f06285cad3ffdcc61f417ac4ba158 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 9 Feb 2008 14:02:07 -0800 Subject: Add "--show-all" revision walker flag for debugging It's really not very easy to visualize the commit walker, because - on purpose - it obvously doesn't show the uninteresting commits! This adds a "--show-all" flag to the revision walker, which will make it show uninteresting commits too, and they'll have a '^' in front of them (it also fixes a logic error for !verbose_header for boundary commits - we should show the '-' even if left_right isn't shown). A separate patch to gitk to teach it the new '^' was sent to paulus. With the change in place, it actually is interesting even for the cases that git doesn't have any problems with, ie for the kernel you can do: gitk -d --show-all v2.6.24.. and you see just how far down it has to parse things to see it all. The use of "-d" is a good idea, since the date-ordered toposort is much better at showing why it goes deep down (ie the date of some of those commits after 2.6.24 is much older, because they were merged from trees that weren't rebased). So I think this is a useful feature even for non-debugging - just to visualize what git does internally more. When it actually breaks out due to the "everybody_uninteresting()" case, it adds the uninteresting commits (both the one it's looking at now, and the list of pending ones) to the list This way, we really list *all* the commits we've looked at. Because we now end up listing commits we may not even have been parsed at all "show_log" and "show_commit" need to protect against commits that don't have a commit buffer entry. That second part is debatable just how it should work. Maybe we shouldn't show such entries at all (with this patch those entries do get shown, they just don't get any message shown with them). But I think this is a useful case. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- log-tree.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 1f3fcf16ad..e9ba6df9d2 100644 --- a/log-tree.c +++ b/log-tree.c @@ -149,10 +149,12 @@ void show_log(struct rev_info *opt, const char *sep) opt->loginfo = NULL; if (!opt->verbose_header) { - if (opt->left_right) { - if (commit->object.flags & BOUNDARY) - putchar('-'); - else if (commit->object.flags & SYMMETRIC_LEFT) + if (commit->object.flags & BOUNDARY) + putchar('-'); + else if (commit->object.flags & UNINTERESTING) + putchar('^'); + else if (opt->left_right) { + if (commit->object.flags & SYMMETRIC_LEFT) putchar('<'); else putchar('>'); @@ -250,6 +252,8 @@ void show_log(struct rev_info *opt, const char *sep) fputs("commit ", stdout); if (commit->object.flags & BOUNDARY) putchar('-'); + else if (commit->object.flags & UNINTERESTING) + putchar('^'); else if (opt->left_right) { if (commit->object.flags & SYMMETRIC_LEFT) putchar('<'); @@ -278,6 +282,9 @@ void show_log(struct rev_info *opt, const char *sep) } } + if (!commit->buffer) + return; + /* * And then the pretty-printed message itself */ -- cgit v1.2.3 From b02bd65f679024ce25afeddf7e96d6d7aea5fca6 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Mon, 18 Feb 2008 22:56:08 -0500 Subject: Export some email and pretty-printing functions These will be used for generating the cover letter in addition to the patch emails. Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- log-tree.c | 126 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 68 insertions(+), 58 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 1f3fcf16ad..1b084dc27b 100644 --- a/log-tree.c +++ b/log-tree.c @@ -137,6 +137,72 @@ static int has_non_ascii(const char *s) return 0; } +void log_write_email_headers(struct rev_info *opt, const char *name, + const char **subject_p, const char **extra_headers_p) +{ + const char *subject = NULL; + const char *extra_headers = opt->extra_headers; + if (opt->total > 0) { + static char buffer[64]; + snprintf(buffer, sizeof(buffer), + "Subject: [%s %0*d/%d] ", + opt->subject_prefix, + digits_in_number(opt->total), + opt->nr, opt->total); + subject = buffer; + } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) { + static char buffer[256]; + snprintf(buffer, sizeof(buffer), + "Subject: [%s] ", + opt->subject_prefix); + subject = buffer; + } else { + subject = "Subject: "; + } + + printf("From %s Mon Sep 17 00:00:00 2001\n", name); + if (opt->message_id) + printf("Message-Id: <%s>\n", opt->message_id); + if (opt->ref_message_id) + printf("In-Reply-To: <%s>\nReferences: <%s>\n", + opt->ref_message_id, opt->ref_message_id); + if (opt->mime_boundary) { + static char subject_buffer[1024]; + static char buffer[1024]; + snprintf(subject_buffer, sizeof(subject_buffer) - 1, + "%s" + "MIME-Version: 1.0\n" + "Content-Type: multipart/mixed;" + " 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", + extra_headers ? extra_headers : "", + mime_boundary_leader, opt->mime_boundary, + mime_boundary_leader, opt->mime_boundary); + extra_headers = subject_buffer; + + snprintf(buffer, sizeof(buffer) - 1, + "--%s%s\n" + "Content-Type: text/x-patch;" + " name=\"%s.diff\"\n" + "Content-Transfer-Encoding: 8bit\n" + "Content-Disposition: %s;" + " filename=\"%s.diff\"\n\n", + mime_boundary_leader, opt->mime_boundary, + name, + opt->no_inline ? "attachment" : "inline", + name); + opt->diffopt.stat_sep = buffer; + } + *subject_p = subject; + *extra_headers_p = extra_headers; +} + void show_log(struct rev_info *opt, const char *sep) { struct strbuf msgbuf; @@ -186,64 +252,8 @@ void show_log(struct rev_info *opt, const char *sep) */ 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), - "Subject: [%s %0*d/%d] ", - opt->subject_prefix, - digits_in_number(opt->total), - opt->nr, opt->total); - subject = buffer; - } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) { - static char buffer[256]; - snprintf(buffer, sizeof(buffer), - "Subject: [%s] ", - opt->subject_prefix); - subject = buffer; - } else { - subject = "Subject: "; - } - - printf("From %s Mon Sep 17 00:00:00 2001\n", sha1); - if (opt->message_id) - printf("Message-Id: <%s>\n", opt->message_id); - if (opt->ref_message_id) - printf("In-Reply-To: <%s>\nReferences: <%s>\n", - opt->ref_message_id, opt->ref_message_id); - if (opt->mime_boundary) { - static char subject_buffer[1024]; - static char buffer[1024]; - snprintf(subject_buffer, sizeof(subject_buffer) - 1, - "%s" - "MIME-Version: 1.0\n" - "Content-Type: multipart/mixed;" - " 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", - extra_headers ? extra_headers : "", - mime_boundary_leader, opt->mime_boundary, - mime_boundary_leader, opt->mime_boundary); - extra_headers = subject_buffer; - - snprintf(buffer, sizeof(buffer) - 1, - "--%s%s\n" - "Content-Type: text/x-patch;" - " name=\"%s.diff\"\n" - "Content-Transfer-Encoding: 8bit\n" - "Content-Disposition: %s;" - " filename=\"%s.diff\"\n\n", - mime_boundary_leader, opt->mime_boundary, - sha1, - opt->no_inline ? "attachment" : "inline", - sha1); - opt->diffopt.stat_sep = buffer; - } + log_write_email_headers(opt, sha1_to_hex(commit->object.sha1), + &subject, &extra_headers); } else if (opt->commit_format != CMIT_FMT_USERFORMAT) { fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout); if (opt->commit_format != CMIT_FMT_ONELINE) -- cgit v1.2.3 From 6bf4f1b4c9d78b2061bd5f3bf77bb21112b755be Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 14 Mar 2008 17:10:09 -0700 Subject: format-patch: generate MIME header as needed even when there is format.header Earlier, the callchain from pretty_print_commit() down to pp_title_line() had an unwarranted assumption that the presense of "after_subject" parameter, means the caller has already output MIME headers for attachments. The parameter's primary purpose is to give extra header lines the caller wants to place after pp_title_line() generates the "Subject: " line. This assumption does not hold when the user used the format.header configuration variable to pass extra headers, and caused a message with non-ASCII character to lack proper MIME headers (e.g. 8-bit CTE header). The earlier logic also failed to suppress duplicated MIME headers when "format-patch -s --attach" is asked for and the signer's name demanded 8-bit clean transport. This patch fixes the logic by introducing a separate need_8bit_cte parameter passed down the callchain. This can have one of these values: -1 : we've already done MIME crap and we do not want to add extra header to say this is 8bit in pp_title_line(); 0 : we haven't done MIME and we have not seen anything that is 8bit yet; 1 : we haven't done MIME and we have seen something that is 8bit; pp_title_line() must add MIME header. It adds two tests by Jeff King who independently diagnosed this issue. Signed-off-by: Junio C Hamano --- log-tree.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 1f3fcf16ad..dd94f393a0 100644 --- a/log-tree.c +++ b/log-tree.c @@ -146,6 +146,7 @@ void show_log(struct rev_info *opt, const char *sep) int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40; const char *extra; const char *subject = NULL, *extra_headers = opt->extra_headers; + int need_8bit_cte = 0; opt->loginfo = NULL; if (!opt->verbose_header) { @@ -214,6 +215,8 @@ void show_log(struct rev_info *opt, const char *sep) if (opt->mime_boundary) { static char subject_buffer[1024]; static char buffer[1024]; + + need_8bit_cte = -1; /* never */ snprintf(subject_buffer, sizeof(subject_buffer) - 1, "%s" "MIME-Version: 1.0\n" @@ -282,9 +285,11 @@ void show_log(struct rev_info *opt, const char *sep) * And then the pretty-printed message itself */ strbuf_init(&msgbuf, 0); + if (need_8bit_cte >= 0) + need_8bit_cte = has_non_ascii(opt->add_signoff); pretty_print_commit(opt->commit_format, commit, &msgbuf, abbrev, subject, extra_headers, opt->date_mode, - has_non_ascii(opt->add_signoff)); + need_8bit_cte); if (opt->add_signoff) append_signoff(&msgbuf, opt->add_signoff); -- cgit v1.2.3 From 42c8c74c1401352b0f388e47a2c9fcd52171c9d3 Mon Sep 17 00:00:00 2001 From: Govind Salinas Date: Fri, 21 Mar 2008 10:05:06 -0500 Subject: pretty.c: add %x00 format specifier. This adds a %xXX format which inserts two hexdigits after %x as a byte value in the resulting string. This can be used to add a NUL byte or any other byte that can make machine parsing easier. It is also necessary to use fwrite to print out the data since printf will terminate if you feed it a NUL. Signed-off-by: Govind Salinas Signed-off-by: Junio C Hamano --- log-tree.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 5b2963998c..9d54061601 100644 --- a/log-tree.c +++ b/log-tree.c @@ -317,8 +317,10 @@ void show_log(struct rev_info *opt, const char *sep) if (opt->show_log_size) printf("log size %i\n", (int)msgbuf.len); - if (msgbuf.len) - printf("%s%s%s", msgbuf.buf, extra, sep); + if (msgbuf.len) { + fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout); + printf("%s%s", extra, sep); + } strbuf_release(&msgbuf); } -- 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 --- log-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 9d54061601..8f5436b747 100644 --- a/log-tree.c +++ b/log-tree.c @@ -249,9 +249,9 @@ void show_log(struct rev_info *opt, const char *sep) * not have an empty line between entries. */ extra = ""; - if (*sep != '\n' && opt->commit_format == CMIT_FMT_ONELINE) + if (*sep != '\n' && opt->use_terminator) extra = "\n"; - if (opt->shown_one && opt->commit_format != CMIT_FMT_ONELINE) + if (opt->shown_one && !opt->use_terminator) putchar(opt->diffopt.line_termination); opt->shown_one = 1; -- 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 --- log-tree.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 8f5436b747..4c7d7ef0c6 100644 --- a/log-tree.c +++ b/log-tree.c @@ -208,14 +208,13 @@ void log_write_email_headers(struct rev_info *opt, const char *name, *extra_headers_p = extra_headers; } -void show_log(struct rev_info *opt, const char *sep) +void show_log(struct rev_info *opt) { struct strbuf msgbuf; struct log_info *log = opt->loginfo; struct commit *commit = log->commit, *parent = log->parent; int abbrev = opt->diffopt.abbrev; int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40; - const char *extra; const char *subject = NULL, *extra_headers = opt->extra_headers; int need_8bit_cte = 0; @@ -240,17 +239,10 @@ void show_log(struct rev_info *opt, const char *sep) } /* - * The "oneline" format has several special cases: - * - The pretty-printed commit lacks a newline at the end - * of the buffer, but we do want to make sure that we - * have a newline there. If the separator isn't already - * a newline, add an extra one. - * - unlike other log messages, the one-line format does - * not have an empty line between entries. + * If use_terminator is set, add a newline at the end of the entry. + * Otherwise, add a diffopt.line_termination character before all + * entries but the first. (IOW, as a separator between entries) */ - extra = ""; - if (*sep != '\n' && opt->use_terminator) - extra = "\n"; if (opt->shown_one && !opt->use_terminator) putchar(opt->diffopt.line_termination); opt->shown_one = 1; @@ -292,10 +284,8 @@ void show_log(struct rev_info *opt, const char *sep) show_reflog_message(opt->reflog_info, opt->commit_format == CMIT_FMT_ONELINE, opt->date_mode); - if (opt->commit_format == CMIT_FMT_ONELINE) { - printf("%s", sep); + if (opt->commit_format == CMIT_FMT_ONELINE) return; - } } } @@ -319,7 +309,8 @@ void show_log(struct rev_info *opt, const char *sep) if (msgbuf.len) { fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout); - printf("%s%s", extra, sep); + if (opt->use_terminator) + putchar('\n'); } strbuf_release(&msgbuf); } @@ -342,7 +333,7 @@ int log_tree_diff_flush(struct rev_info *opt) * an extra newline between the end of log and the * output for readability. */ - show_log(opt, opt->diffopt.msg_sep); + show_log(opt); if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) && opt->verbose_header && opt->commit_format != CMIT_FMT_ONELINE) { @@ -430,7 +421,7 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit) shown = log_tree_diff(opt, commit, &log); if (!shown && opt->loginfo && opt->always_show_header) { log.parent = NULL; - show_log(opt, ""); + show_log(opt); shown = 1; } opt->loginfo = NULL; -- cgit v1.2.3 From 9b58bfe8f4ea130a4518f6fbe9927fef78093f1b Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Tue, 29 Apr 2008 01:33:00 -0700 Subject: log: print log entry terminator even if the message is empty This eliminates a special case in the show_log() function, to help simplify the terminator semantics. Now show_log() always prints a newline after the log entry when use_terminator is set, even if the log message is empty. This change should only affect the --pretty=tformat output, since that was the only way to trigger this special case. Signed-off-by: Adam Simpkins Signed-off-by: Junio C Hamano --- log-tree.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 4c7d7ef0c6..d3fb0e520c 100644 --- a/log-tree.c +++ b/log-tree.c @@ -307,11 +307,10 @@ void show_log(struct rev_info *opt) if (opt->show_log_size) printf("log size %i\n", (int)msgbuf.len); - if (msgbuf.len) { + if (msgbuf.len) fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout); - if (opt->use_terminator) - putchar('\n'); - } + if (opt->use_terminator) + putchar('\n'); strbuf_release(&msgbuf); } -- cgit v1.2.3 From 885cf808998c4e6d685c669a44f02b37f6965fd9 Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Sun, 4 May 2008 03:36:52 -0700 Subject: revision API: split parent rewriting and parent printing options This change allows parent rewriting to be performed without causing the log and rev-list commands to print the parents. Signed-off-by: Adam Simpkins Signed-off-by: Junio C Hamano --- log-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index d3fb0e520c..74829d720f 100644 --- a/log-tree.c +++ b/log-tree.c @@ -231,7 +231,7 @@ void show_log(struct rev_info *opt) putchar('>'); } fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); - if (opt->parents) + if (opt->print_parents) show_parents(commit, abbrev_commit); show_decorations(commit); putchar(opt->diffopt.line_termination); @@ -271,7 +271,7 @@ void show_log(struct rev_info *opt) } fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); - if (opt->parents) + if (opt->print_parents) show_parents(commit, abbrev_commit); if (parent) printf(" (from %s)", -- cgit v1.2.3 From 7fefda5cc7a5faf7962092367bedb321a634d54d Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Sun, 4 May 2008 03:36:54 -0700 Subject: log and rev-list: add --graph option This new option causes a text-based representation of the history to be printed to the left of the normal output. Signed-off-by: Adam Simpkins Signed-off-by: Junio C Hamano --- log-tree.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 7 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 74829d720f..1474d1f5d9 100644 --- a/log-tree.c +++ b/log-tree.c @@ -1,6 +1,7 @@ #include "cache.h" #include "diff.h" #include "commit.h" +#include "graph.h" #include "log-tree.h" #include "reflog-walk.h" @@ -165,11 +166,16 @@ void log_write_email_headers(struct rev_info *opt, const char *name, } printf("From %s Mon Sep 17 00:00:00 2001\n", name); - if (opt->message_id) + graph_show_oneline(opt->graph); + if (opt->message_id) { printf("Message-Id: <%s>\n", opt->message_id); - if (opt->ref_message_id) + graph_show_oneline(opt->graph); + } + if (opt->ref_message_id) { printf("In-Reply-To: <%s>\nReferences: <%s>\n", opt->ref_message_id, opt->ref_message_id); + graph_show_oneline(opt->graph); + } if (opt->mime_boundary) { static char subject_buffer[1024]; static char buffer[1024]; @@ -220,6 +226,8 @@ void show_log(struct rev_info *opt) opt->loginfo = NULL; if (!opt->verbose_header) { + graph_show_commit(opt->graph); + if (commit->object.flags & BOUNDARY) putchar('-'); else if (commit->object.flags & UNINTERESTING) @@ -234,6 +242,10 @@ void show_log(struct rev_info *opt) if (opt->print_parents) show_parents(commit, abbrev_commit); show_decorations(commit); + if (opt->graph && !graph_is_commit_finished(opt->graph)) { + putchar('\n'); + graph_show_remainder(opt->graph); + } putchar(opt->diffopt.line_termination); return; } @@ -243,10 +255,32 @@ void show_log(struct rev_info *opt) * Otherwise, add a diffopt.line_termination character before all * entries but the first. (IOW, as a separator between entries) */ - if (opt->shown_one && !opt->use_terminator) + if (opt->shown_one && !opt->use_terminator) { + /* + * If entries are separated by a newline, the output + * should look human-readable. If the last entry ended + * with a newline, print the graph output before this + * newline. Otherwise it will end up as a completely blank + * line and will look like a gap in the graph. + * + * If the entry separator is not a newline, the output is + * primarily intended for programmatic consumption, and we + * never want the extra graph output before the entry + * separator. + */ + if (opt->diffopt.line_termination == '\n' && + !opt->missing_newline) + graph_show_padding(opt->graph); putchar(opt->diffopt.line_termination); + } opt->shown_one = 1; + /* + * If the history graph was requested, + * print the graph, up to this commit's line + */ + graph_show_commit(opt->graph); + /* * Print header line of header.. */ @@ -279,8 +313,19 @@ void show_log(struct rev_info *opt) abbrev_commit)); show_decorations(commit); printf("%s", diff_get_color_opt(&opt->diffopt, DIFF_RESET)); - putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); + if (opt->commit_format == CMIT_FMT_ONELINE) { + putchar(' '); + } else { + putchar('\n'); + graph_show_oneline(opt->graph); + } if (opt->reflog_info) { + /* + * setup_revisions() ensures that opt->reflog_info + * and opt->graph cannot both be set, + * so we don't need to worry about printing the + * graph info here. + */ show_reflog_message(opt->reflog_info, opt->commit_format == CMIT_FMT_ONELINE, opt->date_mode); @@ -304,13 +349,30 @@ void show_log(struct rev_info *opt) if (opt->add_signoff) append_signoff(&msgbuf, opt->add_signoff); - if (opt->show_log_size) + if (opt->show_log_size) { printf("log size %i\n", (int)msgbuf.len); + graph_show_oneline(opt->graph); + } - if (msgbuf.len) + /* + * Set opt->missing_newline if msgbuf doesn't + * end in a newline (including if it is empty) + */ + if (!msgbuf.len || msgbuf.buf[msgbuf.len - 1] != '\n') + opt->missing_newline = 1; + else + opt->missing_newline = 0; + + if (opt->graph) + graph_show_commit_msg(opt->graph, &msgbuf); + else fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout); - if (opt->use_terminator) + if (opt->use_terminator) { + if (!opt->missing_newline) + graph_show_padding(opt->graph); putchar('\n'); + } + strbuf_release(&msgbuf); } -- cgit v1.2.3 From 7528f27dd677bed65d758667a621034b853595b4 Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Sun, 25 May 2008 00:07:21 -0700 Subject: log --graph --left-right: show left/right information in place of '*' With the --graph option, the graph already outputs 'o' instead of '*' for boundary commits. Make it emit '<' or '>' when --left-right is specified. (This change also disables the '^' prefix for UNINTERESTING commits. The graph code currently doesn't print anything special for these commits, since it assumes no UNINTERESTING, non-BOUNDARY commits are displayed. This is potentially a bug if UNINTERESTING non-BOUNDARY commits can actually be displayed via some code path.) [jc: squashed the left-right change from Dscho and Adam's fixup into one] Signed-off-by: Adam Simpkins Signed-off-by: Junio C Hamano --- log-tree.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 1474d1f5d9..5505606ed6 100644 --- a/log-tree.c +++ b/log-tree.c @@ -228,15 +228,17 @@ void show_log(struct rev_info *opt) if (!opt->verbose_header) { graph_show_commit(opt->graph); - if (commit->object.flags & BOUNDARY) - putchar('-'); - else if (commit->object.flags & UNINTERESTING) - putchar('^'); - else if (opt->left_right) { - if (commit->object.flags & SYMMETRIC_LEFT) - putchar('<'); - else - putchar('>'); + if (!opt->graph) { + if (commit->object.flags & BOUNDARY) + putchar('-'); + else if (commit->object.flags & UNINTERESTING) + putchar('^'); + else if (opt->left_right) { + if (commit->object.flags & SYMMETRIC_LEFT) + putchar('<'); + else + putchar('>'); + } } fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); if (opt->print_parents) @@ -293,15 +295,18 @@ void show_log(struct rev_info *opt) fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout); if (opt->commit_format != CMIT_FMT_ONELINE) fputs("commit ", stdout); - if (commit->object.flags & BOUNDARY) - putchar('-'); - else if (commit->object.flags & UNINTERESTING) - putchar('^'); - else if (opt->left_right) { - if (commit->object.flags & SYMMETRIC_LEFT) - putchar('<'); - else - putchar('>'); + + if (!opt->graph) { + if (commit->object.flags & BOUNDARY) + putchar('-'); + else if (commit->object.flags & UNINTERESTING) + putchar('^'); + else if (opt->left_right) { + if (commit->object.flags & SYMMETRIC_LEFT) + putchar('<'); + else + putchar('>'); + } } fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); -- cgit v1.2.3 From 6b2fbaaffc5ec762eae5d23b58b1dc0a88e2275e Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Tue, 29 Jul 2008 22:49:33 -0700 Subject: format-patch: Produce better output with --inline or --attach This patch makes two small changes to improve the output of --inline and --attach. The first is to write a newline preceding the boundary. This is needed because MIME defines the encapsulation boundary as including the preceding CRLF (or in this case, just LF), so we should be writing one. Without this, the last newline in the pre-diff content is consumed instead. The second change is to always write the line termination character (default: newline) even when using --inline or --attach. This is simply to improve the aesthetics of the resulting message. When using --inline an email client should render the resulting message identically to the non-inline version. And when using --attach this adds a blank line preceding the attachment in the email, which is visually attractive. Signed-off-by: Kevin Ballard Signed-off-by: Junio C Hamano --- log-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 5505606ed6..bd8b9e45ab 100644 --- a/log-tree.c +++ b/log-tree.c @@ -198,7 +198,7 @@ void log_write_email_headers(struct rev_info *opt, const char *name, extra_headers = subject_buffer; snprintf(buffer, sizeof(buffer) - 1, - "--%s%s\n" + "\n--%s%s\n" "Content-Type: text/x-patch;" " name=\"%s.diff\"\n" "Content-Transfer-Encoding: 8bit\n" -- cgit v1.2.3 From 84102a338df08a365ed0336304322adc05bc1581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Valdemar=20M=C3=B8rch?= Date: Mon, 11 Aug 2008 08:46:25 +0200 Subject: Teach git log --exit-code to return an appropriate exit code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Valdemar Mørch Signed-off-by: Junio C Hamano --- log-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index bd8b9e45ab..30cd5bb228 100644 --- a/log-tree.c +++ b/log-tree.c @@ -432,7 +432,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log struct commit_list *parents; unsigned const char *sha1 = commit->object.sha1; - if (!opt->diff) + if (!opt->diff && !DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS)) return 0; /* Root commit? */ -- cgit v1.2.3 From cab4feb67db64d3d201145d9748b33d148f96185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 4 Sep 2008 23:39:21 +0200 Subject: move load_ref_decorations() to log-tree.c and export it log-tree.c is the ideal place for load_ref_decorations() and its helper functions to live in, because the variable name_decoration they're operating on is already located there, so move them thither. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- log-tree.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 30cd5bb228..2c1f3e673a 100644 --- a/log-tree.c +++ b/log-tree.c @@ -1,12 +1,48 @@ #include "cache.h" #include "diff.h" #include "commit.h" +#include "tag.h" #include "graph.h" #include "log-tree.h" #include "reflog-walk.h" +#include "refs.h" struct decoration name_decoration = { "object names" }; +static void add_name_decoration(const char *prefix, const char *name, struct object *obj) +{ + int plen = strlen(prefix); + int nlen = strlen(name); + struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + plen + nlen); + memcpy(res->name, prefix, plen); + memcpy(res->name + plen, name, nlen + 1); + res->next = add_decoration(&name_decoration, obj, res); +} + +static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data) +{ + struct object *obj = parse_object(sha1); + if (!obj) + return 0; + add_name_decoration("", refname, obj); + while (obj->type == OBJ_TAG) { + obj = ((struct tag *)obj)->tagged; + if (!obj) + break; + add_name_decoration("tag: ", refname, obj); + } + return 0; +} + +void load_ref_decorations(void) +{ + static int loaded; + if (!loaded) { + loaded = 1; + for_each_ref(add_ref_decoration, NULL); + } +} + static void show_parents(struct commit *commit, int abbrev) { struct commit_list *p; -- cgit v1.2.3 From f285a2d7ed6548666989406de8f0e7233eb84368 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 9 Oct 2008 14:12:12 -0500 Subject: Replace calls to strbuf_init(&foo, 0) with STRBUF_INIT initializer Many call sites use strbuf_init(&foo, 0) to initialize local strbuf variable "foo" which has not been accessed since its declaration. These can be replaced with a static initialization using the STRBUF_INIT macro which is just as readable, saves a function call, and takes up fewer lines. Signed-off-by: Brandon Casey Signed-off-by: Shawn O. Pearce --- log-tree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 2c1f3e673a..cec3c06136 100644 --- a/log-tree.c +++ b/log-tree.c @@ -252,7 +252,7 @@ void log_write_email_headers(struct rev_info *opt, const char *name, void show_log(struct rev_info *opt) { - struct strbuf msgbuf; + struct strbuf msgbuf = STRBUF_INIT; struct log_info *log = opt->loginfo; struct commit *commit = log->commit, *parent = log->parent; int abbrev = opt->diffopt.abbrev; @@ -381,7 +381,6 @@ void show_log(struct rev_info *opt) /* * And then the pretty-printed message itself */ - strbuf_init(&msgbuf, 0); if (need_8bit_cte >= 0) need_8bit_cte = has_non_ascii(opt->add_signoff); pretty_print_commit(opt->commit_format, commit, &msgbuf, -- cgit v1.2.3 From 0f3a290b89b89bb5375cf5019b067e4a99f02620 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 27 Oct 2008 12:51:59 -0700 Subject: Add a 'source' decorator for commits We already support decorating commits by tags or branches that point to them, but especially when we are looking at multiple branches together, we sometimes want to see _how_ we reached a particular commit. We can abuse the '->util' field in the commit to keep track of that as we walk the commit lists, and get a reasonably useful view into which branch or tag first reaches that commit. Of course, if the commit is reachable through multiple sources (which is common), our particular choice of "first" reachable is entirely random and depends on the particular path we happened to follow. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- log-tree.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index cec3c06136..cf7947b9c9 100644 --- a/log-tree.c +++ b/log-tree.c @@ -52,11 +52,13 @@ static void show_parents(struct commit *commit, int abbrev) } } -void show_decorations(struct commit *commit) +void show_decorations(struct rev_info *opt, struct commit *commit) { const char *prefix; struct name_decoration *decoration; + if (opt->show_source && commit->util) + printf(" %s", (char *) commit->util); decoration = lookup_decoration(&name_decoration, &commit->object); if (!decoration) return; @@ -279,7 +281,7 @@ void show_log(struct rev_info *opt) fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); if (opt->print_parents) show_parents(commit, abbrev_commit); - show_decorations(commit); + show_decorations(opt, commit); if (opt->graph && !graph_is_commit_finished(opt->graph)) { putchar('\n'); graph_show_remainder(opt->graph); @@ -352,7 +354,7 @@ void show_log(struct rev_info *opt) printf(" (from %s)", diff_unique_abbrev(parent->object.sha1, abbrev_commit)); - show_decorations(commit); + show_decorations(opt, commit); printf("%s", diff_get_color_opt(&opt->diffopt, DIFF_RESET)); if (opt->commit_format == CMIT_FMT_ONELINE) { putchar(' '); -- cgit v1.2.3 From d467a525da28b28a0d8e16a42e121ab638fa7347 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 3 Nov 2008 11:23:57 -0800 Subject: Make '--decorate' set an explicit 'show_decorations' flag We will want to add decorations without necessarily showing them, so add an explicit revisions info flag as to whether we're showing decorations or not. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- log-tree.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index cf7947b9c9..5444f0860b 100644 --- a/log-tree.c +++ b/log-tree.c @@ -59,6 +59,8 @@ void show_decorations(struct rev_info *opt, struct commit *commit) if (opt->show_source && commit->util) printf(" %s", (char *) commit->util); + if (!opt->show_decorations) + return; decoration = lookup_decoration(&name_decoration, &commit->object); if (!decoration) return; -- cgit v1.2.3 From 8c4021abfd170278d1a3431e2777bedd0c01fbb1 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 15 Nov 2008 10:02:01 -0800 Subject: Fix machine-parseability of 'git log --source' The space between the commit and the source attribute is not easily machine-parseable: if we combine --source with --parents and give a SHA1 as a starting point, it's unnecessarily hard to see where the list of parents ends and the source decoration begins. Example: git show --parents --source $(git rev-list HEAD) which is admittedly contrived, but can easily happen in scripting. So use a instead of a space as the source separator. The other decorations didn't have this issue, because they were surrounded by parenthesis, so it's obvious that they aren't parent SHA1's. It so happens that _visually_ this makes no difference for "git log --source", since "commit <40-char SHA1>" is 47 characters, so both a space and a will end up showing as a single commit. Of course, with '--pretty=oneline' or '--parents' or '--abbrev-commit' you'll see the difference. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- log-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 5444f0860b..194ddb13da 100644 --- a/log-tree.c +++ b/log-tree.c @@ -58,7 +58,7 @@ void show_decorations(struct rev_info *opt, struct commit *commit) struct name_decoration *decoration; if (opt->show_source && commit->util) - printf(" %s", (char *) commit->util); + printf("\t%s", (char *) commit->util); if (!opt->show_decorations) return; decoration = lookup_decoration(&name_decoration, &commit->object); -- cgit v1.2.3 From 7fcda9201e192413c2e63fe35ce6664dbc81705d Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Fri, 13 Feb 2009 23:10:41 +0100 Subject: log: do not print ellipses with --abbrev-commit 'git log --abbrev-commit' added an ellipsis to all commit names that were abbreviated. This was particularly annoying if you wanted to cut&paste the sha1 from the terminal, since selecting by word would pick up '...' too. So use find_unique_abbrev() instead of diff_unique_abbrev() in all log-related commit sha1 printing routines, and also change the formatting of the 'Merge: parent1 parent2' line output via pretty_print_commit(). Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- log-tree.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 194ddb13da..84a74e544b 100644 --- a/log-tree.c +++ b/log-tree.c @@ -48,7 +48,7 @@ static void show_parents(struct commit *commit, int abbrev) struct commit_list *p; for (p = commit->parents; p ; p = p->next) { struct commit *parent = p->item; - printf(" %s", diff_unique_abbrev(parent->object.sha1, abbrev)); + printf(" %s", find_unique_abbrev(parent->object.sha1, abbrev)); } } @@ -280,7 +280,7 @@ void show_log(struct rev_info *opt) putchar('>'); } } - fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); + fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); if (opt->print_parents) show_parents(commit, abbrev_commit); show_decorations(opt, commit); @@ -348,13 +348,13 @@ void show_log(struct rev_info *opt) putchar('>'); } } - fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), + fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); if (opt->print_parents) show_parents(commit, abbrev_commit); if (parent) printf(" (from %s)", - diff_unique_abbrev(parent->object.sha1, + find_unique_abbrev(parent->object.sha1, abbrev_commit)); show_decorations(opt, commit); printf("%s", diff_get_color_opt(&opt->diffopt, DIFF_RESET)); -- cgit v1.2.3 From b079c50e03a812f5c8197b8f38e0a5fe6dd31321 Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Thu, 19 Feb 2009 22:26:31 +0100 Subject: format-patch: track several references Currently, format-patch can only track a single reference (the In-Reply-To:) for each mail. To ensure proper threading, we should list all known references for every mail. Change the rev_info.ref_message_id field to a string_list, so that we can append references at will, and change the output formatting routines to print all of them in the References: header. The last entry in the list is implicitly assumed to be the In-Reply-To:, which gives output consistent with RFC 2822: The "References:" field will contain the contents of the parent's "References:" field (if any) followed by the contents of the parent's "Message-ID:" field (if any). Note that this is just preparatory work; nothing uses it yet, so all "References:" fields in the output are still only one deep. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- log-tree.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 84a74e544b..a315ebb78f 100644 --- a/log-tree.c +++ b/log-tree.c @@ -6,6 +6,7 @@ #include "log-tree.h" #include "reflog-walk.h" #include "refs.h" +#include "string-list.h" struct decoration name_decoration = { "object names" }; @@ -211,9 +212,13 @@ void log_write_email_headers(struct rev_info *opt, const char *name, printf("Message-Id: <%s>\n", opt->message_id); graph_show_oneline(opt->graph); } - if (opt->ref_message_id) { - printf("In-Reply-To: <%s>\nReferences: <%s>\n", - opt->ref_message_id, opt->ref_message_id); + if (opt->ref_message_ids && opt->ref_message_ids->nr > 0) { + int i, n; + n = opt->ref_message_ids->nr; + printf("In-Reply-To: <%s>\n", opt->ref_message_ids->items[n-1].string); + for (i = 0; i < n; i++) + printf("%s<%s>\n", (i > 0 ? "\t" : "References: "), + opt->ref_message_ids->items[i].string); graph_show_oneline(opt->graph); } if (opt->mime_boundary) { -- cgit v1.2.3 From fd13b21f52b499ff6fa951ce27d4b9c9f0653087 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sat, 7 Mar 2009 21:02:26 +0100 Subject: Move local variables to narrower scopes These weren't used outside and can be safely moved Signed-off-by: Benjamin Kramer Signed-off-by: Junio C Hamano --- log-tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 84a74e544b..63cff74350 100644 --- a/log-tree.c +++ b/log-tree.c @@ -79,18 +79,18 @@ void show_decorations(struct rev_info *opt, struct commit *commit) */ static int detect_any_signoff(char *letter, int size) { - char ch, *cp; + char *cp; int seen_colon = 0; int seen_at = 0; int seen_name = 0; int seen_head = 0; cp = letter + size; - while (letter <= --cp && (ch = *cp) == '\n') + while (letter <= --cp && *cp == '\n') continue; while (letter <= cp) { - ch = *cp--; + char ch = *cp--; if (ch == '\n') break; -- cgit v1.2.3 From 6fa8e6278b210bfa56fcb54ed38d2b485350e7c6 Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Sun, 22 Mar 2009 19:14:04 -0700 Subject: format-patch: move get_patch_filename() into log-tree Signed-off-by: Stephen Boyd Signed-off-by: Junio C Hamano --- log-tree.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 9565c184db..aee9995531 100644 --- a/log-tree.c +++ b/log-tree.c @@ -179,6 +179,28 @@ static int has_non_ascii(const char *s) return 0; } +void get_patch_filename(struct commit *commit, int nr, const char *suffix, + struct strbuf *buf) +{ + int suffix_len = strlen(suffix) + 1; + int start_len = buf->len; + + strbuf_addf(buf, commit ? "%04d-" : "%d", nr); + if (commit) { + format_commit_message(commit, "%f", buf, DATE_NORMAL); + /* + * Replace characters at the end with the suffix if the + * filename is too long + */ + if (buf->len + suffix_len > FORMAT_PATCH_NAME_MAX + start_len) + strbuf_splice(buf, + start_len + FORMAT_PATCH_NAME_MAX - suffix_len, + suffix_len, suffix, suffix_len); + else + strbuf_addstr(buf, suffix); + } +} + void log_write_email_headers(struct rev_info *opt, const char *name, const char **subject_p, const char **extra_headers_p, -- cgit v1.2.3 From 108dab2811701c20d6d6e8d9fe8af88e41d65d77 Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Sun, 22 Mar 2009 19:14:05 -0700 Subject: format-patch: --attach/inline uses filename instead of SHA1 Currently when format-patch is used with --attach or --inline the patch attachment has the SHA1 of the commit for its filename. This replaces the SHA1 with the filename used by format-patch when outputting to files. Fix tests relying on the SHA1 output and add a test showing how the --suffix option affects the attachment filename output. Signed-off-by: Stephen Boyd Signed-off-by: Junio C Hamano --- log-tree.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index aee9995531..56a3488592 100644 --- a/log-tree.c +++ b/log-tree.c @@ -201,13 +201,14 @@ void get_patch_filename(struct commit *commit, int nr, const char *suffix, } } -void log_write_email_headers(struct rev_info *opt, const char *name, +void log_write_email_headers(struct rev_info *opt, struct commit *commit, const char **subject_p, const char **extra_headers_p, int *need_8bit_cte_p) { const char *subject = NULL; const char *extra_headers = opt->extra_headers; + const char *name = sha1_to_hex(commit->object.sha1); *need_8bit_cte_p = 0; /* unknown */ if (opt->total > 0) { @@ -246,6 +247,7 @@ void log_write_email_headers(struct rev_info *opt, const char *name, if (opt->mime_boundary) { static char subject_buffer[1024]; static char buffer[1024]; + struct strbuf filename = STRBUF_INIT; *need_8bit_cte_p = -1; /* NEVER */ snprintf(subject_buffer, sizeof(subject_buffer) - 1, "%s" @@ -264,18 +266,21 @@ void log_write_email_headers(struct rev_info *opt, const char *name, mime_boundary_leader, opt->mime_boundary); extra_headers = subject_buffer; + get_patch_filename(opt->numbered_files ? NULL : commit, opt->nr, + opt->patch_suffix, &filename); snprintf(buffer, sizeof(buffer) - 1, "\n--%s%s\n" "Content-Type: text/x-patch;" - " name=\"%s.diff\"\n" + " name=\"%s\"\n" "Content-Transfer-Encoding: 8bit\n" "Content-Disposition: %s;" - " filename=\"%s.diff\"\n\n", + " filename=\"%s\"\n\n", mime_boundary_leader, opt->mime_boundary, - name, + filename.buf, opt->no_inline ? "attachment" : "inline", - name); + filename.buf); opt->diffopt.stat_sep = buffer; + strbuf_release(&filename); } *subject_p = subject; *extra_headers_p = extra_headers; @@ -355,8 +360,7 @@ void show_log(struct rev_info *opt) */ if (opt->commit_format == CMIT_FMT_EMAIL) { - log_write_email_headers(opt, sha1_to_hex(commit->object.sha1), - &subject, &extra_headers, + log_write_email_headers(opt, commit, &subject, &extra_headers, &need_8bit_cte); } else if (opt->commit_format != CMIT_FMT_USERFORMAT) { fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout); -- cgit v1.2.3 From b09b868f7fee689483d00bea3d52c0f14a80386c Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Fri, 27 Mar 2009 01:13:01 +0100 Subject: log-tree: fix patch filename computation in "git format-patch" When using "git format-patch", "get_patch_filename" in "log-tree.c" calls "strbuf_splice" that could die with the following message: "`pos + len' is too far after the end of the buffer" if you have: buf->len < start_len + FORMAT_PATCH_NAME_MAX but: buf->len + suffix_len > start_len + FORMAT_PATCH_NAME_MAX This patch tries to get rid of that bug. [jc: w/ simplified logic] Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- log-tree.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 56a3488592..5bd29e6994 100644 --- a/log-tree.c +++ b/log-tree.c @@ -187,17 +187,12 @@ void get_patch_filename(struct commit *commit, int nr, const char *suffix, strbuf_addf(buf, commit ? "%04d-" : "%d", nr); if (commit) { + int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len; + format_commit_message(commit, "%f", buf, DATE_NORMAL); - /* - * Replace characters at the end with the suffix if the - * filename is too long - */ - if (buf->len + suffix_len > FORMAT_PATCH_NAME_MAX + start_len) - strbuf_splice(buf, - start_len + FORMAT_PATCH_NAME_MAX - suffix_len, - suffix_len, suffix, suffix_len); - else - strbuf_addstr(buf, suffix); + if (max_len < buf->len) + strbuf_setlen(buf, max_len); + strbuf_addstr(buf, suffix); } } -- cgit v1.2.3 From de435ac0f633b1f68dba2970cb7fa019171e40fe Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 14 May 2009 00:32:53 +0300 Subject: Prettify log decorations even more "tag: v1.6.2.5" looks much better than "tag: refs/tags/v1.6.2.5". Signed-off-by: Felipe Contreras Acked-by: Jeff King Signed-off-by: Junio C Hamano --- log-tree.c | 1 + 1 file changed, 1 insertion(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 5bd29e6994..59d63eb67e 100644 --- a/log-tree.c +++ b/log-tree.c @@ -25,6 +25,7 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in struct object *obj = parse_object(sha1); if (!obj) return 0; + refname = prettify_refname(refname); add_name_decoration("", refname, obj); while (obj->type == OBJ_TAG) { obj = ((struct tag *)obj)->tagged; -- cgit v1.2.3 From 8715227df65071b38a3c91553cdb51365aa5cfd9 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 1 Jul 2009 03:26:28 -0400 Subject: log-tree: fix confusing comment This comment mentions the case where use_terminator is set, but this case is not handled at all by this chunk of code. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- log-tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 59d63eb67e..6f73c17d74 100644 --- a/log-tree.c +++ b/log-tree.c @@ -321,7 +321,8 @@ void show_log(struct rev_info *opt) } /* - * If use_terminator is set, add a newline at the end of the entry. + * If use_terminator is set, we already handled any record termination + * at the end of the last record. * Otherwise, add a diffopt.line_termination character before all * entries but the first. (IOW, as a separator between entries) */ -- cgit v1.2.3 From 28e9cf6512cae1b50a2d2003bb59da4392d99e2e Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 10 Aug 2009 18:22:18 +0200 Subject: Expose the has_non_ascii() function This function is useful outside of log-tree.c, too. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- log-tree.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 6f73c17d74..a3b4c0692c 100644 --- a/log-tree.c +++ b/log-tree.c @@ -168,18 +168,6 @@ static unsigned int digits_in_number(unsigned int number) return result; } -static int has_non_ascii(const char *s) -{ - int ch; - if (!s) - return 0; - while ((ch = *s++) != '\0') { - if (non_ascii(ch)) - return 1; - } - return 0; -} - void get_patch_filename(struct commit *commit, int nr, const char *suffix, struct strbuf *buf) { -- cgit v1.2.3 From 33e7018c459e6583b899690cabd21c808ffd3c85 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sat, 15 Aug 2009 16:23:12 +0200 Subject: git-log: allow --decorate[=short|full] Commit de435ac0 changed the behavior of --decorate from printing the full ref (e.g., "refs/heads/master") to a shorter, more human-readable version (e.g., just "master"). While this is nice for human readers, external tools using the output from "git log" may prefer the full version. This patch introduces an extension to --decorate to allow the caller to specify either the short or the full versions. Signed-off-by: Lars Hjemli Acked-by: Jeff King Signed-off-by: Junio C Hamano --- log-tree.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index a3b4c0692c..1c9eefee33 100644 --- a/log-tree.c +++ b/log-tree.c @@ -25,7 +25,8 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in struct object *obj = parse_object(sha1); if (!obj) return 0; - refname = prettify_refname(refname); + if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS) + refname = prettify_refname(refname); add_name_decoration("", refname, obj); while (obj->type == OBJ_TAG) { obj = ((struct tag *)obj)->tagged; @@ -36,12 +37,12 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in return 0; } -void load_ref_decorations(void) +void load_ref_decorations(int flags) { static int loaded; if (!loaded) { loaded = 1; - for_each_ref(add_ref_decoration, NULL); + for_each_ref(add_ref_decoration, &flags); } } -- cgit v1.2.3 From f4ea32f0b48bc300afcb7c980c5a294deba31daa Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 24 Sep 2009 04:28:15 -0400 Subject: improve reflog date/number heuristic When we show a reflog, we have two ways of naming the entry: by sequence number (e.g., HEAD@{0}) or by date (e.g., HEAD@{10 minutes ago}). There is no explicit option to set one or the other, but we guess based on whether or not the user has provided us with a date format, showing them the date version if they have done so, and the sequence number otherwise. This usually made sense if the use did something like "git log -g --date=relative". However, it didn't make much sense if the user set the date format using the log.date config variable; in that case, all of their reflogs would end up as dates. This patch records the source of the date format and only triggers the date-based view if --date= was given on the command line. Signed-off-by: Jeff King Signed-off-by: Shawn O. Pearce --- log-tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 1c9eefee33..1618f3c79a 100644 --- a/log-tree.c +++ b/log-tree.c @@ -390,7 +390,9 @@ void show_log(struct rev_info *opt) */ show_reflog_message(opt->reflog_info, opt->commit_format == CMIT_FMT_ONELINE, - opt->date_mode); + opt->date_mode_explicit ? + opt->date_mode : + DATE_NORMAL); if (opt->commit_format == CMIT_FMT_ONELINE) return; } -- cgit v1.2.3 From 77abcbdc268d048b7a19af405607fb8d14e630ed Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Mon, 12 Oct 2009 22:34:12 +0200 Subject: Let --decorate show HEAD position 'git log --graph --oneline --decorate --all' is a useful way to get a general overview of the repository state, similar to 'gitk --all'. Let it indicate the position of HEAD by loading that ref too, so that the --decorate code can see it. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- log-tree.c | 1 + 1 file changed, 1 insertion(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 1618f3c79a..f7d54f2f1b 100644 --- a/log-tree.c +++ b/log-tree.c @@ -43,6 +43,7 @@ void load_ref_decorations(int flags) if (!loaded) { loaded = 1; for_each_ref(add_ref_decoration, &flags); + head_ref(add_ref_decoration, &flags); } } -- cgit v1.2.3 From dd2e794a214350711db46c4e08d9b19188a7d63a Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Mon, 19 Oct 2009 17:48:08 +0200 Subject: Refactor pretty_print_commit arguments into a struct pretty_print_commit() has a bunch of rarely-used arguments, and introducing more of them requires yet another update of all the call sites. Refactor most of them into a struct to make future extensions easier. The ones that stay "plain" arguments were chosen on the grounds that all callers put real arguments there, whereas some callers have 0/NULL for all arguments that were factored into the struct. We declare the struct 'const' to ensure none of the callers are bitten by the changed (no longer call-by-value) semantics. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- log-tree.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index f7d54f2f1b..1675035d84 100644 --- a/log-tree.c +++ b/log-tree.c @@ -179,8 +179,10 @@ void get_patch_filename(struct commit *commit, int nr, const char *suffix, strbuf_addf(buf, commit ? "%04d-" : "%d", nr); if (commit) { int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len; + struct pretty_print_context ctx = {0}; + ctx.date_mode = DATE_NORMAL; - format_commit_message(commit, "%f", buf, DATE_NORMAL); + format_commit_message(commit, "%f", buf, &ctx); if (max_len < buf->len) strbuf_setlen(buf, max_len); strbuf_addstr(buf, suffix); @@ -277,10 +279,9 @@ void show_log(struct rev_info *opt) struct strbuf msgbuf = STRBUF_INIT; struct log_info *log = opt->loginfo; struct commit *commit = log->commit, *parent = log->parent; - int abbrev = opt->diffopt.abbrev; int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40; - const char *subject = NULL, *extra_headers = opt->extra_headers; - int need_8bit_cte = 0; + const char *extra_headers = opt->extra_headers; + struct pretty_print_context ctx = {0}; opt->loginfo = NULL; if (!opt->verbose_header) { @@ -347,8 +348,8 @@ void show_log(struct rev_info *opt) */ if (opt->commit_format == CMIT_FMT_EMAIL) { - log_write_email_headers(opt, commit, &subject, &extra_headers, - &need_8bit_cte); + log_write_email_headers(opt, commit, &ctx.subject, &extra_headers, + &ctx.need_8bit_cte); } else if (opt->commit_format != CMIT_FMT_USERFORMAT) { fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout); if (opt->commit_format != CMIT_FMT_ONELINE) @@ -405,11 +406,12 @@ void show_log(struct rev_info *opt) /* * And then the pretty-printed message itself */ - if (need_8bit_cte >= 0) - need_8bit_cte = has_non_ascii(opt->add_signoff); - pretty_print_commit(opt->commit_format, commit, &msgbuf, - abbrev, subject, extra_headers, opt->date_mode, - need_8bit_cte); + if (ctx.need_8bit_cte >= 0) + ctx.need_8bit_cte = has_non_ascii(opt->add_signoff); + ctx.date_mode = opt->date_mode; + ctx.abbrev = opt->diffopt.abbrev; + ctx.after_subject = extra_headers; + pretty_print_commit(opt->commit_format, commit, &msgbuf, &ctx); if (opt->add_signoff) append_signoff(&msgbuf, opt->add_signoff); -- cgit v1.2.3 From 8f8f5476cd6542387d435c242752404cf144005f Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Mon, 19 Oct 2009 17:48:10 +0200 Subject: Introduce new pretty formats %g[sdD] for reflog information Add three new --pretty=format escapes: %gD long reflog descriptor (e.g. refs/stash@{0}) %gd short reflog descriptor (e.g. stash@{0}) %gs reflog message This is achieved by passing down the reflog info, if any, inside the pretty_print_context struct. We use the newly refactored get_reflog_selector(), and give it some extra functionality to extract a shortened ref. The shortening is cached inside the commit_reflogs struct; the only allocation of it happens in read_complete_reflog(), where it is initialised to 0. Also add another helper get_reflog_message() for the message extraction. Note that the --format="%h %gD: %gs" tests may not work in real repositories, as the --pretty formatter doesn't know to leave away the ": " on the last commit in an incomplete (because git-gc removed the old part) reflog. This equivalence is nevertheless the main goal of this patch. Thanks to Jeff King for reviews, the %gd testcase and documentation. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- log-tree.c | 1 + 1 file changed, 1 insertion(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 1675035d84..0fdf159f80 100644 --- a/log-tree.c +++ b/log-tree.c @@ -411,6 +411,7 @@ void show_log(struct rev_info *opt) ctx.date_mode = opt->date_mode; ctx.abbrev = opt->diffopt.abbrev; ctx.after_subject = extra_headers; + ctx.reflog_info = opt->reflog_info; pretty_print_commit(opt->commit_format, commit, &msgbuf, &ctx); if (opt->add_signoff) -- cgit v1.2.3 From 66b2ed09c2f0f212c5cd5c095c1f1052ecbb9491 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 20 Jan 2010 13:59:36 -0800 Subject: Fix "log" family not to be too agressive about showing notes Giving "Notes" information in the default output format of "log" and "show" is a sensible progress (the user has asked for it by having the notes), but for some commands (e.g. "format-patch") spewing notes into the formatted commit log message without being asked is too aggressive. Enable notes output only for "log", "show", "whatchanged" by default and only when the user didn't ask any specific --pretty/--format from the command line; users can explicitly override this default with --show-notes and --no-notes option. Parts of tests are taken from Jeff King's fix. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- log-tree.c | 1 + 1 file changed, 1 insertion(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 0fdf159f80..27afcf6972 100644 --- a/log-tree.c +++ b/log-tree.c @@ -284,6 +284,7 @@ void show_log(struct rev_info *opt) struct pretty_print_context ctx = {0}; opt->loginfo = NULL; + ctx.show_notes = opt->show_notes; if (!opt->verbose_header) { graph_show_commit(opt->graph); -- cgit v1.2.3 From 88d9d45d071379e81e585faa95e4f28414d7d973 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Wed, 10 Feb 2010 02:11:49 +0100 Subject: git log -p -m: document -m and honor --first-parent git log -p -m is used to show one merge entry per parent, with an appropriate diff; this can be useful when examining histories where full set of changes introduced by a merged branch is interesting, not only the conflicts. This patch properly documents the -m switch, which has so far been mentioned only as a fairly special diff-tree flag. It also makes the code show full patch entry only for the first parent when --first-parent is used. Thus: git log -p -m --first-parent will show the history from the "main branch perspective", while also including full diff of changes introduced by other merged in branches. Signed-off-by: Petr Baudis Signed-off-by: Junio C Hamano --- log-tree.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 27afcf6972..d3ae969f60 100644 --- a/log-tree.c +++ b/log-tree.c @@ -514,6 +514,16 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log return 0; else if (opt->combine_merges) return do_diff_combined(opt, commit); + else if (opt->first_parent_only) { + /* + * Generate merge log entry only for the first + * parent, showing summary diff of the others + * we merged _in_. + */ + diff_tree_sha1(parents->item->object.sha1, sha1, "", &opt->diffopt); + log_tree_diff_flush(opt); + return !opt->loginfo; + } /* If we show individual diffs, show the parent info */ log->parent = parents->item; -- cgit v1.2.3 From 81bd1b2a96ecc12dcc72fc2b22aa5b7691186685 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Wed, 26 May 2010 15:08:03 +0800 Subject: Output the graph columns at the end of the commit message There is an empty line between the commit message and the diff output. Add the graph columns as prefix of this line. Signed-off-by: Bo Yang Signed-off-by: Junio C Hamano --- log-tree.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index d3ae969f60..2e2be7c40f 100644 --- a/log-tree.c +++ b/log-tree.c @@ -469,6 +469,12 @@ int log_tree_diff_flush(struct rev_info *opt) int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH; if ((pch & opt->diffopt.output_format) == pch) printf("---"); + if (opt->diffopt.output_prefix) { + struct strbuf *msg = NULL; + msg = opt->diffopt.output_prefix(&opt->diffopt, + opt->diffopt.output_prefix_data); + fwrite(msg->buf, msg->len, 1, stdout); + } putchar('\n'); } } -- cgit v1.2.3 From a7524128750ebf34fe0639e1e5d7abd03aff0302 Mon Sep 17 00:00:00 2001 From: Nazri Ramliy Date: Sat, 19 Jun 2010 09:37:34 +0800 Subject: log-tree.c: Use struct name_decoration's type for classifying decoration The "tag: " prefix is no longer prepended to the name of the decoration. It is now printed conditionally by show_decorations if the decoration type is DECORATION_REF_TAG. Signed-off-by: Nazri Ramliy Signed-off-by: Junio C Hamano --- log-tree.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 2e2be7c40f..bec609676e 100644 --- a/log-tree.c +++ b/log-tree.c @@ -10,29 +10,50 @@ struct decoration name_decoration = { "object names" }; -static void add_name_decoration(const char *prefix, const char *name, struct object *obj) +enum decoration_type { + DECORATION_NONE = 0, + DECORATION_REF_LOCAL, + DECORATION_REF_REMOTE, + DECORATION_REF_TAG, + DECORATION_REF_STASH, + DECORATION_REF_HEAD, +}; + +static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj) { - int plen = strlen(prefix); int nlen = strlen(name); - struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + plen + nlen); - memcpy(res->name, prefix, plen); - memcpy(res->name + plen, name, nlen + 1); + struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + nlen); + memcpy(res->name, name, nlen + 1); + res->type = type; res->next = add_decoration(&name_decoration, obj, res); } static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data) { struct object *obj = parse_object(sha1); + enum decoration_type type = DECORATION_NONE; if (!obj) return 0; + + if (!prefixcmp(refname, "refs/heads")) + type = DECORATION_REF_LOCAL; + else if (!prefixcmp(refname, "refs/remotes")) + type = DECORATION_REF_REMOTE; + else if (!prefixcmp(refname, "refs/tags")) + type = DECORATION_REF_TAG; + else if (!prefixcmp(refname, "refs/stash")) + type = DECORATION_REF_STASH; + else if (!prefixcmp(refname, "HEAD")) + type = DECORATION_REF_HEAD; + if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS) refname = prettify_refname(refname); - add_name_decoration("", refname, obj); + add_name_decoration(type, refname, obj); while (obj->type == OBJ_TAG) { obj = ((struct tag *)obj)->tagged; if (!obj) break; - add_name_decoration("tag: ", refname, obj); + add_name_decoration(DECORATION_REF_TAG, refname, obj); } return 0; } @@ -70,7 +91,10 @@ void show_decorations(struct rev_info *opt, struct commit *commit) return; prefix = " ("; while (decoration) { - printf("%s%s", prefix, decoration->name); + printf("%s", prefix); + if (decoration->type == DECORATION_REF_TAG) + printf("tag: "); + printf("%s", decoration->name); prefix = ", "; decoration = decoration->next; } -- cgit v1.2.3 From 67a4b5864f9423ccfe8090365029dae918504830 Mon Sep 17 00:00:00 2001 From: Nazri Ramliy Date: Sat, 19 Jun 2010 09:37:35 +0800 Subject: log --decorate: Colorize commit decorations This makes the decorations stand out more and easier to distinguish and spot because they are colored differently depending on their type. Signed-off-by: Nazri Ramliy Signed-off-by: Junio C Hamano --- log-tree.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index bec609676e..61680f4664 100644 --- a/log-tree.c +++ b/log-tree.c @@ -7,6 +7,7 @@ #include "reflog-walk.h" #include "refs.h" #include "string-list.h" +#include "color.h" struct decoration name_decoration = { "object names" }; @@ -19,6 +20,29 @@ enum decoration_type { DECORATION_REF_HEAD, }; +static char decoration_colors[][COLOR_MAXLEN] = { + GIT_COLOR_RESET, + GIT_COLOR_BOLD_GREEN, /* REF_LOCAL */ + GIT_COLOR_BOLD_RED, /* REF_REMOTE */ + GIT_COLOR_BOLD_YELLOW, /* REF_TAG */ + GIT_COLOR_BOLD_MAGENTA, /* REF_STASH */ + GIT_COLOR_BOLD_CYAN, /* REF_HEAD */ +}; + +static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix) +{ + if (decorate_use_color) + return decoration_colors[ix]; + return ""; +} + +/* + * log-tree.c uses DIFF_OPT_TST for determining whether to use color + * for showing the commit sha1, use the same check for --decorate + */ +#define decorate_get_color_opt(o, ix) \ + decorate_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix) + static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj) { int nlen = strlen(name); @@ -81,6 +105,10 @@ void show_decorations(struct rev_info *opt, struct commit *commit) { const char *prefix; struct name_decoration *decoration; + const char *color_commit = + diff_get_color_opt(&opt->diffopt, DIFF_COMMIT); + const char *color_reset = + decorate_get_color_opt(&opt->diffopt, DECORATION_NONE); if (opt->show_source && commit->util) printf("\t%s", (char *) commit->util); @@ -92,9 +120,13 @@ void show_decorations(struct rev_info *opt, struct commit *commit) prefix = " ("; while (decoration) { printf("%s", prefix); + fputs(decorate_get_color_opt(&opt->diffopt, decoration->type), + stdout); if (decoration->type == DECORATION_REF_TAG) - printf("tag: "); + fputs("tag: ", stdout); printf("%s", decoration->name); + fputs(color_reset, stdout); + fputs(color_commit, stdout); prefix = ", "; decoration = decoration->next; } -- cgit v1.2.3 From 5e11bee65f601ba97dc4c61c75fcb2f448fdcb1c Mon Sep 17 00:00:00 2001 From: Nazri Ramliy Date: Thu, 24 Jun 2010 08:21:16 +0800 Subject: Allow customizable commit decorations colors Signed-off-by: Nazri Ramliy Signed-off-by: Junio C Hamano --- log-tree.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 61680f4664..b46ed3baef 100644 --- a/log-tree.c +++ b/log-tree.c @@ -36,6 +36,42 @@ static const char *decorate_get_color(int decorate_use_color, enum decoration_ty return ""; } +static int parse_decorate_color_slot(const char *slot) +{ + /* + * We're comparing with 'ignore-case' on + * (because config.c sets them all tolower), + * but let's match the letters in the literal + * string values here with how they are + * documented in Documentation/config.txt, for + * consistency. + * + * We love being consistent, don't we? + */ + if (!strcasecmp(slot, "branch")) + return DECORATION_REF_LOCAL; + if (!strcasecmp(slot, "remoteBranch")) + return DECORATION_REF_REMOTE; + if (!strcasecmp(slot, "tag")) + return DECORATION_REF_TAG; + if (!strcasecmp(slot, "stash")) + return DECORATION_REF_STASH; + if (!strcasecmp(slot, "HEAD")) + return DECORATION_REF_HEAD; + return -1; +} + +int parse_decorate_color_config(const char *var, const int ofs, const char *value) +{ + int slot = parse_decorate_color_slot(var + ofs); + if (slot < 0) + return 0; + if (!value) + return config_error_nonbool(var); + color_parse(value, var, decoration_colors[slot]); + return 0; +} + /* * log-tree.c uses DIFF_OPT_TST for determining whether to use color * for showing the commit sha1, use the same check for --decorate -- cgit v1.2.3 From 1df2d656cc442dc057e30b6fb130967e5ae19654 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Mon, 7 Mar 2011 13:31:39 +0100 Subject: rev-list/log: factor out revision mark generation Currently, we have identical code for generating revision marks ('<', '>', '-') in 5 places. Factor out the code to a single function get_revision_mark() for easier maintenance and extensibility. Note that the check for !!revs in graph.c (which gets removed effectively by this patch) is superfluous. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- log-tree.c | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index b46ed3baef..1257040311 100644 --- a/log-tree.c +++ b/log-tree.c @@ -380,18 +380,8 @@ void show_log(struct rev_info *opt) if (!opt->verbose_header) { graph_show_commit(opt->graph); - if (!opt->graph) { - if (commit->object.flags & BOUNDARY) - putchar('-'); - else if (commit->object.flags & UNINTERESTING) - putchar('^'); - else if (opt->left_right) { - if (commit->object.flags & SYMMETRIC_LEFT) - putchar('<'); - else - putchar('>'); - } - } + if (!opt->graph) + fputs(get_revision_mark(opt, commit), stdout); fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); if (opt->print_parents) show_parents(commit, abbrev_commit); @@ -448,18 +438,8 @@ void show_log(struct rev_info *opt) if (opt->commit_format != CMIT_FMT_ONELINE) fputs("commit ", stdout); - if (!opt->graph) { - if (commit->object.flags & BOUNDARY) - putchar('-'); - else if (commit->object.flags & UNINTERESTING) - putchar('^'); - else if (opt->left_right) { - if (commit->object.flags & SYMMETRIC_LEFT) - putchar('<'); - else - putchar('>'); - } - } + if (!opt->graph) + fputs(get_revision_mark(opt, commit), stdout); fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); if (opt->print_parents) -- cgit v1.2.3 From b1b47554ae889ca76b66349819c9b95a8be5f646 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Thu, 10 Mar 2011 15:45:03 +0100 Subject: git-log: put space after commit mark Currently, commit marks (left, right, boundary, cherry) are output right before the commit sha1, which makes it difficult to copy sha1s. Sample output for "git log --oneline --cherry": =049c269 t6007: test rev-list --cherry Change this to = 049c269 t6007: test rev-list --cherry which matches exactly the current output of "git log --graph". Leave "git rev-list" output as is (no space) so that they do not break. Adjust "git-svn" which uses "git log --pretty=raw --boundary". Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- log-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 1257040311..2a1e3a94c9 100644 --- a/log-tree.c +++ b/log-tree.c @@ -381,7 +381,7 @@ void show_log(struct rev_info *opt) graph_show_commit(opt->graph); if (!opt->graph) - fputs(get_revision_mark(opt, commit), stdout); + put_revision_mark(opt, commit); fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); if (opt->print_parents) show_parents(commit, abbrev_commit); @@ -439,7 +439,7 @@ void show_log(struct rev_info *opt) fputs("commit ", stdout); if (!opt->graph) - fputs(get_revision_mark(opt, commit), stdout); + put_revision_mark(opt, commit); fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); if (opt->print_parents) -- cgit v1.2.3 From 6bf139440c192e157b9c0dab701fa2100fbb1e1e Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 26 May 2011 18:27:49 -0400 Subject: clean up calling conventions for pretty.c functions We have a pretty_print_context representing the parameters for a pretty-print session, but we did not use it uniformly. As a result, functions kept growing more and more arguments. Let's clean this up in a few ways: 1. All pretty-print pp_* functions now take a context. This lets us reduce the number of arguments to these functions, since we were just passing around the context values separately. 2. The context argument now has a cmit_fmt field, which was passed around separately. That's one less argument per function. 3. The context argument always comes first, which makes calling a little more uniform. This drops lines from some callers, and adds lines in a few places (because we need an extra line to set the context's fmt field). Overall, we don't save many lines, but the lines that are there are a lot simpler and more readable. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- log-tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index b46ed3baef..0d8cc7af2c 100644 --- a/log-tree.c +++ b/log-tree.c @@ -505,7 +505,8 @@ void show_log(struct rev_info *opt) ctx.abbrev = opt->diffopt.abbrev; ctx.after_subject = extra_headers; ctx.reflog_info = opt->reflog_info; - pretty_print_commit(opt->commit_format, commit, &msgbuf, &ctx); + ctx.fmt = opt->commit_format; + pretty_print_commit(&ctx, commit, &msgbuf); if (opt->add_signoff) append_signoff(&msgbuf, opt->add_signoff); -- cgit v1.2.3 From 9553d2b26395d9a19bf60875784661090f607f4a Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 26 May 2011 18:28:17 -0400 Subject: format-patch: preserve subject newlines with -k In older versions of git, we used rfc822 header folding to indicate that the original subject line had multiple lines in it. But since a1f6baa (format-patch: wrap long header lines, 2011-02-23), we now use header folding whenever there is a long line. This means that "git am" cannot trust header folding as a sign from format-patch that newlines should be preserved. Instead, format-patch needs to signal more explicitly that the newlines are significant. This patch does so by rfc2047-encoding the newlines in the subject line. No changes are needed on the "git am" end; it already decodes the newlines properly. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- log-tree.c | 1 + 1 file changed, 1 insertion(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 0d8cc7af2c..0c41789356 100644 --- a/log-tree.c +++ b/log-tree.c @@ -504,6 +504,7 @@ void show_log(struct rev_info *opt) ctx.date_mode = opt->date_mode; ctx.abbrev = opt->diffopt.abbrev; ctx.after_subject = extra_headers; + ctx.preserve_subject = opt->preserve_subject; ctx.reflog_info = opt->reflog_info; ctx.fmt = opt->commit_format; pretty_print_commit(&ctx, commit, &msgbuf); -- cgit v1.2.3 From e7af8e49cd54f1784fa2a0e382f22ca2f98cf4d8 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 30 May 2011 10:19:05 -0400 Subject: format-patch: make zero-length subject prefixes prettier If you give a zero-length subject prefix to format-patch (e.g., "format-patch --subject-prefix="), we will print the ugly: Subject: [ 1/2] your subject here because we always insert a space between the prefix and numbering. Requiring the user to provide the space in their prefix would be more flexible, but would break existing usage. This patch provides a DWIM and suppresses the space for zero-length prefixes, under the assumption that nobody actually wants "[ 1/2]". Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- log-tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 2a1e3a94c9..296f417dfc 100644 --- a/log-tree.c +++ b/log-tree.c @@ -294,8 +294,9 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit, if (opt->total > 0) { static char buffer[64]; snprintf(buffer, sizeof(buffer), - "Subject: [%s %0*d/%d] ", + "Subject: [%s%s%0*d/%d] ", opt->subject_prefix, + *opt->subject_prefix ? " " : "", digits_in_number(opt->total), opt->nr, opt->total); subject = buffer; -- cgit v1.2.3 From 594ffe80e7827b20335c5c6dde2cf57c9919db68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 18 Aug 2011 19:29:34 +0700 Subject: decoration: do not mis-decorate refs with same prefix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We definitely do not want to decorate refs/headsandtails the same as refs/heads/*, for example. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- log-tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index e9457019d5..344f7347cc 100644 --- a/log-tree.c +++ b/log-tree.c @@ -95,11 +95,11 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in if (!obj) return 0; - if (!prefixcmp(refname, "refs/heads")) + if (!prefixcmp(refname, "refs/heads/")) type = DECORATION_REF_LOCAL; - else if (!prefixcmp(refname, "refs/remotes")) + else if (!prefixcmp(refname, "refs/remotes/")) type = DECORATION_REF_REMOTE; - else if (!prefixcmp(refname, "refs/tags")) + else if (!prefixcmp(refname, "refs/tags/")) type = DECORATION_REF_TAG; else if (!prefixcmp(refname, "refs/stash")) type = DECORATION_REF_STASH; -- cgit v1.2.3 From 76f5df305beddb864b3d1d12800d0de442d05596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 18 Aug 2011 19:29:37 +0700 Subject: log: decorate grafted commits with "grafted" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In shallow repositories, this may help detect whether a branch ends, or it is deeper than current depth. It also show graft points that extend a branch. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- log-tree.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 344f7347cc..56052441e2 100644 --- a/log-tree.c +++ b/log-tree.c @@ -18,6 +18,7 @@ enum decoration_type { DECORATION_REF_TAG, DECORATION_REF_STASH, DECORATION_REF_HEAD, + DECORATION_GRAFTED, }; static char decoration_colors[][COLOR_MAXLEN] = { @@ -27,6 +28,7 @@ static char decoration_colors[][COLOR_MAXLEN] = { GIT_COLOR_BOLD_YELLOW, /* REF_TAG */ GIT_COLOR_BOLD_MAGENTA, /* REF_STASH */ GIT_COLOR_BOLD_CYAN, /* REF_HEAD */ + GIT_COLOR_BOLD_BLUE, /* GRAFTED */ }; static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix) @@ -118,6 +120,15 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in return 0; } +static int add_graft_decoration(const struct commit_graft *graft, void *cb_data) +{ + struct commit *commit = lookup_commit(graft->sha1); + if (!commit) + return 0; + add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object); + return 0; +} + void load_ref_decorations(int flags) { static int loaded; @@ -125,6 +136,7 @@ void load_ref_decorations(int flags) loaded = 1; for_each_ref(add_ref_decoration, &flags); head_ref(add_ref_decoration, &flags); + for_each_commit_graft(add_graft_decoration, NULL); } } -- cgit v1.2.3 From f1c9626105d5e4962a5ccaa4620114d03f32ad02 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 17 Aug 2011 22:03:12 -0700 Subject: diff: refactor COLOR_DIFF from a flag into an int This lets us store more than just a bit flag for whether we want color; we can also store whether we want automatic colors. This can be useful for making the automatic-color decision closer to the point of use. This mostly just involves replacing DIFF_OPT_* calls with manipulations of the flag. The biggest exception is that calls to DIFF_OPT_TST must check for "o->use_color > 0", which lets an "unknown" value (i.e., the default) stay at "no color". In the previous code, a value of "-1" was not propagated at all. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- log-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index e9457019d5..9ba8fb2af3 100644 --- a/log-tree.c +++ b/log-tree.c @@ -31,7 +31,7 @@ static char decoration_colors[][COLOR_MAXLEN] = { static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix) { - if (decorate_use_color) + if (decorate_use_color > 0) return decoration_colors[ix]; return ""; } @@ -77,7 +77,7 @@ int parse_decorate_color_config(const char *var, const int ofs, const char *valu * for showing the commit sha1, use the same check for --decorate */ #define decorate_get_color_opt(o, ix) \ - decorate_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix) + decorate_get_color((o)->use_color, ix) static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj) { -- cgit v1.2.3 From 5267d292ecbdc91018db05275ec6057d2c4cfa18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Fri, 19 Aug 2011 19:43:50 +0700 Subject: log: decorate "replaced" on to replaced commits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Old code also decorates "new" commits with "refs/replace/SHA1". This is now gone, but I guess no one will miss it. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- log-tree.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 56052441e2..74fc20da4d 100644 --- a/log-tree.c +++ b/log-tree.c @@ -92,8 +92,22 @@ static void add_name_decoration(enum decoration_type type, const char *name, str static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data) { - struct object *obj = parse_object(sha1); + struct object *obj; enum decoration_type type = DECORATION_NONE; + + if (!prefixcmp(refname, "refs/replace/")) { + unsigned char original_sha1[20]; + if (get_sha1_hex(refname + 13, original_sha1)) { + warning("invalid replace ref %s", refname); + return 0; + } + obj = parse_object(original_sha1); + if (obj) + add_name_decoration(DECORATION_GRAFTED, "replaced", obj); + return 0; + } + + obj = parse_object(sha1); if (!obj) return 0; -- cgit v1.2.3 From daa0c3d9717624a62ce669252be832db12658ec0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 17 Aug 2011 22:04:23 -0700 Subject: color: delay auto-color decision until point of use When we read a color value either from a config file or from the command line, we use git_config_colorbool to convert it from the tristate always/never/auto into a single yes/no boolean value. This has some timing implications with respect to starting a pager. If we start (or decide not to start) the pager before checking the colorbool, everything is fine. Either isatty(1) will give us the right information, or we will properly check for pager_in_use(). However, if we decide to start a pager after we have checked the colorbool, things are not so simple. If stdout is a tty, then we will have already decided to use color. However, the user may also have configured color.pager not to use color with the pager. In this case, we need to actually turn off color. Unfortunately, the pager code has no idea which color variables were turned on (and there are many of them throughout the code, and they may even have been manipulated after the colorbool selection by something like "--color" on the command line). This bug can be seen any time a pager is started after config and command line options are checked. This has affected "git diff" since 89d07f7 (diff: don't run pager if user asked for a diff style exit code, 2007-08-12). It has also affect the log family since 1fda91b (Fix 'git log' early pager startup error case, 2010-08-24). This patch splits the notion of parsing a colorbool and actually checking the configuration. The "use_color" variables now have an additional possible value, GIT_COLOR_AUTO. Users of the variable should use the new "want_color()" wrapper, which will lazily determine and cache the auto-color decision. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- log-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 9ba8fb2af3..95d6d4080e 100644 --- a/log-tree.c +++ b/log-tree.c @@ -31,7 +31,7 @@ static char decoration_colors[][COLOR_MAXLEN] = { static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix) { - if (decorate_use_color > 0) + if (want_color(decorate_use_color)) return decoration_colors[ix]; return ""; } -- cgit v1.2.3 From b9ad500262843c6110968da1f4e7b6717bc71303 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Thu, 25 Aug 2011 17:09:30 +0200 Subject: log: Do not decorate replacements with --no-replace-objects 5267d29 (log: decorate "replaced" on to replaced commits, 2011-08-19) introduced textual decorations for replaced commits, based on the detection of refs/replace. Make it so that additionally the use of --no-replace-objects is detected: I.e. replaced commits are only decorated as replaced when they are actually replaced. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- log-tree.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 74fc20da4d..c40fa50c6f 100644 --- a/log-tree.c +++ b/log-tree.c @@ -97,6 +97,8 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in if (!prefixcmp(refname, "refs/replace/")) { unsigned char original_sha1[20]; + if (!read_replace_refs) + return 0; if (get_sha1_hex(refname + 13, original_sha1)) { warning("invalid replace ref %s", refname); return 0; -- cgit v1.2.3