repository: some light shuffling of code

Michael Muré created

Change summary

repository/repo.go       | 49 ++++++++---------------------------------
repository/tree_entry.go | 32 +++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 39 deletions(-)

Detailed changes

repository/repo.go 🔗

@@ -2,9 +2,7 @@
 package repository
 
 import (
-	"bytes"
 	"errors"
-	"strings"
 
 	"github.com/MichaelMure/git-bug/util/lamport"
 )
@@ -16,6 +14,14 @@ var (
 	ErrClockNotExist = errors.New("clock doesn't exist")
 )
 
+// Repo represents a source code repository.
+type Repo interface {
+	RepoConfig
+	RepoKeyring
+	RepoCommon
+	RepoData
+}
+
 // RepoConfig access the configuration of a repository
 type RepoConfig interface {
 	// LocalConfig give access to the repository scoped configuration
@@ -46,12 +52,8 @@ type RepoCommon interface {
 	GetRemotes() (map[string]string, error)
 }
 
-// Repo represents a source code repository.
-type Repo interface {
-	RepoConfig
-	RepoKeyring
-	RepoCommon
-
+// RepoData give access to the git data storage
+type RepoData interface {
 	// FetchRefs fetch git refs from a remote
 	FetchRefs(remote string, refSpec string) (string, error)
 
@@ -122,37 +124,6 @@ type ClockLoader struct {
 	Witnesser func(repo ClockedRepo) 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) {
-	split := strings.Split(strings.TrimSpace(s), "\n")
-
-	casted := make([]TreeEntry, len(split))
-	for i, line := range split {
-		if line == "" {
-			continue
-		}
-
-		entry, err := ParseTreeEntry(line)
-
-		if err != nil {
-			return nil, err
-		}
-
-		casted[i] = entry
-	}
-
-	return casted, nil
-}
-
 // TestedRepo is an extended ClockedRepo with function for testing only
 type TestedRepo interface {
 	ClockedRepo

repository/tree_entry.go 🔗

@@ -1,6 +1,7 @@
 package repository
 
 import (
+	"bytes"
 	"fmt"
 	"strings"
 )
@@ -68,3 +69,34 @@ func ParseObjectType(mode, objType string) (ObjectType, error) {
 		return Unknown, fmt.Errorf("Unknown git object type %s %s", mode, objType)
 	}
 }
+
+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) {
+	split := strings.Split(strings.TrimSpace(s), "\n")
+
+	casted := make([]TreeEntry, len(split))
+	for i, line := range split {
+		if line == "" {
+			continue
+		}
+
+		entry, err := ParseTreeEntry(line)
+
+		if err != nil {
+			return nil, err
+		}
+
+		casted[i] = entry
+	}
+
+	return casted, nil
+}