make got_worktree_stage() expect absolute on-disk paths
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
diff --git a/lib/worktree.c b/lib/worktree.c
index 969b659..c45b946 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -4858,25 +4858,21 @@ done:
}
static const struct got_error *
-stage_path(const char *path, size_t path_len, const char *path_content,
- struct got_worktree *worktree, struct got_fileindex *fileindex,
- struct got_repository *repo,
+stage_path(const char *relpath, const char *ondisk_path,
+ const char *path_content, struct got_worktree *worktree,
+ struct got_fileindex *fileindex, struct got_repository *repo,
got_worktree_status_cb status_cb, void *status_arg)
{
const struct got_error *err = NULL;
- char *ondisk_path;
struct got_fileindex_entry *ie;
unsigned char status;
struct stat sb;
struct got_object_id *blob_id = NULL;
uint32_t stage;
- if (asprintf(&ondisk_path, "%s/%s", worktree->root_path, path) == -1)
- return got_error_from_errno("asprintf");
-
- ie = got_fileindex_entry_get(fileindex, path, path_len);
+ ie = got_fileindex_entry_get(fileindex, relpath, strlen(relpath));
if (ie == NULL) {
- err = got_error_path(path, GOT_ERR_FILE_STATUS);
+ err = got_error_path(relpath, GOT_ERR_FILE_STATUS);
goto done;
}
@@ -4902,17 +4898,16 @@ stage_path(const char *path, size_t path_len, const char *path_content,
stage = GOT_FILEIDX_STAGE_DELETE;
break;
default:
- err = got_error_path(path, GOT_ERR_FILE_STATUS);
+ err = got_error_path(relpath, GOT_ERR_FILE_STATUS);
goto done;
}
got_fileindex_entry_stage_set(ie, stage);
/* XXX TODO pass 'staged' status separately */
- err = (*status_cb)(status_arg, status, path, blob_id, NULL);
+ err = (*status_cb)(status_arg, status, relpath, blob_id, NULL);
done:
free(blob_id);
- free(ondisk_path);
return err;
}
@@ -4936,8 +4931,15 @@ got_worktree_stage(struct got_worktree *worktree,
goto done;
TAILQ_FOREACH(pe, paths, entry) {
- err = stage_path(pe->path, pe->path_len, (const char *)pe->data,
- worktree, fileindex, repo, status_cb, status_arg);
+ char *relpath;
+ err = got_path_skip_common_ancestor(&relpath,
+ got_worktree_get_root_path(worktree), pe->path);
+ if (err)
+ break;
+ err = stage_path(relpath, pe->path,
+ (const char *)pe->data, worktree, fileindex, repo,
+ status_cb, status_arg);
+ free(relpath);
if (err)
break;
}