Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 98eb3fc

Browse files
committed
Merge branch 'bp/diff-no-index-strbuf-fix' into maint
The directory path used in "git diff --no-index", when it recurses down, was broken with a recent update after v1.7.10.1 release. By Bobby Powers * bp/diff-no-index-strbuf-fix: diff --no-index: don't leak buffers in queue_diff diff --no-index: reset temporary buffer lengths on directory iteration
2 parents a3347b9 + 176a335 commit 98eb3fc

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

diff-no-index.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ static int queue_diff(struct diff_options *o,
6868
struct string_list p1 = STRING_LIST_INIT_DUP;
6969
struct string_list p2 = STRING_LIST_INIT_DUP;
7070
int i1, i2, ret = 0;
71+
size_t len1 = 0, len2 = 0;
7172

7273
if (name1 && read_directory(name1, &p1))
7374
return -1;
@@ -80,18 +81,23 @@ static int queue_diff(struct diff_options *o,
8081
strbuf_addstr(&buffer1, name1);
8182
if (buffer1.len && buffer1.buf[buffer1.len - 1] != '/')
8283
strbuf_addch(&buffer1, '/');
84+
len1 = buffer1.len;
8385
}
8486

8587
if (name2) {
8688
strbuf_addstr(&buffer2, name2);
8789
if (buffer2.len && buffer2.buf[buffer2.len - 1] != '/')
8890
strbuf_addch(&buffer2, '/');
91+
len2 = buffer2.len;
8992
}
9093

9194
for (i1 = i2 = 0; !ret && (i1 < p1.nr || i2 < p2.nr); ) {
9295
const char *n1, *n2;
9396
int comp;
9497

98+
strbuf_setlen(&buffer1, len1);
99+
strbuf_setlen(&buffer2, len2);
100+
95101
if (i1 == p1.nr)
96102
comp = 1;
97103
else if (i2 == p2.nr)
@@ -117,8 +123,8 @@ static int queue_diff(struct diff_options *o,
117123
}
118124
string_list_clear(&p1, 0);
119125
string_list_clear(&p2, 0);
120-
strbuf_reset(&buffer1);
121-
strbuf_reset(&buffer2);
126+
strbuf_release(&buffer1);
127+
strbuf_release(&buffer2);
122128

123129
return ret;
124130
} else {

t/t4053-diff-no-index.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
3+
test_description='diff --no-index'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'setup' '
8+
mkdir a &&
9+
mkdir b &&
10+
echo 1 >a/1 &&
11+
echo 2 >a/2
12+
'
13+
14+
test_expect_success 'git diff --no-index directories' '
15+
git diff --no-index a b >cnt
16+
test $? = 1 && test_line_count = 14 cnt
17+
'
18+
19+
test_done

0 commit comments

Comments
 (0)