From: Junio C Hamano <gitster@pobox.com>
To: Julien Carsique <julien.carsique@gmail.com>
Cc: git@vger.kernel.org, "SZEDER Gábor" <szeder@ira.uka.de>,
"Felipe Contreras" <felipe.contreras@gmail.com>,
"Ramkumar Ramachandra" <artagnon@gmail.com>,
"Simon Oosthoek" <s.oosthoek@xs4all.nl>,
"Eduardo R. D'Avila" <erdavila@gmail.com>,
"Richard Hansen" <rhansen@bbn.com>
Subject: Re: [PATCH] git-prompt.sh: shorter equal upstream branch name
Date: Tue, 30 Sep 2014 15:29:19 -0700 [thread overview]
Message-ID: <xmqqbnpwrbcw.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: 1412091370-11727-1-git-send-email-jcarsique@nuxeo.com
Julien Carsique <julien.carsique@gmail.com> writes:
> From: Julien Carsique <julien.carsique@gmail.com>
>
> When using the "name" option of GIT_PS1_SHOWUPSTREAM to show the upstream
> abbrev name, if the upstream name is the same as the local name, then some
> space could be saved in the prompt. This is especially needed on long branch
> names.
>
> Replace the upstream name with the sign '=' if equal to the local one.
> Example: [master * u= origin/=]$
> instead of: [master * u= origin/master]$
>
> Signed-off-by: Julien Carsique <julien.carsique@gmail.com>
> ---
> contrib/completion/git-prompt.sh | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> index c5473dc..a9aba20 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -209,6 +209,13 @@ __git_ps1_show_upstream ()
> if [[ -n "$count" && -n "$name" ]]; then
> __git_ps1_upstream_name=$(git rev-parse \
> --abbrev-ref "$upstream" 2>/dev/null)
> +
> + __head=${b##refs/heads/}
> + if [ "$__head" = "${__git_ps1_upstream_name##*/}" ]; then
When you are on your "xyz" branch that was forked off of
"refs/remote/origin/xyz/xyz", $__git_ps1_upstream_name would be
"origin/xyz/xyz" and $__head is "xyz" at this point. The latter
matches the former after stripping */ maximally from its front
(i.e. "xyz"). It is unclear if you really want to make these two
match, but as long as you correctly abbreviate you would not lose
information, I would imagine. I am guessing that you would want to
see "origin/xyz/=" in such a case, and if you started your "xyz" off
of "origin/abc/xyz", you would want "origin/abc/=".
> + __git_ps1_upstream_name=${__git_ps1_upstream_name/$__head/=}
Now, what does ${__git_ps1_upstream_name/$__head/=} give us?
This should not do regexp substitution in the first place, I would
think. You made sure $__head is the tail-matching substring of the
longer variable, so you chop that many bytes off of the latter.
Is this new feature something everybody should want unconditionally,
or are there valid reasons why some people may not want to see this
abbreviation happen (even if the implementation were not buggy)?
> + fi
> + unset __head
Unlike __git_ps1_upstream_name, this __head does not have to be
visible outside this function. Wouldn't it be better to declare it
as local (this is bash prompt and we can afford to step outside
POSIX) and there is no need to "unset" after use if you did so, no?
> if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
> p="$p \${__git_ps1_upstream_name}"
> else
prev parent reply other threads:[~2014-09-30 22:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-30 15:36 [PATCH] git-prompt.sh: shorter equal upstream branch name Julien Carsique
2014-09-30 20:44 ` Richard Hansen
2014-09-30 22:35 ` Junio C Hamano
2014-10-01 3:54 ` Richard Hansen
2014-10-01 17:49 ` Junio C Hamano
2014-10-07 15:57 ` Julien Carsique
2014-10-07 19:42 ` Richard Hansen
2014-10-07 20:10 ` Junio C Hamano
2014-09-30 22:29 ` Junio C Hamano [this message]
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=xmqqbnpwrbcw.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=artagnon@gmail.com \
--cc=erdavila@gmail.com \
--cc=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--cc=julien.carsique@gmail.com \
--cc=rhansen@bbn.com \
--cc=s.oosthoek@xs4all.nl \
--cc=szeder@ira.uka.de \
/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.