From: Junio C Hamano <gitster@pobox•com>
To: Felipe Contreras <felipe.contreras@gmail•com>
Cc: git@vger•kernel.org, Stefano Lattarini <stefano.lattarini@gmail•com>
Subject: Re: [PATCH v5 1/2] sha1-name: pass len argument to interpret_branch_name()
Date: Tue, 03 Sep 2013 11:40:37 -0700 [thread overview]
Message-ID: <xmqqioyhsq8q.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1378103670-3394-2-git-send-email-felipe.contreras@gmail.com> (Felipe Contreras's message of "Mon, 2 Sep 2013 01:34:29 -0500")
Felipe Contreras <felipe.contreras@gmail•com> writes:
> This is useful to make sure we don't step outside the boundaries of what
> we are interpreting at the moment. For example while interpreting
> foobar@{u}~1, the job of interpret_branch_name() ends right before ~1,
> but there's no way to figure that out inside the function, unless the
> len argument is passed.
>
> So let's do that.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail•com>
Makes sense to me. Thanks.
> ---
> cache.h | 2 +-
> refs.c | 2 +-
> revision.c | 2 +-
> sha1_name.c | 10 ++++++----
> 4 files changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/cache.h b/cache.h
> index 85b544f..9fbc5fa 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -893,7 +893,7 @@ extern char *resolve_refdup(const char *ref, unsigned char *sha1, int reading, i
>
> extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
> extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
> -extern int interpret_branch_name(const char *str, struct strbuf *);
> +extern int interpret_branch_name(const char *str, int len, struct strbuf *);
> extern int get_sha1_mb(const char *str, unsigned char *sha1);
>
> extern int refname_match(const char *abbrev_name, const char *full_name, const char **rules);
> diff --git a/refs.c b/refs.c
> index 7922261..8fd5faf 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -1951,7 +1951,7 @@ static int remove_empty_directories(const char *file)
> static char *substitute_branch_name(const char **string, int *len)
> {
> struct strbuf buf = STRBUF_INIT;
> - int ret = interpret_branch_name(*string, &buf);
> + int ret = interpret_branch_name(*string, *len, &buf);
>
> if (ret == *len) {
> size_t size;
> diff --git a/revision.c b/revision.c
> index 84ccc05..3ef1384 100644
> --- a/revision.c
> +++ b/revision.c
> @@ -200,7 +200,7 @@ static void add_pending_object_with_mode(struct rev_info *revs,
> revs->no_walk = 0;
> if (revs->reflog_info && obj->type == OBJ_COMMIT) {
> struct strbuf buf = STRBUF_INIT;
> - int len = interpret_branch_name(name, &buf);
> + int len = interpret_branch_name(name, 0, &buf);
> int st;
>
> if (0 < len && name[len] && buf.len)
> diff --git a/sha1_name.c b/sha1_name.c
> index 65ad066..93197b9 100644
> --- a/sha1_name.c
> +++ b/sha1_name.c
> @@ -1012,7 +1012,7 @@ static int reinterpret(const char *name, int namelen, int len, struct strbuf *bu
> int ret;
>
> strbuf_add(buf, name + len, namelen - len);
> - ret = interpret_branch_name(buf->buf, &tmp);
> + ret = interpret_branch_name(buf->buf, buf->len, &tmp);
> /* that data was not interpreted, remove our cruft */
> if (ret < 0) {
> strbuf_setlen(buf, used);
> @@ -1046,14 +1046,16 @@ static int reinterpret(const char *name, int namelen, int len, struct strbuf *bu
> * If the input was ok but there are not N branch switches in the
> * reflog, it returns 0.
> */
> -int interpret_branch_name(const char *name, struct strbuf *buf)
> +int interpret_branch_name(const char *name, int namelen, struct strbuf *buf)
> {
> char *cp;
> struct branch *upstream;
> - int namelen = strlen(name);
> int len = interpret_nth_prior_checkout(name, buf);
> int tmp_len;
>
> + if (!namelen)
> + namelen = strlen(name);
> +
> if (!len) {
> return len; /* syntax Ok, not enough switches */
> } else if (len > 0) {
> @@ -1100,7 +1102,7 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
> int strbuf_branchname(struct strbuf *sb, const char *name)
> {
> int len = strlen(name);
> - int used = interpret_branch_name(name, sb);
> + int used = interpret_branch_name(name, len, sb);
>
> if (used == len)
> return 0;
next prev parent reply other threads:[~2013-09-03 18:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-02 6:34 [PATCH v5 0/2] Add @ shortcut, again Felipe Contreras
2013-09-02 6:34 ` [PATCH v5 1/2] sha1-name: pass len argument to interpret_branch_name() Felipe Contreras
2013-09-03 18:40 ` Junio C Hamano [this message]
2013-09-02 6:34 ` [PATCH v5 2/2] Add new @ shortcut for HEAD Felipe Contreras
2013-09-03 18:50 ` Junio C Hamano
2013-09-09 2:09 ` Felipe Contreras
2013-09-09 22:54 ` Junio C Hamano
2013-09-10 22:08 ` 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=xmqqioyhsq8q.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=felipe.contreras@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=stefano.lattarini@gmail$(echo .)com \
/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