git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Felipe Contreras <felipe.contreras@gmail.com>
Cc: git@vger.kernel.org, Ramkumar Ramachandra <artagnon@gmail.com>,
	Jeff King <peff@peff.net>,
	"Duy Nguyen\" <pclouds@gmail.com>"@b-sasl-quonix.pobox.com
Subject: Re: [PATCH v2 4/6] sha1_name: refactor reinterpret()
Date: Tue, 30 Apr 2013 15:01:43 -0700	[thread overview]
Message-ID: <7va9ofbrug.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1367358554-4257-5-git-send-email-felipe.contreras@gmail.com> (Felipe Contreras's message of "Tue, 30 Apr 2013 16:49:12 -0500")

Felipe Contreras <felipe.contreras@gmail.com> writes:

> This code essentially replaces part of ref with another ref, for example
> '@{-1}@{u}' is replaced with 'master@{u}', but this can be reused for
> other purposes other than nth prior checkouts.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---

Makes sense.


>  sha1_name.c | 42 +++++++++++++++++++++++-------------------
>  1 file changed, 23 insertions(+), 19 deletions(-)
>
> diff --git a/sha1_name.c b/sha1_name.c
> index 93c4e8c..76e3219 100644
> --- a/sha1_name.c
> +++ b/sha1_name.c
> @@ -965,6 +965,27 @@ int get_sha1_mb(const char *name, unsigned char *sha1)
>  	return st;
>  }
>  
> +static int reinterpret(const char *name, int namelen, int len, struct strbuf *buf)
> +{
> +	/* we have extra data, which might need further processing */
> +	struct strbuf tmp = STRBUF_INIT;
> +	int used = buf->len;
> +	int ret;
> +
> +	strbuf_add(buf, name + len, namelen - len);
> +	ret = interpret_branch_name(buf->buf, &tmp);
> +	/* that data was not interpreted, remove our cruft */
> +	if (ret < 0) {
> +		strbuf_setlen(buf, used);
> +		return len;
> +	}
> +	strbuf_reset(buf);
> +	strbuf_addbuf(buf, &tmp);
> +	strbuf_release(&tmp);
> +	/* tweak for size of {-N} versus expanded ref name */
> +	return ret - used + len;
> +}
> +
>  /*
>   * This reads short-hand syntax that not only evaluates to a commit
>   * object name, but also can act as if the end user spelled the name
> @@ -998,25 +1019,8 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
>  		return len; /* syntax Ok, not enough switches */
>  	if (len > 0 && len == namelen)
>  		return len; /* consumed all */
> -	else if (len > 0) {
> -		/* we have extra data, which might need further processing */
> -		struct strbuf tmp = STRBUF_INIT;
> -		int used = buf->len;
> -		int ret;
> -
> -		strbuf_add(buf, name + len, namelen - len);
> -		ret = interpret_branch_name(buf->buf, &tmp);
> -		/* that data was not interpreted, remove our cruft */
> -		if (ret < 0) {
> -			strbuf_setlen(buf, used);
> -			return len;
> -		}
> -		strbuf_reset(buf);
> -		strbuf_addbuf(buf, &tmp);
> -		strbuf_release(&tmp);
> -		/* tweak for size of {-N} versus expanded ref name */
> -		return ret - used + len;
> -	}
> +	else if (len > 0)
> +		return reinterpret(name, namelen, len, buf);
>  
>  	cp = strchr(name, '@');
>  	if (!cp)

  reply	other threads:[~2013-04-30 22:01 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-30 21:49 [PATCH v2 0/6] New @ shortcut for HEAD Felipe Contreras
2013-04-30 21:49 ` [PATCH v2 1/6] sha1_name: remove no-op Felipe Contreras
2013-04-30 21:49 ` [PATCH v2 2/6] sha1_name: remove unnecessary braces Felipe Contreras
2013-04-30 21:49 ` [PATCH v2 3/6] sha1_name: avoid Yoda conditions Felipe Contreras
2013-04-30 22:00   ` Junio C Hamano
2013-04-30 22:04     ` Felipe Contreras
2013-04-30 22:13       ` Junio C Hamano
2013-04-30 22:20         ` Felipe Contreras
2013-04-30 22:30           ` Junio C Hamano
2013-04-30 22:32             ` Junio C Hamano
2013-04-30 22:45             ` Felipe Contreras
2013-04-30 23:02               ` Junio C Hamano
2013-04-30 23:07                 ` Junio C Hamano
2013-04-30 21:49 ` [PATCH v2 4/6] sha1_name: refactor reinterpret() Felipe Contreras
2013-04-30 22:01   ` Junio C Hamano [this message]
2013-04-30 21:49 ` [PATCH v2 5/6] Add new @ shortcut for HEAD Felipe Contreras
2013-04-30 22:07   ` Junio C Hamano
2013-05-01  2:03   ` Duy Nguyen
2013-05-02  2:44     ` Felipe Contreras
2013-05-02 16:49     ` Junio C Hamano
2013-04-30 21:49 ` [PATCH v2 6/6] sha1_name: allow @@{u} to work Felipe Contreras
2013-04-30 22:21   ` 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=7va9ofbrug.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc="Duy Nguyen\" <pclouds@gmail.com>"@b-sasl-quonix.pobox.com \
    --cc=artagnon@gmail.com \
    --cc=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).