git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] fetch: prefer suffix substitution in compact fetch.output
Date: Fri, 25 Jan 2019 13:36:17 -0800	[thread overview]
Message-ID: <xmqqef90fmi6.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20190125095122.28719-1-pclouds@gmail.com> ("Nguyễn Thái Ngọc Duy"'s message of "Fri, 25 Jan 2019 16:51:22 +0700")

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> I have a remote named "jch" and it has a branch with the same name. And
> fetch.output is set to "compact". Fetching this remote looks like this
>
>  From https://github.com/gitster/git
>   + eb7fd39f6b...835363af2f jch                -> */jch  (forced update)
>     6f11fd5edb..59b12ae96a  nd/config-move-to  -> jch/*
>   * [new branch]            nd/diff-parseopt   -> jch/*
>   * [new branch]            nd/the-index-final -> jch/*
>
> Notice that the local side of branch jch starts with "*" instead of
> ending with it like the rest. It's not exactly wrong. It just looks
> weird.
>
> This patch changes the find-and-replace code a bit to try finding prefix
> first before falling back to strstr() which finds a substring from left
> to right. Now we have something less OCD
>
>  From https://github.com/gitster/git
>   + eb7fd39f6b...835363af2f jch                -> jch/*  (forced update)
>     6f11fd5edb..59b12ae96a  nd/config-move-to  -> jch/*
>   * [new branch]            nd/diff-parseopt   -> jch/*
>   * [new branch]            nd/the-index-final -> jch/*

Sounds good.  I do not think strstr() would ever be correct in this
application in the first place.  In what situation would it produce
a reasonable result, I wonder?

> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  builtin/fetch.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index e0140327aa..e0173f8a33 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -629,9 +629,14 @@ static int find_and_replace(struct strbuf *haystack,
>  			    const char *needle,
>  			    const char *placeholder)
>  {
> -	const char *p = strstr(haystack->buf, needle);
> +	const char *p = NULL;
>  	int plen, nlen;
>  
> +	nlen = strlen(needle);
> +	if (ends_with(haystack->buf, needle))
> +		p = haystack->buf + haystack->len - nlen;
> +	else
> +		p = strstr(haystack->buf, needle);
>  	if (!p)
>  		return 0;
>  
> @@ -639,7 +644,6 @@ static int find_and_replace(struct strbuf *haystack,
>  		return 0;
>  
>  	plen = strlen(p);
> -	nlen = strlen(needle);
>  	if (plen > nlen && p[nlen] != '/')
>  		return 0;

  reply	other threads:[~2019-01-25 21:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-25  9:51 [PATCH] fetch: prefer suffix substitution in compact fetch.output Nguyễn Thái Ngọc Duy
2019-01-25 21:36 ` Junio C Hamano [this message]
2019-01-26 23:57   ` Duy Nguyen
2019-02-22  9:52 ` Ideas for even more compact fetch.output=compact output Ævar Arnfjörð Bjarmason
2019-02-22 10:05   ` Duy Nguyen
2019-02-22 18:19     ` Junio C Hamano
2019-02-22 20:00       ` 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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqef90fmi6.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).