Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High level API #140

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Mimic a repo structure in the memory
besicj committed Nov 28, 2017
commit 33c6df173038fba1ca9706faca1f75597e8bc573
47 changes: 23 additions & 24 deletions mixins/high-level.js
Original file line number Diff line number Diff line change
@@ -127,41 +127,40 @@ function highLevel(repo, uName, uPass, hostName) {
repo.loadAs('commit', refHash, function(err, commit) {
if (commit === undefined) { return callback(); }

var files = [];
var repoStructure = {};
repo.treeWalk(commit.tree, function(err, item) {
/*
{
'/': {
mode: xxx,
hash: xzz,
'folder 1': {
mode: xxx,
hash: xzz,
text.txt: {
mode: xxx,
hash: xzz,
content: 'asasgfasgagga'
}
}
}
}
*/
function collectFiles(err, object) {
if (object !== undefined) {
var temp = repoStructure;
var loadType = object.mode === 16384 ? 'tree' : 'text';
console.log(object);
var pathArray = object.path.split('/').filter(function(element) {
return element.length !== 0;
return element.length > 0;
});

console.log(pathArray);
pathArray = ['/'].concat(pathArray);

repo.loadAs(loadType, object.hash, function(err, content) {
//console.log(content);
//files.push(content);
pathArray.forEach(function(element) {
if (temp.hasOwnProperty(element)) {
temp = temp[element]
return true;
}

temp[element] = {
hash: object.hash,
mode: object.mode,
path: object.path
};

if (loadType === 'text') {
temp[element].content = content;
}
});

item.read(collectFiles);
});
} else {
return callback(files);
return callback(repoStructure);
}
}