Skip to content

Commit eb8aa3d

Browse files
committed
Merge branch 'jc/pull-signed-tag'
* jc/pull-signed-tag: commit-tree: teach -m/-F options to read logs from elsewhere commit-tree: update the command line parsing commit: teach --amend to carry forward extra headers merge: force edit and no-ff mode when merging a tag object commit: copy merged signed tags to headers of merge commit merge: record tag objects without peeling in MERGE_HEAD merge: make usage of commit->util more extensible fmt-merge-msg: Add contents of merged tag in the merge message fmt-merge-msg: package options into a structure fmt-merge-msg: avoid early returns refs DWIMmery: use the same rule for both "git fetch" and others fetch: allow "git fetch $there v1.0" to fetch a tag merge: notice local merging of tags and keep it unwrapped fetch: do not store peeled tag object names in FETCH_HEAD Split GPG interface into its own helper library Conflicts: builtin/fmt-merge-msg.c builtin/merge.c
2 parents a4043ae + 96b8d93 commit eb8aa3d

File tree

83 files changed

+825
-406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+825
-406
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
------------------

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ LIB_H += fmt-merge-msg.h
536536
LIB_H += fsck.h
537537
LIB_H += gettext.h
538538
LIB_H += git-compat-util.h
539+
LIB_H += gpg-interface.h
539540
LIB_H += graph.h
540541
LIB_H += grep.h
541542
LIB_H += hash.h
@@ -629,6 +630,7 @@ LIB_OBJS += entry.o
629630
LIB_OBJS += environment.o
630631
LIB_OBJS += exec_cmd.o
631632
LIB_OBJS += fsck.o
633+
LIB_OBJS += gpg-interface.o
632634
LIB_OBJS += graph.o
633635
LIB_OBJS += grep.o
634636
LIB_OBJS += hash.o

builtin.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ extern const char git_usage_string[];
1414
extern const char git_more_info_string[];
1515

1616
extern void prune_packed_objects(int);
17+
18+
struct fmt_merge_msg_opts {
19+
unsigned add_title:1;
20+
int shortlog_len;
21+
};
22+
1723
extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
18-
int merge_title, int shortlog_len);
24+
struct fmt_merge_msg_opts *);
1925
extern void commit_notes(struct notes_tree *t, const char *msg);
2026

2127
struct notes_rewrite_cfg {

builtin/commit-tree.c

Lines changed: 58 additions & 16 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
{
@@ -27,7 +27,7 @@ static void new_parent(struct commit *parent, struct commit_list **parents_p)
2727

2828
int cmd_commit_tree(int argc, const char **argv, const char *prefix)
2929
{
30-
int i;
30+
int i, got_tree = 0;
3131
struct commit_list *parents = NULL;
3232
unsigned char tree_sha1[20];
3333
unsigned char commit_sha1[20];
@@ -37,24 +37,66 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
3737

3838
if (argc < 2 || !strcmp(argv[1], "-h"))
3939
usage(commit_tree_usage);
40-
if (get_sha1(argv[1], tree_sha1))
41-
die("Not a valid object name %s", argv[1]);
4240

43-
for (i = 2; i < argc; i += 2) {
44-
unsigned char sha1[20];
45-
const char *a, *b;
46-
a = argv[i]; b = argv[i+1];
47-
if (!b || strcmp(a, "-p"))
48-
usage(commit_tree_usage);
41+
for (i = 1; i < argc; i++) {
42+
const char *arg = argv[i];
43+
if (!strcmp(arg, "-p")) {
44+
unsigned char sha1[20];
45+
if (argc <= ++i)
46+
usage(commit_tree_usage);
47+
if (get_sha1(argv[i], sha1))
48+
die("Not a valid object name %s", argv[i]);
49+
assert_sha1_type(sha1, OBJ_COMMIT);
50+
new_parent(lookup_commit(sha1), &parents);
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;
4966

50-
if (get_sha1(b, sha1))
51-
die("Not a valid object name %s", b);
52-
assert_sha1_type(sha1, OBJ_COMMIT);
53-
new_parent(lookup_commit(sha1), &parents);
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)
92+
die("Cannot give more than one trees");
93+
got_tree = 1;
5494
}
5595

56-
if (strbuf_read(&buffer, 0, 0) < 0)
57-
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+
}
58100

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

builtin/commit.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
13821382
int allow_fast_forward = 1;
13831383
struct wt_status s;
13841384
struct commit *current_head = NULL;
1385+
struct commit_extra_header *extra = NULL;
13851386

13861387
if (argc == 2 && !strcmp(argv[1], "-h"))
13871388
usage_with_options(builtin_commit_usage, builtin_commit_options);
@@ -1425,7 +1426,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
14251426
pptr = &commit_list_insert(c->item, pptr)->next;
14261427
} else if (whence == FROM_MERGE) {
14271428
struct strbuf m = STRBUF_INIT;
1428-
struct commit *commit;
14291429
FILE *fp;
14301430

14311431
if (!reflog_msg)
@@ -1436,11 +1436,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
14361436
die_errno(_("could not open '%s' for reading"),
14371437
git_path("MERGE_HEAD"));
14381438
while (strbuf_getline(&m, fp, '\n') != EOF) {
1439-
unsigned char sha1[20];
1440-
if (get_sha1_hex(m.buf, sha1) < 0)
1439+
struct commit *parent;
1440+
1441+
parent = get_merge_parent(m.buf);
1442+
if (!parent)
14411443
die(_("Corrupt MERGE_HEAD file (%s)"), m.buf);
1442-
commit = lookup_commit_or_die(sha1, "MERGE_HEAD");
1443-
pptr = &commit_list_insert(commit, pptr)->next;
1444+
pptr = &commit_list_insert(parent, pptr)->next;
14441445
}
14451446
fclose(fp);
14461447
strbuf_release(&m);
@@ -1483,12 +1484,16 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
14831484
exit(1);
14841485
}
14851486

1486-
if (commit_tree(sb.buf, active_cache_tree->sha1, parents, sha1,
1487-
author_ident.buf)) {
1487+
if (amend)
1488+
extra = read_commit_extra_headers(current_head);
1489+
1490+
if (commit_tree_extended(sb.buf, active_cache_tree->sha1, parents, sha1,
1491+
author_ident.buf, extra)) {
14881492
rollback_index_files();
14891493
die(_("failed to write commit object"));
14901494
}
14911495
strbuf_release(&author_ident);
1496+
free_commit_extra_headers(extra);
14921497

14931498
ref_lock = lock_any_ref_for_update("HEAD",
14941499
!current_head

builtin/fetch.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
436436
}
437437
note[note_len] = '\0';
438438
fprintf(fp, "%s\t%s\t%s",
439-
sha1_to_hex(commit ? commit->object.sha1 :
440-
rm->old_sha1),
439+
sha1_to_hex(rm->old_sha1),
441440
rm->merge ? "" : "not-for-merge",
442441
note);
443442
for (i = 0; i < url_len; ++i)

0 commit comments

Comments
 (0)