{"thread":{"id":"35395","subject":"[PATCH] bash prompt: add option to disable for a repository","startedAt":"2013-11-23T13:18:23Z","lastAt":"2013-11-26T08:40:42Z","messageCount":9,"participants":["Heikki Hokkanen","Johannes Sixt","SZEDER Gábor","Jonathan Nieder","Thomas Rast"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"230991","messageId":"1385212703-9611-1-git-send-email-hoxu@users.sf.net","threadId":"35395","inReplyTo":null,"subject":"[PATCH] bash prompt: add option to disable for a repository","fromName":"Heikki Hokkanen","fromEmail":"hoxu@users.sf.net","sentAt":"2013-11-23T13:18:23Z","receivedAt":"2013-11-23T13:18:23Z","isPatch":true,"sender":{"key":"hoxu@users.sf.net","avatar":null},"body":"If bash.prompt is set to false, disable the prompt. This is useful\nfor huge repositories like the home directory.\n\nSigned-off-by: Heikki Hokkanen <hoxu@users.sf.net>\n---\ngit-prompt.sh performance seems to be quite bad for big repositories, so\nwithout a way to disable it selectively for repositories, it becomes unusable\nfor people who have their homedir under git. This patch generalizes the problem\na bit by allowing the prompt to be disabled by setting bash.prompt to false in\nany repository.\n\n contrib/completion/git-prompt.sh | 8 ++++++++\n 1 file changed, 8 insertions(+)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 7b732d2..c982fde 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -84,6 +84,8 @@\n # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on\n # the colored output of \"git status -sb\" and are available only when\n # using __git_ps1 for PROMPT_COMMAND or precmd.\n+#\n+# To disable prompt for a repository, run \"git config bash.prompt false\"\n \n # check whether printf supports -v\n __git_printf_supports_v=\n@@ -304,6 +306,12 @@ __git_ps1 ()\n \t\treturn\n \tfi\n \n+\tlocal prompt_setting\n+\tprompt_setting=$(git config --bool bash.prompt)\n+\tif [ -n \"$prompt_setting\" ] && [ \"$prompt_setting\" == \"false\" ]; then\n+\t\treturn\n+\tfi\n+\n \tlocal short_sha\n \tif [ \"$rev_parse_exit_code\" = \"0\" ]; then\n \t\tshort_sha=\"${repo_info##*$'\\n'}\"\n-- \n1.8.4\n"},{"id":"230992","messageId":"5290BEE7.2070901@kdbg.org","threadId":"35395","inReplyTo":"1385212703-9611-1-git-send-email-hoxu@users.sf.net","subject":"Re: [PATCH] bash prompt: add option to disable for a repository","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2013-11-23T14:42:47Z","receivedAt":"2013-11-23T14:42:47Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 23.11.2013 14:18, schrieb Heikki Hokkanen:\n> If bash.prompt is set to false, disable the prompt. This is useful\n> for huge repositories like the home directory.\n> \n> Signed-off-by: Heikki Hokkanen <hoxu@users.sf.net>\n> ---\n> git-prompt.sh performance seems to be quite bad for big repositories, so\n> without a way to disable it selectively for repositories, it becomes unusable\n> for people who have their homedir under git. This patch generalizes the problem\n> a bit by allowing the prompt to be disabled by setting bash.prompt to false in\n> any repository.\n> \n>  contrib/completion/git-prompt.sh | 8 ++++++++\n>  1 file changed, 8 insertions(+)\n> \n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> index 7b732d2..c982fde 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -84,6 +84,8 @@\n>  # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on\n>  # the colored output of \"git status -sb\" and are available only when\n>  # using __git_ps1 for PROMPT_COMMAND or precmd.\n> +#\n> +# To disable prompt for a repository, run \"git config bash.prompt false\"\n>  \n>  # check whether printf supports -v\n>  __git_printf_supports_v=\n> @@ -304,6 +306,12 @@ __git_ps1 ()\n>  \t\treturn\n>  \tfi\n>  \n> +\tlocal prompt_setting\n> +\tprompt_setting=$(git config --bool bash.prompt)\n> +\tif [ -n \"$prompt_setting\" ] && [ \"$prompt_setting\" == \"false\" ]; then\n> +\t\treturn\n> +\tfi\n> +\n\nGah! This adds a fork+exec each time the prompt is shown. Not good,\nparticularly on Windows.\n\nSince your intent is to disable the prompt in the home directory,\nwouldn't that mean that most of the time you *don't* want the prompt?\nWouldn't you be better served with a method that *turns on* the prompt?\nFor example, a shell function that sets PS1 and another one that unsets\nit? Or a wrapper that inspects a shell variable and calls __git_ps1 only\nwhen you want a prompt.\n\n>  \tlocal short_sha\n>  \tif [ \"$rev_parse_exit_code\" = \"0\" ]; then\n>  \t\tshort_sha=\"${repo_info##*$'\\n'}\"\n> \n\n-- Hannes\n"},{"id":"230996","messageId":"CAOpY_XvN9GJw592MpbcZZ2hzUvSvTHNLebwMmQBK+N-Ez4xM_Q@mail.gmail.com","threadId":"35395","inReplyTo":"5290BEE7.2070901@kdbg.org","subject":"Re: [PATCH] bash prompt: add option to disable for a repository","fromName":"Heikki Hokkanen","fromEmail":"hoxu@users.sf.net","sentAt":"2013-11-23T16:31:52Z","receivedAt":"2013-11-23T16:31:52Z","isPatch":true,"sender":{"key":"hoxu@users.sf.net","avatar":null},"body":"On Sat, Nov 23, 2013 at 4:42 PM, Johannes Sixt <j6t@kdbg.org> wrote:\n> Gah! This adds a fork+exec each time the prompt is shown. Not good,\n> particularly on Windows.\n>\n> Since your intent is to disable the prompt in the home directory,\n> wouldn't that mean that most of the time you *don't* want the prompt?\n> Wouldn't you be better served with a method that *turns on* the prompt?\n> For example, a shell function that sets PS1 and another one that unsets\n> it? Or a wrapper that inspects a shell variable and calls __git_ps1 only\n> when you want a prompt.\n\nActually, I do want the prompt for all other git repositories. The\nproblem with $HOME is that it's the default directory after logging in\nor opening a terminal, so if you have git prompt sourced and your\n$HOME under git, you get an unbearable delay every time you open a\nterminal, or type a command, anywhere, except for a separate git\nrepository.\n\nAnd I do believe I'm not the only one putting $HOME under git, so I\nthink some kind of generic solution to this problem would be nice.\n\nIf running git config on each prompt seems too expensive, do you have\nany better ideas?\n\nRegards,\n\n-- \nHeikki Hokkanen\n"},{"id":"230999","messageId":"20131123163559.GB13824@goldbirke","threadId":"35395","inReplyTo":"1385212703-9611-1-git-send-email-hoxu@users.sf.net","subject":"Re: [PATCH] bash prompt: add option to disable for a repository","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2013-11-23T16:35:59Z","receivedAt":"2013-11-23T16:35:59Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\nOn Sat, Nov 23, 2013 at 03:18:23PM +0200, Heikki Hokkanen wrote:\n> If bash.prompt is set to false, disable the prompt. This is useful\n> for huge repositories like the home directory.\n> \n> Signed-off-by: Heikki Hokkanen <hoxu@users.sf.net>\n> ---\n> git-prompt.sh performance seems to be quite bad for big repositories,\n\nHm, strange.  I wonder what can cause performance problems in big\nrepositories.\n\nSure, there are status indicators that can be expensive, in particular\nthe indicators for dirty index/worktree, untracked files, and\ndivergence from upstream.  However, these must be enabled globally by\nenvironment variables and even then can already be disabled on a\nper-repo basis by configuration variables.  And the rest of the prompt\ncode should perform pretty much independently from the repository\nsize.\n\n> so\n> without a way to disable it selectively for repositories, it becomes unusable\n> for people who have their homedir under git. This patch generalizes the problem\n> a bit by allowing the prompt to be disabled by setting bash.prompt to false in\n> any repository.\n> \n>  contrib/completion/git-prompt.sh | 8 ++++++++\n>  1 file changed, 8 insertions(+)\n\nNo tests.\n\n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> index 7b732d2..c982fde 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -84,6 +84,8 @@\n>  # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on\n>  # the colored output of \"git status -sb\" and are available only when\n>  # using __git_ps1 for PROMPT_COMMAND or precmd.\n> +#\n> +# To disable prompt for a repository, run \"git config bash.prompt false\"\n>  \n>  # check whether printf supports -v\n>  __git_printf_supports_v=\n> @@ -304,6 +306,12 @@ __git_ps1 ()\n>  \t\treturn\n>  \tfi\n>  \n> +\tlocal prompt_setting\n> +\tprompt_setting=$(git config --bool bash.prompt)\n\nI spent quite some time eliminating fork()s and exec()s from the\nprompt, so a fork() for the command substitution's subshell and a\nfork()+exec() for running a git command in the main code path saddens\nme deeply ;)\n\n> +\tif [ -n \"$prompt_setting\" ] && [ \"$prompt_setting\" == \"false\" ]; then\n\nIf $prompt_setting must be false, then checking its non-emptyness is\nsuperfluous.\n\n> +\t\treturn\n\nYou can't just return from __git_ps1(), you must update PS1 in prompt\ncommand mode.  See the few lines just above this hunk.\n\n> +\tfi\n> +\n>  \tlocal short_sha\n>  \tif [ \"$rev_parse_exit_code\" = \"0\" ]; then\n>  \t\tshort_sha=\"${repo_info##*$'\\n'}\"\n> -- \n> 1.8.4\n> \n"},{"id":"231075","messageId":"CAOpY_XvKkdU+2uxj3K4ZgTq+6qniLYH=bwbQZ6jyrDM7+dZAxg@mail.gmail.com","threadId":"35395","inReplyTo":"20131123163559.GB13824@goldbirke","subject":"Re: [PATCH] bash prompt: add option to disable for a repository","fromName":"Heikki Hokkanen","fromEmail":"hoxu@users.sf.net","sentAt":"2013-11-25T16:38:56Z","receivedAt":"2013-11-25T16:38:56Z","isPatch":true,"sender":{"key":"hoxu@users.sf.net","avatar":null},"body":"Hello,\n\nOn Sat, Nov 23, 2013 at 6:35 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> Hm, strange.  I wonder what can cause performance problems in big\n> repositories.\n>\n> Sure, there are status indicators that can be expensive, in particular\n> the indicators for dirty index/worktree, untracked files, and\n> divergence from upstream.  However, these must be enabled globally by\n> environment variables and even then can already be disabled on a\n> per-repo basis by configuration variables.  And the rest of the prompt\n> code should perform pretty much independently from the repository\n> size.\n\nYou are right. The performance issue seems to be indeed fixed by setting\nbash.showDirtyState and bash.showUntrackedFiles to false. And I feel a\nbit stupid for not realizing those were the only reason :)\n\nNow the only remaining issue for me is that I wouldn't like to see git\nprompt under the home directory repository, because then it's turned\non pretty much everywhere.\n\n> I spent quite some time eliminating fork()s and exec()s from the\n> prompt, so a fork() for the command substitution's subshell and a\n> fork()+exec() for running a git command in the main code path saddens\n> me deeply ;)\n\nSeeing how the dirty state/untracked files/upstream configs are\nimplemented, I'm thinking, what if \"bash.prompt\" setting was checked\nsimilarly only when something like GIT_PS1_PERREPOBASIS was set?\n\nIt would keep the default execution path free from added forks, but\nstill allow people to disable git prompt on a per-repository basis.\n\nRegards,\n\n-- \nHeikki Hokkanen\n"},{"id":"231118","messageId":"20131125234344.GA4212@google.com","threadId":"35395","inReplyTo":"CAOpY_XvN9GJw592MpbcZZ2hzUvSvTHNLebwMmQBK+N-Ez4xM_Q@mail.gmail.com","subject":"Re: [PATCH] bash prompt: add option to disable for a repository","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2013-11-25T23:43:44Z","receivedAt":"2013-11-25T23:43:44Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Heikki Hokkanen wrote:\n\n> If running git config on each prompt seems too expensive, do you have\n> any better ideas?\n\nPerhaps a GIT_PS1_NOT_FOR_THESE_REPOS=repo1:repo2:repo3 setting would\nwork.\n\n__git_ps1 would do the one 'git rev-parse --git-dir --...' to find the\nrepo corresponding to the cwd and then could match against the\nconfigured list to decide whether to return early.\n\nHope that helps,\nJonathan\n"},{"id":"231119","messageId":"20131126002625.GA9061@goldbirke","threadId":"35395","inReplyTo":"20131125234344.GA4212@google.com","subject":"Re: [PATCH] bash prompt: add option to disable for a repository","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2013-11-26T00:26:25Z","receivedAt":"2013-11-26T00:26:25Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Mon, Nov 25, 2013 at 03:43:44PM -0800, Jonathan Nieder wrote:\n> Heikki Hokkanen wrote:\n> \n> > If running git config on each prompt seems too expensive, do you have\n> > any better ideas?\n> \n> Perhaps a GIT_PS1_NOT_FOR_THESE_REPOS=repo1:repo2:repo3 setting would\n> work.\n> \n> __git_ps1 would do the one 'git rev-parse --git-dir --...' to find the\n> repo corresponding to the cwd and then could match against the\n> configured list to decide whether to return early.\n\nThat would be a better interface, but the implementation must cope\nwith colons in paths on Unixes, case insensitive file systems, and\ndifferent path representations on Windows (C:\\path\\to\\repo vs.\n/c/PaTh/To/RePo).  I'm not sure we want to go there.\n\nGábor\n"},{"id":"231126","messageId":"5294474A.7070101@viscovery.net","threadId":"35395","inReplyTo":"20131125234344.GA4212@google.com","subject":"Re: [PATCH] bash prompt: add option to disable for a repository","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2013-11-26T07:01:30Z","receivedAt":"2013-11-26T07:01:30Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 11/26/2013 0:43, schrieb Jonathan Nieder:\n> Heikki Hokkanen wrote:\n> \n>> If running git config on each prompt seems too expensive, do you have\n>> any better ideas?\n> \n> Perhaps a GIT_PS1_NOT_FOR_THESE_REPOS=repo1:repo2:repo3 setting would\n> work.\n\nYeah, but... I find the wish to show the bash prompt in some, but not all,\nrepositories so uncommon that I doubt that it must be a feature of\n__git_ps1. There can be a wrapper function that does the repository\ndiscovery and calls into __git_ps1 as needed. No current __git_ps1 users\nneed to be burdened.\n\n-- Hannes\n"},{"id":"231127","messageId":"87li0b1rp1.fsf@thomasrast.ch","threadId":"35395","inReplyTo":"CAOpY_XvN9GJw592MpbcZZ2hzUvSvTHNLebwMmQBK+N-Ez4xM_Q@mail.gmail.com","subject":"Re: [PATCH] bash prompt: add option to disable for a repository","fromName":"Thomas Rast","fromEmail":"tr@thomasrast.ch","sentAt":"2013-11-26T08:40:42Z","receivedAt":"2013-11-26T08:40:42Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Heikki Hokkanen <hoxu@users.sf.net> writes:\n\n> On Sat, Nov 23, 2013 at 4:42 PM, Johannes Sixt <j6t@kdbg.org> wrote:\n>> Gah! This adds a fork+exec each time the prompt is shown. Not good,\n>> particularly on Windows.\n>>\n>> Since your intent is to disable the prompt in the home directory,\n>> wouldn't that mean that most of the time you *don't* want the prompt?\n>> Wouldn't you be better served with a method that *turns on* the prompt?\n>> For example, a shell function that sets PS1 and another one that unsets\n>> it? Or a wrapper that inspects a shell variable and calls __git_ps1 only\n>> when you want a prompt.\n>\n> Actually, I do want the prompt for all other git repositories. The\n> problem with $HOME is that it's the default directory after logging in\n> or opening a terminal, so if you have git prompt sourced and your\n> $HOME under git, you get an unbearable delay every time you open a\n> terminal, or type a command, anywhere, except for a separate git\n> repository.\n\nUmm... is __git_ps1 by itself so slow that you find it unbearable, or is\nit the worktree status discovery?  Because the latter can already be\ncontrolled per repository via bash.showUntrackedFiles and\nbash.showUpstream.\n\n-- \nThomas Rast\ntr@thomasrast.ch\n"}]}