commit - 17ed46186c2a79ae984817ddcdab9f803f23636a
commit + 07f5b47a743b8436b0a26055e563b23c29e3cf28
blob - 39f7d97dd22baa55d4d1314bf1fb2f3a1875a135
blob + 2809f0b675dbf0558310513478adf02778dfe189
--- lib/worktree.c
+++ lib/worktree.c
return err;
}
+static const struct got_error *
+schedule_addition(const char *ondisk_path, struct got_fileindex *fileindex,
+ const char *relpath, got_worktree_status_cb status_cb, void *status_arg,
+ struct got_repository *repo)
+{
+ const struct got_error *err = NULL;
+ struct got_fileindex_entry *ie;
+
+ /* Re-adding an existing entry is a no-op. */
+ if (got_fileindex_entry_get(fileindex, relpath) != NULL)
+ return NULL;
+
+ err = got_fileindex_entry_alloc(&ie, ondisk_path, relpath, NULL, NULL);
+ if (err)
+ return err;
+
+ err = got_fileindex_entry_add(fileindex, ie);
+ if (err) {
+ got_fileindex_entry_free(ie);
+ return err;
+ }
+
+ return report_file_status(ie, relpath, status_cb, status_arg, repo);
+}
+
const struct got_error *
got_worktree_schedule_add(struct got_worktree *worktree,
struct got_pathlist_head *ondisk_paths,
goto done;
TAILQ_FOREACH(pe, ondisk_paths, entry) {
- struct got_fileindex_entry *ie = NULL;
char *relpath;
-
err = got_path_skip_common_ancestor(&relpath,
got_worktree_get_root_path(worktree), pe->path);
if (err)
goto done;
-
- /* Re-adding an existing entry is a no-op. */
- if (got_fileindex_entry_get(fileindex, relpath) != NULL)
- continue;
-
- err = got_fileindex_entry_alloc(&ie, pe->path, relpath,
- NULL, NULL);
+ err = schedule_addition(pe->path, fileindex, relpath,
+ status_cb, status_arg, repo);
free(relpath);
if (err)
goto done;
-
- err = got_fileindex_entry_add(fileindex, ie);
- if (err) {
- got_fileindex_entry_free(ie);
- goto done;
- }
-
- err = report_file_status(ie, pe->path, status_cb, status_arg,
- repo);
- if (err)
- goto done;
}
err = sync_fileindex(fileindex, fileindex_path);