Remove old status implementation This removes the code for the old status implementation.
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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
diff --git a/src/status.c b/src/status.c
index 0732d4a..8d2c7de 100644
--- a/src/status.c
+++ b/src/status.c
@@ -345,316 +345,6 @@ static int status_entry_update_ignore(struct status_entry *e, git_ignores *ignor
return 0;
}
-struct status_st {
- git_repository *repo;
- git_vector *vector;
- git_index *index;
- git_tree *tree;
- git_ignores *ignores;
-
- int workdir_path_len;
- git_buf head_tree_relative_path;
- int head_tree_relative_path_len;
- unsigned int tree_position;
- unsigned int index_position;
- int is_dir:1;
-};
-
-static int retrieve_head_tree(git_tree **tree_out, git_repository *repo)
-{
- git_reference *resolved_head_ref;
- git_commit *head_commit = NULL;
- git_tree *tree;
- int error = 0;
-
- *tree_out = NULL;
-
- if ((error = git_repository_head(&resolved_head_ref, repo)) < 0) {
- /* Assume that a situation where HEAD exists but can not be resolved
- * is valid. A new repository fits this description for instance.
- */
- if (error == GIT_ENOTFOUND)
- return 0;
- return error;
- }
-
- if ((error = git_commit_lookup(
- &head_commit, repo, git_reference_oid(resolved_head_ref))) < 0)
- return error;
-
- git_reference_free(resolved_head_ref);
-
- if ((error = git_commit_tree(&tree, head_commit)) == 0)
- *tree_out = tree;
-
- git_commit_free(head_commit);
- return error;
-}
-
-enum path_type {
- GIT_STATUS_PATH_NULL,
- GIT_STATUS_PATH_IGNORE,
- GIT_STATUS_PATH_FILE,
- GIT_STATUS_PATH_FOLDER,
-};
-
-static int dirent_cb(void *state, git_buf *full_path);
-static int alphasorted_futils_direach(
- git_buf *path, int (*fn)(void *, git_buf *), void *arg);
-
-static int process_folder(
- struct status_st *st,
- const git_tree_entry *tree_entry,
- git_buf *full_path,
- enum path_type path_type)
-{
- git_object *subtree = NULL;
- git_tree *pushed_tree = NULL;
- int error, pushed_tree_position = 0;
- git_otype tree_entry_type = GIT_OBJ_BAD;
-
- if (tree_entry != NULL) {
- tree_entry_type = git_tree_entry_type(tree_entry);
-
- switch (tree_entry_type) {
- case GIT_OBJ_TREE:
- error = git_tree_entry_2object(&subtree, ((git_object *)(st->tree))->repo, tree_entry);
- pushed_tree = st->tree;
- pushed_tree_position = st->tree_position;
- st->tree = (git_tree *)subtree;
- st->tree_position = 0;
- st->head_tree_relative_path_len += 1 + tree_entry->filename_len; /* path + '/' + name */
- break;
-
- case GIT_OBJ_BLOB:
- /* No op */
- break;
-
- case GIT_OBJ_COMMIT:
- /* TODO: proper submodule support */
- break;
-
- default:
- giterr_set(GITERR_REPOSITORY, "Unexpected tree entry type");
- return -1;
- }
- }
-
-
- if (full_path != NULL && path_type == GIT_STATUS_PATH_FOLDER) {
- git_ignores ignores, *old_ignores;
-
- if ((error = git_ignore__for_path(st->repo,
- full_path->ptr + st->workdir_path_len, &ignores)) == 0)
- {
- old_ignores = st->ignores;
- st->ignores = &ignores;
-
- error = alphasorted_futils_direach(full_path, dirent_cb, st);
-
- git_ignore__free(st->ignores);
- st->ignores = old_ignores;
- }
- } else {
- error = dirent_cb(st, NULL);
- }
-
- if (tree_entry_type == GIT_OBJ_TREE) {
- git_object_free(subtree);
- st->head_tree_relative_path_len -= 1 + tree_entry->filename_len;
- st->tree = pushed_tree;
- st->tree_position = pushed_tree_position;
- st->tree_position++;
- }
-
- return error;
-}
-
-static int store_if_changed(struct status_st *st, struct status_entry *e)
-{
- int error = status_entry_update_flags(e);
- if (error < 0)
- return error;
-
- if (status_entry_is_ignorable(e) &&
- (error = status_entry_update_ignore(e, st->ignores, e->path)) < 0)
- return error;
-
- if (e->status_flags == GIT_STATUS_CURRENT) {
- git__free(e);
- return 0;
- }
-
- return git_vector_insert(st->vector, e);
-}
-
-static int determine_status(
- struct status_st *st,
- int in_head, int in_index, int in_workdir,
- const git_tree_entry *tree_entry,
- const git_index_entry *index_entry,
- git_buf *full_path,
- const char *status_path,
- enum path_type path_type)
-{
- struct status_entry *e;
- int error = 0;
- git_otype tree_entry_type = GIT_OBJ_BAD;
-
- if (tree_entry != NULL)
- tree_entry_type = git_tree_entry_type(tree_entry);
-
- /* If we're dealing with a directory in the workdir, let's recursively tackle it first */
- if (path_type == GIT_STATUS_PATH_FOLDER)
- return process_folder(st, tree_entry, full_path, path_type);
-
- /* Are we dealing with a file somewhere? */
- if (in_workdir || in_index || (in_head && tree_entry_type == GIT_OBJ_BLOB)) {
- e = status_entry_new(NULL, status_path);
-
- if (in_head && tree_entry_type == GIT_OBJ_BLOB) {
- status_entry_update_from_tree_entry(e, tree_entry);
- st->tree_position++;
- }
-
- if (in_index) {
- status_entry_update_from_index_entry(e, index_entry);
- st->index_position++;
- }
-
- if (in_workdir &&
- (error = status_entry_update_from_workdir(e, full_path->ptr)) < 0)
- return error; /* The callee has already set the error message */
-
- return store_if_changed(st, e);
- }
-
- /* Are we dealing with a subtree? */
- if (tree_entry_type == GIT_OBJ_TREE) {
- assert(in_head && !in_index && !in_workdir);
- return process_folder(st, tree_entry, full_path, path_type);
- }
-
- /* We're dealing with something else -- most likely a submodule;
- * skip it for now */
- if (in_head)
- st->tree_position++;
- if (in_index)
- st->index_position++;
- return 0;
-}
-
-static int path_type_from(git_buf *full_path, int is_dir)
-{
- if (full_path == NULL)
- return GIT_STATUS_PATH_NULL;
-
- if (!is_dir)
- return GIT_STATUS_PATH_FILE;
-
- if (!git__suffixcmp(full_path->ptr, "/" DOT_GIT "/"))
- return GIT_STATUS_PATH_IGNORE;
-
- return GIT_STATUS_PATH_FOLDER;
-}
-
-static const char *status_path(
- const char *first, const char *second, const char *third)
-{
- /* At least one of them can not be NULL */
- assert(first != NULL || second != NULL || third != NULL);
-
- /* TODO: Fixme. Ensure that when non null, they're all equal */
- if (first != NULL)
- return first;
-
- if (second != NULL)
- return second;
-
- return third;
-}
-
-static int compare(const char *left, const char *right)
-{
- if (left == NULL && right == NULL)
- return 0;
-
- if (left == NULL)
- return 1;
-
- if (right == NULL)
- return -1;
-
- return strcmp(left, right);
-}
-
-/* Greatly inspired from JGit IndexTreeWalker */
-/* https://github.com/spearce/jgit/blob/ed47e29c777accfa78c6f50685a5df2b8f5b8ff5/org.spearce.jgit/src/org/spearce/jgit/lib/IndexTreeWalker.java#L88 */
-
-static int dirent_cb(void *state, git_buf *a)
-{
- const git_tree_entry *m;
- const git_index_entry *entry;
- enum path_type path_type;
- int cmpma, cmpmi, cmpai, error;
- const char *pm, *pa, *pi;
- const char *m_name, *i_name, *a_name;
- struct status_st *st = (struct status_st *)state;
-
- path_type = path_type_from(a, st->is_dir);
-
- if (path_type == GIT_STATUS_PATH_IGNORE)
- return 0; /* Let's skip the ".git" directory */
-
- a_name = (path_type != GIT_STATUS_PATH_NULL) ? a->ptr + st->workdir_path_len : NULL;
-
- /* Loop over head tree and index up to and including this workdir file */
- while (1) {
- if (st->tree == NULL)
- m = NULL;
- else
- m = git_tree_entry_byindex(st->tree, st->tree_position);
-
- entry = git_index_get(st->index, st->index_position);
-
- if ((m == NULL) && (a == NULL) && (entry == NULL))
- return 0;
-
- if (m != NULL) {
- git_buf_truncate(&st->head_tree_relative_path,
- st->head_tree_relative_path_len);
- git_buf_joinpath(&st->head_tree_relative_path,
- st->head_tree_relative_path.ptr, m->filename);
- /* When the tree entry is a folder, append a forward slash to its name */
- if (git_tree_entry_type(m) == GIT_OBJ_TREE)
- git_path_to_dir(&st->head_tree_relative_path);
-
- if (git_buf_oom(&st->head_tree_relative_path))
- return -1;
-
- m_name = st->head_tree_relative_path.ptr;
- } else
- m_name = NULL;
-
- i_name = (entry != NULL) ? entry->path : NULL;
-
- cmpma = compare(m_name, a_name);
- cmpmi = compare(m_name, i_name);
- cmpai = compare(a_name, i_name);
-
- pm = ((cmpma <= 0) && (cmpmi <= 0)) ? m_name : NULL;
- pa = ((cmpma >= 0) && (cmpai <= 0)) ? a_name : NULL;
- pi = ((cmpmi >= 0) && (cmpai >= 0)) ? i_name : NULL;
-
- if ((error = determine_status(st, pm != NULL, pi != NULL, pa != NULL,
- m, entry, a, status_path(pm, pi, pa), path_type)) < 0)
- return error;
-
- if ((pa != NULL) || (path_type == GIT_STATUS_PATH_FOLDER))
- return 0;
- }
-}
-
static int recurse_tree_entry(git_tree *tree, struct status_entry *e, const char *path)
{
char *dir_sep;
@@ -728,7 +418,7 @@ int git_status_file(
status_entry_update_from_index(e, index);
/* Try to find file in HEAD */
- if ((error = retrieve_head_tree(&tree, repo)) < 0)
+ if ((error = resolve_head_to_tree(&tree, repo)) < 0)
goto cleanup;
if (tree != NULL) {
@@ -761,62 +451,6 @@ cleanup:
return error;
}
-/*
- * git_path_direach is not supposed to return entries in an ordered manner.
- * alphasorted_futils_direach wraps git_path_dirload and invokes the
- * callback function by passing it alphabetically sorted path parameters.
- *
- */
-static int alphasorted_futils_direach(
- git_buf *path,
- int (*fn)(void *, git_buf *),
- void *arg)
-{
- int error;
- char *entry;
- git_vector entry_names;
- unsigned int idx;
-
- if (git_vector_init(&entry_names, 16, git__strcmp_cb) < 0)
- return -1;
-
- if ((error = git_path_dirload(path->ptr, 0, 1, &entry_names)) < 0)
- return error;
-
- git_vector_foreach(&entry_names, idx, entry) {
- size_t entry_len = strlen(entry);
- if (git_path_isdir(entry)) {
- /* dirload allocated 1 extra byte so there is space for slash */
- entry[entry_len++] = '/';
- entry[entry_len] = '\0';
- }
- }
-
- git_vector_sort(&entry_names);
-
- git_vector_foreach(&entry_names, idx, entry) {
- /* Walk the entire vector even if there is an error, in order to
- * free up memory, but stop making callbacks after an error.
- */
- if (!error) {
- git_buf entry_path = GIT_BUF_INIT;
- git_buf_attach(&entry_path, entry, 0);
-
- ((struct status_st *)arg)->is_dir =
- (entry_path.ptr[entry_path.size - 1] == '/');
-
- error = fn(arg, &entry_path);
- }
-
- git__free(entry);
- }
-
- git_vector_free(&entry_names);
-
- return error;
-}
-
-
int git_status_should_ignore(git_repository *repo, const char *path, int *ignored)
{
int error;