Skip to content

Commit 96b8d93

Browse files
committed
commit-tree: teach -m/-F options to read logs from elsewhere
Just like "git commit" does. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 79a9312 commit 96b8d93

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

Documentation/git-commit-tree.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ git-commit-tree - Create a new commit object
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git commit-tree' <tree> [(-p <parent commit>)...] < changelog
12+
'git commit-tree' <tree> [(-p <parent>)...] < changelog
13+
'git commit-tree' [(-p <parent>)...] [(-m <message>)...] [(-F <file>)...] <tree>
1314

1415
DESCRIPTION
1516
-----------
1617
This is usually not what an end user wants to run directly. See
1718
linkgit:git-commit[1] instead.
1819

1920
Creates a new commit object based on the provided tree object and
20-
emits the new commit object id on stdout.
21+
emits the new commit object id on stdout. The log message is read
22+
from the standard input, unless `-m` or `-F` options are given.
2123

2224
A commit object may have any number of parents. With exactly one
2325
parent, it is an ordinary commit. Having more than one parent makes
@@ -39,9 +41,17 @@ OPTIONS
3941
<tree>::
4042
An existing tree object
4143

42-
-p <parent commit>::
44+
-p <parent>::
4345
Each '-p' indicates the id of a parent commit object.
4446

47+
-m <message>::
48+
A paragraph in the commig log message. This can be given more than
49+
once and each <message> becomes its own paragraph.
50+
51+
-F <file>::
52+
Read the commit log message from the given file. Use `-` to read
53+
from the standard input.
54+
4555

4656
Commit Information
4757
------------------

builtin/commit-tree.c

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "builtin.h"
1010
#include "utf8.h"
1111

12-
static const char commit_tree_usage[] = "git commit-tree <sha1> [(-p <sha1>)...] < changelog";
12+
static const char commit_tree_usage[] = "git commit-tree [(-p <sha1>)...] [-m <message>] [-F <file>] <sha1> <changelog";
1313

1414
static void new_parent(struct commit *parent, struct commit_list **parents_p)
1515
{
@@ -51,15 +51,52 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
5151
continue;
5252
}
5353

54+
if (!strcmp(arg, "-m")) {
55+
if (argc <= ++i)
56+
usage(commit_tree_usage);
57+
if (buffer.len)
58+
strbuf_addch(&buffer, '\n');
59+
strbuf_addstr(&buffer, argv[i]);
60+
strbuf_complete_line(&buffer);
61+
continue;
62+
}
63+
64+
if (!strcmp(arg, "-F")) {
65+
int fd;
66+
67+
if (argc <= ++i)
68+
usage(commit_tree_usage);
69+
if (buffer.len)
70+
strbuf_addch(&buffer, '\n');
71+
if (!strcmp(argv[i], "-"))
72+
fd = 0;
73+
else {
74+
fd = open(argv[i], O_RDONLY);
75+
if (fd < 0)
76+
die_errno("git commit-tree: failed to open '%s'",
77+
argv[i]);
78+
}
79+
if (strbuf_read(&buffer, fd, 0) < 0)
80+
die_errno("git commit-tree: failed to read '%s'",
81+
argv[i]);
82+
if (fd && close(fd))
83+
die_errno("git commit-tree: failed to close '%s'",
84+
argv[i]);
85+
strbuf_complete_line(&buffer);
86+
continue;
87+
}
88+
5489
if (get_sha1(arg, tree_sha1))
5590
die("Not a valid object name %s", arg);
5691
if (got_tree)
5792
die("Cannot give more than one trees");
5893
got_tree = 1;
5994
}
6095

61-
if (strbuf_read(&buffer, 0, 0) < 0)
62-
die_errno("git commit-tree: failed to read");
96+
if (!buffer.len) {
97+
if (strbuf_read(&buffer, 0, 0) < 0)
98+
die_errno("git commit-tree: failed to read");
99+
}
63100

64101
if (commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) {
65102
strbuf_release(&buffer);

0 commit comments

Comments
 (0)