Skip to content

Commit

Permalink
stack: add a way to get the commit from file revision
Browse files Browse the repository at this point in the history
Summary:
Used by an upcoming change to figure out the commit message of revs of a file
stack.

Reviewed By: evangrayk

Differential Revision: D48491774

fbshipit-source-id: 6aff67285d3c63a5695aaa7ef4eee4566ac052ff
  • Loading branch information
quark-zju authored and facebook-github-bot committed Aug 23, 2023
1 parent 54e7cdf commit 3e9c5cf
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions addons/isl/src/stackEdit/commitStackState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,31 @@ export class CommitStackState extends SelfUpdate<CommitStackRecord> {
.toArray();
}

/**
* Get the commit from a file stack revision.
* Returns undefined when rev is out of range, or the commit is "public" (ex. fileRev is 0).
*/
getCommitFromFileStackRev(fileIdx: number, fileRev: Rev): CommitState | undefined {
const commitRev = this.fileToCommit.get(FileIdx({fileIdx, fileRev}))?.rev;
if (commitRev == null || commitRev < 0) {
return undefined;
}
return unwrap(this.stack.get(commitRev));
}

/**
* Test if a file rev is "absent". An absent file is different from an empty file.
*/
isAbsentFromFileStackRev(fileIdx: number, fileRev: Rev): boolean {
const commitIdx = this.fileToCommit.get(FileIdx({fileIdx, fileRev}));
if (commitIdx == null) {
return true;
}
const {rev, path} = commitIdx;
const file = rev < 0 ? this.bottomFiles.get(path) : this.getFile(rev, path);
return file == null || isAbsent(file);
}

/** Extract utf-8 data from a file. */
getUtf8Data(file: FileState): string {
if (typeof file.data === 'string') {
Expand Down

0 comments on commit 3e9c5cf

Please sign in to comment.