static int prepare_walk(git_revwalk *walk) { int error; git_commit_list *list; git_commit_list_node *next; /* If there were no pushes, we know that the walk is already over */ if (!walk->did_push) { giterr_clear(); return GIT_ITEROVER; } if (walk->did_hide && (error = premark_uninteresting(walk)) < 0) return error; for (list = walk->user_input; list; list = list->next) { if (process_commit(walk, list->item, list->item->uninteresting) < 0) return -1; } if (walk->sorting & GIT_SORT_TOPOLOGICAL) { unsigned short i; while ((error = walk->get_next(&next, walk)) == 0) { for (i = 0; i < next->out_degree; ++i) { git_commit_list_node *parent = next->parents[i]; parent->in_degree++; } if (git_commit_list_insert(next, &walk->iterator_topo) == NULL) return -1; } if (error != GIT_ITEROVER) return error; walk->get_next = &revwalk_next_toposort; } if (walk->sorting & GIT_SORT_REVERSE) { while ((error = walk->get_next(&next, walk)) == 0) if (git_commit_list_insert(next, &walk->iterator_reverse) == NULL) return -1; if (error != GIT_ITEROVER) return error; walk->get_next = &revwalk_next_reverse; } walk->walking = 1; return 0; }
static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting, int from_glob) { git_oid commit_id; int error; git_object *obj, *oobj; git_commit_list_node *commit; git_commit_list *list; if ((error = git_object_lookup(&oobj, walk->repo, oid, GIT_OBJ_ANY)) < 0) return error; error = git_object_peel(&obj, oobj, GIT_OBJ_COMMIT); git_object_free(oobj); if (error == GIT_ENOTFOUND || error == GIT_EINVALIDSPEC || error == GIT_EPEEL) { /* If this comes from e.g. push_glob("tags"), ignore this */ if (from_glob) return 0; giterr_set(GITERR_INVALID, "Object is not a committish"); return -1; } if (error < 0) return error; git_oid_cpy(&commit_id, git_object_id(obj)); git_object_free(obj); commit = git_revwalk__commit_lookup(walk, &commit_id); if (commit == NULL) return -1; /* error already reported by failed lookup */ /* A previous hide already told us we don't want this commit */ if (commit->uninteresting) return 0; if (uninteresting) walk->did_hide = 1; else walk->did_push = 1; commit->uninteresting = uninteresting; list = walk->user_input; if (git_commit_list_insert(commit, &list) == NULL) { giterr_set_oom(); return -1; } walk->user_input = list; return 0; }
git_commit_list *git_commit_list_insert_by_date(git_commit_list_node *item, git_commit_list **list_p) { git_commit_list **pp = list_p; git_commit_list *p; while ((p = *pp) != NULL) { if (git_commit_list_time_cmp(p->item, item) < 0) break; pp = &p->next; } return git_commit_list_insert(item, pp); }
static int revwalk_next_toposort(git_commit_list_node **object_out, git_revwalk *walk) { git_commit_list_node *next; unsigned short i, max; for (;;) { next = git_commit_list_pop(&walk->iterator_topo); if (next == NULL) { giterr_clear(); return GIT_ITEROVER; } if (next->in_degree > 0) { next->topo_delay = 1; continue; } max = next->out_degree; if (walk->first_parent && next->out_degree) max = 1; for (i = 0; i < max; ++i) { git_commit_list_node *parent = next->parents[i]; if (--parent->in_degree == 0 && parent->topo_delay) { parent->topo_delay = 0; if (git_commit_list_insert(parent, &walk->iterator_topo) == NULL) return -1; } } *object_out = next; return 0; } }
static int revwalk_enqueue_unsorted(git_revwalk *walk, git_commit_list_node *commit) { return git_commit_list_insert(commit, &walk->iterator_rand) ? 0 : -1; }