Skip to content

Commit 93d1f19

Browse files
committed
Merge branch 'vd/range-diff-with-custom-pretty-format-fix'
"git range-diff" fixes. * vd/range-diff-with-custom-pretty-format-fix: range-diff: avoid negative string precision range-diff: fix a crash in parsing git-log output
2 parents 5a96715 + 8d1675e commit 93d1f19

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

range-diff.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ static int read_patches(const char *range, struct string_list *list,
6363
"--output-indicator-old=<",
6464
"--output-indicator-context=#",
6565
"--no-abbrev-commit",
66+
"--pretty=medium",
67+
"--notes",
6668
NULL);
6769
if (other_arg)
6870
argv_array_pushv(&cp.args, other_arg->argv);
@@ -106,20 +108,34 @@ static int read_patches(const char *range, struct string_list *list,
106108
continue;
107109
}
108110

111+
if (!util) {
112+
error(_("could not parse first line of `log` output: "
113+
"did not start with 'commit ': '%s'"),
114+
line);
115+
string_list_clear(list, 1);
116+
strbuf_release(&buf);
117+
strbuf_release(&contents);
118+
finish_command(&cp);
119+
return -1;
120+
}
121+
109122
if (starts_with(line, "diff --git")) {
110123
struct patch patch = { 0 };
111124
struct strbuf root = STRBUF_INIT;
112125
int linenr = 0;
126+
int orig_len;
113127

114128
in_header = 0;
115129
strbuf_addch(&buf, '\n');
116130
if (!util->diff_offset)
117131
util->diff_offset = buf.len;
118132
line[len - 1] = '\n';
133+
orig_len = len;
119134
len = parse_git_diff_header(&root, &linenr, 0, line,
120135
len, size, &patch);
121136
if (len < 0)
122-
die(_("could not parse git header '%.*s'"), (int)len, line);
137+
die(_("could not parse git header '%.*s'"),
138+
orig_len, line);
123139
strbuf_addstr(&buf, " ## ");
124140
if (patch.is_new > 0)
125141
strbuf_addf(&buf, "%s (new)", patch.new_name);

t/t3206-range-diff.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,16 @@ test_expect_success 'range-diff overrides diff.noprefix internally' '
513513
git -c diff.noprefix=true range-diff HEAD^...
514514
'
515515

516+
test_expect_success 'basic with modified format.pretty with suffix' '
517+
git -c format.pretty="format:commit %H%d%n" range-diff \
518+
master..topic master..unmodified
519+
'
520+
521+
test_expect_success 'basic with modified format.pretty without "commit "' '
522+
git -c format.pretty="format:%H%n" range-diff \
523+
master..topic master..unmodified
524+
'
525+
516526
test_expect_success 'range-diff compares notes by default' '
517527
git notes add -m "topic note" topic &&
518528
git notes add -m "unmodified note" unmodified &&

0 commit comments

Comments
 (0)