]> git.proxmox.com Git - libgit2.git/blob - src/status.c
05e07be0a53c340a13812944ff2befdcd4737d4d
[libgit2.git] / src / status.c
1 /*
2 * Copyright (C) 2009-2011 the libgit2 contributors
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7
8 #include "common.h"
9 #include "git2.h"
10 #include "fileops.h"
11 #include "hash.h"
12 #include "vector.h"
13 #include "tree.h"
14 #include "git2/status.h"
15 #include "repository.h"
16
17 struct status_entry {
18 git_index_time mtime;
19
20 git_oid head_oid;
21 git_oid index_oid;
22 git_oid wt_oid;
23
24 unsigned int status_flags:6;
25
26 char path[GIT_FLEX_ARRAY]; /* more */
27 };
28
29 static struct status_entry *status_entry_new(git_vector *entries, const char *path)
30 {
31 struct status_entry *e = git__calloc(sizeof(*e) + strlen(path) + 1, 1);
32 if (e == NULL)
33 return NULL;
34
35 if (entries != NULL)
36 git_vector_insert(entries, e);
37
38 strcpy(e->path, path);
39
40 return e;
41 }
42
43 GIT_INLINE(void) status_entry_update_from_tree_entry(struct status_entry *e, const git_tree_entry *tree_entry)
44 {
45 assert(e && tree_entry);
46
47 git_oid_cpy(&e->head_oid, &tree_entry->oid);
48 }
49
50 GIT_INLINE(void) status_entry_update_from_index_entry(struct status_entry *e, const git_index_entry *index_entry)
51 {
52 assert(e && index_entry);
53
54 git_oid_cpy(&e->index_oid, &index_entry->oid);
55 e->mtime = index_entry->mtime;
56 }
57
58 static void status_entry_update_from_index(struct status_entry *e, git_index *index)
59 {
60 int idx;
61 git_index_entry *index_entry;
62
63 assert(e && index);
64
65 idx = git_index_find(index, e->path);
66 if (idx < 0)
67 return;
68
69 index_entry = git_index_get(index, idx);
70
71 status_entry_update_from_index_entry(e, index_entry);
72 }
73
74 static int status_entry_update_from_workdir(struct status_entry *e, const char* full_path)
75 {
76 struct stat filest;
77
78 if (p_stat(full_path, &filest) < GIT_SUCCESS)
79 return git__throw(GIT_EOSERR, "Failed to determine status of file '%s'. Can't read file", full_path);
80
81 if (e->mtime.seconds == (git_time_t)filest.st_mtime)
82 git_oid_cpy(&e->wt_oid, &e->index_oid);
83 else
84 git_odb_hashfile(&e->wt_oid, full_path, GIT_OBJ_BLOB);
85
86 return GIT_SUCCESS;
87 }
88
89 static int status_entry_update_flags(struct status_entry *e)
90 {
91 git_oid zero;
92 int head_zero, index_zero, wt_zero;
93
94 memset(&zero, 0x0, sizeof(git_oid));
95
96 head_zero = git_oid_cmp(&zero, &e->head_oid);
97 index_zero = git_oid_cmp(&zero, &e->index_oid);
98 wt_zero = git_oid_cmp(&zero, &e->wt_oid);
99
100 if (head_zero == 0 && index_zero == 0 && wt_zero == 0)
101 return GIT_ENOTFOUND;
102
103 if (head_zero == 0 && index_zero != 0)
104 e->status_flags |= GIT_STATUS_INDEX_NEW;
105 else if (index_zero == 0 && head_zero != 0)
106 e->status_flags |= GIT_STATUS_INDEX_DELETED;
107 else if (git_oid_cmp(&e->head_oid, &e->index_oid) != 0)
108 e->status_flags |= GIT_STATUS_INDEX_MODIFIED;
109
110 if (index_zero == 0 && wt_zero != 0)
111 e->status_flags |= GIT_STATUS_WT_NEW;
112 else if (wt_zero == 0 && index_zero != 0)
113 e->status_flags |= GIT_STATUS_WT_DELETED;
114 else if (git_oid_cmp(&e->index_oid, &e->wt_oid) != 0)
115 e->status_flags |= GIT_STATUS_WT_MODIFIED;
116
117 return GIT_SUCCESS;
118 }
119
120 struct status_st {
121 git_vector *vector;
122 git_index *index;
123 git_tree *tree;
124
125 int workdir_path_len;
126 git_buf head_tree_relative_path;
127 int head_tree_relative_path_len;
128 unsigned int tree_position;
129 unsigned int index_position;
130 int is_dir:1;
131 };
132
133 static int retrieve_head_tree(git_tree **tree_out, git_repository *repo)
134 {
135 git_reference *resolved_head_ref;
136 git_commit *head_commit = NULL;
137 git_tree *tree;
138 int error = GIT_SUCCESS;
139
140 *tree_out = NULL;
141
142 error = git_repository_head(&resolved_head_ref, repo);
143 /*
144 * We assume that a situation where HEAD exists but can not be resolved is valid.
145 * A new repository fits this description for instance.
146 */
147 if (error == GIT_ENOTFOUND)
148 return GIT_SUCCESS;
149 if (error < GIT_SUCCESS)
150 return git__rethrow(error, "HEAD can't be resolved");
151
152 if ((error = git_commit_lookup(&head_commit, repo, git_reference_oid(resolved_head_ref))) < GIT_SUCCESS)
153 return git__rethrow(error, "The tip of HEAD can't be retrieved");
154
155 git_reference_free(resolved_head_ref);
156
157 if ((error = git_commit_tree(&tree, head_commit)) < GIT_SUCCESS) {
158 error = git__rethrow(error, "The tree of HEAD can't be retrieved");
159 goto exit;
160 }
161
162 *tree_out = tree;
163
164 exit:
165 git_commit_free(head_commit);
166 return error;
167 }
168
169 enum path_type {
170 GIT_STATUS_PATH_NULL,
171 GIT_STATUS_PATH_IGNORE,
172 GIT_STATUS_PATH_FILE,
173 GIT_STATUS_PATH_FOLDER,
174 };
175
176 static int dirent_cb(void *state, git_buf *full_path);
177 static int alphasorted_futils_direach(
178 git_buf *path, int (*fn)(void *, git_buf *), void *arg);
179
180 static int process_folder(
181 struct status_st *st,
182 const git_tree_entry *tree_entry,
183 git_buf *full_path,
184 enum path_type path_type)
185 {
186 git_object *subtree = NULL;
187 git_tree *pushed_tree = NULL;
188 int error, pushed_tree_position = 0;
189 git_otype tree_entry_type = GIT_OBJ_BAD;
190
191 if (tree_entry != NULL) {
192 tree_entry_type = git_tree_entry_type(tree_entry);
193
194 switch (tree_entry_type) {
195 case GIT_OBJ_TREE:
196 error = git_tree_entry_2object(&subtree, ((git_object *)(st->tree))->repo, tree_entry);
197 pushed_tree = st->tree;
198 pushed_tree_position = st->tree_position;
199 st->tree = (git_tree *)subtree;
200 st->tree_position = 0;
201 st->head_tree_relative_path_len += 1 + tree_entry->filename_len; /* path + '/' + name */
202 break;
203
204 case GIT_OBJ_BLOB:
205 /* No op */
206 break;
207
208 default:
209 error = git__throw(GIT_EINVALIDTYPE, "Unexpected tree entry type"); /* TODO: How should we deal with submodules? */
210 }
211 }
212
213 if (full_path != NULL && path_type == GIT_STATUS_PATH_FOLDER)
214 error = alphasorted_futils_direach(full_path, dirent_cb, st);
215 else
216 error = dirent_cb(st, NULL);
217
218 if (tree_entry_type == GIT_OBJ_TREE) {
219 git_object_free(subtree);
220 st->head_tree_relative_path_len -= 1 + tree_entry->filename_len;
221 st->tree = pushed_tree;
222 st->tree_position = pushed_tree_position;
223 st->tree_position++;
224 }
225
226 return error;
227 }
228
229 static int store_if_changed(struct status_st *st, struct status_entry *e)
230 {
231 int error;
232 if ((error = status_entry_update_flags(e)) < GIT_SUCCESS)
233 return git__throw(error, "Failed to process the file '%s'. It doesn't exist in the workdir, in the HEAD nor in the index", e->path);
234
235 if (e->status_flags == GIT_STATUS_CURRENT) {
236 git__free(e);
237 return GIT_SUCCESS;
238 }
239
240 return git_vector_insert(st->vector, e);
241 }
242
243 static int determine_status(struct status_st *st,
244 int in_head, int in_index, int in_workdir,
245 const git_tree_entry *tree_entry,
246 const git_index_entry *index_entry,
247 git_buf *full_path,
248 const char *status_path,
249 enum path_type path_type)
250 {
251 struct status_entry *e;
252 int error = GIT_SUCCESS;
253 git_otype tree_entry_type = GIT_OBJ_BAD;
254
255 if (tree_entry != NULL)
256 tree_entry_type = git_tree_entry_type(tree_entry);
257
258 /* If we're dealing with a directory in the workdir, let's recursively tackle it first */
259 if (path_type == GIT_STATUS_PATH_FOLDER)
260 return process_folder(st, tree_entry, full_path, path_type);
261
262 /* Are we dealing with a file somewhere? */
263 if (in_workdir || in_index || (in_head && tree_entry_type == GIT_OBJ_BLOB)) {
264 e = status_entry_new(NULL, status_path);
265
266 if (in_head && tree_entry_type == GIT_OBJ_BLOB) {
267 status_entry_update_from_tree_entry(e, tree_entry);
268 st->tree_position++;
269 }
270
271 if (in_index) {
272 status_entry_update_from_index_entry(e, index_entry);
273 st->index_position++;
274 }
275
276 if (in_workdir)
277 if ((error = status_entry_update_from_workdir(e, full_path->ptr
278 )) < GIT_SUCCESS)
279 return error; /* The callee has already set the error message */
280
281 return store_if_changed(st, e);
282 }
283
284 /* Last option, we're dealing with a leftover folder tree entry */
285 assert(in_head && !in_index && !in_workdir && (tree_entry_type == GIT_OBJ_TREE));
286 return process_folder(st, tree_entry, full_path, path_type);
287 }
288
289 static int path_type_from(git_buf *full_path, int is_dir)
290 {
291 if (full_path == NULL)
292 return GIT_STATUS_PATH_NULL;
293
294 if (!is_dir)
295 return GIT_STATUS_PATH_FILE;
296
297 if (!git__suffixcmp(full_path->ptr, "/" DOT_GIT "/"))
298 return GIT_STATUS_PATH_IGNORE;
299
300 return GIT_STATUS_PATH_FOLDER;
301 }
302
303 static const char *status_path(const char *first, const char *second, const char *third)
304 {
305 /* At least one of them can not be NULL */
306 assert(first != NULL || second != NULL || third != NULL);
307
308 /* TODO: Fixme. Ensure that when non null, they're all equal */
309 if (first != NULL)
310 return first;
311
312 if (second != NULL)
313 return second;
314
315 return third;
316 }
317
318 static int compare(const char *left, const char *right)
319 {
320 if (left == NULL && right == NULL)
321 return 0;
322
323 if (left == NULL)
324 return 1;
325
326 if (right == NULL)
327 return -1;
328
329 return strcmp(left, right);
330 }
331
332 /* Greatly inspired from JGit IndexTreeWalker */
333 /* https://github.com/spearce/jgit/blob/ed47e29c777accfa78c6f50685a5df2b8f5b8ff5/org.spearce.jgit/src/org/spearce/jgit/lib/IndexTreeWalker.java#L88 */
334
335 static int dirent_cb(void *state, git_buf *a)
336 {
337 const git_tree_entry *m;
338 const git_index_entry *entry;
339 enum path_type path_type;
340 int cmpma, cmpmi, cmpai, error;
341 const char *pm, *pa, *pi;
342 const char *m_name, *i_name, *a_name;
343
344 struct status_st *st = (struct status_st *)state;
345
346 path_type = path_type_from(a, st->is_dir);
347
348 if (path_type == GIT_STATUS_PATH_IGNORE)
349 return GIT_SUCCESS; /* Let's skip the ".git" directory */
350
351 a_name = (path_type != GIT_STATUS_PATH_NULL) ? a->ptr + st->workdir_path_len : NULL;
352
353 while (1) {
354 if (st->tree == NULL)
355 m = NULL;
356 else
357 m = git_tree_entry_byindex(st->tree, st->tree_position);
358
359 entry = git_index_get(st->index, st->index_position);
360
361 if ((m == NULL) && (a == NULL) && (entry == NULL))
362 return GIT_SUCCESS;
363
364 if (m != NULL) {
365 git_buf_truncate(&st->head_tree_relative_path,
366 st->head_tree_relative_path_len);
367 git_buf_joinpath(&st->head_tree_relative_path,
368 st->head_tree_relative_path.ptr, m->filename);
369 /* When the tree entry is a folder, append a forward slash to its name */
370 if (git_tree_entry_type(m) == GIT_OBJ_TREE)
371 git_path_to_dir(&st->head_tree_relative_path);
372
373 if (error < GIT_SUCCESS)
374 return git__rethrow(error, "An error occured while determining the status of '%s'", a->ptr);
375
376 m_name = st->head_tree_relative_path.ptr;
377 } else
378 m_name = NULL;
379
380 i_name = (entry != NULL) ? entry->path : NULL;
381
382 cmpma = compare(m_name, a_name);
383 cmpmi = compare(m_name, i_name);
384 cmpai = compare(a_name, i_name);
385
386 pm = ((cmpma <= 0) && (cmpmi <= 0)) ? m_name : NULL;
387 pa = ((cmpma >= 0) && (cmpai <= 0)) ? a_name : NULL;
388 pi = ((cmpmi >= 0) && (cmpai >= 0)) ? i_name : NULL;
389
390 if((error = determine_status(st, pm != NULL, pi != NULL, pa != NULL, m, entry, a, status_path(pm, pi, pa), path_type)) < GIT_SUCCESS)
391 return git__rethrow(error, "An error occured while determining the status of '%s'", a->ptr);
392
393 if ((pa != NULL) || (path_type == GIT_STATUS_PATH_FOLDER))
394 return GIT_SUCCESS;
395 }
396 }
397
398 static int status_cmp(const void *a, const void *b)
399 {
400 const struct status_entry *entry_a = (const struct status_entry *)(a);
401 const struct status_entry *entry_b = (const struct status_entry *)(b);
402
403 return strcmp(entry_a->path, entry_b->path);
404 }
405
406 #define DEFAULT_SIZE 16
407
408 int git_status_foreach(git_repository *repo, int (*callback)(const char *, unsigned int, void *), void *payload)
409 {
410 git_vector entries;
411 git_index *index = NULL;
412 git_buf temp_path = GIT_BUF_INIT;
413 struct status_st dirent_st = {0};
414 int error = GIT_SUCCESS;
415 unsigned int i;
416 git_tree *tree;
417 struct status_entry *e;
418 const char *workdir;
419
420 if ((workdir = git_repository_workdir(repo)) == NULL)
421 return git__throw(GIT_ERROR,
422 "Cannot retrieve status on a bare repository");
423
424 if ((error = git_repository_index__weakptr(&index, repo)) < GIT_SUCCESS) {
425 return git__rethrow(error,
426 "Failed to determine statuses. Index can't be opened");
427 }
428
429 if ((error = retrieve_head_tree(&tree, repo)) < GIT_SUCCESS) {
430 error = git__rethrow(error, "Failed to determine statuses");
431 goto exit;
432 }
433
434 git_vector_init(&entries, DEFAULT_SIZE, status_cmp);
435
436 dirent_st.workdir_path_len = strlen(workdir);
437 dirent_st.tree_position = 0;
438 dirent_st.index_position = 0;
439 dirent_st.tree = tree;
440 dirent_st.index = index;
441 dirent_st.vector = &entries;
442 git_buf_init(&dirent_st.head_tree_relative_path, 0);
443 dirent_st.head_tree_relative_path_len = 0;
444 dirent_st.is_dir = 1;
445
446 if (git_futils_isdir(workdir)) {
447 error = git__throw(GIT_EINVALIDPATH,
448 "Failed to determine status of file '%s'. "
449 "The given path doesn't lead to a folder", workdir);
450 goto exit;
451 }
452
453 git_buf_sets(&temp_path, workdir);
454
455 error = alphasorted_futils_direach(
456 &temp_path, dirent_cb, &dirent_st);
457
458 if (error < GIT_SUCCESS)
459 error = git__rethrow(error,
460 "Failed to determine statuses. "
461 "An error occured while processing the working directory");
462
463 if ((error == GIT_SUCCESS) && ((error = dirent_cb(&dirent_st, NULL)) < GIT_SUCCESS))
464 error = git__rethrow(error,
465 "Failed to determine statuses. "
466 "An error occured while post-processing the HEAD tree and the index");
467
468 for (i = 0; i < entries.length; ++i) {
469 e = (struct status_entry *)git_vector_get(&entries, i);
470
471 if (error == GIT_SUCCESS) {
472 error = callback(e->path, e->status_flags, payload);
473 if (error < GIT_SUCCESS)
474 error = git__rethrow(error,
475 "Failed to determine statuses. User callback failed");
476 }
477
478 git__free(e);
479 }
480
481 exit:
482 git_buf_free(&dirent_st.head_tree_relative_path);
483 git_buf_free(&temp_path);
484 git_vector_free(&entries);
485 git_tree_free(tree);
486 return error;
487 }
488
489 static int recurse_tree_entry(git_tree *tree, struct status_entry *e, const char *path)
490 {
491 char *dir_sep;
492 const git_tree_entry *tree_entry;
493 git_tree *subtree;
494 int error = GIT_SUCCESS;
495
496 dir_sep = strchr(path, '/');
497 if (!dir_sep) {
498 tree_entry = git_tree_entry_byname(tree, path);
499 if (tree_entry == NULL)
500 return GIT_SUCCESS; /* The leaf doesn't exist in the tree*/
501
502 status_entry_update_from_tree_entry(e, tree_entry);
503 return GIT_SUCCESS;
504 }
505
506 /* Retrieve subtree name */
507 *dir_sep = '\0';
508
509 tree_entry = git_tree_entry_byname(tree, path);
510 if (tree_entry == NULL)
511 return GIT_SUCCESS; /* The subtree doesn't exist in the tree*/
512
513 *dir_sep = '/';
514
515 /* Retreive subtree */
516 if ((error = git_tree_lookup(&subtree, tree->object.repo, &tree_entry->oid)) < GIT_SUCCESS)
517 return git__throw(GIT_EOBJCORRUPTED, "Can't find tree object '%s'", tree_entry->filename);
518
519 error = recurse_tree_entry(subtree, e, dir_sep+1);
520 git_tree_free(subtree);
521 return error;
522 }
523
524 int git_status_file(unsigned int *status_flags, git_repository *repo, const char *path)
525 {
526 struct status_entry *e;
527 git_index *index = NULL;
528 git_buf temp_path = GIT_BUF_INIT;
529 int error = GIT_SUCCESS;
530 git_tree *tree = NULL;
531 const char *workdir;
532
533 assert(status_flags && repo && path);
534
535 if ((workdir = git_repository_workdir(repo)) == NULL)
536 return git__throw(GIT_ERROR,
537 "Cannot retrieve status on a bare repository");
538
539 if ((error = git_buf_joinpath(&temp_path, workdir, path)) < GIT_SUCCESS)
540 return git__rethrow(error,
541 "Failed to determine status of file '%s'", path);
542
543 if (git_futils_isdir(temp_path.ptr) == GIT_SUCCESS) {
544 git_buf_free(&temp_path);
545 return git__throw(GIT_EINVALIDPATH,
546 "Failed to determine status of file '%s'. "
547 "Given path leads to a folder, not a file", path);
548 }
549
550 e = status_entry_new(NULL, path);
551 if (e == NULL) {
552 git_buf_free(&temp_path);
553 return GIT_ENOMEM;
554 }
555
556 /* Find file in Workdir */
557 if (git_futils_exists(temp_path.ptr) == GIT_SUCCESS) {
558 if ((error = status_entry_update_from_workdir(e, temp_path.ptr)) < GIT_SUCCESS)
559 goto cleanup; /* The callee has already set the error message */
560 }
561
562 /* Find file in Index */
563 if ((error = git_repository_index__weakptr(&index, repo)) < GIT_SUCCESS) {
564 git__rethrow(error,
565 "Failed to determine status of file '%s'."
566 "Index can't be opened", path);
567 goto cleanup;
568 }
569
570 status_entry_update_from_index(e, index);
571
572 if ((error = retrieve_head_tree(&tree, repo)) < GIT_SUCCESS) {
573 git__rethrow(error,
574 "Failed to determine status of file '%s'", path);
575 goto cleanup;
576 }
577
578 /* If the repository is not empty, try and locate the file in HEAD */
579 if (tree != NULL) {
580 if ((error = git_buf_sets(&temp_path, path)) < GIT_SUCCESS) {
581 git__rethrow(error,
582 "Failed to determine status of file '%s'", path);
583 goto cleanup;
584 }
585
586 error = recurse_tree_entry(tree, e, temp_path.ptr);
587 if (error < GIT_SUCCESS) {
588 git__rethrow(error,
589 "Failed to determine status of file '%s'. "
590 "An error occured while processing the tree", path);
591 goto cleanup;
592 }
593 }
594
595 /* Determine status */
596 if ((error = status_entry_update_flags(e)) < GIT_SUCCESS) {
597 git__throw(error, "Nonexistent file");
598 goto cleanup;
599 }
600
601 *status_flags = e->status_flags;
602
603 cleanup:
604 git_buf_free(&temp_path);
605 git_tree_free(tree);
606 git__free(e);
607 return error;
608 }
609
610 /*
611 * git_futils_direach is not supposed to return entries in an ordered manner.
612 * alphasorted_futils_direach wraps git_futils_direach and invokes the callback
613 * function by passing it alphabeticcally sorted paths parameters.
614 *
615 */
616
617 struct alphasorted_dirent_info {
618 int is_dir;
619 char path[GIT_FLEX_ARRAY]; /* more */
620 };
621
622 static struct alphasorted_dirent_info *alphasorted_dirent_info_new(const git_buf *path)
623 {
624 int is_dir, size;
625 struct alphasorted_dirent_info *di;
626
627 is_dir = git_futils_isdir(path->ptr) == GIT_SUCCESS ? 1 : 0;
628 size = sizeof(*di) + path->size + is_dir + 1;
629
630 di = git__calloc(size, 1);
631 if (di == NULL)
632 return NULL;
633
634 git_buf_copy_cstr(di->path, path->size + 1, path);
635
636 if (is_dir) {
637 di->is_dir = 1;
638
639 /*
640 * Append a forward slash to the name to force folders
641 * to be ordered in a similar way than in a tree
642 *
643 * The file "subdir" should appear before the file "subdir.txt"
644 * The folder "subdir" should appear after the file "subdir.txt"
645 */
646 di->path[path->size] = '/';
647 }
648
649 return di;
650 }
651
652 static int alphasorted_dirent_info_cmp(const void *a, const void *b)
653 {
654 struct alphasorted_dirent_info *stra = (struct alphasorted_dirent_info *)a;
655 struct alphasorted_dirent_info *strb = (struct alphasorted_dirent_info *)b;
656
657 return strcmp(stra->path, strb->path);
658 }
659
660 static int alphasorted_dirent_cb(void *state, git_buf *full_path)
661 {
662 struct alphasorted_dirent_info *entry;
663 git_vector *entry_names;
664
665 entry_names = (git_vector *)state;
666 entry = alphasorted_dirent_info_new(full_path);
667
668 if (entry == NULL)
669 return GIT_ENOMEM;
670
671 if (git_vector_insert(entry_names, entry) < GIT_SUCCESS) {
672 git__free(entry);
673 return GIT_ENOMEM;
674 }
675
676 return GIT_SUCCESS;
677 }
678
679 static int alphasorted_futils_direach(
680 git_buf *path,
681 int (*fn)(void *, git_buf *),
682 void *arg)
683 {
684 struct alphasorted_dirent_info *entry;
685 git_vector entry_names;
686 unsigned int idx;
687 int error = GIT_SUCCESS;
688 git_buf entry_path = GIT_BUF_INIT;
689
690 if (git_vector_init(&entry_names, 16, alphasorted_dirent_info_cmp) < GIT_SUCCESS)
691 return GIT_ENOMEM;
692
693 error = git_futils_direach(path, alphasorted_dirent_cb, &entry_names);
694
695 git_vector_sort(&entry_names);
696
697 for (idx = 0; idx < entry_names.length; ++idx) {
698 entry = (struct alphasorted_dirent_info *)git_vector_get(&entry_names, idx);
699
700 /* We have to walk the entire vector even if there was an error,
701 * in order to free up memory, but we stop making callbacks after
702 * an error.
703 */
704 if (error == GIT_SUCCESS)
705 error = git_buf_sets(&entry_path, entry->path);
706
707 if (error == GIT_SUCCESS) {
708 ((struct status_st *)arg)->is_dir = entry->is_dir;
709 error = fn(arg, &entry_path);
710 }
711
712 git__free(entry);
713 }
714
715 git_buf_free(&entry_path);
716 git_vector_free(&entry_names);
717 return error;
718 }