t4013: add tests for log -p -m --first-parent
PATCH 1/4 t4013: add tests for log -p -m --first-parent
---
* This is just to finish off where Pasky has left off.
t/t4013-diff-various.sh | 3 + t/t4013/diff.log_-m_-p_--first-parent_master | 100 +++++++++++++ t/t4013/diff.log_-m_-p_master | 200 ++++++++++++++++++++++++++ t/t4013/diff.log_-p_--first-parent_master | 78 ++++++++++ 4 files changed, 381 insertions(+), 0 deletions(-) create mode 100644 t/t4013/diff.log_-m_-p_--first-parent_master create mode 100644 t/t4013/diff.log_-m_-p_master create mode 100644 t/t4013/diff.log_-p_--first-parent_master
t/t4013-diff-various.sh +3 -0
@@ -204,6 +204,9 @@ log --root --patch-with-stat --summary master log --root -c --patch-with-stat --summary master # improved by Timo's patch log --root --cc --patch-with-stat --summary master +log -p --first-parent master +log -m -p --first-parent master +log -m -p master log -SF master log -SF -p master log --decorate --all
t/t4013/diff.log_-m_-p_--first-parent_master new file +100 -0
100 lines not on this page · raw message
t/t4013/diff.log_-m_-p_master new file +200 -0
200 lines not on this page · raw message
t/t4013/diff.log_-p_--first-parent_master new file +78 -0
78 lines not on this page · raw message
Signature · 1 line
1.7.0.2.384.g015e
PATCH 2/4 revision: introduce setup_revision_opt
So far the last parameter to setup_revisions() was to specify the default ref when the command line did not give any (typically "HEAD"). This changes it to take a pointer to a structure so that we can add other information without touching too many codepaths in later patches.
There is no functionality change.
---
builtin-log.c | 30 ++++++++++++++++++++++-------- diff-lib.c | 5 ++++- revision.c | 4 ++-- revision.h | 6 +++++- wt-status.c | 15 +++++++++++---- 5 files changed, 44 insertions(+), 16 deletions(-)
builtin-log.c +22 -8
@@ -32,7 +32,7 @@ static const char * const builtin_log_usage =" or: git show [options] <object>..." ;static void cmd_log_init (int argc,const char **argv,const char *prefix, -struct rev_info *rev) +struct rev_info *rev,struct setup_revision_opt *opt) {int i;int decoration_style =0 ;
@@ -56,7 +56,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,*/ if (argc ==2 && !strcmp (argv[1 ],"-h" ))usage (builtin_log_usage); - argc =setup_revisions (argc, argv, rev,"HEAD" ); + argc =setup_revisions (argc, argv, rev, opt);if (!rev->show_notes_given && !rev->pretty_given) rev->show_notes =1 ;
@@ -262,6 +262,7 @@ static int git_log_config(const char *var, const char *value, void *cb)int cmd_whatchanged (int argc,const char **argv,const char *prefix) {struct rev_info rev; +struct setup_revision_opt opt;git_config (git_log_config,NULL );
@@ -271,7 +272,9 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)init_revisions (&rev, prefix); rev.diff =1 ; rev.simplify_history =0 ; -cmd_log_init (argc, argv, prefix, &rev); +memset (&opt,0 ,sizeof (opt)); + opt.def ="HEAD" ; +cmd_log_init (argc, argv, prefix, &rev, &opt);if (!rev.diffopt.output_format) rev.diffopt.output_format =DIFF_FORMAT_RAW ;return cmd_log_walk (&rev);
@@ -328,6 +331,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) {struct rev_info rev;struct object_array_entry *objects; +struct setup_revision_opt opt;int i, count, ret =0 ;git_config (git_log_config,NULL );
@@ -342,7 +346,9 @@ int cmd_show(int argc, const char **argv, const char *prefix) rev.always_show_header =1 ; rev.ignore_merges =0 ; rev.no_walk =1 ; -cmd_log_init (argc, argv, prefix, &rev); +memset (&opt,0 ,sizeof (opt)); + opt.def ="HEAD" ; +cmd_log_init (argc, argv, prefix, &rev, &opt); count = rev.pending.nr; objects = rev.pending.objects;
@@ -405,6 +411,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)int cmd_log_reflog (int argc,const char **argv,const char *prefix) {struct rev_info rev; +struct setup_revision_opt opt;git_config (git_log_config,NULL );
@@ -415,7 +422,9 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)init_reflog_walk (&rev.reflog_info); rev.abbrev_commit =1 ; rev.verbose_header =1 ; -cmd_log_init (argc, argv, prefix, &rev); +memset (&opt,0 ,sizeof (opt)); + opt.def ="HEAD" ; +cmd_log_init (argc, argv, prefix, &rev, &opt);/* * This means that we override whatever commit format the user gave
@@ -438,6 +447,7 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)int cmd_log (int argc,const char **argv,const char *prefix) {struct rev_info rev; +struct setup_revision_opt opt;git_config (git_log_config,NULL );
@@ -446,7 +456,9 @@ int cmd_log(int argc, const char **argv, const char *prefix)init_revisions (&rev, prefix); rev.always_show_header =1 ; -cmd_log_init (argc, argv, prefix, &rev); +memset (&opt,0 ,sizeof (opt)); + opt.def ="HEAD" ; +cmd_log_init (argc, argv, prefix, &rev, &opt);return cmd_log_walk (&rev); }
@@ -887,6 +899,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)struct commit *commit;struct commit **list =NULL ;struct rev_info rev; +struct setup_revision_opt s_r_opt;int nr =0 , total, i;int use_stdout =0 ;int start_number =-1 ;
@@ -964,8 +977,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) rev.combine_merges =0 ; rev.ignore_merges =1 ;DIFF_OPT_SET (&rev.diffopt,RECURSIVE ); - rev.subject_prefix = fmt_patch_subject_prefix; +memset (&s_r_opt,0 ,sizeof (s_r_opt)); + s_r_opt.def ="HEAD" ;if (default_attach) { rev.mime_boundary = default_attach;
@@ -1037,7 +1051,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)if (keep_subject && subject_prefix)die ("--subject-prefix and -k are mutually exclusive." ); - argc =setup_revisions (argc, argv, &rev,"HEAD" ); + argc =setup_revisions (argc, argv, &rev, &s_r_opt);if (argc >1 )die ("unrecognized argument: %s" , argv[1 ]);
diff-lib.c +4 -1
@@ -510,9 +510,12 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)int index_differs_from (const char *def,int diff_flags) {struct rev_info rev; +struct setup_revision_opt opt;init_revisions (&rev,NULL ); -setup_revisions (0 ,NULL , &rev, def); +memset (&opt,0 ,sizeof (opt)); + opt.def = def; +setup_revisions (0 ,NULL , &rev, &opt);DIFF_OPT_SET (&rev.diffopt,QUICK );DIFF_OPT_SET (&rev.diffopt,EXIT_WITH_STATUS ); rev.diffopt.flags |= diff_flags;
revision.c +2 -2
@@ -1328,7 +1328,7 @@ static void append_prune_data(const char ***prune_data, const char **av)* Returns the number of arguments left that weren't recognized * (which are also moved to the head of the argument list) */ -int setup_revisions (int argc,const char **argv,struct rev_info *revs,const char *def) +int setup_revisions (int argc,const char **argv,struct rev_info *revs,struct setup_revision_opt *opt) {int i, flags, left, seen_dashdash, read_from_stdin;const char **prune_data =NULL ;
@@ -1462,7 +1462,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch revs->prune_data =get_pathspec (revs->prefix, prune_data);if (revs->def ==NULL ) - revs->def = def; + revs->def = opt ? opt->def :NULL ;if (revs->show_merge)prepare_show_merge (revs);if (revs->def && !revs->pending.nr) {
revision.h +5 -1
@@ -137,8 +137,12 @@ struct rev_info {typedef void (*show_early_output_fn_t )(struct rev_info *,struct commit_list *);extern volatile show_early_output_fn_t show_early_output; +struct setup_revision_opt { +const char *def; +}; +extern void init_revisions (struct rev_info *revs,const char *prefix); -extern int setup_revisions (int argc,const char **argv,struct rev_info *revs,const char *def); +extern int setup_revisions (int argc,const char **argv,struct rev_info *revs,struct setup_revision_opt *);extern void parse_revision_opt (struct rev_info *revs,struct parse_opt_ctx_t *ctx,const struct option *options,const char *const usagestr[]);
wt-status.c +11 -4
@@ -290,10 +290,13 @@ static void wt_status_collect_changes_worktree(struct wt_status *s)static void wt_status_collect_changes_index (struct wt_status *s) {struct rev_info rev; +struct setup_revision_opt opt;init_revisions (&rev,NULL ); -setup_revisions (0 ,NULL , &rev, - s->is_initial ?EMPTY_TREE_SHA1_HEX : s->reference); +memset (&opt,0 ,sizeof (opt)); + opt.def = s->is_initial ?EMPTY_TREE_SHA1_HEX : s->reference; +setup_revisions (0 ,NULL , &rev, &opt); + rev.diffopt.output_format |=DIFF_FORMAT_CALLBACK ; rev.diffopt.format_callback = wt_status_collect_updated_cb; rev.diffopt.format_callback_data = s;
@@ -512,11 +515,15 @@ static void wt_status_print_untracked(struct wt_status *s)static void wt_status_print_verbose (struct wt_status *s) {struct rev_info rev; +struct setup_revision_opt opt;init_revisions (&rev,NULL );DIFF_OPT_SET (&rev.diffopt,ALLOW_TEXTCONV ); -setup_revisions (0 ,NULL , &rev, - s->is_initial ?EMPTY_TREE_SHA1_HEX : s->reference); + +memset (&opt,0 ,sizeof (opt)); + opt.def = s->is_initial ?EMPTY_TREE_SHA1_HEX : s->reference; +setup_revisions (0 ,NULL , &rev, &opt); + rev.diffopt.output_format |=DIFF_FORMAT_PATCH ; rev.diffopt.detect_rename =1 ; rev.diffopt.file = s->fp;
Signature · 1 line
1.7.0.2.384.g015e
PATCH 3/4 show -c: show patch text
In reply to Junio C HamanoTraditionally, "show" defaulted to "show --cc" (dense combined patch), but asking for combined patch with "show -c" didn't turn the patch output format on; the placement of this logic in setup_revisions() dates back to cd2bdc5 (Common option parsing for "git log --diff" and friends, 2006-04-14).
This unfortunately cannot be done as a trivial change of "if dense combined is asked, default to patch format" done in setup_revisions() to "if any combined is asked, default to patch format", as "diff-tree -c" needs to default to raw, while "diff-tree --cc" needs to default to patch, and they share the codepath. These command specific defaults are now handled in the new "tweak" callback that can be customized by individual command implementations.
--- builtin-diff-tree.c | 18 ++++++++++++++---- builtin-log.c | 7 +++++++ revision.c | 7 +++---- revision.h | 1 + t/t4013-diff-various.sh | 1 + t/t4013/diff.show_-c_master | 36 ++++++++++++++++++++++++++++++++++++ 6 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 t/t4013/diff.show_-c_master
builtin-diff-tree.c +14 -4
@@ -92,12 +92,23 @@ static const char diff_tree_usage[] =" --root include the initial commit as diff against /dev/null\n" COMMON_DIFF_OPTIONS_HELP ; +static void diff_tree_tweak_rev (struct rev_info *rev,struct setup_revision_opt *opt) +{ +if (!rev->diffopt.output_format) { +if (rev->dense_combined_merges) + rev->diffopt.output_format =DIFF_FORMAT_PATCH ; +else + rev->diffopt.output_format =DIFF_FORMAT_RAW ; + } +} +int cmd_diff_tree (int argc,const char **argv,const char *prefix) {int nr_sha1;char line[1000 ];struct object *tree1, *tree2;static struct rev_info *opt = &log_tree_opt; +struct setup_revision_opt s_r_opt;int read_stdin =0 ;init_revisions (opt, prefix);
@@ -105,7 +116,9 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) opt->abbrev =0 ; opt->diff =1 ; opt->disable_stdin =1 ; - argc =setup_revisions (argc, argv, opt,NULL ); +memset (&s_r_opt,0 ,sizeof (s_r_opt)); + s_r_opt.tweak = diff_tree_tweak_rev; + argc =setup_revisions (argc, argv, opt, &s_r_opt);while (--argc >0 ) {const char *arg = *++argv;
@@ -117,9 +130,6 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)usage (diff_tree_usage); } -if (!opt->diffopt.output_format) - opt->diffopt.output_format =DIFF_FORMAT_RAW ; -/* * NOTE! We expect "a ^b" to be equal to "a..b", so we * reverse the order of the objects if the second one
builtin-log.c +7 -0
@@ -327,6 +327,12 @@ static int show_tree_object(const unsigned char *sha1,return 0 ; } +static void show_rev_tweak_rev (struct rev_info *rev,struct setup_revision_opt *opt) +{ +if (!rev->diffopt.output_format) + rev->diffopt.output_format =DIFF_FORMAT_PATCH ; +} +int cmd_show (int argc,const char **argv,const char *prefix) {struct rev_info rev;
@@ -348,6 +354,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) rev.no_walk =1 ;memset (&opt,0 ,sizeof (opt)); opt.def ="HEAD" ; + opt.tweak = show_rev_tweak_rev;cmd_log_init (argc, argv, prefix, &rev, &opt); count = rev.pending.nr;
revision.c +3 -4
@@ -1463,6 +1463,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct sif (revs->def ==NULL ) revs->def = opt ? opt->def :NULL ; +if (opt && opt->tweak) + opt->tweak (revs, opt);if (revs->show_merge)prepare_show_merge (revs);if (revs->def && !revs->pending.nr) {
@@ -1496,11 +1498,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct sif (!revs->full_diff)diff_tree_setup_paths (revs->prune_data, &revs->diffopt); } -if (revs->combine_merges) { +if (revs->combine_merges) revs->ignore_merges =0 ; -if (revs->dense_combined_merges && !revs->diffopt.output_format) - revs->diffopt.output_format =DIFF_FORMAT_PATCH ; - } revs->diffopt.abbrev = revs->abbrev;if (diff_setup_done (&revs->diffopt) <0 )die ("diff_setup_done failed" );
revision.h +1 -0
@@ -139,6 +139,7 @@ extern volatile show_early_output_fn_t show_early_output;struct setup_revision_opt {const char *def; +void (*tweak)(struct rev_info *,struct setup_revision_opt *); };extern void init_revisions (struct rev_info *revs,const char *prefix);
t/t4013-diff-various.sh +1 -0
@@ -238,6 +238,7 @@ show initial show --root initial show side show master +show -c master show --stat side show --stat --summary side show --patch-with-stat side
t/t4013/diff.show_-c_master new file +36 -0
@@ -0,0 +1,36 @@ +$ git show -c master +commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 +Merge: 9a6d494 c7a2ab9 +Author: A U Thor <[email protected]> +Date: Mon Jun 26 00:04:00 2006 +0000 + + Merge branch 'side' + +diff --combined dir/sub +index cead32e,7289e35..992913c +--- a/dir/sub ++++ b/dir/sub +@@@ -1,6 -1,4 +1,8 @@@ + A + B + +C + +D + +E + +F ++ 1 ++ 2 +diff --combined file0 +index b414108,f4615da..10a8a9f +--- a/file0 ++++ b/file0 +@@@ -1,6 -1,6 +1,9 @@@ + 1 + 2 + 3 + +4 + +5 + +6 ++ A ++ B ++ C +$
Signature · 1 line
1.7.0.2.384.g015e
PATCH 4/4 show --first-parent/-m: do not default to --cc
In reply to Junio C HamanoGiven that "git show" always shows some diff and does not walk the history by default, it is natural to expect "git show --first-parent" to show the difference between the given commit and its first parent. It also would be natural, given that "--cc" is the default, "git show -m" to show pairwise difference from each of the parents.
We however always defaulted to --cc and there was no way to turn it off.
--- builtin-log.c | 12 +++- t/t4013-diff-various.sh | 2 + t/t4013/diff.show_--first-parent_master | 30 ++++++++++ t/t4013/diff.show_-m_master | 93 +++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 t/t4013/diff.show_--first-parent_master create mode 100644 t/t4013/diff.show_-m_master
builtin-log.c +9 -3
@@ -329,6 +329,15 @@ static int show_tree_object(const unsigned char *sha1,static void show_rev_tweak_rev (struct rev_info *rev,struct setup_revision_opt *opt) { +if (rev->ignore_merges) { +/* There was no "-m" on the command line */ + rev->ignore_merges =0 ; +if (!rev->first_parent_only && !rev->combine_merges) { +/* No "--first-parent", "-c", nor "--cc" */ + rev->combine_merges =1 ; + rev->dense_combined_merges =1 ; + } + }if (!rev->diffopt.output_format) rev->diffopt.output_format =DIFF_FORMAT_PATCH ; }
@@ -347,10 +356,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)init_revisions (&rev, prefix); rev.diff =1 ; - rev.combine_merges =1 ; - rev.dense_combined_merges =1 ; rev.always_show_header =1 ; - rev.ignore_merges =0 ; rev.no_walk =1 ;memset (&opt,0 ,sizeof (opt)); opt.def ="HEAD" ;
t/t4013-diff-various.sh +2 -0
@@ -239,6 +239,8 @@ show --root initial show side show master show -c master +show -m master +show --first-parent master show --stat side show --stat --summary side show --patch-with-stat side
t/t4013/diff.show_--first-parent_master new file +30 -0
@@ -0,0 +1,30 @@ +$ git show --first-parent master +commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 +Merge: 9a6d494 c7a2ab9 +Author: A U Thor <[email protected]> +Date: Mon Jun 26 00:04:00 2006 +0000 + + Merge branch 'side' + +diff --git a/dir/sub b/dir/sub +index cead32e..992913c 100644 +--- a/dir/sub ++++ b/dir/sub +@@ -4,3 +4,5 @@ C + D + E + F ++1 ++2 +diff --git a/file0 b/file0 +index b414108..10a8a9f 100644 +--- a/file0 ++++ b/file0 +@@ -4,3 +4,6 @@ + 4 + 5 + 6 ++A ++B ++C +$
t/t4013/diff.show_-m_master new file +93 -0
93 lines not on this page · raw message
Signature · 1 line
1.7.0.2.384.g015e