From: "SZEDER Gábor" <szeder@ira.uka.de>
To: git@vger.kernel.org
Cc: "SZEDER Gábor" <szeder@ira.uka.de>
Subject: [PATCH 06/19] bash prompt: return early from __git_ps1() when not in a git repository
Date: Wed, 9 May 2012 02:44:37 +0200 [thread overview]
Message-ID: <1336524290-30023-7-git-send-email-szeder@ira.uka.de> (raw)
In-Reply-To: <1336524290-30023-1-git-send-email-szeder@ira.uka.de>
... to gain one level of indentation for the bulk of the function.
(The patch looks quite unreadable, you'd better check it with 'git
diff -w'.)
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
contrib/completion/git-completion.bash | 154 +++++++++++++++++----------------
1 file changed, 78 insertions(+), 76 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index cd6a5f12..eaa3df9d 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -217,94 +217,96 @@ __git_ps1_show_upstream ()
__git_ps1 ()
{
local g="$(__gitdir)"
- if [ -n "$g" ]; then
- local r=""
- local b=""
- if [ -f "$g/rebase-merge/interactive" ]; then
- r="|REBASE-i"
- b="$(cat "$g/rebase-merge/head-name")"
- elif [ -d "$g/rebase-merge" ]; then
- r="|REBASE-m"
- b="$(cat "$g/rebase-merge/head-name")"
- else
- if [ -d "$g/rebase-apply" ]; then
- if [ -f "$g/rebase-apply/rebasing" ]; then
- r="|REBASE"
- elif [ -f "$g/rebase-apply/applying" ]; then
- r="|AM"
- else
- r="|AM/REBASE"
- fi
- elif [ -f "$g/MERGE_HEAD" ]; then
- r="|MERGING"
- elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
- r="|CHERRY-PICKING"
- elif [ -f "$g/BISECT_LOG" ]; then
- r="|BISECTING"
- fi
+ if [ -z "$g" ]; then
+ return
+ fi
- b="$(git symbolic-ref HEAD 2>/dev/null)" || {
-
- b="$(
- case "${GIT_PS1_DESCRIBE_STYLE-}" in
- (contains)
- git describe --contains HEAD ;;
- (branch)
- git describe --contains --all HEAD ;;
- (describe)
- git describe HEAD ;;
- (* | default)
- git describe --tags --exact-match HEAD ;;
- esac 2>/dev/null)" ||
-
- b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
- return
- b="($b)"
- }
+ local r=""
+ local b=""
+ if [ -f "$g/rebase-merge/interactive" ]; then
+ r="|REBASE-i"
+ b="$(cat "$g/rebase-merge/head-name")"
+ elif [ -d "$g/rebase-merge" ]; then
+ r="|REBASE-m"
+ b="$(cat "$g/rebase-merge/head-name")"
+ else
+ if [ -d "$g/rebase-apply" ]; then
+ if [ -f "$g/rebase-apply/rebasing" ]; then
+ r="|REBASE"
+ elif [ -f "$g/rebase-apply/applying" ]; then
+ r="|AM"
+ else
+ r="|AM/REBASE"
+ fi
+ elif [ -f "$g/MERGE_HEAD" ]; then
+ r="|MERGING"
+ elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
+ r="|CHERRY-PICKING"
+ elif [ -f "$g/BISECT_LOG" ]; then
+ r="|BISECTING"
fi
- local w=""
- local i=""
- local s=""
- local u=""
- local c=""
- local p=""
+ b="$(git symbolic-ref HEAD 2>/dev/null)" || {
+
+ b="$(
+ case "${GIT_PS1_DESCRIBE_STYLE-}" in
+ (contains)
+ git describe --contains HEAD ;;
+ (branch)
+ git describe --contains --all HEAD ;;
+ (describe)
+ git describe HEAD ;;
+ (* | default)
+ git describe --tags --exact-match HEAD ;;
+ esac 2>/dev/null)" ||
+
+ b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
+ return
+ b="($b)"
+ }
+ fi
- if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
- if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
- c="BARE:"
- else
- b="GIT_DIR!"
- fi
- elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
- if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
- if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
- git diff --no-ext-diff --quiet --exit-code || w="*"
- if git rev-parse --quiet --verify HEAD >/dev/null; then
- git diff-index --cached --quiet HEAD -- || i="+"
- else
- i="#"
- fi
- fi
- fi
- if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
- git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
- fi
+ local w=""
+ local i=""
+ local s=""
+ local u=""
+ local c=""
+ local p=""
- if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
- if [ -n "$(git ls-files --others --exclude-standard)" ]; then
- u="%"
+ if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
+ if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
+ c="BARE:"
+ else
+ b="GIT_DIR!"
+ fi
+ elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
+ if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
+ if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
+ git diff --no-ext-diff --quiet --exit-code || w="*"
+ if git rev-parse --quiet --verify HEAD >/dev/null; then
+ git diff-index --cached --quiet HEAD -- || i="+"
+ else
+ i="#"
fi
fi
+ fi
+ if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
+ git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
+ fi
- if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
- __git_ps1_show_upstream
+ if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
+ if [ -n "$(git ls-files --others --exclude-standard)" ]; then
+ u="%"
fi
fi
- local f="$w$i$s$u"
- printf -- "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
+ if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
+ __git_ps1_show_upstream
+ fi
fi
+
+ local f="$w$i$s$u"
+ printf -- "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
}
__gitcomp_1 ()
--
1.7.10.1.541.gb1be298
next prev parent reply other threads:[~2012-05-09 0:46 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-09 0:44 [PATCH 00/19] Bash prompt speedup SZEDER Gábor
2012-05-09 0:44 ` [PATCH 01/19] tests: move code to run tests under bash into a helper library SZEDER Gábor
2012-05-09 0:44 ` [PATCH 02/19] tests: add tests for the bash prompt functions in the completion script SZEDER Gábor
2012-05-09 8:07 ` Johannes Sixt
2012-05-09 18:08 ` Junio C Hamano
2012-05-10 6:09 ` Johannes Sixt
2012-05-09 18:36 ` Junio C Hamano
2012-05-09 20:33 ` SZEDER Gábor
2012-05-09 0:44 ` [PATCH 03/19] completion: use __gitdir() in _git_log() SZEDER Gábor
2012-05-09 18:41 ` Junio C Hamano
2012-05-09 19:01 ` SZEDER Gábor
2012-05-09 0:44 ` [PATCH 04/19] completion: respect $GIT_DIR SZEDER Gábor
2012-05-09 8:09 ` Johannes Sixt
2012-05-09 18:54 ` Junio C Hamano
2012-05-09 0:44 ` [PATCH 05/19] bash prompt: don't show the prompt when .git/HEAD is unreadable SZEDER Gábor
2012-05-09 19:32 ` Junio C Hamano
2012-05-09 19:45 ` SZEDER Gábor
2012-05-09 0:44 ` SZEDER Gábor [this message]
2012-05-09 0:44 ` [PATCH 07/19] completion: make __gitdir() store repository path in $__git_dir SZEDER Gábor
2012-05-09 19:36 ` Junio C Hamano
2012-05-09 0:44 ` [PATCH 08/19] completion: use $__git_dir instead of $(__gitdir) SZEDER Gábor
2012-05-09 19:43 ` Junio C Hamano
2012-05-09 20:22 ` SZEDER Gábor
2012-05-09 20:56 ` Junio C Hamano
2012-05-09 21:36 ` SZEDER Gábor
2012-05-09 0:44 ` [RFC PATCH 09/19] completion: platform-specific helper function to get physical path SZEDER Gábor
2012-05-09 7:37 ` Johannes Sixt
2012-05-09 0:44 ` [PATCH 10/19] completion: use bash builtins to search for repository SZEDER Gábor
2012-05-09 19:52 ` Junio C Hamano
2012-05-09 22:34 ` SZEDER Gábor
2012-05-09 22:59 ` Junio C Hamano
2012-05-09 0:44 ` [PATCH 11/19] bash prompt: use bash builtins to find out current branch SZEDER Gábor
2012-05-09 20:02 ` Junio C Hamano
2012-05-09 21:11 ` SZEDER Gábor
2012-05-09 21:25 ` Junio C Hamano
2012-05-09 21:45 ` SZEDER Gábor
2012-05-09 21:50 ` Junio C Hamano
2012-05-09 0:44 ` [PATCH 12/19] bash prompt: use bash builtins to check whether inside git dir SZEDER Gábor
2012-05-09 8:07 ` Johannes Sixt
2012-05-09 20:06 ` Junio C Hamano
2012-05-09 0:44 ` [PATCH 13/19] bash prompt: check whether inside the worktree only when necessary SZEDER Gábor
2012-05-09 0:44 ` [PATCH 14/19] bash prompt: use bash builtins to find out current branch during rebase SZEDER Gábor
2012-05-09 0:44 ` [PATCH 15/19] bash prompt: use bash builtins to get detached HEAD abbrev. object name SZEDER Gábor
2012-05-09 0:44 ` [PATCH 16/19] bash prompt: display stash and upstream state even inside the repository SZEDER Gábor
2012-05-09 0:44 ` [PATCH 17/19] bash prompt: use bash builtins to check stash state SZEDER Gábor
2012-05-09 0:44 ` [RFC PATCH 18/19] bash prompt: avoid command substitution when checking for untracked files SZEDER Gábor
2012-05-09 20:32 ` Junio C Hamano
2012-05-09 0:44 ` [PATCH 19/19] bash prompt: alternative git prompt without command substitution SZEDER Gábor
2012-05-09 19:38 ` Andrew Sayers
2012-05-09 22:08 ` SZEDER Gábor
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=1336524290-30023-7-git-send-email-szeder@ira.uka.de \
--to=szeder@ira.uka.de \
--cc=git@vger.kernel.org \
/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).