Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit d346525

Browse files
author
sona-tar
committed
Support non packed git objects for Iterator
1 parent 25e4a41 commit d346525

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

storage/filesystem/internal/dotgit/dotgit.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package dotgit
22

33
import (
44
"errors"
5+
"fmt"
56
"os"
7+
"regexp"
68
"strings"
79

810
"gopkg.in/src-d/go-git.v4/core"
@@ -102,6 +104,42 @@ func (d *DotGit) Idxfile() (fs.FS, string, error) {
102104
return nil, "", ErrIdxNotFound
103105
}
104106

107+
func (d *DotGit) Objectfiles() (fs.FS, []core.Hash, error) {
108+
dotGitobjcts := d.fs.Join(d.path, "objects")
109+
files, err := d.fs.ReadDir(dotGitobjcts)
110+
if err != nil {
111+
return nil, nil, err
112+
}
113+
114+
var objDirs []string
115+
reDir, _ := regexp.Compile("[a-z0-9]{2}")
116+
for _, f := range files {
117+
if f.IsDir() && reDir.MatchString(f.Name()) {
118+
objDirs = append(objDirs, f.Name())
119+
}
120+
}
121+
122+
var objects []core.Hash
123+
reObj, _ := regexp.Compile("[a-z0-9]{38}")
124+
for _, dir := range objDirs {
125+
objs, err := d.fs.ReadDir(d.fs.Join(dotGitobjcts, dir))
126+
127+
if err != nil {
128+
return nil, nil, err
129+
}
130+
131+
for _, obj := range objs {
132+
if reObj.MatchString(obj.Name()) {
133+
name := dir + obj.Name()
134+
fmt.Println(name)
135+
objects = append(objects, core.NewHash(name))
136+
}
137+
}
138+
}
139+
140+
return d.fs, objects, nil
141+
}
142+
105143
func (d *DotGit) Objectfile(h core.Hash) (fs.FS, string, error) {
106144
hash := h.String()
107145
objFile := d.fs.Join(d.path, "objects", hash[0:2], hash[2:40])

storage/filesystem/object.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,23 @@ func (s *ObjectStorage) getFromPackfile(h core.Hash) (core.Object, error) {
137137
func (s *ObjectStorage) Iter(t core.ObjectType) (core.ObjectIter, error) {
138138
var objects []core.Object
139139

140+
_, hashes, err := s.dir.Objectfiles()
141+
if err != nil {
142+
return nil, err
143+
}
144+
145+
for _, hash := range hashes {
146+
object, err := s.getFromObject(hash)
147+
if err != nil {
148+
return nil, err
149+
}
150+
if object.Type() == t {
151+
objects = append(objects, object)
152+
}
153+
}
154+
140155
for hash := range s.index {
141-
object, err := s.Get(hash)
156+
object, err := s.getFromPackfile(hash)
142157
if err != nil {
143158
return nil, err
144159
}

0 commit comments

Comments
 (0)