Skip to content

Commit

Permalink
stackEdit: allow bypassing file stack length check for setFileStack
Browse files Browse the repository at this point in the history
Summary: This is used by the next change.

Reviewed By: muirdm

Differential Revision: D67612069

fbshipit-source-id: 57db4727a7f9669a83c33a267a0f58fce2ae07b7
  • Loading branch information
quark-zju authored and facebook-github-bot committed Dec 30, 2024
1 parent 3ab2199 commit 2d22f73
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions addons/isl/src/stackEdit/commitStackState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1364,11 +1364,22 @@ export class CommitStackState extends SelfUpdate<CommitStackRecord> {
return state.buildFileStacks();
}

/** Replace a file stack. */
/** Replace a file stack. Throws if the new stack has a different length. */
setFileStack(fileIdx: number, stack: FileStackState): CommitStackState {
return this.setFileStackInternal(fileIdx, stack, (oldStack, newStack) => {
assert(oldStack.revLength === newStack.revLength, 'fileStack length mismatch');
});
}

/** Internal use: replace a file stack. */
private setFileStackInternal(
fileIdx: number,
stack: FileStackState,
check?: (oldStack: FileStackState, newStack: FileStackState) => void,
): CommitStackState {
const oldStack = this.fileStacks.get(fileIdx);
assert(oldStack != null, 'fileIdx out of range');
assert(oldStack.revLength === stack.revLength, 'fileStack length mismatch');
check?.(oldStack, stack);
const newInner = this.inner.setIn(['fileStacks', fileIdx], stack);
return new CommitStackState(undefined, newInner);
}
Expand Down

0 comments on commit 2d22f73

Please sign in to comment.