<commit_before>package mount

import (
	"os"

	"bazil.org/fuse"
	"bazil.org/fuse/fs"
	"github.com/sam701/asamstore/asamclient/index"
	"github.com/sam701/asamstore/asamclient/schema"
	"golang.org/x/net/context"
)

type rootNode struct {
	name    string
	ref     schema.BlobRef
	commits []*index.Commit
}

func (r *rootNode) Attr(ctx context.Context, attr *fuse.Attr) error {
	attr.Mode = os.ModeDir | 0700
	attr.Uid = userId
	attr.Gid = groupId
	return nil
}

func (r *rootNode) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
	res := []fuse.Dirent{}
	if r.commits == nil {
		r.commits = bsIndex.GetCommits(r.ref)
	}
	for _, c := range r.commits {
		res = append(res, fuse.Dirent{
			Name: c.CommitTime,
			Type: fuse.DT_Dir,
		})
	}
	return res, nil
}

func (r *rootNode) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (fs.Node, error) {
	for _, c := range r.commits {
		if c.CommitTime == req.Name {
			dirSchema := bsClient.GetSchema(c.Content)
			if dirSchema == nil {
				panic("No such blob: " + c.Content)
			}
			return newDir(c.CommitTime, dirSchema.UnixPermission, dirSchema.DirEntries), nil
		}
	}
	return nil, fuse.ENOENT
}<commit_msg>rootNode.lookup loads commits, as well<commit_after>package mount

import (
	"os"

	"bazil.org/fuse"
	"bazil.org/fuse/fs"
	"github.com/sam701/asamstore/asamclient/index"
	"github.com/sam701/asamstore/asamclient/schema"
	"golang.org/x/net/context"
)

type rootNode struct {
	name    string
	ref     schema.BlobRef
	commits []*index.Commit
}

func (r *rootNode) Attr(ctx context.Context, attr *fuse.Attr) error {
	attr.Mode = os.ModeDir | 0700
	attr.Uid = userId
	attr.Gid = groupId
	return nil
}

func (r *rootNode) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
	res := []fuse.Dirent{}

	for _, c := range r.getCommits() {
		res = append(res, fuse.Dirent{
			Name: c.CommitTime,
			Type: fuse.DT_Dir,
		})
	}
	return res, nil
}

func (r *rootNode) getCommits() []*index.Commit {
	if r.commits == nil {
		r.commits = bsIndex.GetCommits(r.ref)
	}
	return r.commits
}

func (r *rootNode) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (fs.Node, error) {
	for _, c := range r.getCommits() {
		if c.CommitTime == req.Name {
			dirSchema := bsClient.GetSchema(c.Content)
			if dirSchema == nil {
				panic("No such blob: " + c.Content)
			}
			return newDir(c.CommitTime, dirSchema.UnixPermission, dirSchema.DirEntries), nil
		}
	}
	return nil, fuse.ENOENT
}
{'fraction_non_alphanumeric': 0.1449859041482078, 'fraction_numerical': 0.008054772452678213, 'mean_word_length': 3.7045454545454546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1273417', 'n_tokens_mistral': 1057, 'n_tokens_neox': 984, 'n_words': 207}