зеркало из https://github.com/microsoft/git.git
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
This commit is contained in:
Коммит
1fc83452c7
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
7
commit.c
7
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;
|
||||
|
|
22
fsck.c
22
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))
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
2
pretty.c
2
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)
|
||||
|
|
4
rerere.c
4
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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
2
url.c
2
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) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче