Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software:2222/vole.git

A free and open-source forge that lives in your Git repo.

refactor

c5902451905acdaa478f8476844ccd4a510d9ca9 · Keenan Nemetz · 17d ago · parent ec2aba4b

internal/gc/gc.go → forge/gc.go +13−13

@@ -1,4 +1,4 @@
1 // Package gc sweeps the LFS store.
1 // GC sweeps the LFS store.
2 2 //
3 3 // The rule the sweep must never break: an object reachable from a live ref is kept. That
4 4 // is why nothing here trusts a counter — counters drift after a crash, a failed upload or
@@ -23,25 +23,25 @@
23 23 //
24 24 // Anything unmarked and younger than the grace period is kept: an upload that lands while
25 25 // the sweep is marking is not reachable yet, but is not garbage either.
26 package gc
26 package forge
27 27
28 28 import (
29 29 "fmt"
30 30 "time"
31 31
32 "github.com/rodent-software/vole/internal/gitx"
33 "github.com/rodent-software/vole/internal/lfs"
32 "github.com/rodent-software/vole/core/git"
33 "github.com/rodent-software/vole/core/lfs"
34 34 )
35 35
36 36 // Repo is one repository to scan: the name its objects are served under, and the bare
37 37 // directory to read refs from.
38 type Repo struct {
38 type GCRepo struct {
39 39 Name string
40 40 Dir string
41 41 }
42 42
43 type Options struct {
44 Repos []Repo
43 type GCOptions struct {
44 Repos []GCRepo
45 45 Store *lfs.Store
46 46 // RunOIDs are objects named by the run queue, per repository: archived logs and
47 47 // published run artifacts. Neither is reachable from a git ref, so a sweep that only
@@ -57,7 +57,7 @@ type Options struct {
57 57 Now time.Time
58 58 }
59 59
60 type Result struct {
60 type GCResult struct {
61 61 Marked int
62 62 Linked int // links created, which is repair work when it is not zero
63 63 Unlinked int
@@ -72,8 +72,8 @@ type Result struct {
72 72 // Run marks, links, unlinks, then sweeps. A repository that cannot be scanned aborts the
73 73 // sweep: an unreadable ref means "I do not know what is reachable", and guessing costs
74 74 // somebody's data.
75 func Run(opts Options) (Result, error) {
76 var res Result
75 func GC(opts GCOptions) (GCResult, error) {
76 var res GCResult
77 77 if opts.Store == nil {
78 78 return res, fmt.Errorf("gc: no store")
79 79 }
@@ -86,7 +86,7 @@ func Run(opts Options) (Result, error) {
86 86 reachable := make(map[string]map[string]bool, len(opts.Repos))
87 87 all := map[string]bool{}
88 88 for _, repo := range opts.Repos {
89 g := gitx.Open(repo.Dir)
89 g := git.Open(repo.Dir)
90 90 blobs, err := g.AllBlobs()
91 91 if err != nil {
92 92 return res, fmt.Errorf("gc: scan %s: %w", repo.Dir, err)
@@ -210,8 +210,8 @@ func Run(opts Options) (Result, error) {
210 210 // Link is the repair pass: it creates the links a repository is missing and deletes
211 211 // nothing. An instance that predates repository-scoped storage runs it once so its
212 212 // existing objects become fetchable again; so does a namespace somebody deleted.
213 func Link(opts Options) (Result, error) {
213 func GCLink(opts GCOptions) (GCResult, error) {
214 214 opts.LinkOnly = true
215 215 opts.DryRun = false
216 return Run(opts)
216 return GC(opts)
217 217 }