summaryrefslogtreecommitdiff
path: root/builtin/commit.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2016-11-29 13:27:59 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2016-11-29 13:27:59 -0800
commitc8a3ec37abe5395e4f4c14d5e9f0ab8077140f1b (patch)
treef1ab3bfb4e9e8d2f9cad9d7d024de12ca8fcbf44 /builtin/commit.c
parentMerge branch 'jk/rebase-config-insn-fmt-docfix' into maint (diff)
parentcommit: simplify building parents list (diff)
downloadtgif-c8a3ec37abe5395e4f4c14d5e9f0ab8077140f1b.tar.xz
Merge branch 'rs/commit-pptr-simplify' into maint
Code simplification. * rs/commit-pptr-simplify: commit: simplify building parents list
Diffstat (limited to 'builtin/commit.c')
-rw-r--r--builtin/commit.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/builtin/commit.c b/builtin/commit.c
index 7a1ade0d27..63a8424c5a 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1647,7 +1647,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;
@@ -1693,20 +1693,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"),
@@ -1717,7 +1715,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);
@@ -1734,7 +1732,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 */