gunk-dev/the-valley

rebase.go

source68d12192bbd3main's published tip history
21.7 KiB
1// valley rebase: a change's whole stack, rebased onto main.
2//
3// `valley rebase <change>` and review's [b]ase run it. The stack is what
4// valley stack lists (stack.go): the change, and the chain of layers
5// under it, each on the one below. A change with nothing under it is a
6// stack of one, and is rebased the same way.
7//
8// The rebase engine (../rebase) does the work. It captures the chain from
9// one snapshot of origin, refuses a stack it cannot move whole and changes
10// nothing, rebases every layer in one throwaway worktree, bottom first,
11// and publishes in two phases: one atomic push of every layer's branch,
12// leased on the tips it read, and then, bottom first, each change's
13// rebased head added to its record as a new version, as
14// ready --if-active adds one. This verb words what the engine reports. It
15// refuses a stack that holds a change when git config valley.principal
16// names no one, since phase 2 writes each record as that principal.
17//
18// A stack prints a manifest at the end: each layer's old and new head,
19// whether its branch moved, whether a version was added, and the exact
20// valley ready command that finishes each layer left unfinished. A change
21// alone prints what rebase has always printed.
22//
23// An interrupt or a SIGTERM while the stack is rebased cancels the
24// rebase: the engine kills git and anything git started, such as a hook,
25// and removes its worktree and its refs. Nothing is pushed, and the verb
26// exits 130. Review's [b]ase is cancelled by an interrupt alone, and
27// review acts on a SIGTERM once the rebase has ended (review.go).
28
29package main
30
31import (
32 "context"
33 "errors"
34 "fmt"
35 "io"
36 "os"
37 "os/signal"
38 "strings"
39 "sync/atomic"
40 "syscall"
41
42 "the-valley/change"
43 "the-valley/rebase"
44)
45
46const rebaseUsage = "usage: valley rebase [--known-signers <file>] [--integrator-name <name>] <change>"
47
48// What became of a layer's branch in the push.
49const (
50 pushNot = "not pushed"
51 pushDone = "pushed"
52 pushUnknown = "may have moved"
53)
54
55// errReported is a failure whose words are printed already.
56var errReported = errors.New("reported")
57
58// errInterrupted is a rebase a signal cancelled. It prints nothing, and
59// exits 130.
60var errInterrupted = errors.New("interrupted")
61
62// layer is one line of the manifest: a layer of the stack, and what became
63// of it.
64type layer struct {
65 name string // a change's handle, or a branch's name
66 id string // a change's ID; "" for a plain branch
67 branch string // the branch the rebase pushes
68 head string // the head rebased
69 rebased string // its rebased head
70 pushed string // what became of its branch: pushNot, pushDone or pushUnknown
71 added int // the version phase 2 added, or 0
72}
73
74// rebaseRun is one rebase of a stack.
75type rebaseRun struct {
76 g git
77 s *snapshot
78 f *rebase.Family
79 given string // the name the change was given by
80 stdout, stderr io.Writer
81 signals []os.Signal // what cancels the rebase
82}
83
84// top is the change the stack is under, the last of its layers.
85func (r *rebaseRun) top() *rebase.Layer { return r.f.Start }
86func (r *rebaseRun) single() bool { return len(r.f.Layers) == 1 }
87
88// index is a layer's place in the stack, from 0 at the bottom.
89func (r *rebaseRun) index(l *rebase.Layer) int {
90 for k, m := range r.f.Layers {
91 if m == l {
92 return k
93 }
94 }
95 return -1
96}
97
98// place is where a layer sits, for a refusal that names it: nothing for a
99// change alone, and otherwise ", layer <k> of <n> under <top>,".
100func (r *rebaseRun) place(l *rebase.Layer) string {
101 if r.single() {
102 return ""
103 }
104 return fmt.Sprintf(", layer %d of %d under %s,", r.index(l)+1, len(r.f.Layers), r.top().Name)
105}
106
107// rebaseCommandArgs is what `valley rebase` passes to the verb: the
108// signer flags, as given, and then the change's name. It takes one name,
109// and no flag but the signer flags. --head is review's alone: its [b]ase
110// names the head it showed.
111func rebaseCommandArgs(args []string) ([]string, error) {
112 var verify []string
113 name := ""
114 for i := 0; i < len(args); i++ {
115 switch a := args[i]; {
116 case a == "--known-signers" || a == "--integrator-name":
117 if i+1 == len(args) {
118 return nil, failure(rebaseUsage)
119 }
120 verify = append(verify, a, args[i+1])
121 i++
122 case strings.HasPrefix(a, "--known-signers=") || strings.HasPrefix(a, "--integrator-name="):
123 verify = append(verify, a)
124 case strings.HasPrefix(a, "-"):
125 return nil, failure(rebaseUsage)
126 case name != "":
127 return nil, failure(rebaseUsage)
128 default:
129 name = a
130 }
131 }
132 if name == "" {
133 return nil, failure(rebaseUsage)
134 }
135 return append(verify, name), nil
136}
137
138func parseRebaseArgs(args []string) (name, want string, err error) {
139 var rest []string
140 for i := 0; i < len(args); i++ {
141 switch a := args[i]; {
142 case a == "--head" && i+1 < len(args):
143 want = args[i+1]
144 i++
145 case strings.HasPrefix(a, "--head="):
146 want = strings.TrimPrefix(a, "--head=")
147 case strings.HasPrefix(a, "-"):
148 return "", "", failure(rebaseUsage)
149 default:
150 rest = append(rest, a)
151 }
152 }
153 if len(rest) != 1 || (want != "" && !isObjectID(want)) {
154 return "", "", failure(rebaseUsage)
155 }
156 return rest[0], want, nil
157}
158
159// runRebase rebases the stack under the change named. --head is the head
160// the caller showed as the change's: the rebase refuses when the change
161// is at another head by now.
162func runRebase(g git, args []string, stdout, stderr io.Writer) int {
163 return rebaseCancelledBy(g, newVerifier(), args, stdout, stderr, os.Interrupt, syscall.SIGTERM)
164}
165
166// rebaseCancelledBy is runRebase, its reads verifying transfer statements
167// with v, cancelled by the signals given.
168func rebaseCancelledBy(g git, v verifier, args []string, stdout, stderr io.Writer, signals ...os.Signal) int {
169 err := rebaseStack(g, v, args, stdout, stderr, signals)
170 switch {
171 case err == nil:
172 return 0
173 case errors.Is(err, errInterrupted):
174 return 130
175 case !errors.Is(err, errReported):
176 fmt.Fprintf(stderr, "valley: %s\n", err)
177 }
178 return 1
179}
180
181func rebaseStack(g git, v verifier, args []string, stdout, stderr io.Writer, signals []os.Signal) error {
182 name, want, err := parseRebaseArgs(args)
183 if err != nil {
184 return err
185 }
186 if !g.succeeds(true, "rev-parse", "--git-dir") {
187 return failure("not a git repository")
188 }
189 res, err := resolveRecorded(g, name)
190 if err != nil {
191 return err
192 }
193 if res.id != "" && res.branch == "" {
194 return failure(fmt.Sprintf("change %s v%d records no branch, and rebase acts on a change's branch. Approve its head alone: valley approve --head %s %s",
195 res.handle, res.version, res.head, res.handle))
196 }
197 s, err := readSnapshot(g, v)
198 if err != nil {
199 return err
200 }
201 if s.tip == "" {
202 return failure("origin has no " + recordTarget + " to rebase onto")
203 }
204 f, err := rebase.Capture(s.land, rebase.Selection{ID: res.id, Branch: res.branch, Head: want})
205 if err != nil {
206 return err
207 }
208 r := &rebaseRun{g: g, s: s, f: f, given: name, stdout: stdout, stderr: stderr, signals: signals}
209 if err := f.Check(); err != nil {
210 return r.refused(err)
211 }
212 // review offers [b]ase only to a stack that is stale. One that
213 // fast-forwards already is left alone, rather than rewritten for
214 // nothing.
215 if top := r.top(); f.FastForwards() {
216 fmt.Fprintf(stdout, "%s already fast-forwards from origin/%s; nothing rebased\n head %s\n", top.Branch, recordTarget, top.Head)
217 return nil
218 }
219 principal, err := r.needPrincipal()
220 if err != nil {
221 return err
222 }
223 eg := g.engine()
224 eg.Stdout = stdout
225 p, err := r.prepare(eg)
226 if err != nil {
227 return err
228 }
229 defer p.Release(context.Background(), eg)
230 pub, err := rebase.Publish(context.Background(), eg, p)
231 if err != nil {
232 return r.refused(err)
233 }
234 return r.publish(eg, pub, principal)
235}
236
237// needPrincipal is the principal git config valley.principal names, and
238// refuses a stack that holds a change when it names no one: phase 2 writes
239// each change's record as that principal, and finding out there would
240// leave every branch moved and no version added.
241func (r *rebaseRun) needPrincipal() (string, error) {
242 changes := false
243 for _, l := range r.f.Layers {
244 changes = changes || l.ID != ""
245 }
246 p, err := r.g.output(true, "config", "valley.principal")
247 if !changes || err == nil && change.ValidPrincipal(p) {
248 return p, nil
249 }
250 what := fmt.Sprintf("rebasing change %s adds the rebased head to its record", r.top().Name)
251 if !r.single() {
252 what = fmt.Sprintf("rebasing the stack under %s adds each change's rebased head to its record", r.top().Name)
253 }
254 return "", failure(what + " as the principal your key pushes as, and git config valley.principal names none, so nothing is rebased; set it with git config valley.principal <name>")
255}
256
257// prepare has the engine rebase every layer, the user's checkout
258// untouched. An interrupt or a SIGTERM meanwhile cancels the rebase, and
259// once the engine has removed its worktree the run ends with
260// errInterrupted.
261func (r *rebaseRun) prepare(eg rebase.Git) (*rebase.Prepared, error) {
262 ctx, cancel := context.WithCancel(context.Background())
263 defer cancel()
264 interrupted := make(chan os.Signal, 1)
265 signal.Notify(interrupted, r.signals...)
266 defer signal.Stop(interrupted)
267 var signalled atomic.Bool
268 done := make(chan struct{})
269 defer close(done)
270 go func() {
271 select {
272 case <-interrupted:
273 signalled.Store(true)
274 cancel()
275 case <-done:
276 }
277 }()
278 p, err := rebase.Prepare(ctx, eg, r.f)
279 if signalled.Load() || errors.Is(err, context.Canceled) || errors.Is(err, rebase.ErrInterrupted) {
280 if p != nil {
281 p.Release(context.Background(), eg)
282 }
283 return nil, errInterrupted
284 }
285 if err != nil {
286 return nil, r.refused(err)
287 }
288 return p, nil
289}
290
291// refused words a refusal the engine gives as valley rebase has always
292// worded it: with the layer's place in the stack, and the command that
293// acts on it. Several are one line each.
294func (r *rebaseRun) refused(err error) error {
295 var many rebase.Refusals
296 if errors.As(err, &many) {
297 var words []string
298 for _, one := range many {
299 words = append(words, r.words(one))
300 }
301 return failure(strings.Join(words, "\nvalley: "))
302 }
303 var one *rebase.Refusal
304 if errors.As(err, &one) {
305 return failure(r.words(one))
306 }
307 return err
308}
309
310func (r *rebaseRun) words(x *rebase.Refusal) string {
311 l := x.Layer
312 switch x.Kind {
313 case rebase.NoBranch:
314 return fmt.Sprintf("change %s v%d%s records no branch, so the rebase has no branch to push it to; nothing rebased",
315 l.Name, l.Version, r.place(l))
316 case rebase.BranchMissing:
317 if r.single() {
318 return "no such branch on origin: " + l.Branch
319 }
320 return fmt.Sprintf("change %s v%d%s is on the branch %s, and origin has no such branch; nothing rebased",
321 l.Name, l.Version, r.place(l), l.Branch)
322 case rebase.NotReady:
323 return fmt.Sprintf("change %s v%d%s is %s, not ready; nothing rebased. Ready it first: %s",
324 l.Name, l.Version, r.place(l), l.Record.State, readyHint(l.ID, l.Branch))
325 case rebase.HeadMoved:
326 if l.ID == "" {
327 return fmt.Sprintf("origin/%s is at %s, and is no longer at %s, the head shown; nothing rebased", l.Branch, l.Head, x.Commit)
328 }
329 return fmt.Sprintf("change %s is at v%d, %s, and this run began at %s; nothing rebased. Review it again at its new head",
330 l.Name, l.Version, l.Head, versionAt(l, x.Commit))
331 case rebase.TipMoved:
332 return fmt.Sprintf("change %s v%d%s records the head %s, and origin/%s is at %s; nothing rebased. Ready the branch's head as a new version of %s to act on it: %s",
333 l.Name, l.Version, r.place(l), l.Head, l.Branch, l.Tip, l.Name, readyCommand(l.Tip, l.ID, l.Branch))
334 case rebase.BranchOfChange:
335 return fmt.Sprintf("change %s v%d records the head %s, and origin/%s%s is at %s; nothing rebased. Ready the branch's head as a new version of %s to act on it: %s",
336 x.Handle, x.Version.N, headOf(x.Version), l.Branch, r.place(l), l.Tip, x.Handle, readyCommand(l.Tip, x.Change.ID, l.Branch))
337 case rebase.SharedBranch:
338 return fmt.Sprintf("%s and %s, layers %d and %d of %d under %s, are both on the branch %s; nothing rebased",
339 x.Other.Name, l.Name, r.index(x.Other)+1, r.index(l)+1, len(r.f.Layers), r.top().Name, l.Branch)
340 case rebase.Conflict:
341 if r.single() {
342 return fmt.Sprintf("%s conflicts with main — resolve by hand; nothing changed", l.Branch)
343 }
344 return fmt.Sprintf("%s, layer %d of %d under %s, conflicts with %s — resolve by hand; nothing changed",
345 l.Name, r.index(l)+1, len(r.f.Layers), r.top().Name, x.Below)
346 case rebase.RecordNotReady:
347 v := x.Change.Record.ActiveVersion()
348 return fmt.Sprintf("change %s v%d%s is %s, not ready; nothing pushed. Ready it first: %s",
349 l.Name, v.N, r.place(l), x.Change.Record.State, readyHint(l.ID, v.Branch))
350 case rebase.RecordNewHead:
351 v := x.Change.Record.ActiveVersion()
352 return fmt.Sprintf("change %s%s is at v%d, %s, and this run began at v%d, %s; nothing pushed. Review it again at its new head",
353 l.Name, r.place(l), v.N, headOf(v), l.Version, l.Head)
354 case rebase.RecordChanged:
355 return fmt.Sprintf("the record of change %s%s changed while it was rebased; nothing pushed. Rebase it again: valley rebase %s",
356 l.Name, r.place(l), r.top().Name)
357 case rebase.BranchUnread:
358 return fmt.Sprintf("could not read %s again against origin's records; nothing pushed", strings.TrimSuffix(r.plainName(l), ","))
359 case rebase.BecameChange:
360 n, h, name := x.Change, x.Handle, r.plainName(l)
361 v := n.Record.ActiveVersion()
362 switch {
363 case n.Record.State != change.Ready:
364 return fmt.Sprintf("%s is now change %s v%d, which is %s, not ready; nothing pushed. Ready it first: %s",
365 name, h, v.N, n.Record.State, readyHint(n.ID, v.Branch))
366 case headOf(v) != l.Head:
367 return fmt.Sprintf("%s is now change %s v%d, which records the head %s, and this run began at %s; nothing pushed. Review it again by its handle",
368 name, h, v.N, headOf(v), l.Head)
369 }
370 return fmt.Sprintf("%s is now change %s v%d; nothing pushed. Rebase it again by its handle: valley rebase %s", name, h, v.N, h)
371 }
372 return x.Error()
373}
374
375// plainName is how a refusal names a plain branch of the stack: as it was
376// given, for a branch alone, and otherwise as origin's, with its place.
377func (r *rebaseRun) plainName(l *rebase.Layer) string {
378 if r.single() {
379 return r.given
380 }
381 return "origin/" + l.Branch + r.place(l)
382}
383
384// versionAt names a head of a change by its version too, when its record
385// has one there.
386func versionAt(l *rebase.Layer, head string) string {
387 for _, v := range l.Record.Versions {
388 if headOf(v) == head {
389 return fmt.Sprintf("v%d, %s", v.N, head)
390 }
391 }
392 return head
393}
394
395// publish says what became of the branch push, adds each change's version
396// when the branches moved, and says what became of each layer.
397func (r *rebaseRun) publish(eg rebase.Git, pub *rebase.Publication, principal string) error {
398 top := r.top()
399 switch pub.Push {
400 case rebase.Refused:
401 if r.single() {
402 return failure(fmt.Sprintf("lease on origin/%s failed (it moved since the fetch); nothing pushed", top.Branch))
403 }
404 r.writeManifest(pub)
405 var why []string
406 for _, ref := range pub.Refused {
407 why = append(why, "origin/"+strings.TrimPrefix(ref.Ref, "refs/heads/")+": "+ref.Why)
408 }
409 return failure(fmt.Sprintf("origin refused the push of the stack's branches, so none moved (%s); nothing pushed. Rebase the stack again: valley rebase %s",
410 strings.Join(why, "; "), top.Name))
411 case rebase.Unknown:
412 r.writeManifest(pub)
413 var refs []string
414 for _, l := range r.f.Layers {
415 refs = append(refs, shellQuote("refs/heads/"+l.Branch))
416 }
417 return failure("the push of the branches failed, and whether origin took it is not known. Check with git ls-remote origin " +
418 strings.Join(refs, " ") + ": a branch at its new head is pushed, and the command above finishes its change")
419 case rebase.Unpushed:
420 return failure("could not run the push of the branches; nothing pushed")
421 }
422 if r.single() {
423 fmt.Fprintf(r.stdout, "rebased %s onto origin/%s, pushed with --force-with-lease\n", top.Branch, recordTarget)
424 fmt.Fprintf(r.stdout, " head %s\n", pub.Result(top).Head)
425 }
426 r.addVersions(eg, pub, principal)
427 if !r.single() {
428 r.writeManifest(pub)
429 }
430 r.otherStacks()
431 n := len(unfinished(r.rows(pub)))
432 switch {
433 case n > 0 && r.single():
434 return errReported
435 case n == 1:
436 return failure(fmt.Sprintf("1 change of the stack under %s is unfinished; finish it with the command above", top.Name))
437 case n > 0:
438 return failure(fmt.Sprintf("%d changes of the stack under %s are unfinished; finish each with the command above", n, top.Name))
439 }
440 return nil
441}
442
443// addVersions is phase 2: bottom first, each change's rebased head is
444// added to its record as a new version, while the change is still ready
445// at the head the rebase began with. A change alone says what ready says,
446// as it always has.
447func (r *rebaseRun) addVersions(eg rebase.Git, pub *rebase.Publication, principal string) {
448 for _, res := range pub.Results {
449 l := res.Layer
450 if l.ID == "" {
451 continue
452 }
453 pub.Append(context.Background(), eg, principal, res)
454 if ap := res.Appended; ap.Err != nil {
455 fmt.Fprintf(r.stderr, "valley: %s\n", ap.Err)
456 if r.single() {
457 fmt.Fprintf(r.stderr, "valley: origin/%s is rebased to %s, and no version of %s records it. Ready it once the change is ready: %s\n",
458 l.Branch, res.Head, l.Name, readyCommand(res.Head, l.ID, l.Branch))
459 }
460 } else if r.single() {
461 fmt.Fprintf(r.stdout, "%s %s v%d ready\n", project(r.g), ap.Handle, ap.Version)
462 }
463 }
464}
465
466// rows is the manifest's line for each layer, bottom first.
467func (r *rebaseRun) rows(pub *rebase.Publication) []*layer {
468 var rows []*layer
469 for _, res := range pub.Results {
470 l := res.Layer
471 row := &layer{name: l.Name, id: l.ID, branch: l.Branch, head: l.Head, rebased: res.Head, pushed: pushNot}
472 switch res.Branch {
473 case rebase.Pushed:
474 row.pushed = pushDone
475 case rebase.Unknown:
476 row.pushed = pushUnknown
477 }
478 if res.Appended != nil {
479 row.added = res.Appended.Version
480 }
481 rows = append(rows, row)
482 }
483 return rows
484}
485
486// unfinished is each change layer whose branch may hold its rebased head
487// with no version recording it.
488func unfinished(layers []*layer) []*layer {
489 var left []*layer
490 for _, l := range layers {
491 if l.id != "" && l.pushed != pushNot && l.added == 0 {
492 left = append(left, l)
493 }
494 }
495 return left
496}
497
498func (r *rebaseRun) writeManifest(pub *rebase.Publication) {
499 io.WriteString(r.stdout, manifest(r.top().Name, r.rows(pub)))
500}
501
502// manifest is what the rebase did to each layer, bottom first, one line
503// each: its old and new head, what became of its branch, and for a change
504// whether a version was added. Then, for each change left unfinished, the
505// valley ready command that finishes it.
506func manifest(top string, layers []*layer) string {
507 var b strings.Builder
508 fmt.Fprintf(&b, "the stack under %s, bottom first:\n", top)
509 width := 0
510 for _, l := range layers {
511 width = max(width, columns(l.name))
512 }
513 for _, l := range layers {
514 rebased := "(not rebased)"
515 if l.rebased != "" {
516 rebased = short(l.rebased)
517 }
518 status := "origin/" + l.branch + " " + l.pushed
519 switch {
520 case l.id != "" && l.added > 0:
521 status += fmt.Sprintf(", v%d added", l.added)
522 case l.id != "":
523 status += ", no version added"
524 }
525 fmt.Fprintf(&b, " %s%s %s -> %s %s\n", l.name, strings.Repeat(" ", width-columns(l.name)), short(l.head), rebased, status)
526 }
527 for _, l := range unfinished(layers) {
528 fmt.Fprintf(&b, "to finish %s: %s\n", l.name, readyCommand(l.rebased, l.id, l.branch))
529 }
530 return b.String()
531}
532
533// otherStacks names each ready change and plain branch outside the stack
534// whose head contains a layer's old head, such as a second stack on a
535// lower layer. The rebase left it on that old head, and does not move it.
536func (r *rebaseRun) otherStacks() {
537 ids, branches := map[string]bool{}, map[string]bool{}
538 for _, l := range r.f.Layers {
539 ids[l.ID], branches[l.Branch] = true, true
540 }
541 on := func(head string) *rebase.Layer {
542 for k := len(r.f.Layers) - 1; k >= 0; k-- {
543 if l := r.f.Layers[k]; head == l.Head || r.s.reach(head)[l.Head] {
544 return l
545 }
546 }
547 return nil
548 }
549 for _, n := range r.s.all {
550 if ids[n.id] || n.record.State != change.Ready || !unlanded(r.s, n) {
551 continue
552 }
553 if l := on(headOf(n.record.ActiveVersion())); l != nil {
554 h := r.s.o.handle(n.id)
555 fmt.Fprintf(r.stdout, "%s is now on an old head of %s; rebase it with valley rebase %s\n", h, l.Name, h)
556 }
557 }
558 for _, b := range r.s.unrecorded() {
559 if l := on(b.Head); l != nil && !branches[b.Branch] {
560 fmt.Fprintf(r.stdout, "%s is now on an old head of %s; rebase it with valley rebase %s\n", branchName(b.Branch), l.Name, shellQuote(b.Branch))
561 }
562 }
563}
564
565// readyHint is the valley ready line that readies a change again, naming
566// the branch unless its version records none.
567func readyHint(id, branch string) string {
568 if branch == "" {
569 return "valley ready --change " + id
570 }
571 return "valley ready --change " + id + " " + shellQuote(branch)
572}
573
574// readyCommand is the valley ready line that adds head to a change's
575// record as a new version on branch.
576func readyCommand(head, id, branch string) string {
577 return "valley ready --head " + head + " --change " + id + " " + shellQuote(branch)
578}
579
580// bringsOf is the handle of each change that has not landed, other than
581// except, with a version head among the commits head would bring to
582// main: those it reaches and main does not, in the order of the changes'
583// IDs. approve refuses a head that does not fast-forward from main and
584// would bring one, since it is a layer of a stack that has to be rebased
585// first.
586func bringsOf(g git, v verifier, except, head string) ([]string, error) {
587 if !g.succeeds(true, "cat-file", "-e", head+"^{commit}") {
588 return nil, failure("no commit " + head + " here")
589 }
590 s, err := readSnapshot(g, v)
591 if err != nil {
592 return nil, err
593 }
594 if s.tip == "" {
595 return nil, failure("origin has no " + recordTarget + " to read against")
596 }
597 reach := s.reach(head)
598 var handles []string
599 for _, n := range s.all {
600 if n.id == except || !unlanded(s, n) {
601 continue
602 }
603 for _, v := range n.record.Versions {
604 if reach[headOf(v)] {
605 handles = append(handles, s.o.handle(n.id))
606 break
607 }
608 }
609 }
610 return handles, nil
611}