Allow git merge ":/<pattern>"
It probably is not such a good idea to use ":/<pattern>" to specify which commit to merge, as ":/<pattern>" can often hit unexpected commits, but somebody tried it and got a nonsense error message: fatal: ':/Foo bar' does not point to a commit So here is a for-the-sake-of-consistency update that is fairly useless that allows users to carefully try not shooting in the foot. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Sep 7, 2011 at 11:16 UTC
6099835c1900876c813be6114ff4e81f6d90e8a3
2 files changed
+14
-11
builtin/merge.c
+14
-5
@@ -405,6 +405,16 @@ static void finish(const unsigned char *new_head, const char *msg)
405
strbuf_release(&reflog_message);
406
}
407
408
+static struct object *want_commit(const char *name)
409
+{
410
+ struct object *obj;
411
+ unsigned char sha1[20];
412
+ if (get_sha1(name, sha1))
413
+ return NULL;
414
+ obj = parse_object(sha1);
415
+ return peel_to_type(name, 0, obj, OBJ_COMMIT);
416
+}
417
+
418
/* Get the name for the merge commit's message. */
419
static void merge_name(const char *remote, struct strbuf *msg)
420
{
@@ -420,7 +430,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
430
remote = bname.buf;
431
432
memset(branch_head, 0, sizeof(branch_head));
423
- remote_head = peel_to_type(remote, 0, NULL, OBJ_COMMIT);
433
+ remote_head = want_commit(remote);
434
if (!remote_head)
435
die(_("'%s' does not point to a commit"), remote);
436
@@ -1130,7 +1140,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1140
if (!allow_fast_forward)
1141
die(_("Non-fast-forward commit does not make sense into "
1142
"an empty head"));
1133
- remote_head = peel_to_type(argv[0], 0, NULL, OBJ_COMMIT);
1143
+ remote_head = want_commit(argv[0]);
1144
if (!remote_head)
1145
die(_("%s - not something we can merge"), argv[0]);
1146
read_empty(remote_head->sha1, 0);
@@ -1176,7 +1186,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1186
struct object *o;
1187
struct commit *commit;
1188
1179
- o = peel_to_type(argv[i], 0, NULL, OBJ_COMMIT);
1189
+ o = want_commit(argv[i]);
1190
if (!o)
1191
die(_("%s - not something we can merge"), argv[i]);
1192
commit = lookup_commit(o->sha1);
@@ -1244,8 +1254,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1254
if (have_message)
1255
strbuf_addstr(&msg,
1256
" (no commit created; -m option ignored)");
1247
- o = peel_to_type(sha1_to_hex(remoteheads->item->object.sha1),
1248
- 0, NULL, OBJ_COMMIT);
1257
+ o = want_commit(sha1_to_hex(remoteheads->item->object.sha1));
1258
if (!o)
1259
return 1;
1260
sha1_name.c
-6
@@ -501,12 +501,6 @@ struct object *peel_to_type(const char *name, int namelen,
501
{
502
if (name && !namelen)
503
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
- }
504
while (1) {
505
if (!o || (!o->parsed && !parse_object(o->sha1)))
506
return NULL;