commit - 8ec7bf544b91f06b5397a8a49d567134bda525e8
commit + 3605a8140cfc3c18e051b6af5ebb6fb404968853
blob - f1a8eaa237c320ae2a51b94f0de8462067b07eec
blob + 4a682d42af7719b25a8ec3735f15f04f85e91a2e
--- lib/worktree.c
+++ lib/worktree.c
DIR *workdir = NULL;
char *fileindex_path = NULL;
struct got_fileindex *fileindex = NULL;
- FILE *index = NULL;
struct got_fileindex_diff_dir_cb fdiff_cb;
struct diff_dir_cb_arg arg;
char *ondisk_path = NULL;
- fileindex = got_fileindex_alloc();
- if (fileindex == NULL) {
- err = got_error_from_errno("got_fileindex_alloc");
- goto done;
- }
-
- if (asprintf(&fileindex_path, "%s/%s/%s", worktree->root_path,
- GOT_WORKTREE_GOT_DIR, GOT_WORKTREE_FILE_INDEX) == -1) {
- err = got_error_from_errno("asprintf");
- fileindex_path = NULL;
- goto done;
- }
-
- index = fopen(fileindex_path, "rb");
- if (index == NULL) {
- if (errno != ENOENT) {
- err = got_error_from_errno2("fopen", fileindex_path);
- goto done;
- }
- } else {
- err = got_fileindex_read(fileindex, index);
- fclose(index);
- if (err)
- goto done;
- }
+ 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) {
{
struct got_fileindex *fileindex = NULL;
char *fileindex_path = NULL;
- FILE *index = NULL;
const struct got_error *err = NULL, *sync_err, *unlockerr;
struct got_pathlist_entry *pe;
if (err)
return err;
-
- fileindex = got_fileindex_alloc();
- if (fileindex == NULL) {
- err = got_error_from_errno("got_fileindex_alloc");
- goto done;
- }
-
- if (asprintf(&fileindex_path, "%s/%s/%s", worktree->root_path,
- GOT_WORKTREE_GOT_DIR, GOT_WORKTREE_FILE_INDEX) == -1) {
- err = got_error_from_errno("asprintf");
- fileindex_path = NULL;
- goto done;
- }
-
- index = fopen(fileindex_path, "rb");
- if (index == NULL) {
- err = got_error_from_errno2("fopen", fileindex_path);
- goto done;
- }
-
- err = got_fileindex_read(fileindex, index);
+ err = open_fileindex(&fileindex, &fileindex_path, worktree);
if (err)
goto done;
if (sync_err && err == NULL)
err = sync_err;
done:
- if (index) {
- if (fclose(index) != 0 && err == NULL)
- err = got_error_from_errno("fclose");
- }
if (fileindex)
got_fileindex_free(fileindex);
unlockerr = lock_worktree(worktree, LOCK_SH);
{
struct got_fileindex *fileindex = NULL;
char *fileindex_path = NULL;
- FILE *index = NULL;
const struct got_error *err = NULL, *sync_err, *unlockerr;
struct got_pathlist_entry *pe;
if (err)
return err;
- fileindex = got_fileindex_alloc();
- if (fileindex == NULL) {
- err = got_error_from_errno("got_fileindex_alloc");
- goto done;
- }
-
- if (asprintf(&fileindex_path, "%s/%s/%s", worktree->root_path,
- GOT_WORKTREE_GOT_DIR, GOT_WORKTREE_FILE_INDEX) == -1) {
- err = got_error_from_errno("asprintf");
- fileindex_path = NULL;
- goto done;
- }
-
- index = fopen(fileindex_path, "rb");
- if (index == NULL) {
- err = got_error_from_errno2("fopen", fileindex_path);
- goto done;
- }
-
- err = got_fileindex_read(fileindex, index);
+ err = open_fileindex(&fileindex, &fileindex_path, worktree);
if (err)
goto done;
if (sync_err && err == NULL)
err = sync_err;
done:
- if (index) {
- if (fclose(index) != 0 && err == NULL)
- err = got_error_from_errno("fclose");
- }
if (fileindex)
got_fileindex_free(fileindex);
unlockerr = lock_worktree(worktree, LOCK_SH);
{
struct got_fileindex *fileindex = NULL;
char *fileindex_path = NULL;
- FILE *index = NULL;
const struct got_error *err = NULL, *unlockerr = NULL;
const struct got_error *sync_err = NULL;
struct got_pathlist_entry *pe;
if (err)
return err;
- fileindex = got_fileindex_alloc();
- if (fileindex == NULL) {
- err = got_error_from_errno("got_fileindex_alloc");
- goto done;
- }
-
- if (asprintf(&fileindex_path, "%s/%s/%s", worktree->root_path,
- GOT_WORKTREE_GOT_DIR, GOT_WORKTREE_FILE_INDEX) == -1) {
- err = got_error_from_errno("asprintf");
- fileindex_path = NULL;
- goto done;
- }
-
- index = fopen(fileindex_path, "rb");
- if (index == NULL) {
- err = got_error_from_errno2("fopen", fileindex_path);
- goto done;
- }
-
- err = got_fileindex_read(fileindex, index);
+ err = open_fileindex(&fileindex, &fileindex_path, worktree);
if (err)
goto done;
if (sync_err && err == NULL)
err = sync_err;
done:
- if (index) {
- if (fclose(index) != 0 && err == NULL)
- err = got_error_from_errno("fclose");
- }
if (fileindex)
got_fileindex_free(fileindex);
unlockerr = lock_worktree(worktree, LOCK_SH);