Skip to content

Conversation

@gaelicWizard
Copy link
Contributor

@gaelicWizard gaelicWizard commented Aug 8, 2021

Description

If we are specifically in the situation #1612 (where Xcode's xcrun is masquerading as svn), then check for a working svn command. If we're not in that situation, then don't waste time on it. This check was added in #1613.

Motivation and Context

This is one of the causes of my shell taking several seconds to start.

How Has This Been Tested?

Tested locally.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the code style of this project.
  • If my change requires a change to the documentation, I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • If I have added a new file, I also added it to clean_files.txt and formatted it using lint_clean_files.sh.
  • I have added tests to cover my changes, and all the new and existing tests pass.

@gaelicWizard
Copy link
Contributor Author

I think that test 'themes base: SVN: ignore SVN repo when using broken SVN command' should only be running on a Mac worker, and alsö it may be a little weird to make the test fail predictably without a broken svn in the standard location. We're testing for a known-broken svn, not for "literally any svn that isn't behaving for unknown reasons". Thoughts?

@NoahGorny
Copy link
Member

I think that test 'themes base: SVN: ignore SVN repo when using broken SVN command' should only be running on a Mac worker, and alsö it may be a little weird to make the test fail predictably without a broken svn in the standard location. We're testing for a known-broken svn, not for "literally any svn that isn't behaving for unknown reasons". Thoughts?

I agree that the test can be changed. I do not think it should only run on macs though- we should mock the conditions for the check and test it, imitating that it is indeed a problematic Mac

@gaelicWizard
Copy link
Contributor Author

As an alternative to my patch here, we could check for xcrun and then invoke xcrun svn to test for broken... I'll see if I can do a version that tries that. It would allow us to mock xcrun for testing without requiring it be at /usr/bin/xcrun

@gaelicWizard
Copy link
Contributor Author

xcrun --find svn

Ok, so how about: (1) if svn found in path, (2) and if xcrun found in path, (3) check if the two are siblings (covers (a) mocking, or (b) non-standard $DEVELOPER_DIR, or (c) /usr/bin/{xcrun,svn}, (4) and if all are true then invoke svn to see if it fails. Should still be much faster than just running svn every shell startup!

@gaelicWizard gaelicWizard marked this pull request as draft August 13, 2021 06:26
@NoahGorny
Copy link
Member

Sounds like a good idea!

@gaelicWizard
Copy link
Contributor Author

I'm sorry, I haven't had much time to learn BATS so this is just sitting waiting for me to circle back to it.

@NoahGorny
Copy link
Member

I'm sorry, I haven't had much time to learn BATS so this is just sitting waiting for me to circle back to it.

There is not much to learn actually, you can look at our docs for reference

@gaelicWizard gaelicWizard force-pushed the SVN branch 3 times, most recently from 3ca6c24 to 7df115d Compare September 11, 2021 06:21
@gaelicWizard gaelicWizard marked this pull request as ready for review September 11, 2021 06:22
@gaelicWizard gaelicWizard force-pushed the SVN branch 6 times, most recently from 734080b to 4f25249 Compare September 11, 2021 06:54
@gaelicWizard
Copy link
Contributor Author

Done and passing.

If we are specifically in the situation Bash-it#1612, then check for a working `svn` command. If we're not in that situation, then don't waste time on it.
This reduces the need to invoke subprocesses
Copy link
Member

@NoahGorny NoahGorny left a comment

Choose a reason for hiding this comment

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

I left one comment, otherwise looks great!

@gaelicWizard
Copy link
Contributor Author

And now I think I'm going to change the test local setup function too. If we're testing that the file loads properly, then loading the file should be part of the test not the setup.

See? This is why I didn't touch BATS at first. Once I start, my brain drags me down the rabbit hole! I may need to start a whole branch just for BATS cleanup! 🙃

(I have a love/hate relationship with my brain. I'll spare you my further whining about my brain.)

@gaelicWizard
Copy link
Contributor Author

Serious question: although it doesn't matter for this particular PR, what are your thoughts on naming the library init function?

Several plugins use init functions (and call them immediately, like I do here) and I very much do like the paradigm of keeping the definition separate from the invocation. I alsö want to introduce a library init hook and plugin init hook (later, in a future PR) such that loading a file doesn't do anything besides declare/define variables and functions and then the we separately run all the init hooks afterwards. This would solve most(?) of the need for explicit ordering of file load (default priorities, &c.), and would make bash-it reload much easier to reason about and test.

I'd like a common prefix for init functions so that "${!_bash-it-hook-enable-@}" expands to "${_bash-it-hook-enable-docker}" "${_bash-it-hook-enable-rvm}" [...] for easier invocation. (But of course, that's for variable names not function names...)

Should I name the one I introduce here _bash-it-hook-lib-init-scm maybe? (Can always rename later if/when implementing the hooks; just trying to think ahead.)

@gaelicWizard gaelicWizard force-pushed the SVN branch 4 times, most recently from f4ed705 to 40ba1f8 Compare September 11, 2021 17:11
Wrap init code in a function and call the function immediately. Several plugins do this, and it allows us to more easily implement a hooks-based system in the future.

Alsö, avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot.
Copy link
Member

@NoahGorny NoahGorny left a comment

Choose a reason for hiding this comment

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

I have another small comment 😄

About the init function- i am pretty sure it will take a long refactor to get bash-it-reload to just call the init of each file and I am not sure it will be worth the effort. I am okay with adding init functions like you did, not sure that changing the reload will happen.

@gaelicWizard
Copy link
Contributor Author

About the init function- i am pretty sure it will take a long refactor to get bash-it-reload to just call the init of each file and I am not sure it will be worth the effort. I am okay with adding init functions like you did, not sure that changing the reload will happen.

That's a whole other discussion that is wildly out of scope here...I only mentioned it because it's on my mind. Functions have scope! (I've shot myself in the foot with this one, can you tell? 😉)

Copy link
Member

@NoahGorny NoahGorny left a comment

Choose a reason for hiding this comment

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

Well done @gaelicWizard!
Another great work by you (or your brain worms)

@gaelicWizard
Copy link
Contributor Author

Anything else needed for this PR?

@NoahGorny
Copy link
Member

nope- well done!

@NoahGorny NoahGorny merged commit b48f3fd into Bash-it:master Sep 18, 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.

2 participants