1.5 KB45 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 {YOU_ARE_HERE_VIRTUAL_COMMIT} from '../dag/virtualCommit';
12import {t} from '../i18n';
13import {CommitPreview} from '../previews';
14import {latestSuccessor} from '../successionUtils';
15import {GotoBaseOperation} from './GotoBaseOperation';
16
17export class GotoOperation extends GotoBaseOperation {
18 constructor(protected destination: SucceedableRevset | ExactRevset | OptimisticRevset) {
19 super(destination);
20 }
21
22 getInitialInlineProgress(): [hash: string, message: string][] {
23 return [[YOU_ARE_HERE_VIRTUAL_COMMIT.hash, t('moving...')]];
24 }
25
26 optimisticDag(dag: Dag): Dag {
27 const headCommitHash = dag.resolve('.')?.hash;
28 if (headCommitHash == null) {
29 return dag;
30 }
31 const dest = dag.resolve(latestSuccessor(dag, this.destination));
32 const src = dag.get(headCommitHash);
33 if (dest == null || src == null || dest.hash === src.hash) {
34 return dag;
35 }
36 return dag.replaceWith([src.hash, dest.hash], (h, c) => {
37 const isDest = h === dest.hash;
38 const previewType = isDest
39 ? CommitPreview.GOTO_DESTINATION
40 : CommitPreview.GOTO_PREVIOUS_LOCATION;
41 return c?.merge({isDot: isDest, previewType});
42 });
43 }
44}
45