commit 347d1d3e2dfb259ebdcaf3ce280b6dcdcedcaa6f from: Stefan Sperling date: Fri Jul 12 13:04:27 2019 UTC eliminate redundant fileindex open for status during commit and rebase -a commit - 55bd499d8ff69fab8462d256adae072aa762727f commit + 347d1d3e2dfb259ebdcaf3ce280b6dcdcedcaa6f blob - cf788412d7d82a9e76021c6f880b299fe5b307f2 blob + 1bd7e852da64d1f96f8debd8b8ab459dff0a64a8 --- lib/worktree.c +++ lib/worktree.c @@ -2153,23 +2153,18 @@ status_new(void *arg, struct dirent *de, const char *p return err; } -const struct got_error * -got_worktree_status(struct got_worktree *worktree, const char *path, - struct got_repository *repo, got_worktree_status_cb status_cb, - void *status_arg, got_worktree_cancel_cb cancel_cb, void *cancel_arg) +static const struct got_error * +worktree_status(struct got_worktree *worktree, const char *path, + struct got_fileindex *fileindex, struct got_repository *repo, + got_worktree_status_cb status_cb, void *status_arg, + got_worktree_cancel_cb cancel_cb, void *cancel_arg) { const struct got_error *err = NULL; DIR *workdir = NULL; - char *fileindex_path = NULL; - struct got_fileindex *fileindex = NULL; struct got_fileindex_diff_dir_cb fdiff_cb; struct diff_dir_cb_arg arg; char *ondisk_path = NULL; - err = open_fileindex(&fileindex, &fileindex_path, worktree); - if (err) - return err; - if (asprintf(&ondisk_path, "%s%s%s", worktree->root_path, path[0] ? "/" : "", path) == -1) { err = got_error_from_errno("asprintf"); @@ -2210,6 +2205,24 @@ done: if (workdir) closedir(workdir); free(ondisk_path); + return err; +} + +const struct got_error * +got_worktree_status(struct got_worktree *worktree, const char *path, + struct got_repository *repo, got_worktree_status_cb status_cb, + void *status_arg, got_worktree_cancel_cb cancel_cb, void *cancel_arg) +{ + const struct got_error *err = NULL; + char *fileindex_path = NULL; + struct got_fileindex *fileindex = NULL; + + err = open_fileindex(&fileindex, &fileindex_path, worktree); + if (err) + return err; + + err = worktree_status(worktree, path, fileindex, repo, + status_cb, status_arg, cancel_cb, cancel_arg); free(fileindex_path); got_fileindex_free(fileindex); return err; @@ -3262,6 +3275,10 @@ got_worktree_commit(struct got_object_id **new_commit_ if (err) goto done; + err = open_fileindex(&fileindex, &fileindex_path, worktree); + if (err) + goto done; + err = got_ref_open(&head_ref, repo, worktree->head_ref_name, 0); if (err) goto done; @@ -3272,8 +3289,8 @@ got_worktree_commit(struct got_object_id **new_commit_ cc_arg.commitable_paths = &commitable_paths; cc_arg.worktree = worktree; cc_arg.repo = repo; - err = got_worktree_status(worktree, relpath ? relpath : "", - repo, collect_commitables, &cc_arg, NULL, NULL); + err = worktree_status(worktree, relpath ? relpath : "", + fileindex, repo, collect_commitables, &cc_arg, NULL, NULL); if (err) goto done; @@ -3379,10 +3396,6 @@ got_worktree_commit(struct got_object_id **new_commit_ 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, fileindex, worktree); if (err) @@ -4026,14 +4039,14 @@ got_worktree_rebase_abort(struct got_worktree *worktre if (err) goto done; - crp_arg.revertible_paths = &revertible_paths; - crp_arg.worktree = worktree; - err = got_worktree_status(worktree, "", repo, - collect_revertible_paths, &crp_arg, NULL, NULL); + err = open_fileindex(&fileindex, &fileindex_path, worktree); if (err) goto done; - err = open_fileindex(&fileindex, &fileindex_path, worktree); + crp_arg.revertible_paths = &revertible_paths; + crp_arg.worktree = worktree; + err = worktree_status(worktree, "", fileindex, repo, + collect_revertible_paths, &crp_arg, NULL, NULL); if (err) goto done;