Message ID | 20181106162413.9785-1-avarab@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2] range-diff: add a --no-patch option to show a summary | expand |
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > diff --git a/builtin/range-diff.c b/builtin/range-diff.c > index f01a0be851..05d1f6b6b6 100644 > --- a/builtin/range-diff.c > +++ b/builtin/range-diff.c > @@ -16,11 +16,14 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix) > int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT; > struct diff_options diffopt = { NULL }; > int simple_color = -1; > + int no_patch = 0; > struct option options[] = { > OPT_INTEGER(0, "creation-factor", &creation_factor, > N_("Percentage by which creation is weighted")), > OPT_BOOL(0, "no-dual-color", &simple_color, > N_("use simple diff colors")), > + OPT_BOOL_F('s', "no-patch", &no_patch, > + N_("show patch output"), PARSE_OPT_NONEG), As OPT_BOOL("patch") natively takes "--no-patch" to flip the bool off, an int variable "patch" that is initialized to 1 would make it more readable by avoiding double negation !no_patch like the one we see below. I guess the reason behind the contortion you wanted to give the synonym --silent to it? > @@ -92,7 +95,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix) > } > > res = show_range_diff(range1.buf, range2.buf, creation_factor, > - simple_color < 1, &diffopt); > + simple_color < 1, !no_patch, &diffopt); > strbuf_release(&range1); > strbuf_release(&range2); > @@ -7,6 +7,7 @@ > > int show_range_diff(const char *range1, const char *range2, > int creation_factor, int dual_color, > + int patch, > struct diff_options *diffopt); Other than that small "Huh?", the code looks good to me. > diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh > index 6aae364171..27e071650b 100755 > --- a/t/t3206-range-diff.sh > +++ b/t/t3206-range-diff.sh > @@ -122,6 +122,26 @@ test_expect_success 'changed commit' ' > test_cmp expected actual > ' > > +test_expect_success 'changed commit -p & --patch' ' > + git range-diff --no-color -p topic...changed >actual && > + test_cmp expected actual && > + git range-diff --no-color --patch topic...changed >actual && > + test_cmp expected actual This makes sure that -p and --patch produces the same output as the default case? I am not sure who in the parseopt API groks the single letter "-p" in this case offhand. Care to explain how? The other side of the test to see -s/--no-patch we see below also makes sense. > +test_expect_success 'changed commit -s & --no-patch' ' > +... > + cat >expected <<-EOF && Quote EOF to allow readers skim the contents without looking for and worrying about $substitutions in there, unless there are tons of offending code in the same script already in which case we should leave the clean-up outside this primary change.
Hi, On Wed, 7 Nov 2018, Junio C Hamano wrote: > Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > > > diff --git a/builtin/range-diff.c b/builtin/range-diff.c > > index f01a0be851..05d1f6b6b6 100644 > > --- a/builtin/range-diff.c > > +++ b/builtin/range-diff.c > > @@ -16,11 +16,14 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix) > > int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT; > > struct diff_options diffopt = { NULL }; > > int simple_color = -1; > > + int no_patch = 0; > > struct option options[] = { > > OPT_INTEGER(0, "creation-factor", &creation_factor, > > N_("Percentage by which creation is weighted")), > > OPT_BOOL(0, "no-dual-color", &simple_color, > > N_("use simple diff colors")), > > + OPT_BOOL_F('s', "no-patch", &no_patch, > > + N_("show patch output"), PARSE_OPT_NONEG), > > As OPT_BOOL("patch") natively takes "--no-patch" to flip the bool > off, an int variable "patch" that is initialized to 1 would make it > more readable by avoiding double negation !no_patch like the one we > see below. I guess the reason behind the contortion you wanted to > give the synonym --silent to it? In light of my investigation that revealed that the original behavior (which is still documented in the manual page of range-diff) was broken, and I would much rather see that fixed than adding a workaround. I would be fine with my patch being combined with the update to the manual page and the regression test, as a v3. Ciao, Dscho > > > @@ -92,7 +95,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix) > > } > > > > res = show_range_diff(range1.buf, range2.buf, creation_factor, > > - simple_color < 1, &diffopt); > > + simple_color < 1, !no_patch, &diffopt); > > > strbuf_release(&range1); > > strbuf_release(&range2); > > > @@ -7,6 +7,7 @@ > > > > int show_range_diff(const char *range1, const char *range2, > > int creation_factor, int dual_color, > > + int patch, > > struct diff_options *diffopt); > > Other than that small "Huh?", the code looks good to me. > > > diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh > > index 6aae364171..27e071650b 100755 > > --- a/t/t3206-range-diff.sh > > +++ b/t/t3206-range-diff.sh > > @@ -122,6 +122,26 @@ test_expect_success 'changed commit' ' > > test_cmp expected actual > > ' > > > > +test_expect_success 'changed commit -p & --patch' ' > > + git range-diff --no-color -p topic...changed >actual && > > + test_cmp expected actual && > > + git range-diff --no-color --patch topic...changed >actual && > > + test_cmp expected actual > > This makes sure that -p and --patch produces the same output as the > default case? I am not sure who in the parseopt API groks the > single letter "-p" in this case offhand. Care to explain how? > > The other side of the test to see -s/--no-patch we see below also > makes sense. > > > +test_expect_success 'changed commit -s & --no-patch' ' > > +... > > + cat >expected <<-EOF && > > Quote EOF to allow readers skim the contents without looking for and > worrying about $substitutions in there, unless there are tons of > offending code in the same script already in which case we should > leave the clean-up outside this primary change. > >
diff --git a/Documentation/git-range-diff.txt b/Documentation/git-range-diff.txt index f693930fdb..6c1eb647a1 100644 --- a/Documentation/git-range-diff.txt +++ b/Documentation/git-range-diff.txt @@ -57,6 +57,11 @@ to revert to color all lines according to the outer diff markers See the ``Algorithm`` section below for an explanation why this is needed. +-s:: +--no-patch:: + Suppress diff output. Only shows how the range has changed at + a commit-level. + <range1> <range2>:: Compare the commits specified by the two ranges, where `<range1>` is considered an older version of `<range2>`. diff --git a/builtin/log.c b/builtin/log.c index 061d4fd864..e063bcf2dd 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1096,7 +1096,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, if (rev->rdiff1) { fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title); show_range_diff(rev->rdiff1, rev->rdiff2, - rev->creation_factor, 1, &rev->diffopt); + rev->creation_factor, 1, 1, &rev->diffopt); } } diff --git a/builtin/range-diff.c b/builtin/range-diff.c index f01a0be851..05d1f6b6b6 100644 --- a/builtin/range-diff.c +++ b/builtin/range-diff.c @@ -16,11 +16,14 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix) int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT; struct diff_options diffopt = { NULL }; int simple_color = -1; + int no_patch = 0; struct option options[] = { OPT_INTEGER(0, "creation-factor", &creation_factor, N_("Percentage by which creation is weighted")), OPT_BOOL(0, "no-dual-color", &simple_color, N_("use simple diff colors")), + OPT_BOOL_F('s', "no-patch", &no_patch, + N_("show patch output"), PARSE_OPT_NONEG), OPT_END() }; int i, j, res = 0; @@ -92,7 +95,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix) } res = show_range_diff(range1.buf, range2.buf, creation_factor, - simple_color < 1, &diffopt); + simple_color < 1, !no_patch, &diffopt); strbuf_release(&range1); strbuf_release(&range2); diff --git a/log-tree.c b/log-tree.c index 7a83e99250..843e3ef83b 100644 --- a/log-tree.c +++ b/log-tree.c @@ -762,7 +762,7 @@ void show_log(struct rev_info *opt) next_commentary_block(opt, NULL); fprintf_ln(opt->diffopt.file, "%s", opt->rdiff_title); show_range_diff(opt->rdiff1, opt->rdiff2, - opt->creation_factor, 1, &opt->diffopt); + opt->creation_factor, 1, 1, &opt->diffopt); memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff)); } diff --git a/range-diff.c b/range-diff.c index bd8083f2d1..c1bfa593ce 100644 --- a/range-diff.c +++ b/range-diff.c @@ -436,6 +436,7 @@ static struct strbuf *output_prefix_cb(struct diff_options *opt, void *data) int show_range_diff(const char *range1, const char *range2, int creation_factor, int dual_color, + int patch, struct diff_options *diffopt) { int res = 0; @@ -453,7 +454,10 @@ int show_range_diff(const char *range1, const char *range2, struct strbuf indent = STRBUF_INIT; memcpy(&opts, diffopt, sizeof(opts)); - opts.output_format = DIFF_FORMAT_PATCH; + if (patch) + opts.output_format = DIFF_FORMAT_PATCH; + else + opts.output_format = DIFF_FORMAT_NO_OUTPUT; opts.flags.suppress_diff_headers = 1; opts.flags.dual_color_diffed_diffs = dual_color; opts.output_prefix = output_prefix_cb; diff --git a/range-diff.h b/range-diff.h index 190593f0c7..99bbc1cd9f 100644 --- a/range-diff.h +++ b/range-diff.h @@ -7,6 +7,7 @@ int show_range_diff(const char *range1, const char *range2, int creation_factor, int dual_color, + int patch, struct diff_options *diffopt); #endif diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh index 6aae364171..27e071650b 100755 --- a/t/t3206-range-diff.sh +++ b/t/t3206-range-diff.sh @@ -122,6 +122,26 @@ test_expect_success 'changed commit' ' test_cmp expected actual ' +test_expect_success 'changed commit -p & --patch' ' + git range-diff --no-color -p topic...changed >actual && + test_cmp expected actual && + git range-diff --no-color --patch topic...changed >actual && + test_cmp expected actual +' + +test_expect_success 'changed commit -s & --no-patch' ' + git range-diff --no-color --no-patch topic...changed >actual && + cat >expected <<-EOF && + 1: 4de457d = 1: a4b3333 s/5/A/ + 2: fccce22 = 2: f51d370 s/4/A/ + 3: 147e64e ! 3: 0559556 s/11/B/ + 4: a63e992 ! 4: d966c5c s/12/B/ + EOF + test_cmp expected actual && + git range-diff --no-color -s topic...changed >actual && + test_cmp expected actual +' + test_expect_success 'changed commit with sm config' ' git range-diff --no-color --submodule=log topic...changed >actual && cat >expected <<-EOF && @@ -151,6 +171,17 @@ test_expect_success 'changed commit with sm config' ' test_cmp expected actual ' +test_expect_success 'changed commit with sm config --no-patch' ' + git range-diff --no-color --no-patch --submodule=log topic...changed >actual && + cat >expected <<-EOF && + 1: 4de457d = 1: a4b3333 s/5/A/ + 2: fccce22 = 2: f51d370 s/4/A/ + 3: 147e64e ! 3: 0559556 s/11/B/ + 4: a63e992 ! 4: d966c5c s/12/B/ + EOF + test_cmp expected actual +' + test_expect_success 'no commits on one side' ' git commit --amend -m "new message" && git range-diff master HEAD@{1} HEAD @@ -176,6 +207,17 @@ test_expect_success 'changed message' ' test_cmp expected actual ' +test_expect_success 'changed message --no-patch' ' + git range-diff --no-color --no-patch topic...changed-message >actual && + sed s/Z/\ /g >expected <<-EOF && + 1: 4de457d = 1: f686024 s/5/A/ + 2: fccce22 ! 2: 4ab067d s/4/A/ + 3: 147e64e = 3: b9cb956 s/11/B/ + 4: a63e992 = 4: 8add5f1 s/12/B/ + EOF + test_cmp expected actual +' + test_expect_success 'dual-coloring' ' sed -e "s|^:||" >expect <<-\EOF && :<YELLOW>1: a4b3333 = 1: f686024 s/5/A/<RESET> @@ -215,6 +257,18 @@ test_expect_success 'dual-coloring' ' test_cmp expect actual ' +test_expect_success 'dual-coloring --no-patch' ' + sed -e "s|^:||" >expect <<-\EOF && + :<YELLOW>1: a4b3333 = 1: f686024 s/5/A/<RESET> + :<RED>2: f51d370 <RESET><YELLOW>!<RESET><GREEN> 2: 4ab067d<RESET><YELLOW> s/4/A/<RESET> + :<RED>3: 0559556 <RESET><YELLOW>!<RESET><GREEN> 3: b9cb956<RESET><YELLOW> s/11/B/<RESET> + :<RED>4: d966c5c <RESET><YELLOW>!<RESET><GREEN> 4: 8add5f1<RESET><YELLOW> s/12/B/<RESET> + EOF + git range-diff changed...changed-message --color --dual-color --no-patch >actual.raw && + test_decode_color >actual <actual.raw && + test_cmp expect actual +' + for prev in topic master..topic do test_expect_success "format-patch --range-diff=$prev" '