Functions for a date-ordered queue of commits, progressively pulled out of the history incrementally. Linus wanted this for finding the most recent common ancestor, and it might be relevant to logging.
Signed-Off-By: Daniel Barkalow <[EMAIL PROTECTED]> Index: commit.c =================================================================== --- b3cf8daf9b619ae9f06a28f42a4ae01b69729206/commit.c (mode:100644 sha1:0099baa63971d86ee30ef2a7da25057f0f45a964) +++ 7e5a0d93117ecadfb15de3a6bebdb1aa94234fde/commit.c (mode:100644 sha1:ef9af397471817837e1799d72f6707e0ccc949b9) @@ -83,3 +83,47 @@ free(temp); } } + +static void insert_by_date(struct commit_list **list, struct commit *item) +{ + struct commit_list **pp = list; + struct commit_list *p; + while ((p = *pp) != NULL) { + if (p->item->date < item->date) { + break; + } + pp = &p->next; + } + struct commit_list *insert = malloc(sizeof(struct commit_list)); + insert->next = *pp; + *pp = insert; + insert->item = item; +} + + +void sort_by_date(struct commit_list **list) +{ + struct commit_list *ret = NULL; + while (*list) { + insert_by_date(&ret, (*list)->item); + *list = (*list)->next; + } + *list = ret; +} + +struct commit *pop_most_recent_commit(struct commit_list **list) +{ + struct commit *ret = (*list)->item; + struct commit_list *parents = ret->parents; + struct commit_list *old = *list; + + *list = (*list)->next; + free(old); + + while (parents) { + parse_commit(parents->item); + insert_by_date(list, parents->item); + parents = parents->next; + } + return ret; +} Index: commit.h =================================================================== --- b3cf8daf9b619ae9f06a28f42a4ae01b69729206/commit.h (mode:100644 sha1:8cd20b046875f5f7e534b0607fdd97f330f53272) +++ 7e5a0d93117ecadfb15de3a6bebdb1aa94234fde/commit.h (mode:100644 sha1:35679482132ae5a6b7d72bbb684f21472470717c) @@ -24,4 +24,8 @@ void free_commit_list(struct commit_list *list); +void sort_by_date(struct commit_list **list); + +struct commit *pop_most_recent_commit(struct commit_list **list); + #endif /* COMMIT_H */ - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html