Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
twavv committed May 3, 2023
1 parent 8e9b71f commit 253fb67
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 121 deletions.
12 changes: 4 additions & 8 deletions cmd/av/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package main

import (
"context"
"github.com/aviator-co/av/internal/utils/cleanup"
"github.com/sirupsen/logrus"
"io/ioutil"
"os"
"strings"
Expand Down Expand Up @@ -62,12 +60,7 @@ Examples:
return err
}
tx := db.WriteTx()
var cu cleanup.Cleanup
defer cu.Cleanup()
cu.Add(func() {
logrus.WithError(reterr).Debug("aborting db transaction")
tx.Abort()
})
defer tx.Abort()

body := prCreateFlags.Body
// Special case: ready body from stdin
Expand Down Expand Up @@ -97,6 +90,9 @@ Examples:
); err != nil {
return err
}
if err := tx.Commit(); err != nil {
return err
}
return nil
},
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/av/stack_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/aviator-co/av/internal/utils/cleanup"
"golang.org/x/exp/slices"
"io/ioutil"
"os"
Expand Down Expand Up @@ -113,8 +112,7 @@ base branch.
return err
}
tx := db.WriteTx()
cu := cleanup.New(func() { tx.Abort() })
defer cu.Cleanup()
defer tx.Abort()

// Read any preexisting state.
// This is required to allow us to handle --continue/--abort
Expand Down
8 changes: 5 additions & 3 deletions cmd/av/stack_tidy.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"github.com/aviator-co/av/internal/utils/cleanup"
"strings"

"github.com/aviator-co/av/internal/git"
Expand Down Expand Up @@ -30,8 +29,7 @@ operates on only av's internal metadata, and it won't delete the actual Git bran
return err
}
tx := db.WriteTx()
cu := cleanup.New(func() { tx.Abort() })
defer cu.Cleanup()
defer tx.Abort()
origBranches := tx.AllBranches()
branches := make(map[string]*meta.Branch)
for name, br := range origBranches {
Expand Down Expand Up @@ -60,6 +58,10 @@ operates on only av's internal metadata, and it won't delete the actual Git bran
}
tx.SetBranch(*br)
}

if err := tx.Commit(); err != nil {
return err
}
return nil
},
}
Expand Down
5 changes: 1 addition & 4 deletions cmd/av/stack_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"github.com/aviator-co/av/internal/utils/cleanup"
"strings"

"github.com/aviator-co/av/internal/git"
Expand All @@ -24,9 +23,7 @@ var stackTreeCmd = &cobra.Command{
if err != nil {
return err
}
tx := db.WriteTx()
cu := cleanup.New(func() { tx.Abort() })
defer cu.Cleanup()
tx := db.ReadTx()

defaultBranch, err := repo.DefaultBranch()
if err != nil {
Expand Down
65 changes: 0 additions & 65 deletions internal/meta/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,68 +147,3 @@ func Trunk(tx ReadTx, name string) (string, bool) {
}
return "", false
}

//func FindStackRoot(branches map[string]Branch, name string) (Branch, bool) {
// branchMeta, ok := branches[name]
// if !ok {
// return Branch{}, false
// }
// if branchMeta.Parent.Trunk {
// return branchMeta, true
// }
// return FindStackRoot(branches, branchMeta.Parent.Name)
//}

//// WriteBranch writes branch metadata to the git repository.
//// It can be loaded again with ReadBranch.
//func WriteBranch(repo *git.Repo, s Branch) error {
// // Assert a few invariants here
// // These should be checked by the caller before calling WriteBranch, but
// // we want to be extra safe to avoid getting into an inconsistent state.
// if s.Name == "" {
// return errors.New("cannot write branch metadata: branch name is empty")
// }
//
// if s.Parent.Name == s.Name {
// return errors.New("cannot write branch metadata: parent branch is the same as the branch itself")
// }
//
// if s.Parent.Trunk && s.Parent.Head != "" {
// return errors.New("invariant error: cannot write branch metadata: parent branch is a trunk branch and has a head commit assigned")
// } else if !s.Parent.Trunk && s.Parent.Head == "" {
// return errors.New("invariant error: cannot write branch metadata: parent branch is not a trunk branch and has no head commit assigned")
// }
//
// if slices.Contains(s.Children, s.Name) {
// return errors.New("cannot write branch metadata: branch is a child of itself")
// }
//
// refName := branchMetaRefName(s.Name)
// content, err := json.Marshal(s)
// if err != nil {
// return errors.Wrap(err, "failed to marshal stack metadata")
// }
// objectId, err := repo.GitStdin(
// []string{"hash-object", "-w", "--stdin"},
// bytes.NewReader(content),
// )
// if err != nil {
// return errors.Wrap(err, "failed to store stack metadata in git")
// }
// if err := repo.UpdateRef(&git.UpdateRef{Ref: refName, New: objectId}); err != nil {
// return err
// }
// logrus.
// WithFields(logrus.Fields{"ref": refName, "sha": git.ShortSha(objectId)}).
// Debug("created stack ref")
// return nil
//}
//
//func DeleteBranch(repo *git.Repo, name string) error {
// refName := branchMetaRefName(name)
// if err := repo.UpdateRef(&git.UpdateRef{Ref: refName, New: git.Missing}); err != nil {
// return err
// }
// logrus.WithField("ref", refName).Debug("deleted branch metadata")
// return nil
//}
38 changes: 0 additions & 38 deletions internal/meta/branchstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,6 @@ type BranchState struct {
Head string `json:"head,omitempty"`
}

//// BaseCommit determines the base commit for the given branch.
//// The base commit is defined as the latest commit on the branch that should not
//// be considered one of the critical commits on the stacked branch itself.
//// This is essentially the merge-base of the branch and its parent and should be
//// used as the `<upstream>` in the `git rebase --onto <parent-branch> <upstream>`
//// command.
//func (b *Branch) BaseCommit(r *git.Repo) (string, error) {
// // For non-root stacked branches, we always store the head commit in the
// // metadata.
// if b.Parent.Head != "" {
// return b.Parent.Head, nil
// }
//
// // Otherwise, this branch is a stack root (and the parent is a trunk branch)
// // so we just need to determine the merge base. The critical assumption here
// // is that commits in trunk branches are never modified (i.e., rebased).
// if !b.Parent.Trunk {
// // COMPAT:
// // This shouldn't happen for any branch created after this commit is
// // introduced, but we don't want to completely barf for branches that
// // were already created.
// logrus.Warnf(
// "invariant error: corrupt stack metadata: "+
// "branch %q parent %q should have (head XOR trunk) set "+
// "(this may result in incorrect rebases)",
// b.Name, b.Parent.Name,
// )
// }
//
// base, err := r.MergeBase(&git.MergeBase{
// Revs: []string{b.Name, b.Parent.Name},
// })
// if err != nil {
// return "", errors.WrapIff(err, "failed to determine merge base for branch %q and %q", b.Name, b.Parent.Name)
// }
// return base, nil
//}

// unmarshalBranchState unmarshals a BranchState from JSON (which can either be
// a string value or a JSON object).
func unmarshalBranchState(data []byte) (BranchState, error) {
Expand Down

0 comments on commit 253fb67

Please sign in to comment.