Skip to content

Commit fcab40a

Browse files
committed
Merge branch 'mv/merge-in-c'
* mv/merge-in-c: reduce_heads(): protect from duplicate input reduce_heads(): thinkofix Add a new test for git-merge-resolve t6021: add a new test for git-merge-resolve Teach merge.log to "git-merge" again Build in merge Fix t7601-merge-pull-config.sh on AIX git-commit-tree: make it usable from other builtins Add new test case to ensure git-merge prepends the custom merge message Add new test case to ensure git-merge reduces octopus parents when possible Introduce reduce_heads() Introduce get_merge_bases_many() Add new test to ensure git-merge handles more than 25 refs. Introduce get_octopus_merge_bases() in commit.c git-fmt-merge-msg: make it usable from other builtins Move read_cache_unmerged() to read-cache.c Add new test to ensure git-merge handles pull.twohead and pull.octopus Move parse-options's skip_prefix() to git-compat-util.h Move commit_list_count() to commit.c Move split_cmdline() to alias.c Conflicts: Makefile parse-options.c
2 parents c158cae + 711f6b2 commit fcab40a

24 files changed

+1916
-219
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ SCRIPT_SH += git-lost-found.sh
240240
SCRIPT_SH += git-merge-octopus.sh
241241
SCRIPT_SH += git-merge-one-file.sh
242242
SCRIPT_SH += git-merge-resolve.sh
243-
SCRIPT_SH += git-merge.sh
244243
SCRIPT_SH += git-mergetool.sh
245244
SCRIPT_SH += git-parse-remote.sh
246245
SCRIPT_SH += git-pull.sh
@@ -515,6 +514,7 @@ BUILTIN_OBJS += builtin-ls-remote.o
515514
BUILTIN_OBJS += builtin-ls-tree.o
516515
BUILTIN_OBJS += builtin-mailinfo.o
517516
BUILTIN_OBJS += builtin-mailsplit.o
517+
BUILTIN_OBJS += builtin-merge.o
518518
BUILTIN_OBJS += builtin-merge-base.o
519519
BUILTIN_OBJS += builtin-merge-file.o
520520
BUILTIN_OBJS += builtin-merge-ours.o

alias.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,57 @@ char *alias_lookup(const char *alias)
2121
git_config(alias_lookup_cb, NULL);
2222
return alias_val;
2323
}
24+
25+
int split_cmdline(char *cmdline, const char ***argv)
26+
{
27+
int src, dst, count = 0, size = 16;
28+
char quoted = 0;
29+
30+
*argv = xmalloc(sizeof(char*) * size);
31+
32+
/* split alias_string */
33+
(*argv)[count++] = cmdline;
34+
for (src = dst = 0; cmdline[src];) {
35+
char c = cmdline[src];
36+
if (!quoted && isspace(c)) {
37+
cmdline[dst++] = 0;
38+
while (cmdline[++src]
39+
&& isspace(cmdline[src]))
40+
; /* skip */
41+
if (count >= size) {
42+
size += 16;
43+
*argv = xrealloc(*argv, sizeof(char*) * size);
44+
}
45+
(*argv)[count++] = cmdline + dst;
46+
} else if (!quoted && (c == '\'' || c == '"')) {
47+
quoted = c;
48+
src++;
49+
} else if (c == quoted) {
50+
quoted = 0;
51+
src++;
52+
} else {
53+
if (c == '\\' && quoted != '\'') {
54+
src++;
55+
c = cmdline[src];
56+
if (!c) {
57+
free(*argv);
58+
*argv = NULL;
59+
return error("cmdline ends with \\");
60+
}
61+
}
62+
cmdline[dst++] = c;
63+
src++;
64+
}
65+
}
66+
67+
cmdline[dst] = 0;
68+
69+
if (quoted) {
70+
free(*argv);
71+
*argv = NULL;
72+
return error("unclosed quote");
73+
}
74+
75+
return count;
76+
}
77+

builtin-commit-tree.c

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,41 +45,19 @@ static const char commit_utf8_warn[] =
4545
"You may want to amend it after fixing the message, or set the config\n"
4646
"variable i18n.commitencoding to the encoding your project uses.\n";
4747

48-
int cmd_commit_tree(int argc, const char **argv, const char *prefix)
48+
int commit_tree(const char *msg, unsigned char *tree,
49+
struct commit_list *parents, unsigned char *ret)
4950
{
50-
int i;
51-
struct commit_list *parents = NULL;
52-
unsigned char tree_sha1[20];
53-
unsigned char commit_sha1[20];
54-
struct strbuf buffer;
5551
int encoding_is_utf8;
52+
struct strbuf buffer;
5653

57-
git_config(git_default_config, NULL);
58-
59-
if (argc < 2)
60-
usage(commit_tree_usage);
61-
if (get_sha1(argv[1], tree_sha1))
62-
die("Not a valid object name %s", argv[1]);
63-
64-
check_valid(tree_sha1, OBJ_TREE);
65-
for (i = 2; i < argc; i += 2) {
66-
unsigned char sha1[20];
67-
const char *a, *b;
68-
a = argv[i]; b = argv[i+1];
69-
if (!b || strcmp(a, "-p"))
70-
usage(commit_tree_usage);
71-
72-
if (get_sha1(b, sha1))
73-
die("Not a valid object name %s", b);
74-
check_valid(sha1, OBJ_COMMIT);
75-
new_parent(lookup_commit(sha1), &parents);
76-
}
54+
check_valid(tree, OBJ_TREE);
7755

7856
/* Not having i18n.commitencoding is the same as having utf-8 */
7957
encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
8058

8159
strbuf_init(&buffer, 8192); /* should avoid reallocs for the headers */
82-
strbuf_addf(&buffer, "tree %s\n", sha1_to_hex(tree_sha1));
60+
strbuf_addf(&buffer, "tree %s\n", sha1_to_hex(tree));
8361

8462
/*
8563
* NOTE! This ordering means that the same exact tree merged with a
@@ -102,14 +80,47 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
10280
strbuf_addch(&buffer, '\n');
10381

10482
/* And add the comment */
105-
if (strbuf_read(&buffer, 0, 0) < 0)
106-
die("git-commit-tree: read returned %s", strerror(errno));
83+
strbuf_addstr(&buffer, msg);
10784

10885
/* And check the encoding */
10986
if (encoding_is_utf8 && !is_utf8(buffer.buf))
11087
fprintf(stderr, commit_utf8_warn);
11188

112-
if (!write_sha1_file(buffer.buf, buffer.len, commit_type, commit_sha1)) {
89+
return write_sha1_file(buffer.buf, buffer.len, commit_type, ret);
90+
}
91+
92+
int cmd_commit_tree(int argc, const char **argv, const char *prefix)
93+
{
94+
int i;
95+
struct commit_list *parents = NULL;
96+
unsigned char tree_sha1[20];
97+
unsigned char commit_sha1[20];
98+
struct strbuf buffer = STRBUF_INIT;
99+
100+
git_config(git_default_config, NULL);
101+
102+
if (argc < 2)
103+
usage(commit_tree_usage);
104+
if (get_sha1(argv[1], tree_sha1))
105+
die("Not a valid object name %s", argv[1]);
106+
107+
for (i = 2; i < argc; i += 2) {
108+
unsigned char sha1[20];
109+
const char *a, *b;
110+
a = argv[i]; b = argv[i+1];
111+
if (!b || strcmp(a, "-p"))
112+
usage(commit_tree_usage);
113+
114+
if (get_sha1(b, sha1))
115+
die("Not a valid object name %s", b);
116+
check_valid(sha1, OBJ_COMMIT);
117+
new_parent(lookup_commit(sha1), &parents);
118+
}
119+
120+
if (strbuf_read(&buffer, 0, 0) < 0)
121+
die("git-commit-tree: read returned %s", strerror(errno));
122+
123+
if (!commit_tree(buffer.buf, tree_sha1, parents, commit_sha1)) {
113124
printf("%s\n", sha1_to_hex(commit_sha1));
114125
return 0;
115126
}

0 commit comments

Comments
 (0)