pickaxe: factor out has_changes
Move duplicate if/else construct into its own helper function. 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:26 UTC
15dafaf80dda8e90114ae178569b9600ebd07109
1 file changed
+21
-36
diffcore-pickaxe.c
+21
-36
@@ -190,13 +190,31 @@ 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)
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
+
211
static void diffcore_pickaxe_count(struct diff_options *o)
212
{
213
const char *needle = o->pickaxe;
214
int opts = o->pickaxe_opts;
215
struct diff_queue_struct *q = &diff_queued_diff;
216
unsigned long len = strlen(needle);
199
- int i, has_changes;
217
+ int i;
218
regex_t regex, *regexp = NULL;
219
kwset_t kws = NULL;
220
struct diff_queue_struct outq;
@@ -223,22 +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];
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))
245
goto out; /* do not munge the queue */
246
}
247
@@ -254,25 +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];
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))
261
diff_q(&outq, p);
262
else
263
diff_free_filepair(p);