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

Re: [PATCH 2/2] fast-import: allow to tag newly created objects

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 23, 2011, 18:32 UTC
Message-ID
<7vy5ykq8rb.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1314015019-6636-3-git-send-email-divanorama@gmail.com>
Dmitry Ivankov <divanorama@gmail.com> writes:
Show 11 quoted lines
>  	} else if (!get_sha1(from, sha1)) {
> -		type = sha1_object_info(sha1, NULL);
> -		if (type < 0)
> -			die("Not a valid object: %s", from);
> +		struct object_entry *oe = find_object(sha1);
> +		if (!oe) {
> +			type = sha1_object_info(sha1, NULL);
> +			if (type < 0)
> +				die("Not a valid object: %s", from);
> +		} else
> +			type = oe->type;

It might be just a "taste" thing, but I would have expected the above to be written like so:

	struct object_entry *oe = find_object(sha1);
	if (!oe)
		type = sha1_object_info(sha1, NULL);
	else
		type = oe->type;
	if (type < 0)
		die("Not a valid object: %s", from);

The point being that find_object()->type and the return value of sha1_object_info() are supposed to be compatible and interchangeably used, which is exactly why the same variable "type" gets assigned and later be used in the same codeflow, so they should get the same error checking, even if it happens to be that the current implementation of find_object() never returns an object with invalid type in it.

Previous: Dmitry Ivankov
Message 4 of 4 in “fast-import: tag any object by sha1”
  1. 0/2 fast-import: tag any object by sha1Dmitry Ivankov, Aug 22, 2011
  2. 1/2 fast-import: add tests for tagging blobsDmitry Ivankov, Aug 22, 2011
  3. 2/2 fast-import: allow to tag newly created objectsDmitry Ivankov, Aug 22, 2011
  4. Junio C HamanoAug 23, 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.