aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/git/diff.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/server/src/git/diff.ts')
-rw-r--r--packages/server/src/git/diff.ts21
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));
}