1.1 KB39 lines
Blame
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8import type {Dag} from '../previews';
9import type {ExactRevset, OptimisticRevset, SucceedableRevset} from '../types';
10
11import {latestSuccessor} from '../successionUtils';
12import {Operation} from './Operation';
13
14export class BulkRebaseOperation extends Operation {
15 constructor(
16 private sources: Array<SucceedableRevset | ExactRevset | OptimisticRevset>,
17 private destination: SucceedableRevset | ExactRevset | OptimisticRevset,
18 ) {
19 super('BulkRebaseOperation');
20 }
21
22 static opName = 'Bulk rebase commits';
23
24 getArgs() {
25 return [
26 'rebase',
27 ...this.sources.map(source => ['--rev', source]).flat(),
28 '-d',
29 this.destination,
30 ];
31 }
32
33 optimisticDag(dag: Dag): Dag {
34 const dest = dag.resolve(latestSuccessor(dag, this.destination))?.hash;
35 const source = this.sources.map(s => latestSuccessor(dag, s));
36 return dag.rebase(source, dest);
37 }
38}
39