From a4562d2d5a35536771745b0aa19d705eb47234e7 Mon Sep 17 00:00:00 2001 From: Patrick DeVivo Date: Fri, 3 Jul 2020 15:59:58 -0400 Subject: [PATCH] initial commit :tada: --- .github/workflows/test.yml | 32 ++++ .vscode/settings.json | 11 ++ Makefile | 11 ++ README.md | 164 +++++++++++++++++++++ cmd/root.go | 268 ++++++++++++++++++++++++++++++++++ gitqlite.go | 9 ++ go.mod | 16 ++ go.sum | 227 ++++++++++++++++++++++++++++ pkg/gitqlite/git_log.go | 244 +++++++++++++++++++++++++++++++ pkg/gitqlite/git_ref.go | 129 ++++++++++++++++ pkg/gitqlite/git_tree.go | 228 +++++++++++++++++++++++++++++ pkg/gitqlite/gitqlite.go | 80 ++++++++++ pkg/gitqlite/gitqlite_test.go | 193 ++++++++++++++++++++++++ 13 files changed, 1612 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 .vscode/settings.json create mode 100644 Makefile create mode 100644 README.md create mode 100644 cmd/root.go create mode 100644 gitqlite.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 pkg/gitqlite/git_log.go create mode 100644 pkg/gitqlite/git_ref.go create mode 100644 pkg/gitqlite/git_tree.go create mode 100644 pkg/gitqlite/gitqlite.go create mode 100644 pkg/gitqlite/gitqlite_test.go diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..3a6e72ed --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,32 @@ +name: tests +on: [push] +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14.3 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + + - name: Vet + run: make vet + + - name: Test + run: make test + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v1 + with: + version: v1.26 + args: --build-tags sqlite_vtable diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..12134f86 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "go.buildFlags": [ + "-tags='sqlite_vtable'" + ], + "go.vetFlags": [ + "-tags='sqlite_vtable'" + ], + "go.toolsEnvVars": { + "GOFLAGS": "-tags='sqlite_vtable'" + } +} diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..a4d1c6c5 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +vet: + go vet -v -tags=sqlite_vtable ./... + +build: + go build -v -tags=sqlite_vtable gitqlite.go + +lint: + golangci-lint run --build-tags sqlite_vtable + +test: + go test -v -tags=sqlite_vtable ./... diff --git a/README.md b/README.md new file mode 100644 index 00000000..c54045b4 --- /dev/null +++ b/README.md @@ -0,0 +1,164 @@ +[![GoDev](https://img.shields.io/static/v1?label=godev&message=reference&color=00add8)](https://pkg.go.dev/github.com/augmentable-dev/gitqlite) +[![BuildStatus](https://github.com/augmentable-dev/gitqlite/workflows/tests/badge.svg)](https://github.com/augmentable-dev/gitqlite/actions?workflow=tests) +[![Go Report Card](https://goreportcard.com/badge/github.com/augmentable-dev/gitqlite)](https://goreportcard.com/report/github.com/augmentable-dev/gitqlite) +[![TODOs](https://badgen.net/https/api.tickgit.com/badgen/github.com/augmentable-dev/gitqlite)](https://www.tickgit.com/browse?repo=github.com/augmentable-dev/gitqlite) + + +# gitqlite + +`gitqlite` is a tool for running SQL queries on git repositories. +It implements SQLite [virtual tables](https://www.sqlite.org/vtab.html) and uses [go-git](https://github.com/go-git/go-git). +It's meant for ad-hoc querying of git repositories on disk through a common interface (SQL), as an alternative to patching together various shell commands. + +## Installation + +``` +go install -v -tags=sqlite_vtable github.com/augmentable-dev/gitqlite +``` + +Will use the go tool chain to install a binary to `$GOBIN`. + +``` +GOBIN=$(pwd) go install -v -tags=sqlite_vtable github.com/augmentable-dev/gitqlite +``` + +Will produce a binary in your current directory. + +TODO: more installation instructions + +## Usage + +``` +gitqlite -h +``` + +Will output the most up to date usage instructions for your version of the CLI. +Typically the first argument is a SQL query string: + +``` +gitqlite "SELECT * FROM commits" +``` + +Your current working directory will be used as the path to the git repository to query by default. +Use the `--repo` flag to specify an alternate path, or even a remote repository reference (http(s) or ssh). +`gitqlite` will clone the remote repository to a temporary directory before executing a query. + +You can also pass a query in via `stdin`: + +``` +cat query.sql | gitqlite +``` + +By default, output will be an ASCII table. +Use `--format json` or `--format csv` for alternatives. +See `-h` for all the options. + +### Tables + +#### `commits` + +Similar to `git log`, the `commits` table includes all commits in the history of the currently checked out commit. + +| Column | Type | +|-----------------|----------| +| id | TEXT | +| message | TEXT | +| summary | TEXT | +| author_name | TEXT | +| author_email | TEXT | +| author_when | DATETIME | +| committer_name | TEXT | +| committer_email | TEXT | +| committer_when | DATETIME | +| parent_id | TEXT | +| parent_count | INT | +| tree_id | TEXT | +| additions | INT | +| deletions | INT | + +#### `files` + +The `files` table iterates over _ALL_ the files in a commit history, by default from what's checked out in the repository. +The full table is every file in every tree of a commit history. +Use the `commit_id` column to filter for files that belong to the work tree of a specific commit. + +| Column | Type | +|-----------|------| +| commit_id | TEXT | +| tree_id | TEXT | +| name | TEXT | +| mode | TEXT | +| type | TEXT | +| contents | TEXT | + +#### `refs` + +| Column | Type | +|--------|------| +| name | TEXT | +| type | TEXT | +| hash | TEXT | + +### Example Queries + +This will return all commits in the history of the currently checked out branch/commit of the repo. +```sql +SELECT * FROM commits +``` + +Return the (de-duplicated) email addresses of commit authors: +```sql +SELECT DISTINCT author_email FROM commits +``` + +Return the commit counts of every author (by email): +```sql +SELECT author_email, count(*) FROM commits GROUP BY author_email ORDER BY count(*) DESC +``` + +Same as above, but excluding merge commits: +```sql +SELECT author_email, count(*) FROM commits WHERE parent_count < 2 GROUP BY author_email ORDER BY count(*) DESC +``` + +This is an expensive query. +It will iterate over every file in every tree of every commit in the current history: +```sql +SELECT * FROM files +``` + + +Outputs the set of files in the tree of a certain commit: +```sql +SELECT * FROM files WHERE commit_id='some_commit_id' +``` + + +Same as above if you just have the commit short id: +```sql +SELECT * FROM files WHERE commit_id LIKE 'shortened_commit_id%' +``` + + +Returns author emails with lines added/removed, ordered by total number of commits in the history: +```sql +SELECT count(*) AS commits, SUM(additions) AS additions, SUM(deletions) AS deletions, author_email FROM commits GROUP BY author_email ORDER BY commits +``` + + + +Returns commit counts by author, broken out by day of the week: + +```sql +SELECT + count(*) AS commits, + count(case when strftime('%w',author_when)='0' then 1 end) as sunday, + count(case when strftime('%w',author_when)='1' then 1 end) as monday, + count(case when strftime('%w',author_when)='2' then 1 end) as tuesday, + count(case when strftime('%w',author_when)='3' then 1 end) as wednesday, + count(case when strftime('%w',author_when)='4' then 1 end) as thursday, + count(case when strftime('%w',author_when)='5' then 1 end) as friday, + count(case when strftime('%w',author_when)='6' then 1 end) as saturday, + author_email +FROM commits GROUP BY author_email ORDER BY commits +``` diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 00000000..f578c518 --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,268 @@ +package cmd + +import ( + "bufio" + "database/sql" + "encoding/csv" + "encoding/json" + "fmt" + "io/ioutil" + "os" + "path/filepath" + + "github.com/augmentable-dev/gitqlite/pkg/gitqlite" + "github.com/gitsight/go-vcsurl" + "github.com/go-git/go-git/v5" + _ "github.com/mattn/go-sqlite3" + "github.com/olekukonko/tablewriter" + "github.com/spf13/cobra" +) + +//define flags in here +var ( + repo string + format string +) + +func init() { + RootCmd.PersistentFlags().StringVar(&repo, "repo", ".", "path to git repository (defaults to current directory). A remote git repository may also be specified, it will be cloned to a temporary directory on disk before query execution. Default git credentials are used for non-public remote repos.") + RootCmd.PersistentFlags().StringVar(&format, "format", "table", "specify the output format. Options are 'csv' 'tsv' 'table' and 'json'") +} + +func handleError(err error) { + if err != nil { + fmt.Println(err) + os.Exit(1) + } +} + +var RootCmd = &cobra.Command{ + Use: `gitqlite "SELECT * FROM commits"`, + Long: ` + gitqlite is a CLI for querying git repositories with SQL, using SQLite virtual tables. + Example queries can be found in the GitHub repo: https://github.com/augmentable-dev/gitqlite`, + Short: `query your github repos with SQL`, + Run: func(cmd *cobra.Command, args []string) { + info, err := os.Stdin.Stat() + handleError(err) + + var query string + if len(args) > 0 { + query = args[0] + } else if info.Mode()&os.ModeCharDevice == 0 { + query, err = readStdin() + handleError(err) + } else { + err = cmd.Help() + handleError(err) + os.Exit(0) + } + + cwd, err := os.Getwd() + handleError(err) + + // if a repo path is not supplied either as a flag or the second argument, use the current directory + if repo == "" { + if len(args) > 1 { + repo = args[1] + } else { + repo = cwd + } + } + + // if the repo can be parsed as a remote git url, clone it to a temporary directory and use that as the repo path + remote, err := vcsurl.Parse(repo) + if err == nil { + r, err := remote.Remote(vcsurl.HTTPS) + handleError(err) + + dir, err := ioutil.TempDir("", "repo") + handleError(err) + + _, err = git.PlainClone(dir, false, &git.CloneOptions{ + URL: r, + }) + handleError(err) + + defer func() { + err := os.RemoveAll(dir) + handleError(err) + }() + + repo = dir + } + + repo, err = filepath.Abs(repo) + if err != nil { + handleError(err) + } + + g, err := gitqlite.New(repo) + handleError(err) + + rows, err := g.DB.Query(query) + handleError(err) + + defer rows.Close() + err = displayDB(rows) + handleError(err) + }, +} + +func Execute() { + if err := RootCmd.Execute(); err != nil { + handleError(err) + } +} + +func displayDB(rows *sql.Rows) error { + + switch format { + case "csv": + err := csvDisplay(rows, ',') + if err != nil { + return err + } + case "tsv": + err := csvDisplay(rows, '\t') + if err != nil { + return err + } + case "json": + err := jsonDisplay(rows) + if err != nil { + return err + } + //TODO: switch between table and csv dependent on num columns(suggested num for table 5<= + default: + err := tableDisplay(rows) + if err != nil { + return err + } + + } + return nil +} + +func csvDisplay(rows *sql.Rows, commaChar rune) error { + + columns, err := rows.Columns() + if err != nil { + return err + } + w := csv.NewWriter(os.Stdout) + w.Comma = commaChar + + err = w.Write(columns) + if err != nil { + return err + } + pointers := make([]interface{}, len(columns)) + container := make([]sql.NullString, len(columns)) + + for i := range pointers { + pointers[i] = &container[i] + } + for rows.Next() { + err := rows.Scan(pointers...) + if err != nil { + return err + } + + r := make([]string, len(columns)) + for i, c := range container { + if c.Valid { + r[i] = c.String + } + } + + err = w.Write(r) + if err != nil { + return err + } + } + w.Flush() + return nil +} + +func jsonDisplay(rows *sql.Rows) error { + columns, err := rows.Columns() + if err != nil { + return err + } + + values := make([]interface{}, len(columns)) + for i := range values { + values[i] = new(interface{}) + } + + enc := json.NewEncoder(os.Stdout) + + for rows.Next() { + err = rows.Scan(values...) + if err != nil { + return err + } + + dest := make(map[string]interface{}) + + for i, column := range columns { + dest[column] = *(values[i].(*interface{})) + } + + err := enc.Encode(dest) + if err != nil { + return err + } + + } + + return nil +} +func tableDisplay(rows *sql.Rows) error { + columns, err := rows.Columns() + if err != nil { + return err + } + pointers := make([]interface{}, len(columns)) + container := make([]sql.NullString, len(columns)) + + for i := range pointers { + pointers[i] = &container[i] + } + table := tablewriter.NewWriter(os.Stdout) + table.SetHeader(columns) + for rows.Next() { + + err := rows.Scan(pointers...) + if err != nil { + return err + } + + r := make([]string, len(columns)) + for i, c := range container { + if c.Valid { + r[i] = c.String + } else { + r[i] = "NULL" + } + } + + table.Append(r) + if err != nil { + return err + } + } + table.Render() + return nil +} + +func readStdin() (string, error) { + reader := bufio.NewReader(os.Stdin) + output, err := ioutil.ReadAll(reader) + if err != nil { + return "", err + } + returnString := string(output) + return returnString, nil +} diff --git a/gitqlite.go b/gitqlite.go new file mode 100644 index 00000000..b1e4d8f1 --- /dev/null +++ b/gitqlite.go @@ -0,0 +1,9 @@ +package main + +import ( + "github.com/augmentable-dev/gitqlite/cmd" +) + +func main() { + cmd.Execute() +} diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..08775c1a --- /dev/null +++ b/go.mod @@ -0,0 +1,16 @@ +module github.com/augmentable-dev/gitqlite + +go 1.13 + +require ( + github.com/gitsight/go-vcsurl v1.0.0 + github.com/go-git/go-git/v5 v5.1.0 + github.com/mattn/go-runewidth v0.0.9 // indirect + github.com/mattn/go-sqlite3 v2.0.3+incompatible + github.com/olekukonko/tablewriter v0.0.4 + github.com/spf13/cobra v1.0.0 + github.com/spf13/pflag v1.0.5 // indirect + golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect + golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect + gopkg.in/yaml.v2 v2.3.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..109b1108 --- /dev/null +++ b/go.sum @@ -0,0 +1,227 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs= +github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA= +github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= +github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= +github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= +github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gitsight/go-vcsurl v1.0.0 h1:5tPEZWW6eN4cACq6IPV7ThikoLO1HnZtS0oMVJ0yIxA= +github.com/gitsight/go-vcsurl v1.0.0/go.mod h1:qRFdKDa/0Lh9MT0xE+qQBYZ/01+mY1H40rZUHR24X9U= +github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= +github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= +github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= +github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E= +github.com/go-git/go-billy/v5 v5.0.0 h1:7NQHvd9FVid8VL4qVUMm8XifBK+2xCoZ2lSk0agRrHM= +github.com/go-git/go-billy/v5 v5.0.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= +github.com/go-git/go-git-fixtures/v4 v4.0.1 h1:q+IFMfLx200Q3scvt2hN79JsEzy4AmBTp/pqnefH+Bc= +github.com/go-git/go-git-fixtures/v4 v4.0.1/go.mod h1:m+ICp2rF3jDhFgEZ/8yziagdT1C+ZpZcrJjappBCDSw= +github.com/go-git/go-git/v5 v5.1.0 h1:HxJn9g/E7eYvKW3Fm7Jt4ee8LXfPOm/H1cdDu8vEssk= +github.com/go-git/go-git/v5 v5.1.0/go.mod h1:ZKfuPUoY1ZqIG4QG9BDBh3G4gLM5zvPuSJAozQrZuyM= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg= +github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY= +github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54= +github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U= +github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8= +github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA= +github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= +github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8= +github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= +github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= +github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo= +golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/pkg/gitqlite/git_log.go b/pkg/gitqlite/git_log.go new file mode 100644 index 00000000..69f9cf63 --- /dev/null +++ b/pkg/gitqlite/git_log.go @@ -0,0 +1,244 @@ +package gitqlite + +import ( + "fmt" + "io" + "strings" + "time" + + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing/object" + "github.com/mattn/go-sqlite3" +) + +type gitLogModule struct{} + +type gitLogTable struct { + repoPath string + repo *git.Repository +} + +func (m *gitLogModule) Create(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) { + err := c.DeclareVTab(fmt.Sprintf(` + CREATE TABLE %q ( + id TEXT, + message TEXT, + summary TEXT, + author_name TEXT, + author_email TEXT, + author_when DATETIME, + committer_name TEXT, + committer_email TEXT, + committer_when DATETIME, + parent_id TEXT, + parent_count INT(10), + tree_id TEXT, + additions INT(10), + deletions INT(10) + )`, args[0])) + if err != nil { + return nil, err + } + + // the repoPath will be enclosed in double quotes "..." since ensureTables uses %q when setting up the table + // we need to pop those off when referring to the actual directory in the fs + repoPath := args[3][1 : len(args[3])-1] + return &gitLogTable{repoPath: repoPath}, nil +} + +func (m *gitLogModule) Connect(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) { + return m.Create(c, args) +} + +func (m *gitLogModule) DestroyModule() {} + +func (v *gitLogTable) Open() (sqlite3.VTabCursor, error) { + repo, err := git.PlainOpen(v.repoPath) + if err != nil { + return nil, err + } + v.repo = repo + headRef, err := v.repo.Head() + if err != nil { + return nil, err + } + + iter, err := v.repo.Log(&git.LogOptions{ + From: headRef.Hash(), + Order: git.LogOrderCommitterTime, + }) + if err != nil { + return nil, err + } + + commit, err := iter.Next() + if err != nil { + return nil, err + } + + return &commitCursor{0, v.repo, commit, iter, false}, nil +} + +func (v *gitLogTable) BestIndex(cst []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy) (*sqlite3.IndexResult, error) { + // TODO this should actually be implemented! + dummy := make([]bool, len(cst)) + return &sqlite3.IndexResult{Used: dummy}, nil +} + +func (v *gitLogTable) Disconnect() error { + v.repo = nil + return nil +} +func (v *gitLogTable) Destroy() error { return nil } + +type commitCursor struct { + index int + repo *git.Repository + current *object.Commit + commitIter object.CommitIter + eof bool +} + +func (vc *commitCursor) Column(c *sqlite3.SQLiteContext, col int) error { + + commit := vc.current + author := commit.Author + committer := commit.Committer + + switch col { + case 0: + //commit id + c.ResultText(commit.ID().String()) + case 1: + //commit message + c.ResultText(commit.Message) + case 2: + //commit summary + c.ResultText(strings.Split(commit.Message, "\n")[0]) + case 3: + //commit author name + c.ResultText(author.Name) + case 4: + //commit author email + c.ResultText(author.Email) + case 5: + //author when + c.ResultText(author.When.Format(time.RFC3339Nano)) + case 6: + //committer name + c.ResultText(committer.Name) + case 7: + //committer email + c.ResultText(committer.Email) + case 8: + //committer when + c.ResultText(committer.When.Format(time.RFC3339Nano)) + case 9: + //parent_id + if int(commit.NumParents()) > 0 { + p, err := commit.Parent(0) + if err != nil { + return err + } + c.ResultText(p.ID().String()) + } else { + c.ResultNull() + } + case 10: + //parent_count + c.ResultInt(int(commit.NumParents())) + case 11: + //tree_id + tree, err := vc.current.Tree() + if err != nil { + return err + } + c.ResultText(tree.ID().String()) + + case 12: + if int(commit.NumParents()) > 0 { + additions, _, err := statCalc(commit) + if err != nil { + return err + } + c.ResultInt(additions) + } else { + c.ResultInt(0) + } + case 13: + if int(commit.NumParents()) > 0 { + _, deletions, err := statCalc(commit) + if err != nil { + return err + } + c.ResultInt(deletions) + } else { + c.ResultInt(0) + } + + } + return nil +} + +func (vc *commitCursor) Filter(idxNum int, idxStr string, vals []interface{}) error { + vc.index = 0 + return nil +} + +func (vc *commitCursor) Next() error { + vc.index++ + + commit, err := vc.commitIter.Next() + if err != nil { + if err == io.EOF { + vc.current = nil + vc.eof = true + return nil + } + return err + } + + vc.current = commit + return nil +} + +func (vc *commitCursor) EOF() bool { + return vc.eof +} + +func (vc *commitCursor) Rowid() (int64, error) { + return int64(vc.index), nil +} + +func (vc *commitCursor) Close() error { + vc.commitIter.Close() + return nil +} + +//statCalc calculates the number of additions/deletions and returns in format additions, deletions +func statCalc(c *object.Commit) (int, int, error) { + p, err := c.Parent(0) + if err != nil { + return 0, 0, err + } + parentTree, err := p.Tree() + if err != nil { + return 0, 0, err + } + tree, err := c.Tree() + if err != nil { + return 0, 0, err + } + + patch, err := parentTree.Patch(tree) + if err != nil { + return 0, 0, err + } + additions, deletions := 0, 0 + stats := patch.Stats() + for i := range stats { + additions += stats[i].Addition + deletions += stats[i].Deletion + } + return additions, deletions, nil +} diff --git a/pkg/gitqlite/git_ref.go b/pkg/gitqlite/git_ref.go new file mode 100644 index 00000000..f33ab94a --- /dev/null +++ b/pkg/gitqlite/git_ref.go @@ -0,0 +1,129 @@ +package gitqlite + +import ( + "fmt" + "io" + + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing" + "github.com/go-git/go-git/v5/plumbing/storer" + "github.com/mattn/go-sqlite3" +) + +type gitRefModule struct{} + +type gitRefTable struct { + repoPath string + repo *git.Repository +} + +func (m *gitRefModule) Create(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) { + err := c.DeclareVTab(fmt.Sprintf(` + CREATE TABLE %q( + name TEXT, + type TEXT, + hash TEXT + )`, args[0])) + if err != nil { + return nil, err + } + repoPath := args[3][1 : len(args[3])-1] + return &gitRefTable{repoPath: repoPath}, nil +} + +func (m *gitRefModule) Connect(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) { + return m.Create(c, args) +} + +func (m *gitRefModule) DestroyModule() {} + +func (vc *refCursor) Column(c *sqlite3.SQLiteContext, col int) error { + + ref := vc.current + nameNHash := ref.Strings() + switch col { + case 0: + //RefName + c.ResultText(nameNHash[0]) + + case 1: + //RefType + c.ResultText(ref.Type().String()) + case 2: + //RefHash + c.ResultText(nameNHash[1]) + } + return nil +} +func (v *gitRefTable) BestIndex(cst []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy) (*sqlite3.IndexResult, error) { + // TODO this should actually be implemented! + dummy := make([]bool, len(cst)) + return &sqlite3.IndexResult{Used: dummy}, nil +} + +func (v *gitRefTable) Disconnect() error { + v.repo = nil + return nil +} + +func (v *gitRefTable) Destroy() error { return nil } + +type refCursor struct { + index int + repo *git.Repository + iterator storer.ReferenceIter + current *plumbing.Reference + eof bool +} + +func (v *gitRefTable) Open() (sqlite3.VTabCursor, error) { + repo, err := git.PlainOpen(v.repoPath) + if err != nil { + return nil, err + } + v.repo = repo + + refIter, err := repo.References() + if err != nil { + return nil, err + } + current, err := refIter.Next() + if err != nil { + return nil, err + } + + return &refCursor{0, v.repo, refIter, current, false}, nil +} + +func (vc *refCursor) Next() error { + vc.index++ + //Iterates to next ref + file, err := vc.iterator.Next() + if err != nil { + if err == io.EOF { + vc.current = nil + vc.eof = true + return nil + } + return err + } + // if not EOF and not err go to next ref + vc.current = file + return nil +} +func (vc *refCursor) Filter(idxNum int, idxStr string, vals []interface{}) error { + vc.index = 0 + return nil +} +func (vc *refCursor) EOF() bool { + return vc.eof +} + +func (vc *refCursor) Rowid() (int64, error) { + return int64(vc.index), nil +} + +func (vc *refCursor) Close() error { + vc.iterator.Close() + return nil +} diff --git a/pkg/gitqlite/git_tree.go b/pkg/gitqlite/git_tree.go new file mode 100644 index 00000000..4082a5d2 --- /dev/null +++ b/pkg/gitqlite/git_tree.go @@ -0,0 +1,228 @@ +package gitqlite + +import ( + "fmt" + "io" + + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing/object" + "github.com/mattn/go-sqlite3" +) + +type gitTreeModule struct{} + +type gitTreeTable struct { + repoPath string + repo *git.Repository +} + +func (m *gitTreeModule) Create(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) { + err := c.DeclareVTab(fmt.Sprintf(` + CREATE TABLE %q( + commit_id TEXT, + tree_id TEXT, + name TEXT, + mode TEXT, + type TEXT, + contents TEXT + )`, args[0])) + if err != nil { + return nil, err + } + repoPath := args[3][1 : len(args[3])-1] + return &gitTreeTable{repoPath: repoPath}, nil +} + +func (m *gitTreeModule) Connect(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) { + return m.Create(c, args) +} + +func (m *gitTreeModule) DestroyModule() {} + +func (vc *treeCursor) Column(c *sqlite3.SQLiteContext, col int) error { + commit := vc.iterator.commit + treeHeadEntry := commit.TreeHash.String() // should be structure Name String Id *Oid Type ObjectType Filemode Filemode + currentFile := vc.current + fileMode, err := currentFile.Mode.ToOSFileMode() + if err != nil { + return err + } + fileContents, err := currentFile.Contents() + if err != nil { + return err + } + name := currentFile.Name + + switch col { + case 0: + //commit id + c.ResultText(commit.ID().String()) + case 1: + //tree id + c.ResultText(treeHeadEntry) + case 2: + //tree name + c.ResultText(name) + case 3: + //filemode + c.ResultText(fileMode.String()) + case 4: + //filetype + c.ResultText(currentFile.Type().String()) + case 5: + //File + // change this to text with the blob section of go-git + + c.ResultText(fileContents) + } + return nil + //return errors.New("something messed up in column") +} +func (v *gitTreeTable) BestIndex(cst []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy) (*sqlite3.IndexResult, error) { + // TODO this should actually be implemented! + dummy := make([]bool, len(cst)) + return &sqlite3.IndexResult{Used: dummy}, nil +} + +func (v *gitTreeTable) Disconnect() error { + v.repo = nil + return nil +} + +func (v *gitTreeTable) Destroy() error { return nil } + +type treeCommitIterator struct { + commitIter object.CommitIter + commit *object.Commit + treeFileIter *object.FileIter +} + +func NewTreeCommitIterator(commitIter object.CommitIter) (*treeCommitIterator, error) { + commit, err := commitIter.Next() + if err != nil { + return nil, err + } + + tree, err := commit.Tree() + if err != nil { + return nil, err + } + + treeFileIter := tree.Files() + + return &treeCommitIterator{commitIter, commit, treeFileIter}, nil +} + +func (iter *treeCommitIterator) Next() (*object.File, error) { + file, err := iter.treeFileIter.Next() + if err != nil { + // if it is the last file in the tree go to the next commit + + if err == io.EOF { + + commit, err := iter.commitIter.Next() + + if err != nil { + + //if it is the last file in the last tree of the commits return EOF + if err == io.EOF { + return nil, io.EOF + } + return nil, err + } + iter.commit = commit + tree, err := commit.Tree() + if err != nil { + return nil, err + } + fileIter := tree.Files() + iter.treeFileIter = fileIter + file, err := iter.treeFileIter.Next() + if err != nil { + return nil, err + } + return file, nil + } + return nil, err + } + return file, nil + +} + +func (iter *treeCommitIterator) Close() { + iter.treeFileIter.Close() + iter.commitIter.Close() +} + +type treeCursor struct { + index int + repo *git.Repository + iterator *treeCommitIterator + current *object.File + eof bool +} + +func (v *gitTreeTable) Open() (sqlite3.VTabCursor, error) { + repo, err := git.PlainOpen(v.repoPath) + if err != nil { + return nil, err + } + v.repo = repo + + headRef, err := v.repo.Head() + if err != nil { + return nil, err + } + iter, err := v.repo.Log(&git.LogOptions{ + From: headRef.Hash(), + Order: git.LogOrderCommitterTime, + }) + if err != nil { + return nil, err + } + + treeCommitIter, err := NewTreeCommitIterator(iter) + if err != nil { + return nil, err + } + + current, err := treeCommitIter.Next() + if err != nil { + return nil, err + } + + return &treeCursor{0, v.repo, treeCommitIter, current, false}, nil +} + +func (vc *treeCursor) Next() error { + vc.index++ + //Iterates to next file + file, err := vc.iterator.Next() + if err != nil { + if err == io.EOF { + vc.current = nil + vc.eof = true + return nil + } + return err + } + // if not EOF and not err go to next file in tree + vc.current = file + return nil +} +func (vc *treeCursor) Filter(idxNum int, idxStr string, vals []interface{}) error { + vc.index = 0 + return nil +} +func (vc *treeCursor) EOF() bool { + return vc.eof +} + +func (vc *treeCursor) Rowid() (int64, error) { + return int64(vc.index), nil +} + +func (vc *treeCursor) Close() error { + vc.iterator.Close() + return nil +} diff --git a/pkg/gitqlite/gitqlite.go b/pkg/gitqlite/gitqlite.go new file mode 100644 index 00000000..6e422bd8 --- /dev/null +++ b/pkg/gitqlite/gitqlite.go @@ -0,0 +1,80 @@ +package gitqlite + +import ( + "database/sql" + "fmt" + + "github.com/go-git/go-git/v5" + "github.com/mattn/go-sqlite3" +) + +// GitQLite loads git repositories into sqlite +type GitQLite struct { + DB *sql.DB + RepoPath string +} + +func init() { + sql.Register("gitqlite", &sqlite3.SQLiteDriver{ + ConnectHook: func(conn *sqlite3.SQLiteConn) error { + err := conn.CreateModule("git_log", &gitLogModule{}) + if err != nil { + return err + } + + err = conn.CreateModule("git_tree", &gitTreeModule{}) + if err != nil { + return err + } + + err = conn.CreateModule("git_ref", &gitRefModule{}) + if err != nil { + return err + } + + return nil + }, + }) +} + +// New creates an instance of GitQLite +func New(repoPath string) (*GitQLite, error) { + // see https://github.com/mattn/go-sqlite3/issues/204 + // also mentioned in the FAQ of the README: https://github.com/mattn/go-sqlite3#faq + db, err := sql.Open("gitqlite", "file::memory:?cache=shared") + if err != nil { + return nil, err + } + + _, err = git.PlainOpen(repoPath) + if err != nil { + return nil, err + } + + g := &GitQLite{DB: db, RepoPath: repoPath} + + err = g.ensureTables() + if err != nil { + return nil, err + } + + return g, nil +} + +// creates the virtual tables inside of the *sql.DB +func (g *GitQLite) ensureTables() error { + _, err := g.DB.Exec(fmt.Sprintf("CREATE VIRTUAL TABLE commits USING git_log(%q);", g.RepoPath)) + if err != nil { + return err + } + _, err = g.DB.Exec(fmt.Sprintf("CREATE VIRTUAL TABLE files USING git_tree(%q);", g.RepoPath)) + if err != nil { + return err + } + _, err = g.DB.Exec(fmt.Sprintf("CREATE VIRTUAL TABLE refs USING git_ref(%q);", g.RepoPath)) + if err != nil { + return err + } + + return nil +} diff --git a/pkg/gitqlite/gitqlite_test.go b/pkg/gitqlite/gitqlite_test.go new file mode 100644 index 00000000..cd6a1c71 --- /dev/null +++ b/pkg/gitqlite/gitqlite_test.go @@ -0,0 +1,193 @@ +package gitqlite + +import ( + "database/sql" + "io/ioutil" + "os" + "testing" + + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing" + "github.com/go-git/go-git/v5/plumbing/object" +) + +var ( + fixtureRepoCloneURL = "https://github.com/augmentable-dev/tickgit" + fixtureRepo *git.Repository + instance *GitQLite +) + +func TestMain(m *testing.M) { + close, err := initFixtureRepo() + if err != nil { + panic(err) + } + code := m.Run() + close() + os.Exit(code) +} + +func initFixtureRepo() (func() error, error) { + dir, err := ioutil.TempDir("", "repo") + if err != nil { + return nil, err + } + + fixtureRepo, err = git.PlainClone(dir, false, &git.CloneOptions{ + URL: fixtureRepoCloneURL, + }) + if err != nil { + return nil, err + } + + instance, err = New(dir) + if err != nil { + return nil, err + } + + return func() error { + err := os.RemoveAll(dir) + if err != nil { + return err + } + return nil + }, nil +} + +func TestModuleInitialization(t *testing.T) { + if instance.DB == nil { + t.Fatal("expected non-nil DB, got nil") + } +} + +func TestCommitCounts(t *testing.T) { + headRef, err := fixtureRepo.Head() + if err != nil { + t.Fatal(err) + } + commitChecker, err := fixtureRepo.Log(&git.LogOptions{ + From: headRef.Hash(), + Order: git.LogOrderCommitterTime, + }) + if err != nil { + t.Fatal(err) + } + + commitCount := 0 + err = commitChecker.ForEach(func(c *object.Commit) error { + commitCount++ + return nil + }) + if err != nil { + t.Fatal(err) + } + + //checks commits + rows, err := instance.DB.Query("SELECT * FROM commits") + if err != nil { + t.Fatal(err) + } + defer rows.Close() + columns, err := rows.Columns() + if err != nil { + t.Fatal(err) + } + expected := 14 + if len(columns) != expected { + t.Fatalf("expected %d columns, got: %d", expected, len(columns)) + } + numRows := getRowsCount(rows) + if err != nil { + t.Fatal(err) + } + expected = commitCount + if numRows != expected { + t.Fatalf("expected %d rows got: %d", expected, numRows) + } +} + +func TestFileCounts(t *testing.T) { + headRef, err := fixtureRepo.Head() + if err != nil { + t.Fatal(err) + } + commitChecker, err := fixtureRepo.Log(&git.LogOptions{ + From: headRef.Hash(), + Order: git.LogOrderCommitterTime, + }) + if err != nil { + t.Fatal(err) + } + numFiles := 0 + err = commitChecker.ForEach(func(c *object.Commit) error { + numFiles++ + return nil + }) + if err != nil { + t.Fatal(err) + } + + fileRows, err := instance.DB.Query("SELECT DISTINCT commit_id FROM files") + if err != nil { + t.Fatal(err) + } + defer fileRows.Close() + numFileRows := getRowsCount(fileRows) + if numFileRows != numFiles { + t.Fatalf("expected %d rows got : %d", numFiles, numFileRows) + } + columnQuery, err := instance.DB.Query("SELECT * FROM files LIMIT 1") + if err != nil { + t.Fatal(err) + } + columns, err := columnQuery.Columns() + if err != nil { + t.Fatal(err) + } + if len(columns) != 6 { + t.Fatalf("expected %d columns got : %d", 6, len(columns)) + } +} + +func TestRefCounts(t *testing.T) { + refChecker, err := fixtureRepo.References() + if err != nil { + t.Fatal(err) + } + refCount := 0 + err = refChecker.ForEach(func(r *plumbing.Reference) error { + refCount++ + return nil + }) + if err != nil { + t.Fatal(err) + } + + //check refs + refRows, err := instance.DB.Query("SELECT * FROM refs") + if err != nil { + t.Fatal(err) + } + + columns, err := refRows.Columns() + if err != nil { + t.Fatal(err) + } + expected := 3 + if len(columns) != expected { + t.Fatalf("expected %d columns, got: %d", expected, len(columns)) + } + numRows := getRowsCount(refRows) + if numRows != refCount { + t.Fatalf("expected %d rows got : %d", refCount, numRows) + } +} + +func getRowsCount(rows *sql.Rows) int { + count := 0 + for rows.Next() { + count++ + } + + return count +}