diff options
Diffstat (limited to 'commit.c')
-rw-r--r-- | commit.c | 76 |
1 files changed, 33 insertions, 43 deletions
@@ -245,7 +245,12 @@ void set_commit_buffer(struct commit *commit, void *buffer, unsigned long size) const void *get_cached_commit_buffer(const struct commit *commit, unsigned long *sizep) { - struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit); + struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit); + if (!v) { + if (sizep) + *sizep = 0; + return NULL; + } if (sizep) *sizep = v->size; return v->buffer; @@ -272,24 +277,31 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep) void unuse_commit_buffer(const struct commit *commit, const void *buffer) { - struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit); - if (v->buffer != buffer) + struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit); + if (!(v && v->buffer == buffer)) free((void *)buffer); } void free_commit_buffer(struct commit *commit) { - struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit); - free(v->buffer); - v->buffer = NULL; - v->size = 0; + struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit); + if (v) { + free(v->buffer); + v->buffer = NULL; + v->size = 0; + } } const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep) { - struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit); + struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit); void *ret; + if (!v) { + if (sizep) + *sizep = 0; + return NULL; + } ret = v->buffer; if (sizep) *sizep = v->size; @@ -443,11 +455,8 @@ struct commit_list *copy_commit_list(struct commit_list *list) void free_commit_list(struct commit_list *list) { - while (list) { - struct commit_list *temp = list; - list = temp->next; - free(temp); - } + while (list) + pop_commit(&list); } struct commit_list * commit_list_insert_by_date(struct commit *item, struct commit_list **list) @@ -493,12 +502,8 @@ void commit_list_sort_by_date(struct commit_list **list) struct commit *pop_most_recent_commit(struct commit_list **list, unsigned int mark) { - struct commit *ret = (*list)->item; + struct commit *ret = pop_commit(list); struct commit_list *parents = ret->parents; - struct commit_list *old = *list; - - *list = (*list)->next; - free(old); while (parents) { struct commit *commit = parents->item; @@ -849,11 +854,9 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co list = paint_down_to_common(one, n, twos); while (list) { - struct commit_list *next = list->next; - if (!(list->item->object.flags & STALE)) - commit_list_insert_by_date(list->item, &result); - free(list); - list = next; + struct commit *commit = pop_commit(&list); + if (!(commit->object.flags & STALE)) + commit_list_insert_by_date(commit, &result); } return result; } @@ -1232,33 +1235,24 @@ free_return: free(buf); } -void check_commit_signature(const struct commit *commit, struct signature_check *sigc) +int check_commit_signature(const struct commit *commit, struct signature_check *sigc) { struct strbuf payload = STRBUF_INIT; struct strbuf signature = STRBUF_INIT; - struct strbuf gpg_output = STRBUF_INIT; - struct strbuf gpg_status = STRBUF_INIT; - int status; + int ret = 1; sigc->result = 'N'; if (parse_signed_commit(commit, &payload, &signature) <= 0) goto out; - status = verify_signed_buffer(payload.buf, payload.len, - signature.buf, signature.len, - &gpg_output, &gpg_status); - if (status && !gpg_output.len) - goto out; - sigc->payload = strbuf_detach(&payload, NULL); - sigc->gpg_output = strbuf_detach(&gpg_output, NULL); - sigc->gpg_status = strbuf_detach(&gpg_status, NULL); - parse_gpg_output(sigc); + ret = check_signature(payload.buf, payload.len, signature.buf, + signature.len, sigc); out: - strbuf_release(&gpg_status); - strbuf_release(&gpg_output); strbuf_release(&payload); strbuf_release(&signature); + + return ret; } @@ -1543,13 +1537,9 @@ int commit_tree_extended(const char *msg, size_t msg_len, * if everything else stays the same. */ while (parents) { - struct commit_list *next = parents->next; - struct commit *parent = parents->item; - + struct commit *parent = pop_commit(&parents); strbuf_addf(&buffer, "parent %s\n", sha1_to_hex(parent->object.sha1)); - free(parents); - parents = next; } /* Person/date information */ |