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

Re: [RFC/PATCH] replace: add --graft option

From
Jeff King <peff@peff.net>
Date
May 19, 2014, 11:21 UTC
Message-ID
<20140519112151.GC17492@sigill.intra.peff.net>
In-Reply-To
<20140518182939.5260.91202.chriscool@tuxfamily.org>
On Sun, May 18, 2014 at 08:29:38PM +0200, Christian Couder wrote:
Show 14 quoted lines
> +static int create_graft(int argc, const char **argv, int force)
> +{
> +	unsigned char old[20], new[20];
> +	const char *old_ref = argv[0];
> +	struct strbuf buf = STRBUF_INIT;
> +	struct strbuf new_parents = STRBUF_INIT;
> +	const char *parent_start, *parent_end;
> +	int i;
> +
> +	if (get_sha1(old_ref, old) < 0)
> +		die(_("Not a valid object name: '%s'"), old_ref);
> +	lookup_commit_or_die(old, old_ref);
> +	if (read_sha1_commit(old, &buf))
> +		die(_("Invalid commit: '%s'"), old_ref);
Do we want to peel to commits here? That is, should:
  git replace --graft v1.5.0 v1.4.0

work? On the one hand, I see it as friendly. On the other, it may be a bit surprising when working with something as potentially dangerous a replace refs. If we don't do it automatically, the user can still say "v1.5.0^{commit}" to be explicit. I dunno; maybe I am being overly paranoid.

Show 8 quoted lines
> +	/* prepare new parents */
> +	for (i = 1; i < argc; i++) {
> +		unsigned char sha1[20];
> +		if (get_sha1(argv[i], sha1) < 0)
> +			die(_("Not a valid object name: '%s'"), argv[i]);
> +		lookup_commit_or_die(sha1, argv[i]);
> +		strbuf_addf(&new_parents, "parent %s\n", sha1_to_hex(sha1));
> +	}
Either way, I think _this_ peeling is a sane thing to do.
-Peff
Previous: Christian Couder
Message 8 of 8 in “replace: add --graft option”
  1. replace: add --graft optionChristian Couder, May 18, 2014
  2. Michael HaggertyMay 19, 2014
  3. Jeff KingMay 19, 2014
  4. Junio C HamanoMay 19, 2014
  5. Jeff KingMay 19, 2014
  6. Junio C HamanoMay 19, 2014
  7. Christian CouderMay 23, 2014
  8. Jeff KingMay 19, 2014

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.