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

Re: [PATCH] replace: fix replacing object with itself

From
Jeff King <peff@peff.net>
Date
Nov 9, 2014, 05:58 UTC
Message-ID
<20141109055842.GB13445@peff.net>
In-Reply-To
<1415491531-29913-1-git-send-email-manzurmm@gmail.com>
On Sun, Nov 09, 2014 at 01:05:31AM +0100, Manzur Mukhitdinov wrote:
Show 5 quoted lines
> When object is replaced with itself git shows unhelpful messages like(git log):
>     "fatal: replace depth too high for object <SHA1>"
> 
> Prevents user from replacing object with itself(with test for checking
> this case).

I thought we already did this in the last round of git-replace patches, but it looks like we only did it for the newly added --edit and --graft cases, not "git replace X X". I think this is probably a good step. I've also considered that this should be another way of deleting the replacement, but I think we decided that was too magical.

Show 12 quoted lines
> diff --git a/builtin/replace.c b/builtin/replace.c
> index 294b61b..b7e05ad 100644
> --- a/builtin/replace.c
> +++ b/builtin/replace.c
> @@ -186,6 +186,9 @@ static int replace_object(const char *object_ref, const char *replace_ref, int f
>  	if (get_sha1(replace_ref, repl))
>  		die("Failed to resolve '%s' as a valid ref.", replace_ref);
>  
> +	if (!hashcmp(object, repl))
> +		return error("new object is the same as the old one: '%s'", sha1_to_hex(object));
> +
>  	return replace_object_sha1(object_ref, object, replace_ref, repl, force);

I think all of the callers of replace_object_sha1 do this same check now. Can we just move the check into that function instead of adding another instance of it?

-Peff
Previous: Manzur MukhitdinovNext: Junio C Hamano
Message 2 of 3 in “replace: fix replacing object with itself”
  1. replace: fix replacing object with itselfManzur Mukhitdinov, Nov 9, 2014
  2. Jeff KingNov 9, 2014
  3. Junio C HamanoNov 9, 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.