commit - 234035bc7943e32aa92668438f4c0ba9c85e2f83
commit + 9c6338c4052d0127c812ecc3bd4a5ddde55ba2f0
blob - 91723c534485c31a0ef0cf0edbbfcf1805d77afb
blob + bf46d7caa36ff6b6f886316e5eb111732546b6d5
--- lib/worktree.c
+++ lib/worktree.c
memcpy(ie->commit_sha1, a->base_commit_id->sha1, SHA1_DIGEST_LENGTH);
return NULL;
+}
+
+static const struct got_error *
+sync_fileindex(struct got_fileindex *fileindex, const char *fileindex_path)
+{
+ const struct got_error *err = NULL;
+ char *new_fileindex_path = NULL;
+ FILE *new_index = NULL;
+
+ err = got_opentemp_named(&new_fileindex_path, &new_index,
+ fileindex_path);
+ if (err)
+ goto done;
+
+ err = got_fileindex_write(fileindex, new_index);
+ if (err)
+ goto done;
+
+ if (rename(new_fileindex_path, fileindex_path) != 0) {
+ err = got_error_from_errno3("rename", new_fileindex_path,
+ fileindex_path);
+ unlink(new_fileindex_path);
+ }
+done:
+ if (new_index)
+ fclose(new_index);
+ free(new_fileindex_path);
+ return err;
}
const struct got_error *
struct got_commit_object *commit = NULL;
struct got_object_id *tree_id = NULL;
struct got_tree_object *tree = NULL;
- char *fileindex_path = NULL, *new_fileindex_path = NULL;
struct got_fileindex *fileindex = NULL;
- FILE *new_index = NULL;
+ char *fileindex_path = NULL;
struct got_fileindex_diff_tree_cb diff_cb;
struct diff_cb_arg arg;
char *relpath = NULL, *entry_name = NULL;
if (err)
goto done;
- err = got_opentemp_named(&new_fileindex_path, &new_index,
- fileindex_path);
- if (err)
- goto done;
-
err = ref_base_commit(worktree, repo);
if (err)
goto done;
}
/* Try to sync the fileindex back to disk in any case. */
- err = got_fileindex_write(fileindex, new_index);
- if (err)
- goto done;
-
- if (rename(new_fileindex_path, fileindex_path) != 0) {
- err = got_error_from_errno3("rename", new_fileindex_path,
- fileindex_path);
- unlink(new_fileindex_path);
- goto done;
- }
-
- free(new_fileindex_path);
- new_fileindex_path = NULL;
-
+ err = sync_fileindex(fileindex, fileindex_path);
done:
+ free(fileindex_path);
free(relpath);
if (tree)
got_object_tree_close(tree);
if (commit)
got_object_commit_close(commit);
- if (new_fileindex_path)
- unlink(new_fileindex_path);
- if (new_index)
- fclose(new_index);
- free(new_fileindex_path);
- free(fileindex_path);
got_fileindex_free(fileindex);
if (checkout_err)
err = checkout_err;
arg.cancel_cb = cancel_cb;
arg.cancel_arg = cancel_arg;
err = got_diff_tree(tree1, tree2, "", "", repo, merge_file_cb, &arg);
+ if (err)
+ goto done;
+
+ err = sync_fileindex(fileindex, fileindex_path);
done:
- free(fileindex_path);
got_fileindex_free(fileindex);
if (tree1)
got_object_tree_close(tree1);
struct got_repository *repo)
{
struct got_fileindex *fileindex = NULL;
- char *fileindex_path = NULL, *new_fileindex_path = NULL;
- FILE *index = NULL, *new_index = NULL;
+ char *fileindex_path = NULL;
+ FILE *index = NULL;
const struct got_error *err = NULL, *unlockerr = NULL;
struct got_pathlist_entry *pe;
goto done;
}
- err = got_opentemp_named(&new_fileindex_path, &new_index,
- fileindex_path);
- if (err)
- goto done;
-
- err = got_fileindex_write(fileindex, new_index);
- if (err)
- goto done;
-
- if (rename(new_fileindex_path, fileindex_path) != 0) {
- err = got_error_from_errno3("rename", new_fileindex_path,
- fileindex_path);
- goto done;
- }
-
- free(new_fileindex_path);
- new_fileindex_path = NULL;
-
+ err = sync_fileindex(fileindex, fileindex_path);
done:
if (index) {
if (fclose(index) != 0 && err == NULL)
err = got_error_from_errno("fclose");
- }
- if (new_fileindex_path) {
- if (unlink(new_fileindex_path) != 0 && err == NULL)
- err = got_error_from_errno2("unlink",
- new_fileindex_path);
- free(new_fileindex_path);
}
if (fileindex)
got_fileindex_free(fileindex);
{
struct got_fileindex *fileindex = NULL;
struct got_fileindex_entry *ie = NULL;
- char *relpath, *fileindex_path = NULL, *new_fileindex_path = NULL;
- FILE *index = NULL, *new_index = NULL;
+ char *relpath, *fileindex_path ;
+ FILE *index = NULL;
const struct got_error *err = NULL, *unlockerr = NULL;
unsigned char status;
struct stat sb;
got_fileindex_entry_mark_deleted_from_disk(ie);
- err = got_opentemp_named(&new_fileindex_path, &new_index,
- fileindex_path);
+ err = sync_fileindex(fileindex, fileindex_path);
if (err)
goto done;
-
- err = got_fileindex_write(fileindex, new_index);
- if (err)
- goto done;
-
- if (rename(new_fileindex_path, fileindex_path) != 0) {
- err = got_error_from_errno3("rename", new_fileindex_path,
- fileindex_path);
- goto done;
- }
-
- free(new_fileindex_path);
- new_fileindex_path = NULL;
err = report_file_status(ie, ondisk_path, status_cb, status_arg, repo);
done:
if (fclose(index) != 0 && err == NULL)
err = got_error_from_errno("fclose");
}
- if (new_fileindex_path) {
- if (unlink(new_fileindex_path) != 0 && err == NULL)
- err = got_error_from_errno2("unlink",
- new_fileindex_path);
- free(new_fileindex_path);
- }
if (fileindex)
got_fileindex_free(fileindex);
unlockerr = lock_worktree(worktree, LOCK_SH);
{
struct got_fileindex *fileindex = NULL;
struct got_fileindex_entry *ie = NULL;
- char *relpath, *fileindex_path = NULL, *new_fileindex_path = NULL;
+ char *relpath, *fileindex_path = NULL;
char *tree_path = NULL, *parent_path, *te_name;
- FILE *index = NULL, *new_index = NULL;
+ FILE *index = NULL;
const struct got_error *err = NULL, *unlockerr = NULL;
struct got_tree_object *tree = NULL;
struct got_object_id id, *tree_id = NULL;
goto done;
}
- err = got_opentemp_named(&new_fileindex_path, &new_index,
- fileindex_path);
+ err = sync_fileindex(fileindex, fileindex_path);
if (err)
- goto done;
-
- err = got_fileindex_write(fileindex, new_index);
- if (err)
- goto done;
-
- if (rename(new_fileindex_path, fileindex_path) != 0) {
- err = got_error_from_errno3("rename", new_fileindex_path,
- fileindex_path);
goto done;
- }
-
- free(new_fileindex_path);
- new_fileindex_path = NULL;
done:
free(relpath);
free(tree_path);
if (fclose(index) != 0 && err == NULL)
err = got_error_from_errno("fclose");
}
- if (new_fileindex_path) {
- if (unlink(new_fileindex_path) != 0 && err == NULL)
- err = got_error_from_errno2("unlink",
- new_fileindex_path);
- free(new_fileindex_path);
- }
if (fileindex)
got_fileindex_free(fileindex);
unlockerr = lock_worktree(worktree, LOCK_SH);
struct got_object_id *new_base_commit_id, struct got_worktree *worktree)
{
const struct got_error *err = NULL;
- char *fileindex_path = NULL, *new_fileindex_path = NULL;
+ char *fileindex_path = NULL;
struct got_fileindex *fileindex = NULL;
- FILE *new_index = NULL;
struct got_pathlist_entry *pe;
err = open_fileindex(&fileindex, &fileindex_path, worktree);
if (err)
return err;
- err = got_opentemp_named(&new_fileindex_path, &new_index,
- fileindex_path);
- if (err)
- goto done;
-
TAILQ_FOREACH(pe, commitable_paths, entry) {
struct got_fileindex_entry *ie;
struct got_commitable *ct = pe->data;
}
}
- err = got_fileindex_write(fileindex, new_index);
- if (err)
- goto done;
-
- if (rename(new_fileindex_path, fileindex_path) != 0) {
- err = got_error_from_errno3("rename", new_fileindex_path,
- fileindex_path);
- unlink(new_fileindex_path);
- goto done;
- }
-
- free(new_fileindex_path);
- new_fileindex_path = NULL;
-
+ err = sync_fileindex(fileindex, fileindex_path);
done:
- if (new_fileindex_path)
- unlink(new_fileindex_path);
- if (new_index)
- fclose(new_index);
- free(new_fileindex_path);
free(fileindex_path);
got_fileindex_free(fileindex);
return err;