| 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 | |
| 8 | import type {Dag} from '../previews'; |
| 9 | import type {ExactRevset, OptimisticRevset, SucceedableRevset} from '../types'; |
| 10 | |
| 11 | import {latestSuccessor} from '../successionUtils'; |
| 12 | import {exactRevset} from '../types'; |
| 13 | import {Operation} from './Operation'; |
| 14 | |
| 15 | export class RebaseAllDraftCommitsOperation extends Operation { |
| 16 | constructor( |
| 17 | private timeRangeDays: number | undefined, |
| 18 | private destination: SucceedableRevset | ExactRevset | OptimisticRevset, |
| 19 | ) { |
| 20 | super('RebaseAllDraftCommitsOperation'); |
| 21 | } |
| 22 | |
| 23 | static opName = 'Rebase all draft commits'; |
| 24 | |
| 25 | getArgs() { |
| 26 | return [ |
| 27 | 'rebase', |
| 28 | '-s', |
| 29 | exactRevset( |
| 30 | this.timeRangeDays == null ? 'draft()' : `draft() & date(-${this.timeRangeDays})`, |
| 31 | ), |
| 32 | '-d', |
| 33 | this.destination, |
| 34 | ]; |
| 35 | } |
| 36 | |
| 37 | optimisticDag(dag: Dag): Dag { |
| 38 | const dest = dag.resolve(latestSuccessor(dag, this.destination))?.hash; |
| 39 | const draft = dag.draft(); |
| 40 | return dag.rebase(draft, dest); |
| 41 | } |
| 42 | } |
| 43 | |