Skip to content
Snippets Groups Projects
Commit 1b218c84 authored by Nick Thomas's avatar Nick Thomas
Browse files

Initial blob-reading and json-encoding stubs

parent ad4c9c9b
No related branches found
No related tags found
1 merge request!1Initial implementation of an elasticsearch indexer in Go
Loading
Loading
@@ -3,6 +3,8 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"
 
"srcd.works/go-git.v4"
Loading
Loading
@@ -30,6 +32,31 @@ type Repo struct {
ToCommit *object.Commit
}
 
type ReaderAsJSONString struct {
io.Reader
}
func (r *ReaderAsJSONString) MarshalJSON() ([]byte, error) {
/* TODO: fewer copies
out := bytes.NewBuffer(nil)
err := out.WriteByte('"')
_, err = io.Copy(out, r.Reader) // FIXME: convert to valid JSON string data, escape quote marks
err = out.WriteByte('"')
return out.Bytes(), err
*/
data, err := ioutil.ReadAll(r.Reader)
if err != nil {
return nil, err
}
return json.Marshal(string(data))
}
type Req struct {
Blob *ReaderAsJSONString `json:"blob"`
}
func NewRepo(projectPath string, fromSHA string, toSHA string) (*Repo, error) {
out := &Repo{}
 
Loading
Loading
@@ -167,10 +194,18 @@ func main() {
 
insOrModFile := func(file *object.File) {
fmt.Println("Write", file.Name)
// Read & json-encode the file so we do the same work as the Ruby version
reader, err := file.Blob.Reader()
if err != nil {
os.Exit(1)
}
json.NewEncoder(ioutil.Discard).Encode(&Req{&ReaderAsJSONString{reader}})
reader.Close()
}
 
delFile := func(file *object.File) {
fmt.Println("Delete", file.Name)
// The Ruby version doesn't read the file either
}
 
// index_blobs
Loading
Loading
@@ -178,6 +213,14 @@ func main() {
 
commit := func(c *object.Commit) {
fmt.Println("Commit", c.ID())
// TODO: Read & json-encode the commit so we do the same disc work as the ruby version
//reader, err := c.Blob.Reader()
//if err != nil {
// os.Exit(1)
//}
//json.NewEncoder(ioutil.Discard).Encode(&Req{&ReaderAsJSONString{reader}})
//reader.Close()
}
 
// index_commits
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment