aboutsummaryrefslogtreecommitdiffstats
path: root/repository/repo.go
diff options
context:
space:
mode:
Diffstat (limited to 'repository/repo.go')
-rw-r--r--repository/repo.go51
1 files changed, 49 insertions, 2 deletions
diff --git a/repository/repo.go b/repository/repo.go
index a58f35d9..26fe0fa6 100644
--- a/repository/repo.go
+++ b/repository/repo.go
@@ -1,7 +1,11 @@
// Package repository contains helper methods for working with a Git repo.
package repository
-import "github.com/MichaelMure/git-bug/util"
+import (
+ "bytes"
+ "github.com/MichaelMure/git-bug/util"
+ "strings"
+)
// Repo represents a source code repository.
type Repo interface {
@@ -26,8 +30,11 @@ type Repo interface {
// StoreData will store arbitrary data and return the corresponding hash
StoreData(data []byte) (util.Hash, error)
+ // ReadData will attempt to read arbitrary data from the given hash
+ ReadData(hash util.Hash) ([]byte, error)
+
// StoreTree will store a mapping key-->Hash as a Git tree
- StoreTree(mapping map[string]util.Hash) (util.Hash, error)
+ StoreTree(mapping []TreeEntry) (util.Hash, error)
// StoreCommit will store a Git commit with the given Git tree
StoreCommit(treeHash util.Hash) (util.Hash, error)
@@ -37,4 +44,44 @@ type Repo interface {
// UpdateRef will create or update a Git reference
UpdateRef(ref string, hash util.Hash) error
+
+ // ListRefs will return a list of Git ref matching the given refspec
+ ListRefs(refspec string) ([]string, error)
+
+ // ListCommits will return the list of tree hashes of a ref, in chronological order
+ ListCommits(ref string) ([]util.Hash, error)
+
+ // ListEntries will return the list of entries in a Git tree
+ ListEntries(hash util.Hash) ([]TreeEntry, error)
+}
+
+func prepareTreeEntries(entries []TreeEntry) bytes.Buffer {
+ var buffer bytes.Buffer
+
+ for _, entry := range entries {
+ buffer.WriteString(entry.Format())
+ }
+
+ return buffer
+}
+
+func readTreeEntries(s string) ([]TreeEntry, error) {
+ splitted := strings.Split(s, "\n")
+
+ casted := make([]TreeEntry, len(splitted))
+ for i, line := range splitted {
+ if line == "" {
+ continue
+ }
+
+ entry, err := ParseTreeEntry(line)
+
+ if err != nil {
+ return nil, err
+ }
+
+ casted[i] = entry
+ }
+
+ return casted, nil
}