Skip to content

Commit bd36191

Browse files
Denton-Lgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9f726e1 commit bd36191

File tree

7 files changed

+72
-10
lines changed

7 files changed

+72
-10
lines changed

Documentation/git-range-diff.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ to revert to color all lines according to the outer diff markers
5757
See the ``Algorithm`` section below for an explanation why this is
5858
needed.
5959

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+
6064
<range1> <range2>::
6165
Compare the commits specified by the two ranges, where
6266
`<range1>` is considered an older version of `<range2>`.
@@ -75,7 +79,7 @@ to revert to color all lines according to the outer diff markers
7579
linkgit:git-diff[1]), most notably the `--color=[<when>]` and
7680
`--no-color` options. These options are used when generating the "diff
7781
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
7983
diff options passed to `git log` when generating those patches.
8084

8185
OUTPUT STABILITY

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
11891189
diff_setup_done(&opts);
11901190
fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title);
11911191
show_range_diff(rev->rdiff1, rev->rdiff2,
1192-
rev->creation_factor, 1, &opts);
1192+
rev->creation_factor, 1, &opts, NULL);
11931193
}
11941194
}
11951195

builtin/range-diff.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
1515
{
1616
int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT;
1717
struct diff_options diffopt = { NULL };
18+
struct argv_array other_arg = ARGV_ARRAY_INIT;
1819
int simple_color = -1;
1920
struct option range_diff_options[] = {
2021
OPT_INTEGER(0, "creation-factor", &creation_factor,
2122
N_("Percentage by which creation is weighted")),
2223
OPT_BOOL(0, "no-dual-color", &simple_color,
2324
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),
2428
OPT_END()
2529
};
2630
struct option *options;
@@ -78,7 +82,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
7882
FREE_AND_NULL(options);
7983

8084
res = show_range_diff(range1.buf, range2.buf, creation_factor,
81-
simple_color < 1, &diffopt);
85+
simple_color < 1, &diffopt, &other_arg);
8286

8387
strbuf_release(&range1);
8488
strbuf_release(&range2);

log-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ void show_log(struct rev_info *opt)
770770
opts.use_color = opt->diffopt.use_color;
771771
diff_setup_done(&opts);
772772
show_range_diff(opt->rdiff1, opt->rdiff2,
773-
opt->creation_factor, 1, &opts);
773+
opt->creation_factor, 1, &opts, NULL);
774774

775775
memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
776776
}

range-diff.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ static size_t find_end_of_line(char *buffer, unsigned long size)
4040
* Reads the patches into a string list, with the `util` field being populated
4141
* as struct object_id (will need to be free()d).
4242
*/
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)
4445
{
4546
struct child_process cp = CHILD_PROCESS_INIT;
4647
struct strbuf buf = STRBUF_INIT, contents = STRBUF_INIT;
@@ -61,8 +62,11 @@ static int read_patches(const char *range, struct string_list *list)
6162
"--output-indicator-new=>",
6263
"--output-indicator-old=<",
6364
"--output-indicator-context=#",
64-
"--no-abbrev-commit", range,
65+
"--no-abbrev-commit",
6566
NULL);
67+
if (other_arg)
68+
argv_array_pushv(&cp.args, other_arg->argv);
69+
argv_array_push(&cp.args, range);
6670
cp.out = -1;
6771
cp.no_stdin = 1;
6872
cp.git_cmd = 1;
@@ -502,16 +506,17 @@ static struct strbuf *output_prefix_cb(struct diff_options *opt, void *data)
502506

503507
int show_range_diff(const char *range1, const char *range2,
504508
int creation_factor, int dual_color,
505-
struct diff_options *diffopt)
509+
struct diff_options *diffopt,
510+
struct argv_array *other_arg)
506511
{
507512
int res = 0;
508513

509514
struct string_list branch1 = STRING_LIST_INIT_DUP;
510515
struct string_list branch2 = STRING_LIST_INIT_DUP;
511516

512-
if (read_patches(range1, &branch1))
517+
if (read_patches(range1, &branch1, other_arg))
513518
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))
515520
res = error(_("could not parse log for '%s'"), range2);
516521

517522
if (!res) {

range-diff.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define RANGE_DIFF_H
33

44
#include "diff.h"
5+
#include "argv-array.h"
56

67
#define RANGE_DIFF_CREATION_FACTOR_DEFAULT 60
78

@@ -12,6 +13,7 @@
1213
*/
1314
int show_range_diff(const char *range1, const char *range2,
1415
int creation_factor, int dual_color,
15-
struct diff_options *diffopt);
16+
struct diff_options *diffopt,
17+
struct argv_array *other_arg);
1618

1719
#endif

t/t3206-range-diff.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,53 @@ test_expect_success 'range-diff compares notes by default' '
529529
test_cmp expect actual
530530
'
531531

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+
532579
test_expect_success 'format-patch --range-diff compares notes by default' '
533580
git notes add -m "topic note" topic &&
534581
git notes add -m "unmodified note" unmodified &&

0 commit comments

Comments
 (0)