From f6a5fe05c887a658c20257d2ef6bf2780f792873 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 27 Jul 2021 13:18:42 +0200 Subject: Refactored the backend a bit & added TSDoc/JSDoc comments to the diff class --- packages/server/src/git/diff.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'packages/server/src/git/diff.ts') diff --git a/packages/server/src/git/diff.ts b/packages/server/src/git/diff.ts index 2e88609..d3b788c 100644 --- a/packages/server/src/git/diff.ts +++ b/packages/server/src/git/diff.ts @@ -7,18 +7,32 @@ type PatchHeaderData = { last: number | null } +/** + * A representation of a diff + */ export class Diff { private _ng_diff: NodeGitDiff; + /** + * @param diff A Nodegit diff + */ constructor(diff: NodeGitDiff) { this._ng_diff = diff; } + /** + * Returns all of the diff's patches in a raw format + */ public async rawPatches(): Promise { return String(await this._ng_diff.toBuf(1)); } - public async patchHeaderData(): Promise { + /** + * Returns information about patch headers + * + * @returns The indexes and lengths of patch headers + */ + public async patchHeaderData(): Promise> { const raw_patches = (await this.rawPatches()).split("\n"); const patch_headers = String(await this._ng_diff.toBuf(2)).split("\n"); @@ -42,6 +56,11 @@ export class Diff { }, { indexes: [], lengths: [], last: null }); } + /** + * Returns the diff's patches + * + * @returns An array of patch instances + */ public async patches(): Promise { return (await this._ng_diff.patches()).map((patch, index) => new Patch(this, patch, index)); } -- cgit v1.2.3-18-g5258