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

Re: [PATCH v2 2/3] fast-import: allow "merge $null_sha1" command

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jun 27, 2012, 21:33 UTC
Message-ID
<20120627213355.GO12774@burratino>
In-Reply-To
<1340818825-13754-3-git-send-email-divanorama@gmail.com>
Dmitry Ivankov wrote:
> "from $null_sha1" and "merge $empty_branch" are already allowed so
> allow "merge $null_sha1" command too.

The reader might not realize that null_sha1 means 0000000000000000000000000000000000000000 until she reads the test script. Is it possible to help her save time?

[...]
Show 20 quoted lines
> --- a/fast-import.c
> +++ b/fast-import.c
> @@ -2631,12 +2631,14 @@ static struct hash_list *parse_merge(unsigned int *count)
>  				die("Mark :%" PRIuMAX " not a commit", idnum);
>  			hashcpy(n->sha1, oe->idx.sha1);
>  		} else if (!get_sha1(from, n->sha1)) {
> -			unsigned long size;
> -			char *buf = read_object_with_reference(n->sha1,
> -				commit_type, &size, n->sha1);
> -			if (!buf || size < 46)
> -				die("Not a valid commit: %s", from);
> -			free(buf);
> +			if (!is_null_sha1(n->sha1)) {
> +				unsigned long size;
> +				char *buf = read_object_with_reference(n->sha1,
> +					commit_type, &size, n->sha1);
> +				if (!buf || size < 46)
> +					die("Not a valid commit: %s", from);
> +				free(buf);
> +			}

Hm, ok. Maybe the "peel onion" call guarded by this "if" could be a separate function to make this cleaner (and avoid some duplication of code with other functions while at it)?

e.g.,
	static int peel_to_commit(unsigned char sha1[20])
	{
		unsigned long size;
		char *buf = read_object_with_reference(...);
		if (!buf)
			return -1;
		free(buf);
		if (size < strlen("commit ") + 40)
			return -1;
		return 0;
	}
	...
		if (is_null_sha1(n->sha1))
			; /* ok */
		else if (peel_to_commit(n->sha1))
			die("Not a valid commit: %s", from);

I like the direction, but as it is, this patch feels kind of "meh" to me.

Thanks again and hope that helps, Jonathan

Previous: Dmitry IvankovNext: Junio C Hamano
Message 6 of 12 in “fast-import: disallow empty branches as parents”
  1. 0/3 fast-import: disallow empty branches as parentsDmitry Ivankov, Jun 27, 2012
  2. 1/3 fast-import: do not write null_sha1 as a merge parentDmitry Ivankov, Jun 27, 2012
  3. Jonathan NiederJun 27, 2012
  4. Jonathan NiederJul 24, 2012
  5. 2/3 fast-import: allow "merge $null_sha1" commandDmitry Ivankov, Jun 27, 2012
  6. Jonathan NiederJun 27, 2012
  7. Junio C HamanoJun 27, 2012
  8. Jonathan NiederJun 27, 2012
  9. Jonathan NiederJul 23, 2012
  10. 3/3 fast-import: disallow "merge $itself" commandDmitry Ivankov, Jun 27, 2012
  11. Jonathan NiederJun 27, 2012
  12. Jonathan NiederJul 24, 2012

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.