Skip to content

Conversation

@ian-craig
Copy link
Contributor

@ian-craig ian-craig commented May 21, 2021

Fixes #2548

Adds support for skipping status check (git status and git diff) when generating the prompt, while still showing the branch name.

Adds a simple mode for powershell and bash which get the branch name by just reading .git/HEAD which should not slow down with large repos.

I decided to change the color to gray when status=false to indicate that the status is unknown. This would avoid misleading people into thinking they are "clean" if they apply the config only to specific repos.

Copy link
Contributor

@chrisant996 chrisant996 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it looks cool. If I'm reading it right, then the way that cmderGitStatusOptIn now can be a bool or a string seems problematic (see specific comments for details).

A couple alternatives could be:

  • Consider updating the usage of cmderGitStatusOptIn in the clink-completions repo as well.
  • Consider making a new config setting instead of modifying an existing one.

Or @daxgames may have something else in mind.

vendor/clink.lua Outdated
-- Has branch => therefore it is a git folder, now figure out status
local gitStatus = get_git_status()
local gitConflict = get_git_conflict()
if cmderGitStatusOptIn ~= 'branchonly' then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The vladimir-kotikov/clink-completions repo has a dependency on cmderGitStatusOptIn being a true/false value. The contents of that repo are copied into the %CMDER_ROOT%\vendor\clink-completions directory.

This new setting won't behave as intended in certain repos, and when it's used it will bring back the slow behavior #2484 that was fixed by 6027ac3.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, wasn't aware of this.

Would the following seem OK instead?

local statusSetting = get_git_status_setting()
cmderGitStatusOptIn = statusSetting == true
...
if statusSetting ~= 'branchonly' then

I'll be unavailable for the next few days but can come back and iterate on this next week.

Copy link
Contributor Author

@ian-craig ian-craig May 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a more important question is... do we want clink-completions's filter to still run? The goal of this PR was to avoid expensive operations, and the clink-completions filter appears to only be doing fast operations that aren't affected by repo size.

In which case I could do cmderGitStatusOptIn = statusSetting ~= false so that 'branchonly' keeps the clink-completions filter on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not aware of anyone ever complaining we showed the Git branch in the prompt. The only complaint has ALWAYS been the prompt can be slow in a large Git repo.

My thought was that *status = false changes from 'no status and no branch' to 'no status with branch' so we scrap the cmdstatus = branchonly setting.

Currently Cmder's Git Opt Out functionality has feature parity across Cmd, Powershell, and Bash shells this PR only affects git status opt out in Cmd shells so we should also:

  • Modify %cmder_root%\vendor\git-prompt.sh to just display the branch for Bash shells if status=false or bashstatus=false
  • Modify %cmder_root%\vendor\psmodules\Cmder.ps1 to just display the branch for Powershell shells ifstatus=falseorpsstatus=false`
    • We do not have much control of how Powershell prompt is displayed because we use a function from Posh-Git so this will be more difficult.

This would maintain current compatibility with bash and powershell shells for these settings.

Lastly disabling git status checks in Cmder whether the branch is displayed or not the clink-completions git-prompt filter should not run either.

Copy link
Contributor

@chrisant996 chrisant996 May 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the clink-completions filter appears to only be doing fast operations that aren't affected by repo size.

It only seems that way because most of us don't use repos large enough to reproduce the problem. I recommend reading #2484, and especially this comment and this comment with the detailed explanation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all sounds good to me, so I've:

  1. Removed the "branchonly" concept
  2. Made cmder.*status=false only prevent the status operations, not printing branch name for cmd
  3. Added new simple branch name logic for bash and powershell to mimic the behavior of cmd in the status=false case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And I'm no longer touching anything related to clink-completions so that is still off when status=false)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .lua part looks good to me now. I have no familiarity with the affected .sh or .ps1 scripts or how Cmder integrates with those shells, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will test it out later. Thanks

@ian-craig ian-craig changed the title Add branchonly option to cmdstatus Show branch name when cmder.status=false without doing expensive status ops May 26, 2021
@ian-craig ian-craig changed the title Show branch name when cmder.status=false without doing expensive status ops Show branch name when cmder.status=false without expensive status ops May 26, 2021
@daxgames
Copy link
Member

daxgames commented May 30, 2021

Does not seem to work for me:

cmd::cmder
image

EDIT: Powershell and bash(After copying the edited git-prompt.sh from your change to vendor\git-for-windows\etc\profile.d\git-prompt.sh) seems to work but cmd::cmder does not display the branch.

@daxgames
Copy link
Member

@ian-craig I opened a PR to your branch that fixes the cmd::Cmder side of things:

ian-craig#1

image

@ian-craig
Copy link
Contributor Author

Thanks @daxgames, I've merged your changes and am happy with the switch to white.

Unrelated side note... Is there supposed to be no space before the branch name in cmd? It looks like there used to be a space in older versions for cmd, and still is for powershell and bash. I thought I'd messed something up in my testing but it looks like your screenshots show this too.

@daxgames daxgames merged commit 62a6311 into cmderdev:master Jul 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git status slows down prompt in large repos

3 participants