From b27dca5faaa47bab48cd0461773552b897f8a4b1 Mon Sep 17 00:00:00 2001 From: amtoine Date: Thu, 26 Oct 2023 19:02:59 +0200 Subject: [PATCH 1/3] support reading the cache from `GIT_REPOS_CACHE` --- nu-git-manager/fs/store.nu | 9 ++++++--- nu-git-manager/mod.nu | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/nu-git-manager/fs/store.nu b/nu-git-manager/fs/store.nu index 4446edc1..c4f9f28d 100644 --- a/nu-git-manager/fs/store.nu +++ b/nu-git-manager/fs/store.nu @@ -8,9 +8,12 @@ export def get-repo-store-path []: nothing -> path { } export def get-repo-store-cache-path []: nothing -> path { - $env.XDG_CACHE_HOME? - | default ($nu.home-path | path join ".cache") - | path join "nu-git-manager/cache.nuon" + $env.GIT_REPOS_CACHE? + | default ( + $env.XDG_CACHE_HOME? + | default ($nu.home-path | path join ".cache") + | path join "nu-git-manager/cache.nuon" + ) | path expand | path sanitize } diff --git a/nu-git-manager/mod.nu b/nu-git-manager/mod.nu index 81239e61..f1f0adc7 100644 --- a/nu-git-manager/mod.nu +++ b/nu-git-manager/mod.nu @@ -22,6 +22,7 @@ def "nu-complete git-protocols" []: nothing -> table Date: Thu, 26 Oct 2023 19:03:25 +0200 Subject: [PATCH 2/3] expand the cache tests --- tests/mod.nu | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/mod.nu b/tests/mod.nu index 32a87e5f..4ac29cc0 100644 --- a/tests/mod.nu +++ b/tests/mod.nu @@ -93,10 +93,12 @@ export def get-store-root [] { export def get-repo-cache [] { let cases = [ - [env, expected]; + [env, expected]; - [{XDG_CACHE_HOME: null}, "~/.cache/nu-git-manager/cache.nuon"], - [{XDG_CACHE_HOME: "~/xdg"}, "~/xdg/nu-git-manager/cache.nuon"], + [{GIT_REPOS_CACHE: null, XDG_CACHE_HOME: null}, "~/.cache/nu-git-manager/cache.nuon"], + [{GIT_REPOS_CACHE: "~/my_cache", XDG_CACHE_HOME: null}, "~/my_cache"], + [{GIT_REPOS_CACHE: null, XDG_CACHE_HOME: "~/xdg"}, "~/xdg/nu-git-manager/cache.nuon"], + [{GIT_REPOS_CACHE: "~/my_cache", XDG_CACHE_HOME: "~/xdg"}, "~/my_cache"], ] for case in $cases { From b38ed6381db7934e06ba6948ffdf31e829dde5f4 Mon Sep 17 00:00:00 2001 From: amtoine Date: Thu, 26 Oct 2023 19:25:55 +0200 Subject: [PATCH 3/3] open cache without assuming it's `.nuon` the file format should still be NUON. --- nu-git-manager/mod.nu | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/nu-git-manager/mod.nu b/nu-git-manager/mod.nu index f1f0adc7..a6d49c25 100644 --- a/nu-git-manager/mod.nu +++ b/nu-git-manager/mod.nu @@ -96,7 +96,13 @@ export def "gm clone" [ check-cache-file $cache_file print --no-newline "updating cache... " - open $cache_file | append $local_path | uniq | sort | save --force $cache_file + open --raw $cache_file + | from nuon + | append $local_path + | uniq + | sort + | to nuon + | save --force $cache_file print "done" null @@ -119,7 +125,7 @@ export def "gm list" [ let cache_file = get-repo-store-cache-path check-cache-file $cache_file - let repos = open $cache_file + let repos = open --raw $cache_file | from nuon if $full_path { $repos } else { @@ -171,7 +177,7 @@ export def "gm status" []: nothing -> record nothing { mkdir ($cache_file | path dirname) print --no-newline "updating cache... " - list-repos-in-store | save --force $cache_file + let foo = list-repos-in-store + print ($foo | describe) + print $foo + $foo | to nuon | save --force $cache_file print "done" null @@ -272,7 +281,12 @@ export def "gm remove" [ check-cache-file $cache_file print --no-newline "updating cache... " - open $cache_file | where $it != ($root | path join $repo_to_remove) | save --force $cache_file + open --raw $cache_file + | from nuon + | where $it != ($root + | path join $repo_to_remove) + | to nuon + | save --force $cache_file print "done" null