Commit f45d51ff8e04c6849413c13aedcf5abacc3c69bd

Ben Straub 2012-11-20T19:57:46

API updates for index.h

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
diff --git a/examples/general.c b/examples/general.c
index d9bb6c0..9ea264e 100644
--- a/examples/general.c
+++ b/examples/general.c
@@ -371,7 +371,7 @@ int main (int argc, char** argv)
   // All these properties are exported publicly in the `git_index_entry` struct
   ecount = git_index_entrycount(index);
   for (i = 0; i < ecount; ++i) {
-    git_index_entry *e = git_index_get_byindex(index, i);
+    const git_index_entry *e = git_index_get_byindex(index, i);
 
     printf("path: %s\n", e->path);
     printf("mtime: %d\n", (int)e->mtime.seconds);
diff --git a/include/git2/index.h b/include/git2/index.h
index 8e1a7e5..195e5b1 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -21,10 +21,10 @@
  */
 GIT_BEGIN_DECL
 
-#define GIT_IDXENTRY_NAMEMASK (0x0fff)
+#define GIT_IDXENTRY_NAMEMASK  (0x0fff)
 #define GIT_IDXENTRY_STAGEMASK (0x3000)
-#define GIT_IDXENTRY_EXTENDED (0x4000)
-#define GIT_IDXENTRY_VALID		(0x8000)
+#define GIT_IDXENTRY_EXTENDED  (0x4000)
+#define GIT_IDXENTRY_VALID     (0x8000)
 #define GIT_IDXENTRY_STAGESHIFT 12
 
 /*
@@ -34,26 +34,26 @@ GIT_BEGIN_DECL
  *
  * In-memory only flags:
  */
-#define GIT_IDXENTRY_UPDATE			(1 << 0)
-#define GIT_IDXENTRY_REMOVE			(1 << 1)
-#define GIT_IDXENTRY_UPTODATE			(1 << 2)
-#define GIT_IDXENTRY_ADDED				(1 << 3)
+#define GIT_IDXENTRY_UPDATE            (1 << 0)
+#define GIT_IDXENTRY_REMOVE            (1 << 1)
+#define GIT_IDXENTRY_UPTODATE          (1 << 2)
+#define GIT_IDXENTRY_ADDED             (1 << 3)
 
-#define GIT_IDXENTRY_HASHED			(1 << 4)
-#define GIT_IDXENTRY_UNHASHED			(1 << 5)
-#define GIT_IDXENTRY_WT_REMOVE			(1 << 6) /* remove in work directory */
-#define GIT_IDXENTRY_CONFLICTED		(1 << 7)
+#define GIT_IDXENTRY_HASHED            (1 << 4)
+#define GIT_IDXENTRY_UNHASHED          (1 << 5)
+#define GIT_IDXENTRY_WT_REMOVE         (1 << 6) /* remove in work directory */
+#define GIT_IDXENTRY_CONFLICTED        (1 << 7)
 
-#define GIT_IDXENTRY_UNPACKED			(1 << 8)
+#define GIT_IDXENTRY_UNPACKED          (1 << 8)
 #define GIT_IDXENTRY_NEW_SKIP_WORKTREE (1 << 9)
 
 /*
  * Extended on-disk flags:
  */
-#define GIT_IDXENTRY_INTENT_TO_ADD		(1 << 13)
-#define GIT_IDXENTRY_SKIP_WORKTREE		(1 << 14)
+#define GIT_IDXENTRY_INTENT_TO_ADD     (1 << 13)
+#define GIT_IDXENTRY_SKIP_WORKTREE     (1 << 14)
 /* GIT_IDXENTRY_EXTENDED2 is for future extension */
-#define GIT_IDXENTRY_EXTENDED2			(1 << 15)
+#define GIT_IDXENTRY_EXTENDED2         (1 << 15)
 
 #define GIT_IDXENTRY_EXTENDED_FLAGS (GIT_IDXENTRY_INTENT_TO_ADD | GIT_IDXENTRY_SKIP_WORKTREE)
 
@@ -119,11 +119,11 @@ enum {
  *
  * The index must be freed once it's no longer in use.
  *
- * @param index the pointer for the new index
+ * @param out the pointer for the new index
  * @param index_path the path to the index file in disk
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_index_open(git_index **index, const char *index_path);
+GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path);
 
 /**
  * Create an in-memory index object.
@@ -133,10 +133,10 @@ GIT_EXTERN(int) git_index_open(git_index **index, const char *index_path);
  *
  * The index must be freed once it's no longer in use.
  *
- * @param index the pointer for the new index
+ * @param out the pointer for the new index
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_index_new(git_index **index);
+GIT_EXTERN(int) git_index_new(git_index **out);
 
 /**
  * Free an existing index object.
@@ -201,7 +201,7 @@ GIT_EXTERN(int) git_index_write(git_index *index);
  * @param tree tree to read
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_index_read_tree(git_index *index, git_tree *tree);
+GIT_EXTERN(int) git_index_read_tree(git_index *index, const git_tree *tree);
 
 /**
  * Write the index as a tree
@@ -217,12 +217,12 @@ GIT_EXTERN(int) git_index_read_tree(git_index *index, git_tree *tree);
  *
  * The index must not contain any file in conflict.
  *
- * @param oid Pointer where to store the OID of the written tree
+ * @param out Pointer where to store the OID of the written tree
  * @param index Index to write
  * @return 0 on success, GIT_EUNMERGED when the index is not clean
  * or an error code
  */
-GIT_EXTERN(int) git_index_write_tree(git_oid *oid, git_index *index);
+GIT_EXTERN(int) git_index_write_tree(git_oid *out, git_index *index);
 
 /**
  * Write the index as a tree to the given repository
@@ -233,13 +233,13 @@ GIT_EXTERN(int) git_index_write_tree(git_oid *oid, git_index *index);
  *
  * The index must not contain any file in conflict.
  *
- * @param oid Pointer where to store OID of the the written tree
+ * @param out Pointer where to store OID of the the written tree
  * @param index Index to write
  * @param repo Repository where to write the tree
  * @return 0 on success, GIT_EUNMERGED when the index is not clean
  * or an error code
  */
-GIT_EXTERN(int) git_index_write_tree_to(git_oid *oid, git_index *index, git_repository *repo);
+GIT_EXTERN(int) git_index_write_tree_to(git_oid *out, git_index *index, git_repository *repo);
 
 /**@}*/
 
@@ -282,7 +282,7 @@ GIT_EXTERN(void) git_index_clear(git_index *index);
  * @param n the position of the entry
  * @return a pointer to the entry; NULL if out of bounds
  */
-GIT_EXTERN(git_index_entry *) git_index_get_byindex(git_index *index, size_t n);
+GIT_EXTERN(const git_index_entry *) git_index_get_byindex(git_index *index, size_t n);
 
 /**
  * Get a pointer to one of the entries in the index
@@ -298,7 +298,7 @@ GIT_EXTERN(git_index_entry *) git_index_get_byindex(git_index *index, size_t n);
  * @param stage stage to search
  * @return a pointer to the entry; NULL if it was not found
  */
-GIT_EXTERN(git_index_entry *) git_index_get_bypath(git_index *index, const char *path, int stage);
+GIT_EXTERN(const git_index_entry *) git_index_get_bypath(git_index *index, const char *path, int stage);
 
 /**
  * Remove an entry from the index
@@ -402,7 +402,8 @@ GIT_EXTERN(int) git_index_find(git_index *index, const char *path);
  * @param their_entry the entry data for their side of the merge conflict
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_index_conflict_add(git_index *index,
+GIT_EXTERN(int) git_index_conflict_add(
+   git_index *index,
 	const git_index_entry *ancestor_entry,
 	const git_index_entry *our_entry,
 	const git_index_entry *their_entry);
@@ -475,7 +476,7 @@ GIT_EXTERN(int) git_index_reuc_find(git_index *index, const char *path);
  * Get a resolve undo entry from the index.
  *
  * The returned entry is read-only and should not be modified
- * of freed by the caller.
+ * or freed by the caller.
  *
  * @param index an existing index object
  * @param path path to search
@@ -487,7 +488,7 @@ GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_bypath(git_index *in
  * Get a resolve undo entry from the index.
  *
  * The returned entry is read-only and should not be modified
- * of freed by the caller.
+ * or freed by the caller.
  *
  * @param index an existing index object
  * @param n the position of the entry
@@ -496,7 +497,7 @@ GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_bypath(git_index *in
 GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_byindex(git_index *index, size_t n);
 
 /**
- * Adds an resolve undo entry for a file based on the given parameters.
+ * Adds a resolve undo entry for a file based on the given parameters.
  *
  * The resolve undo entry contains the OIDs of files that were involved
  * in a merge conflict after the conflict has been resolved.  This allows
@@ -510,26 +511,26 @@ GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_byindex(git_index *i
  * @param index an existing index object
  * @param path filename to add
  * @param ancestor_mode mode of the ancestor file
- * @param ancestor_oid oid of the ancestor file
+ * @param ancestor_id oid of the ancestor file
  * @param our_mode mode of our file
- * @param our_oid oid of our file
+ * @param our_id oid of our file
  * @param their_mode mode of their file
- * @param their_oid oid of their file
+ * @param their_id oid of their file
  * @return 0 or an error code
  */
 GIT_EXTERN(int) git_index_reuc_add(git_index *index, const char *path,
-	int ancestor_mode, git_oid *ancestor_oid,
-	int our_mode, git_oid *our_oid,
-	int their_mode, git_oid *their_oid);
+	int ancestor_mode, git_oid *ancestor_id,
+	int our_mode, git_oid *our_id,
+	int their_mode, git_oid *their_id);
 
 /**
  * Remove an resolve undo entry from the index
  *
  * @param index an existing index object
- * @param position position of the resolve undo entry to remove
+ * @param n position of the resolve undo entry to remove
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_index_reuc_remove(git_index *index, int position);
+GIT_EXTERN(int) git_index_reuc_remove(git_index *index, size_t n);
 
 /**@}*/
 
diff --git a/include/git2/tree.h b/include/git2/tree.h
index d201410..0104ba1 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -371,7 +371,7 @@ typedef enum {
  * @return 0 or an error code
  */
 GIT_EXTERN(int) git_tree_walk(
-	git_tree *tree,
+	const git_tree *tree,
 	git_treewalk_mode mode,
 	git_treewalk_cb callback,
 	void *payload);
diff --git a/src/attr.c b/src/attr.c
index b575744..95d63be 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -295,7 +295,7 @@ static int load_attr_blob_from_index(
 {
 	int error;
 	git_index *index;
-	git_index_entry *entry;
+	const git_index_entry *entry;
 
 	if ((error = git_repository_index__weakptr(&index, repo)) < 0 ||
 		(error = git_index_find(index, relfile)) < 0)
diff --git a/src/index.c b/src/index.c
index 971fec9..fb0061c 100644
--- a/src/index.c
+++ b/src/index.c
@@ -494,14 +494,14 @@ unsigned int git_index_entrycount(git_index *index)
 	return (unsigned int)index->entries.length;
 }
 
-git_index_entry *git_index_get_byindex(git_index *index, size_t n)
+const git_index_entry *git_index_get_byindex(git_index *index, size_t n)
 {
 	assert(index);
 	git_vector_sort(&index->entries);
 	return git_vector_get(&index->entries, n);
 }
 
-git_index_entry *git_index_get_bypath(git_index *index, const char *path, int stage)
+const git_index_entry *git_index_get_bypath(git_index *index, const char *path, int stage)
 {
 	int pos;
 
@@ -1072,7 +1072,7 @@ const git_index_reuc_entry *git_index_reuc_get_byindex(
 	return git_vector_get(&index->reuc, n);
 }
 
-int git_index_reuc_remove(git_index *index, int position)
+int git_index_reuc_remove(git_index *index, size_t position)
 {
 	int error;
 	git_index_reuc_entry *reuc;
@@ -1599,7 +1599,7 @@ static int read_tree_cb(const char *root, const git_tree_entry *tentry, void *da
 	return 0;
 }
 
-int git_index_read_tree(git_index *index, git_tree *tree)
+int git_index_read_tree(git_index *index, const git_tree *tree)
 {
 	git_index_clear(index);
 
diff --git a/src/iterator.c b/src/iterator.c
index ec3c08e..469913d 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -337,7 +337,7 @@ static int index_iterator__current(
 	git_iterator *self, const git_index_entry **entry)
 {
 	index_iterator *ii = (index_iterator *)self;
-	git_index_entry *ie = git_index_get_byindex(ii->index, ii->current);
+	const git_index_entry *ie = git_index_get_byindex(ii->index, ii->current);
 
 	if (ie != NULL &&
 		ii->base.end != NULL &&
diff --git a/src/submodule.c b/src/submodule.c
index bc38f1f..b6e5c96 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -733,7 +733,7 @@ int git_submodule_reload(git_submodule *submodule)
 
 	pos = git_index_find(index, submodule->path);
 	if (pos >= 0) {
-		git_index_entry *entry = git_index_get_byindex(index, pos);
+		const git_index_entry *entry = git_index_get_byindex(index, pos);
 
 		if (S_ISGITLINK(entry->mode)) {
 			if ((error = submodule_load_from_index(repo, entry)) < 0)
diff --git a/src/tree.c b/src/tree.c
index 2529801..6692263 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -356,7 +356,7 @@ static unsigned int find_next_dir(const char *dirname, git_index *index, unsigne
 
 	dirlen = strlen(dirname);
 	for (i = start; i < entries; ++i) {
-		git_index_entry *entry = git_index_get_byindex(index, i);
+		const git_index_entry *entry = git_index_get_byindex(index, i);
 		if (strlen(entry->path) < dirlen ||
 		    memcmp(entry->path, dirname, dirlen) ||
 			(dirlen > 0 && entry->path[dirlen] != '/')) {
@@ -421,7 +421,7 @@ static int write_tree(
 	 * need to keep track of the current position.
 	 */
 	for (i = start; i < entries; ++i) {
-		git_index_entry *entry = git_index_get_byindex(index, i);
+		const git_index_entry *entry = git_index_get_byindex(index, i);
 		char *filename, *next_slash;
 
 	/*
@@ -807,7 +807,7 @@ int git_tree_entry_bypath(
 }
 
 static int tree_walk(
-	git_tree *tree,
+	const git_tree *tree,
 	git_treewalk_cb callback,
 	git_buf *path,
 	void *payload,
@@ -860,7 +860,7 @@ static int tree_walk(
 }
 
 int git_tree_walk(
-	git_tree *tree,
+	const git_tree *tree,
 	git_treewalk_mode mode,
 	git_treewalk_cb callback,
 	void *payload)
diff --git a/tests-clar/attr/repo.c b/tests-clar/attr/repo.c
index b51d5e3..1d2b1e8 100644
--- a/tests-clar/attr/repo.c
+++ b/tests-clar/attr/repo.c
@@ -267,7 +267,7 @@ static void add_to_workdir(const char *filename, const char *content)
 static void assert_proper_normalization(git_index *index, const char *filename, const char *expected_sha)
 {
 	int index_pos;
-	git_index_entry *entry;
+	const git_index_entry *entry;
 
 	add_to_workdir(filename, CONTENT);
 	cl_git_pass(git_index_add_from_workdir(index, filename));
diff --git a/tests-clar/index/conflicts.c b/tests-clar/index/conflicts.c
index 91ff926..790e067 100644
--- a/tests-clar/index/conflicts.c
+++ b/tests-clar/index/conflicts.c
@@ -132,7 +132,7 @@ void test_index_conflicts__get(void)
 
 void test_index_conflicts__remove(void)
 {
-	git_index_entry *entry;
+	const git_index_entry *entry;
 	size_t i;
 	
 	cl_assert(git_index_entrycount(repo_index) == 8);
@@ -156,7 +156,7 @@ void test_index_conflicts__remove(void)
 
 void test_index_conflicts__moved_to_reuc(void)
 {
-	git_index_entry *entry;
+	const git_index_entry *entry;
 	size_t i;
 
 	cl_assert(git_index_entrycount(repo_index) == 8);
@@ -178,7 +178,7 @@ void test_index_conflicts__moved_to_reuc(void)
 void test_index_conflicts__remove_all_conflicts(void)
 {
 	size_t i;
-	git_index_entry *entry;
+	const git_index_entry *entry;
 
 	cl_assert(git_index_entrycount(repo_index) == 8);
 
diff --git a/tests-clar/index/filemodes.c b/tests-clar/index/filemodes.c
index 882d417..a2d5df6 100644
--- a/tests-clar/index/filemodes.c
+++ b/tests-clar/index/filemodes.c
@@ -25,7 +25,7 @@ void test_index_filemodes__read(void)
 	cl_assert_equal_i(6, git_index_entrycount(index));
 
 	for (i = 0; i < 6; ++i) {
-		git_index_entry *entry = git_index_get_byindex(index, i);
+		const git_index_entry *entry = git_index_get_byindex(index, i);
 		cl_assert(entry != NULL);
 		cl_assert(((entry->mode & 0100) ? 1 : 0) == expected[i]);
 	}
@@ -54,7 +54,7 @@ static void add_and_check_mode(
 	git_index *index, const char *filename, unsigned int expect_mode)
 {
 	int pos;
-	git_index_entry *entry;
+	const git_index_entry *entry;
 
 	cl_git_pass(git_index_add_from_workdir(index, filename));
 
diff --git a/tests-clar/index/rename.c b/tests-clar/index/rename.c
index e16ec00..adbbcfa 100644
--- a/tests-clar/index/rename.c
+++ b/tests-clar/index/rename.c
@@ -7,7 +7,7 @@ void test_index_rename__single_file(void)
 	git_index *index;
 	int position;
 	git_oid expected;
-	git_index_entry *entry;
+	const git_index_entry *entry;
 
 	p_mkdir("rename", 0700);
 
diff --git a/tests-clar/index/stage.c b/tests-clar/index/stage.c
index 9c9d296..0f3b298 100644
--- a/tests-clar/index/stage.c
+++ b/tests-clar/index/stage.c
@@ -27,7 +27,7 @@ void test_index_stage__cleanup(void)
 void test_index_stage__add_always_adds_stage_0(void)
 {
 	int entry_idx;
-	git_index_entry *entry;
+	const git_index_entry *entry;
 
     cl_git_mkfile("./mergedrepo/new-file.txt", "new-file\n");
 
@@ -41,7 +41,7 @@ void test_index_stage__add_always_adds_stage_0(void)
 void test_index_stage__find_gets_first_stage(void)
 {
 	int entry_idx;
-	git_index_entry *entry;
+	const git_index_entry *entry;
 
 	cl_assert((entry_idx = git_index_find(repo_index, "one.txt")) >= 0);
 	cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
diff --git a/tests-clar/index/tests.c b/tests-clar/index/tests.c
index 3b71b70..4d613d6 100644
--- a/tests-clar/index/tests.c
+++ b/tests-clar/index/tests.c
@@ -208,7 +208,7 @@ void test_index_tests__add(void)
    git_index *index;
    git_filebuf file = GIT_FILEBUF_INIT;
    git_repository *repo;
-   git_index_entry *entry;
+   const git_index_entry *entry;
    git_oid id1;
 
    /* Intialize a new repository */
diff --git a/tests-clar/object/commit/commitstagedfile.c b/tests-clar/object/commit/commitstagedfile.c
index 6dc536e..55c70d9 100644
--- a/tests-clar/object/commit/commitstagedfile.c
+++ b/tests-clar/object/commit/commitstagedfile.c
@@ -21,7 +21,7 @@ void test_object_commit_commitstagedfile__cleanup(void)
 void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
 {
 	git_index *index;
-	git_index_entry *entry;
+	const git_index_entry *entry;
 	git_oid expected_blob_oid, tree_oid, expected_tree_oid, commit_oid, expected_commit_oid;
 	git_signature *signature;
 	git_tree *tree;