Skip to content

Commit 7cdb9b4

Browse files
peffgitster
authored andcommitted
diffcore-pickaxe: remove fill_one()
fill_one is _almost_ identical to just calling fill_textconv; the exception is that for the !DIFF_FILE_VALID case, fill_textconv gives us an empty buffer rather than a NULL one. Since we currently use the NULL pointer as a signal that the file is not present on one side of the diff, we must now switch to using DIFF_FILE_VALID to make the same check. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Simon Ruderich <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bc61589 commit 7cdb9b4

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

diffcore-pickaxe.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,6 @@ static void diffgrep_consume(void *priv, char *line, unsigned long len)
7474
line[len] = hold;
7575
}
7676

77-
static void fill_one(struct diff_filespec *one,
78-
mmfile_t *mf, struct userdiff_driver *textconv)
79-
{
80-
if (DIFF_FILE_VALID(one)) {
81-
mf->size = fill_textconv(textconv, one, &mf->ptr);
82-
} else {
83-
memset(mf, 0, sizeof(*mf));
84-
}
85-
}
86-
8777
static int diff_grep(struct diff_filepair *p, struct diff_options *o,
8878
regex_t *regexp, kwset_t kws)
8979
{
@@ -99,15 +89,15 @@ static int diff_grep(struct diff_filepair *p, struct diff_options *o,
9989
textconv_one = get_textconv(p->one);
10090
textconv_two = get_textconv(p->two);
10191

102-
fill_one(p->one, &mf1, textconv_one);
103-
fill_one(p->two, &mf2, textconv_two);
92+
mf1.size = fill_textconv(textconv_one, p->one, &mf1.ptr);
93+
mf2.size = fill_textconv(textconv_two, p->two, &mf2.ptr);
10494

105-
if (!mf1.ptr) {
106-
if (!mf2.ptr)
95+
if (!DIFF_FILE_VALID(p->one)) {
96+
if (!DIFF_FILE_VALID(p->two))
10797
return 0; /* ignore unmerged */
10898
/* created "two" -- does it have what we are looking for? */
10999
hit = !regexec(regexp, mf2.ptr, 1, &regmatch, 0);
110-
} else if (!mf2.ptr) {
100+
} else if (!DIFF_FILE_VALID(p->two)) {
111101
/* removed "one" -- did it have what we are looking for? */
112102
hit = !regexec(regexp, mf1.ptr, 1, &regmatch, 0);
113103
} else {
@@ -224,16 +214,16 @@ static int has_changes(struct diff_filepair *p, struct diff_options *o,
224214
if (textconv_one == textconv_two && diff_unmodified_pair(p))
225215
return 0;
226216

227-
fill_one(p->one, &mf1, textconv_one);
228-
fill_one(p->two, &mf2, textconv_two);
217+
mf1.size = fill_textconv(textconv_one, p->one, &mf1.ptr);
218+
mf2.size = fill_textconv(textconv_two, p->two, &mf2.ptr);
229219

230-
if (!mf1.ptr) {
231-
if (!mf2.ptr)
220+
if (!DIFF_FILE_VALID(p->one)) {
221+
if (!DIFF_FILE_VALID(p->two))
232222
ret = 0; /* ignore unmerged */
233223
/* created */
234224
ret = contains(&mf2, o, regexp, kws) != 0;
235225
}
236-
else if (!mf2.ptr) /* removed */
226+
else if (!DIFF_FILE_VALID(p->two)) /* removed */
237227
ret = contains(&mf1, o, regexp, kws) != 0;
238228
else
239229
ret = contains(&mf1, o, regexp, kws) !=

0 commit comments

Comments
 (0)