| 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 {Author, DateTuple, Hash, RepoPath} from './common'; |
| 9 | |
| 10 | /* Types for the `debugimportstack` and `debugoutputstack` commands. */ |
| 11 | |
| 12 | /** |
| 13 | * Placeholder commit hash to identify "to be created" commits. |
| 14 | * Starts with ":". Can be referred by "parents" of other commits. |
| 15 | */ |
| 16 | export type Mark = string; |
| 17 | |
| 18 | /** Matches output of debugexportstack. See debugstack.py. */ |
| 19 | export type ExportStack = ExportCommit[]; |
| 20 | |
| 21 | export type ExportCommit = { |
| 22 | /** `true` for commits explicitly requested via debugstack command. */ |
| 23 | requested: boolean; |
| 24 | /** Commit hash. `ffffffffffffffffffffffffffffffffffffffff` (`node.wdirhex`) means the working copy. */ |
| 25 | node: Hash; |
| 26 | author: Author; |
| 27 | date: DateTuple; |
| 28 | /* Commit message. */ |
| 29 | text: string; |
| 30 | /** `true` for public commits. */ |
| 31 | immutable: boolean; |
| 32 | parents?: Hash[]; |
| 33 | /** Files changed by this commit. `null` means the file is deleted. */ |
| 34 | files?: {[path: RepoPath]: ExportFile | null}; |
| 35 | relevantFiles?: {[path: RepoPath]: ExportFile | null}; |
| 36 | }; |
| 37 | |
| 38 | export type ExportFile = { |
| 39 | /** UTF-8 content. */ |
| 40 | data?: string; |
| 41 | /** Binary content encoded in base85. */ |
| 42 | dataBase85?: string; |
| 43 | /** Reference to other files. */ |
| 44 | dataRef?: {node: Hash; path: RepoPath}; |
| 45 | /** If present, this file is copied (or renamed) from another file. */ |
| 46 | copyFrom?: RepoPath; |
| 47 | /** 'x': executable. 'l': symlink. 'm': submodule. */ |
| 48 | flags?: FileFlag; |
| 49 | }; |
| 50 | |
| 51 | /** Matches input of debugimportstack. See debugstack.py. */ |
| 52 | export type ImportStack = ImportAction[]; |
| 53 | |
| 54 | /** |
| 55 | * - 'x': executable. |
| 56 | * - 'l': symlink. |
| 57 | * - 'm': submodule. |
| 58 | * - 'a': absent (deleted), only used in ISL, not by debugimportstack. |
| 59 | * - '.': unchanged, only used by debugimportstack. |
| 60 | */ |
| 61 | export type FileFlag = '' | 'x' | 'l' | 'm' | 'a' | '.'; |
| 62 | |
| 63 | export type ImportAction = |
| 64 | | ['commit', ImportCommit] |
| 65 | | ['amend', ImportAmendCommit] |
| 66 | | ['goto', ImportGoto] |
| 67 | | ['reset', ImportReset] |
| 68 | | ['hide', ImportHide] |
| 69 | | ['write', {[path: RepoPath]: ExportFile | '.' | null}]; |
| 70 | |
| 71 | export type ImportCommit = { |
| 72 | /** Placeholder commit hash. Must start with ":". */ |
| 73 | mark: Mark; |
| 74 | author?: Author; |
| 75 | date?: DateTuple; |
| 76 | /** Commit message. */ |
| 77 | text: string; |
| 78 | parents: (Hash | Mark)[]; |
| 79 | predecessors?: (Hash | Mark)[]; |
| 80 | /** Why predecessors are obsoleted? For example, 'amend', 'split', 'histedit'. */ |
| 81 | operation?: string; |
| 82 | files: {[path: RepoPath]: ExportFile | '.' | null}; |
| 83 | }; |
| 84 | |
| 85 | /** Amend a commit. Similar to `ImportCommit` but many fields are optional. */ |
| 86 | export type ImportAmendCommit = { |
| 87 | /** Commit to amend. */ |
| 88 | node: Hash; |
| 89 | /** Placeholder commit hash. Must start with ":". */ |
| 90 | mark: Mark; |
| 91 | author?: Author; |
| 92 | date?: DateTuple; |
| 93 | /** Commit message. */ |
| 94 | text?: string; |
| 95 | parents?: (Hash | Mark)[]; |
| 96 | predecessors?: (Hash | Mark)[]; |
| 97 | /** Why predecessors are obsoleted? For example, 'amend', 'split', 'histedit'. */ |
| 98 | operation?: string; |
| 99 | files?: {[path: RepoPath]: ExportFile | '.' | null}; |
| 100 | }; |
| 101 | |
| 102 | /** Update the "current commit" without changing the working copy. */ |
| 103 | export type ImportReset = {mark: Mark}; |
| 104 | |
| 105 | /** Checkout the given commit. */ |
| 106 | export type ImportGoto = {mark: Mark}; |
| 107 | |
| 108 | /** Hide commits if they do not have visible descendants. */ |
| 109 | export type ImportHide = {nodes: Hash[]}; |
| 110 | |
| 111 | /** Matches output of debugimportstack. See debugstack.py. */ |
| 112 | export type ImportedStack = ImportedCommit[]; |
| 113 | |
| 114 | /** The given `mark` has a known commit hash `node`. */ |
| 115 | export type ImportedCommit = {node: Hash; mark: Mark}; |
| 116 | |