Skip to content

Commit ee20a12

Browse files
Miklos Vajnagitster
authored andcommitted
commit_tree(): add a new author parameter
In case it's NULL, it is still determined automatically, but now you have the ability to specify one yourself. Signed-off-by: Miklos Vajna <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent da06a80 commit ee20a12

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

builtin-commit-tree.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ static const char commit_utf8_warn[] =
4646
"variable i18n.commitencoding to the encoding your project uses.\n";
4747

4848
int commit_tree(const char *msg, unsigned char *tree,
49-
struct commit_list *parents, unsigned char *ret)
49+
struct commit_list *parents, unsigned char *ret,
50+
const char *author)
5051
{
5152
int result;
5253
int encoding_is_utf8;
@@ -74,7 +75,9 @@ int commit_tree(const char *msg, unsigned char *tree,
7475
}
7576

7677
/* Person/date information */
77-
strbuf_addf(&buffer, "author %s\n", git_author_info(IDENT_ERROR_ON_NO_NAME));
78+
if (!author)
79+
author = git_author_info(IDENT_ERROR_ON_NO_NAME);
80+
strbuf_addf(&buffer, "author %s\n", author);
7881
strbuf_addf(&buffer, "committer %s\n", git_committer_info(IDENT_ERROR_ON_NO_NAME));
7982
if (!encoding_is_utf8)
8083
strbuf_addf(&buffer, "encoding %s\n", git_commit_encoding);
@@ -123,7 +126,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
123126
if (strbuf_read(&buffer, 0, 0) < 0)
124127
die("git commit-tree: read returned %s", strerror(errno));
125128

126-
if (!commit_tree(buffer.buf, tree_sha1, parents, commit_sha1)) {
129+
if (!commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) {
127130
printf("%s\n", sha1_to_hex(commit_sha1));
128131
return 0;
129132
}

builtin-merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ static int merge_trivial(void)
691691
parent->next = xmalloc(sizeof(struct commit_list *));
692692
parent->next->item = remoteheads->item;
693693
parent->next->next = NULL;
694-
commit_tree(merge_msg.buf, result_tree, parent, result_commit);
694+
commit_tree(merge_msg.buf, result_tree, parent, result_commit, NULL);
695695
finish(result_commit, "In-index merge");
696696
drop_save();
697697
return 0;
@@ -720,7 +720,7 @@ static int finish_automerge(struct commit_list *common,
720720
}
721721
free_commit_list(remoteheads);
722722
strbuf_addch(&merge_msg, '\n');
723-
commit_tree(merge_msg.buf, result_tree, parents, result_commit);
723+
commit_tree(merge_msg.buf, result_tree, parents, result_commit, NULL);
724724
strbuf_addf(&buf, "Merge made by %s.", wt_strategy);
725725
finish(result_commit, buf.buf);
726726
strbuf_release(&buf);

builtin.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ extern int read_line_with_nul(char *buf, int size, FILE *file);
1717
extern int fmt_merge_msg(int merge_summary, struct strbuf *in,
1818
struct strbuf *out);
1919
extern int commit_tree(const char *msg, unsigned char *tree,
20-
struct commit_list *parents, unsigned char *ret);
20+
struct commit_list *parents, unsigned char *ret,
21+
const char *author);
2122
extern int check_pager_config(const char *cmd);
2223

2324
extern int cmd_add(int argc, const char **argv, const char *prefix);

0 commit comments

Comments
 (0)