From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v5 2/4] merge: use return value of resolve_ref() to determine if HEAD is invalid
Date: Sat, 17 Sep 2011 21:57:43 +1000 [thread overview]
Message-ID: <1316260665-1728-2-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1316260665-1728-1-git-send-email-pclouds@gmail.com>
resolve_ref() only updates "head" when it returns non NULL value (it
may update "head" even when returning NULL, but not in all cases).
Because "head" is not initialized before the call, is_null_sha1() is
not enough. Check also resolve_ref() return value.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
>> - if (is_null_sha1(head))
>> - head_invalid = 1;
>> + if (!is_null_sha1(head)) {
>> + head_commit = lookup_commit(head);
>> + if (!head_commit)
>> + die(_("could not parse HEAD"));
>> + }
>
> Is this is_null_sha1() valid without first clearing head[]?
No it's not.
builtin/merge.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index a068660..c371484 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1030,7 +1030,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
branch = resolve_ref("HEAD", head, 0, &flag);
if (branch && !prefixcmp(branch, "refs/heads/"))
branch += 11;
- if (is_null_sha1(head))
+ if (!branch || is_null_sha1(head))
head_invalid = 1;
git_config(git_merge_config, NULL);
--
1.7.3.1.256.g2539c.dirty
next prev parent reply other threads:[~2011-09-17 11:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-17 11:57 [PATCH v5 1/4] merge: keep stash[] a local variable Nguyễn Thái Ngọc Duy
2011-09-17 11:57 ` Nguyễn Thái Ngọc Duy [this message]
2011-09-17 11:57 ` [PATCH v5 3/4] merge: remove global variable head[] Nguyễn Thái Ngọc Duy
2011-09-17 11:57 ` [PATCH v5 4/4] Accept tags in HEAD or MERGE_HEAD Nguyễn Thái Ngọc Duy
2011-09-18 21:51 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1316260665-1728-2-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).