commands: teach uploadContext how to init the gitscanner
This commit is contained in:
parent
781c7f55ad
commit
7cf53a746a
@ -6,7 +6,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/git-lfs/git-lfs/git"
|
||||
"github.com/git-lfs/git-lfs/lfs"
|
||||
"github.com/rubyist/tracerx"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@ -53,11 +52,10 @@ func prePushCommand(cmd *cobra.Command, args []string) {
|
||||
|
||||
ctx := newUploadContext(args[0], prePushDryRun)
|
||||
|
||||
gitscanner := lfs.NewGitScanner(nil)
|
||||
if err := gitscanner.RemoteForPush(ctx.Remote); err != nil {
|
||||
gitscanner, err := ctx.buildGitScanner()
|
||||
if err != nil {
|
||||
ExitWithError(err)
|
||||
}
|
||||
|
||||
defer gitscanner.Close()
|
||||
|
||||
// We can be passed multiple lines of refs
|
||||
|
@ -1,7 +1,6 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/git-lfs/git-lfs/errors"
|
||||
@ -23,8 +22,8 @@ var (
|
||||
func uploadsBetweenRefAndRemote(ctx *uploadContext, refnames []string) {
|
||||
tracerx.Printf("Upload refs %v to remote %v", refnames, ctx.Remote)
|
||||
|
||||
gitscanner := lfs.NewGitScanner(nil)
|
||||
if err := gitscanner.RemoteForPush(ctx.Remote); err != nil {
|
||||
gitscanner, err := ctx.buildGitScanner()
|
||||
if err != nil {
|
||||
ExitWithError(err)
|
||||
}
|
||||
defer gitscanner.Close()
|
||||
@ -45,34 +44,6 @@ func uploadsBetweenRefAndRemote(ctx *uploadContext, refnames []string) {
|
||||
ctx.Await()
|
||||
}
|
||||
|
||||
func uploadLeftOrAll(g *lfs.GitScanner, ctx *uploadContext, ref string) error {
|
||||
var multiErr error
|
||||
cb := func(p *lfs.WrappedPointer, err error) {
|
||||
if err != nil {
|
||||
if multiErr != nil {
|
||||
multiErr = fmt.Errorf("%v\n%v", multiErr, err)
|
||||
} else {
|
||||
multiErr = err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
uploadPointers(ctx, p)
|
||||
}
|
||||
|
||||
if pushAll {
|
||||
if err := g.ScanRefWithDeleted(ref, cb); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := g.ScanLeftToRemote(ref, cb); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return multiErr
|
||||
}
|
||||
|
||||
func uploadsWithObjectIDs(ctx *uploadContext, oids []string) {
|
||||
for _, oid := range oids {
|
||||
mp, err := lfs.LocalMediaPath(oid)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
@ -12,6 +13,19 @@ import (
|
||||
"github.com/git-lfs/git-lfs/tq"
|
||||
)
|
||||
|
||||
func uploadLeftOrAll(g *lfs.GitScanner, ctx *uploadContext, ref string) error {
|
||||
if pushAll {
|
||||
if err := g.ScanRefWithDeleted(ref, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := g.ScanLeftToRemote(ref, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return ctx.scannerError()
|
||||
}
|
||||
|
||||
type uploadContext struct {
|
||||
Remote string
|
||||
DryRun bool
|
||||
@ -35,6 +49,10 @@ type uploadContext struct {
|
||||
|
||||
// locks from theirLocks that were modified in this push
|
||||
unownedLocks []*locking.Lock
|
||||
|
||||
// tracks errors from gitscanner callbacks
|
||||
scannerErr error
|
||||
errMu sync.Mutex
|
||||
}
|
||||
|
||||
func newUploadContext(remote string, dryRun bool) *uploadContext {
|
||||
@ -71,6 +89,36 @@ func newUploadContext(remote string, dryRun bool) *uploadContext {
|
||||
return ctx
|
||||
}
|
||||
|
||||
func (c *uploadContext) scannerError() error {
|
||||
c.errMu.Lock()
|
||||
defer c.errMu.Unlock()
|
||||
|
||||
return c.scannerErr
|
||||
}
|
||||
|
||||
func (c *uploadContext) addScannerError(err error) {
|
||||
c.errMu.Lock()
|
||||
defer c.errMu.Unlock()
|
||||
|
||||
if c.scannerErr != nil {
|
||||
c.scannerErr = fmt.Errorf("%v\n%v", c.scannerErr, err)
|
||||
} else {
|
||||
c.scannerErr = err
|
||||
}
|
||||
}
|
||||
|
||||
func (c *uploadContext) buildGitScanner() (*lfs.GitScanner, error) {
|
||||
gitscanner := lfs.NewGitScanner(func(p *lfs.WrappedPointer, err error) {
|
||||
if err != nil {
|
||||
c.addScannerError(err)
|
||||
} else {
|
||||
uploadPointers(c, p)
|
||||
}
|
||||
})
|
||||
|
||||
return gitscanner, gitscanner.RemoteForPush(c.Remote)
|
||||
}
|
||||
|
||||
// AddUpload adds the given oid to the set of oids that have been uploaded in
|
||||
// the current process.
|
||||
func (c *uploadContext) SetUploaded(oid string) {
|
||||
|
Loading…
Reference in New Issue
Block a user