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 <vmiklos@frugalware.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Miklos Vajna committed
Sep 10, 2008 at 22:10 UTC
ee20a129de6f332da092e93feb2dd5f8330f9bc0
3 files changed
+10
-6
builtin-commit-tree.c
+6
-3
@@ -46,7 +46,8 @@ static const char commit_utf8_warn[] =
46
"variable i18n.commitencoding to the encoding your project uses.\n";
47
48
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)
51
{
52
int result;
53
int encoding_is_utf8;
@@ -74,7 +75,9 @@ int commit_tree(const char *msg, unsigned char *tree,
75
}
76
77
/* 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);
81
strbuf_addf(&buffer, "committer %s\n", git_committer_info(IDENT_ERROR_ON_NO_NAME));
82
if (!encoding_is_utf8)
83
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)
126
if (strbuf_read(&buffer, 0, 0) < 0)
127
die("git commit-tree: read returned %s", strerror(errno));
128
126
- if (!commit_tree(buffer.buf, tree_sha1, parents, commit_sha1)) {
129
+ if (!commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) {
130
printf("%s\n", sha1_to_hex(commit_sha1));
131
return 0;
132
}
builtin-merge.c
+2
-2
@@ -691,7 +691,7 @@ static int merge_trivial(void)
691
parent->next = xmalloc(sizeof(struct commit_list *));
692
parent->next->item = remoteheads->item;
693
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);
695
finish(result_commit, "In-index merge");
696
drop_save();
697
return 0;
@@ -720,7 +720,7 @@ static int finish_automerge(struct commit_list *common,
720
}
721
free_commit_list(remoteheads);
722
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);
724
strbuf_addf(&buf, "Merge made by %s.", wt_strategy);
725
finish(result_commit, buf.buf);
726
strbuf_release(&buf);
builtin.h
+2
-1
@@ -17,7 +17,8 @@ extern int read_line_with_nul(char *buf, int size, FILE *file);
17
extern int fmt_merge_msg(int merge_summary, struct strbuf *in,
18
struct strbuf *out);
19
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);
22
extern int check_pager_config(const char *cmd);
23
24
extern int cmd_add(int argc, const char **argv, const char *prefix);