addons/isl/src/dag/dagCommitInfo.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {List, RecordOf} from 'immutable';
b69ab319import type {InternalTypes} from '../InternalTypes';
b69ab3110import type {CommitPreview, WithPreviewType} from '../previews';
b69ab3111import type {CommitRev} from '../stackEdit/commitStackState';
b69ab3112import type {
b69ab3113 CommitInfo,
b69ab3114 CommitPhaseType,
b69ab3115 Hash,
b69ab3116 RepoRelativePath,
b69ab3117 StableCommitMetadata,
b69ab3118 SuccessorInfo,
b69ab3119} from '../types';
b69ab3120
b69ab3121import {Record} from 'immutable';
b69ab3122import {SelfUpdate} from 'shared/immutableExt';
b69ab3123
b69ab3124type DagExt = {
b69ab3125 /** Distance ancestors that are treated as direct parents. */
b69ab3126 ancestors?: List<Hash>;
b69ab3127
b69ab3128 /**
b69ab3129 * Insertion batch. Larger: later inserted.
b69ab3130 * All 'sl log' commits share a same initial number.
b69ab3131 * Later previews might have larger numbers.
b69ab3132 * Used for sorting.
b69ab3133 */
b69ab3134 seqNumber?: number;
b69ab3135
b69ab3136 /** If true, this is a virtual "You are here" commit. */
b69ab3137 isYouAreHere?: boolean;
b69ab3138
b69ab3139 /** If constructed from a "CommitStack", the "Rev" of the commit. */
b69ab3140 stackRev?: CommitRev;
b69ab3141};
b69ab3142
b69ab3143// Note: There are some non-immutable containers (Array) in `CommitInfo`
b69ab3144// such as bookmarks. Since the "commitInfos" are "normalized" by
b69ab3145// `reuseEqualObjects`. Those non-immutable properties should still
b69ab3146// compare fine.
b69ab3147type CommitInfoExtProps = CommitInfo & WithPreviewType & DagExt;
b69ab3148
b69ab3149const CommitInfoExtRecord = Record<CommitInfoExtProps>({
b69ab3150 title: '',
b69ab3151 hash: '',
b69ab3152 parents: [],
b69ab3153 grandparents: [],
b69ab3154 phase: 'draft',
b69ab3155 isDot: false,
b69ab3156 author: '',
b69ab3157 date: new Date(0),
b69ab3158 description: '',
b69ab3159 bookmarks: [],
b69ab3160 remoteBookmarks: [],
b69ab3161 successorInfo: undefined,
b69ab3162 closestPredecessors: undefined,
b69ab3163 optimisticRevset: undefined,
b69ab3164 filePathsSample: [],
b69ab3165 totalFileCount: 0,
b69ab3166 diffId: undefined,
b69ab3167 isFollower: undefined,
b69ab3168 stableCommitMetadata: undefined,
b69ab3169 maxCommonPathPrefix: '',
b69ab3170 fullRepoBranch: undefined,
b69ab3171
b69ab3172 // WithPreviewType
b69ab3173 previewType: undefined,
b69ab3174
b69ab3175 // DagExt
b69ab3176 ancestors: undefined,
b69ab3177 seqNumber: undefined,
b69ab3178 isYouAreHere: undefined,
b69ab3179 stackRev: undefined,
b69ab3180});
b69ab3181type CommitInfoExtRecord = RecordOf<CommitInfoExtProps>;
b69ab3182
b69ab3183/** Immutable, extended `CommitInfo` */
b69ab3184export class DagCommitInfo extends SelfUpdate<CommitInfoExtRecord> {
b69ab3185 constructor(record: CommitInfoExtRecord) {
b69ab3186 super(record);
b69ab3187 }
b69ab3188
b69ab3189 static fromCommitInfo(info: Partial<CommitInfoExtProps>): DagCommitInfo {
b69ab3190 const record = CommitInfoExtRecord(info);
b69ab3191 return new DagCommitInfo(record);
b69ab3192 }
b69ab3193
b69ab3194 // Immutable.js APIs
b69ab3195
b69ab3196 set<K extends keyof CommitInfoExtProps>(key: K, value: CommitInfoExtProps[K]): DagCommitInfo {
b69ab3197 return new DagCommitInfo(this.inner.set(key, value));
b69ab3198 }
b69ab3199
b69ab31100 withMutations(mutator: (mutable: CommitInfoExtRecord) => CommitInfoExtRecord) {
b69ab31101 const record = this.inner.withMutations(mutator);
b69ab31102 return new DagCommitInfo(record);
b69ab31103 }
b69ab31104
b69ab31105 merge(
b69ab31106 ...collections: Array<Partial<CommitInfoExtProps> | Iterable<[string, unknown]>>
b69ab31107 ): DagCommitInfo {
b69ab31108 return this.withMutations(m => m.merge(...collections));
b69ab31109 }
b69ab31110
b69ab31111 // Getters
b69ab31112
b69ab31113 public get title(): string {
b69ab31114 return this.inner.title;
b69ab31115 }
b69ab31116
b69ab31117 public get hash(): Hash {
b69ab31118 return this.inner.hash;
b69ab31119 }
b69ab31120
b69ab31121 public get parents(): ReadonlyArray<Hash> {
b69ab31122 return this.inner.parents;
b69ab31123 }
b69ab31124
b69ab31125 public get grandparents(): ReadonlyArray<Hash> {
b69ab31126 return this.inner.grandparents;
b69ab31127 }
b69ab31128
b69ab31129 get phase(): CommitPhaseType {
b69ab31130 return this.inner.phase;
b69ab31131 }
b69ab31132
b69ab31133 get isDot(): boolean {
b69ab31134 return this.inner.isDot;
b69ab31135 }
b69ab31136
b69ab31137 get author(): string {
b69ab31138 return this.inner.author;
b69ab31139 }
b69ab31140
b69ab31141 get date(): Date {
b69ab31142 return this.inner.date;
b69ab31143 }
b69ab31144
b69ab31145 get description(): string {
b69ab31146 return this.inner.description;
b69ab31147 }
b69ab31148
b69ab31149 get bookmarks(): ReadonlyArray<string> {
b69ab31150 return this.inner.bookmarks;
b69ab31151 }
b69ab31152
b69ab31153 get remoteBookmarks(): ReadonlyArray<string> {
b69ab31154 return this.inner.remoteBookmarks;
b69ab31155 }
b69ab31156
b69ab31157 get successorInfo(): Readonly<SuccessorInfo> | undefined {
b69ab31158 return this.inner.successorInfo;
b69ab31159 }
b69ab31160
b69ab31161 get closestPredecessors(): ReadonlyArray<Hash> | undefined {
b69ab31162 return this.inner.closestPredecessors;
b69ab31163 }
b69ab31164
b69ab31165 get optimisticRevset(): string | undefined {
b69ab31166 return this.inner.optimisticRevset;
b69ab31167 }
b69ab31168
b69ab31169 get filePathsSample(): ReadonlyArray<RepoRelativePath> {
b69ab31170 return this.inner.filePathsSample;
b69ab31171 }
b69ab31172
b69ab31173 get totalFileCount(): number {
b69ab31174 return this.inner.totalFileCount;
b69ab31175 }
b69ab31176
b69ab31177 get diffId(): string | undefined {
b69ab31178 return this.inner.diffId;
b69ab31179 }
b69ab31180
b69ab31181 get isFollower(): boolean | undefined {
b69ab31182 return this.inner.isFollower;
b69ab31183 }
b69ab31184
b69ab31185 get stableCommitMetadata(): ReadonlyArray<StableCommitMetadata> | undefined {
b69ab31186 return this.inner.stableCommitMetadata;
b69ab31187 }
b69ab31188
b69ab31189 get fullRepoBranch(): InternalTypes['FullRepoBranch'] | undefined {
b69ab31190 return this.inner.fullRepoBranch;
b69ab31191 }
b69ab31192
b69ab31193 get previewType(): CommitPreview | undefined {
b69ab31194 return this.inner.previewType;
b69ab31195 }
b69ab31196
b69ab31197 get ancestors(): List<Hash> | undefined {
b69ab31198 return this.inner.ancestors;
b69ab31199 }
b69ab31200
b69ab31201 get seqNumber(): number | undefined {
b69ab31202 return this.inner.seqNumber;
b69ab31203 }
b69ab31204
b69ab31205 get isYouAreHere(): boolean | undefined {
b69ab31206 return this.inner.isYouAreHere;
b69ab31207 }
b69ab31208
b69ab31209 get stackRev(): CommitRev | undefined {
b69ab31210 return this.inner.stackRev;
b69ab31211 }
b69ab31212
b69ab31213 get maxCommonPathPrefix(): string {
b69ab31214 return this.inner.maxCommonPathPrefix;
b69ab31215 }
b69ab31216}