walkers-mixin
This is part of the ES-Git project.
Install
npm install --save @es-git/walkers-mixin
Usage
Mix this in with an IObjectRepo.
This mixin provides ways to walk the repo, either along it's history or in the tree of one commit. This mixin uses async iterables
import objectsMixin from '@es-git/objects-mixin';
import walkersMixin from '@es-git/walkers-mixin';
import MemoryRepo from '@es-git/memory-repo';
const Repo = mix(MemoryRepo)
.with(objectsMixin)
.with(walkersMixin);
const repo = new Repo();
for await(const commit of repo.walkComits(await repo.getRef('refs/heads/master'))){
console.log(commit.message);
}
for await(const fileOrFolder of repo.walkTree(await repo.getRef('refs/heads/master'))){
console.log(fileOrFolder.path.join('/'));
}
for await(const file of repo.listFiles(await repo.getRef('refs/heads/master'))){
console.log(file.path.join('/'));
}
Interfaces
IWalkersRepo
interface IWalkersRepo {
walkCommits(...hash : Hash[]) : AsyncIterableIterator<HashAndCommitObject>
walkTree(hash : Hash) : AsyncIterableIterator<HashModePath>
listFiles(hash: Hash): AsyncIterableIterator<HashModePath>
}
type Hash = string;
type HashAndCommitObject = {
readonly hash : Hash
readonly commit : CommitObject
}
type HashModePath = {
readonly hash : Hash
readonly mode : Mode
readonly path : string[]
}