commit 031a5338903e1e2bbb80b6f1e17d58a5a6374271 from: Stefan Sperling date: Tue Mar 26 09:46:18 2019 UTC make got_worktree_schedule_add() report 'added' via status_cb commit - c2253644018132a8c4b267e35612a927606904b5 commit + 031a5338903e1e2bbb80b6f1e17d58a5a6374271 blob - c37a9a280271db6641303be9f76910b0e5d5aa2c blob + b6b518579e34e85b27052c4b28680fef25d63669 --- got/got.c +++ got/got.c @@ -1855,6 +1855,7 @@ static const struct got_error * cmd_add(int argc, char *argv[]) { const struct got_error *error = NULL; + struct got_repository *repo = NULL; struct got_worktree *worktree = NULL; char *cwd = NULL, *path = NULL, *relpath = NULL; int ch; @@ -1888,15 +1889,22 @@ cmd_add(int argc, char *argv[]) if (error) goto done; - error = apply_unveil(NULL, 0, got_worktree_get_root_path(worktree)); + error = got_repo_open(&repo, got_worktree_get_repo_path(worktree)); + if (error != NULL) + goto done; + + error = apply_unveil(got_repo_get_path(repo), 1, + got_worktree_get_root_path(worktree)); if (error) goto done; - error = got_worktree_schedule_add(&relpath, worktree, path); + error = got_worktree_schedule_add(worktree, path, print_status, NULL, + repo); if (error) goto done; - printf("%c %s\n", GOT_STATUS_ADD, relpath); done: + if (repo) + got_repo_close(repo); if (worktree) got_worktree_close(worktree); free(path); blob - 51e30c84ed559444e681b1e0d16454d4bf167cee blob + d6cae67b59be7b305f805fc6a0b6590bff63815c --- include/got_worktree.h +++ include/got_worktree.h @@ -132,13 +132,9 @@ const struct got_error *got_worktree_status(struct got const struct got_error *got_worktree_resolve_path(char **, struct got_worktree *, const char *); -/* - * Schedule a file at an on-disk path for addition in the next commit. - * Return the added file's path relative to the root of the work tree. - * The caller must dispose of this relative path with free(3). - */ -const struct got_error *got_worktree_schedule_add(char **, - struct got_worktree *, const char *); +/* Schedule a file at an on-disk path for addition in the next commit. */ +const struct got_error *got_worktree_schedule_add(struct got_worktree *, + const char *, got_worktree_status_cb, void *, struct got_repository *); /* * Remove a file from disk and schedule it to be deleted in the next commit. blob - 9b86570baa1094b9fc829a3d2d4e98e1faf72521 blob + 45ca7be94cdab1bb2773b7db0bd0c221c06b1516 --- lib/worktree.c +++ lib/worktree.c @@ -1601,27 +1601,27 @@ done: } const struct got_error * -got_worktree_schedule_add(char **relpath, struct got_worktree *worktree, - const char *ondisk_path) +got_worktree_schedule_add(struct got_worktree *worktree, + const char *ondisk_path, got_worktree_status_cb status_cb, void *status_arg, + struct got_repository *repo) { struct got_fileindex *fileindex = NULL; struct got_fileindex_entry *ie = NULL; - char *fileindex_path = NULL, *new_fileindex_path = NULL; + char *relpath, *fileindex_path = NULL, *new_fileindex_path = NULL; FILE *index = NULL, *new_index = NULL; const struct got_error *err = NULL, *unlockerr = NULL; + int ie_added = 0; - *relpath = NULL; - err = lock_worktree(worktree, LOCK_EX); if (err) return err; - err = got_path_skip_common_ancestor(relpath, + err = got_path_skip_common_ancestor(&relpath, got_worktree_get_root_path(worktree), ondisk_path); if (err) goto done; - err = got_fileindex_entry_alloc(&ie, ondisk_path, *relpath, NULL, NULL); + err = got_fileindex_entry_alloc(&ie, ondisk_path, relpath, NULL, NULL); if (err) goto done; @@ -1651,7 +1651,7 @@ got_worktree_schedule_add(char **relpath, struct got_w err = got_fileindex_entry_add(fileindex, ie); if (err) goto done; - ie = NULL; /* now owned by fileindex; don't free separately */ + ie_added = 1; /* now owned by fileindex; don't free separately */ err = got_opentemp_named(&new_fileindex_path, &new_index, fileindex_path); @@ -1669,6 +1669,8 @@ got_worktree_schedule_add(char **relpath, struct got_w free(new_fileindex_path); new_fileindex_path = NULL; + + err = report_file_status(ie, ondisk_path, status_cb, status_arg, repo); done: if (index) { if (fclose(index) != 0 && err == NULL) @@ -1679,17 +1681,14 @@ done: err = got_error_from_errno(); free(new_fileindex_path); } - if (ie) + if (!ie_added) got_fileindex_entry_free(ie); if (fileindex) got_fileindex_free(fileindex); unlockerr = lock_worktree(worktree, LOCK_SH); if (unlockerr && err == NULL) err = unlockerr; - if (err) { - free(*relpath); - *relpath = NULL; - } + free(relpath); return err; }