From a737bc4695f99b05a3c4807c88fc30b1a1eb89b5 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 26 Jul 2021 17:33:54 +0200 Subject: Refactored the git tree, tree entry & blob classes --- packages/server/src/git/tree.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'packages/server/src/git/tree.ts') diff --git a/packages/server/src/git/tree.ts b/packages/server/src/git/tree.ts index 2cec528..ca645ef 100644 --- a/packages/server/src/git/tree.ts +++ b/packages/server/src/git/tree.ts @@ -1,23 +1,25 @@ -import { Blob } from "./blob"; import { Tree as NodeGitTree } from "nodegit"; import { Repository } from "./repository"; -import { TreeEntry } from "./tree_entry"; +import { BaseTreeEntry, createTreeEntry, TreeEntry } from "./tree_entry"; import { createError, TreeError } from "./error"; export class Tree { - private _ng_tree: NodeGitTree; - private _owner: Repository; + protected _owner: Repository; + protected _ng_tree: NodeGitTree; + + public path: string; constructor(owner: Repository, tree: NodeGitTree) { - this._ng_tree = tree; this._owner = owner; + this._ng_tree = tree; + this.path = tree.path(); } public entries(): TreeEntry[] { return this._ng_tree.entries().map(entry => new TreeEntry(this._owner, entry)); } - public async find(path: string): Promise { + public async find(path: string): Promise { const entry = await this._ng_tree.getEntry(path).catch(err => { if(err.errno === -3) { throw(createError(TreeError, 404, "Path not found")); @@ -25,7 +27,7 @@ export class Tree { throw(createError(TreeError, 500, "Failed to get tree path")); }); - return entry.isBlob() ? new Blob(entry) : new Tree(this._owner, await entry.getTree()); + return createTreeEntry(this._owner, entry); } public findExists(path: string): Promise { -- cgit v1.2.3-18-g5258