pickaxe: pass diff_options to contains and has_changes
Remove the unused parameter needle from contains() and has_changes(). Also replace the parameter len with a pointer to the diff_options. We can use its member pickaxe to check if the needle is an empty string and use the kwsmatch structure to find out the length of the match instead. This change is done as a preparation to unify the signatures of has_changes() and diff_grep(), which will be used in the patch after the next one to factor out common code. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Oct 6, 2011 at 18:50 UTC
5d176fb6b6a22f19f7a15fc344dfb08af1e29ed7
1 file changed
+14
-14
diffcore-pickaxe.c
+14
-14
@@ -144,14 +144,13 @@ static void diffcore_pickaxe_grep(struct diff_options *o)
144
return;
145
}
146
147
-static unsigned int contains(struct diff_filespec *one,
148
- const char *needle, unsigned long len,
147
+static unsigned int contains(struct diff_filespec *one, struct diff_options *o,
148
regex_t *regexp, kwset_t kws)
149
{
150
unsigned int cnt;
151
unsigned long sz;
152
const char *data;
154
- if (!len)
153
+ if (!o->pickaxe[0])
154
return 0;
155
if (diff_populate_filespec(one, 0))
156
return 0;
@@ -175,14 +174,15 @@ static unsigned int contains(struct diff_filespec *one,
174
175
} else { /* Classic exact string match */
176
while (sz) {
178
- size_t offset = kwsexec(kws, data, sz, NULL);
177
+ struct kwsmatch kwsm;
178
+ size_t offset = kwsexec(kws, data, sz, &kwsm);
179
const char *found;
180
if (offset == -1)
181
break;
182
else
183
found = data + offset;
184
- sz -= found - data + len;
185
- data = found + len;
184
+ sz -= found - data + kwsm.size[0];
185
+ data = found + kwsm.size[0];
186
cnt++;
187
}
188
}
@@ -190,20 +190,20 @@ static unsigned int contains(struct diff_filespec *one,
190
return cnt;
191
}
192
193
-static int has_changes(struct diff_filepair *p, const char *needle,
194
- unsigned long len, regex_t *regexp, kwset_t kws)
193
+static int has_changes(struct diff_filepair *p, struct diff_options *o,
194
+ regex_t *regexp, kwset_t kws)
195
{
196
if (!DIFF_FILE_VALID(p->one)) {
197
if (!DIFF_FILE_VALID(p->two))
198
return 0; /* ignore unmerged */
199
/* created */
200
- return contains(p->two, needle, len, regexp, kws) != 0;
200
+ return contains(p->two, o, regexp, kws) != 0;
201
}
202
if (!DIFF_FILE_VALID(p->two))
203
- return contains(p->one, needle, len, regexp, kws) != 0;
203
+ return contains(p->one, o, regexp, kws) != 0;
204
if (!diff_unmodified_pair(p)) {
205
- return contains(p->one, needle, len, regexp, kws) !=
206
- contains(p->two, needle, len, regexp, kws);
205
+ return contains(p->one, o, regexp, kws) !=
206
+ contains(p->two, o, regexp, kws);
207
}
208
return 0;
209
}
@@ -241,7 +241,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
241
/* Showing the whole changeset if needle exists */
242
for (i = 0; i < q->nr; i++) {
243
struct diff_filepair *p = q->queue[i];
244
- if (has_changes(p, needle, len, regexp, kws))
244
+ if (has_changes(p, o, regexp, kws))
245
goto out; /* do not munge the queue */
246
}
247
@@ -257,7 +257,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
257
/* Showing only the filepairs that has the needle */
258
for (i = 0; i < q->nr; i++) {
259
struct diff_filepair *p = q->queue[i];
260
- if (has_changes(p, needle, len, regexp, kws))
260
+ if (has_changes(p, o, regexp, kws))
261
diff_q(&outq, p);
262
else
263
diff_free_filepair(p);