|
1 | 1 | package commands
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "fmt" |
5 | 4 | "github.com/github/git-lfs/lfs"
|
6 |
| - "github.com/rubyist/tracerx" |
7 | 5 | "github.com/spf13/cobra"
|
8 | 6 | "io/ioutil"
|
9 | 7 | "os"
|
10 |
| - "path/filepath" |
11 | 8 | "strings"
|
12 | 9 | )
|
13 | 10 |
|
@@ -73,80 +70,40 @@ func prePushCommand(cmd *cobra.Command, args []string) {
|
73 | 70 | Panic(err, "Error scanning for Git LFS files")
|
74 | 71 | }
|
75 | 72 |
|
| 73 | + uploadQueue := lfs.NewUploadQueue(lfs.Config.ConcurrentUploads(), len(pointers)) |
| 74 | + |
76 | 75 | for i, pointer := range pointers {
|
77 | 76 | if prePushDryRun {
|
78 | 77 | Print("push %s", pointer.Name)
|
79 | 78 | continue
|
80 | 79 | }
|
81 | 80 |
|
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 { |
83 | 83 | if Debugging || wErr.Panic {
|
84 | 84 | Panic(wErr.Err, wErr.Error())
|
85 | 85 | } else {
|
86 | 86 | Exit(wErr.Error())
|
87 | 87 | }
|
88 | 88 | }
|
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 |
| - } |
103 | 89 |
|
104 |
| - cb, file, cbErr := lfs.CopyCallbackFile("push", filename, index, totalFiles) |
105 |
| - if cbErr != nil { |
106 |
| - Error(cbErr.Error()) |
| 90 | + uploadQueue.Upload(u) |
107 | 91 | }
|
108 | 92 |
|
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 | + } |
144 | 102 |
|
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 | + } |
147 | 106 | }
|
148 |
| - |
149 |
| - return nil |
150 | 107 | }
|
151 | 108 |
|
152 | 109 | // decodeRefs pulls the sha1s out of the line read from the pre-push
|
|
0 commit comments