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

Re: [PATCH] commit: check return value of lookup_commit()

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 16, 2011, 18:02 UTC
Message-ID
<7vy5ytgrps.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CACsJy8AusStKNWuw3j740r4Nc0FhzR+jJZJNaesxn68pr7dTqA@mail.gmail.com>
Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
Show 13 quoted lines
> 2011/8/16 Junio C Hamano <gitster@pobox.com>:
>> The change itself looks good to me but a point and a half to think about:
>>
>>  - In this if/elseif/.../else cascade, everybody except for the
>>   "initial_commit" case needs to make sure that head_sha1 points at a
>>   valid commit and get an commit object. Hoisting the scope of the
>>   variable "commit" one level in your patch is good, but it would make it
>>   easier to read and the future code modification much less error prone
>>   if (1) you called lookup_commit() and checked for errors before
>>   entering this if/elseif/... cascade, and (2) you renamed this variable
>>   to "head_commit".
>
> But then I would need to avoid die()ing in "initial_commit" case.
That's exactly what I said.
	if (!initial)
	        /* we need to know the head_commit */
                head_commit = lookup_and_check(HEAD);
	/* depending on what kind of commit, we need different stuff */
        if (initial)
        	... going to create a parentless commit
	else if (amending)
		... use the head_commit to learn parent, reuse the message
                ... from there
	else if ...

These two are independent if/else cascades in the sense that the first is about learning the details of head_commit, and the latter is about learning how the commit is done, and in a subset of the latter head_commit is used.

Show 7 quoted lines
>>  - Whether we like it or not, many people have a broken reimplementations
>>   of git that can put a non-commit in HEAD, and they won't be fixed
>>   overnight. Instead of erroring out, would it be nicer of us if we just
>>   warned, unwrapped the tag and used the tagged commit instead?
>
> How about replacing those lookup_commit() with this? It would tolerate
> tag-in-branch case, but also warn users that something's gone wrong.
Yes, that is exactly what I meant.
Thakns.
Previous: Nguyen Thai Ngoc DuyNext: Nguyen Thai Ngoc Duy
Message 4 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.