diff options
author | Vicent Marti <tanoku@gmail.com> | 2010-05-22 18:15:42 +0200 |
---|---|---|
committer | Andreas Ericsson <ae@op5.se> | 2010-06-02 10:32:06 +0200 |
commit | 36b7cdb6a1a2e685c7141406808366d4c4b9f98e (patch) | |
tree | c29a831c884ea240437bd2459e60ffb383dcd149 /src/commit.c | |
parent | 89039682651474c6e2bf9abcc02cb71897f8b4e1 (diff) | |
download | libgit2-36b7cdb6a1a2e685c7141406808366d4c4b9f98e.tar.gz |
Changed 'git_commit_list' from a linked list to a doubly-linked list.
Changed 'git_commit' to use bit fields instead of flags.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
Diffstat (limited to 'src/commit.c')
-rw-r--r-- | src/commit.c | 105 |
1 files changed, 83 insertions, 22 deletions
diff --git a/src/commit.c b/src/commit.c index 8654e891d..b196a807b 100644 --- a/src/commit.c +++ b/src/commit.c @@ -40,12 +40,13 @@ void git_commit__mark_uninteresting(git_commit *commit) if (commit == NULL) return; - git_commit_list *parents = commit->parents; + git_commit_node *parents = commit->parents.head; - commit->flags |= GIT_COMMIT_HIDE; + commit->uninteresting = 1; - while (parents) { - parents->commit->flags |= GIT_COMMIT_HIDE; + while (parents) + { + parents->commit->uninteresting = 1; parents = parents->next; } } @@ -185,10 +186,10 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len) return -1; // Inherit uninteresting flag - if (commit->flags & GIT_COMMIT_HIDE) - parent->flags |= GIT_COMMIT_HIDE; + if (commit->uninteresting) + parent->uninteresting = 1; - git_commit_list_insert(&commit->parents, parent); + git_commit_list_append(&commit->parents, parent); } if (git_commit__parse_time(&commit->commit_time, buffer, buffer_end) < 0) @@ -199,30 +200,90 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len) return 0; } -void git_commit_list_insert(git_commit_list **list, git_commit *commit) +void git_commit_list_append(git_commit_list *list, git_commit *commit) { - if (*list == NULL) - { - *list = git__malloc(sizeof(git_commit_list)); + git_commit_node *node = NULL; + + node = git__malloc(sizeof(git_commit_list)); + + if (node == NULL) + return; - if (*list == NULL) - return; + node->commit = commit; + node->next = NULL; + node->prev = list->tail; - (*list)->commit = commit; - (*list)->next = NULL; + if (list->tail == NULL) + { + list->head = list->tail = node; } else { - git_commit_list *new_list = NULL; + list->tail->next = node; + list->tail = node; + } + + list->size++; +} + +git_commit *git_commit_list_pop_back(git_commit_list *list) +{ + git_commit_node *node; + git_commit *commit; + + if (list->tail == NULL) + return NULL; + + node = list->tail; + list->tail = list->tail->prev; + if (list->tail == NULL) + list->head = NULL; + + commit = node->commit; + free(node); + + list->size--; - new_list = git__malloc(sizeof(git_commit_list)); + return commit; +} + +git_commit *git_commit_list_pop_front(git_commit_list *list) +{ + git_commit_node *node; + git_commit *commit; + + if (list->head == NULL) + return NULL; + + node = list->head; + list->head = list->head->next; + if (list->head == NULL) + list->tail = NULL; + + commit = node->commit; + free(node); - if (new_list == NULL) - return; + list->size--; - new_list->commit = commit; - new_list->next = *list; + return commit; +} + +void git_commit_list_clear(git_commit_list *list, int free_commits) +{ + git_commit_node *node, *next_node; - *list = new_list; + node = list->head; + while (node) + { + if (free_commits) + free(node->commit); + + next_node = node->next; + free(node); + node = next_node; } + + list->head = list->tail = NULL; + list->size = 0; } + |