git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v5 2/4] merge: use return value of resolve_ref() to determine if HEAD is invalid

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Sep 17, 2011, 11:57 UTC
Message-ID
<1316260665-1728-2-git-send-email-pclouds@gmail.com>
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
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 2 of 5 in “merge: keep stash[] a local variable”
  1. 1/4 merge: keep stash[] a local variableNguyễn Thái Ngọc Duy, Sep 17, 2011
  2. 2/4 merge: use return value of resolve_ref() to determine if HEAD is invalidNguyễn Thái Ngọc Duy, Sep 17, 2011
  3. 3/4 merge: remove global variable head[]Nguyễn Thái Ngọc Duy, Sep 17, 2011
  4. 4/4 Accept tags in HEAD or MERGE_HEADNguyễn Thái Ngọc Duy, Sep 17, 2011
  5. Junio C HamanoSep 18, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.