Skip to content

Commit 15dafaf

Browse files
René Scharfegitster
authored andcommitted
pickaxe: factor out has_changes
Move duplicate if/else construct into its own helper function. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8e854b0 commit 15dafaf

File tree

1 file changed

+21
-36
lines changed

1 file changed

+21
-36
lines changed

diffcore-pickaxe.c

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,31 @@ static unsigned int contains(struct diff_filespec *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)
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;
201+
}
202+
if (!DIFF_FILE_VALID(p->two))
203+
return contains(p->one, needle, len, 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);
207+
}
208+
return 0;
209+
}
210+
193211
static void diffcore_pickaxe_count(struct diff_options *o)
194212
{
195213
const char *needle = o->pickaxe;
196214
int opts = o->pickaxe_opts;
197215
struct diff_queue_struct *q = &diff_queued_diff;
198216
unsigned long len = strlen(needle);
199-
int i, has_changes;
217+
int i;
200218
regex_t regex, *regexp = NULL;
201219
kwset_t kws = NULL;
202220
struct diff_queue_struct outq;
@@ -223,22 +241,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
223241
/* Showing the whole changeset if needle exists */
224242
for (i = 0; i < q->nr; i++) {
225243
struct diff_filepair *p = q->queue[i];
226-
if (!DIFF_FILE_VALID(p->one)) {
227-
if (!DIFF_FILE_VALID(p->two))
228-
continue; /* ignore unmerged */
229-
/* created */
230-
if (contains(p->two, needle, len, regexp, kws))
231-
has_changes++;
232-
}
233-
else if (!DIFF_FILE_VALID(p->two)) {
234-
if (contains(p->one, needle, len, regexp, kws))
235-
has_changes++;
236-
}
237-
else if (!diff_unmodified_pair(p) &&
238-
contains(p->one, needle, len, regexp, kws) !=
239-
contains(p->two, needle, len, regexp, kws))
240-
has_changes++;
241-
if (has_changes)
244+
if (has_changes(p, needle, len, regexp, kws))
242245
goto out; /* do not munge the queue */
243246
}
244247

@@ -254,25 +257,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
254257
/* Showing only the filepairs that has the needle */
255258
for (i = 0; i < q->nr; i++) {
256259
struct diff_filepair *p = q->queue[i];
257-
has_changes = 0;
258-
if (!DIFF_FILE_VALID(p->one)) {
259-
if (!DIFF_FILE_VALID(p->two))
260-
; /* ignore unmerged */
261-
/* created */
262-
else if (contains(p->two, needle, len, regexp,
263-
kws))
264-
has_changes = 1;
265-
}
266-
else if (!DIFF_FILE_VALID(p->two)) {
267-
if (contains(p->one, needle, len, regexp, kws))
268-
has_changes = 1;
269-
}
270-
else if (!diff_unmodified_pair(p) &&
271-
contains(p->one, needle, len, regexp, kws) !=
272-
contains(p->two, needle, len, regexp, kws))
273-
has_changes = 1;
274-
275-
if (has_changes)
260+
if (has_changes(p, needle, len, regexp, kws))
276261
diff_q(&outq, p);
277262
else
278263
diff_free_filepair(p);

0 commit comments

Comments
 (0)