Skip to content

Commit c8a3ec3

Browse files
committed
Merge branch 'rs/commit-pptr-simplify' into maint
Code simplification. * rs/commit-pptr-simplify: commit: simplify building parents list
2 parents 50b8276 + de9f7fa commit c8a3ec3

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
@@ -1647,7 +1647,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16471647
const char *index_file, *reflog_msg;
16481648
char *nl;
16491649
unsigned char sha1[20];
1650-
struct commit_list *parents = NULL, **pptr = &parents;
1650+
struct commit_list *parents = NULL;
16511651
struct stat statbuf;
16521652
struct commit *current_head = NULL;
16531653
struct commit_extra_header *extra = NULL;
@@ -1693,20 +1693,18 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16931693
if (!reflog_msg)
16941694
reflog_msg = "commit (initial)";
16951695
} else if (amend) {
1696-
struct commit_list *c;
1697-
16981696
if (!reflog_msg)
16991697
reflog_msg = "commit (amend)";
1700-
for (c = current_head->parents; c; c = c->next)
1701-
pptr = &commit_list_insert(c->item, pptr)->next;
1698+
parents = copy_commit_list(current_head->parents);
17021699
} else if (whence == FROM_MERGE) {
17031700
struct strbuf m = STRBUF_INIT;
17041701
FILE *fp;
17051702
int allow_fast_forward = 1;
1703+
struct commit_list **pptr = &parents;
17061704

17071705
if (!reflog_msg)
17081706
reflog_msg = "commit (merge)";
1709-
pptr = &commit_list_insert(current_head, pptr)->next;
1707+
pptr = commit_list_append(current_head, pptr);
17101708
fp = fopen(git_path_merge_head(), "r");
17111709
if (fp == NULL)
17121710
die_errno(_("could not open '%s' for reading"),
@@ -1717,7 +1715,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17171715
parent = get_merge_parent(m.buf);
17181716
if (!parent)
17191717
die(_("Corrupt MERGE_HEAD file (%s)"), m.buf);
1720-
pptr = &commit_list_insert(parent, pptr)->next;
1718+
pptr = commit_list_append(parent, pptr);
17211719
}
17221720
fclose(fp);
17231721
strbuf_release(&m);
@@ -1734,7 +1732,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17341732
reflog_msg = (whence == FROM_CHERRY_PICK)
17351733
? "commit (cherry-pick)"
17361734
: "commit";
1737-
pptr = &commit_list_insert(current_head, pptr)->next;
1735+
commit_list_insert(current_head, &parents);
17381736
}
17391737

17401738
/* Finally, get the commit message */

0 commit comments

Comments
 (0)