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 <peff@peff.net> Signed-off-by: Simon Ruderich <simon@ruderich.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Apr 4, 2013 at 20:08 UTC 7cdb9b42c359000b1d3d604f847598afd015b7c7
1 file changed +10 -20
diffcore-pickaxe.c
+10 -20
@@ -74,16 +74,6 @@ static void diffgrep_consume(void *priv, char *line, unsigned long len)
74 line[len] = hold;
75 }
76
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 -
77 static int diff_grep(struct diff_filepair *p, struct diff_options *o,
78 regex_t *regexp, kwset_t kws)
79 {
@@ -99,15 +89,15 @@ static int diff_grep(struct diff_filepair *p, struct diff_options *o,
89 textconv_one = get_textconv(p->one);
90 textconv_two = get_textconv(p->two);
91
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);
94
105 - if (!mf1.ptr) {
106 - if (!mf2.ptr)
95 + if (!DIFF_FILE_VALID(p->one)) {
96 + if (!DIFF_FILE_VALID(p->two))
97 return 0; /* ignore unmerged */
98 /* created "two" -- does it have what we are looking for? */
99 hit = !regexec(regexp, mf2.ptr, 1, &regmatch, 0);
110 - } else if (!mf2.ptr) {
100 + } else if (!DIFF_FILE_VALID(p->two)) {
101 /* removed "one" -- did it have what we are looking for? */
102 hit = !regexec(regexp, mf1.ptr, 1, &regmatch, 0);
103 } else {
@@ -224,16 +214,16 @@ static int has_changes(struct diff_filepair *p, struct diff_options *o,
214 if (textconv_one == textconv_two && diff_unmodified_pair(p))
215 return 0;
216
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);
219
230 - if (!mf1.ptr) {
231 - if (!mf2.ptr)
220 + if (!DIFF_FILE_VALID(p->one)) {
221 + if (!DIFF_FILE_VALID(p->two))
222 ret = 0; /* ignore unmerged */
223 /* created */
224 ret = contains(&mf2, o, regexp, kws) != 0;
225 }
236 - else if (!mf2.ptr) /* removed */
226 + else if (!DIFF_FILE_VALID(p->two)) /* removed */
227 ret = contains(&mf1, o, regexp, kws) != 0;
228 else
229 ret = contains(&mf1, o, regexp, kws) !=