commit - f2c16586bf7eef0299baac130ef7b91666023712
commit + 768aea60a17834a020b4c7ddd4cb6c3c3496debc
blob - d2d1a1e5b9f28edf231797d5d56c665283746c11
blob + e384ebc955c80bfb8377f98004ea75fd12568b56
--- lib/worktree.c
+++ lib/worktree.c
struct commitable {
char *path;
+ char *ondisk_path;
unsigned char status;
struct got_object_id *id;
struct got_object_id *base_id;
+ mode_t mode;
};
static void
free_commitable(struct commitable *ct)
{
free(ct->path);
+ free(ct->ondisk_path);
free(ct->id);
free(ct->base_id);
free(ct);
struct commitable *ct = NULL;
struct got_pathlist_entry *new = NULL;
char *parent_path = NULL, *path = NULL;
+ struct stat sb;
if (status == GOT_STATUS_CONFLICT)
return got_error(GOT_ERR_COMMIT_CONFLICT);
if (ct == NULL) {
err = got_error_from_errno();
goto done;
+ }
+
+ if (asprintf(&ct->ondisk_path, "%s/%s", a->worktree->root_path,
+ relpath) == -1) {
+ err = got_error_from_errno();
+ goto done;
+ }
+ if (status == GOT_STATUS_DELETE) {
+ sb.st_mode = GOT_DEFAULT_FILE_MODE;
+ } else {
+ if (lstat(ct->ondisk_path, &sb) != 0) {
+ err = got_error_from_errno();
+ goto done;
+ }
+ ct->mode = sb.st_mode;
}
ct->status = status;
return err;
}
+static mode_t
+get_ct_file_mode(struct commitable *ct)
+{
+ return S_IFREG | (ct->mode & ((S_IRWXU | S_IRWXG | S_IRWXO)));
+}
+
static const struct got_error *
alloc_modified_blob_tree_entry(struct got_tree_entry **new_te,
struct got_tree_entry *te, struct commitable *ct)
if (err)
goto done;
- /* XXX TODO: update mode from disk (derive from ct?)! */
- (*new_te)->mode = GOT_DEFAULT_FILE_MODE;
+ (*new_te)->mode = get_ct_file_mode(ct);
free((*new_te)->id);
(*new_te)->id = got_object_id_dup(ct->id);
goto done;
}
- /* XXX TODO: update mode from disk (derive from ct?)! */
- (*new_te)->mode = GOT_DEFAULT_FILE_MODE;
+ (*new_te)->mode = get_ct_file_mode(ct);
(*new_te)->id = got_object_id_dup(ct->id);
if ((*new_te)->id == NULL) {
*slash = '\0'; /* trim trailing path components */
new_te = calloc(1, sizeof(*new_te));
- new_te->mode = GOT_DEFAULT_DIR_MODE;
+ new_te->mode = S_IFDIR;
new_te->name = strdup(child_path);
if (new_te->name == NULL) {
got_object_tree_entry_close(new_te);
TAILQ_FOREACH(pe, commitable_paths, entry) {
struct got_fileindex_entry *ie;
struct commitable *ct = pe->data;
- char *ondisk_path;
-
- if (asprintf(&ondisk_path, "%s/%s",
- worktree->root_path, pe->path) == -1) {
- err = got_error_from_errno();
- goto done;
- }
ie = got_fileindex_entry_get(fileindex, pe->path);
if (ie) {
got_fileindex_entry_free(ie);
} else
err = got_fileindex_entry_update(ie,
- ondisk_path, ct->id->sha1,
+ ct->ondisk_path, ct->id->sha1,
new_base_commit_id->sha1, 1);
} else {
err = got_fileindex_entry_alloc(&ie,
- ondisk_path, pe->path, ct->id->sha1,
+ ct->ondisk_path, pe->path, ct->id->sha1,
new_base_commit_id->sha1);
if (err)
goto done;
if (err)
goto done;
}
- free(ondisk_path);
}
err = got_fileindex_write(fileindex, new_index);