From: Junio C Hamano Date: Wed, 16 Jul 2014 18:33:09 +0000 (-0700) Subject: Merge branch 'rs/code-cleaning' X-Git-Tag: v2.1.0-rc0~31 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/1fc83452c76e65385b3da69ea94eb957e36e6c78?ds=inline;hp=-c Merge branch 'rs/code-cleaning' * rs/code-cleaning: fsck: simplify fsck_commit_buffer() by using commit_list_count() commit: use commit_list_append() instead of duplicating its code merge: simplify merge_trivial() by using commit_list_append() use strbuf_addch for adding single characters use strbuf_addbuf for adding strbufs --- 1fc83452c76e65385b3da69ea94eb957e36e6c78 diff --combined builtin/merge.c index 22491a1c2b,f50270efb1..ce82eb297d --- a/builtin/merge.c +++ b/builtin/merge.c @@@ -657,12 -657,14 +657,12 @@@ static int try_merge_strategy(const cha struct commit_list *remoteheads, struct commit *head, const char *head_arg) { - int index_fd; struct lock_file *lock = xcalloc(1, sizeof(struct lock_file)); - index_fd = hold_locked_index(lock, 1); + hold_locked_index(lock, 1); refresh_cache(REFRESH_QUIET); if (active_cache_changed && - (write_cache(index_fd, active_cache, active_nr) || - commit_locked_index(lock))) + write_locked_index(&the_index, lock, COMMIT_LOCK)) return error(_("Unable to write index.")); rollback_lock_file(lock); @@@ -670,6 -672,7 +670,6 @@@ int clean, x; struct commit *result; struct lock_file *lock = xcalloc(1, sizeof(struct lock_file)); - int index_fd; struct commit_list *reversed = NULL; struct merge_options o; struct commit_list *j; @@@ -697,11 -700,12 +697,11 @@@ for (j = common; j; j = j->next) commit_list_insert(j->item, &reversed); - index_fd = hold_locked_index(lock, 1); + hold_locked_index(lock, 1); clean = merge_recursive(&o, head, remoteheads->item, reversed, &result); if (active_cache_changed && - (write_cache(index_fd, active_cache, active_nr) || - commit_locked_index(lock))) + write_locked_index(&the_index, lock, COMMIT_LOCK)) die (_("unable to write %s"), get_index_file()); rollback_lock_file(lock); return clean ? 0 : 1; @@@ -839,16 -843,14 +839,14 @@@ static void prepare_to_commit(struct co static int merge_trivial(struct commit *head, struct commit_list *remoteheads) { unsigned char result_tree[20], result_commit[20]; - struct commit_list *parent = xmalloc(sizeof(*parent)); + struct commit_list *parents, **pptr = &parents; write_tree_trivial(result_tree); printf(_("Wonderful.\n")); - parent->item = head; - parent->next = xmalloc(sizeof(*parent->next)); - parent->next->item = remoteheads->item; - parent->next->next = NULL; + pptr = commit_list_append(head, pptr); + pptr = commit_list_append(remoteheads->item, pptr); prepare_to_commit(remoteheads); - if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parent, + if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents, result_commit, NULL, sign_commit)) die(_("failed to write commit object")); finish(head, remoteheads, result_commit, "In-index merge"); @@@ -1278,7 -1280,10 +1276,7 @@@ int cmd_merge(int argc, const char **ar printf(_("Commit %s has a good GPG signature by %s\n"), hex, signature_check.signer); - free(signature_check.gpg_output); - free(signature_check.gpg_status); - free(signature_check.signer); - free(signature_check.key); + signature_check_clear(&signature_check); } } diff --combined commit.c index acb74b55d4,61d2e13f48..f43970dca1 --- a/commit.c +++ b/commit.c @@@ -447,12 -447,7 +447,7 @@@ struct commit_list *copy_commit_list(st struct commit_list *head = NULL; struct commit_list **pp = &head; while (list) { - struct commit_list *new; - new = xmalloc(sizeof(struct commit_list)); - new->item = list->item; - new->next = NULL; - *pp = new; - pp = &new->next; + pp = commit_list_append(list->item, pp); list = list->next; } return head; @@@ -1270,7 -1265,6 +1265,7 @@@ void check_commit_signature(const struc &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); diff --combined merge-recursive.c index 8e44d7e5f3,fad7b2c2b8..5814d056ff --- a/merge-recursive.c +++ b/merge-recursive.c @@@ -171,7 -171,7 +171,7 @@@ static void output(struct merge_option strbuf_vaddf(&o->obuf, fmt, ap); va_end(ap); - strbuf_add(&o->obuf, "\n", 1); + strbuf_addch(&o->obuf, '\n'); if (!o->buffer_output) flush_output(o); } @@@ -267,7 -267,9 +267,7 @@@ struct tree *write_tree_from_memory(str active_cache_tree = cache_tree(); if (!cache_tree_fully_valid(active_cache_tree) && - cache_tree_update(active_cache_tree, - (const struct cache_entry * const *)active_cache, - active_nr, 0) < 0) + cache_tree_update(&the_index, 0) < 0) die(_("error building trees")); result = lookup_tree(active_cache_tree->sha1); @@@ -1999,7 -2001,7 +1999,7 @@@ int merge_recursive_generic(struct merg const unsigned char **base_list, struct commit **result) { - int clean, index_fd; + int clean; struct lock_file *lock = xcalloc(1, sizeof(struct lock_file)); struct commit *head_commit = get_ref(head, o->branch1); struct commit *next_commit = get_ref(merge, o->branch2); @@@ -2016,11 -2018,12 +2016,11 @@@ } } - index_fd = hold_locked_index(lock, 1); + hold_locked_index(lock, 1); clean = merge_recursive(o, head_commit, next_commit, ca, result); if (active_cache_changed && - (write_cache(index_fd, active_cache, active_nr) || - commit_locked_index(lock))) + write_locked_index(&the_index, lock, COMMIT_LOCK)) return error(_("Unable to write index.")); return clean ? 0 : 1; diff --combined pretty.c index 14357e233f,6e54934723..eb676d6d54 --- a/pretty.c +++ b/pretty.c @@@ -1376,7 -1376,7 +1376,7 @@@ static size_t format_and_pad_commit(str case trunc_none: break; } - strbuf_addstr(sb, local_sb.buf); + strbuf_addbuf(sb, &local_sb); } else { int sb_len = sb->len, offset = 0; if (c->flush_type == flush_left) @@@ -1520,6 -1520,8 +1520,6 @@@ void format_commit_message(const struc free(context.commit_encoding); unuse_commit_buffer(commit, context.message); - free(context.signature_check.gpg_output); - free(context.signature_check.signer); } static void pp_header(struct pretty_print_context *pp, diff --combined rerere.c index ffc6a5b168,04d923d8cf..d84b495895 --- a/rerere.c +++ b/rerere.c @@@ -207,11 -207,11 +207,11 @@@ static int handle_path(unsigned char *s strbuf_reset(&one); strbuf_reset(&two); } else if (hunk == RR_SIDE_1) - strbuf_addstr(&one, buf.buf); + strbuf_addbuf(&one, &buf); else if (hunk == RR_ORIGINAL) ; /* discard */ else if (hunk == RR_SIDE_2) - strbuf_addstr(&two, buf.buf); + strbuf_addbuf(&two, &buf); else rerere_io_putstr(buf.buf, io); continue; @@@ -492,7 -492,8 +492,7 @@@ static int update_paths(struct string_l } if (!status && active_cache_changed) { - if (write_cache(fd, active_cache, active_nr) || - commit_locked_index(&index_lock)) + if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) die("Unable to write new index file"); } else if (fd >= 0) rollback_lock_file(&index_lock);