Look up locked commit from remote commits as well

- also filters for unique commits, should really be done in the back end
This commit is contained in:
Mattias Granlund 2024-04-25 19:07:41 +02:00
parent 066d520f1a
commit ebc696ad26
3 changed files with 12 additions and 3 deletions

View File

@ -4,7 +4,7 @@
import LargeDiffMessage from './LargeDiffMessage.svelte';
import { computeAddedRemovedByHunk } from '$lib/utils/metrics';
import { tooltip } from '$lib/utils/tooltip';
import { getLocalCommits } from '$lib/vbranches/contexts';
import { getLocalCommits, getRemoteCommits } from '$lib/vbranches/contexts';
import { getLockText } from '$lib/vbranches/tooltip';
import type { HunkSection, ContentSection } from '$lib/utils/fileSections';
@ -21,6 +21,9 @@
$: minWidth = getGutterMinWidth(maxLineNumber);
const localCommits = isFileLocked ? getLocalCommits() : undefined;
const remoteCommits = isFileLocked ? getRemoteCommits() : undefined;
const commits = isFileLocked ? ($localCommits || []).concat($remoteCommits || []) : undefined;
let alwaysShow = false;
function getGutterMinWidth(max: number) {
@ -52,10 +55,10 @@
<div class="indicators text-base-11">
<span class="added">+{added}</span>
<span class="removed">-{removed}</span>
{#if section.hunk.lockedTo && $localCommits}
{#if section.hunk.lockedTo && commits}
<div
use:tooltip={{
text: getLockText(section.hunk.lockedTo, $localCommits),
text: getLockText(section.hunk.lockedTo, commits),
delay: 500
}}
>

View File

@ -0,0 +1,4 @@
// If a value occurs > 1 times then all but one will fail this condition.
export function unique(value: any, index: number, array: any[]) {
return array.indexOf(value) === index;
}

View File

@ -1,3 +1,4 @@
import { unique } from '$lib/utils/filters';
import type { Commit } from './types';
export function getLockText(commitId: string[] | string, commits: Commit[]): string {
@ -6,6 +7,7 @@ export function getLockText(commitId: string[] | string, commits: Commit[]): str
const lockedIds = typeof commitId == 'string' ? [commitId] : (commitId as string[]);
const descriptions = lockedIds
.filter(unique)
.map((id) => {
const commit = commits.find((commit) => commit.id == id);
const shortCommitId = commit?.id.slice(0, 7);