refactor file index syncing out of update_fileindex_after_commit()
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
diff --git a/lib/worktree.c b/lib/worktree.c
index b663092..f1a8eaa 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -3110,17 +3110,12 @@ done:
static const struct got_error *
update_fileindex_after_commit(struct got_pathlist_head *commitable_paths,
- struct got_object_id *new_base_commit_id, struct got_worktree *worktree)
+ struct got_object_id *new_base_commit_id, struct got_fileindex *fileindex,
+ struct got_worktree *worktree)
{
- const struct got_error *err = NULL, *sync_err;
- char *fileindex_path = NULL;
- struct got_fileindex *fileindex = NULL;
+ const struct got_error *err = NULL;
struct got_pathlist_entry *pe;
- err = open_fileindex(&fileindex, &fileindex_path, worktree);
- if (err)
- return err;
-
TAILQ_FOREACH(pe, commitable_paths, entry) {
struct got_fileindex_entry *ie;
struct got_commitable *ct = pe->data;
@@ -3145,11 +3140,6 @@ update_fileindex_after_commit(struct got_pathlist_head *commitable_paths,
break;
}
}
- sync_err = sync_fileindex(fileindex, fileindex_path);
- if (sync_err && err == NULL)
- err = sync_err;
- free(fileindex_path);
- got_fileindex_free(fileindex);
return err;
}
@@ -3265,7 +3255,9 @@ got_worktree_commit(struct got_object_id **new_commit_id,
got_worktree_status_cb status_cb, void *status_arg,
struct got_repository *repo)
{
- const struct got_error *err = NULL, *unlockerr = NULL;
+ const struct got_error *err = NULL, *unlockerr = NULL, *sync_err;
+ struct got_fileindex *fileindex = NULL;
+ char *fileindex_path = NULL;
struct collect_commitables_arg cc_arg;
struct got_pathlist_head commitable_paths;
struct got_pathlist_entry *pe;
@@ -3415,11 +3407,22 @@ got_worktree_commit(struct got_object_id **new_commit_id,
if (err)
goto done;
+ err = open_fileindex(&fileindex, &fileindex_path, worktree);
+ if (err)
+ goto done;
+
err = update_fileindex_after_commit(&commitable_paths,
- *new_commit_id, worktree);
+ *new_commit_id, fileindex, worktree);
if (err)
goto done;
done:
+ if (fileindex) {
+ sync_err = sync_fileindex(fileindex, fileindex_path);
+ if (sync_err && err == NULL)
+ err = sync_err;
+ got_fileindex_free(fileindex);
+ }
+ free(fileindex_path);
unlockerr = lock_worktree(worktree, LOCK_SH);
if (unlockerr && err == NULL)
err = unlockerr;