diff options
Diffstat (limited to 'commit.c')
-rw-r--r-- | commit.c | 78 |
1 files changed, 41 insertions, 37 deletions
@@ -49,6 +49,19 @@ struct commit *lookup_commit(const unsigned char *sha1) return check_commit(obj, sha1, 0); } +struct commit *lookup_commit_reference_by_name(const char *name) +{ + unsigned char sha1[20]; + struct commit *commit; + + if (get_sha1(name, sha1)) + return NULL; + commit = lookup_commit_reference(sha1); + if (!commit || parse_commit(commit)) + return NULL; + return commit; +} + static unsigned long parse_commit_date(const char *buf, const char *tail) { const char *dateptr; @@ -137,12 +150,8 @@ struct commit_graft *read_graft_line(char *buf, int len) buf[--len] = '\0'; if (buf[0] == '#' || buf[0] == '\0') return NULL; - if ((len + 1) % 41) { - bad_graft_data: - error("bad graft data: %s", buf); - free(graft); - return NULL; - } + if ((len + 1) % 41) + goto bad_graft_data; i = (len + 1) / 41 - 1; graft = xmalloc(sizeof(*graft) + 20 * i); graft->nr_parent = i; @@ -155,6 +164,11 @@ struct commit_graft *read_graft_line(char *buf, int len) goto bad_graft_data; } return graft; + +bad_graft_data: + error("bad graft data: %s", buf); + free(graft); + return NULL; } static int read_graft_file(const char *graft_file) @@ -200,22 +214,12 @@ struct commit_graft *lookup_commit_graft(const unsigned char *sha1) return commit_graft[pos]; } -int write_shallow_commits(struct strbuf *out, int use_pack_protocol) +int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data) { - int i, count = 0; - for (i = 0; i < commit_graft_nr; i++) - if (commit_graft[i]->nr_parent < 0) { - const char *hex = - sha1_to_hex(commit_graft[i]->sha1); - count++; - if (use_pack_protocol) - packet_buf_write(out, "shallow %s", hex); - else { - strbuf_addstr(out, hex); - strbuf_addch(out, '\n'); - } - } - return count; + int i, ret; + for (i = ret = 0; i < commit_graft_nr && !ret; i++) + ret = fn(commit_graft[i], cb_data); + return ret; } int unregister_shallow(const unsigned char *sha1) @@ -231,10 +235,10 @@ int unregister_shallow(const unsigned char *sha1) return 0; } -int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size) +int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size) { - char *tail = buffer; - char *bufptr = buffer; + const char *tail = buffer; + const char *bufptr = buffer; unsigned char parent[20]; struct commit_list **pptr; struct commit_graft *graft; @@ -360,7 +364,7 @@ void free_commit_list(struct commit_list *list) } } -struct commit_list * insert_by_date(struct commit *item, struct commit_list **list) +struct commit_list * commit_list_insert_by_date(struct commit *item, struct commit_list **list) { struct commit_list **pp = list; struct commit_list *p; @@ -374,11 +378,11 @@ struct commit_list * insert_by_date(struct commit *item, struct commit_list **li } -void sort_by_date(struct commit_list **list) +void commit_list_sort_by_date(struct commit_list **list) { struct commit_list *ret = NULL; while (*list) { - insert_by_date((*list)->item, &ret); + commit_list_insert_by_date((*list)->item, &ret); *list = (*list)->next; } *list = ret; @@ -398,7 +402,7 @@ struct commit *pop_most_recent_commit(struct commit_list **list, struct commit *commit = parents->item; if (!parse_commit(commit) && !(commit->object.flags & mark)) { commit->object.flags |= mark; - insert_by_date(commit, list); + commit_list_insert_by_date(commit, list); } parents = parents->next; } @@ -487,7 +491,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo) /* process the list in topological order */ if (!lifo) - sort_by_date(&work); + commit_list_sort_by_date(&work); pptr = list; *list = NULL; @@ -501,7 +505,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo) commit = work_item->item; for (parents = commit->parents; parents ; parents = parents->next) { - struct commit *parent=parents->item; + struct commit *parent = parents->item; if (!parent->indegree) continue; @@ -513,7 +517,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo) */ if (--parent->indegree == 1) { if (!lifo) - insert_by_date(parent, &work); + commit_list_insert_by_date(parent, &work); else commit_list_insert(parent, &work); } @@ -573,10 +577,10 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co } one->object.flags |= PARENT1; - insert_by_date(one, &list); + commit_list_insert_by_date(one, &list); for (i = 0; i < n; i++) { twos[i]->object.flags |= PARENT2; - insert_by_date(twos[i], &list); + commit_list_insert_by_date(twos[i], &list); } while (interesting(list)) { @@ -594,7 +598,7 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co if (flags == (PARENT1 | PARENT2)) { if (!(commit->object.flags & RESULT)) { commit->object.flags |= RESULT; - insert_by_date(commit, &result); + commit_list_insert_by_date(commit, &result); } /* Mark parents of a found merge stale */ flags |= STALE; @@ -608,7 +612,7 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co if (parse_commit(p)) return NULL; p->object.flags |= flags; - insert_by_date(p, &list); + commit_list_insert_by_date(p, &list); } } @@ -618,7 +622,7 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co while (list) { struct commit_list *next = list->next; if (!(list->item->object.flags & STALE)) - insert_by_date(list->item, &result); + commit_list_insert_by_date(list->item, &result); free(list); list = next; } @@ -711,7 +715,7 @@ struct commit_list *get_merge_bases_many(struct commit *one, result = NULL; for (i = 0; i < cnt; i++) { if (rslt[i]) - insert_by_date(rslt[i], &result); + commit_list_insert_by_date(rslt[i], &result); } free(rslt); return result; |