addons/isl/src/operations/BulkRebaseOperation.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {Dag} from '../previews';
b69ab319import type {ExactRevset, OptimisticRevset, SucceedableRevset} from '../types';
b69ab3110
b69ab3111import {latestSuccessor} from '../successionUtils';
b69ab3112import {Operation} from './Operation';
b69ab3113
b69ab3114export class BulkRebaseOperation extends Operation {
b69ab3115 constructor(
b69ab3116 private sources: Array<SucceedableRevset | ExactRevset | OptimisticRevset>,
b69ab3117 private destination: SucceedableRevset | ExactRevset | OptimisticRevset,
b69ab3118 ) {
b69ab3119 super('BulkRebaseOperation');
b69ab3120 }
b69ab3121
b69ab3122 static opName = 'Bulk rebase commits';
b69ab3123
b69ab3124 getArgs() {
b69ab3125 return [
b69ab3126 'rebase',
b69ab3127 ...this.sources.map(source => ['--rev', source]).flat(),
b69ab3128 '-d',
b69ab3129 this.destination,
b69ab3130 ];
b69ab3131 }
b69ab3132
b69ab3133 optimisticDag(dag: Dag): Dag {
b69ab3134 const dest = dag.resolve(latestSuccessor(dag, this.destination))?.hash;
b69ab3135 const source = this.sources.map(s => latestSuccessor(dag, s));
b69ab3136 return dag.rebase(source, dest);
b69ab3137 }
b69ab3138}