Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: deploytool/cmd/luci_deploy/checkout.go

Issue 2963503003: [errors] Greatly simplify common/errors package. (Closed)
Patch Set: fix nits Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « deploytool/cmd/luci_deploy/build.go ('k') | deploytool/cmd/luci_deploy/config.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "crypto/sha256" 8 "crypto/sha256"
9 "encoding/hex" 9 "encoding/hex"
10 "fmt" 10 "fmt"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 if err != nil { 69 if err != nil {
70 logError(c, err, "Failed to checkout.") 70 logError(c, err, "Failed to checkout.")
71 return 1 71 return 1
72 } 72 }
73 return 0 73 return 0
74 } 74 }
75 75
76 func checkout(w *work, l *deployLayout, applyOverrides bool) error { 76 func checkout(w *work, l *deployLayout, applyOverrides bool) error {
77 frozen, err := l.initFrozenCheckout(w) 77 frozen, err := l.initFrozenCheckout(w)
78 if err != nil { 78 if err != nil {
79 » » return errors.Annotate(err).Reason("failed to initialize checkou t").Err() 79 » » return errors.Annotate(err, "failed to initialize checkout").Err ()
80 } 80 }
81 81
82 // reg is our internal checkout registry. This represents the actual 82 // reg is our internal checkout registry. This represents the actual
83 // repository checkouts that we perform. Duplicate sources to the same 83 // repository checkouts that we perform. Duplicate sources to the same
84 // repository will be deduplicated here. 84 // repository will be deduplicated here.
85 fs, err := l.workingFilesystem() 85 fs, err := l.workingFilesystem()
86 if err != nil { 86 if err != nil {
87 » » return errors.Annotate(err).Err() 87 » » return errors.Annotate(err, "").Err()
88 } 88 }
89 checkoutDir, err := fs.Base().EnsureDirectory(checkoutsSubdir) 89 checkoutDir, err := fs.Base().EnsureDirectory(checkoutsSubdir)
90 if err != nil { 90 if err != nil {
91 » » return errors.Annotate(err).Reason("failed to create checkout di rectory").Err() 91 » » return errors.Annotate(err, "failed to create checkout directory ").Err()
92 } 92 }
93 93
94 repoDir, err := checkoutDir.EnsureDirectory("repository") 94 repoDir, err := checkoutDir.EnsureDirectory("repository")
95 if err != nil { 95 if err != nil {
96 » » return errors.Annotate(err).Reason("failed to create repository directory %(dir)q"). 96 » » return errors.Annotate(err, "failed to create repository directo ry %q", repoDir).Err()
97 » » » D("dir", repoDir).Err()
98 } 97 }
99 98
100 reg := checkoutRegistry{ 99 reg := checkoutRegistry{
101 repoDir: repoDir, 100 repoDir: repoDir,
102 } 101 }
103 102
104 // Do a central checkout of registry repositories. We will project this using 103 // Do a central checkout of registry repositories. We will project this using
105 // sorted keys so that checkout failures happen consistently. 104 // sorted keys so that checkout failures happen consistently.
106 var ( 105 var (
107 scs []*sourceCheckout 106 scs []*sourceCheckout
(...skipping 17 matching lines...) Expand all
125 sort.Strings(srcKeys) 124 sort.Strings(srcKeys)
126 125
127 for i, srcKey := range srcKeys { 126 for i, srcKey := range srcKeys {
128 sc := sourceCheckout{ 127 sc := sourceCheckout{
129 FrozenLayout_Source: sg.Source[srcKey], 128 FrozenLayout_Source: sg.Source[srcKey],
130 group: sgKey, 129 group: sgKey,
131 name: srcKey, 130 name: srcKey,
132 } 131 }
133 132
134 if err := sc.addRegistryRepos(&reg); err != nil { 133 if err := sc.addRegistryRepos(&reg); err != nil {
135 » » » » return errors.Annotate(err).Reason("failed to ad d [%(sourceCheckout)s] to registry"). 134 » » » » return errors.Annotate(err, "failed to add [%s] to registry", sc).Err()
136 » » » » » D("sourceCheckout", sc).Err()
137 } 135 }
138 136
139 // If we're overriding sources, and this source is overr idden, then apply 137 // If we're overriding sources, and this source is overr idden, then apply
140 // this and add the overriding source to the registry as well. 138 // this and add the overriding source to the registry as well.
141 // 139 //
142 // We will still keep the original source in the registr y so it doesn't 140 // We will still keep the original source in the registr y so it doesn't
143 // get deleted during cleanup. 141 // get deleted during cleanup.
144 if applyOverrides { 142 if applyOverrides {
145 if override, ok := l.userSourceOverrides[sc.over rideURL]; ok { 143 if override, ok := l.userSourceOverrides[sc.over rideURL]; ok {
146 log.Infof(w, "Applying user repository o verride: [%+v] => [%+v]", sc.Source, override) 144 log.Infof(w, "Applying user repository o verride: [%+v] => [%+v]", sc.Source, override)
147 145
148 // Any local overrides cause the source group to be considered 146 // Any local overrides cause the source group to be considered
149 // tainted. 147 // tainted.
150 sc.FrozenLayout_Source.Source = override 148 sc.FrozenLayout_Source.Source = override
151 sc.FrozenLayout_Source.Source.Tainted = true 149 sc.FrozenLayout_Source.Source.Tainted = true
152 150
153 if err := sc.addRegistryRepos(&reg); err != nil { 151 if err := sc.addRegistryRepos(&reg); err != nil {
154 » » » » » » return errors.Annotate(err).Reas on("failed to add (overridden) [%(sourceCheckout)s] to registry"). 152 » » » » » » return errors.Annotate(err, "fai led to add (overridden) [%s] to registry", sc).Err()
155 » » » » » » » D("sourceCheckout", sc). Err()
156 } 153 }
157 } 154 }
158 } 155 }
159 156
160 groupSrcs[i] = &sc 157 groupSrcs[i] = &sc
161 scs = append(scs, &sc) 158 scs = append(scs, &sc)
162 } 159 }
163 160
164 sgSources[sgKey] = groupSrcs 161 sgSources[sgKey] = groupSrcs
165 } 162 }
166 if err := reg.checkout(w); err != nil { 163 if err := reg.checkout(w); err != nil {
167 » » return errors.Annotate(err).Reason("failed to checkout sources") .Err() 164 » » return errors.Annotate(err, "failed to checkout sources").Err()
168 } 165 }
169 166
170 // Execute each source checkout in parallel. 167 // Execute each source checkout in parallel.
171 sourcesDir, err := checkoutDir.EnsureDirectory("sources") 168 sourcesDir, err := checkoutDir.EnsureDirectory("sources")
172 if err != nil { 169 if err != nil {
173 » » return errors.Annotate(err).Reason("failed to create sources dir ectory").Err() 170 » » return errors.Annotate(err, "failed to create sources directory" ).Err()
174 } 171 }
175 172
176 err = w.RunMulti(func(workC chan<- func() error) { 173 err = w.RunMulti(func(workC chan<- func() error) {
177 for _, sc := range scs { 174 for _, sc := range scs {
178 sc := sc 175 sc := sc
179 workC <- func() error { 176 workC <- func() error {
180 root, err := sourcesDir.EnsureDirectory(sc.group , sc.name) 177 root, err := sourcesDir.EnsureDirectory(sc.group , sc.name)
181 if err != nil { 178 if err != nil {
182 » » » » » return errors.Annotate(err).Reason("fail ed to create checkout directory").Err() 179 » » » » » return errors.Annotate(err, "failed to c reate checkout directory").Err()
183 } 180 }
184 181
185 if err := sc.checkout(w, root); err != nil { 182 if err := sc.checkout(w, root); err != nil {
186 » » » » » return errors.Annotate(err).Reason("fail ed to checkout %(sourceCheckout)s"). 183 » » » » » return errors.Annotate(err, "failed to c heckout %s", sc).Err()
187 » » » » » » D("sourceCheckout", sc).Err()
188 } 184 }
189 return nil 185 return nil
190 } 186 }
191 } 187 }
192 }) 188 })
193 if err != nil { 189 if err != nil {
194 return err 190 return err
195 } 191 }
196 192
197 // Build our source groups' checkout revision hashes. 193 // Build our source groups' checkout revision hashes.
198 for _, sgKey := range sgKeys { 194 for _, sgKey := range sgKeys {
199 sg := frozen.SourceGroup[sgKey] 195 sg := frozen.SourceGroup[sgKey]
200 if sg.RevisionHash != "" { 196 if sg.RevisionHash != "" {
201 // Already calculated. 197 // Already calculated.
202 continue 198 continue
203 } 199 }
204 200
205 hash := sha256.New() 201 hash := sha256.New()
206 for _, sc := range sgSources[sgKey] { 202 for _, sc := range sgSources[sgKey] {
207 if sc.Revision == "" { 203 if sc.Revision == "" {
208 » » » » return errors.Reason("source %(sourceCheckout)q has an empty revision"). 204 » » » » return errors.Reason("source %q has an empty rev ision", sc).Err()
209 » » » » » D("sourceCheckout", sc.String()).Err()
210 } 205 }
211 fmt.Fprintf(hash, "%s@%s\x00", sc.name, sc.Revision) 206 fmt.Fprintf(hash, "%s@%s\x00", sc.name, sc.Revision)
212 207
213 // If any of our sources was determined to be tainted, t aint the source 208 // If any of our sources was determined to be tainted, t aint the source
214 // group too. 209 // group too.
215 if sc.cs.tainted || sc.Source.Tainted { 210 if sc.cs.tainted || sc.Source.Tainted {
216 sg.Tainted = true 211 sg.Tainted = true
217 } 212 }
218 } 213 }
219 214
220 sg.RevisionHash = hex.EncodeToString(hash.Sum(nil)) 215 sg.RevisionHash = hex.EncodeToString(hash.Sum(nil))
221 log.Fields{ 216 log.Fields{
222 "sourceGroup": sgKey, 217 "sourceGroup": sgKey,
223 "revision": sg.RevisionHash, 218 "revision": sg.RevisionHash,
224 "tainted": sg.Tainted, 219 "tainted": sg.Tainted,
225 }.Debugf(w, "Checked out source group.") 220 }.Debugf(w, "Checked out source group.")
226 } 221 }
227 222
228 // Create the frozen checkout file. 223 // Create the frozen checkout file.
229 frozenFile := checkoutDir.File(frozenCheckoutName) 224 frozenFile := checkoutDir.File(frozenCheckoutName)
230 if err := frozenFile.GenerateTextProto(w, frozen); err != nil { 225 if err := frozenFile.GenerateTextProto(w, frozen); err != nil {
231 » » return errors.Annotate(err).Reason("failed to create frozen chec kout protobuf").Err() 226 » » return errors.Annotate(err, "failed to create frozen checkout pr otobuf").Err()
232 } 227 }
233 228
234 if err := checkoutDir.CleanUp(); err != nil { 229 if err := checkoutDir.CleanUp(); err != nil {
235 » » return errors.Annotate(err).Reason("failed to do full cleanup of cleanup sources filesystem").Err() 230 » » return errors.Annotate(err, "failed to do full cleanup of cleanu p sources filesystem").Err()
236 } 231 }
237 232
238 return nil 233 return nil
239 } 234 }
240 235
241 func checkoutFrozen(l *deployLayout) (*deploy.FrozenLayout, error) { 236 func checkoutFrozen(l *deployLayout) (*deploy.FrozenLayout, error) {
242 path := filepath.Join(l.WorkingPath, checkoutsSubdir, frozenCheckoutName ) 237 path := filepath.Join(l.WorkingPath, checkoutsSubdir, frozenCheckoutName )
243 238
244 var frozen deploy.FrozenLayout 239 var frozen deploy.FrozenLayout
245 if err := unmarshalTextProtobuf(path, &frozen); err != nil { 240 if err := unmarshalTextProtobuf(path, &frozen); err != nil {
246 » » return nil, errors.Annotate(err).Err() 241 » » return nil, errors.Annotate(err, "").Err()
247 } 242 }
248 return &frozen, nil 243 return &frozen, nil
249 } 244 }
250 245
251 // sourceCheckout manages the operation of checking out the specified layout 246 // sourceCheckout manages the operation of checking out the specified layout
252 // source. 247 // source.
253 type sourceCheckout struct { 248 type sourceCheckout struct {
254 *deploy.FrozenLayout_Source 249 *deploy.FrozenLayout_Source
255 250
256 // group is the name of the source group. 251 // group is the name of the source group.
(...skipping 13 matching lines...) Expand all
270 return fmt.Sprintf("%s.%s", sc.group, sc.name) 265 return fmt.Sprintf("%s.%s", sc.group, sc.name)
271 } 266 }
272 267
273 func (sc *sourceCheckout) addRegistryRepos(reg *checkoutRegistry) error { 268 func (sc *sourceCheckout) addRegistryRepos(reg *checkoutRegistry) error {
274 switch t := sc.Source.GetSource().(type) { 269 switch t := sc.Source.GetSource().(type) {
275 case *deploy.Source_Git: 270 case *deploy.Source_Git:
276 g := t.Git 271 g := t.Git
277 272
278 u, err := url.Parse(g.Url) 273 u, err := url.Parse(g.Url)
279 if err != nil { 274 if err != nil {
280 » » » return errors.Annotate(err).Reason("failed to parse Git URL [%(url)s]").D("url", g.Url).Err() 275 » » » return errors.Annotate(err, "failed to parse Git URL [%s ]", g.Url).Err()
281 } 276 }
282 277
283 // Add a Git checkout operation for this source to the registry. 278 // Add a Git checkout operation for this source to the registry.
284 sc.cs = reg.add(&gitCheckoutOperation{ 279 sc.cs = reg.add(&gitCheckoutOperation{
285 url: u, 280 url: u,
286 ref: g.Ref, 281 ref: g.Ref,
287 }, sc.Source.RunScripts) 282 }, sc.Source.RunScripts)
288 sc.overrideURL = g.Url 283 sc.overrideURL = g.Url
289 } 284 }
290 285
291 return nil 286 return nil
292 } 287 }
293 288
294 func (sc *sourceCheckout) checkout(w *work, root *managedfs.Dir) error { 289 func (sc *sourceCheckout) checkout(w *work, root *managedfs.Dir) error {
295 checkoutPath := root.File("c") 290 checkoutPath := root.File("c")
296 291
297 switch t := sc.Source.GetSource().(type) { 292 switch t := sc.Source.GetSource().(type) {
298 case *deploy.Source_Git: 293 case *deploy.Source_Git:
299 if sc.cs.path == "" { 294 if sc.cs.path == "" {
300 panic("registry repo path is not set") 295 panic("registry repo path is not set")
301 } 296 }
302 297
303 // Add a symlink between our raw checkout and our current checko ut. 298 // Add a symlink between our raw checkout and our current checko ut.
304 if err := checkoutPath.SymlinkFrom(sc.cs.path, true); err != nil { 299 if err := checkoutPath.SymlinkFrom(sc.cs.path, true); err != nil {
305 » » » return errors.Annotate(err).Err() 300 » » » return errors.Annotate(err, "").Err()
306 } 301 }
307 sc.Relpath = checkoutPath.RelPath() 302 sc.Relpath = checkoutPath.RelPath()
308 303
309 default: 304 default:
310 » » return errors.Reason("don't know how to checkout %(type)T").D("t ype", t).Err() 305 » » return errors.Reason("don't know how to checkout %T", t).Err()
311 } 306 }
312 307
313 sc.Revision = sc.cs.revision 308 sc.Revision = sc.cs.revision
314 sc.MajorVersion = sc.cs.majorVersion 309 sc.MajorVersion = sc.cs.majorVersion
315 sc.MinorVersion = sc.cs.minorVersion 310 sc.MinorVersion = sc.cs.minorVersion
316 sc.InitResult = &deploy.SourceInitResult{ 311 sc.InitResult = &deploy.SourceInitResult{
317 GoPath: append(sc.Source.GoPath, sc.cs.sir.GoPath...), 312 GoPath: append(sc.Source.GoPath, sc.cs.sir.GoPath...),
318 } 313 }
319 return nil 314 return nil
320 } 315 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 for _, key := range opKeys { 388 for _, key := range opKeys {
394 key, cs := key, reg.singletons[key] 389 key, cs := key, reg.singletons[key]
395 workC <- func() error { 390 workC <- func() error {
396 // Generate the path of this checkout. We do thi s by hashing the checkout's 391 // Generate the path of this checkout. We do thi s by hashing the checkout's
397 // key. 392 // key.
398 pathHash := sha256.Sum256([]byte(key)) 393 pathHash := sha256.Sum256([]byte(key))
399 394
400 // Perform the actual checkout operation. 395 // Perform the actual checkout operation.
401 checkoutDir, err := reg.repoDir.EnsureDirectory( hex.EncodeToString(pathHash[:])) 396 checkoutDir, err := reg.repoDir.EnsureDirectory( hex.EncodeToString(pathHash[:]))
402 if err != nil { 397 if err != nil {
403 » » » » » return errors.Annotate(err).Reason("fail ed to create checkout directory for %(key)q").D("key", key).Err() 398 » » » » » return errors.Annotate(err, "failed to c reate checkout directory for %q", key).Err()
404 } 399 }
405 400
406 log.Fields{ 401 log.Fields{
407 "key": key, 402 "key": key,
408 "checkoutPath": checkoutDir, 403 "checkoutPath": checkoutDir,
409 }.Debugf(w, "Creating checkout directory.") 404 }.Debugf(w, "Creating checkout directory.")
410 if err := cs.op.checkout(w, cs, checkoutDir); er r != nil { 405 if err := cs.op.checkout(w, cs, checkoutDir); er r != nil {
411 return err 406 return err
412 } 407 }
413 408
414 // Make sure "checkout" did what it was supposed to. 409 // Make sure "checkout" did what it was supposed to.
415 if cs.path == "" { 410 if cs.path == "" {
416 return errors.New("checkout did not popu late path") 411 return errors.New("checkout did not popu late path")
417 } 412 }
418 413
419 // If there is a deployment configuration, load/ parse/execute it. 414 // If there is a deployment configuration, load/ parse/execute it.
420 sl, err := loadSourceLayout(cs.path) 415 sl, err := loadSourceLayout(cs.path)
421 if err != nil { 416 if err != nil {
422 » » » » » return errors.Annotate(err).Reason("fail ed to load source layout").Err() 417 » » » » » return errors.Annotate(err, "failed to l oad source layout").Err()
423 } 418 }
424 419
425 var sir deploy.SourceInitResult 420 var sir deploy.SourceInitResult
426 if sl != nil { 421 if sl != nil {
427 sir.GoPath = sl.GoPath 422 sir.GoPath = sl.GoPath
428 423
429 if len(sl.Init) > 0 { 424 if len(sl.Init) > 0 {
430 if cs.runInit { 425 if cs.runInit {
431 for i, in := range sl.In it { 426 for i, in := range sl.In it {
432 inResult, err := sourceInit(w, cs.path, in) 427 inResult, err := sourceInit(w, cs.path, in)
433 if err != nil { 428 if err != nil {
434 » » » » » » » » » return e rrors.Annotate(err).Reason("failed to run source init #%(index)d"). 429 » » » » » » » » » return e rrors.Annotate(err, "failed to run source init #%d", i).Err()
435 » » » » » » » » » » D("index", i).Err()
436 } 430 }
437 431
438 // Merge this So urceInitResult into the common repository 432 // Merge this So urceInitResult into the common repository
439 // result. 433 // result.
440 sir.GoPath = app end(sir.GoPath, inResult.GoPath...) 434 sir.GoPath = app end(sir.GoPath, inResult.GoPath...)
441 } 435 }
442 } else { 436 } else {
443 log.Fields{ 437 log.Fields{
444 "key": key, 438 "key": key,
445 "path": cs.path, 439 "path": cs.path,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 path = dir.String() 507 path = dir.String()
514 ref := g.ref 508 ref := g.ref
515 if ref == "" { 509 if ref == "" {
516 ref = "master" 510 ref = "master"
517 } 511 }
518 gitDir := filepath.Join(path, ".git") 512 gitDir := filepath.Join(path, ".git")
519 needsFetch, resetRef := true, "refs/deploytool/checkout" 513 needsFetch, resetRef := true, "refs/deploytool/checkout"
520 switch st, err := os.Stat(gitDir); { 514 switch st, err := os.Stat(gitDir); {
521 case err == nil: 515 case err == nil:
522 if !st.IsDir() { 516 if !st.IsDir() {
523 » » » » return errors.Reason("checkout Git path [%(path) s] exists, and is not a directory").D("path", gitDir).Err() 517 » » » » return errors.Reason("checkout Git path [%s] exi sts, and is not a directory", gitDir).Err()
524 } 518 }
525 519
526 case isNotExist(err): 520 case isNotExist(err):
527 // If the target directory doesn't exist, run "git clone ". 521 // If the target directory doesn't exist, run "git clone ".
528 log.Fields{ 522 log.Fields{
529 "source": g.url, 523 "source": g.url,
530 "destination": path, 524 "destination": path,
531 }.Infof(w, "No current checkout; cloning...") 525 }.Infof(w, "No current checkout; cloning...")
532 if err := git.clone(w, g.url.String(), path); err != nil { 526 if err := git.clone(w, g.url.String(), path); err != nil {
533 return err 527 return err
534 } 528 }
535 if err = git.exec(path, "update-ref", resetRef, ref).che ck(w); err != nil { 529 if err = git.exec(path, "update-ref", resetRef, ref).che ck(w); err != nil {
536 » » » » return errors.Annotate(err).Reason("failed to ch eckout %(ref)q from %(url)q").D("ref", ref).D("url", g.url).Err() 530 » » » » return errors.Annotate(err, "failed to checkout %q from %q", ref, g.url).Err()
537 } 531 }
538 needsFetch = false 532 needsFetch = false
539 533
540 default: 534 default:
541 » » » return errors.Annotate(err).Reason("failed to stat check out Git directory [%(dir)s]").D("dir", gitDir).Err() 535 » » » return errors.Annotate(err, "failed to stat checkout Git directory [%s]", gitDir).Err()
542 } 536 }
543 537
544 // Check out the desired commit/ref by resetting the repository. 538 // Check out the desired commit/ref by resetting the repository.
545 // 539 //
546 // Check if the referenced ref is a commit that is already prese nt in the 540 // Check if the referenced ref is a commit that is already prese nt in the
547 // repository. 541 // repository.
548 x := git.exec(path, "rev-parse", ref) 542 x := git.exec(path, "rev-parse", ref)
549 switch rc, err := x.run(w); { 543 switch rc, err := x.run(w); {
550 case err != nil: 544 case err != nil:
551 » » » return errors.Annotate(err).Reason("failed to check for commit %(ref)q").D("ref", ref).Err() 545 » » » return errors.Annotate(err, "failed to check for commit %q", ref).Err()
552 546
553 case rc == 0: 547 case rc == 0:
554 // If the ref resolved to itself, then it's a commit and it's already in the 548 // If the ref resolved to itself, then it's a commit and it's already in the
555 // repository, so no need to fetch. 549 // repository, so no need to fetch.
556 if strings.TrimSpace(x.stdout.String()) == ref { 550 if strings.TrimSpace(x.stdout.String()) == ref {
557 resetRef = ref 551 resetRef = ref
558 needsFetch = false 552 needsFetch = false
559 } 553 }
560 fallthrough 554 fallthrough
561 555
562 default: 556 default:
563 // If our checkout isn't ready, fetch the ref remotely. 557 // If our checkout isn't ready, fetch the ref remotely.
564 if needsFetch { 558 if needsFetch {
565 if err := git.exec(path, "fetch", "origin", fmt. Sprintf("%s:%s", ref, resetRef)).check(w); err != nil { 559 if err := git.exec(path, "fetch", "origin", fmt. Sprintf("%s:%s", ref, resetRef)).check(w); err != nil {
566 » » » » » return errors.Annotate(err).Reason("fail ed to fetch %(ref)q from remote").D("ref", ref).Err() 560 » » » » » return errors.Annotate(err, "failed to f etch %q from remote", ref).Err()
567 } 561 }
568 } 562 }
569 563
570 // Reset to "resetRef". 564 // Reset to "resetRef".
571 if err := git.exec(path, "reset", "--hard", resetRef).ch eck(w); err != nil { 565 if err := git.exec(path, "reset", "--hard", resetRef).ch eck(w); err != nil {
572 » » » » return errors.Annotate(err).Reason("failed to ch eckout %(ref)q (%(localRef)q) from %(url)q"). 566 » » » » return errors.Annotate(err, "failed to checkout %q (%q) from %q", ref, resetRef, g.url).Err()
573 » » » » » D("ref", ref).D("localRef", resetRef).D( "url", g.url).Err()
574 } 567 }
575 } 568 }
576 } 569 }
577 570
578 // Get the current Git repository parameters. 571 // Get the current Git repository parameters.
579 var ( 572 var (
580 revision, mergeBase string 573 revision, mergeBase string
581 revCount int 574 revCount int
582 ) 575 )
583 err = w.RunMulti(func(workC chan<- func() error) { 576 err = w.RunMulti(func(workC chan<- func() error) {
584 // Get HEAD revision. 577 // Get HEAD revision.
585 workC <- func() (err error) { 578 workC <- func() (err error) {
586 revision, err = git.getHEAD(w, path) 579 revision, err = git.getHEAD(w, path)
587 return 580 return
588 } 581 }
589 582
590 // Get merge base revision. 583 // Get merge base revision.
591 workC <- func() (err error) { 584 workC <- func() (err error) {
592 mergeBase, err = git.getMergeBase(w, path, "origin/maste r") 585 mergeBase, err = git.getMergeBase(w, path, "origin/maste r")
593 return 586 return
594 } 587 }
595 588
596 // Get commit depth. 589 // Get commit depth.
597 workC <- func() (err error) { 590 workC <- func() (err error) {
598 revCount, err = git.getRevListCount(w, path) 591 revCount, err = git.getRevListCount(w, path)
599 return 592 return
600 } 593 }
601 }) 594 })
602 if err != nil { 595 if err != nil {
603 » » return errors.Annotate(err).Reason("failed to get Git repository properties").Err() 596 » » return errors.Annotate(err, "failed to get Git repository proper ties").Err()
604 } 597 }
605 598
606 // We're tainted if our merge base doesn't equal our current revision. 599 // We're tainted if our merge base doesn't equal our current revision.
607 if mergeBase != revision { 600 if mergeBase != revision {
608 cs.tainted = true 601 cs.tainted = true
609 } 602 }
610 603
611 log.Fields{ 604 log.Fields{
612 "url": g.url, 605 "url": g.url,
613 "ref": g.ref, 606 "ref": g.ref,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 return nil, err 645 return nil, err
653 } 646 }
654 647
655 // Create a temporary directory for the SourceInitResult. 648 // Create a temporary directory for the SourceInitResult.
656 var r deploy.SourceInitResult 649 var r deploy.SourceInitResult
657 err = withTempDir(func(tdir string) error { 650 err = withTempDir(func(tdir string) error {
658 resultPath := filepath.Join(tdir, "source_init_result.cf g") 651 resultPath := filepath.Join(tdir, "source_init_result.cf g")
659 652
660 scriptPath := deployToNative(path, ps.Path) 653 scriptPath := deployToNative(path, ps.Path)
661 if err := python.exec(scriptPath, path, resultPath).cwd( path).check(w); err != nil { 654 if err := python.exec(scriptPath, path, resultPath).cwd( path).check(w); err != nil {
662 » » » » return errors.Annotate(err).Reason("failed to ex ecute [%(scriptPath)s]").D("scriptPath", scriptPath).Err() 655 » » » » return errors.Annotate(err, "failed to execute [ %s]", scriptPath).Err()
663 } 656 }
664 657
665 switch err := unmarshalTextProtobuf(resultPath, &r); { 658 switch err := unmarshalTextProtobuf(resultPath, &r); {
666 case err == nil, isNotExist(err): 659 case err == nil, isNotExist(err):
667 return nil 660 return nil
668 661
669 default: 662 default:
670 » » » » return errors.Annotate(err).Reason("failed to st at SourceInitResult [%(resultPath)s]"). 663 » » » » return errors.Annotate(err, "failed to stat Sour ceInitResult [%s]", resultPath).Err()
671 » » » » » D("resultPath", resultPath).Err()
672 } 664 }
673 }) 665 })
674 return &r, err 666 return &r, err
675 667
676 default: 668 default:
677 » » return nil, errors.Reason("unknown source init type %(type)T").D ("type", t).Err() 669 » » return nil, errors.Reason("unknown source init type %T", t).Err( )
678 } 670 }
679 } 671 }
OLDNEW
« no previous file with comments | « deploytool/cmd/luci_deploy/build.go ('k') | deploytool/cmd/luci_deploy/config.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698