Permalink
Browse files

WIP: Try go-git implementation.

  • Loading branch information...
dmitshur committed Aug 12, 2017
1 parent 5b25b3f commit 27d38ba8d19caaab8d0b3d030da6b4d91940c0cf
Showing with 36 additions and 18 deletions.
  1. +32 −14 229/main.go
  2. +4 −4 229/vcs/git/git.go
View
@@ -14,46 +14,58 @@ import (
"sourcegraph.com/sourcegraph/go-vcs/vcs"
"sourcegraph.com/sourcegraph/go-vcs/vcs/gitcmd"
gogit "github.com/shazow/go-vcs/vcs/git"
"github.com/shurcooL/play/229/vcs/git"
)
func main() {
const dir = "/src/net/http"
//const dir = "/src/encoding"
const tag = "go1.9rc2"
{
err := runDisk(dir)
if err != nil {
log.Fatalln(err)
}
}
// net/http: read total: 16.042893ms 1.2 MB (1182569 bytes) 3fcc1476bde7246ce53e3fbc5a71cd9ec0e4cbead3a7ed941385f4dd2742dd7e
if false {
{
gitcmd.SetModTime = true
err := runGit(dir)
err := runGit(func(dir string) (vcs.Repository, error) { return gitcmd.Open(dir) }, dir, tag)
if err != nil {
log.Fatalln(err)
}
}
// net/http: read total: 10.837731283s 1.2 MB (1182569 bytes) 3fcc1476bde7246ce53e3fbc5a71cd9ec0e4cbead3a7ed941385f4dd2742dd7e
if false {
{
gitcmd.SetModTime = false
err := runGit(dir)
err := runGit(func(dir string) (vcs.Repository, error) { return gitcmd.Open(dir) }, dir, tag)
if err != nil {
log.Fatalln(err)
}
}
// read total: 2.885154088s 1.2 MB (1182569 bytes) 3fcc1476bde7246ce53e3fbc5a71cd9ec0e4cbead3a7ed941385f4dd2742dd7e
{
err := runNewGit(dir)
err := runGit(func(dir string) (vcs.Repository, error) { return gogit.Open(dir) }, dir, tag)
if err != nil {
log.Fatalln(err)
}
}
// net/http: ?
if false {
err := runNewGit(dir, tag)
if err != nil {
log.Fatalln(err)
}
}
// Output:
// net/http: read total: 8.861625ms 1.2 MB (1182569 bytes) 3fcc1476bde7246ce53e3fbc5a71cd9ec0e4cbead3a7ed941385f4dd2742dd7e
// net/http: read total: 6.591873992s 1.2 MB (1182569 bytes) 3fcc1476bde7246ce53e3fbc5a71cd9ec0e4cbead3a7ed941385f4dd2742dd7e
// net/http: read total: 815.592838ms 1.2 MB (1182569 bytes) 3fcc1476bde7246ce53e3fbc5a71cd9ec0e4cbead3a7ed941385f4dd2742dd7e
// net/http: read total: 1.608730649s 1.2 MB (1182569 bytes) 3fcc1476bde7246ce53e3fbc5a71cd9ec0e4cbead3a7ed941385f4dd2742dd7e
}
func runDisk(dir string) error {
@@ -100,13 +112,19 @@ func runDisk(dir string) error {
return nil
}
func runGit(dir string) error {
func runGit(open vcs.Opener, dir, tag string) error {
t := time.Now()
r, err := vcs.Open("git", "/tmp/try/vcs-store/git/https/go.googlesource.com/go")
r, err := open("/tmp/try/vcs-store/git/https/go.googlesource.com/go")
if err != nil {
return err
}
fmt.Println("using:", r)
commitID, err := r.ResolveTag(tag)
if err != nil {
return err
}
fs, err := r.FileSystem("go1.9rc2")
fmt.Println("resolved tag:", commitID)
fs, err := r.FileSystem(commitID)
if err != nil {
return err
}
@@ -141,13 +159,13 @@ func runGit(dir string) error {
return nil
}
func runNewGit(dir string) error {
func runNewGit(dir, tag string) error {
t := time.Now()
r, err := git.Open("/tmp/try/vcs-store/git/https/go.googlesource.com/go")
if err != nil {
return err
}
fs, err := r.FileSystem("go1.9rc2")
fs, err := r.FileSystem(tag)
if err != nil {
return err
}
View
@@ -48,12 +48,12 @@ func (fs fileSystem) Open(path string) (http.File, error) {
env.Set("LANG", "en_US.UTF-8")
cmd.Env = env
t := time.Now()
//t := time.Now()
out, err := cmd.Output()
if err != nil {
return nil, fmt.Errorf("git.fileSystem.Open: %v: %v", strings.Join(cmd.Args, " "), err)
}
fmt.Println("ls-treeing:", time.Since(t))
//fmt.Println("ls-treeing:", time.Since(t))
idx := bytes.IndexByte(out, '\x00')
if idx == -1 {
@@ -73,12 +73,12 @@ func (fs fileSystem) Open(path string) (http.File, error) {
env.Set("LANG", "en_US.UTF-8")
cmd.Env = env
t := time.Now()
//t := time.Now()
out, err := cmd.Output()
if err != nil {
return nil, fmt.Errorf("git.fileSystem.Open: %v: %v", strings.Join(cmd.Args, " "), err)
}
fmt.Println("cat-filing:", time.Since(t))
//fmt.Println("cat-filing:", time.Since(t))
return file{
fs: fs,

0 comments on commit 27d38ba

Please sign in to comment.