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.
---
git.c +1 -0
@@ -373,6 +373,7 @@ static int cmd_show(int argc, const char rev.diffopt.recursive =1 ; rev.combine_merges =1 ; rev.dense_combined_merges =1 ; + rev.always_show_header =1 ; rev.ignore_merges =0 ; rev.no_walk =1 ;return cmd_log_wc (argc, argv, envp, &rev);
log-tree.c +14 -4
@@ -43,7 +43,7 @@ static int diff_root_tree(struct rev_infreturn 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(struc 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)
Thanks for fixing this. I've applied and merged it to the "next" branch.
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(). rev->use_precomputed_header and perhaps rev->header can be dropped and replaced with a call to a function to print formatted log to stdout (or perhaps a FILE *, because I want to reuse this to make output part of "git-format-patch" internal) from log-tree.
For that, I'd need to define a new CMIT_FMT for the format-patch output. Another thing needed is to clean up the commit_prefix local variable defined in cmd_log_wc() -- it should use rev->header_prefix, but before that the part that rewrites opt->header_prefix to have a blank line between commits, in log-tree.c::do_diff_combined() and log_tree_commit() need to be cleaned up.
For the header_prefix line, there also is a subtle difference between the one-commit diff-tree and log. The former lists "this commit (from that commit)", which is perhaps useful for cut and paste purposes. The latter just says "this commit".
I wish this "diff-tree SHA1 (from ANOTHERSHA1)" format can be dropped and replaced with "commit SHA1" format like "git log" does uniformly, but it might be already depended upon by Porcelains.
If the commit is not a merge, "commit SHA1" means the same thing as "diff-tree SHA1 (from SHA1^)", and if it _is_ a merge, then the merge parents are listed on the "Merge: " line anyway for all formats other than --pretty=oneline, so unless this change breaks an Porcelain, there is really no downside.
Quoted 4 lines · Junio C Hamano
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 incmd_log_wc().
Maybe. I'm not convinced, though. The reason? cmd_log_wc needs to generate it regardless, for the "always" case.
Also, I think the "---" printing should be removed, and moved into the "diffstat" flushing code. Right now it does the wrong thing entirely if no diff exists, but we have always_show_header: it will print the "---" for no good reason.
Quoted 4 lines
I wish this "diff-tree SHA1 (from ANOTHERSHA1)" format can be dropped and replaced with "commit SHA1" format like "git log" does uniformly, but it might be already depended upon by Porcelains.
I think it might be worth just trying. A lot of the formats were pretty ad-hoc, and since everybody had their own routines, there was no reason to even try to keep them similar. Now, we'd be better off trying to make them look as close to each other as possible, and I suspect there's not a lot of porcelain that cares deeply about that format..
Linus
Quoted 2 lines · Linus Torvalds
Also, I think the "---" printing should be removed, and moved into the "diffstat" flushing code.
I am not sure if that belongs to diffstat flush. I was instead planning to move it to diff-flush code, and show it only when we actually show any diffs. IOW, I think we would want it even when we are doing "--pretty -p", not "--pretty --patch-with-stat".
Quoted 3 lines · Junio C Hamano
I am not sure if that belongs to diffstat flush. I was instead planning to move it to diff-flush code
Well, that's broken right now with the stat part, for some reason.
Quoted 3 lines
and show it only when we actually show any diffs. IOW, I think we would want it even when we are doing "--pretty -p", not "--pretty --patch-with-stat".
I'd personally prefer to see it only in front of diffstat, and leave the patches the way they have been before. For patches, I find the indentation of the commit message to be visually (a) much more pleasing and (b) more pronounced than a "---" anyway.
Perhaps configurable? git-format-patch doesn't want the indentation (and thus "---" makes sense for both patches and diffstat), while "git log" definitely does, because it's much more visually clear _and_ it makes the header/comment structure totally unambiguous.
Linus
Quoted 3 lines · Linus Torvalds
Maybe. I'm not convinced, though. The reason?
cmd_log_wcneeds to generate it regardless, for the "always" case.
Of course, you could just have the "diff" logic unconditionally do the call-back. That would be clean enough.
Quoted 4 lines
Also, I think the "---" printing should be removed, and moved into the "diffstat" flushing code. Right now it does the wrong thing entirely if no diff exists, but we have
always_show_header: it will print the "---" for no good reason.
The alternative is to do something like this, but because the "diffstat" doesn't flush the header priperly, it doesn't add the "---" for merges (and it used to not show the log at all, even for "git log", before I fixed it).
Try it with
git log --cc --patch-with-stat
to see what I mean.
I do agree that this would be much cleaner with a "print header" callback in the diffopt structure. This patch is the really hacky "continue to do things the ugly way" approach to fix some of the uglier output.
Only meant as a RFC and to illustrate what I think the output should look like (modulo the lack of "---" before a diffstat with no patch - for merges). Not meant to actually be applied, I think this can be done much more cleanly with the callback.
Linus
---
git.c +14 -6
@@ -284,7 +284,7 @@ static int cmd_log_wc(int argc, const chstruct commit *commit;char *buf =xmalloc (LOGSIZE );const char *commit_prefix ="commit " ; -int shown =0 ; +int shown =0 , always_show_header; rev->abbrev =DEFAULT_ABBREV ; rev->commit_format =CMIT_FMT_DEFAULT ;
@@ -295,13 +295,19 @@ static int cmd_log_wc(int argc, const chif (rev->commit_format ==CMIT_FMT_ONELINE ) commit_prefix ="" ; +/* +* We handle always_show_header outselves, and leave the +* "---" handling to log_tree_commit +*/ + always_show_header = rev->always_show_header; + rev->always_show_header =0 ; +prepare_revision_walk (rev);setup_pager ();while ((commit =get_revision (rev)) !=NULL ) {unsigned long ofs =0 ; -if (shown && rev->diff && - rev->commit_format !=CMIT_FMT_ONELINE ) +if (shown && rev->commit_format !=CMIT_FMT_ONELINE )putchar ('\n' ); ofs =sprintf (buf,"%s" , commit_prefix);
@@ -338,14 +344,16 @@ static int cmd_log_wc(int argc, const ch buf + ofs,LOGSIZE - ofs -20 , rev->abbrev); +if (always_show_header || !rev->diff) { +fputs (buf, stdout); + ofs =0 ; + }if (rev->diff) { +strcpy (buf + ofs, rev->diffopt.with_stat ?"---" :"\n" ); rev->use_precomputed_header = buf; -strcpy (buf + ofs,"\n---\n" );log_tree_commit (rev, commit); } -else -printf ("%s\n" , buf); shown =1 ;free (commit->buffer); commit->buffer =NULL ;
Log message printout cleanups
In reply to Junio C HamanoQuoted 4 lines · Junio C Hamano
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 incmd_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.
--- combine-diff.c | 47 ++++++-------- diff-files.c | 27 ++++---- diff-tree.c | 1 diff.h | 8 +- git.c | 57 +---------------- log-tree.c | 167 ++++++++++++++++++++++++++++----------------------- log-tree.h | 5 ++ rev-list.c | 9 ++- revision.c | 3 - revision.h | 8 +- t/t1200-tutorial.sh | 4 + 11 files changed, 151 insertions(+), 185 deletions(-)
combine-diff.c +21 -26
@@ -5,6 +5,7 @@ #include "diff.h"#include "diffcore.h" #include "quote.h" #include "xdiff-interface.h" +#include "log-tree.h" static int uninteresting (struct diff_filepair *p) {
@@ -585,9 +586,9 @@ static void reuse_combine_diff(struct sl }static int show_patch_diff (struct combine_diff_path *elem,int num_parent, -int dense,const char *header, -struct diff_options *opt) +int dense,struct rev_info *rev) { +struct diff_options *opt = &rev->diffopt;unsigned long result_size, cnt, lno;char *result, *cp, *ep;struct sline *sline;/* survived lines */
@@ -689,10 +690,8 @@ static int show_patch_diff(struct combinif (show_hunks || mode_differs || working_tree_file) {const char *abb; -if (header) { - shown_header++; -printf ("%s%c" , header, opt->line_termination); - } +if (rev->loginfo) +show_log (rev, rev->loginfo,"\n" );printf ("diff --%s " , dense ?"cc" :"combined" );if (quote_c_style (elem->path,NULL ,NULL ,0 ))quote_c_style (elem->path,NULL , stdout,0 );
@@ -750,8 +749,9 @@ static int show_patch_diff(struct combin#define COLONS "::::::::::::::::::::::::::::::::" -static void show_raw_diff (struct combine_diff_path *p,int num_parent,const char *header,struct diff_options *opt) +static void show_raw_diff (struct combine_diff_path *p,int num_parent,struct rev_info *rev) { +struct diff_options *opt = &rev->diffopt;int i, offset, mod_type ='A' ;const char *prefix;int line_termination, inter_name_termination;
@@ -761,8 +761,8 @@ static void show_raw_diff(struct combineif (!line_termination) inter_name_termination =0 ; -if (header) -printf ("%s%c" , header, line_termination); +if (rev->loginfo) +show_log (rev, rev->loginfo,"\n" );for (i =0 ; i < num_parent; i++) {if (p->parent[i].mode)
@@ -810,31 +810,31 @@ static void show_raw_diff(struct combine } } -int show_combined_diff (struct combine_diff_path *p, +void show_combined_diff (struct combine_diff_path *p,int num_parent,int dense, -const char *header, -struct diff_options *opt) +struct rev_info *rev) { +struct diff_options *opt = &rev->diffopt;if (!p->len) -return 0 ; +return ;switch (opt->output_format) {case DIFF_FORMAT_RAW :case DIFF_FORMAT_NAME_STATUS :case DIFF_FORMAT_NAME : -show_raw_diff (p, num_parent, header, opt); -return 1 ; +show_raw_diff (p, num_parent, rev); +return ;default :case DIFF_FORMAT_PATCH : -return show_patch_diff (p, num_parent, dense, header, opt); +show_patch_diff (p, num_parent, dense, rev); } } -const char *diff_tree_combined_merge (const unsigned char *sha1, -const char *header,int dense, -struct diff_options *opt) +void diff_tree_combined_merge (const unsigned char *sha1, +int dense,struct rev_info *rev) { +struct diff_options *opt = &rev->diffopt;struct commit *commit =lookup_commit (sha1);struct diff_options diffopts;struct commit_list *parents;
@@ -874,17 +874,13 @@ const char *diff_tree_combined_merge(conint saved_format = opt->output_format; opt->output_format =DIFF_FORMAT_RAW ;for (p = paths; p; p = p->next) { -if (show_combined_diff (p, num_parent, dense, - header, opt)) - header =NULL ; +show_combined_diff (p, num_parent, dense, rev); } opt->output_format = saved_format;putchar (opt->line_termination); }for (p = paths; p; p = p->next) { -if (show_combined_diff (p, num_parent, dense, - header, opt)) - header =NULL ; +show_combined_diff (p, num_parent, dense, rev); } }
@@ -894,5 +890,4 @@ const char *diff_tree_combined_merge(con paths = paths->next;free (tmp); } -return header; }
diff-files.c +14 -13
@@ -5,12 +5,14 @@*/ #include "cache.h" #include "diff.h" +#include "commit.h" +#include "revision.h" static const char diff_files_usage[] ="git-diff-files [-q] [-0/-1/2/3 |-c|--cc] [<common diff options>] [<path>...]" COMMON_DIFF_OPTIONS_HELP ; -static struct diff_options diff_options; +static struct rev_info rev;static int silent =0 ;static int diff_unmerged_stage =2 ;static int combine_merges =0 ;
@@ -18,12 +20,12 @@ static int dense_combined_merges = 0;static void show_unmerge (const char *path) { -diff_unmerge (&diff_options, path); +diff_unmerge (&rev.diffopt, path); }static void show_file (int pfx,struct cache_entry *ce) { -diff_addremove (&diff_options, pfx,ntohl (ce->ce_mode), +diff_addremove (&rev.diffopt, pfx,ntohl (ce->ce_mode), ce->sha1, ce->name,NULL ); }
@@ -31,7 +33,7 @@ static void show_modified(int oldmode, i const unsigned char *old_sha1, const unsigned char *sha1, char *path) { - diff_change(&diff_options, oldmode, mode, old_sha1, sha1, path, NULL); + diff_change(&rev.diffopt, oldmode, mode, old_sha1, sha1, path, NULL); }int main (int argc,const char **argv)
@@ -41,7 +43,7 @@ int main(int argc, const char **argv)int entries, i;git_config (git_diff_config); -diff_setup (&diff_options); +diff_setup (&rev.diffopt);while (1 < argc && argv[1 ][0 ] =='-' ) {if (!strcmp (argv[1 ],"--" )) { argv++;
@@ -74,7 +76,7 @@ int main(int argc, const char **argv) dense_combined_merges = combine_merges =1 ; else {int diff_opt_cnt; - diff_opt_cnt =diff_opt_parse (&diff_options, + diff_opt_cnt =diff_opt_parse (&rev.diffopt, argv+1 , argc-1 );if (diff_opt_cnt <0 )usage (diff_files_usage);
@@ -89,13 +91,13 @@ int main(int argc, const char **argv) argv++; argc--; }if (dense_combined_merges) - diff_options.output_format =DIFF_FORMAT_PATCH ; + rev.diffopt.output_format =DIFF_FORMAT_PATCH ;/* Find the directory, and set up the pathspec */ pathspec =get_pathspec (prefix, argv +1 ); entries =read_cache (); -if (diff_setup_done (&diff_options) <0 ) +if (diff_setup_done (&rev.diffopt) <0 )usage (diff_files_usage);/* At this point, if argc == 1, then we are doing everything.
@@ -167,8 +169,7 @@ int main(int argc, const char **argv)if (combine_merges && num_compare_stages ==2 ) {show_combined_diff (&combine.p,2 , dense_combined_merges, -NULL , - &diff_options); + &rev);free (combine.p.path);continue ; }
@@ -194,7 +195,7 @@ int main(int argc, const char **argv)continue ; } changed =ce_match_stat (ce, &st,0 ); -if (!changed && !diff_options.find_copies_harder) +if (!changed && !rev.diffopt.find_copies_harder)continue ; oldmode =ntohl (ce->ce_mode);
@@ -207,7 +208,7 @@ int main(int argc, const char **argv) ce->sha1, (changed ? null_sha1 : ce->sha1), ce->name); } -diffcore_std (&diff_options); -diff_flush (&diff_options); +diffcore_std (&rev.diffopt); +diff_flush (&rev.diffopt);return 0 ; }
diff-tree.c +1 -0
@@ -71,6 +71,7 @@ int main(int argc, const char **argv) nr_sha1 =0 ;init_revisions (opt); opt->abbrev =0 ; + opt->diff =1 ; argc =setup_revisions (argc, argv, opt,NULL );while (--argc >0 ) {
diff.h +4 -4
@@ -6,6 +6,7 @@ #define DIFF_H#include "tree-walk.h" +struct rev_info ;struct diff_options ; typedef void (*change_fn_t)(struct diff_options *options,
@@ -70,11 +71,10 @@ #define combine_diff_path_size(n, l) \ (sizeof (struct combine_diff_path ) + \ sizeof(struct combine_diff_parent) * (n) + (l) + 1) -extern int show_combined_diff (struct combine_diff_path *elem,int num_parent, -int dense,const char *header, -struct diff_options *); +extern void show_combined_diff (struct combine_diff_path *elem,int num_parent, +int dense,struct rev_info *); -extern const char *diff_tree_combined_merge (const unsigned char *sha1,const char *,int ,struct diff_options *opt); +extern void diff_tree_combined_merge (const unsigned char *sha1,int ,struct rev_info *); extern void diff_addremove(struct diff_options *, int addremove,
git.c +2 -55
77 lines not on this page · raw message
log-tree.c +93 -74
212 lines not on this page · raw message
log-tree.h +5 -0
@@ -3,9 +3,14 @@ #define LOG_TREE_H#include "revision.h" +struct log_info { +struct commit *commit, *parent; +}; +void init_log_tree_opt (struct rev_info *);int log_tree_diff_flush (struct rev_info *);int log_tree_commit (struct rev_info *,struct commit *);int log_tree_opt_parse (struct rev_info *,const char **,int ); +void show_log (struct rev_info *opt,struct log_info *log,const char *sep);#endif
rev-list.c +5 -4
@@ -41,13 +41,14 @@ struct rev_info revs;static int bisect_list =0 ;static int show_timestamp =0 ;static int hdr_termination =0 ; +static const char *header_prefix;static void show_commit (struct commit *commit) {if (show_timestamp)printf ("%lu " , commit->date); -if (*revs.header_prefix) -fputs (revs.header_prefix, stdout); +if (header_prefix) +fputs (header_prefix, stdout);if (commit->object.flags &BOUNDARY )putchar ('-' );if (revs.abbrev_commit && revs.abbrev)
@@ -322,9 +323,9 @@ int main(int argc, const char **argv)/* The command line has a --pretty */ hdr_termination ='\n' ;if (revs.commit_format ==CMIT_FMT_ONELINE ) - revs.header_prefix ="" ; + header_prefix ="" ;else - revs.header_prefix ="commit " ; + header_prefix ="commit " ; } list = revs.commits;
revision.c +0 -3
@@ -498,7 +498,6 @@ void init_revisions(struct rev_info *rev revs->topo_setter = topo_sort_default_setter; revs->topo_getter = topo_sort_default_getter; - revs->header_prefix ="" ; revs->commit_format =CMIT_FMT_DEFAULT ;diff_setup (&revs->diffopt);
@@ -675,12 +674,10 @@ int setup_revisions(int argc, const char }if (!strcmp (arg,"-v" )) { revs->verbose_header =1 ; - revs->header_prefix ="diff-tree " ;continue ; }if (!strncmp (arg,"--pretty" ,8 )) { revs->verbose_header =1 ; - revs->header_prefix ="diff-tree " ; revs->commit_format =get_commit_format (arg+8 );continue ; }
revision.h +4 -4
@@ -11,6 +11,7 @@ #define BOUNDARY_SHOW (1u<<6)#define ADDED (1u<<7)/* Parents already parsed and added? */ struct rev_info ; +struct log_info ;typedef void (prune_fn_t )(struct rev_info *revs,struct commit *commit);
@@ -52,12 +53,11 @@ struct rev_info { always_show_header:1 ;/* Format info */ - unsigned int abbrev_commit:1; + unsigned int shown_one:1, + abbrev_commit:1;unsigned int abbrev;enum cmit_fmt commit_format; -const char *header_prefix; -const char *header; -const char *use_precomputed_header; +struct log_info *loginfo;/* special limits */ int max_count;
t/t1200-tutorial.sh +2 -2
@@ -49,7 +49,7 @@ #rm hello #test_expect_success 'git-read-tree --reset HEAD' "git-read-tree --reset HEAD ; test \"hello: needs update\" = \"$(git-update-index --refresh)\"" cat > whatchanged.expect << EOF -diff-tree VARIABLE (from root) +commit VARIABLE Author: VARIABLE Date: VARIABLE
@@ -72,7 +72,7 @@ index 0000000..557db03 EOF git-whatchanged -p --root | \ - sed -e "1s/^\(.\{10\}\).\{40\}/\1VARIABLE/" \ + sed -e "1s/^\(.\{7\}\).\{40\}/\1VARIABLE/" \ -e "2,3s/^\(.\{8\}\).*$/\1VARIABLE/" \ > whatchanged.output test_expect_success 'git-whatchanged -p --root' 'cmp whatchanged.expect whatchanged.output'
Re: Log message printout cleanups
Quoted 9 lines · Linus Torvalds
Quoted 4 lines · Junio C Hamano
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 incmd_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.
I like the new cmd_log_wc() loop very much; I was planning to do this myself, but I was too slow ;-).
Thanks.
Re: Log message printout cleanups
Quoted 5 lines · Junio C Hamano
I like the new
cmd_log_wc()loop very much; I was planning to do this myself, but I was too slow ;-).Thanks.
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".
I realize that Dscho has been looking at some much "fancier" merge diffstats, but I really do believe that the "what got merged" difference to the original branch (ie parent 1) is what you want in practice.
Anyway, that's a totally separate issue, I'll let you guys fight that out.
Linus
---
combine-diff.c +16 -6
@@ -585,6 +585,16 @@ static void reuse_combine_diff(struct sl sline->p_lno[i] = sline->p_lno[j]; } +static void dump_quoted_path (const char *prefix,const char *path) +{ +fputs (prefix, stdout); +if (quote_c_style (path,NULL ,NULL ,0 )) +quote_c_style (path,NULL , stdout,0 ); +else +printf ("%s" , path); +putchar ('\n' ); +} +static int show_patch_diff (struct combine_diff_path *elem,int num_parent,int dense,struct rev_info *rev) {
@@ -692,12 +702,7 @@ static int show_patch_diff(struct combinif (rev->loginfo)show_log (rev, rev->loginfo,"\n" ); -printf ("diff --%s " , dense ?"cc" :"combined" ); -if (quote_c_style (elem->path,NULL ,NULL ,0 )) -quote_c_style (elem->path,NULL , stdout,0 ); -else -printf ("%s" , elem->path); -putchar ('\n' ); +dump_quoted_path (dense ?"diff --cc " :"diff --combined " , elem->path);printf ("index " );for (i =0 ; i < num_parent; i++) { abb = find_unique_abbrev(elem->parent[i].sha1,
@@ -728,6 +733,8 @@ static int show_patch_diff(struct combin }putchar ('\n' ); } +dump_quoted_path ("--- a/" , elem->path); +dump_quoted_path ("+++ b/" , elem->path);dump_sline (sline, cnt, num_parent); }free (result);
@@ -861,6 +868,9 @@ void diff_tree_combined_merge(const unsi &diffopts);diffcore_std (&diffopts); paths =intersect_paths (paths, i, num_parent); + +if (diffopts.with_stat && rev->loginfo) +show_log (rev, rev->loginfo,"---\n" );diff_flush (&diffopts); }
log-tree.c +1 -2
@@ -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 }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 ; }
Re: Log message printout cleanups
Quoted 9 lines · Linus Torvalds
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".
I realize that Dscho has been looking at some much "fancier" merge diffstats, but I really do believe that the "what got merged" difference to the original branch (ie parent 1) is what you want in practice.
Anyway, that's a totally separate issue, I'll let you guys fight that out.
I agree with your opinion 100% from usability point of view, although I admit one of the fancier format was suggested by me.
Showing stat from the first parent makes --stat inconsistent from what the "fake diff" shows, but I think it is a sensible thing to do. The purpose of two are different in that (1) stat is a way to see the extent of damage to what you had before you merged, and (2) --cc is a way to see how complex the merge was, to spot obvious merge mistakes and sanity check the merge at the contents level.
Re: Log message printout cleanups
Quoted 3 lines · Linus Torvalds
I realize that Dscho has been looking at some much "fancier" merge diffstats, but I really do believe that the "what got merged" difference to the original branch (ie parent 1) is what you want in practice.
These days I find myself running "git log --stat" more often than "git whatchanged"; it looks so much nicer ;-).
Thanks for a job well done.
Re: Log message printout cleanups
Quoted 5 lines · Junio C Hamano
These days I find myself running "git log --stat" more often than "git whatchanged"; it looks so much nicer ;-).
Thanks for a job well done.
There's actually something _wrong_ with "git log --stat".
What happens is that "git log" will enable "rev.combine_merges" by default, and that means that together with "--stat" ignoring merges by default, it will _instead_ generate a "--cc" diff for that merge.
I think that behaviour was introduced by the "--stat" code by Dscho, and not by my rewrite.
You can see it on the kernel archive on commit 88dd9c16, for example:
git log --stat 88dd9c16
will make it pretty obvious what I'm talking about.
I still haven't looked a lot at what the diffstat code does, so I don't know what the obvious fix is. Maybe setting "ignore_merges". And maybe just making the diffstat thing do the right thing for merges.
I'll leave that up to you, I'm getting pretty fed up with "git log" right now ;)
Linus
Re: Log message printout cleanups
Quoted 8 lines · Linus Torvalds
There's actually something _wrong_ with "git log --stat".
What happens is that "git log" will enable "rev.combine_merges" by default, and that means that together with "--stat" ignoring merges by default, it will _instead_ generate a "--cc" diff for that merge.
I'll leave that up to you, I'm getting pretty fed up with "git log" right now ;)
The primary problem is that the code in "next" was before the "fancy diffstat for combined" work by Johannes; it punts and always shows the patch output even when stat is asked for.
I think this does what both of us want. One thing I noticed is that log-tree-diff-flush does "---\n" under --patch-with-stat but not under --stat; I matched that here.
-- >8 --
combine-diff: show diffstat with the first parent.
Even under combine-diff, asking for stat (either with --stat or --patch-with-stat) gives you diffstat for the first parent.
While the combined patch is useful to highlight the complexity and interaction of the parts touched by all branches when reviewing a merge commit, diffstat is a tool to assess the extent of damage the merge brings in, and showing stat with the first parent is more sensible than clever per-parent diffstat.
---
combine-diff.c | 24 +++++++++++++++++++----- 1 files changed, 19 insertions(+), 5 deletions(-)
combine-diff.c +19 -5
@@ -831,10 +831,11 @@ void show_combined_diff(struct combine_dcase DIFF_FORMAT_NAME :show_raw_diff (p, num_parent, rev);return ; - -default :case DIFF_FORMAT_PATCH :show_patch_diff (p, num_parent, dense, rev); +return ; +default : +return ; } }
@@ -847,10 +848,13 @@ void diff_tree_combined_merge(const unsistruct commit_list *parents;struct combine_diff_path *p, *paths =NULL ;int num_parent, i, num_paths; +int do_diffstat; + do_diffstat = (opt->output_format ==DIFF_FORMAT_DIFFSTAT || + opt->with_stat); diffopts = *opt; - diffopts.output_format =DIFF_FORMAT_NO_OUTPUT ; diffopts.with_raw =0 ; + diffopts.with_stat =0 ; diffopts.recursive =1 ;/* count parents */
@@ -864,14 +868,24 @@ void diff_tree_combined_merge(const unsiparents ; parents = parents->next, i++) {struct commit *parent = parents->item; +/* show stat against the first parent even +* when doing combined diff. +*/ +if (i ==0 && do_diffstat) + diffopts.output_format =DIFF_FORMAT_DIFFSTAT ; +else + diffopts.output_format =DIFF_FORMAT_NO_OUTPUT ;diff_tree_sha1 (parent->object.sha1, commit->object.sha1,"" , &diffopts);diffcore_std (&diffopts); paths =intersect_paths (paths, i, num_parent); -if (diffopts.with_stat && rev->loginfo) -show_log (rev, rev->loginfo,"---\n" ); +if (do_diffstat && rev->loginfo) +show_log (rev, rev->loginfo, + opt->with_stat ?"---\n" :"\n" );diff_flush (&diffopts); +if (opt->with_stat) +putchar ('\n' ); }/* find out surviving paths */
Re: Log message printout cleanups
Quoted 4 lines · Junio C Hamano
I think this does what both of us want. One thing I noticed is that log-tree-diff-flush does "---\n" under --patch-with-stat but not under --stat; I matched that here.
Looks very nice now. Thanks.
My only slight complaint is that I think it should be possible to do
git log --cc --stat
to get both patches and stat, but that doesn't work. You have to write
git log --cc --patch-with-stat
to get both ;/
But that's just a small (and unimportant) detail.
Here's another really small detail: with merges, there's two newlines between the diffstat and the diff. That bug doesn't show up with regular commits.
But this all looks very nice. I agree that "git log --stat" is a very nice way to look at the log, much better than "git-whatchanged". And the thing that has really fallen out of this all is how you can do
git log --stat --full-diff drivers/pci/
which git-whatchanged historically didn't support (of course, now it does, but you're right, the new "git log" is so nice that I'm starting to teach myself not to use "git whatchanged" any more).
Linus
Re: Log message printout cleanups
Quoted 10 lines · Linus Torvalds
But this all looks very nice. I agree that "git log --stat" is a very nice way to look at the log, much better than "git-whatchanged". And the thing that has really fallen out of this all is how you can do
git log --stat --full-diff drivers/pci/which git-whatchanged historically didn't support (of course, now it does, but you're right, the new "git log" is so nice that I'm starting to teach myself not to use "git whatchanged" any more).
Junio, I just tested the "master" branch, and "git log --stat" doesn't work there. You may _think_ it works because you've tested it on the git tree, were it looks like it is working, but it's missing setting "recursive", so it won't actually go into any subdirectories (so it mostly works for git itself which has most stuff in the top-level directory, but it almost completely doesn't work for linux)
"git log -r --stat" works, so it's really just a missing that.
Something like this (this is master, not "next").
"next" actually has the same bug, but there it is hidden because "git log" sets recursive automatically. Which may or may not be appropriate. It might be worthwhile to fix it properly in "next" too (there the same
if (...output_format == DIFF_FORMAT_PATCH) ...recursive = 1;
is in revision.c: setup_revisions()).
Linus
----
git.c +2 -1
@@ -344,7 +344,8 @@ static int cmd_log(int argc, const char opt.ignore_merges =0 ;if (opt.dense_combined_merges) opt.diffopt.output_format =DIFF_FORMAT_PATCH ; -if (opt.diffopt.output_format ==DIFF_FORMAT_PATCH ) +if (opt.diffopt.output_format ==DIFF_FORMAT_PATCH || + opt.diffopt.output_format ==DIFF_FORMAT_DIFFSTAT ) opt.diffopt.recursive =1 ;if (!full_diff && rev.prune_data)diff_tree_setup_paths (rev.prune_data, &opt.diffopt);
PATCH 1/1 diff --stat: make sure to set recursive.
Quoted 6 lines · Linus Torvalds
Junio, I just tested the "master" branch, and "git log --stat" doesn't work there. You may _think_ it works because you've tested it on the git tree, were it looks like it is working, but it's missing setting "recursive", so it won't actually go into any subdirectories (so it mostly works for git itself which has most stuff in the top-level directory, but it almost completely doesn't work for linux)
True. It shows that I usually install and use "next" version exclusively, which is fine during the normal development phase, but it was a wrong thing to keep doing just before the release.
I think diff-tree --stat has the same problem in "master", so I'd do it slightly differently.
-- >8 --
Just like "patch" format always needs recursive, "diffstat" format does not make sense without setting recursive.
---
diff-tree.c | 3 --- diff.c | 10 ++++++++++ git.c | 2 -- 3 files changed, 10 insertions(+), 5 deletions(-)
f56ef54174598d5362d0446c5a560cb5892537c2
diff-tree.c +0 -3
@@ -117,9 +117,6 @@ int main(int argc, const char **argv)if (opt->dense_combined_merges) opt->diffopt.output_format =DIFF_FORMAT_PATCH ; -if (opt->diffopt.output_format ==DIFF_FORMAT_PATCH ) - opt->diffopt.recursive =1 ; -diff_tree_setup_paths (get_pathspec (prefix, argv), &opt->diffopt);diff_setup_done (&opt->diffopt);
diff.c +10 -0
@@ -1029,6 +1029,16 @@ int diff_setup_done(struct diff_options options->detect_rename != DIFF_DETECT_COPY) || (0 <= options->rename_limit && !options->detect_rename))return -1 ; + +/* +* These cases always need recursive; we do not drop caller-supplied +* recursive bits for other formats here. +*/ +if ((options->output_format ==DIFF_FORMAT_PATCH ) || + (options->output_format ==DIFF_FORMAT_DIFFSTAT ) || + (options->with_stat)) + options->recursive =1 ; +if (options->detect_rename && options->rename_limit <0 ) options->rename_limit = diff_rename_limit_default;if (options->setup &DIFF_SETUP_USE_CACHE ) {
git.c +0 -2
@@ -344,8 +344,6 @@ static int cmd_log(int argc, const char opt.ignore_merges =0 ;if (opt.dense_combined_merges) opt.diffopt.output_format =DIFF_FORMAT_PATCH ; -if (opt.diffopt.output_format ==DIFF_FORMAT_PATCH ) - opt.diffopt.recursive =1 ;if (!full_diff && rev.prune_data)diff_tree_setup_paths (rev.prune_data, &opt.diffopt);diff_setup_done (&opt.diffopt);
Signature · 1 line
1.3.0.rc4.g8060
Re: Log message printout cleanups
In reply to Linus TorvaldsQuoted 2 lines · Linus Torvalds
Junio, I just tested the "master" branch, and "git log --stat" doesn't work there.
Ahhhh.
git.c static int cmd_log(int argc, const char · line 349
Quoted 5 lines
git.c +2
-1opt.diffopt.output_format =DIFF_FORMAT_PATCH ; -if (opt.diffopt.output_format ==DIFF_FORMAT_PATCH ) +if (opt.diffopt.output_format ==DIFF_FORMAT_PATCH || + opt.diffopt.output_format ==DIFF_FORMAT_DIFFSTAT ) opt.diffopt.recursive =1 ;
When pointed out in a patch from, it looks so obvious. *BLUSH*
Thanks.
Re: Log message printout cleanups
In reply to Junio C HamanoQuoted 4 lines · Junio C Hamano
Showing stat from the first parent makes --stat inconsistent from what the "fake diff" shows, but I think it is a sensible thing to do.
It might actually be even more than sensible: it's a huge hint especially for users of "--cc" (or even --combined) that the diff we show really isn't all there is to the merge. So having the "full" diffstat is not just usually what you want to see, it's probably also a really good hint for people who otherwise might not realize that our combined diffs have skipped all the common parts.
Btw, I just noticed that I broke "--pretty=oneline" AGAIN. That thing 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).
Linus
---
log-tree.c +12 -2
@@ -10,6 +9,7 @@ void show_log(struct rev_info *opt, strustruct 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 ;
@@ -19,8 +19,17 @@ void show_log(struct rev_info *opt, stru }/* -* 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 ;
@@ -39,7 +48,7 @@ void show_log(struct rev_info *opt, stru* 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)