diff options
author | HampusM <hampus@hampusmat.com> | 2021-08-07 19:16:01 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-08-07 19:16:01 +0200 |
commit | 17c20d77600407209908de5541415f2c4a85f5e3 (patch) | |
tree | d318292028004251b14f9fb87fa1a85838da906d /packages | |
parent | b2152da8f4bea1a655f7c9c7c07b24c041173f0a (diff) |
Implemented tree entry commit history
Diffstat (limited to 'packages')
-rw-r--r-- | packages/server/src/git/tree_entry.ts | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/packages/server/src/git/tree_entry.ts b/packages/server/src/git/tree_entry.ts index 22de716..182543e 100644 --- a/packages/server/src/git/tree_entry.ts +++ b/packages/server/src/git/tree_entry.ts @@ -1,11 +1,8 @@ import { Commit } from "./commit"; import { Revwalk as NodeGitRevwalk, TreeEntry as NodeGitTreeEntry } from "nodegit"; import { Repository } from "./repository"; -import { dirname } from "path"; -import { findAsync } from "./misc"; import { Tree } from "./tree"; import { Blob } from "./blob"; -import { createError, TreeError } from "./error"; /** * The core structure of a tree entry @@ -43,6 +40,27 @@ export abstract class BaseTreeEntry { return new Commit(this._owner, file_hist[0].commit); } + + /** + * Returns the tree entry's commit history + * + * @returns An array of commit instances + */ + public async history(count?: number): Promise<Commit[]> { + const rev_walk = NodeGitRevwalk.create(this._owner.ng_repository); + rev_walk.pushRef(`refs/heads/${this._owner.branch_name}`); + + const commit_cnt = (await rev_walk.getCommitsUntil(() => true)).length; + + rev_walk.pushRef(`refs/heads/${this._owner.branch_name}`); + const file_hist = await rev_walk.fileHistoryWalk(this.path, commit_cnt); + + const commit_history = file_hist.map(hist_entry => new Commit(this._owner, hist_entry.commit)); + + return count + ? commit_history.slice(0, count) + : commit_history; + } } /** |