diff options
author | HampusM <hampus@hampusmat.com> | 2021-07-27 13:18:42 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-07-27 13:18:42 +0200 |
commit | f6a5fe05c887a658c20257d2ef6bf2780f792873 (patch) | |
tree | 9ee4b42ed04b3fe7decdac10b20ec96ca764d378 /packages/server/src/git/diff.ts | |
parent | 69c58c94bd8cc0d469ae301931d4571aca84851a (diff) |
Refactored the backend a bit & added TSDoc/JSDoc comments to the diff class
Diffstat (limited to 'packages/server/src/git/diff.ts')
-rw-r--r-- | packages/server/src/git/diff.ts | 21 |
1 files changed, 20 insertions, 1 deletions
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<string> { return String(await this._ng_diff.toBuf(1)); } - public async patchHeaderData(): Promise<PatchHeaderData> { + /** + * Returns information about patch headers + * + * @returns The indexes and lengths of patch headers + */ + public async patchHeaderData(): Promise<Omit<PatchHeaderData, "last">> { 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 { }, <PatchHeaderData>{ indexes: [], lengths: [], last: null }); } + /** + * Returns the diff's patches + * + * @returns An array of patch instances + */ public async patches(): Promise<Patch[]> { return (await this._ng_diff.patches()).map((patch, index) => new Patch(this, patch, index)); } |