| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import type {List, RecordOf} from 'immutable'; |
| b69ab31 | | | 9 | import type {InternalTypes} from '../InternalTypes'; |
| b69ab31 | | | 10 | import type {CommitPreview, WithPreviewType} from '../previews'; |
| b69ab31 | | | 11 | import type {CommitRev} from '../stackEdit/commitStackState'; |
| b69ab31 | | | 12 | import type { |
| b69ab31 | | | 13 | CommitInfo, |
| b69ab31 | | | 14 | CommitPhaseType, |
| b69ab31 | | | 15 | Hash, |
| b69ab31 | | | 16 | RepoRelativePath, |
| b69ab31 | | | 17 | StableCommitMetadata, |
| b69ab31 | | | 18 | SuccessorInfo, |
| b69ab31 | | | 19 | } from '../types'; |
| b69ab31 | | | 20 | |
| b69ab31 | | | 21 | import {Record} from 'immutable'; |
| b69ab31 | | | 22 | import {SelfUpdate} from 'shared/immutableExt'; |
| b69ab31 | | | 23 | |
| b69ab31 | | | 24 | type DagExt = { |
| b69ab31 | | | 25 | /** Distance ancestors that are treated as direct parents. */ |
| b69ab31 | | | 26 | ancestors?: List<Hash>; |
| b69ab31 | | | 27 | |
| b69ab31 | | | 28 | /** |
| b69ab31 | | | 29 | * Insertion batch. Larger: later inserted. |
| b69ab31 | | | 30 | * All 'sl log' commits share a same initial number. |
| b69ab31 | | | 31 | * Later previews might have larger numbers. |
| b69ab31 | | | 32 | * Used for sorting. |
| b69ab31 | | | 33 | */ |
| b69ab31 | | | 34 | seqNumber?: number; |
| b69ab31 | | | 35 | |
| b69ab31 | | | 36 | /** If true, this is a virtual "You are here" commit. */ |
| b69ab31 | | | 37 | isYouAreHere?: boolean; |
| b69ab31 | | | 38 | |
| b69ab31 | | | 39 | /** If constructed from a "CommitStack", the "Rev" of the commit. */ |
| b69ab31 | | | 40 | stackRev?: CommitRev; |
| b69ab31 | | | 41 | }; |
| b69ab31 | | | 42 | |
| b69ab31 | | | 43 | // Note: There are some non-immutable containers (Array) in `CommitInfo` |
| b69ab31 | | | 44 | // such as bookmarks. Since the "commitInfos" are "normalized" by |
| b69ab31 | | | 45 | // `reuseEqualObjects`. Those non-immutable properties should still |
| b69ab31 | | | 46 | // compare fine. |
| b69ab31 | | | 47 | type CommitInfoExtProps = CommitInfo & WithPreviewType & DagExt; |
| b69ab31 | | | 48 | |
| b69ab31 | | | 49 | const CommitInfoExtRecord = Record<CommitInfoExtProps>({ |
| b69ab31 | | | 50 | title: '', |
| b69ab31 | | | 51 | hash: '', |
| b69ab31 | | | 52 | parents: [], |
| b69ab31 | | | 53 | grandparents: [], |
| b69ab31 | | | 54 | phase: 'draft', |
| b69ab31 | | | 55 | isDot: false, |
| b69ab31 | | | 56 | author: '', |
| b69ab31 | | | 57 | date: new Date(0), |
| b69ab31 | | | 58 | description: '', |
| b69ab31 | | | 59 | bookmarks: [], |
| b69ab31 | | | 60 | remoteBookmarks: [], |
| b69ab31 | | | 61 | successorInfo: undefined, |
| b69ab31 | | | 62 | closestPredecessors: undefined, |
| b69ab31 | | | 63 | optimisticRevset: undefined, |
| b69ab31 | | | 64 | filePathsSample: [], |
| b69ab31 | | | 65 | totalFileCount: 0, |
| b69ab31 | | | 66 | diffId: undefined, |
| b69ab31 | | | 67 | isFollower: undefined, |
| b69ab31 | | | 68 | stableCommitMetadata: undefined, |
| b69ab31 | | | 69 | maxCommonPathPrefix: '', |
| b69ab31 | | | 70 | fullRepoBranch: undefined, |
| b69ab31 | | | 71 | |
| b69ab31 | | | 72 | // WithPreviewType |
| b69ab31 | | | 73 | previewType: undefined, |
| b69ab31 | | | 74 | |
| b69ab31 | | | 75 | // DagExt |
| b69ab31 | | | 76 | ancestors: undefined, |
| b69ab31 | | | 77 | seqNumber: undefined, |
| b69ab31 | | | 78 | isYouAreHere: undefined, |
| b69ab31 | | | 79 | stackRev: undefined, |
| b69ab31 | | | 80 | }); |
| b69ab31 | | | 81 | type CommitInfoExtRecord = RecordOf<CommitInfoExtProps>; |
| b69ab31 | | | 82 | |
| b69ab31 | | | 83 | /** Immutable, extended `CommitInfo` */ |
| b69ab31 | | | 84 | export class DagCommitInfo extends SelfUpdate<CommitInfoExtRecord> { |
| b69ab31 | | | 85 | constructor(record: CommitInfoExtRecord) { |
| b69ab31 | | | 86 | super(record); |
| b69ab31 | | | 87 | } |
| b69ab31 | | | 88 | |
| b69ab31 | | | 89 | static fromCommitInfo(info: Partial<CommitInfoExtProps>): DagCommitInfo { |
| b69ab31 | | | 90 | const record = CommitInfoExtRecord(info); |
| b69ab31 | | | 91 | return new DagCommitInfo(record); |
| b69ab31 | | | 92 | } |
| b69ab31 | | | 93 | |
| b69ab31 | | | 94 | // Immutable.js APIs |
| b69ab31 | | | 95 | |
| b69ab31 | | | 96 | set<K extends keyof CommitInfoExtProps>(key: K, value: CommitInfoExtProps[K]): DagCommitInfo { |
| b69ab31 | | | 97 | return new DagCommitInfo(this.inner.set(key, value)); |
| b69ab31 | | | 98 | } |
| b69ab31 | | | 99 | |
| b69ab31 | | | 100 | withMutations(mutator: (mutable: CommitInfoExtRecord) => CommitInfoExtRecord) { |
| b69ab31 | | | 101 | const record = this.inner.withMutations(mutator); |
| b69ab31 | | | 102 | return new DagCommitInfo(record); |
| b69ab31 | | | 103 | } |
| b69ab31 | | | 104 | |
| b69ab31 | | | 105 | merge( |
| b69ab31 | | | 106 | ...collections: Array<Partial<CommitInfoExtProps> | Iterable<[string, unknown]>> |
| b69ab31 | | | 107 | ): DagCommitInfo { |
| b69ab31 | | | 108 | return this.withMutations(m => m.merge(...collections)); |
| b69ab31 | | | 109 | } |
| b69ab31 | | | 110 | |
| b69ab31 | | | 111 | // Getters |
| b69ab31 | | | 112 | |
| b69ab31 | | | 113 | public get title(): string { |
| b69ab31 | | | 114 | return this.inner.title; |
| b69ab31 | | | 115 | } |
| b69ab31 | | | 116 | |
| b69ab31 | | | 117 | public get hash(): Hash { |
| b69ab31 | | | 118 | return this.inner.hash; |
| b69ab31 | | | 119 | } |
| b69ab31 | | | 120 | |
| b69ab31 | | | 121 | public get parents(): ReadonlyArray<Hash> { |
| b69ab31 | | | 122 | return this.inner.parents; |
| b69ab31 | | | 123 | } |
| b69ab31 | | | 124 | |
| b69ab31 | | | 125 | public get grandparents(): ReadonlyArray<Hash> { |
| b69ab31 | | | 126 | return this.inner.grandparents; |
| b69ab31 | | | 127 | } |
| b69ab31 | | | 128 | |
| b69ab31 | | | 129 | get phase(): CommitPhaseType { |
| b69ab31 | | | 130 | return this.inner.phase; |
| b69ab31 | | | 131 | } |
| b69ab31 | | | 132 | |
| b69ab31 | | | 133 | get isDot(): boolean { |
| b69ab31 | | | 134 | return this.inner.isDot; |
| b69ab31 | | | 135 | } |
| b69ab31 | | | 136 | |
| b69ab31 | | | 137 | get author(): string { |
| b69ab31 | | | 138 | return this.inner.author; |
| b69ab31 | | | 139 | } |
| b69ab31 | | | 140 | |
| b69ab31 | | | 141 | get date(): Date { |
| b69ab31 | | | 142 | return this.inner.date; |
| b69ab31 | | | 143 | } |
| b69ab31 | | | 144 | |
| b69ab31 | | | 145 | get description(): string { |
| b69ab31 | | | 146 | return this.inner.description; |
| b69ab31 | | | 147 | } |
| b69ab31 | | | 148 | |
| b69ab31 | | | 149 | get bookmarks(): ReadonlyArray<string> { |
| b69ab31 | | | 150 | return this.inner.bookmarks; |
| b69ab31 | | | 151 | } |
| b69ab31 | | | 152 | |
| b69ab31 | | | 153 | get remoteBookmarks(): ReadonlyArray<string> { |
| b69ab31 | | | 154 | return this.inner.remoteBookmarks; |
| b69ab31 | | | 155 | } |
| b69ab31 | | | 156 | |
| b69ab31 | | | 157 | get successorInfo(): Readonly<SuccessorInfo> | undefined { |
| b69ab31 | | | 158 | return this.inner.successorInfo; |
| b69ab31 | | | 159 | } |
| b69ab31 | | | 160 | |
| b69ab31 | | | 161 | get closestPredecessors(): ReadonlyArray<Hash> | undefined { |
| b69ab31 | | | 162 | return this.inner.closestPredecessors; |
| b69ab31 | | | 163 | } |
| b69ab31 | | | 164 | |
| b69ab31 | | | 165 | get optimisticRevset(): string | undefined { |
| b69ab31 | | | 166 | return this.inner.optimisticRevset; |
| b69ab31 | | | 167 | } |
| b69ab31 | | | 168 | |
| b69ab31 | | | 169 | get filePathsSample(): ReadonlyArray<RepoRelativePath> { |
| b69ab31 | | | 170 | return this.inner.filePathsSample; |
| b69ab31 | | | 171 | } |
| b69ab31 | | | 172 | |
| b69ab31 | | | 173 | get totalFileCount(): number { |
| b69ab31 | | | 174 | return this.inner.totalFileCount; |
| b69ab31 | | | 175 | } |
| b69ab31 | | | 176 | |
| b69ab31 | | | 177 | get diffId(): string | undefined { |
| b69ab31 | | | 178 | return this.inner.diffId; |
| b69ab31 | | | 179 | } |
| b69ab31 | | | 180 | |
| b69ab31 | | | 181 | get isFollower(): boolean | undefined { |
| b69ab31 | | | 182 | return this.inner.isFollower; |
| b69ab31 | | | 183 | } |
| b69ab31 | | | 184 | |
| b69ab31 | | | 185 | get stableCommitMetadata(): ReadonlyArray<StableCommitMetadata> | undefined { |
| b69ab31 | | | 186 | return this.inner.stableCommitMetadata; |
| b69ab31 | | | 187 | } |
| b69ab31 | | | 188 | |
| b69ab31 | | | 189 | get fullRepoBranch(): InternalTypes['FullRepoBranch'] | undefined { |
| b69ab31 | | | 190 | return this.inner.fullRepoBranch; |
| b69ab31 | | | 191 | } |
| b69ab31 | | | 192 | |
| b69ab31 | | | 193 | get previewType(): CommitPreview | undefined { |
| b69ab31 | | | 194 | return this.inner.previewType; |
| b69ab31 | | | 195 | } |
| b69ab31 | | | 196 | |
| b69ab31 | | | 197 | get ancestors(): List<Hash> | undefined { |
| b69ab31 | | | 198 | return this.inner.ancestors; |
| b69ab31 | | | 199 | } |
| b69ab31 | | | 200 | |
| b69ab31 | | | 201 | get seqNumber(): number | undefined { |
| b69ab31 | | | 202 | return this.inner.seqNumber; |
| b69ab31 | | | 203 | } |
| b69ab31 | | | 204 | |
| b69ab31 | | | 205 | get isYouAreHere(): boolean | undefined { |
| b69ab31 | | | 206 | return this.inner.isYouAreHere; |
| b69ab31 | | | 207 | } |
| b69ab31 | | | 208 | |
| b69ab31 | | | 209 | get stackRev(): CommitRev | undefined { |
| b69ab31 | | | 210 | return this.inner.stackRev; |
| b69ab31 | | | 211 | } |
| b69ab31 | | | 212 | |
| b69ab31 | | | 213 | get maxCommonPathPrefix(): string { |
| b69ab31 | | | 214 | return this.inner.maxCommonPathPrefix; |
| b69ab31 | | | 215 | } |
| b69ab31 | | | 216 | } |