diff options
author | HampusM <hampus@hampusmat.com> | 2021-08-06 18:37:37 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-08-06 18:37:37 +0200 |
commit | d978be0a3bbf650cd55543570ed18fcb015fc08d (patch) | |
tree | ab1e48503b37a6562614bb410af4f5df8ca6f76d /packages/server/src/git/tree_entry.ts | |
parent | 8c6a59cd766fead4998c957d86a0e33fd58d1cde (diff) |
Simplified getting tree entries's last commits
Diffstat (limited to 'packages/server/src/git/tree_entry.ts')
-rw-r--r-- | packages/server/src/git/tree_entry.ts | 20 |
1 files 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 +} |