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