From: Junio C Hamano <gitster@pobox•com>
To: Manzur Mukhitdinov <manzurmm@gmail•com>
Cc: git@vger•kernel.org, Jeff King <peff@peff•net>
Subject: Re: [PATCH] replace: fix replacing object with itself
Date: Fri, 14 Nov 2014 14:45:55 -0800 [thread overview]
Message-ID: <xmqqppcp1jvg.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1415887559-16585-1-git-send-email-manzurmm@gmail.com> (Manzur Mukhitdinov's message of "Thu, 13 Nov 2014 15:05:59 +0100")
Manzur Mukhitdinov <manzurmm@gmail•com> writes:
> 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).
>
> Signed-off-by: Manzur Mukhitdinov <manzurmm@gmail•com>
> ---
The patch is not wrong per-se, but I wonder how useful this "do not
replace itself but all other forms of loops are not checked at all"
would be in practice. If your user did this:
git replace A B ;# pretend as if what is in B is in A
git replace B C ;# pretend as if what is in C is in B
git replace C A ;# pretend as if we have loop
git log C
she would not be helped with this patch at all, no?
We have the "replace depth" thing, which is a poor-man's substitute
for loop detection, primarily because we do not want to incur high
cost of loop detection at runtime. Shouldn't we be doing at least
the same amount of loop-avoidance check, if we really want to avoid
triggering the "replace depth" check at runtime?
> builtin/replace.c | 8 +++-----
> t/t6050-replace.sh | 11 +++++++++--
> 2 files changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/builtin/replace.c b/builtin/replace.c
> index 294b61b..628377a 100644
> --- a/builtin/replace.c
> +++ b/builtin/replace.c
> @@ -157,6 +157,9 @@ static int replace_object_sha1(const char *object_ref,
> char ref[PATH_MAX];
> struct ref_lock *lock;
>
> + if (!hashcmp(object, repl))
> + return error("new object is the same as the old one: '%s'", sha1_to_hex(object));
> +
> obj_type = sha1_object_info(object, NULL);
> repl_type = sha1_object_info(repl, NULL);
> if (!force && obj_type != repl_type)
> @@ -295,9 +298,6 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
>
> free(tmpfile);
>
> - if (!hashcmp(old, new))
> - return error("new object is the same as the old one: '%s'", sha1_to_hex(old));
> -
> return replace_object_sha1(object_ref, old, "replacement", new, force);
> }
>
> @@ -406,8 +406,6 @@ static int create_graft(int argc, const char **argv, int force)
>
> strbuf_release(&buf);
>
> - if (!hashcmp(old, new))
> - return error("new commit is the same as the old one: '%s'", sha1_to_hex(old));
>
> return replace_object_sha1(old_ref, old, "replacement", new, force);
> }
> diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh
> index 4d5a25e..5f96374 100755
> --- a/t/t6050-replace.sh
> +++ b/t/t6050-replace.sh
> @@ -369,9 +369,8 @@ test_expect_success '--edit with and without already replaced object' '
> git cat-file commit "$PARA3" | grep "A fake Thor"
> '
>
> -test_expect_success '--edit and change nothing or command failed' '
> +test_expect_success '--edit with failed editor' '
> git replace -d "$PARA3" &&
> - test_must_fail env GIT_EDITOR=true git replace --edit "$PARA3" &&
> test_must_fail env GIT_EDITOR="./fakeeditor;false" git replace --edit "$PARA3" &&
> GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" &&
> git replace -l | grep "$PARA3" &&
> @@ -440,4 +439,12 @@ test_expect_success GPG '--graft on a commit with a mergetag' '
> git replace -d $HASH10
> '
>
> +test_expect_success 'replacing object with itself must fail' '
> + test_must_fail git replace $HASH1 $HASH1 &&
> + HASH8=$(git rev-parse --verify HEAD) &&
> + test_must_fail git replace HEAD $HASH8 &&
> + test_must_fail git replace --graft HEAD HEAD^ &&
> + test_must_fail env GIT_EDITOR=true git replace --edit HEAD
> +'
> +
> test_done
next prev parent reply other threads:[~2014-11-14 22:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-13 14:05 [PATCH] replace: fix replacing object with itself Manzur Mukhitdinov
2014-11-14 22:45 ` Junio C Hamano [this message]
2014-11-15 11:55 ` Christian Couder
2014-11-16 18:59 ` Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2014-11-10 23:20 Manzur Mukhitdinov
2014-11-11 3:03 ` Jeff King
2014-11-09 0:05 Manzur Mukhitdinov
2014-11-09 5:58 ` Jeff King
2014-11-09 17:35 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqppcp1jvg.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=manzurmm@gmail$(echo .)com \
--cc=peff@peff$(echo .)net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox