Skip to content

Allow ls to display git status of files - #7620

Closed
KodiCraft wants to merge 10 commits into
nushell:mainfrom
KodiCraft:main
Closed

KodiCraft wants to merge 10 commits into
nushell:mainfrom
KodiCraft:main

Conversation

@KodiCraft

Copy link
Copy Markdown

Description

(Thank you for improving Nushell. Please, check our contributing guide and talk to the core team before making major changes.)

(Description of your pull request goes here. Provide examples and/or screenshots if your changes affect the user experience.)
This PR adds the -g flag to ls which allows it to display the git status of a file. It also adds a matching example in the command's examples.

Preview of ls with the new -g flag
Preview of the ls --help command

It's worth noting that the current implementation lacks any caching and is very slow. Just like with -d, it must not be enabled by default.

User-Facing Changes

(List of all changes that impact the user experience here. This helps us keep track of breaking changes.)
ls now has the -g flag which adds a git_status column listing the git status of various files, if any. Related entries in the command's Examples are also added.

@rgwood

rgwood commented Dec 27, 2022

Copy link
Copy Markdown
Contributor

Hi, thanks for the PR!

We're generally reluctant to add large new dependencies to Nushell; our build times and binary sizes are already slower and larger than we would like them to be.

It looks like git2 is quite large (~5.5MB, ~138K SLoC); it would help to know how much
it adds to cargo build compile times and cargo build --release binary sizes.

@KodiCraft

Copy link
Copy Markdown
Author

I ran comparisons on my own computer, with a sample size of 10 clean builds (cargo clean; cargo build or cargo clean; cargo build --release) per test, with my full CPU and with only one core.
The release binary size is the same in MB up to the first decimal place (32.6MB) and the average build time is very close (35 vs 32 seconds on full CPU, 3:21 vs 3:16 on one core).

These times are reported by cargo build itself.

These seem like rather small costs, though this wasn't a scientific or large scale test. If needed, I could run some larger scale tests.

@rgwood

rgwood commented Dec 28, 2022

Copy link
Copy Markdown
Contributor

Thanks, I appreciate the numbers! Going from 32s to 35s would be adding about 9% to our build time and I personally think that's a lot for one small feature.

I'm not sure what OS you're building on, but on Linux this PR adds ~500kb to the nu executable (as measured by running cargo build --release; ls target/release | format filesize KB size on your PR and on main). 23,807 KB -> 24,304 KB. Not the end of the world, but not nothing either.

Sorry for being a bit of a downer, this is a very cool feature. But if we're going to compile and bundle an entire Git implementation with Nushell, we need to make sure that the benefits outweigh the costs.

Let's see how other contributors feel.

@fdncred

fdncred commented Dec 28, 2022

Copy link
Copy Markdown
Contributor

@KodiCraft For some perspective, we're very familiar with the git dependencies and what it does. I originally wrote the gstat git status plugin as an internal regular command. Back when I did that, has to probably be two years ago now, it was decided that the dependencies were too big to be added to the core, which is why it's a plugin right now. Then some time later, I accepted a PR that included git via shadow_rs (which we see in the output in the version command). We ran with that for a while and then we chatted about it a bit, and IIRC, @rgwood removed the git dependency from how we implemented shadow_rs so that now we don't have a dependency on git any longer.

Having said all that, I'm in the same camp as @rgwood and don't really feel compelled to accept this PR but I wanted to share this history so you understand why we're so reluctant.

I wonder if we'd accept this PR if it were written by shelling out and doing a git status --porcelain and parsing it? I'm not sure really. Seems like that would be slow but I'm not sure where @rgwood sits on that or where the other core-team members feel.

Sorry for rattling on so long. I just wanted you to know that we appreciate your work and effort but don't want to just dismiss it.

@kubouch

kubouch commented Dec 28, 2022

Copy link
Copy Markdown
Contributor

I agree, I don't think we should land it due to the git2 dependency which prove to be quite slow in the gstat plugin. Also, our built-in ls command should provide basic functionality for navigating the file system without having a million flags. We cannot support everything inside ls, we need to draw a line somewhere and in my opinion, git status lies beyond that line. Extended functionality can be always handled via custom commands / plugins.

This is exactly why we have the contributing guide linked in the PR template and ask people to talk to us before implementing new features. You would get a similar response before spending time implementing your PR. I don't mean to discourage you from contributing. We're grateful that you dedicated your time to work on Nushell, we just don't feel confident landing this PR.

@theAkito

Copy link
Copy Markdown

In addition to all the valid & correct performance related objections, I would like to add, that I deem something like git simply out of scope for the core project. This should be a plugin a user has to install on his own.

Naturally, a lot of users are probably involved with git related workflows, however it does not belong straight up in the core of a shell.

Everything in the core should roughly be directly related to what a shell does at its core. Dealing with files & directories, calculating sizes, etc. But git on the other hand, is a completely different story.

@KodiCraft

Copy link
Copy Markdown
Author

That's perfectly valid and understandable, thank you for the feedback.

Closing this PR

@KodiCraft KodiCraft closed this Dec 28, 2022
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.

5 participants