Commit 37b25ac57f78dc72e6bf4e516e24dc5010098cee

Edward Thomson 2018-07-08T16:12:58

apply: move location to an argument, not the opts Move the location option to an argument, out of the options structure. This allows the options structure to be re-used for functions that don't need to know the location, since it's implicit in their functionality. For example, `git_apply_tree` should not take a location, but is expected to take all the other options.

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
diff --git a/include/git2/apply.h b/include/git2/apply.h
index 3bf6aad..cdeb9ed 100644
--- a/include/git2/apply.h
+++ b/include/git2/apply.h
@@ -22,6 +22,21 @@
 GIT_BEGIN_DECL
 
 /**
+ * Apply options structure
+ *
+ * Initialize with `GIT_APPLY_OPTIONS_INIT`. Alternatively, you can
+ * use `git_apply_init_options`.
+ *
+ * @see git_apply_to_tree, git_apply
+ */
+typedef struct {
+	unsigned int version;
+} git_apply_options;
+
+#define GIT_APPLY_OPTIONS_VERSION 1
+#define GIT_APPLY_OPTIONS_INIT {GIT_APPLY_OPTIONS_VERSION}
+
+/**
  * Apply a `git_diff` to a `git_tree`, and return the resulting image
  * as an index.
  *
@@ -29,12 +44,14 @@ GIT_BEGIN_DECL
  * @param repo the repository to apply
  * @param preimage the tree to apply the diff to
  * @param diff the diff to apply
+ * @param options the options for the apply (or null for defaults)
  */
 GIT_EXTERN(int) git_apply_to_tree(
 	git_index **out,
 	git_repository *repo,
 	git_tree *preimage,
-	git_diff *diff);
+	git_diff *diff,
+	const git_apply_options *options);
 
 typedef enum {
 	/**
@@ -56,27 +73,20 @@ typedef enum {
 	GIT_APPLY_LOCATION_BOTH = 2,
 } git_apply_location_t;
 
-typedef struct {
-	unsigned int version;
-
-	git_apply_location_t location;
-} git_apply_options;
-
-#define GIT_APPLY_OPTIONS_VERSION 1
-#define GIT_APPLY_OPTIONS_INIT {GIT_APPLY_OPTIONS_VERSION}
-
 /**
  * Apply a `git_diff` to the given repository, making changes directly
  * in the working directory, the index, or both.
  *
  * @param repo the repository to apply to
  * @param diff the diff to apply
+ * @param location the location to apply (workdir, index or both)
  * @param options the options for the apply (or null for defaults)
  */
 GIT_EXTERN(int) git_apply(
 	git_repository *repo,
 	git_diff *diff,
-	git_apply_options *options);
+	git_apply_location_t location,
+	const git_apply_options *options);
 
 /** @} */
 GIT_END_DECL
diff --git a/src/apply.c b/src/apply.c
index d098f96..e6c2ae1 100644
--- a/src/apply.c
+++ b/src/apply.c
@@ -472,10 +472,12 @@ int git_apply_to_tree(
 	git_index **out,
 	git_repository *repo,
 	git_tree *preimage,
-	git_diff *diff)
+	git_diff *diff,
+	const git_apply_options *given_opts)
 {
 	git_index *postimage = NULL;
 	git_reader *pre_reader = NULL;
+	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 	const git_diff_delta *delta;
 	size_t i;
 	int error = 0;
@@ -484,6 +486,9 @@ int git_apply_to_tree(
 
 	*out = NULL;
 
+	if (given_opts)
+		memcpy(&opts, given_opts, sizeof(git_apply_options));
+
 	if ((error = git_reader_for_tree(&pre_reader, preimage)) < 0)
 		goto done;
 
@@ -529,6 +534,7 @@ static int git_apply__to_workdir(
 	git_diff *diff,
 	git_index *preimage,
 	git_index *postimage,
+	git_apply_location_t location,
 	git_apply_options *opts)
 {
 	git_vector paths = GIT_VECTOR_INIT;
@@ -537,6 +543,8 @@ static int git_apply__to_workdir(
 	size_t i;
 	int error;
 
+	GIT_UNUSED(opts);
+
 	/*
 	 * Limit checkout to the paths affected by the diff; this ensures
 	 * that other modifications in the working directory are unaffected.
@@ -559,7 +567,7 @@ static int git_apply__to_workdir(
 	checkout_opts.checkout_strategy |= GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH;
 	checkout_opts.checkout_strategy |= GIT_CHECKOUT_DONT_WRITE_INDEX;
 
-	if (opts->location == GIT_APPLY_LOCATION_WORKDIR)
+	if (location == GIT_APPLY_LOCATION_WORKDIR)
 		checkout_opts.checkout_strategy |= GIT_CHECKOUT_DONT_UPDATE_INDEX;
 
 	checkout_opts.paths.strings = (char **)paths.contents;
@@ -636,7 +644,8 @@ done:
 int git_apply(
 	git_repository *repo,
 	git_diff *diff,
-	git_apply_options *given_opts)
+	git_apply_location_t location,
+	const git_apply_options *given_opts)
 {
 	git_indexwriter indexwriter = GIT_INDEXWRITER_INIT;
 	git_index *index = NULL, *preimage = NULL, *postimage = NULL;
@@ -658,7 +667,7 @@ int git_apply(
 	 * in `--cached` or `--index` mode, we apply to the contents already
 	 * in the index.
 	 */
-	switch (opts.location) {
+	switch (location) {
 	case GIT_APPLY_LOCATION_BOTH:
 		error = git_reader_for_workdir(&pre_reader, repo, true);
 		break;
@@ -695,15 +704,15 @@ int git_apply(
 			goto done;
 	}
 
-	switch (opts.location) {
+	switch (location) {
 	case GIT_APPLY_LOCATION_BOTH:
-		error = git_apply__to_workdir(repo, diff, preimage, postimage, &opts);
+		error = git_apply__to_workdir(repo, diff, preimage, postimage, location, &opts);
 		break;
 	case GIT_APPLY_LOCATION_INDEX:
 		error = git_apply__to_index(repo, diff, preimage, postimage, &opts);
 		break;
 	case GIT_APPLY_LOCATION_WORKDIR:
-		error = git_apply__to_workdir(repo, diff, preimage, postimage, &opts);
+		error = git_apply__to_workdir(repo, diff, preimage, postimage, location, &opts);
 		break;
 	default:
 		assert(false);
@@ -712,9 +721,6 @@ int git_apply(
 	if (error < 0)
 		goto done;
 
-	if (error < 0)
-		goto done;
-
 	error = git_indexwriter_commit(&indexwriter);
 
 done:
diff --git a/tests/apply/both.c b/tests/apply/both.c
index db8cb82..e937166 100644
--- a/tests/apply/both.c
+++ b/tests/apply/both.c
@@ -30,7 +30,6 @@ void test_apply_both__generated_diff(void)
 	git_tree *a_tree, *b_tree;
 	git_diff *diff;
 	git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	struct merge_index_entry both_expected[] = {
 		{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
@@ -52,9 +51,7 @@ void test_apply_both__generated_diff(void)
 	cl_git_pass(git_commit_tree(&b_tree, b_commit));
 
 	cl_git_pass(git_diff_tree_to_tree(&diff, repo, a_tree, b_tree, &diff_opts));
-
-	opts.location = GIT_APPLY_LOCATION_BOTH;
-	cl_git_pass(git_apply(repo, diff, &opts));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
 
 	validate_apply_index(repo, both_expected, both_expected_cnt);
 	validate_apply_workdir(repo, both_expected, both_expected_cnt);
@@ -69,7 +66,6 @@ void test_apply_both__generated_diff(void)
 void test_apply_both__parsed_diff(void)
 {
 	git_diff *diff;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	struct merge_index_entry both_expected[] = {
 		{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
@@ -84,9 +80,7 @@ void test_apply_both__parsed_diff(void)
 
 	cl_git_pass(git_diff_from_buffer(&diff,
 		DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
-
-	opts.location = GIT_APPLY_LOCATION_BOTH;
-	cl_git_pass(git_apply(repo, diff, &opts));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
 
 	validate_apply_index(repo, both_expected, both_expected_cnt);
 	validate_apply_workdir(repo, both_expected, both_expected_cnt);
@@ -97,7 +91,6 @@ void test_apply_both__parsed_diff(void)
 void test_apply_both__removes_file(void)
 {
 	git_diff *diff;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	struct merge_index_entry both_expected[] = {
 		{ 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" },
@@ -111,9 +104,7 @@ void test_apply_both__removes_file(void)
 
 	cl_git_pass(git_diff_from_buffer(&diff, DIFF_DELETE_FILE,
 		strlen(DIFF_DELETE_FILE)));
-
-	opts.location = GIT_APPLY_LOCATION_BOTH;
-	cl_git_pass(git_apply(repo, diff, &opts));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
 
 	validate_apply_index(repo, both_expected, both_expected_cnt);
 	validate_apply_workdir(repo, both_expected, both_expected_cnt);
@@ -124,7 +115,6 @@ void test_apply_both__removes_file(void)
 void test_apply_both__adds_file(void)
 {
 	git_diff *diff;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	struct merge_index_entry both_expected[] = {
 		{ 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" },
@@ -140,9 +130,7 @@ void test_apply_both__adds_file(void)
 
 	cl_git_pass(git_diff_from_buffer(&diff,
 		DIFF_ADD_FILE, strlen(DIFF_ADD_FILE)));
-
-	opts.location = GIT_APPLY_LOCATION_BOTH;
-	cl_git_pass(git_apply(repo, diff, &opts));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
 
 	validate_apply_index(repo, both_expected, both_expected_cnt);
 	validate_apply_workdir(repo, both_expected, both_expected_cnt);
@@ -154,7 +142,6 @@ void test_apply_both__application_failure_leaves_index_unmodified(void)
 {
 	git_diff *diff;
 	git_index *index;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	const char *diff_file = DIFF_MODIFY_TWO_FILES;
 
@@ -175,9 +162,7 @@ void test_apply_both__application_failure_leaves_index_unmodified(void)
 	git_index_free(index);
 
 	cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
-
-	opts.location = GIT_APPLY_LOCATION_BOTH;
-	cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, &opts));
+	cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
 
 	validate_apply_index(repo, index_expected, index_expected_cnt);
 	validate_workdir_unchanged(repo);
@@ -190,7 +175,6 @@ void test_apply_both__index_must_match_workdir(void)
 	git_diff *diff;
 	git_index *index;
 	git_index_entry idx_entry;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	const char *diff_file = DIFF_MODIFY_TWO_FILES;
 
@@ -215,9 +199,7 @@ void test_apply_both__index_must_match_workdir(void)
 	git_index_free(index);
 
 	cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
-
-	opts.location = GIT_APPLY_LOCATION_BOTH;
-	cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, &opts));
+	cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
 
 	git_diff_free(diff);
 }
@@ -226,7 +208,6 @@ void test_apply_both__application_failure_leaves_workdir_unmodified(void)
 {
 	git_diff *diff;
 	git_index *index;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	const char *diff_file = DIFF_MODIFY_TWO_FILES;
 
@@ -251,9 +232,7 @@ void test_apply_both__application_failure_leaves_workdir_unmodified(void)
 	git_index_free(index);
 
 	cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
-
-	opts.location = GIT_APPLY_LOCATION_BOTH;
-	cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, &opts));
+	cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
 
 	validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
 
@@ -265,7 +244,6 @@ void test_apply_both__keeps_nonconflicting_changes(void)
 	git_diff *diff;
 	git_index *index;
 	git_index_entry idx_entry;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	const char *diff_file = DIFF_MODIFY_TWO_FILES;
 
@@ -307,9 +285,7 @@ void test_apply_both__keeps_nonconflicting_changes(void)
 	cl_git_rewritefile("merge-recursive/gravy.txt", "Hello, world.\n");
 
 	cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
-
-	opts.location = GIT_APPLY_LOCATION_BOTH;
-	cl_git_pass(git_apply(repo, diff, &opts));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
 
 	validate_apply_index(repo, index_expected, index_expected_cnt);
 	validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
@@ -321,7 +297,6 @@ void test_apply_both__can_apply_nonconflicting_file_changes(void)
 {
 	git_diff *diff;
 	git_index *index;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	const char *diff_file = DIFF_MODIFY_TWO_FILES;
 
@@ -350,9 +325,7 @@ void test_apply_both__can_apply_nonconflicting_file_changes(void)
 	git_index_free(index);
 
 	cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
-
-	opts.location = GIT_APPLY_LOCATION_BOTH;
-	cl_git_pass(git_apply(repo, diff, &opts));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
 
 	validate_apply_index(repo, both_expected, both_expected_cnt);
 	validate_apply_workdir(repo, both_expected, both_expected_cnt);
@@ -365,7 +338,6 @@ void test_apply_both__honors_crlf_attributes(void)
 	git_diff *diff;
 	git_oid oid;
 	git_commit *commit;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	const char *diff_file = DIFF_MODIFY_TWO_FILES;
 
@@ -403,9 +375,7 @@ void test_apply_both__honors_crlf_attributes(void)
 	git_commit_free(commit);
 
 	cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
-
-	opts.location = GIT_APPLY_LOCATION_BOTH;
-	cl_git_pass(git_apply(repo, diff, &opts));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
 
 	validate_apply_index(repo, index_expected, index_expected_cnt);
 	validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
diff --git a/tests/apply/index.c b/tests/apply/index.c
index 5f6321a..9c9094c 100644
--- a/tests/apply/index.c
+++ b/tests/apply/index.c
@@ -30,7 +30,6 @@ void test_apply_index__generate_diff(void)
 	git_tree *a_tree, *b_tree;
 	git_diff *diff;
 	git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	struct merge_index_entry index_expected[] = {
 		{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
@@ -52,9 +51,7 @@ void test_apply_index__generate_diff(void)
 	cl_git_pass(git_commit_tree(&b_tree, b_commit));
 
 	cl_git_pass(git_diff_tree_to_tree(&diff, repo, a_tree, b_tree, &diff_opts));
-
-	opts.location = GIT_APPLY_LOCATION_INDEX;
-	cl_git_pass(git_apply(repo, diff, &opts));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
 
 	validate_apply_index(repo, index_expected, index_expected_cnt);
 	validate_workdir_unchanged(repo);
@@ -69,7 +66,6 @@ void test_apply_index__generate_diff(void)
 void test_apply_index__parsed_diff(void)
 {
 	git_diff *diff;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	struct merge_index_entry index_expected[] = {
 		{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
@@ -84,9 +80,7 @@ void test_apply_index__parsed_diff(void)
 
 	cl_git_pass(git_diff_from_buffer(&diff,
 		DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
-
-	opts.location = GIT_APPLY_LOCATION_INDEX;
-	cl_git_pass(git_apply(repo, diff, &opts));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
 
 	validate_apply_index(repo, index_expected, index_expected_cnt);
 	validate_workdir_unchanged(repo);
@@ -97,7 +91,6 @@ void test_apply_index__parsed_diff(void)
 void test_apply_index__removes_file(void)
 {
 	git_diff *diff;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	struct merge_index_entry index_expected[] = {
 		{ 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" },
@@ -111,9 +104,7 @@ void test_apply_index__removes_file(void)
 
 	cl_git_pass(git_diff_from_buffer(&diff, DIFF_DELETE_FILE,
 		strlen(DIFF_DELETE_FILE)));
-
-	opts.location = GIT_APPLY_LOCATION_INDEX;
-	cl_git_pass(git_apply(repo, diff, &opts));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
 
 	validate_apply_index(repo, index_expected, index_expected_cnt);
 	validate_workdir_unchanged(repo);
@@ -124,7 +115,6 @@ void test_apply_index__removes_file(void)
 void test_apply_index__adds_file(void)
 {
 	git_diff *diff;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	struct merge_index_entry index_expected[] = {
 		{ 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" },
@@ -140,9 +130,7 @@ void test_apply_index__adds_file(void)
 
 	cl_git_pass(git_diff_from_buffer(&diff,
 		DIFF_ADD_FILE, strlen(DIFF_ADD_FILE)));
-
-	opts.location = GIT_APPLY_LOCATION_INDEX;
-	cl_git_pass(git_apply(repo, diff, &opts));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
 
 	validate_apply_index(repo, index_expected, index_expected_cnt);
 	validate_workdir_unchanged(repo);
@@ -153,7 +141,6 @@ void test_apply_index__adds_file(void)
 void test_apply_index__modified_workdir_with_unmodified_index_is_ok(void)
 {
 	git_diff *diff;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	const char *diff_file = DIFF_MODIFY_TWO_FILES;
 
@@ -183,9 +170,7 @@ void test_apply_index__modified_workdir_with_unmodified_index_is_ok(void)
 	cl_git_rewritefile("merge-recursive/veal.txt", "Hello, world.\n");
 
 	cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
-
-	opts.location = GIT_APPLY_LOCATION_INDEX;
-	cl_git_pass(git_apply(repo, diff, &opts));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
 
 	validate_apply_index(repo, index_expected, index_expected_cnt);
 	validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
@@ -197,7 +182,6 @@ void test_apply_index__application_failure_leaves_index_unmodified(void)
 {
 	git_diff *diff;
 	git_index *index;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	const char *diff_file = DIFF_MODIFY_TWO_FILES;
 
@@ -218,9 +202,7 @@ void test_apply_index__application_failure_leaves_index_unmodified(void)
 	git_index_free(index);
 
 	cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
-
-	opts.location = GIT_APPLY_LOCATION_INDEX;
-	cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, &opts));
+	cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
 
 	validate_apply_index(repo, index_expected, index_expected_cnt);
 
@@ -232,7 +214,6 @@ void test_apply_index__keeps_nonconflicting_changes(void)
 	git_diff *diff;
 	git_index *index;
 	git_index_entry idx_entry;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	const char *diff_file = DIFF_MODIFY_TWO_FILES;
 
@@ -260,9 +241,7 @@ void test_apply_index__keeps_nonconflicting_changes(void)
 	git_index_free(index);
 
 	cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
-
-	opts.location = GIT_APPLY_LOCATION_INDEX;
-	cl_git_pass(git_apply(repo, diff, &opts));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
 
 	validate_apply_index(repo, index_expected, index_expected_cnt);
 	validate_workdir_unchanged(repo);
@@ -275,7 +254,6 @@ void test_apply_index__can_apply_nonconflicting_file_changes(void)
 	git_diff *diff;
 	git_index *index;
 	git_index_entry idx_entry;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	const char *diff_file = DIFF_MODIFY_TWO_FILES;
 
@@ -308,9 +286,7 @@ void test_apply_index__can_apply_nonconflicting_file_changes(void)
 	git_index_free(index);
 
 	cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
-
-	opts.location = GIT_APPLY_LOCATION_INDEX;
-	cl_git_pass(git_apply(repo, diff, &opts));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
 
 	validate_apply_index(repo, index_expected, index_expected_cnt);
 	validate_workdir_unchanged(repo);
@@ -321,7 +297,6 @@ void test_apply_index__can_apply_nonconflicting_file_changes(void)
 void test_apply_index__change_mode(void)
 {
 	git_diff *diff;
-	git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
 
 	const char *diff_file = DIFF_EXECUTABLE_FILE;
 
@@ -337,9 +312,7 @@ void test_apply_index__change_mode(void)
 		sizeof(struct merge_index_entry);
 
 	cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
-
-	opts.location = GIT_APPLY_LOCATION_INDEX;
-	cl_git_pass(git_apply(repo, diff, &opts));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
 
 	validate_apply_index(repo, index_expected, index_expected_cnt);
 	validate_workdir_unchanged(repo);
diff --git a/tests/apply/tree.c b/tests/apply/tree.c
index 38c64c0..f35b13c 100644
--- a/tests/apply/tree.c
+++ b/tests/apply/tree.c
@@ -45,7 +45,7 @@ void test_apply_tree__one(void)
 
 	cl_git_pass(git_diff_tree_to_tree(&diff, repo, a_tree, b_tree, &opts));
 
-	cl_git_pass(git_apply_to_tree(&index, repo, a_tree, diff));
+	cl_git_pass(git_apply_to_tree(&index, repo, a_tree, diff, NULL));
 	merge_test_index(index, expected, 6);
 
 	git_index_free(index);
diff --git a/tests/apply/workdir.c b/tests/apply/workdir.c
index dc304a1..ab1dc25 100644
--- a/tests/apply/workdir.c
+++ b/tests/apply/workdir.c
@@ -50,8 +50,7 @@ void test_apply_workdir__generated_diff(void)
 	cl_git_pass(git_commit_tree(&b_tree, b_commit));
 
 	cl_git_pass(git_diff_tree_to_tree(&diff, repo, a_tree, b_tree, &opts));
-
-	cl_git_pass(git_apply(repo, diff, NULL));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
 
 	validate_index_unchanged(repo);
 	validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
@@ -80,7 +79,7 @@ void test_apply_workdir__parsed_diff(void)
 
 	cl_git_pass(git_diff_from_buffer(&diff,
 		DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
-	cl_git_pass(git_apply(repo, diff, NULL));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
 
 	validate_index_unchanged(repo);
 	validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
@@ -104,7 +103,7 @@ void test_apply_workdir__removes_file(void)
 
 	cl_git_pass(git_diff_from_buffer(&diff, DIFF_DELETE_FILE,
 		strlen(DIFF_DELETE_FILE)));
-	cl_git_pass(git_apply(repo, diff, NULL));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
 
 	validate_index_unchanged(repo);
 	validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
@@ -130,7 +129,7 @@ void test_apply_workdir__adds_file(void)
 
 	cl_git_pass(git_diff_from_buffer(&diff,
 		DIFF_ADD_FILE, strlen(DIFF_ADD_FILE)));
-	cl_git_pass(git_apply(repo, diff, NULL));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
 
 	validate_index_unchanged(repo);
 	validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
@@ -179,7 +178,7 @@ void test_apply_workdir__modified_index_with_unmodified_workdir_is_ok(void)
 	cl_git_pass(git_index_write(index));
 
 	cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
-	cl_git_pass(git_apply(repo, diff, NULL));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
 
 	validate_apply_index(repo, index_expected, index_expected_cnt);
 	validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
@@ -210,7 +209,7 @@ void test_apply_workdir__application_failure_leaves_workdir_unmodified(void)
 	    "This is a modification.\n");
 
 	cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
-	cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, NULL));
+	cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
 
 	validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
 
@@ -236,7 +235,7 @@ void test_apply_workdir__keeps_nonconflicting_changes(void)
 
 	cl_git_pass(git_diff_from_buffer(&diff,
 		DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
-	cl_git_pass(git_apply(repo, diff, NULL));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
 
 	validate_index_unchanged(repo);
 	validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
@@ -270,7 +269,7 @@ void test_apply_workdir__can_apply_nonconflicting_file_changes(void)
 	    "This line is added in the workdir.\n");
 
 	cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
-	cl_git_pass(git_apply(repo, diff, NULL));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
 
 	validate_index_unchanged(repo);
 	validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
@@ -297,7 +296,7 @@ void test_apply_workdir__change_mode(void)
 		sizeof(struct merge_index_entry);
 
 	cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
-	cl_git_pass(git_apply(repo, diff, NULL));
+	cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
 
 	validate_index_unchanged(repo);
 	validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);