2018-08-13 13:33:02 +02:00
|
|
|
#include "cache.h"
|
|
|
|
#include "builtin.h"
|
|
|
|
#include "parse-options.h"
|
2018-08-13 13:33:04 +02:00
|
|
|
#include "range-diff.h"
|
range-diff: also show the diff between patches
Just like tbdiff, we now show the diff between matching patches. This is
a "diff of two diffs", so it can be a bit daunting to read for the
beginner.
An alternative would be to display an interdiff, i.e. the hypothetical
diff which is the result of first reverting the old diff and then
applying the new diff.
Especially when rebasing frequently, an interdiff is often not feasible,
though: if the old diff cannot be applied in reverse (due to a moving
upstream), an interdiff can simply not be inferred.
This commit brings `range-diff` closer to feature parity with regard
to tbdiff.
To make `git range-diff` respect e.g. color.diff.* settings, we have
to adjust git_branch_config() accordingly.
Note: while we now parse diff options such as --color, the effect is not
yet the same as in tbdiff, where also the commit pairs would be colored.
This is left for a later commit.
Note also: while tbdiff accepts the `--no-patches` option to suppress
these diffs between patches, we prefer the `-s` (or `--no-patch`) option
that is automatically supported via our use of diff_opt_parse().
And finally note: to support diff options, we have to call
`parse_options()` such that it keeps unknown options, and then loop over
those and let `diff_opt_parse()` handle them. After that loop, we have
to call `parse_options()` again, to make sure that no unknown options
are left.
Helped-by: Thomas Gummerer <t.gummerer@gmail.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-13 13:33:07 +02:00
|
|
|
#include "config.h"
|
2021-01-27 17:37:22 +01:00
|
|
|
#include "revision.h"
|
2018-08-13 13:33:02 +02:00
|
|
|
|
|
|
|
static const char * const builtin_range_diff_usage[] = {
|
|
|
|
N_("git range-diff [<options>] <old-base>..<old-tip> <new-base>..<new-tip>"),
|
|
|
|
N_("git range-diff [<options>] <old-tip>...<new-tip>"),
|
|
|
|
N_("git range-diff [<options>] <base> <old-tip> <new-tip>"),
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
int cmd_range_diff(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
range-diff: also show the diff between patches
Just like tbdiff, we now show the diff between matching patches. This is
a "diff of two diffs", so it can be a bit daunting to read for the
beginner.
An alternative would be to display an interdiff, i.e. the hypothetical
diff which is the result of first reverting the old diff and then
applying the new diff.
Especially when rebasing frequently, an interdiff is often not feasible,
though: if the old diff cannot be applied in reverse (due to a moving
upstream), an interdiff can simply not be inferred.
This commit brings `range-diff` closer to feature parity with regard
to tbdiff.
To make `git range-diff` respect e.g. color.diff.* settings, we have
to adjust git_branch_config() accordingly.
Note: while we now parse diff options such as --color, the effect is not
yet the same as in tbdiff, where also the commit pairs would be colored.
This is left for a later commit.
Note also: while tbdiff accepts the `--no-patches` option to suppress
these diffs between patches, we prefer the `-s` (or `--no-patch`) option
that is automatically supported via our use of diff_opt_parse().
And finally note: to support diff options, we have to call
`parse_options()` such that it keeps unknown options, and then loop over
those and let `diff_opt_parse()` handle them. After that loop, we have
to call `parse_options()` again, to make sure that no unknown options
are left.
Helped-by: Thomas Gummerer <t.gummerer@gmail.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-13 13:33:07 +02:00
|
|
|
struct diff_options diffopt = { NULL };
|
2020-07-28 22:24:27 +02:00
|
|
|
struct strvec other_arg = STRVEC_INIT;
|
2021-02-05 15:46:11 +01:00
|
|
|
struct range_diff_options range_diff_opts = {
|
|
|
|
.creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT,
|
|
|
|
.diffopt = &diffopt,
|
|
|
|
.other_arg = &other_arg
|
|
|
|
};
|
2021-02-05 15:46:13 +01:00
|
|
|
int simple_color = -1, left_only = 0, right_only = 0;
|
2019-03-24 09:20:12 +01:00
|
|
|
struct option range_diff_options[] = {
|
2021-02-05 15:46:11 +01:00
|
|
|
OPT_INTEGER(0, "creation-factor",
|
|
|
|
&range_diff_opts.creation_factor,
|
2021-03-29 16:46:34 +02:00
|
|
|
N_("percentage by which creation is weighted")),
|
2018-08-13 13:33:30 +02:00
|
|
|
OPT_BOOL(0, "no-dual-color", &simple_color,
|
2018-08-23 23:57:48 +02:00
|
|
|
N_("use simple diff colors")),
|
2019-11-20 22:18:45 +01:00
|
|
|
OPT_PASSTHRU_ARGV(0, "notes", &other_arg,
|
|
|
|
N_("notes"), N_("passed to 'git log'"),
|
|
|
|
PARSE_OPT_OPTARG),
|
2021-02-05 15:46:13 +01:00
|
|
|
OPT_BOOL(0, "left-only", &left_only,
|
|
|
|
N_("only emit output related to the first range")),
|
|
|
|
OPT_BOOL(0, "right-only", &right_only,
|
|
|
|
N_("only emit output related to the second range")),
|
2018-08-13 13:33:02 +02:00
|
|
|
OPT_END()
|
|
|
|
};
|
2019-03-24 09:20:12 +01:00
|
|
|
struct option *options;
|
2022-08-26 11:39:30 +02:00
|
|
|
int i, dash_dash = -1, res = 0;
|
2018-08-13 13:33:04 +02:00
|
|
|
struct strbuf range1 = STRBUF_INIT, range2 = STRBUF_INIT;
|
2022-08-26 11:39:29 +02:00
|
|
|
struct object_id oid;
|
2022-08-26 11:39:30 +02:00
|
|
|
const char *three_dots = NULL;
|
2018-08-13 13:33:02 +02:00
|
|
|
|
range-diff: also show the diff between patches
Just like tbdiff, we now show the diff between matching patches. This is
a "diff of two diffs", so it can be a bit daunting to read for the
beginner.
An alternative would be to display an interdiff, i.e. the hypothetical
diff which is the result of first reverting the old diff and then
applying the new diff.
Especially when rebasing frequently, an interdiff is often not feasible,
though: if the old diff cannot be applied in reverse (due to a moving
upstream), an interdiff can simply not be inferred.
This commit brings `range-diff` closer to feature parity with regard
to tbdiff.
To make `git range-diff` respect e.g. color.diff.* settings, we have
to adjust git_branch_config() accordingly.
Note: while we now parse diff options such as --color, the effect is not
yet the same as in tbdiff, where also the commit pairs would be colored.
This is left for a later commit.
Note also: while tbdiff accepts the `--no-patches` option to suppress
these diffs between patches, we prefer the `-s` (or `--no-patch`) option
that is automatically supported via our use of diff_opt_parse().
And finally note: to support diff options, we have to call
`parse_options()` such that it keeps unknown options, and then loop over
those and let `diff_opt_parse()` handle them. After that loop, we have
to call `parse_options()` again, to make sure that no unknown options
are left.
Helped-by: Thomas Gummerer <t.gummerer@gmail.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-13 13:33:07 +02:00
|
|
|
git_config(git_diff_ui_config, NULL);
|
|
|
|
|
2018-09-21 17:57:24 +02:00
|
|
|
repo_diff_setup(the_repository, &diffopt);
|
range-diff: also show the diff between patches
Just like tbdiff, we now show the diff between matching patches. This is
a "diff of two diffs", so it can be a bit daunting to read for the
beginner.
An alternative would be to display an interdiff, i.e. the hypothetical
diff which is the result of first reverting the old diff and then
applying the new diff.
Especially when rebasing frequently, an interdiff is often not feasible,
though: if the old diff cannot be applied in reverse (due to a moving
upstream), an interdiff can simply not be inferred.
This commit brings `range-diff` closer to feature parity with regard
to tbdiff.
To make `git range-diff` respect e.g. color.diff.* settings, we have
to adjust git_branch_config() accordingly.
Note: while we now parse diff options such as --color, the effect is not
yet the same as in tbdiff, where also the commit pairs would be colored.
This is left for a later commit.
Note also: while tbdiff accepts the `--no-patches` option to suppress
these diffs between patches, we prefer the `-s` (or `--no-patch`) option
that is automatically supported via our use of diff_opt_parse().
And finally note: to support diff options, we have to call
`parse_options()` such that it keeps unknown options, and then loop over
those and let `diff_opt_parse()` handle them. After that loop, we have
to call `parse_options()` again, to make sure that no unknown options
are left.
Helped-by: Thomas Gummerer <t.gummerer@gmail.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-13 13:33:07 +02:00
|
|
|
|
2019-03-24 09:20:12 +01:00
|
|
|
options = parse_options_concat(range_diff_options, diffopt.parseopts);
|
2019-05-09 23:28:51 +02:00
|
|
|
argc = parse_options(argc, argv, prefix, options,
|
2022-08-26 11:39:30 +02:00
|
|
|
builtin_range_diff_usage, PARSE_OPT_KEEP_DASHDASH);
|
range-diff: also show the diff between patches
Just like tbdiff, we now show the diff between matching patches. This is
a "diff of two diffs", so it can be a bit daunting to read for the
beginner.
An alternative would be to display an interdiff, i.e. the hypothetical
diff which is the result of first reverting the old diff and then
applying the new diff.
Especially when rebasing frequently, an interdiff is often not feasible,
though: if the old diff cannot be applied in reverse (due to a moving
upstream), an interdiff can simply not be inferred.
This commit brings `range-diff` closer to feature parity with regard
to tbdiff.
To make `git range-diff` respect e.g. color.diff.* settings, we have
to adjust git_branch_config() accordingly.
Note: while we now parse diff options such as --color, the effect is not
yet the same as in tbdiff, where also the commit pairs would be colored.
This is left for a later commit.
Note also: while tbdiff accepts the `--no-patches` option to suppress
these diffs between patches, we prefer the `-s` (or `--no-patch`) option
that is automatically supported via our use of diff_opt_parse().
And finally note: to support diff options, we have to call
`parse_options()` such that it keeps unknown options, and then loop over
those and let `diff_opt_parse()` handle them. After that loop, we have
to call `parse_options()` again, to make sure that no unknown options
are left.
Helped-by: Thomas Gummerer <t.gummerer@gmail.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-13 13:33:07 +02:00
|
|
|
|
|
|
|
diff_setup_done(&diffopt);
|
|
|
|
|
2018-07-22 11:57:12 +02:00
|
|
|
/* force color when --dual-color was used */
|
|
|
|
if (!simple_color)
|
|
|
|
diffopt.use_color = 1;
|
2018-08-13 13:33:22 +02:00
|
|
|
|
2022-08-26 11:39:30 +02:00
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
if (!strcmp(argv[i], "--")) {
|
|
|
|
dash_dash = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dash_dash == 3 ||
|
|
|
|
(dash_dash < 0 && argc > 2 &&
|
|
|
|
!get_oid_committish(argv[0], &oid) &&
|
|
|
|
!get_oid_committish(argv[1], &oid) &&
|
|
|
|
!get_oid_committish(argv[2], &oid))) {
|
|
|
|
if (dash_dash < 0)
|
|
|
|
; /* already validated arguments */
|
|
|
|
else if (get_oid_committish(argv[0], &oid))
|
2022-08-26 11:39:29 +02:00
|
|
|
usage_msg_optf(_("not a revision: '%s'"),
|
|
|
|
builtin_range_diff_usage, options,
|
|
|
|
argv[0]);
|
|
|
|
else if (get_oid_committish(argv[1], &oid))
|
|
|
|
usage_msg_optf(_("not a revision: '%s'"),
|
|
|
|
builtin_range_diff_usage, options,
|
|
|
|
argv[1]);
|
|
|
|
else if (get_oid_committish(argv[2], &oid))
|
|
|
|
usage_msg_optf(_("not a revision: '%s'"),
|
|
|
|
builtin_range_diff_usage, options,
|
|
|
|
argv[2]);
|
|
|
|
|
range-diff: reorder argument handling
In d9c66f0b5bf (range-diff: first rudimentary implementation,
2018-08-13), we introduced the argument handling of the `range-diff`
command, special-casing three different stanzas based on the argument
count.
The somewhat unorthodox order (first handling the case of 2 arguments,
then 3, then 1) was chosen for clarity: the natural argument number is 2
because that is how many revision ranges are used internally. The code
to handle three arguments is relatively trivial, so it was added next.
And finally, the code to ungarble a single symmetric range into two
separate ones was added, because it was the most complicated (the most
inelegant part being about interpreting empty sides of the symmetric
range as `HEAD`).
In preparation for allowing pathspecs in `git range-diff` invocations,
where we no longer have the luxury of using the number of arguments to
disambiguate between these three different ways to specify the commit
ranges, we need to order these cases by argument count, in descending
order.
This patch is best viewed with `--color-moved`.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-26 11:39:28 +02:00
|
|
|
strbuf_addf(&range1, "%s..%s", argv[0], argv[1]);
|
|
|
|
strbuf_addf(&range2, "%s..%s", argv[0], argv[2]);
|
2022-08-26 11:39:30 +02:00
|
|
|
|
|
|
|
strvec_pushv(&other_arg, argv +
|
|
|
|
(dash_dash < 0 ? 3 : dash_dash));
|
|
|
|
} else if (dash_dash == 2 ||
|
|
|
|
(dash_dash < 0 && argc > 1 &&
|
|
|
|
is_range_diff_range(argv[0]) &&
|
|
|
|
is_range_diff_range(argv[1]))) {
|
|
|
|
if (dash_dash < 0)
|
|
|
|
; /* already validated arguments */
|
|
|
|
else if (!is_range_diff_range(argv[0]))
|
2022-08-26 11:39:29 +02:00
|
|
|
usage_msg_optf(_("not a commit range: '%s'"),
|
|
|
|
builtin_range_diff_usage, options,
|
|
|
|
argv[0]);
|
|
|
|
else if (!is_range_diff_range(argv[1]))
|
|
|
|
usage_msg_optf(_("not a commit range: '%s'"),
|
|
|
|
builtin_range_diff_usage, options,
|
|
|
|
argv[1]);
|
2018-08-13 13:33:04 +02:00
|
|
|
|
2022-08-26 11:39:29 +02:00
|
|
|
strbuf_addstr(&range1, argv[0]);
|
2018-08-13 13:33:04 +02:00
|
|
|
strbuf_addstr(&range2, argv[1]);
|
2022-08-26 11:39:30 +02:00
|
|
|
|
|
|
|
strvec_pushv(&other_arg, argv +
|
|
|
|
(dash_dash < 0 ? 2 : dash_dash));
|
|
|
|
} else if (dash_dash == 1 ||
|
|
|
|
(dash_dash < 0 && argc > 0 &&
|
|
|
|
(three_dots = strstr(argv[0], "...")))) {
|
|
|
|
const char *a, *b;
|
2018-08-13 13:33:04 +02:00
|
|
|
int a_len;
|
|
|
|
|
2022-08-26 11:39:30 +02:00
|
|
|
if (dash_dash < 0)
|
|
|
|
; /* already validated arguments */
|
|
|
|
else if (!(three_dots = strstr(argv[0], "...")))
|
2022-08-26 11:39:29 +02:00
|
|
|
usage_msg_optf(_("not a symmetric range: '%s'"),
|
2022-08-26 11:39:30 +02:00
|
|
|
builtin_range_diff_usage, options,
|
|
|
|
argv[0]);
|
2018-08-13 13:33:04 +02:00
|
|
|
|
2022-08-26 11:39:30 +02:00
|
|
|
if (three_dots == argv[0]) {
|
2018-08-13 13:33:04 +02:00
|
|
|
a = "HEAD";
|
|
|
|
a_len = strlen(a);
|
2022-08-26 11:39:30 +02:00
|
|
|
} else {
|
|
|
|
a = argv[0];
|
|
|
|
a_len = (int)(three_dots - a);
|
2018-08-13 13:33:04 +02:00
|
|
|
}
|
2022-08-26 11:39:30 +02:00
|
|
|
|
|
|
|
if (three_dots[3])
|
|
|
|
b = three_dots + 3;
|
|
|
|
else
|
2018-08-13 13:33:04 +02:00
|
|
|
b = "HEAD";
|
2022-08-26 11:39:30 +02:00
|
|
|
|
2018-08-13 13:33:04 +02:00
|
|
|
strbuf_addf(&range1, "%s..%.*s", b, a_len, a);
|
|
|
|
strbuf_addf(&range2, "%.*s..%s", a_len, a, b);
|
2022-08-26 11:39:30 +02:00
|
|
|
|
|
|
|
strvec_pushv(&other_arg, argv +
|
|
|
|
(dash_dash < 0 ? 1 : dash_dash));
|
2022-08-26 11:39:29 +02:00
|
|
|
} else
|
|
|
|
usage_msg_opt(_("need two commit ranges"),
|
|
|
|
builtin_range_diff_usage, options);
|
2019-03-24 09:20:12 +01:00
|
|
|
FREE_AND_NULL(options);
|
2018-08-13 13:33:04 +02:00
|
|
|
|
2021-02-05 15:46:11 +01:00
|
|
|
range_diff_opts.dual_color = simple_color < 1;
|
2021-02-05 15:46:13 +01:00
|
|
|
range_diff_opts.left_only = left_only;
|
|
|
|
range_diff_opts.right_only = right_only;
|
2021-02-05 15:46:11 +01:00
|
|
|
res = show_range_diff(range1.buf, range2.buf, &range_diff_opts);
|
2018-08-13 13:33:04 +02:00
|
|
|
|
2020-07-28 22:24:27 +02:00
|
|
|
strvec_clear(&other_arg);
|
2018-08-13 13:33:04 +02:00
|
|
|
strbuf_release(&range1);
|
|
|
|
strbuf_release(&range2);
|
|
|
|
|
|
|
|
return res;
|
2018-08-13 13:33:02 +02:00
|
|
|
}
|