writing the lowest level of trees works now
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
diff --git a/lib/worktree.c b/lib/worktree.c
index 4ddafdd..48514a2 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -2204,6 +2204,7 @@ struct commitable {
char *path;
unsigned char status;
struct got_object_id *id;
+ struct got_object_id *base_id;
struct got_object_id *tree_id;
};
@@ -2212,6 +2213,7 @@ free_commitable(struct commitable *ct)
{
free(ct->path);
free(ct->id);
+ free(ct->base_id);
free(ct->tree_id);
free(ct);
}
@@ -2257,6 +2259,11 @@ collect_commitables(void *arg, unsigned char status, const char *path,
ct->status = status;
ct->id = NULL;
+ ct->base_id = got_object_id_dup(id);
+ if (ct->base_id == NULL) {
+ err = got_error_from_errno();
+ goto done;
+ }
err = got_object_id_by_path(&ct->tree_id, a->repo,
a->worktree->base_commit_id, parent_path);
if (err)
@@ -2294,6 +2301,8 @@ write_tree(struct got_object_id *base_tree_id, void *data, void *arg)
struct got_object_id *new_tree_id = NULL;
TAILQ_INIT(&new_entries);
+ new_tree_entries.nentries = 0;
+ SIMPLEQ_INIT(&new_tree_entries.head);
err = got_object_open_as_tree(&base_tree, a->repo, base_tree_id);
if (err)
@@ -2302,15 +2311,16 @@ write_tree(struct got_object_id *base_tree_id, void *data, void *arg)
base_entries = got_object_tree_get_entries(base_tree);
SIMPLEQ_FOREACH(te, &base_entries->head, entry) {
+ struct got_tree_entry *new_te = NULL;
+ struct got_pathlist_entry *new_pe = NULL;
+ int ct_found = 0;
TAILQ_FOREACH(pe, a->commitable_paths, entry) {
struct commitable *ct = NULL;
- struct got_tree_entry *new_te = NULL;
- struct got_pathlist_entry *new_pe = NULL;
char *ct_name = NULL;
ct = pe->data;
- if (got_object_id_cmp(ct->tree_id, te->id) != 0)
+ if (got_object_id_cmp(ct->base_id, te->id) != 0)
continue; /* not part of this tree */
ct_name = basename(pe->path);
@@ -2322,9 +2332,11 @@ write_tree(struct got_object_id *base_tree_id, void *data, void *arg)
if (strcmp(te->name, ct_name) != 0)
continue;
+ ct_found = 1;
+
if (ct->status == GOT_STATUS_DELETE) {
/* Deleted entries disappear. */
- continue;
+ break;
}
/* Modified entries get updated mode and ID. */
@@ -2332,7 +2344,6 @@ write_tree(struct got_object_id *base_tree_id, void *data, void *arg)
err = got_object_tree_entry_dup(&new_te, te);
if (err)
goto done;
- new_te->mode = GOT_DEFAULT_FILE_MODE; /* XXX */
free(new_te->id);
} else if (ct->status == GOT_STATUS_ADD) {
/* Added entries get... well, added. */
@@ -2341,32 +2352,39 @@ write_tree(struct got_object_id *base_tree_id, void *data, void *arg)
err = got_error_from_errno();
goto done;
}
- new_te->mode = GOT_DEFAULT_FILE_MODE; /* XXX */
new_te->name = strdup(ct_name);
if (new_te->name == NULL) {
err = got_error_from_errno();
goto done;
}
}
+ new_te->mode = GOT_DEFAULT_FILE_MODE; /* XXX */
new_te->id = got_object_id_dup(ct->id);
if (new_te->id == NULL) {
err = got_error_from_errno();
goto done;
}
+ break;
+ }
- err = got_pathlist_insert(&new_pe, &new_entries,
- te->name, new_te);
+ if (new_te == NULL) {
+ if (ct_found) /* GOT_STATUS_DELETE */
+ continue;
+ err = got_object_tree_entry_dup(&new_te, te);
if (err)
goto done;
- if (new_pe == NULL) {
- err = got_error(GOT_ERR_TREE_DUP_ENTRY);
- goto done;
- }
+ }
+
+ err = got_pathlist_insert(&new_pe, &new_entries,
+ new_te->name, new_te);
+ if (err)
+ goto done;
+ if (new_pe == NULL) {
+ err = got_error(GOT_ERR_TREE_DUP_ENTRY);
+ goto done;
}
}
- new_tree_entries.nentries = 0;
- SIMPLEQ_INIT(&new_tree_entries.head);
TAILQ_FOREACH(pe, &new_entries, entry) {
struct got_tree_entry *te = pe->data;
new_tree_entries.nentries++;
@@ -2376,10 +2394,10 @@ write_tree(struct got_object_id *base_tree_id, void *data, void *arg)
err = got_object_tree_create(&new_tree_id, &new_tree_entries, a->repo);
done:
free(new_tree_id);
+ got_object_tree_entries_close(&new_tree_entries);
+ got_pathlist_free(&new_entries);
if (base_tree)
got_object_tree_close(base_tree);
- got_pathlist_free(&new_entries);
- got_object_tree_entries_close(&new_tree_entries);
return err;
}