aboutsummaryrefslogtreecommitdiff
path: root/src/api/git.js
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-05-30 12:19:49 +0200
committerHampusM <hampus@hampusmat.com>2021-05-30 12:19:49 +0200
commitb5064a73c9cf7e737fe620eeb38040d683dbf87d (patch)
tree10ba6608188ba7dba8b6ecac00b9e279057c305a /src/api/git.js
parent6edf567693ab885bcbab0a894001e1bcbca939c1 (diff)
Added a tree api endpoint
Diffstat (limited to 'src/api/git.js')
-rw-r--r--src/api/git.js47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/api/git.js b/src/api/git.js
index 97d38ac..f0c2783 100644
--- a/src/api/git.js
+++ b/src/api/git.js
@@ -315,9 +315,54 @@ function connectToGitHTTPBackend(base_dir, req, reply)
git_pack.on("close", () => reply.raw.end());
}
+function getTreeEntries(entries)
+{
+ return entries.reduce((acc, entry) =>
+ {
+ return acc.then((obj) =>
+ {
+ const basename = path.parse(entry.path()).base;
+
+ if(entry.isBlob()) {
+ console.log("blob " + entry.path());
+ obj[basename] = { oid: entry.oid(), type: "blob" };
+ return obj;
+ }
+
+ if(entry.isTree()) {
+ console.log("tree " + entry.path());
+ return entry.getTree().then((tree) =>
+ {
+ console.log("LMAO " + tree.path());
+ return getTreeEntries(tree.entries()).then((tree_entries) =>
+ {
+ obj[basename] = { oid: entry.oid(), type: "tree", tree: tree_entries };
+ return obj;
+ });
+ });
+ }
+ });
+
+ }, Promise.resolve({}));
+}
+
+async function getTree(base_dir, repo_name)
+{
+ repo_name = addRepoDirSuffix(repo_name);
+
+ const repo = await git.Repository.openBare(`${base_dir}/${repo_name}`);
+ const master_commit = await repo.getMasterCommit();
+
+ const tree = await master_commit.getTree();
+ const entries = tree.entries();
+
+ return await getTreeEntries(entries);
+}
+
module.exports.getLog = getLog;
module.exports.getRepos = getRepos;
module.exports.getRepoFile = getRepoFile;
module.exports.getCommit = getCommit;
module.exports.doesCommitExist = doesCommitExist;
-module.exports.connectToGitHTTPBackend = connectToGitHTTPBackend; \ No newline at end of file
+module.exports.connectToGitHTTPBackend = connectToGitHTTPBackend;
+module.exports.getTree = getTree; \ No newline at end of file