aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/git/blob.ts
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-07-26 17:33:54 +0200
committerHampusM <hampus@hampusmat.com>2021-07-26 17:33:54 +0200
commita737bc4695f99b05a3c4807c88fc30b1a1eb89b5 (patch)
tree4ca8f9955a80a09a508c55f86daeb2aba2ae64ac /packages/server/src/git/blob.ts
parent35151a0283141ddac96f8cc71b59cd1030e31f3d (diff)
Refactored the git tree, tree entry & blob classes
Diffstat (limited to 'packages/server/src/git/blob.ts')
-rw-r--r--packages/server/src/git/blob.ts24
1 files changed, 18 insertions, 6 deletions
diff --git a/packages/server/src/git/blob.ts b/packages/server/src/git/blob.ts
index e44a979..ef9f9ab 100644
--- a/packages/server/src/git/blob.ts
+++ b/packages/server/src/git/blob.ts
@@ -1,17 +1,29 @@
-import { TreeEntry as NodeGitTreeEntry } from "nodegit";
import { BlobError, createError } from "./error";
+import { Tree } from "./tree";
+import { BlobTreeEntry } from "./tree_entry";
export class Blob {
- private _ng_tree_entry: NodeGitTreeEntry;
+ private _tree_entry: BlobTreeEntry;
- constructor(entry: NodeGitTreeEntry) {
- this._ng_tree_entry = entry;
+ public path;
+
+ constructor(entry: BlobTreeEntry, path: string) {
+ this._tree_entry = entry;
+
+ this.path = path;
}
public async content(): Promise<string> {
- if(!this._ng_tree_entry.isBlob()) {
+ return this._tree_entry.content();
+ }
+
+ public static async fromPath(tree: Tree, path: string): Promise<Blob> {
+ const entry = await tree.find(path);
+
+ if(!(entry instanceof BlobTreeEntry)) {
throw(createError(BlobError, 500, "Not a blob"));
}
- return this._ng_tree_entry.isBlob() ? (await this._ng_tree_entry.getBlob()).toString() : "";
+
+ return new Blob(entry, path);
}
} \ No newline at end of file