Skip to content

Commit

Permalink
commit: simplify building parents list
Browse files Browse the repository at this point in the history
Push pptr down into the FROM_MERGE branch of the if/else statement,
where it's actually used, and call commit_list_append() for appending
elements instead of playing tricks with commit_list_insert().  Call
copy_commit_list() in the amend branch instead of open-coding it.  Don't
bother setting pptr in the final branch as it's not used thereafter.

Signed-off-by: Rene Scharfe <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
rscharfe authored and gitster committed Oct 30, 2016
1 parent 0b65a8d commit de9f7fa
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
const char *index_file, *reflog_msg;
char *nl;
unsigned char sha1[20];
struct commit_list *parents = NULL, **pptr = &parents;
struct commit_list *parents = NULL;
struct stat statbuf;
struct commit *current_head = NULL;
struct commit_extra_header *extra = NULL;
Expand Down Expand Up @@ -1681,20 +1681,18 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
if (!reflog_msg)
reflog_msg = "commit (initial)";
} else if (amend) {
struct commit_list *c;

if (!reflog_msg)
reflog_msg = "commit (amend)";
for (c = current_head->parents; c; c = c->next)
pptr = &commit_list_insert(c->item, pptr)->next;
parents = copy_commit_list(current_head->parents);
} else if (whence == FROM_MERGE) {
struct strbuf m = STRBUF_INIT;
FILE *fp;
int allow_fast_forward = 1;
struct commit_list **pptr = &parents;

if (!reflog_msg)
reflog_msg = "commit (merge)";
pptr = &commit_list_insert(current_head, pptr)->next;
pptr = commit_list_append(current_head, pptr);
fp = fopen(git_path_merge_head(), "r");
if (fp == NULL)
die_errno(_("could not open '%s' for reading"),
Expand All @@ -1705,7 +1703,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
parent = get_merge_parent(m.buf);
if (!parent)
die(_("Corrupt MERGE_HEAD file (%s)"), m.buf);
pptr = &commit_list_insert(parent, pptr)->next;
pptr = commit_list_append(parent, pptr);
}
fclose(fp);
strbuf_release(&m);
Expand All @@ -1722,7 +1720,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
reflog_msg = (whence == FROM_CHERRY_PICK)
? "commit (cherry-pick)"
: "commit";
pptr = &commit_list_insert(current_head, pptr)->next;
commit_list_insert(current_head, &parents);
}

/* Finally, get the commit message */
Expand Down

0 comments on commit de9f7fa

Please sign in to comment.