Rename Commit -> DetailedCommit

This commit is contained in:
Caleb Owens 2024-07-16 11:59:55 +02:00
parent f8261130dc
commit af3b82e9f8
No known key found for this signature in database
9 changed files with 46 additions and 35 deletions

View File

@ -20,7 +20,7 @@
import { listRemoteCommitFiles } from '$lib/vbranches/remoteCommits';
import {
RemoteCommit,
Commit,
DetailedCommit,
RemoteFile,
VirtualBranch,
type CommitStatus
@ -28,7 +28,7 @@
import { type Snippet } from 'svelte';
export let branch: VirtualBranch | undefined = undefined;
export let commit: Commit | RemoteCommit;
export let commit: DetailedCommit | RemoteCommit;
export let commitUrl: string | undefined = undefined;
export let isHeadCommit: boolean = false;
export let isUnapplied = false;
@ -66,7 +66,7 @@
}
}
function undoCommit(commit: Commit | RemoteCommit) {
function undoCommit(commit: DetailedCommit | RemoteCommit) {
if (!branch || !$baseBranch) {
console.error('Unable to undo commit');
return;
@ -74,7 +74,7 @@
branchController.undoCommit(branch.id, commit.id);
}
let isUndoable = commit instanceof Commit;
let isUndoable = commit instanceof DetailedCommit;
const hasCommitUrl = !commit.isLocal && commitUrl;
@ -192,7 +192,9 @@
dragDirection = isTop ? 'up' : 'down';
}}
use:draggableCommit={commit instanceof Commit && !isUnapplied && type !== 'integrated'
use:draggableCommit={commit instanceof DetailedCommit &&
!isUnapplied &&
type !== 'integrated'
? {
label: commit.descriptionTitle,
sha: commitShortSha,

View File

@ -3,13 +3,13 @@
import CardOverlay from '$lib/dropzone/CardOverlay.svelte';
import Dropzone from '$lib/dropzone/Dropzone.svelte';
import { getContext, maybeGetContextStore } from '$lib/utils/context';
import { RemoteCommit, VirtualBranch, Commit } from '$lib/vbranches/types';
import { RemoteCommit, VirtualBranch, DetailedCommit } from '$lib/vbranches/types';
import type { Snippet } from 'svelte';
const commitDragActionsFactory = getContext(CommitDragActionsFactory);
interface Props {
commit: Commit | RemoteCommit;
commit: DetailedCommit | RemoteCommit;
children: Snippet;
}

View File

@ -5,7 +5,7 @@ import {
RemoteCommit,
RemoteFile,
type VirtualBranch,
type Commit
type DetailedCommit
} from '$lib/vbranches/types';
import type { Project } from '$lib/backend/projects';
import type { BranchController } from '$lib/vbranches/branchController';
@ -15,7 +15,7 @@ class CommitDragActions {
private branchController: BranchController,
private project: Project,
private branch: VirtualBranch,
private commit: Commit | RemoteCommit
private commit: DetailedCommit | RemoteCommit
) {}
acceptAmend(data: any) {
@ -102,7 +102,7 @@ export class CommitDragActionsFactory {
private project: Project
) {}
build(branch: VirtualBranch, commit: Commit | RemoteCommit) {
build(branch: VirtualBranch, commit: DetailedCommit | RemoteCommit) {
return new CommitDragActions(this.branchController, this.project, branch, commit);
}
}

View File

@ -1,4 +1,4 @@
import type { AnyCommit, AnyFile, Commit, Hunk, RemoteCommit } from '../vbranches/types';
import type { AnyCommit, AnyFile, DetailedCommit, Hunk, RemoteCommit } from '../vbranches/types';
export function nonDraggable() {
return {
@ -31,7 +31,7 @@ export class DraggableFile {
export class DraggableCommit {
constructor(
public readonly branchId: string,
public readonly commit: Commit,
public readonly commit: DetailedCommit,
public readonly isHeadCommit: boolean
) {}
}

View File

@ -1,6 +1,6 @@
import { DraggableCommit } from '$lib/dragging/draggables';
import type { BranchController } from '$lib/vbranches/branchController';
import type { VirtualBranch, Commit } from '$lib/vbranches/types';
import type { VirtualBranch, DetailedCommit } from '$lib/vbranches/types';
// Exported for type access only
export class ReorderDropzone {
@ -33,7 +33,7 @@ export class ReorderDropzoneManager {
constructor(
private branchController: BranchController,
private branch: VirtualBranch,
commits: Commit[]
commits: DetailedCommit[]
) {
this.indexer = new Indexer(commits);
}
@ -54,7 +54,7 @@ export class ReorderDropzoneManager {
export class ReorderDropzoneManagerFactory {
constructor(private branchController: BranchController) {}
build(branch: VirtualBranch, commits: Commit[]) {
build(branch: VirtualBranch, commits: DetailedCommit[]) {
return new ReorderDropzoneManager(this.branchController, branch, commits);
}
}
@ -64,7 +64,7 @@ class Indexer {
private dropzoneIndexes = new Map<string, number>();
private commitIndexes = new Map<string, number>();
constructor(commits: Commit[]) {
constructor(commits: DetailedCommit[]) {
this.dropzoneIndexes.set('top', 0);
commits.forEach((commit, index) => {

View File

@ -1,14 +1,14 @@
import { buildContextStore } from '$lib/utils/context';
import type { AnyCommit, Commit, RemoteCommit } from './types';
import type { AnyCommit, DetailedCommit, RemoteCommit } from './types';
// When we can't use type for context objects we build typed getter/setter pairs
// to avoid using symbols explicitly.
export const [getLocalCommits, createLocalCommitsContextStore] =
buildContextStore<Commit[]>('localCommits');
buildContextStore<DetailedCommit[]>('localCommits');
export const [getLocalAndRemoteCommits, createLocalAndRemoteCommitsContextStore] =
buildContextStore<Commit[]>('remoteCommits');
buildContextStore<DetailedCommit[]>('remoteCommits');
export const [getIntegratedCommits, createIntegratedCommitsContextStore] =
buildContextStore<Commit[]>('integratedCommits');
buildContextStore<DetailedCommit[]>('integratedCommits');
export const [getRemoteCommits, createRemoteCommitsContextStore] =
buildContextStore<RemoteCommit[]>('remoteCommits');
export const [getCommitStore, createCommitStore] = buildContextStore<AnyCommit | undefined>(

View File

@ -1,7 +1,10 @@
import { HunkLock, type Commit } from './types';
import { HunkLock, type DetailedCommit } from './types';
import { unique } from '$lib/utils/filters';
export function getLockText(hunkLocks: HunkLock | HunkLock[] | string, commits: Commit[]): string {
export function getLockText(
hunkLocks: HunkLock | HunkLock[] | string,
commits: DetailedCommit[]
): string {
if (!hunkLocks || commits === undefined) return 'Depends on a committed change';
const locks = hunkLocks instanceof HunkLock ? [hunkLocks] : (hunkLocks as HunkLock[]);

View File

@ -103,8 +103,8 @@ export class VirtualBranch {
notes!: string;
@Type(() => LocalFile)
files!: LocalFile[];
@Type(() => Commit)
commits!: Commit[];
@Type(() => DetailedCommit)
commits!: DetailedCommit[];
requiresForce!: boolean;
description!: string;
head!: string;
@ -165,7 +165,7 @@ export type ComponentColor =
| 'purple';
export type CommitStatus = 'local' | 'localAndRemote' | 'integrated' | 'remote';
export class Commit {
export class DetailedCommit {
id!: string;
author!: Author;
description!: string;
@ -181,8 +181,8 @@ export class Commit {
isSigned!: boolean;
relatedTo?: RemoteCommit;
prev?: Commit;
next?: Commit;
prev?: DetailedCommit;
next?: DetailedCommit;
get isLocal() {
return !this.isRemote && !this.isIntegrated;
@ -203,7 +203,7 @@ export class Commit {
return splitMessage(this.description).description || undefined;
}
isParentOf(possibleChild: Commit) {
isParentOf(possibleChild: DetailedCommit) {
return possibleChild.parentIds.includes(this.id);
}
@ -212,8 +212,8 @@ export class Commit {
}
}
export function isLocalCommit(obj: any): obj is Commit {
return obj instanceof Commit;
export function isLocalCommit(obj: any): obj is DetailedCommit {
return obj instanceof DetailedCommit;
}
export class RemoteCommit {
@ -228,7 +228,7 @@ export class RemoteCommit {
prev?: RemoteCommit;
next?: RemoteCommit;
relatedTo?: Commit;
relatedTo?: DetailedCommit;
get isLocal() {
return false;
@ -255,7 +255,7 @@ export function isRemoteCommit(obj: any): obj is RemoteCommit {
return obj instanceof RemoteCommit;
}
export type AnyCommit = Commit | RemoteCommit;
export type AnyCommit = DetailedCommit | RemoteCommit;
export function commitCompare(left: AnyCommit, right: AnyCommit): boolean {
if (left.id === right.id) return true;

View File

@ -1,4 +1,10 @@
import { VirtualBranch, Commit, RemoteCommit, VirtualBranches, commitCompare } from './types';
import {
VirtualBranch,
DetailedCommit,
RemoteCommit,
VirtualBranches,
commitCompare
} from './types';
import { invoke, listen } from '$lib/backend/ipc';
import { RemoteBranchService } from '$lib/stores/remoteBranches';
import { plainToInstance } from 'class-transformer';
@ -94,14 +100,14 @@ export class VirtualBranchService {
}
}
function linkAsParentChildren(commits: Commit[] | RemoteCommit[]) {
function linkAsParentChildren(commits: DetailedCommit[] | RemoteCommit[]) {
for (let j = 0; j < commits.length; j++) {
const commit = commits[j];
if (j === 0) {
commit.next = undefined;
} else {
const child = commits[j - 1];
if (child instanceof Commit) commit.next = child;
if (child instanceof DetailedCommit) commit.next = child;
if (child instanceof RemoteCommit) commit.next = child;
}
if (j !== commits.length - 1) {