aboutsummaryrefslogtreecommitdiff
path: root/object/fetch
diff options
context:
space:
mode:
Diffstat (limited to 'object/fetch')
-rw-r--r--object/fetch/blob.go4
-rw-r--r--object/fetch/header.go4
-rw-r--r--object/fetch/path.go2
-rw-r--r--object/fetch/reader.go2
-rw-r--r--object/fetch/treefs.go18
-rw-r--r--object/fetch/treefs_test.go6
6 files changed, 16 insertions, 20 deletions
diff --git a/object/fetch/blob.go b/object/fetch/blob.go
index 9af34922..d40ec875 100644
--- a/object/fetch/blob.go
+++ b/object/fetch/blob.go
@@ -32,7 +32,7 @@ func (fetcher *Fetcher) ExactBlob(id oid.ObjectID) (*stored.Stored[*blob.Blob],
// together with its content size in bytes.
//
// Labels: Life-Parent, Close-Caller.
-func (fetcher *Fetcher) ExactBlobReader(id oid.ObjectID) (io.ReadCloser, uint64, error) {
+func (fetcher *Fetcher) ExactBlobReader(id oid.ObjectID) (io.ReadCloser, int, error) {
return fetcher.exactReader(id, typ.Blob)
}
@@ -87,7 +87,7 @@ func (fetcher *Fetcher) PeelToBlobID(id oid.ObjectID) (oid.ObjectID, error) {
// together with its content size in bytes.
//
// Labels: Life-Parent, Close-Caller.
-func (fetcher *Fetcher) PeelToBlobReader(id oid.ObjectID) (io.ReadCloser, uint64, error) {
+func (fetcher *Fetcher) PeelToBlobReader(id oid.ObjectID) (io.ReadCloser, int, error) {
blobID, err := fetcher.PeelToBlobID(id)
if err != nil {
return nil, 0, err
diff --git a/object/fetch/header.go b/object/fetch/header.go
index 7a8df483..ee02ef69 100644
--- a/object/fetch/header.go
+++ b/object/fetch/header.go
@@ -8,7 +8,7 @@ import (
// Header returns the object type and content size at id.
//
// Labels: Life-Parent.
-func (fetcher *Fetcher) Header(id oid.ObjectID) (typ.Type, uint64, error) {
+func (fetcher *Fetcher) Header(id oid.ObjectID) (typ.Type, int, error) {
ty, size, err := fetcher.store.ReadHeader(id)
if err != nil {
return typ.Unknown, 0, wrapObjectReadError(id, err)
@@ -20,7 +20,7 @@ func (fetcher *Fetcher) Header(id oid.ObjectID) (typ.Type, uint64, error) {
// Size returns the object content size at id.
//
// Labels: Life-Parent.
-func (fetcher *Fetcher) Size(id oid.ObjectID) (uint64, error) {
+func (fetcher *Fetcher) Size(id oid.ObjectID) (int, error) {
size, err := fetcher.store.ReadSize(id)
if err != nil {
return 0, wrapObjectReadError(id, err)
diff --git a/object/fetch/path.go b/object/fetch/path.go
index f8eca507..e8b12481 100644
--- a/object/fetch/path.go
+++ b/object/fetch/path.go
@@ -47,7 +47,7 @@ func (err *PathNotTreeError) Error() string {
// for an io/fs.FS-like interface.
//
// Labels: Life-Parent.
-func (fetcher *Fetcher) Path(root oid.ObjectID, parts []string) (tree.Entry, error) {
+func (fetcher *Fetcher) Path(root oid.ObjectID, parts [][]byte) (tree.Entry, error) {
if len(parts) == 0 {
return tree.Entry{}, ErrPathInvalid
}
diff --git a/object/fetch/reader.go b/object/fetch/reader.go
index 8baf1119..b1b4f7c2 100644
--- a/object/fetch/reader.go
+++ b/object/fetch/reader.go
@@ -10,7 +10,7 @@ import (
// exactReader reads one object's content stream
// and verifies that its header type matches wantType.
-func (fetcher *Fetcher) exactReader(id oid.ObjectID, wantType typ.Type) (io.ReadCloser, uint64, error) {
+func (fetcher *Fetcher) exactReader(id oid.ObjectID, wantType typ.Type) (io.ReadCloser, int, error) {
gotType, size, rc, err := fetcher.store.ReadReaderContent(id)
if err != nil {
return nil, 0, wrapObjectReadError(id, err)
diff --git a/object/fetch/treefs.go b/object/fetch/treefs.go
index da92af51..d12e3dd6 100644
--- a/object/fetch/treefs.go
+++ b/object/fetch/treefs.go
@@ -1,17 +1,16 @@
package fetch
import (
+ "bytes"
"errors"
"fmt"
"io"
"io/fs"
- "strings"
"time"
oid "lindenii.org/go/furgit/object/id"
"lindenii.org/go/furgit/object/tree"
"lindenii.org/go/furgit/object/tree/mode"
- "lindenii.org/go/lgo/intconv"
)
// TreeFS exposes one Git tree as an fs.FS view backed by a Fetcher.
@@ -49,12 +48,12 @@ var ErrGitlinkNotFile = fmt.Errorf("%w: object/fetch: gitlink entries are not re
// generic fs consumers classify it correctly.
var ErrIsDirectory = fmt.Errorf("%w: object/fetch: is a directory", fs.ErrInvalid)
-func splitPath(path string) []string {
+func splitPath(path string) [][]byte {
if len(path) == 0 {
return nil
}
- return strings.Split(path, "/")
+ return bytes.Split([]byte(path), []byte("/"))
}
type treeEntryValue struct {
@@ -69,7 +68,7 @@ func (entry treeEntryValue) isDir() bool {
return entry.mode == mode.Directory
}
-func (entry treeEntryValue) blobSize(fetcher *Fetcher) (uint64, error) {
+func (entry treeEntryValue) blobSize(fetcher *Fetcher) (int, error) {
return fetcher.Size(entry.objectID)
}
@@ -198,7 +197,7 @@ func (treeFS *TreeFS) Open(name string) (fs.File, error) {
entries := make([]fs.DirEntry, 0, len(tree.Object().Entries()))
for _, child := range tree.Object().Entries() {
childEntry := treeEntryValue{
- name: child.Name,
+ name: string(child.Name),
mode: child.Mode,
objectID: child.ID,
treeEntry: &child,
@@ -402,7 +401,7 @@ func (treeFS *TreeFS) resolvePath(op treeFSOp, name string) (treeEntryValue, err
}
return treeEntryValue{
- name: entry.Name,
+ name: string(entry.Name),
mode: entry.Mode,
objectID: entry.ID,
treeEntry: &entry,
@@ -434,10 +433,7 @@ func (treeFS *TreeFS) statEntry(entry treeEntryValue) (*treeFSInfo, error) {
return nil, err
}
- size, err = intconv.Uint64ToInt64(sz)
- if err != nil {
- return nil, fmt.Errorf("object/fetch: blob size overflows int64: %w", err)
- }
+ size = int64(sz)
}
var sys any
diff --git a/object/fetch/treefs_test.go b/object/fetch/treefs_test.go
index ba292276..05240823 100644
--- a/object/fetch/treefs_test.go
+++ b/object/fetch/treefs_test.go
@@ -35,12 +35,12 @@ func TestTreeFS(t *testing.T) {
}
subTreeID := writeTree(t, store, []tree.Entry{
- {Mode: mode.Executable, Name: "exec.sh", ID: execID},
+ {Mode: mode.Executable, Name: []byte("exec.sh"), ID: execID},
})
rootTreeID := writeTree(t, store, []tree.Entry{
- {Mode: mode.Regular, Name: "plain.txt", ID: plainID},
- {Mode: mode.Directory, Name: "dir", ID: subTreeID},
+ {Mode: mode.Regular, Name: []byte("plain.txt"), ID: plainID},
+ {Mode: mode.Directory, Name: []byte("dir"), ID: subTreeID},
})
commitID := writeCommit(t, store, rootTreeID)