Skip to content

Commit c672f01

Browse files
committed
Merge branch 'jc/want-commit'
* jc/want-commit: Allow git merge ":/<pattern>"
2 parents e2b1405 + 6099835 commit c672f01

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

builtin/merge.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,16 @@ static void finish(const unsigned char *new_head, const char *msg)
403403
strbuf_release(&reflog_message);
404404
}
405405

406+
static struct object *want_commit(const char *name)
407+
{
408+
struct object *obj;
409+
unsigned char sha1[20];
410+
if (get_sha1(name, sha1))
411+
return NULL;
412+
obj = parse_object(sha1);
413+
return peel_to_type(name, 0, obj, OBJ_COMMIT);
414+
}
415+
406416
/* Get the name for the merge commit's message. */
407417
static void merge_name(const char *remote, struct strbuf *msg)
408418
{
@@ -418,7 +428,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
418428
remote = bname.buf;
419429

420430
memset(branch_head, 0, sizeof(branch_head));
421-
remote_head = peel_to_type(remote, 0, NULL, OBJ_COMMIT);
431+
remote_head = want_commit(remote);
422432
if (!remote_head)
423433
die(_("'%s' does not point to a commit"), remote);
424434

@@ -1124,7 +1134,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
11241134
if (!allow_fast_forward)
11251135
die(_("Non-fast-forward commit does not make sense into "
11261136
"an empty head"));
1127-
remote_head = peel_to_type(argv[0], 0, NULL, OBJ_COMMIT);
1137+
remote_head = want_commit(argv[0]);
11281138
if (!remote_head)
11291139
die(_("%s - not something we can merge"), argv[0]);
11301140
read_empty(remote_head->sha1, 0);
@@ -1170,7 +1180,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
11701180
struct object *o;
11711181
struct commit *commit;
11721182

1173-
o = peel_to_type(argv[i], 0, NULL, OBJ_COMMIT);
1183+
o = want_commit(argv[i]);
11741184
if (!o)
11751185
die(_("%s - not something we can merge"), argv[i]);
11761186
commit = lookup_commit(o->sha1);
@@ -1238,8 +1248,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12381248
if (have_message)
12391249
strbuf_addstr(&msg,
12401250
" (no commit created; -m option ignored)");
1241-
o = peel_to_type(sha1_to_hex(remoteheads->item->object.sha1),
1242-
0, NULL, OBJ_COMMIT);
1251+
o = want_commit(sha1_to_hex(remoteheads->item->object.sha1));
12431252
if (!o)
12441253
return 1;
12451254

sha1_name.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,6 @@ struct object *peel_to_type(const char *name, int namelen,
501501
{
502502
if (name && !namelen)
503503
namelen = strlen(name);
504-
if (!o) {
505-
unsigned char sha1[20];
506-
if (get_sha1_1(name, namelen, sha1))
507-
return NULL;
508-
o = parse_object(sha1);
509-
}
510504
while (1) {
511505
if (!o || (!o->parsed && !parse_object(o->sha1)))
512506
return NULL;

0 commit comments

Comments
 (0)