commands: extract CollectErrors() and ReportErrors() from Await()
This commit is contained in:
parent
88812a4ad2
commit
1ade8ec224
@ -72,6 +72,11 @@ type uploadContext struct {
|
||||
// tracks errors from gitscanner callbacks
|
||||
scannerErr error
|
||||
errMu sync.Mutex
|
||||
|
||||
// filename => oid
|
||||
missing map[string]string
|
||||
corrupt map[string]string
|
||||
otherErrs []error
|
||||
}
|
||||
|
||||
func newUploadContext(dryRun bool) *uploadContext {
|
||||
@ -85,6 +90,9 @@ func newUploadContext(dryRun bool) *uploadContext {
|
||||
gitfilter: lfs.NewGitFilter(cfg),
|
||||
lockVerifier: newLockVerifier(manifest),
|
||||
allowMissing: cfg.Git.Bool("lfs.allowincompletepush", true),
|
||||
missing: make(map[string]string),
|
||||
corrupt: make(map[string]string),
|
||||
otherErrs: make([]error, 0),
|
||||
}
|
||||
|
||||
var sink io.Writer = os.Stdout
|
||||
@ -222,30 +230,30 @@ func uploadPointers(c *uploadContext, unfiltered ...*lfs.WrappedPointer) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *uploadContext) Await() {
|
||||
c.tq.Wait()
|
||||
func (c *uploadContext) CollectErrors(tqueues ...*tq.TransferQueue) {
|
||||
for _, tqueue := range tqueues {
|
||||
tqueue.Wait()
|
||||
|
||||
var missing = make(map[string]string)
|
||||
var corrupt = make(map[string]string)
|
||||
var others = make([]error, 0, len(c.tq.Errors()))
|
||||
|
||||
for _, err := range c.tq.Errors() {
|
||||
if malformed, ok := err.(*tq.MalformedObjectError); ok {
|
||||
if malformed.Missing() {
|
||||
missing[malformed.Name] = malformed.Oid
|
||||
} else if malformed.Corrupt() {
|
||||
corrupt[malformed.Name] = malformed.Oid
|
||||
for _, err := range tqueue.Errors() {
|
||||
if malformed, ok := err.(*tq.MalformedObjectError); ok {
|
||||
if malformed.Missing() {
|
||||
c.missing[malformed.Name] = malformed.Oid
|
||||
} else if malformed.Corrupt() {
|
||||
c.corrupt[malformed.Name] = malformed.Oid
|
||||
}
|
||||
} else {
|
||||
c.otherErrs = append(c.otherErrs, err)
|
||||
}
|
||||
} else {
|
||||
others = append(others, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, err := range others {
|
||||
func (c *uploadContext) ReportErrors() {
|
||||
for _, err := range c.otherErrs {
|
||||
FullError(err)
|
||||
}
|
||||
|
||||
if len(missing) > 0 || len(corrupt) > 0 {
|
||||
if len(c.missing) > 0 || len(c.corrupt) > 0 {
|
||||
var action string
|
||||
if c.allowMissing {
|
||||
action = "missing objects"
|
||||
@ -254,10 +262,10 @@ func (c *uploadContext) Await() {
|
||||
}
|
||||
|
||||
Print("LFS upload %s:", action)
|
||||
for name, oid := range missing {
|
||||
for name, oid := range c.missing {
|
||||
Print(" (missing) %s (%s)", name, oid)
|
||||
}
|
||||
for name, oid := range corrupt {
|
||||
for name, oid := range c.corrupt {
|
||||
Print(" (corrupt) %s (%s)", name, oid)
|
||||
}
|
||||
|
||||
@ -266,7 +274,7 @@ func (c *uploadContext) Await() {
|
||||
}
|
||||
}
|
||||
|
||||
if len(others) > 0 {
|
||||
if len(c.otherErrs) > 0 {
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
@ -289,6 +297,11 @@ func (c *uploadContext) Await() {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *uploadContext) Await() {
|
||||
c.CollectErrors(c.tq)
|
||||
c.ReportErrors()
|
||||
}
|
||||
|
||||
var (
|
||||
githubHttps, _ = url.Parse("https://github.com")
|
||||
githubSsh, _ = url.Parse("ssh://github.com")
|
||||
|
Loading…
Reference in New Issue
Block a user