mirror of
https://github.com/therootcompany/golib.git
synced 2026-04-24 20:58:00 +00:00
refactor: remove Run from gitshallow.Repo
Polling loop (ticker + Sync check) is generic to any update source — git HEAD, HTTP ETag, file mtime. Caller drives the loop.
This commit is contained in:
parent
d6837d31ed
commit
73b033c3e1
@ -1,14 +1,12 @@
|
|||||||
package gitshallow
|
package gitshallow
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Repo manages a shallow git clone used as a periodically-updated data source.
|
// Repo manages a shallow git clone used as a periodically-updated data source.
|
||||||
@ -58,28 +56,6 @@ func (r *Repo) Init(lightGC bool) error {
|
|||||||
return r.invokeCallbacks()
|
return r.invokeCallbacks()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run periodically syncs the repo and invokes callbacks when HEAD changes.
|
|
||||||
// Blocks until ctx is done.
|
|
||||||
// lightGC=false (zero value) runs aggressive GC with immediate pruning to minimize disk use.
|
|
||||||
// Pass true to skip both when the periodic GC is too slow for your workload.
|
|
||||||
func (r *Repo) Run(ctx context.Context, lightGC bool) {
|
|
||||||
ticker := time.NewTicker(47 * time.Minute)
|
|
||||||
defer ticker.Stop()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ticker.C:
|
|
||||||
if updated, err := r.Sync(lightGC); err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "error: git sync: %v\n", err)
|
|
||||||
} else if updated {
|
|
||||||
fmt.Fprintf(os.Stderr, "git: repo updated\n")
|
|
||||||
}
|
|
||||||
case <-ctx.Done():
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clone performs a shallow clone (--depth N --single-branch --no-tags).
|
// Clone performs a shallow clone (--depth N --single-branch --no-tags).
|
||||||
func (r *Repo) Clone() (bool, error) {
|
func (r *Repo) Clone() (bool, error) {
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user