Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement cache based listing #29

Merged
merged 29 commits into from
Oct 24, 2023
Merged

implement cache based listing #29

merged 29 commits into from
Oct 24, 2023

Conversation

amtoine
Copy link
Owner

@amtoine amtoine commented Oct 20, 2023

description

#26 had three major flaws, list-repos-in-store

  • did depend on GNU find on Linux and MacOS
  • did use glob on Windows, which is slow
  • did not catch any bare repo and did list nested directories, such as Git modules

this PR tries to solve these at once

  • will use glob only for all the OSes and removed the dependency on find
  • will use a cache to store the state of the repos currently managed by gm
  • the globbing pattern and post-treatment will both catch the bare repos and remove nested duplicates

new features

  • gm cache is a new command that gives the cache currently used
    • the cache will follow the XDG Base Directory specification and will default to ~/.local/share/nu-git-manager/cache.nuon
    • it has a --update switch to force a full update of the cache: this might take some time
  • gm list will simply open the cache and dump it's content as a list: this will be super fast
  • gm clone and gm remove will update the cache in a super fast way, without list-repos-in-store
    • gm clone will just append the new path to the cache
    • gm remove will just remove the removed path from the cache
    • otherwise, if the user changes the store manually, they will have to run gm cache --update manually to fix gm list's output
  • gm list will be used in other commands instead of list-repos-in-store to use the cache

Note
paths will be more sanitized by removing the drive, e.g. D:, from the beginning of Windows paths

Note
list-repos-in-store will throw a DEBUG line when the store does not exist.
the CI will set NU_LOG_LEVEL to DEBUG to see that in the CI.

Note
this PR makes sure all paths are sanitized and removes mention to path_sep from the gm module

details on the changes

with this PR, list-repos-in-store will

  • use glob
  • search for any occurence of a HEAD file
  • remove invalid matches, e.g. multiple HEADs that are stored in multiple places in .git/ directories
  • remove nested duplicates from the list, e.g. Git submodules

tests

this PR adds two tests

  • get-repo-cache to make sure the cache is properly setup
  • list-all-repos-in-store to make sure list-repos-in-store can list all repos, bare ones included, without nested duplicates, in a fake store

a real-life example would be the `nushell` and `nushell.github.io`
repos: we want them both.
a real-life example would be the `nushell` and `nushell.github.io`
repos: before this change, `nushell.github.io` would be discarded by
`list-repos-in-store` because `nushell.github.io` starts with `nushell`.
keeping the trailing `/` in all paths fixes the error because
`nushell.github.io/` does not start with `nushell/` anymore 👌
because the paths are sanitized, they will all use `/`
@amtoine amtoine requested a review from melMass October 20, 2023 13:37
@amtoine
Copy link
Owner Author

amtoine commented Oct 20, 2023

Note
might need to add back some more --not to the glob call

amtoine added a commit to amtoine/dotfiles that referenced this pull request Oct 20, 2023
related to
- amtoine/nu-git-manager#29

will require to install `nu-git-manager` with Nupm from amtoine/nu-git-manager#29.
@amtoine
Copy link
Owner Author

amtoine commented Oct 20, 2023

i've added NOTEs in the PR description about fixing this PR's CI for Windows, hope that's clear enough 👀 🤞

@melMass
Copy link
Collaborator

melMass commented Oct 21, 2023

Nice!!

  • gm cache is a new command that gives the cache currently used

I don't see this exposed?

edit: the whole module silently failed to load actually... I see it in code but it wasn't working in the cli

  • gm clone and gm remove will run gm list --update to update the cache

Wouldn't that be super slow? (I still have to test it out)


Not sure what it is, maybe the imports, I'll check that

image

@amtoine
Copy link
Owner Author

amtoine commented Oct 21, 2023

I don't see this exposed?

edit: the whole module silently failed to load actually... I see it in code but it wasn't working in the cli

use ./nu-git-manager/ "gm cache"

works on my side 👍

Wouldn't that be super slow? (I still have to test it out)

it will very likely be much slower than just updating the cloned / removed project 🤔
i'll work on that 👍

Not sure what it is, maybe the imports, I'll check that

if gm cache hasn't been brought into scope that's expected 😉

i'll work on a little toolkit to simplify that 😌

when cloning or removing a project, there is no need to update the
whole cache, that takes unnecessary time...

this commit only appends the new project to the cache or removes it
when using `gm clone` or `gm remove`.
because it started to be used in multiple places, i've refactored
the check of the cache existence in `check-cache-file` in the
`fs/store/` module.
@amtoine
Copy link
Owner Author

amtoine commented Oct 21, 2023

Wouldn't that be super slow? (I still have to test it out)

that should be muuuuuch faster anyways thanks to fa3f5ea 🤞

@melMass
Copy link
Collaborator

melMass commented Oct 21, 2023

works on my side 👍

Yep this was before I understand that all commands are imported individually, I added it to the readme here b12bd94 I wasn't sure because it was only used to get the cache path but with your new commit it make sense imo to mention it in the import examples

that should be muuuuuch faster anyways thanks to fa3f5ea 🤞

Awesome!

@amtoine
Copy link
Owner Author

amtoine commented Oct 21, 2023

Yep this was before I understand that all commands are imported individually, I added it to the readme here b12bd94 I wasn't sure because it was only used to get the cache path but with your new commit it make sense imo to mention it in the import examples

oooh ok ok 👍
you can also run

use nu-git-manager *

😋

Awesome!

tell me when the changes are ok, or feel free to land if there's nothing more to add right now 😌

@melMass
Copy link
Collaborator

melMass commented Oct 24, 2023

Small detail (as it works fine) but there is still a backslash there:

image

@melMass
Copy link
Collaborator

melMass commented Oct 24, 2023

There is no much point in my addition to the readme, I reverted it

Copy link
Collaborator

@melMass melMass left a comment

Choose a reason for hiding this comment

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

🚀

@melMass melMass merged commit f454d80 into main Oct 24, 2023
3 checks passed
@melMass melMass deleted the cache-based-listing branch October 24, 2023 12:37
@amtoine
Copy link
Owner Author

amtoine commented Oct 24, 2023

thanks for landing this 🙏

@amtoine amtoine mentioned this pull request Oct 28, 2023
4 tasks
@amtoine amtoine mentioned this pull request Jan 22, 2024
amtoine added a commit that referenced this pull request Jan 22, 2024
this has been introduced in
#29, likely through an
annoying and automatic formatting of the Markdown document 😮
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