commit-tree: teach -m/-F options to read logs from elsewhere
Just like "git commit" does. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Nov 9, 2011 at 11:54 UTC
96b8d93a539f3a9f43f0fc38214db8753cac3c2e
2 files changed
+53
-6
Documentation/git-commit-tree.txt
+13
-3
@@ -9,7 +9,8 @@ git-commit-tree - Create a new commit object
9
SYNOPSIS
10
--------
11
[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>
14
15
DESCRIPTION
16
-----------
@@ -17,7 +18,8 @@ This is usually not what an end user wants to run directly. See
18
linkgit:git-commit[1] instead.
19
20
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.
23
24
A commit object may have any number of parents. With exactly one
25
parent, it is an ordinary commit. Having more than one parent makes
@@ -39,9 +41,17 @@ OPTIONS
41
<tree>::
42
An existing tree object
43
42
--p <parent commit>::
44
+-p <parent>::
45
Each '-p' indicates the id of a parent commit object.
46
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
+
55
56
Commit Information
57
------------------
builtin/commit-tree.c
+40
-3
@@ -9,7 +9,7 @@
9
#include "builtin.h"
10
#include "utf8.h"
11
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";
13
14
static void new_parent(struct commit *parent, struct commit_list **parents_p)
15
{
@@ -51,6 +51,41 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
51
continue;
52
}
53
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
+
89
if (get_sha1(arg, tree_sha1))
90
die("Not a valid object name %s", arg);
91
if (got_tree)
@@ -58,8 +93,10 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
93
got_tree = 1;
94
}
95
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
+ }
100
101
if (commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) {
102
strbuf_release(&buffer);