commit 4bcdc8959af14bcb2e50c7f303df6c055573bc7a from: Omar Polo date: Tue May 17 17:35:17 2022 UTC refactor got_patch / got_worktree_patch_complete let got_patch own fileindex_path and call got_worktree_patch_complete only if got_wokrtree_patch_prepare hasn't failed. suggested by stsp@ commit - f2dd780737c47f6d92e6fe01cbd51bf93c91b3b3 commit + 4bcdc8959af14bcb2e50c7f303df6c055573bc7a blob - df7a870d179d5039ef98102550709b5ffff9889d blob + 610e03aa8788afbfcdcdc782c96c1c1965707674 --- include/got_worktree.h +++ include/got_worktree.h @@ -572,4 +572,4 @@ got_worktree_patch_schedule_rm(const char *, struct go /* Complete the patch operation. */ const struct got_error * -got_worktree_patch_complete(struct got_fileindex *, char *); +got_worktree_patch_complete(struct got_fileindex *, const char *); blob - cf2c864ecb722b3f8a59e4a0fc56d4be0a05d5b8 blob + 5567c9d7af0b485bd3e050850d053f429d2f1fb1 --- lib/patch.c +++ lib/patch.c @@ -710,7 +710,7 @@ got_patch(int fd, struct got_worktree *worktree, struc int nop, int strip, int reverse, got_patch_progress_cb progress_cb, void *progress_arg, got_cancel_cb cancel_cb, void *cancel_arg) { - const struct got_error *err = NULL, *complete_err; + const struct got_error *err = NULL, *complete_err = NULL; struct got_fileindex *fileindex = NULL; char *fileindex_path = NULL; char *oldpath, *newpath; @@ -798,9 +798,12 @@ got_patch(int fd, struct got_worktree *worktree, struc } done: - complete_err = got_worktree_patch_complete(fileindex, fileindex_path); + if (fileindex != NULL) + complete_err = got_worktree_patch_complete(fileindex, + fileindex_path); if (complete_err && err == NULL) err = complete_err; + free(fileindex_path); if (fd != -1 && close(fd) == -1 && err == NULL) err = got_error_from_errno("close"); if (ibuf != NULL) blob - e01fe524031c935a8e3f660c884d826abc5ca120 blob + ca8e4d6a6ba63c5f3e16487196a7a3bf16fa888b --- lib/worktree.c +++ lib/worktree.c @@ -8952,15 +8952,12 @@ got_worktree_patch_schedule_rm(const char *path, struc const struct got_error * got_worktree_patch_complete(struct got_fileindex *fileindex, - char *fileindex_path) + const char *fileindex_path) { const struct got_error *err = NULL; - if (fileindex) { - err = sync_fileindex(fileindex, fileindex_path); - got_fileindex_free(fileindex); - } + err = sync_fileindex(fileindex, fileindex_path); + got_fileindex_free(fileindex); - free(fileindex_path); return err; }