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

Re: [PATCH v4 4/4] Accept tags in HEAD or MERGE_HEAD

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 19, 2011, 20:17 UTC
Message-ID
<7vaab52m2r.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1313765407-29925-4-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
>  Junio's point, that if HEAD holds a tag, then head_sha1 and head->object.sha1
>  in statement [1] are different, is entirely correct. However, favoring
>  head->object.sha1 over head_sha1 is not enough. The variable head_sha1 is
>  still there. Somewhere, some time, people may misuse it.

That is why I suggested _removing_ head_sha1[] altogether, so that there is only one source of information. is_initial becomes !current_head and head_sha1 becomes (current_head ? current_head->object.sha1 : null_sha1).

Show 14 quoted lines
> diff --git a/commit.c b/commit.c
> index ac337c7..9e7f7ef 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -39,6 +39,25 @@ struct commit *lookup_commit_reference(const unsigned char *sha1)
>  	return lookup_commit_reference_gently(sha1, 0);
>  }
>  
> +/*
> + * Look sha1 up for a commit, defer if needed. If deference occurs,
> + * update "sha1" for consistency with retval->object.sha1. Also warn
> + * users this case because it is expected that sha1 points directly to
> + * a commit.
> + */

That's de-reference, not deference ;-). You may want to be more explicit about what kind of de-reference you are talking about.

/*
 * Get a commit object for the given sha1, unwrapping a tag object that
 * point at a commit while at it. ref_name is only used when the result 
 * is not a commit in the error message to report where we got the sha1
 * from.
 */

I actually was hoping that you would have this comment in commit.h to help people who want to add callers of this function, not next to the implementation.

As I said earlier, I do not think updating sha1[] here is necessary. The caller should be updated to use c->object.sha1 instead.

Show 12 quoted lines
> +struct commit *lookup_commit_or_die(unsigned char *sha1, const char *ref_name)
> +{
> +	struct commit *c = lookup_commit_reference(sha1);
> +	if (!c)
> +		die(_("could not parse %s"), ref_name);
> +	if (hashcmp(sha1, c->object.sha1)) {
> +		warning(_("%s %s is not a commit!"),
> +			ref_name, sha1_to_hex(sha1));
> +		hashcpy(sha1, c->object.sha1);
> +	}
> +	return c;
> +}
Previous: Nguyễn Thái Ngọc DuyNext: Nguyen Thai Ngoc Duy
Message 18 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.