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
cmd/vole/gc.go +10−22
| @@ -9,11 +9,12 @@ import ( | |||
| 9 | 9 | "os" | |
| 10 | 10 | "time" | |
| 11 | 11 | ||
| 12 | "github.com/rodent-software/vole/internal/config" | ||
| 13 | "github.com/rodent-software/vole/internal/gc" | ||
| 14 | "github.com/rodent-software/vole/internal/lfs" | ||
| 15 | "github.com/rodent-software/vole/internal/repo" | ||
| 16 | "github.com/rodent-software/vole/internal/runs" | ||
| 12 | "github.com/rodent-software/vole/ci/runs" | ||
| 13 | "github.com/rodent-software/vole/core/lfs" | ||
| 14 | "github.com/rodent-software/vole/forge" | ||
| 15 | "github.com/rodent-software/vole/forge/config" | ||
| 16 | "github.com/rodent-software/vole/forge/repo" | ||
| 17 | "github.com/rodent-software/vole/internal/format" | ||
| 17 | 18 | ) | |
| 18 | 19 | ||
| 19 | 20 | const gcUsage = `usage: vole gc [--dry-run] [--grace duration] | |
| @@ -62,9 +63,9 @@ func cmdGC(args []string) error { | |||
| 62 | 63 | if err != nil { | |
| 63 | 64 | return err | |
| 64 | 65 | } | |
| 65 | scan := make([]gc.Repo, 0, len(repos)) | ||
| 66 | scan := make([]forge.GCRepo, 0, len(repos)) | ||
| 66 | 67 | for _, m := range repos { | |
| 67 | scan = append(scan, gc.Repo{Name: m.Name, Dir: m.Dir}) | ||
| 68 | scan = append(scan, forge.GCRepo{Name: m.Name, Dir: m.Dir}) | ||
| 68 | 69 | } | |
| 69 | 70 | ||
| 70 | 71 | // Archived logs are roots too. The queue is opened only if it exists, so gc | |
| @@ -94,7 +95,7 @@ func cmdGC(args []string) error { | |||
| 94 | 95 | } | |
| 95 | 96 | } | |
| 96 | 97 | ||
| 97 | res, err := gc.Run(gc.Options{ | ||
| 98 | res, err := forge.GC(forge.GCOptions{ | ||
| 98 | 99 | Repos: scan, | |
| 99 | 100 | Store: lfs.New(cfg.LFSDir(), 0), // no cap: gc reads, it does not accept | |
| 100 | 101 | RunOIDs: runOIDs, | |
| @@ -115,7 +116,7 @@ func cmdGC(args []string) error { | |||
| 115 | 116 | if res.Linked > 0 || res.Unlinked > 0 { | |
| 116 | 117 | fmt.Printf("linked %d object(s) into their repositories, unlinked %d\n", res.Linked, res.Unlinked) | |
| 117 | 118 | } | |
| 118 | fmt.Printf("%s %d object(s), %s\n", verb, res.Swept, humanBytes(res.SweptB)) | ||
| 119 | fmt.Printf("%s %d object(s), %s\n", verb, res.Swept, format.Bytes(res.SweptB)) | ||
| 119 | 120 | if res.Within > 0 { | |
| 120 | 121 | fmt.Printf("kept %d unreferenced object(s) younger than %s\n", res.Within, grace) | |
| 121 | 122 | } | |
| @@ -127,16 +128,3 @@ func cmdGC(args []string) error { | |||
| 127 | 128 | } | |
| 128 | 129 | return nil | |
| 129 | 130 | } | |
| 130 | |||
| 131 | func humanBytes(n int64) string { | ||
| 132 | const unit = 1024 | ||
| 133 | if n < unit { | ||
| 134 | return fmt.Sprintf("%d B", n) | ||
| 135 | } | ||
| 136 | div, exp := int64(unit), 0 | ||
| 137 | for m := n / unit; m >= unit; m /= unit { | ||
| 138 | div *= unit | ||
| 139 | exp++ | ||
| 140 | } | ||
| 141 | return fmt.Sprintf("%.1f %ciB", float64(n)/float64(div), "KMGTPE"[exp]) | ||
| 142 | } | ||