aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-07-28 13:02:32 +0200
committerMichael Muré <batolettre@gmail.com>2020-09-29 20:42:21 +0200
commit30d1640bf47fcd14b1d26e8f5965bb61ae61859f (patch)
tree3217777573dff5eee3174b1fc7a0cc52f3bfe5b8
parent3ecbf8db28105d147340b80d65a5a6d537233135 (diff)
downloadgit-bug-30d1640bf47fcd14b1d26e8f5965bb61ae61859f.tar.gz
repository: some light shuffling of code
-rw-r--r--repository/repo.go49
-rw-r--r--repository/tree_entry.go32
2 files changed, 42 insertions, 39 deletions
diff --git a/repository/repo.go b/repository/repo.go
index 7a69a14f..806edace 100644
--- a/repository/repo.go
+++ b/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
diff --git a/repository/tree_entry.go b/repository/tree_entry.go
index 8b3de8e2..6c5ec1a5 100644
--- a/repository/tree_entry.go
+++ b/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
+}