summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-07-16 11:33:09 -0700
committerJunio C Hamano <gitster@pobox.com>2014-07-16 11:33:09 -0700
commit1fc83452c76e65385b3da69ea94eb957e36e6c78 (patch)
tree6d6105b9a9fed643036df3d0fceabde1ab1479c7
parentf357797678aa5ae35c63623b8b76eb682d5b9b79 (diff)
parent9d02150cf4d833935161ef265e4dc03807caa800 (diff)
downloadgit-1fc83452c76e65385b3da69ea94eb957e36e6c78.tar.gz
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
-rw-r--r--builtin/log.c2
-rw-r--r--builtin/merge.c10
-rw-r--r--commit.c7
-rw-r--r--fsck.c22
-rw-r--r--merge-recursive.c2
-rw-r--r--pathspec.c2
-rw-r--r--pretty.c2
-rw-r--r--rerere.c4
-rw-r--r--sha1_name.c2
-rw-r--r--url.c2
10 files changed, 19 insertions, 36 deletions
diff --git a/builtin/log.c b/builtin/log.c
index 27c1b65db4..4389722b4b 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -861,7 +861,7 @@ static void add_branch_description(struct strbuf *buf, const char *branch_name)
read_branch_desc(&desc, branch_name);
if (desc.len) {
strbuf_addch(buf, '\n');
- strbuf_add(buf, desc.buf, desc.len);
+ strbuf_addbuf(buf, &desc);
strbuf_addch(buf, '\n');
}
}
diff --git a/builtin/merge.c b/builtin/merge.c
index 22491a1c2b..ce82eb297d 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -839,16 +839,14 @@ static void prepare_to_commit(struct commit_list *remoteheads)
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");
diff --git a/commit.c b/commit.c
index acb74b55d4..f43970dca1 100644
--- a/commit.c
+++ b/commit.c
@@ -447,12 +447,7 @@ struct commit_list *copy_commit_list(struct commit_list *list)
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;
diff --git a/fsck.c b/fsck.c
index a4e8593e78..56156fff44 100644
--- a/fsck.c
+++ b/fsck.c
@@ -281,7 +281,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
{
unsigned char tree_sha1[20], sha1[20];
struct commit_graft *graft;
- int parents = 0;
+ unsigned parent_count, parent_line_count = 0;
int err;
if (!skip_prefix(buffer, "tree ", &buffer))
@@ -293,27 +293,17 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n')
return error_func(&commit->object, FSCK_ERROR, "invalid 'parent' line format - bad sha1");
buffer += 41;
- parents++;
+ parent_line_count++;
}
graft = lookup_commit_graft(commit->object.sha1);
+ parent_count = commit_list_count(commit->parents);
if (graft) {
- struct commit_list *p = commit->parents;
- parents = 0;
- while (p) {
- p = p->next;
- parents++;
- }
- if (graft->nr_parent == -1 && !parents)
+ if (graft->nr_parent == -1 && !parent_count)
; /* shallow commit */
- else if (graft->nr_parent != parents)
+ else if (graft->nr_parent != parent_count)
return error_func(&commit->object, FSCK_ERROR, "graft objects missing");
} else {
- struct commit_list *p = commit->parents;
- while (p && parents) {
- p = p->next;
- parents--;
- }
- if (p || parents)
+ if (parent_count != parent_line_count)
return error_func(&commit->object, FSCK_ERROR, "parent objects missing");
}
if (!skip_prefix(buffer, "author ", &buffer))
diff --git a/merge-recursive.c b/merge-recursive.c
index 8e44d7e5f3..5814d056ff 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -171,7 +171,7 @@ static void output(struct merge_options *o, int v, const char *fmt, ...)
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);
}
diff --git a/pathspec.c b/pathspec.c
index 8043099955..89f2c8ffff 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -338,7 +338,7 @@ static void NORETURN unsupported_magic(const char *pattern,
if (!(magic & m->bit))
continue;
if (sb.len)
- strbuf_addstr(&sb, " ");
+ strbuf_addch(&sb, ' ');
if (short_magic & m->bit)
strbuf_addf(&sb, "'%c'", m->mnemonic);
else
diff --git a/pretty.c b/pretty.c
index 14357e233f..eb676d6d54 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1376,7 +1376,7 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */
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)
diff --git a/rerere.c b/rerere.c
index ffc6a5b168..d84b495895 100644
--- a/rerere.c
+++ b/rerere.c
@@ -207,11 +207,11 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_siz
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;
diff --git a/sha1_name.c b/sha1_name.c
index 5bfa841699..6ccd3a53f8 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -946,7 +946,7 @@ static int interpret_nth_prior_checkout(const char *name, int namelen,
retval = 0;
if (0 < for_each_reflog_ent_reverse("HEAD", grab_nth_branch_switch, &cb)) {
strbuf_reset(buf);
- strbuf_add(buf, cb.buf.buf, cb.buf.len);
+ strbuf_addbuf(buf, &cb.buf);
retval = brace - name + 1;
}
diff --git a/url.c b/url.c
index 335d97d3f7..7ca2a69e10 100644
--- a/url.c
+++ b/url.c
@@ -121,7 +121,7 @@ void end_url_with_slash(struct strbuf *buf, const char *url)
{
strbuf_addstr(buf, url);
if (buf->len && buf->buf[buf->len - 1] != '/')
- strbuf_addstr(buf, "/");
+ strbuf_addch(buf, '/');
}
void str_end_url_with_slash(const char *url, char **dest) {