Skip to content

Commit de9f7fa

Browse files
rscharfegitster
authored andcommitted
commit: simplify building parents list
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]>
1 parent 0b65a8d commit de9f7fa

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

builtin/commit.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16391639
const char *index_file, *reflog_msg;
16401640
char *nl;
16411641
unsigned char sha1[20];
1642-
struct commit_list *parents = NULL, **pptr = &parents;
1642+
struct commit_list *parents = NULL;
16431643
struct stat statbuf;
16441644
struct commit *current_head = NULL;
16451645
struct commit_extra_header *extra = NULL;
@@ -1681,20 +1681,18 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16811681
if (!reflog_msg)
16821682
reflog_msg = "commit (initial)";
16831683
} else if (amend) {
1684-
struct commit_list *c;
1685-
16861684
if (!reflog_msg)
16871685
reflog_msg = "commit (amend)";
1688-
for (c = current_head->parents; c; c = c->next)
1689-
pptr = &commit_list_insert(c->item, pptr)->next;
1686+
parents = copy_commit_list(current_head->parents);
16901687
} else if (whence == FROM_MERGE) {
16911688
struct strbuf m = STRBUF_INIT;
16921689
FILE *fp;
16931690
int allow_fast_forward = 1;
1691+
struct commit_list **pptr = &parents;
16941692

16951693
if (!reflog_msg)
16961694
reflog_msg = "commit (merge)";
1697-
pptr = &commit_list_insert(current_head, pptr)->next;
1695+
pptr = commit_list_append(current_head, pptr);
16981696
fp = fopen(git_path_merge_head(), "r");
16991697
if (fp == NULL)
17001698
die_errno(_("could not open '%s' for reading"),
@@ -1705,7 +1703,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17051703
parent = get_merge_parent(m.buf);
17061704
if (!parent)
17071705
die(_("Corrupt MERGE_HEAD file (%s)"), m.buf);
1708-
pptr = &commit_list_insert(parent, pptr)->next;
1706+
pptr = commit_list_append(parent, pptr);
17091707
}
17101708
fclose(fp);
17111709
strbuf_release(&m);
@@ -1722,7 +1720,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17221720
reflog_msg = (whence == FROM_CHERRY_PICK)
17231721
? "commit (cherry-pick)"
17241722
: "commit";
1725-
pptr = &commit_list_insert(current_head, pptr)->next;
1723+
commit_list_insert(current_head, &parents);
17261724
}
17271725

17281726
/* Finally, get the commit message */

0 commit comments

Comments
 (0)