Skip to content

Commit e904708

Browse files
author
rubyist
committed
Use the queue in the pre push command as well
1 parent 0a9ebaf commit e904708

File tree

1 file changed

+17
-60
lines changed

1 file changed

+17
-60
lines changed

commands/commands_pre_push.go

Lines changed: 17 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package commands
22

33
import (
4-
"fmt"
54
"github.com/github/git-lfs/lfs"
6-
"github.com/rubyist/tracerx"
75
"github.com/spf13/cobra"
86
"io/ioutil"
97
"os"
10-
"path/filepath"
118
"strings"
129
)
1310

@@ -73,80 +70,40 @@ func prePushCommand(cmd *cobra.Command, args []string) {
7370
Panic(err, "Error scanning for Git LFS files")
7471
}
7572

73+
uploadQueue := lfs.NewUploadQueue(lfs.Config.ConcurrentUploads(), len(pointers))
74+
7675
for i, pointer := range pointers {
7776
if prePushDryRun {
7877
Print("push %s", pointer.Name)
7978
continue
8079
}
8180

82-
if wErr := pushAsset(pointer.Oid, pointer.Name, i+1, len(pointers)); wErr != nil {
81+
u, wErr := lfs.NewUploadable(pointer.Oid, pointer.Name, i+1, len(pointers))
82+
if wErr != nil {
8383
if Debugging || wErr.Panic {
8484
Panic(wErr.Err, wErr.Error())
8585
} else {
8686
Exit(wErr.Error())
8787
}
8888
}
89-
}
90-
}
91-
92-
// pushAsset pushes the asset with the given oid to the Git LFS API.
93-
func pushAsset(oid, filename string, index, totalFiles int) *lfs.WrappedError {
94-
tracerx.Printf("checking_asset: %s %s %d/%d", oid, filename, index, totalFiles)
95-
path, err := lfs.LocalMediaPath(oid)
96-
if err != nil {
97-
return lfs.Errorf(err, "Error uploading file %s (%s)", filename, oid)
98-
}
99-
100-
if err := ensureFile(filename, path); err != nil {
101-
return lfs.Errorf(err, "Error uploading file %s (%s)", filename, oid)
102-
}
10389

104-
cb, file, cbErr := lfs.CopyCallbackFile("push", filename, index, totalFiles)
105-
if cbErr != nil {
106-
Error(cbErr.Error())
90+
uploadQueue.Upload(u)
10791
}
10892

109-
if file != nil {
110-
defer file.Close()
111-
}
112-
113-
fmt.Fprintf(os.Stderr, "Uploading %s\n", filename)
114-
return lfs.Upload(path, filename, cb)
115-
}
116-
117-
// ensureFile makes sure that the cleanPath exists before pushing it. If it
118-
// does not exist, it attempts to clean it by reading the file at smudgePath.
119-
func ensureFile(smudgePath, cleanPath string) error {
120-
if _, err := os.Stat(cleanPath); err == nil {
121-
return nil
122-
}
123-
124-
expectedOid := filepath.Base(cleanPath)
125-
localPath := filepath.Join(lfs.LocalWorkingDir, smudgePath)
126-
file, err := os.Open(localPath)
127-
if err != nil {
128-
return err
129-
}
130-
131-
defer file.Close()
132-
133-
stat, err := file.Stat()
134-
if err != nil {
135-
return err
136-
}
137-
138-
cleaned, err := lfs.PointerClean(file, stat.Size(), nil)
139-
if err != nil {
140-
return err
141-
}
142-
143-
cleaned.Close()
93+
if !prePushDryRun {
94+
uploadQueue.Process()
95+
for _, err := range uploadQueue.Errors() {
96+
if Debugging || err.Panic {
97+
LoggedError(err.Err, err.Error())
98+
} else {
99+
Error(err.Error())
100+
}
101+
}
144102

145-
if expectedOid != cleaned.Oid {
146-
return fmt.Errorf("Expected %s to have an OID of %s, got %s", smudgePath, expectedOid, cleaned.Oid)
103+
if len(uploadQueue.Errors()) > 0 {
104+
os.Exit(2)
105+
}
147106
}
148-
149-
return nil
150107
}
151108

152109
// decodeRefs pulls the sha1s out of the line read from the pre-push

0 commit comments

Comments
 (0)