mirror of
https://github.com/MichaelMure/git-bug.git
synced 2024-12-14 17:51:44 +03:00
repository: some light shuffling of code
This commit is contained in:
parent
3ecbf8db28
commit
30d1640bf4
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user