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

Re: [PATCH v2] commit: accept tag objects in HEAD/MERGE_HEAD

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Aug 18, 2011, 02:10 UTC
Message-ID
<CACsJy8BxAOtaJKv50_Ntr2qjEpJNaWNq_obYv4u+L3O=z27wLA@mail.gmail.com>
In-Reply-To
<7vy5yrex70.fsf@alter.siamese.dyndns.org>
2011/8/18 Junio C Hamano <gitster@pobox.com>:
> By the way, what happens when you try to merge when HEAD points at a tag
> that points at a commit? Would we end up creating a commit that points at
> a bogus parent?

I guess I'd segfault the same way commit does. It does lookup_commit(head) without checking the result.

Show 21 quoted lines
>> diff --git a/builtin/commit.c b/builtin/commit.c
>> index 2088b6b..f327595 100644
>> --- a/builtin/commit.c
>> +++ b/builtin/commit.c
>> @@ -1387,6 +1387,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>>       unsigned char commit_sha1[20];
>>       struct ref_lock *ref_lock;
>>       struct commit_list *parents = NULL, **pptr = &parents;
>> +     struct commit *commit;
>>       struct stat statbuf;
>>       int allow_fast_forward = 1;
>>       struct wt_status s;
>
> Here, you are being inconsistent with your own argument you made in your
> previous message "later somebody may forget to update the former while
> updating the latter" when I suggested to separate the two logically
> separate operations (grab the head_commit object when necessary, and
> decide how the commit is made). By hoisting of the scope of "commit", you
> made the variable undefined when dealing with the initial_commit, exposing
> the code to the same risk that somebody may try to use "commit" variable
> after the if/elseif/... cascade, where it may or may not be defined.
Fair enough.
Show 16 quoted lines
>> @@ -1423,12 +1424,11 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>>                       reflog_msg = "commit (initial)";
>>       } else if (amend) {
>>               struct commit_list *c;
>> -             struct commit *commit;
>>
>>               if (!reflog_msg)
>>                       reflog_msg = "commit (amend)";
>> -             commit = lookup_commit(head_sha1);
>> -             if (!commit || parse_commit(commit))
>> +             commit = lookup_expect_commit(head_sha1, "HEAD");
>> +             if (parse_commit(commit))
>>                       die(_("could not parse HEAD commit"));
>
> Is this still necessary? I think your lookup_expect_commit() already
> checks this condition and barfs.

It is. lookup_expect_commit() does not parse commit content, only makes sure it's a commit object.

-- 
Duy
Previous: Junio C HamanoNext: Nguyễn Thái Ngọc Duy
Message 8 of 21 in “commit: check return value of lookup_commit()”
  1. commit: check return value of lookup_commit()Nguyễn Thái Ngọc Duy, Aug 15, 2011
  2. Junio C HamanoAug 15, 2011
  3. Nguyen Thai Ngoc DuyAug 16, 2011
  4. Junio C HamanoAug 16, 2011
  5. Nguyen Thai Ngoc DuyAug 17, 2011
  6. commit: accept tag objects in HEAD/MERGE_HEADNguyễn Thái Ngọc Duy, Aug 17, 2011
  7. Junio C HamanoAug 17, 2011
  8. Nguyen Thai Ngoc DuyAug 18, 2011
  9. Accept tags in HEAD or MERGE_HEADNguyễn Thái Ngọc Duy, Aug 18, 2011
  10. Junio C HamanoAug 18, 2011
  11. Nguyen Thai Ngoc DuyAug 19, 2011
  12. 1/4 commit: remove global variable head_sha1[]Nguyễn Thái Ngọc Duy, Aug 19, 2011
  13. 2/4 merge: keep stash[] a local variableNguyễn Thái Ngọc Duy, Aug 19, 2011
  14. Junio C HamanoAug 19, 2011
  15. 3/4 merge: remove global variable head[]Nguyễn Thái Ngọc Duy, Aug 19, 2011
  16. Junio C HamanoAug 23, 2011
  17. 4/4 Accept tags in HEAD or MERGE_HEADNguyễn Thái Ngọc Duy, Aug 19, 2011
  18. Junio C HamanoAug 19, 2011
  19. Nguyen Thai Ngoc DuyAug 20, 2011
  20. Junio C HamanoAug 19, 2011
  21. Nguyen Thai Ngoc DuyAug 20, 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.