Commit 134d8c918c3430b19b75f45b1e490ce2aae526ff

Russell Belfer 2013-01-08T15:53:13

Update iterator API with flags for ignore_case This changes the iterator API so that flags can be passed in to the constructor functions to control the ignore_case behavior. At this point, the flags are not supported on tree iterators (i.e. there is no functional change over the old API), but the API changes are all made to accomodate this. By the way, I went with a flags parameter because in the future I have a couple of other ideas for iterator flags that will make it easier to fix some diff/status/checkout bugs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
diff --git a/src/checkout.c b/src/checkout.c
index d5a471d..411bf3b 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -224,7 +224,7 @@ static int checkout_action_wd_only(
 	if (!git_pathspec_match_path(
 			pathspec, wd->path,
 			(data->strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH) != 0,
-			workdir->ignore_case))
+			git_iterator_ignore_case(workdir)))
 		return 0;
 
 	/* check if item is tracked in the index but not in the checkout diff */
@@ -1130,7 +1130,7 @@ static int checkout_data_init(
 		if ((error = git_config_refresh(cfg)) < 0)
 			goto cleanup;
 
-		if (git_iterator_inner_type(target) == GIT_ITERATOR_INDEX) {
+		if (git_iterator_inner_type(target) == GIT_ITERATOR_TYPE_INDEX) {
 			/* if we are iterating over the index, don't reload */
 			data->index = git_iterator_index_get_index(target);
 			GIT_REFCOUNT_INC(data->index);
@@ -1208,6 +1208,7 @@ int git_checkout_iterator(
 	git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
 	uint32_t *actions = NULL;
 	size_t *counts = NULL;
+	git_iterator_flag_t iterflags = 0;
 
 	/* initialize structures and options */
 	error = checkout_data_init(&data, target, opts);
@@ -1228,18 +1229,21 @@ int git_checkout_iterator(
 		diff_opts.pathspec = data.opts.paths;
 
 	/* set up iterators */
+
+	iterflags = git_iterator_ignore_case(target) ?
+		GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE;
+
 	if ((error = git_iterator_reset(target, data.pfx, data.pfx)) < 0 ||
 		(error = git_iterator_for_workdir_range(
-			&workdir, data.repo, data.pfx, data.pfx)) < 0 ||
+			&workdir, data.repo, iterflags, data.pfx, data.pfx)) < 0 ||
 		(error = git_iterator_for_tree_range(
-			&baseline, data.opts.baseline, data.pfx, data.pfx)) < 0)
+			&baseline, data.opts.baseline, iterflags, data.pfx, data.pfx)) < 0)
 		goto cleanup;
 
 	/* Handle case insensitivity for baseline if necessary */
-	if (workdir->ignore_case && !baseline->ignore_case) {
+	if (git_iterator_ignore_case(workdir) != git_iterator_ignore_case(baseline))
 		if ((error = git_iterator_spoolandsort_push(baseline, true)) < 0)
 			goto cleanup;
-	}
 
 	/* Generate baseline-to-target diff which will include an entry for
 	 * every possible update that might need to be made.
diff --git a/src/diff.c b/src/diff.c
index 5e34b92..4b60935 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -418,7 +418,7 @@ static int maybe_modified(
 	git_delta_t status = GIT_DELTA_MODIFIED;
 	unsigned int omode = oitem->mode;
 	unsigned int nmode = nitem->mode;
-	bool new_is_workdir = (new_iter->type == GIT_ITERATOR_WORKDIR);
+	bool new_is_workdir = (new_iter->type == GIT_ITERATOR_TYPE_WORKDIR);
 
 	GIT_UNUSED(old_iter);
 
@@ -556,7 +556,9 @@ static int diff_list_init_from_iterators(
 
 	/* Use case-insensitive compare if either iterator has
 	 * the ignore_case bit set */
-	if (!old_iter->ignore_case && !new_iter->ignore_case) {
+	if (!git_iterator_ignore_case(old_iter) &&
+		!git_iterator_ignore_case(new_iter))
+	{
 		diff->opts.flags &= ~GIT_DIFF_DELTAS_ARE_ICASE;
 
 		diff->strcomp    = git__strcmp;
@@ -714,7 +716,7 @@ int git_diff__from_iterators(
 			else if (git_iterator_current_is_ignored(new_iter))
 				delta_type = GIT_DELTA_IGNORED;
 
-			else if (new_iter->type != GIT_ITERATOR_WORKDIR)
+			else if (new_iter->type != GIT_ITERATOR_TYPE_WORKDIR)
 				delta_type = GIT_DELTA_ADDED;
 
 			if (diff_delta__from_one(diff, delta_type, nitem) < 0)
@@ -786,8 +788,8 @@ int git_diff_tree_to_tree(
 	assert(diff && repo);
 
 	DIFF_FROM_ITERATORS(
-		git_iterator_for_tree_range(&a, old_tree, pfx, pfx),
-		git_iterator_for_tree_range(&b, new_tree, pfx, pfx)
+		git_iterator_for_tree_range(&a, old_tree, 0, pfx, pfx),
+		git_iterator_for_tree_range(&b, new_tree, 0, pfx, pfx)
 	);
 
 	return error;
@@ -808,8 +810,8 @@ int git_diff_tree_to_index(
 		return error;
 
 	DIFF_FROM_ITERATORS(
-		git_iterator_for_tree_range(&a, old_tree, pfx, pfx),
-	    git_iterator_for_index_range(&b, index, pfx, pfx)
+		git_iterator_for_tree_range(&a, old_tree, 0, pfx, pfx),
+	    git_iterator_for_index_range(&b, index, 0, pfx, pfx)
 	);
 
 	return error;
@@ -829,8 +831,8 @@ int git_diff_index_to_workdir(
 		return error;
 
 	DIFF_FROM_ITERATORS(
-		git_iterator_for_index_range(&a, index, pfx, pfx),
-	    git_iterator_for_workdir_range(&b, repo, pfx, pfx)
+		git_iterator_for_index_range(&a, index, 0, pfx, pfx),
+	    git_iterator_for_workdir_range(&b, repo, 0, pfx, pfx)
 	);
 
 	return error;
@@ -848,8 +850,8 @@ int git_diff_tree_to_workdir(
 	assert(diff && repo);
 
 	DIFF_FROM_ITERATORS(
-		git_iterator_for_tree_range(&a, old_tree, pfx, pfx),
-	    git_iterator_for_workdir_range(&b, repo, pfx, pfx)
+		git_iterator_for_tree_range(&a, old_tree, 0, pfx, pfx),
+	    git_iterator_for_workdir_range(&b, repo, 0, pfx, pfx)
 	);
 
 	return error;
diff --git a/src/diff_output.c b/src/diff_output.c
index d271e8a..8a7a7a2 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -495,7 +495,7 @@ static void diff_patch_init(
 		patch->old_src = patch->diff->old_src;
 		patch->new_src = patch->diff->new_src;
 	} else {
-		patch->old_src = patch->new_src = GIT_ITERATOR_TREE;
+		patch->old_src = patch->new_src = GIT_ITERATOR_TYPE_TREE;
 	}
 }
 
@@ -578,7 +578,7 @@ static int diff_patch_load(
 	 */
 
 	if ((delta->old_file.flags & GIT_DIFF_FILE_NO_DATA) == 0 &&
-		patch->old_src == GIT_ITERATOR_WORKDIR) {
+		patch->old_src == GIT_ITERATOR_TYPE_WORKDIR) {
 		if ((error = get_workdir_content(
 				ctxt, delta, &delta->old_file, &patch->old_data)) < 0)
 			goto cleanup;
@@ -587,7 +587,7 @@ static int diff_patch_load(
 	}
 
 	if ((delta->new_file.flags & GIT_DIFF_FILE_NO_DATA) == 0 &&
-		patch->new_src == GIT_ITERATOR_WORKDIR) {
+		patch->new_src == GIT_ITERATOR_TYPE_WORKDIR) {
 		if ((error = get_workdir_content(
 				ctxt, delta, &delta->new_file, &patch->new_data)) < 0)
 			goto cleanup;
@@ -596,7 +596,7 @@ static int diff_patch_load(
 	}
 
 	if ((delta->old_file.flags & GIT_DIFF_FILE_NO_DATA) == 0 &&
-		patch->old_src != GIT_ITERATOR_WORKDIR) {
+		patch->old_src != GIT_ITERATOR_TYPE_WORKDIR) {
 		if ((error = get_blob_content(
 				ctxt, delta, &delta->old_file,
 				&patch->old_data, &patch->old_blob)) < 0)
@@ -606,7 +606,7 @@ static int diff_patch_load(
 	}
 
 	if ((delta->new_file.flags & GIT_DIFF_FILE_NO_DATA) == 0 &&
-		patch->new_src != GIT_ITERATOR_WORKDIR) {
+		patch->new_src != GIT_ITERATOR_TYPE_WORKDIR) {
 		if ((error = get_blob_content(
 				ctxt, delta, &delta->new_file,
 				&patch->new_data, &patch->new_blob)) < 0)
diff --git a/src/iterator.c b/src/iterator.c
index 3d75dd8..a9df39b 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -24,12 +24,11 @@
 #define ITERATOR_BASE_INIT(P,NAME_LC,NAME_UC) do { \
 	(P) = git__calloc(1, sizeof(NAME_LC ## _iterator)); \
 	GITERR_CHECK_ALLOC(P); \
-	(P)->base.type    = GIT_ITERATOR_ ## NAME_UC; \
+	(P)->base.type    = GIT_ITERATOR_TYPE_ ## NAME_UC; \
 	(P)->base.cb    = &(P)->cb; \
 	ITERATOR_SET_CB(P,NAME_LC); \
 	(P)->base.start   = start ? git__strdup(start) : NULL; \
 	(P)->base.end     = end ? git__strdup(end) : NULL; \
-	(P)->base.ignore_case = false; \
 	if ((start && !(P)->base.start) || (end && !(P)->base.end)) { \
 		git__free(P); return -1; } \
 	} while (0)
@@ -54,6 +53,31 @@ static int iterator__reset_range(
 	return 0;
 }
 
+static int iterator_update_ignore_case(
+	git_iterator *iter,
+	git_iterator_flag_t flags)
+{
+	int error = 0, ignore_case = -1;
+
+	if ((flags & GIT_ITERATOR_IGNORE_CASE) != 0)
+		ignore_case = true;
+	else if ((flags & GIT_ITERATOR_DONT_IGNORE_CASE) != 0)
+		ignore_case = false;
+	else {
+		git_index *index;
+
+		if (!(error = git_repository_index__weakptr(&index, iter->repo)))
+			ignore_case = (index->ignore_case != false);
+	}
+
+	if (ignore_case > 0)
+		iter->flags = (iter->flags | GIT_ITERATOR_IGNORE_CASE);
+	else if (ignore_case == 0)
+		iter->flags = (iter->flags & ~GIT_ITERATOR_IGNORE_CASE);
+
+	return error;
+}
+
 static int empty_iterator__no_item(
 	git_iterator *iter, const git_index_entry **entry)
 {
@@ -91,13 +115,14 @@ typedef struct {
 	git_iterator_callbacks cb;
 } empty_iterator;
 
-int git_iterator_for_nothing(git_iterator **iter)
+int git_iterator_for_nothing(git_iterator **iter, git_iterator_flag_t flags)
 {
 	empty_iterator *i = git__calloc(1, sizeof(empty_iterator));
 	GITERR_CHECK_ALLOC(i);
 
-	i->base.type  = GIT_ITERATOR_EMPTY;
+	i->base.type  = GIT_ITERATOR_TYPE_EMPTY;
 	i->base.cb    = &i->cb;
+	i->base.flags = flags;
 	i->cb.current = empty_iterator__no_item;
 	i->cb.at_end  = empty_iterator__at_end;
 	i->cb.advance = empty_iterator__no_item;
@@ -349,6 +374,7 @@ static int tree_iterator__reset(
 int git_iterator_for_tree_range(
 	git_iterator **iter,
 	git_tree *tree,
+	git_iterator_flag_t flags,
 	const char *start,
 	const char *end)
 {
@@ -356,7 +382,7 @@ int git_iterator_for_tree_range(
 	tree_iterator *ti;
 
 	if (tree == NULL)
-		return git_iterator_for_nothing(iter);
+		return git_iterator_for_nothing(iter, flags);
 
 	if ((error = git_tree__dup(&tree, tree)) < 0)
 		return error;
@@ -364,13 +390,23 @@ int git_iterator_for_tree_range(
 	ITERATOR_BASE_INIT(ti, tree, TREE);
 
 	ti->base.repo = git_tree_owner(tree);
+
+	if ((error = iterator_update_ignore_case((git_iterator *)ti, flags)) < 0)
+		goto fail;
+
+	/* TODO: implement icase support natively in tree iterators */
+	ti->base.flags = (ti->base.flags & ~GIT_ITERATOR_IGNORE_CASE);
+
 	ti->stack = ti->tail = tree_iterator__alloc_frame(tree, ti->base.start);
 
 	if ((error = tree_iterator__expand_tree(ti)) < 0)
-		git_iterator_free((git_iterator *)ti);
-	else
-		*iter = (git_iterator *)ti;
+		goto fail;
+
+	*iter = (git_iterator *)ti;
+	return 0;
 
+fail:
+	git_iterator_free((git_iterator *)ti);
 	return error;
 }
 
@@ -466,15 +502,19 @@ static void index_iterator__free(git_iterator *self)
 int git_iterator_for_index_range(
 	git_iterator **iter,
 	git_index  *index,
+	git_iterator_flag_t flags,
 	const char *start,
 	const char *end)
 {
 	index_iterator *ii;
 
+	GIT_UNUSED(flags);
+
 	ITERATOR_BASE_INIT(ii, index, INDEX);
 
 	ii->base.repo = git_index_owner(index);
-	ii->base.ignore_case = index->ignore_case;
+	if (index->ignore_case)
+		ii->base.flags |= GIT_ITERATOR_IGNORE_CASE;
 	ii->index = index;
 	GIT_REFCOUNT_INC(index);
 
@@ -530,7 +570,8 @@ static workdir_iterator_frame *workdir_iterator__alloc_frame(
 	workdir_iterator *wi)
 {
 	workdir_iterator_frame *wf = git__calloc(1, sizeof(workdir_iterator_frame));
-	git_vector_cmp entry_compare = CASESELECT(wi->base.ignore_case,
+	git_vector_cmp entry_compare = CASESELECT(
+		(wi->base.flags & GIT_ITERATOR_IGNORE_CASE) != 0,
 		git_path_with_stat_cmp_icase, git_path_with_stat_cmp);
 
 	if (wf == NULL)
@@ -592,7 +633,8 @@ static int workdir_iterator__expand_dir(workdir_iterator *wi)
 	GITERR_CHECK_ALLOC(wf);
 
 	error = git_path_dirload_with_stat(
-		wi->path.ptr, wi->root_len, wi->base.ignore_case,
+		wi->path.ptr, wi->root_len,
+		(wi->base.flags & GIT_ITERATOR_IGNORE_CASE) != 0,
 		wi->base.start, wi->base.end, &wf->entries);
 
 	if (error < 0 || wf->entries.length == 0) {
@@ -775,12 +817,12 @@ static int workdir_iterator__update_entry(workdir_iterator *wi)
 int git_iterator_for_workdir_range(
 	git_iterator **iter,
 	git_repository *repo,
+	git_iterator_flag_t flags,
 	const char *start,
 	const char *end)
 {
 	int error;
 	workdir_iterator *wi;
-	git_index *index;
 
 	assert(iter && repo);
 
@@ -791,13 +833,8 @@ int git_iterator_for_workdir_range(
 	ITERATOR_BASE_INIT(wi, workdir, WORKDIR);
 	wi->base.repo = repo;
 
-	if ((error = git_repository_index__weakptr(&index, repo)) < 0) {
-		git_iterator_free((git_iterator *)wi);
-		return error;
-	}
-
-	/* Match ignore_case flag for iterator to that of the index */
-	wi->base.ignore_case = index->ignore_case;
+	if ((error = iterator_update_ignore_case((git_iterator *)wi, flags)) < 0)
+		goto fail;
 
 	if (git_buf_sets(&wi->path, git_repository_workdir(repo)) < 0 ||
 		git_path_to_dir(&wi->path) < 0 ||
@@ -808,23 +845,24 @@ int git_iterator_for_workdir_range(
 	}
 
 	wi->root_len = wi->path.size;
-	wi->entrycmp = wi->base.ignore_case ?
+	wi->entrycmp = (wi->base.flags & GIT_ITERATOR_IGNORE_CASE) != 0 ?
 		workdir_iterator__entry_cmp_icase : workdir_iterator__entry_cmp_case;
 
 	if ((error = workdir_iterator__expand_dir(wi)) < 0) {
-		if (error == GIT_ENOTFOUND)
-			error = 0;
-		else {
-			git_iterator_free((git_iterator *)wi);
-			wi = NULL;
-		}
+		if (error != GIT_ENOTFOUND)
+			goto fail;
+		giterr_clear();
 	}
 
 	*iter = (git_iterator *)wi;
+	return 0;
 
+fail:
+	git_iterator_free((git_iterator *)wi);
 	return error;
 }
 
+
 typedef struct {
 	/* replacement callbacks */
 	git_iterator_callbacks cb;
@@ -899,12 +937,12 @@ void git_iterator_spoolandsort_pop(git_iterator *self)
 {
 	spoolandsort_callbacks *scb = (spoolandsort_callbacks *)self->cb;
 
-	if (self->type != GIT_ITERATOR_SPOOLANDSORT)
+	if (self->type != GIT_ITERATOR_TYPE_SPOOLANDSORT)
 		return;
 
 	self->cb   = scb->orig;
 	self->type = scb->orig_type;
-	self->ignore_case = !self->ignore_case;
+	self->flags ^= GIT_ITERATOR_IGNORE_CASE;
 
 	spoolandsort_iterator__free_callbacks(scb);
 }
@@ -921,7 +959,7 @@ int git_iterator_spoolandsort_push(git_iterator *iter, bool ignore_case)
 	spoolandsort_callbacks *scb;
 	int (*entrycomp)(const void *a, const void *b);
 
-	if (iter->ignore_case == ignore_case)
+	if (((iter->flags & GIT_ITERATOR_IGNORE_CASE) != 0) == (ignore_case != 0))
 		return 0;
 
 	scb = git__calloc(1, sizeof(spoolandsort_callbacks));
@@ -964,8 +1002,8 @@ int git_iterator_spoolandsort_push(git_iterator *iter, bool ignore_case)
 	git_vector_sort(&scb->entries);
 
 	iter->cb   = (git_iterator_callbacks *)scb;
-	iter->type = GIT_ITERATOR_SPOOLANDSORT;
-	iter->ignore_case = !iter->ignore_case;
+	iter->type = GIT_ITERATOR_TYPE_SPOOLANDSORT;
+	iter->flags ^= GIT_ITERATOR_IGNORE_CASE;
 
 	return 0;
 
@@ -992,11 +1030,11 @@ void git_iterator_free(git_iterator *iter)
 
 git_index *git_iterator_index_get_index(git_iterator *iter)
 {
-	if (iter->type == GIT_ITERATOR_INDEX)
+	if (iter->type == GIT_ITERATOR_TYPE_INDEX)
 		return ((index_iterator *)iter)->index;
 
-	if (iter->type == GIT_ITERATOR_SPOOLANDSORT &&
-		((spoolandsort_callbacks *)iter->cb)->orig_type == GIT_ITERATOR_INDEX)
+	if (iter->type == GIT_ITERATOR_TYPE_SPOOLANDSORT &&
+		((spoolandsort_callbacks *)iter->cb)->orig_type == GIT_ITERATOR_TYPE_INDEX)
 		return ((index_iterator *)iter)->index;
 
 	return NULL;
@@ -1004,7 +1042,7 @@ git_index *git_iterator_index_get_index(git_iterator *iter)
 
 git_iterator_type_t git_iterator_inner_type(git_iterator *iter)
 {
-	if (iter->type == GIT_ITERATOR_SPOOLANDSORT)
+	if (iter->type == GIT_ITERATOR_TYPE_SPOOLANDSORT)
 		return ((spoolandsort_callbacks *)iter->cb)->orig_type;
 
 	return iter->type;
@@ -1013,7 +1051,7 @@ git_iterator_type_t git_iterator_inner_type(git_iterator *iter)
 int git_iterator_current_tree_entry(
 	git_iterator *iter, const git_tree_entry **tree_entry)
 {
-	*tree_entry = (iter->type != GIT_ITERATOR_TREE) ? NULL :
+	*tree_entry = (iter->type != GIT_ITERATOR_TYPE_TREE) ? NULL :
 		tree_iterator__tree_entry((tree_iterator *)iter);
 	return 0;
 }
@@ -1027,7 +1065,7 @@ int git_iterator_current_parent_tree(
 	tree_iterator_frame *tf;
 	const char *scan = parent_path;
 
-	if (iter->type != GIT_ITERATOR_TREE || ti->stack == NULL)
+	if (iter->type != GIT_ITERATOR_TYPE_TREE || ti->stack == NULL)
 		goto notfound;
 
 	for (tf = ti->tail; tf != NULL; tf = tf->prev) {
@@ -1061,7 +1099,7 @@ int git_iterator_current_is_ignored(git_iterator *iter)
 {
 	workdir_iterator *wi = (workdir_iterator *)iter;
 
-	if (iter->type != GIT_ITERATOR_WORKDIR)
+	if (iter->type != GIT_ITERATOR_TYPE_WORKDIR)
 		return 0;
 
 	if (wi->is_ignored != -1)
@@ -1078,7 +1116,7 @@ int git_iterator_advance_into_directory(
 {
 	workdir_iterator *wi = (workdir_iterator *)iter;
 
-	if (iter->type == GIT_ITERATOR_WORKDIR &&
+	if (iter->type == GIT_ITERATOR_TYPE_WORKDIR &&
 		wi->entry.path &&
 		(wi->entry.mode == GIT_FILEMODE_TREE ||
 		 wi->entry.mode == GIT_FILEMODE_COMMIT))
@@ -1112,7 +1150,7 @@ int git_iterator_current_workdir_path(git_iterator *iter, git_buf **path)
 {
 	workdir_iterator *wi = (workdir_iterator *)iter;
 
-	if (iter->type != GIT_ITERATOR_WORKDIR || !wi->entry.path)
+	if (iter->type != GIT_ITERATOR_TYPE_WORKDIR || !wi->entry.path)
 		*path = NULL;
 	else
 		*path = &wi->path;
diff --git a/src/iterator.h b/src/iterator.h
index 727da97..67e8a42 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -12,20 +12,26 @@
 #include "vector.h"
 #include "buffer.h"
 
-#define ITERATOR_PREFIXCMP(ITER, STR, PREFIX)	(((ITER).ignore_case) ? \
+#define ITERATOR_PREFIXCMP(ITER, STR, PREFIX)	\
+	(((ITER).flags & GIT_ITERATOR_IGNORE_CASE) != 0 ? \
 	git__prefixcmp_icase((STR), (PREFIX)) : \
 	git__prefixcmp((STR), (PREFIX)))
 
 typedef struct git_iterator git_iterator;
 
 typedef enum {
-	GIT_ITERATOR_EMPTY = 0,
-	GIT_ITERATOR_TREE = 1,
-	GIT_ITERATOR_INDEX = 2,
-	GIT_ITERATOR_WORKDIR = 3,
-	GIT_ITERATOR_SPOOLANDSORT = 4
+	GIT_ITERATOR_TYPE_EMPTY = 0,
+	GIT_ITERATOR_TYPE_TREE = 1,
+	GIT_ITERATOR_TYPE_INDEX = 2,
+	GIT_ITERATOR_TYPE_WORKDIR = 3,
+	GIT_ITERATOR_TYPE_SPOOLANDSORT = 4
 } git_iterator_type_t;
 
+typedef enum {
+	GIT_ITERATOR_IGNORE_CASE = (1 << 0), /* ignore_case */
+	GIT_ITERATOR_DONT_IGNORE_CASE = (1 << 1), /* force ignore_case off */
+} git_iterator_flag_t;
+
 typedef struct {
 	int (*current)(git_iterator *, const git_index_entry **);
 	int (*at_end)(git_iterator *);
@@ -41,33 +47,55 @@ struct git_iterator {
 	git_repository *repo;
 	char *start;
 	char *end;
-	bool ignore_case;
+	unsigned int flags;
 };
 
-extern int git_iterator_for_nothing(git_iterator **out);
+extern int git_iterator_for_nothing(
+	git_iterator **out, git_iterator_flag_t flags);
 
+/* tree iterators will match the ignore_case value from the index of the
+ * repository, unless you override with a non-zero flag value
+ */
 extern int git_iterator_for_tree_range(
-	git_iterator **out, git_tree *tree, const char *start, const char *end);
+	git_iterator **out,
+	git_tree *tree,
+	git_iterator_flag_t flags,
+	const char *start,
+	const char *end);
 
 GIT_INLINE(int) git_iterator_for_tree(git_iterator **out, git_tree *tree)
 {
-	return git_iterator_for_tree_range(out, tree, NULL, NULL);
+	return git_iterator_for_tree_range(out, tree, 0, NULL, NULL);
 }
 
+/* index iterators will take the ignore_case value from the index; the
+ * ignore_case flags are not used
+ */
 extern int git_iterator_for_index_range(
-	git_iterator **out, git_index *index, const char *start, const char *end);
+	git_iterator **out,
+	git_index *index,
+	git_iterator_flag_t flags,
+	const char *start,
+	const char *end);
 
 GIT_INLINE(int) git_iterator_for_index(git_iterator **out, git_index *index)
 {
-	return git_iterator_for_index_range(out, index, NULL, NULL);
+	return git_iterator_for_index_range(out, index, 0, NULL, NULL);
 }
 
+/* workdir iterators will match the ignore_case value from the index of the
+ * repository, unless you override with a non-zero flag value
+ */
 extern int git_iterator_for_workdir_range(
-	git_iterator **out, git_repository *repo, const char *start, const char *end);
+	git_iterator **out,
+	git_repository *repo,
+	git_iterator_flag_t flags,
+	const char *start,
+	const char *end);
 
 GIT_INLINE(int) git_iterator_for_workdir(git_iterator **out, git_repository *repo)
 {
-	return git_iterator_for_workdir_range(out, repo, NULL, NULL);
+	return git_iterator_for_workdir_range(out, repo, 0, NULL, NULL);
 }
 
 extern void git_iterator_free(git_iterator *iter);
@@ -127,6 +155,16 @@ GIT_INLINE(git_repository *) git_iterator_owner(git_iterator *iter)
 	return iter->repo;
 }
 
+GIT_INLINE(git_iterator_flag_t) git_iterator_flags(git_iterator *iter)
+{
+	return iter->flags;
+}
+
+GIT_INLINE(bool) git_iterator_ignore_case(git_iterator *iter)
+{
+	return ((iter->flags & GIT_ITERATOR_IGNORE_CASE) != 0);
+}
+
 extern int git_iterator_current_tree_entry(
 	git_iterator *iter, const git_tree_entry **tree_entry);
 
diff --git a/tests-clar/diff/iterator.c b/tests-clar/diff/iterator.c
index de083ea..6fc5730 100644
--- a/tests-clar/diff/iterator.c
+++ b/tests-clar/diff/iterator.c
@@ -35,7 +35,8 @@ static void tree_iterator_test(
 	git_repository *repo = cl_git_sandbox_init(sandbox);
 
 	cl_assert(t = resolve_commit_oid_to_tree(repo, treeish));
-	cl_git_pass(git_iterator_for_tree_range(&i, t, start, end));
+	cl_git_pass(git_iterator_for_tree_range(
+		&i, t, GIT_ITERATOR_DONT_IGNORE_CASE, start, end));
 
 	/* test loop */
 	cl_git_pass(git_iterator_current(i, &entry));
@@ -304,7 +305,8 @@ void test_diff_iterator__tree_special_functions(void)
 		repo, "24fa9a9fc4e202313e24b648087495441dab432b");
 	cl_assert(t != NULL);
 
-	cl_git_pass(git_iterator_for_tree_range(&i, t, NULL, NULL));
+	cl_git_pass(git_iterator_for_tree_range(
+		&i, t, GIT_ITERATOR_DONT_IGNORE_CASE, NULL, NULL));
 	cl_git_pass(git_iterator_current(i, &entry));
 
 	while (entry != NULL) {
@@ -362,7 +364,7 @@ static void index_iterator_test(
 	git_repository *repo = cl_git_sandbox_init(sandbox);
 
 	cl_git_pass(git_repository_index(&index, repo));
-	cl_git_pass(git_iterator_for_index_range(&i, index, start, end));
+	cl_git_pass(git_iterator_for_index_range(&i, index, 0, start, end));
 	cl_git_pass(git_iterator_current(i, &entry));
 
 	while (entry != NULL) {
@@ -536,7 +538,7 @@ static void workdir_iterator_test(
 	int count = 0, count_all = 0, count_all_post_reset = 0;
 	git_repository *repo = cl_git_sandbox_init(sandbox);
 
-	cl_git_pass(git_iterator_for_workdir_range(&i, repo, start, end));
+	cl_git_pass(git_iterator_for_workdir_range(&i, repo, 0, start, end));
 	cl_git_pass(git_iterator_current(i, &entry));
 
 	while (entry != NULL) {
@@ -734,7 +736,7 @@ void test_diff_iterator__workdir_builtin_ignores(void)
 	cl_git_mkfile("attr/sub/.git", "whatever");
 
 	cl_git_pass(
-		git_iterator_for_workdir_range(&i, repo, "dir", "sub/sub/file"));
+		git_iterator_for_workdir_range(&i, repo, 0, "dir", "sub/sub/file"));
 	cl_git_pass(git_iterator_current(i, &entry));
 
 	for (idx = 0; entry != NULL; ++idx) {