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

read cache from env #39

Merged
merged 3 commits into from
Oct 26, 2023
Merged

read cache from env #39

merged 3 commits into from
Oct 26, 2023

Conversation

amtoine
Copy link
Owner

@amtoine amtoine commented Oct 26, 2023

i was trying to help @stormasm with a strange bug of his and wanted to run something like the following to not use either my personal store nor my cache:

with-env {
    GIT_REPOS_HOME: /tmp/repos,
    GIT_REPOS_CACHE: /tmp/repos.cache
} {
    gm update-cache
}

description

this PR allows gm to read the cache location from $env.GIT_REPOS_CACHE before the XDG location and the default one.
this change happens in the get-repo-store-cache-path command and mirrors the behaviour from get-repo-store-path

Note
because the extension of the cache can now be anything, e.g. .cache in the snippet of this PR, gm can not assume that it's NUON directly

  • open --raw $cache_file | from nuon is used to open the content of the cache
  • to nuon | save --force $cache_file is used to dump the new cache to its file

user-facing changes

with-env {
    GIT_REPOS_HOME: /tmp/repos,
    GIT_REPOS_CACHE: /tmp/repos.cache
} {
    gm update-cache
}

can now be used to play with gm without messing with the real store of repos.

@stormasm
Copy link

@amtoine thanks for this ! I will continue to check it out and understand more how this works...

@amtoine amtoine mentioned this pull request Oct 26, 2023
4 tasks
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.

Agreed! we mentioned both in previous PRs

@melMass melMass merged commit 8feef80 into main Oct 26, 2023
3 checks passed
@amtoine amtoine deleted the read-cache-from-env branch October 27, 2023 08:34
This was referenced Oct 27, 2023
amtoine added a commit that referenced this pull request Oct 28, 2023
as explained in
#24 (comment),
i encountered a cache bug when working on #39 => because the cache path
can now be fully set by the user with `$env.GIT_REPOS_CACHE`, it does
not have the `.nuon` extension in general and thus we cannot assume
`open $env.GIT_REPOS_CACHE` to open the file as NUON data...

## description
in order to allow testing more of the internals of the `gm` commands, i
propose in this PR to move the cache logic as much as possible from `gm`
itself to a new internal `fs/cache.nu` module.

> **Important**
> this might sounds like *clean code*, e.g. where you put all the code
in nested oneliners...
> i would argue it's not the goal of this PR and the fact that the
resulting commands are quite small is simply because they are doing
quite simple stuff!
> the goal here is to move the internal logic out of the public `gm`
which exposes the main API to allow testing as much as possible without
require to `gm clone` actual repositories or `gm remove` in an
interactive manner 😋

### changelog
- move `get-repo-store-cache-path` and `check-cache-file` to a new
`fs/cache.nu` module
- move most of the cache logic to commands in `fs/cache.nu`
- adds tests for the cache functionalities

## tests
a new `cache-manipulation` test in `tests/mod.nu`.

---------

Co-authored-by: Mel Massadian <melmassadian@gmail.com>
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.

3 participants