]> git.ipfire.org Git - thirdparty/git.git/commitdiff
range-diff: pass through --notes to `git log`
authorDenton Liu <liu.denton@gmail.com>
Wed, 20 Nov 2019 21:18:45 +0000 (13:18 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 Nov 2019 00:29:52 +0000 (09:29 +0900)
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>
Documentation/git-range-diff.txt
builtin/log.c
builtin/range-diff.c
log-tree.c
range-diff.c
range-diff.h
t/t3206-range-diff.sh

index 8a6ea2c6c5c7a39a9f34d6b93388f3343c1e3026..a2c25f44909d5c3cf2e69023fe578f2d93e6104b 100644 (file)
@@ -57,6 +57,10 @@ to revert to color all lines according to the outer diff markers
        See the ``Algorithm`` section below for an explanation why this is
        needed.
 
+--[no-]notes[=<ref>]::
+       This flag is passed to the `git log` program
+       (see linkgit:git-log[1]) that generates the patches.
+
 <range1> <range2>::
        Compare the commits specified by the two ranges, where
        `<range1>` is considered an older version of `<range2>`.
@@ -75,7 +79,7 @@ to revert to color all lines according to the outer diff markers
 linkgit:git-diff[1]), most notably the `--color=[<when>]` and
 `--no-color` options. These options are used when generating the "diff
 between patches", i.e. to compare the author, commit message and diff of
-corresponding old/new commits. There is currently no means to tweak the
+corresponding old/new commits. There is currently no means to tweak most of the
 diff options passed to `git log` when generating those patches.
 
 OUTPUT STABILITY
index a26f223ab4ad9ae8cfe9405fb5ff62dd48509775..047ac4594dbcddbb408273149f75fae72048da18 100644 (file)
@@ -1189,7 +1189,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
                diff_setup_done(&opts);
                fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title);
                show_range_diff(rev->rdiff1, rev->rdiff2,
-                               rev->creation_factor, 1, &opts);
+                               rev->creation_factor, 1, &opts, NULL);
        }
 }
 
index 9202e75544761f274d3e360a3dc609fff294d0bb..98acf3533e118ca934f9004666a58371a2347c7d 100644 (file)
@@ -15,12 +15,16 @@ 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 };
+       struct argv_array other_arg = ARGV_ARRAY_INIT;
        int simple_color = -1;
        struct option range_diff_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_PASSTHRU_ARGV(0, "notes", &other_arg,
+                                 N_("notes"), N_("passed to 'git log'"),
+                                 PARSE_OPT_OPTARG),
                OPT_END()
        };
        struct option *options;
@@ -78,7 +82,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
        FREE_AND_NULL(options);
 
        res = show_range_diff(range1.buf, range2.buf, creation_factor,
-                             simple_color < 1, &diffopt);
+                             simple_color < 1, &diffopt, &other_arg);
 
        strbuf_release(&range1);
        strbuf_release(&range2);
index 923a299e704afe672b93aaa2d17f8c37d9c6a0fa..151e12f41578b1e30d2de825528beda6627d66a9 100644 (file)
@@ -770,7 +770,7 @@ void show_log(struct rev_info *opt)
                opts.use_color = opt->diffopt.use_color;
                diff_setup_done(&opts);
                show_range_diff(opt->rdiff1, opt->rdiff2,
-                               opt->creation_factor, 1, &opts);
+                               opt->creation_factor, 1, &opts, NULL);
 
                memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
        }
index 623397221daf47660073712f56b7e10b37b4e485..f56b4012a284831bd2edefeed141ca8717d219b6 100644 (file)
@@ -40,7 +40,8 @@ static size_t find_end_of_line(char *buffer, unsigned long size)
  * Reads the patches into a string list, with the `util` field being populated
  * as struct object_id (will need to be free()d).
  */
-static int read_patches(const char *range, struct string_list *list)
+static int read_patches(const char *range, struct string_list *list,
+                       struct argv_array *other_arg)
 {
        struct child_process cp = CHILD_PROCESS_INIT;
        struct strbuf buf = STRBUF_INIT, contents = STRBUF_INIT;
@@ -61,8 +62,11 @@ static int read_patches(const char *range, struct string_list *list)
                        "--output-indicator-new=>",
                        "--output-indicator-old=<",
                        "--output-indicator-context=#",
-                       "--no-abbrev-commit", range,
+                       "--no-abbrev-commit",
                        NULL);
+       if (other_arg)
+               argv_array_pushv(&cp.args, other_arg->argv);
+       argv_array_push(&cp.args, range);
        cp.out = -1;
        cp.no_stdin = 1;
        cp.git_cmd = 1;
@@ -502,16 +506,17 @@ 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,
-                   struct diff_options *diffopt)
+                   struct diff_options *diffopt,
+                   struct argv_array *other_arg)
 {
        int res = 0;
 
        struct string_list branch1 = STRING_LIST_INIT_DUP;
        struct string_list branch2 = STRING_LIST_INIT_DUP;
 
-       if (read_patches(range1, &branch1))
+       if (read_patches(range1, &branch1, other_arg))
                res = error(_("could not parse log for '%s'"), range1);
-       if (!res && read_patches(range2, &branch2))
+       if (!res && read_patches(range2, &branch2, other_arg))
                res = error(_("could not parse log for '%s'"), range2);
 
        if (!res) {
index 08a50b6e98fc768f42e48b33c70ffbf17a7e8e4c..7d918ab9edcb7206e9a984d934af6f011b631a1b 100644 (file)
@@ -2,6 +2,7 @@
 #define RANGE_DIFF_H
 
 #include "diff.h"
+#include "argv-array.h"
 
 #define RANGE_DIFF_CREATION_FACTOR_DEFAULT 60
 
@@ -12,6 +13,7 @@
  */
 int show_range_diff(const char *range1, const char *range2,
                    int creation_factor, int dual_color,
-                   struct diff_options *diffopt);
+                   struct diff_options *diffopt,
+                   struct argv_array *other_arg);
 
 #endif
index b936c16dd1b2bf1b8684d79e9a4d002d1d98c3fe..521b4a83ecbe5de5ac1a89fd9ea3929395b2d76e 100755 (executable)
@@ -529,6 +529,53 @@ test_expect_success 'range-diff compares notes by default' '
        test_cmp expect actual
 '
 
+test_expect_success 'range-diff with --no-notes' '
+       git notes add -m "topic note" topic &&
+       git notes add -m "unmodified note" unmodified &&
+       test_when_finished git notes remove topic unmodified &&
+       git range-diff --no-color --no-notes master..topic master..unmodified \
+               >actual &&
+       cat >expect <<-EOF &&
+       1:  $(test_oid t1) = 1:  $(test_oid u1) s/5/A/
+       2:  $(test_oid t2) = 2:  $(test_oid u2) s/4/A/
+       3:  $(test_oid t3) = 3:  $(test_oid u3) s/11/B/
+       4:  $(test_oid t4) = 4:  $(test_oid u4) s/12/B/
+       EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'range-diff with multiple --notes' '
+       git notes --ref=note1 add -m "topic note1" topic &&
+       git notes --ref=note1 add -m "unmodified note1" unmodified &&
+       test_when_finished git notes --ref=note1 remove topic unmodified &&
+       git notes --ref=note2 add -m "topic note2" topic &&
+       git notes --ref=note2 add -m "unmodified note2" unmodified &&
+       test_when_finished git notes --ref=note2 remove topic unmodified &&
+       git range-diff --no-color --notes=note1 --notes=note2 master..topic master..unmodified \
+               >actual &&
+       sed s/Z/\ /g >expect <<-EOF &&
+       1:  $(test_oid t1) = 1:  $(test_oid u1) s/5/A/
+       2:  $(test_oid t2) = 2:  $(test_oid u2) s/4/A/
+       3:  $(test_oid t3) = 3:  $(test_oid u3) s/11/B/
+       4:  $(test_oid t4) ! 4:  $(test_oid u4) s/12/B/
+           @@ Commit message
+           Z
+           Z
+           Z ## Notes (note1) ##
+           -    topic note1
+           +    unmodified note1
+           Z
+           Z
+           Z ## Notes (note2) ##
+           -    topic note2
+           +    unmodified note2
+           Z
+           Z ## file ##
+           Z@@ file: A
+       EOF
+       test_cmp expect actual
+'
+
 test_expect_success 'format-patch --range-diff compares notes by default' '
        git notes add -m "topic note" topic &&
        git notes add -m "unmodified note" unmodified &&