Skip to content

Commit ac9ecc8

Browse files
committed
WIP range-diff: offer to diff also merge commits
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent fe86abd commit ac9ecc8

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

builtin/range-diff.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
1818
{
1919
struct diff_options diffopt = { NULL };
2020
struct strvec other_arg = STRVEC_INIT;
21+
struct strvec diff_merges_arg = STRVEC_INIT;
2122
struct range_diff_options range_diff_opts = {
2223
.creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT,
2324
.diffopt = &diffopt,
@@ -33,6 +34,9 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
3334
OPT_PASSTHRU_ARGV(0, "notes", &other_arg,
3435
N_("notes"), N_("passed to 'git log'"),
3536
PARSE_OPT_OPTARG),
37+
OPT_PASSTHRU_ARGV(0, "diff-merges", &diff_merges_arg,
38+
N_("style"), N_("passed to 'git log'"),
39+
PARSE_OPT_OPTARG),
3640
OPT_BOOL(0, "left-only", &left_only,
3741
N_("only emit output related to the first range")),
3842
OPT_BOOL(0, "right-only", &right_only,
@@ -59,6 +63,12 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
5963
if (!simple_color)
6064
diffopt.use_color = 1;
6165

66+
/* If `--diff-merges` was specified, imply `--merges` */
67+
if (diff_merges_arg.nr) {
68+
range_diff_opts.include_merges = 1;
69+
strvec_pushv(&other_arg, diff_merges_arg.v);
70+
}
71+
6272
for (i = 0; i < argc; i++)
6373
if (!strcmp(argv[i], "--")) {
6474
dash_dash = i;
@@ -152,6 +162,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
152162
res = show_range_diff(range1.buf, range2.buf, &range_diff_opts);
153163

154164
strvec_clear(&other_arg);
165+
strvec_clear(&diff_merges_arg);
155166
strbuf_release(&range1);
156167
strbuf_release(&range2);
157168

range-diff.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ struct patch_util {
3535
* as struct object_id (will need to be free()d).
3636
*/
3737
static int read_patches(const char *range, struct string_list *list,
38-
const struct strvec *other_arg)
38+
const struct strvec *other_arg,
39+
unsigned int include_merges)
3940
{
4041
struct child_process cp = CHILD_PROCESS_INIT;
4142
struct strbuf buf = STRBUF_INIT, contents = STRBUF_INIT;
@@ -46,7 +47,7 @@ static int read_patches(const char *range, struct string_list *list,
4647
size_t size;
4748
int ret = -1;
4849

49-
strvec_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
50+
strvec_pushl(&cp.args, "log", "--no-color", "-p",
5051
"--reverse", "--date-order", "--decorate=no",
5152
"--no-prefix", "--submodule=short",
5253
/*
@@ -61,6 +62,8 @@ static int read_patches(const char *range, struct string_list *list,
6162
"--pretty=medium",
6263
"--notes",
6364
NULL);
65+
if (!include_merges)
66+
strvec_push(&cp.args, "--no-merges");
6467
strvec_push(&cp.args, range);
6568
if (other_arg)
6669
strvec_pushv(&cp.args, other_arg->v);
@@ -93,11 +96,14 @@ static int read_patches(const char *range, struct string_list *list,
9396
}
9497

9598
if (skip_prefix(line, "commit ", &p)) {
99+
char *q;
96100
if (util) {
97101
string_list_append(list, buf.buf)->util = util;
98102
strbuf_reset(&buf);
99103
}
100104
CALLOC_ARRAY(util, 1);
105+
if (include_merges && (q = strstr(p, " (from ")))
106+
*q = '\0';
101107
if (repo_get_oid(the_repository, p, &util->oid)) {
102108
error(_("could not parse commit '%s'"), p);
103109
FREE_AND_NULL(util);
@@ -563,13 +569,14 @@ int show_range_diff(const char *range1, const char *range2,
563569

564570
struct string_list branch1 = STRING_LIST_INIT_DUP;
565571
struct string_list branch2 = STRING_LIST_INIT_DUP;
572+
unsigned int include_merges = range_diff_opts->include_merges;
566573

567574
if (range_diff_opts->left_only && range_diff_opts->right_only)
568575
res = error(_("options '%s' and '%s' cannot be used together"), "--left-only", "--right-only");
569576

570-
if (!res && read_patches(range1, &branch1, range_diff_opts->other_arg))
577+
if (!res && read_patches(range1, &branch1, range_diff_opts->other_arg, include_merges))
571578
res = error(_("could not parse log for '%s'"), range1);
572-
if (!res && read_patches(range2, &branch2, range_diff_opts->other_arg))
579+
if (!res && read_patches(range2, &branch2, range_diff_opts->other_arg, include_merges))
573580
res = error(_("could not parse log for '%s'"), range2);
574581

575582
if (!res) {

range-diff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct range_diff_options {
1010
int creation_factor;
1111
unsigned dual_color:1;
1212
unsigned left_only:1, right_only:1;
13+
unsigned include_merges:1;
1314
const struct diff_options *diffopt; /* may be NULL */
1415
const struct strvec *other_arg; /* may be NULL */
1516
};

0 commit comments

Comments
 (0)