-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Import existing branch metadata from ref storage (#95)
Per title. Also fixed a forgotten `tx.Commit` in `stack tidy` as well as added a line of output to that command.
- Loading branch information
Showing
39 changed files
with
1,036 additions
and
588 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"emperror.dev/errors" | ||
"github.com/aviator-co/av/internal/git" | ||
"github.com/aviator-co/av/internal/meta" | ||
"github.com/aviator-co/av/internal/meta/jsonfiledb" | ||
"github.com/aviator-co/av/internal/meta/refmeta" | ||
"github.com/sirupsen/logrus" | ||
"os" | ||
"os/exec" | ||
"path" | ||
"strings" | ||
) | ||
|
||
func getRepoInfo() (*git.Repo, meta.Repository, error) { | ||
repo, err := getRepo() | ||
if err != nil { | ||
return nil, meta.Repository{}, err | ||
var cachedRepo *git.Repo | ||
|
||
func getRepo() (*git.Repo, error) { | ||
if cachedRepo == nil { | ||
cmd := exec.Command("git", "rev-parse", "--show-toplevel") | ||
if rootFlags.Directory != "" { | ||
cmd.Dir = rootFlags.Directory | ||
} | ||
toplevel, err := cmd.Output() | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to determine repo toplevel (are you running inside a Git repo?)") | ||
} | ||
cachedRepo, err = git.OpenRepo(strings.TrimSpace(string(toplevel))) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to open git repo") | ||
} | ||
} | ||
return cachedRepo, nil | ||
} | ||
|
||
repoMeta, err := meta.ReadRepository(repo) | ||
func getDB(repo *git.Repo) (meta.DB, error) { | ||
dbPath := path.Join(repo.GitDir(), "av", "av.db") | ||
existingStat, _ := os.Stat(dbPath) | ||
db, err := jsonfiledb.OpenPath(dbPath) | ||
if err != nil { | ||
return nil, meta.Repository{}, err | ||
return nil, err | ||
} | ||
|
||
logrus.Debugf("loaded repository metadata: %+v", repoMeta) | ||
return repo, repoMeta, nil | ||
if existingStat == nil { | ||
logrus.Debug("Initializing new av database") | ||
if err := refmeta.Import(repo, db); err != nil { | ||
return nil, errors.WrapIff(err, "failed to import ref metadata into av database") | ||
} | ||
} | ||
return db, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.