Added sort method for commit lists. Fixed bug when parsing time headers from commits. Signed-off-by: Vicent Marti <tanoku@gmail.com> Signed-off-by: Andreas Ericsson <ae@op5.se>
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
diff --git a/src/commit.c b/src/commit.c
index 1763ca8..dec93ef 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -97,7 +97,7 @@ git_commit *git_commit_lookup(git_revpool *pool, const git_oid *id)
{
git_commit *commit = NULL;
- if (pool == NULL || pool->db == NULL)
+ if (pool == NULL)
return NULL;
commit = (git_commit *)git_revpool_table_lookup(pool->commits, id);
@@ -126,14 +126,14 @@ int git_commit__parse_time(time_t *commit_time, char *buffer, const char *buffer
return -1;
buffer = memchr(buffer, '\n', buffer_end - buffer);
- if (buffer == 0 || buffer >= buffer_end)
+ if (buffer == 0 || ++buffer >= buffer_end)
return -1;
if (memcmp(buffer, "committer ", 10) != 0)
return -1;
buffer = memchr(buffer, '\n', buffer_end - buffer);
- if (buffer == 0 || buffer >= buffer_end)
+ if (buffer == 0 || ++buffer >= buffer_end)
return -1;
*commit_time = strtol(buffer, &buffer, 10);
@@ -291,3 +291,57 @@ void git_commit_list_clear(git_commit_list *list, int free_commits)
list->size = 0;
}
+void git_commit_list_sort(git_commit_list *list)
+{
+ git_commit_node *p, *q, *e, *tail;
+ int in_size, p_size, q_size, merge_count, i;
+
+ if (list->head == NULL)
+ return;
+
+ in_size = 1;
+
+ do
+ {
+ p = list->head;
+ tail = NULL;
+ merge_count = 0;
+
+ while (p != NULL)
+ {
+ merge_count++;
+ q = p;
+ p_size = 0;
+ q_size = in_size;
+
+ for (i = 0; i < in_size && q; ++i, q = q->next)
+ p_size++;
+
+ while (p_size > 0 || (q_size > 0 && q))
+ {
+ if (p_size == 0)
+ e = q, q = q->next, q_size--;
+
+ else if (q_size == 0 || q == NULL ||
+ p->commit->commit_time <= q->commit->commit_time)
+ e = p, p = p->next, p_size--;
+
+ else
+ e = q, q = q->next, q_size--;
+
+ if (tail != NULL)
+ tail->next = e;
+ else
+ list->head = e;
+
+ tail = e;
+ }
+
+ p = q;
+ }
+
+ tail->next = NULL;
+ in_size *= 2;
+
+ } while (merge_count > 1);
+}
diff --git a/src/commit.h b/src/commit.h
index 818d98c..72ea4e9 100644
--- a/src/commit.h
+++ b/src/commit.h
@@ -47,5 +47,6 @@ void git_commit_list_clear(git_commit_list *list, int free_commits);
void git_commit_list_append(git_commit_list *list, git_commit *commit);
git_commit *git_commit_list_pop_back(git_commit_list *list);
git_commit *git_commit_list_pop_front(git_commit_list *list);
+void git_commit_list_sort(git_commit_list *list);
#endif