git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH] commit: check return value of lookup_commit()
Date: Tue, 16 Aug 2011 11:02:23 -0700	[thread overview]
Message-ID: <7vy5ytgrps.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <CACsJy8AusStKNWuw3j740r4Nc0FhzR+jJZJNaesxn68pr7dTqA@mail.gmail.com> (Nguyen Thai Ngoc Duy's message of "Tue, 16 Aug 2011 20:22:27 +0700")

Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:

> 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.

>>  - 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.

  reply	other threads:[~2011-08-16 18:02 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-15 15:38 [PATCH] commit: check return value of lookup_commit() Nguyễn Thái Ngọc Duy
2011-08-15 17:46 ` Junio C Hamano
2011-08-16 13:22   ` Nguyen Thai Ngoc Duy
2011-08-16 18:02     ` Junio C Hamano [this message]
2011-08-17  1:32       ` Nguyen Thai Ngoc Duy
2011-08-17  1:42 ` [PATCH v2] commit: accept tag objects in HEAD/MERGE_HEAD Nguyễn Thái Ngọc Duy
2011-08-17 17:59   ` Junio C Hamano
2011-08-18  2:10     ` Nguyen Thai Ngoc Duy
2011-08-18 13:43   ` [PATCH v3] Accept tags in HEAD or MERGE_HEAD Nguyễn Thái Ngọc Duy
2011-08-18 18:54     ` Junio C Hamano
2011-08-19 12:53       ` Nguyen Thai Ngoc Duy
2011-08-19 14:50     ` [PATCH v4 1/4] commit: remove global variable head_sha1[] Nguyễn Thái Ngọc Duy
2011-08-19 14:50       ` [PATCH v4 2/4] merge: keep stash[] a local variable Nguyễn Thái Ngọc Duy
2011-08-19 22:59         ` Junio C Hamano
2011-08-19 14:50       ` [PATCH v4 3/4] merge: remove global variable head[] Nguyễn Thái Ngọc Duy
2011-08-23 18:46         ` Junio C Hamano
2011-08-19 14:50       ` [PATCH v4 4/4] Accept tags in HEAD or MERGE_HEAD Nguyễn Thái Ngọc Duy
2011-08-19 20:17         ` Junio C Hamano
2011-08-20 16:37           ` Nguyen Thai Ngoc Duy
2011-08-19 18:57       ` [PATCH v4 1/4] commit: remove global variable head_sha1[] Junio C Hamano
2011-08-20 12:03         ` Nguyen Thai Ngoc Duy

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=7vy5ytgrps.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.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).