All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Christian Couder <chriscool@tuxfamily.org>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>,
	Michael Haggerty <mhagger@alum.mit.edu>,
	Jakub Narebski <jnareb@gmail.com>,
	Eric Sunshine <sunshine@sunshineco.com>
Subject: Re: [PATCH v6 02/10] replace: add --graft option
Date: Wed, 09 Jul 2014 07:59:20 -0700	[thread overview]
Message-ID: <xmqqsima7f3r.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: 20140707063540.3708.51047.chriscool@tuxfamily.org

Christian Couder <chriscool@tuxfamily.org> writes:

> The usage string for this option is:
>
> git replace [-f] --graft <commit> [<parent>...]
>
> First we create a new commit that is the same as <commit>
> except that its parents are [<parents>...]
>
> Then we create a replace ref that replace <commit> with
> the commit we just created.
>
> With this new option, it should be straightforward to
> convert grafts to replace refs.

Sensible.

>
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  builtin/replace.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 73 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/replace.c b/builtin/replace.c
> index 1bb491d..ad47237 100644
> --- a/builtin/replace.c
> +++ b/builtin/replace.c
> @@ -17,6 +17,7 @@
>  static const char * const git_replace_usage[] = {
>  	N_("git replace [-f] <object> <replacement>"),
>  	N_("git replace [-f] --edit <object>"),
> +	N_("git replace [-f] --graft <commit> [<parent>...]"),
>  	N_("git replace -d <object>..."),
>  	N_("git replace [--format=<format>] [-l [<pattern>]]"),
>  	NULL
> @@ -294,6 +295,66 @@ static int edit_and_replace(const char *object_ref, int force)
>  	return replace_object_sha1(object_ref, old, "replacement", new, force);
>  }
>  
> +static void replace_parents(struct strbuf *buf, int argc, const char **argv)
> +{
> +	struct strbuf new_parents = STRBUF_INIT;
> +	const char *parent_start, *parent_end;
> +	int i;
> +
> +	/* find existing parents */
> +	parent_start = buf->buf;
> +	parent_start += 46; /* "tree " + "hex sha1" + "\n" */
> +	parent_end = parent_start;
> +
> +	while (starts_with(parent_end, "parent "))
> +		parent_end += 48; /* "parent " + "hex sha1" + "\n" */
> +
> +	/* prepare new parents */
> +	for (i = 1; i < argc; i++) {

It looks somewhat strange that both replace_parents() and
create_graft() take familiar-looking <argc, argv> pair, but one
ignores argv[0] and uses the remainder and the other uses argv[0].
Shouldn't this function consume argv[] starting from [0] for
consistency?  You'd obviously need to update the caller to adjust
the arguments it gives to this function.

> +static int create_graft(int argc, const char **argv, int force)
> +{
> +	unsigned char old[20], new[20];
> +	const char *old_ref = argv[0];
> +...
> +
> +	replace_parents(&buf, argc, argv);
> +
> +	if (write_sha1_file(buf.buf, buf.len, commit_type, new))
> +		die(_("could not write replacement commit for: '%s'"), old_ref);
> +
> +	strbuf_release(&buf);
> +
> +	if (!hashcmp(old, new))
> +		return error("new commit is the same as the old one: '%s'", sha1_to_hex(old));

Is this really an error?  It may be a warning-worthy situation for a
user or a script to end up doing a no-op graft, e.g.

	git replace --graft HEAD HEAD^

but I wonder if it is more convenient to signal an error (like this
patch does) or just ignore the request and return without adding the
replace ref.

Other than these two points, looks good to me.

Thanks.

  reply	other threads:[~2014-07-09 14:59 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-07  6:35 [PATCH v6 00/10] Add --graft option to git replace Christian Couder
2014-07-07  6:35 ` [PATCH v6 01/10] replace: cleanup redirection style in tests Christian Couder
2014-07-07  6:35 ` [PATCH v6 02/10] replace: add --graft option Christian Couder
2014-07-09 14:59   ` Junio C Hamano [this message]
2014-07-10  9:30     ` Christian Couder
2014-07-10 16:51       ` Junio C Hamano
2014-07-10 17:36         ` Junio C Hamano
2014-07-11  8:59           ` Christian Couder
2014-07-11 14:22             ` Junio C Hamano
2014-07-11 16:24               ` Christian Couder
2014-07-11 18:25                 ` Junio C Hamano
2014-07-11 18:29                   ` Jeff King
2014-07-07  6:35 ` [PATCH v6 03/10] replace: add test for --graft Christian Couder
2014-07-07 22:16   ` Junio C Hamano
2014-07-08  5:36     ` Christian Couder
2014-07-07  6:35 ` [PATCH v6 04/10] Documentation: replace: add --graft option Christian Couder
2014-07-07  6:35 ` [PATCH v6 05/10] contrib: add convert-grafts-to-replace-refs.sh Christian Couder
2014-07-07  6:35 ` [PATCH v6 06/10] replace: remove signature when using --graft Christian Couder
2014-07-07  6:35 ` [PATCH v6 07/10] replace: add test for --graft with signed commit Christian Couder
2014-07-07  6:35 ` [PATCH v6 08/10] commit: add for_each_mergetag() Christian Couder
2014-07-07 22:30   ` Junio C Hamano
2014-07-08  5:53     ` Christian Couder
2014-07-07  6:35 ` [PATCH v6 09/10] replace: check mergetags when using --graft Christian Couder
2014-07-07 22:28   ` Junio C Hamano
2014-07-08  5:35     ` Christian Couder
2014-07-07  6:35 ` [PATCH v6 10/10] replace: add test for --graft with a mergetag Christian Couder

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=xmqqsima7f3r.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=jnareb@gmail.com \
    --cc=mhagger@alum.mit.edu \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.