range-diff: pass through --notes to `git log`
When a commit being range-diff'd has a note attached to it, the note will be compared as well. However, if a user has multiple notes refs or if they want to suppress notes from being printed, there is currently no way to do this. Pass through `--[no-]notes[=<ref>]` to the `git log` call so that this option is customizable. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Denton Liu committed
Nov 20, 2019 at 13:18 UTC
bd361918868284c06a438b832dbc95e11266fd5b
7 files changed
+72
-10
Documentation/git-range-diff.txt
+5
-1
@@ -57,6 +57,10 @@ to revert to color all lines according to the outer diff markers
57
See the ``Algorithm`` section below for an explanation why this is
58
needed.
59
60
+--[no-]notes[=<ref>]::
61
+ This flag is passed to the `git log` program
62
+ (see linkgit:git-log[1]) that generates the patches.
63
+
64
<range1> <range2>::
65
Compare the commits specified by the two ranges, where
66
`<range1>` is considered an older version of `<range2>`.
@@ -75,7 +79,7 @@ to revert to color all lines according to the outer diff markers
79
linkgit:git-diff[1]), most notably the `--color=[<when>]` and
80
`--no-color` options. These options are used when generating the "diff
81
between patches", i.e. to compare the author, commit message and diff of
78
-corresponding old/new commits. There is currently no means to tweak the
82
+corresponding old/new commits. There is currently no means to tweak most of the
83
diff options passed to `git log` when generating those patches.
84
85
OUTPUT STABILITY
builtin/log.c
+1
-1
@@ -1189,7 +1189,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
1189
diff_setup_done(&opts);
1190
fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title);
1191
show_range_diff(rev->rdiff1, rev->rdiff2,
1192
- rev->creation_factor, 1, &opts);
1192
+ rev->creation_factor, 1, &opts, NULL);
1193
}
1194
}
1195
builtin/range-diff.c
+5
-1
@@ -15,12 +15,16 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
15
{
16
int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT;
17
struct diff_options diffopt = { NULL };
18
+ struct argv_array other_arg = ARGV_ARRAY_INIT;
19
int simple_color = -1;
20
struct option range_diff_options[] = {
21
OPT_INTEGER(0, "creation-factor", &creation_factor,
22
N_("Percentage by which creation is weighted")),
23
OPT_BOOL(0, "no-dual-color", &simple_color,
24
N_("use simple diff colors")),
25
+ OPT_PASSTHRU_ARGV(0, "notes", &other_arg,
26
+ N_("notes"), N_("passed to 'git log'"),
27
+ PARSE_OPT_OPTARG),
28
OPT_END()
29
};
30
struct option *options;
@@ -78,7 +82,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
82
FREE_AND_NULL(options);
83
84
res = show_range_diff(range1.buf, range2.buf, creation_factor,
81
- simple_color < 1, &diffopt);
85
+ simple_color < 1, &diffopt, &other_arg);
86
87
strbuf_release(&range1);
88
strbuf_release(&range2);
log-tree.c
+1
-1
@@ -770,7 +770,7 @@ void show_log(struct rev_info *opt)
770
opts.use_color = opt->diffopt.use_color;
771
diff_setup_done(&opts);
772
show_range_diff(opt->rdiff1, opt->rdiff2,
773
- opt->creation_factor, 1, &opts);
773
+ opt->creation_factor, 1, &opts, NULL);
774
775
memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
776
}
range-diff.c
+10
-5
@@ -40,7 +40,8 @@ static size_t find_end_of_line(char *buffer, unsigned long size)
40
* Reads the patches into a string list, with the `util` field being populated
41
* as struct object_id (will need to be free()d).
42
*/
43
-static int read_patches(const char *range, struct string_list *list)
43
+static int read_patches(const char *range, struct string_list *list,
44
+ struct argv_array *other_arg)
45
{
46
struct child_process cp = CHILD_PROCESS_INIT;
47
struct strbuf buf = STRBUF_INIT, contents = STRBUF_INIT;
@@ -61,8 +62,11 @@ static int read_patches(const char *range, struct string_list *list)
62
"--output-indicator-new=>",
63
"--output-indicator-old=<",
64
"--output-indicator-context=#",
64
- "--no-abbrev-commit", range,
65
+ "--no-abbrev-commit",
66
NULL);
67
+ if (other_arg)
68
+ argv_array_pushv(&cp.args, other_arg->argv);
69
+ argv_array_push(&cp.args, range);
70
cp.out = -1;
71
cp.no_stdin = 1;
72
cp.git_cmd = 1;
@@ -502,16 +506,17 @@ static struct strbuf *output_prefix_cb(struct diff_options *opt, void *data)
506
507
int show_range_diff(const char *range1, const char *range2,
508
int creation_factor, int dual_color,
505
- struct diff_options *diffopt)
509
+ struct diff_options *diffopt,
510
+ struct argv_array *other_arg)
511
{
512
int res = 0;
513
514
struct string_list branch1 = STRING_LIST_INIT_DUP;
515
struct string_list branch2 = STRING_LIST_INIT_DUP;
516
512
- if (read_patches(range1, &branch1))
517
+ if (read_patches(range1, &branch1, other_arg))
518
res = error(_("could not parse log for '%s'"), range1);
514
- if (!res && read_patches(range2, &branch2))
519
+ if (!res && read_patches(range2, &branch2, other_arg))
520
res = error(_("could not parse log for '%s'"), range2);
521
522
if (!res) {
range-diff.h
+3
-1
@@ -2,6 +2,7 @@
2
#define RANGE_DIFF_H
3
4
#include "diff.h"
5
+#include "argv-array.h"
6
7
#define RANGE_DIFF_CREATION_FACTOR_DEFAULT 60
8
@@ -12,6 +13,7 @@
13
*/
14
int show_range_diff(const char *range1, const char *range2,
15
int creation_factor, int dual_color,
15
- struct diff_options *diffopt);
16
+ struct diff_options *diffopt,
17
+ struct argv_array *other_arg);
18
19
#endif
t/t3206-range-diff.sh
+47
@@ -529,6 +529,53 @@ test_expect_success 'range-diff compares notes by default' '
529
test_cmp expect actual
530
'
531
532
+test_expect_success 'range-diff with --no-notes' '
533
+ git notes add -m "topic note" topic &&
534
+ git notes add -m "unmodified note" unmodified &&
535
+ test_when_finished git notes remove topic unmodified &&
536
+ git range-diff --no-color --no-notes master..topic master..unmodified \
537
+ >actual &&
538
+ cat >expect <<-EOF &&
539
+ 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
540
+ 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
541
+ 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
542
+ 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
543
+ EOF
544
+ test_cmp expect actual
545
+'
546
+
547
+test_expect_success 'range-diff with multiple --notes' '
548
+ git notes --ref=note1 add -m "topic note1" topic &&
549
+ git notes --ref=note1 add -m "unmodified note1" unmodified &&
550
+ test_when_finished git notes --ref=note1 remove topic unmodified &&
551
+ git notes --ref=note2 add -m "topic note2" topic &&
552
+ git notes --ref=note2 add -m "unmodified note2" unmodified &&
553
+ test_when_finished git notes --ref=note2 remove topic unmodified &&
554
+ git range-diff --no-color --notes=note1 --notes=note2 master..topic master..unmodified \
555
+ >actual &&
556
+ sed s/Z/\ /g >expect <<-EOF &&
557
+ 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
558
+ 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
559
+ 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
560
+ 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
561
+ @@ Commit message
562
+ Z
563
+ Z
564
+ Z ## Notes (note1) ##
565
+ - topic note1
566
+ + unmodified note1
567
+ Z
568
+ Z
569
+ Z ## Notes (note2) ##
570
+ - topic note2
571
+ + unmodified note2
572
+ Z
573
+ Z ## file ##
574
+ Z@@ file: A
575
+ EOF
576
+ test_cmp expect actual
577
+'
578
+
579
test_expect_success 'format-patch --range-diff compares notes by default' '
580
git notes add -m "topic note" topic &&
581
git notes add -m "unmodified note" unmodified &&