Commit Diff


commit - 5e22b7375b034172c405da8657858663d1051eb3
commit + 36832a8e24b87436ab3bb16483022e6e6d458699
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 - d839f0b09e4b212b919a562a9c3f31e974d718ed
blob + a1a6e6cc16f5af1f3f7f634010c8ae050814f186
--- lib/patch.c
+++ lib/patch.c
@@ -707,7 +707,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;
@@ -795,9 +795,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 - 4b4d9c7fe17283dd56b89923ad3705aa52e12ad1
blob + 0bd2cc6f29e0c093db50c5fcf3546a526a3c9e1f
--- lib/worktree.c
+++ lib/worktree.c
@@ -8949,15 +8949,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;
 }