add an output argument to create_fileindex_entry() Avoids a pointless search of the file index in the case the caller needs to use the newly created file entry.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
diff --git a/lib/worktree.c b/lib/worktree.c
index 5abfa0d..d6fabd6 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -1105,13 +1105,15 @@ done:
}
static const struct got_error *
-create_fileindex_entry(struct got_fileindex *fileindex,
- struct got_object_id *base_commit_id, const char *ondisk_path,
- const char *path, struct got_object_id *blob_id)
+create_fileindex_entry(struct got_fileindex_entry **new_iep,
+ struct got_fileindex *fileindex, struct got_object_id *base_commit_id,
+ const char *ondisk_path, const char *path, struct got_object_id *blob_id)
{
const struct got_error *err = NULL;
struct got_fileindex_entry *new_ie;
+ *new_iep = NULL;
+
err = got_fileindex_entry_alloc(&new_ie, path);
if (err)
return err;
@@ -1125,6 +1127,8 @@ create_fileindex_entry(struct got_fileindex *fileindex,
done:
if (err)
got_fileindex_entry_free(new_ie);
+ else
+ *new_iep = new_ie;
return err;
}
@@ -1898,20 +1902,19 @@ update_blob(struct got_worktree *worktree,
}
if (err)
goto done;
+
if (ie) {
err = got_fileindex_entry_update(ie, ondisk_path,
blob->id.sha1, worktree->base_commit_id->sha1, 1);
} else {
- err = create_fileindex_entry(fileindex,
+ err = create_fileindex_entry(&ie, fileindex,
worktree->base_commit_id, ondisk_path, path,
&blob->id);
}
if (err)
goto done;
+
if (is_bad_symlink) {
- if (ie == NULL)
- ie = got_fileindex_entry_get(fileindex, path,
- strlen(path));
err = got_fileindex_entry_filetype_set(ie,
GOT_FILEIDX_MODE_BAD_SYMLINK);
if (err)