From d978be0a3bbf650cd55543570ed18fcb015fc08d Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 6 Aug 2021 18:37:37 +0200 Subject: Simplified getting tree entries's last commits --- packages/server/src/git/tree_entry.ts | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/packages/server/src/git/tree_entry.ts b/packages/server/src/git/tree_entry.ts index 84f36dd..22de716 100644 --- a/packages/server/src/git/tree_entry.ts +++ b/packages/server/src/git/tree_entry.ts @@ -36,22 +36,12 @@ export abstract class BaseTreeEntry { const rev_walk = NodeGitRevwalk.create(this._owner.ng_repository); rev_walk.pushRef(`refs/heads/${this._owner.branch_name}`); - const commits = await rev_walk.getCommitsUntil(() => true); + const commit_cnt = (await rev_walk.getCommitsUntil(() => true)).length; - const latest_commit = await findAsync(commits, async commit => { - const diff = await commit.getDiff(); - const patches = await diff[0].patches(); - - return Boolean(this instanceof TreeEntry - ? patches.find(patch => dirname(patch.newFile().path()).startsWith(this.path)) - : patches.find(patch => patch.newFile().path() === this.path)); - }); - - if(!latest_commit) { - throw(createError(TreeError, 500, `Failed to get the latest commit of tree entry '${this.path}'!`)); - } + rev_walk.pushRef(`refs/heads/${this._owner.branch_name}`); + const file_hist = await rev_walk.fileHistoryWalk(this.path, commit_cnt); - return new Commit(this._owner, latest_commit); + return new Commit(this._owner, file_hist[0].commit); } } @@ -94,4 +84,4 @@ export function createTreeEntry(owner: Repository, entry: NodeGitTreeEntry): Bas return entry.isBlob() ? new BlobTreeEntry(owner, entry) : new TreeEntry(owner, entry); -} \ No newline at end of file +} -- cgit v1.2.3-18-g5258