Skip to content

Commit 5d176fb

Browse files
René Scharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 15dafaf commit 5d176fb

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

diffcore-pickaxe.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,13 @@ static void diffcore_pickaxe_grep(struct diff_options *o)
144144
return;
145145
}
146146

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,
149148
regex_t *regexp, kwset_t kws)
150149
{
151150
unsigned int cnt;
152151
unsigned long sz;
153152
const char *data;
154-
if (!len)
153+
if (!o->pickaxe[0])
155154
return 0;
156155
if (diff_populate_filespec(one, 0))
157156
return 0;
@@ -175,35 +174,36 @@ static unsigned int contains(struct diff_filespec *one,
175174

176175
} else { /* Classic exact string match */
177176
while (sz) {
178-
size_t offset = kwsexec(kws, data, sz, NULL);
177+
struct kwsmatch kwsm;
178+
size_t offset = kwsexec(kws, data, sz, &kwsm);
179179
const char *found;
180180
if (offset == -1)
181181
break;
182182
else
183183
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];
186186
cnt++;
187187
}
188188
}
189189
diff_free_filespec_data(one);
190190
return cnt;
191191
}
192192

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)
195195
{
196196
if (!DIFF_FILE_VALID(p->one)) {
197197
if (!DIFF_FILE_VALID(p->two))
198198
return 0; /* ignore unmerged */
199199
/* created */
200-
return contains(p->two, needle, len, regexp, kws) != 0;
200+
return contains(p->two, o, regexp, kws) != 0;
201201
}
202202
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;
204204
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);
207207
}
208208
return 0;
209209
}
@@ -241,7 +241,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
241241
/* Showing the whole changeset if needle exists */
242242
for (i = 0; i < q->nr; i++) {
243243
struct diff_filepair *p = q->queue[i];
244-
if (has_changes(p, needle, len, regexp, kws))
244+
if (has_changes(p, o, regexp, kws))
245245
goto out; /* do not munge the queue */
246246
}
247247

@@ -257,7 +257,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
257257
/* Showing only the filepairs that has the needle */
258258
for (i = 0; i < q->nr; i++) {
259259
struct diff_filepair *p = q->queue[i];
260-
if (has_changes(p, needle, len, regexp, kws))
260+
if (has_changes(p, o, regexp, kws))
261261
diff_q(&outq, p);
262262
else
263263
diff_free_filepair(p);

0 commit comments

Comments
 (0)