Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit c6c654c

Browse files
refactor and more cleanup
1 parent 36b9c32 commit c6c654c

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

client/web-sveltekit/src/lib/repo/HistoryPanel.svelte

+7-8
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,18 @@
6565
{@const revURL = isPerforceDepot ? commit.perforceChangelist?.canonicalURL : commit.canonicalURL}
6666
{@const revID = isPerforceDepot ? commit.perforceChangelist?.cid : commit.abbreviatedOID}
6767
{@const revType = isPerforceDepot ? 'changelist' : 'commit'}
68+
{@const revQueryParams = isPerforceDepot
69+
? `?rev=changelist%2f${revID}&diff=1`
70+
: `?rev=${revID}&diff=1`}
71+
{@const revSlug = isPerforceDepot ? `${revType}/${revID}` : revID || ''}
6872

6973
<tr class:selected use:scrollIntoViewOnMount={selected}>
7074
<td class="revision">
7175
<Badge variant="link"><a href={revURL}>{revID}</a></Badge>
7276
</td>
7377
<td class="subject">
7478
{#if enableInlineDiff}
75-
<a
76-
href={selected
77-
? closeURL
78-
: `?rev=${isPerforceDepot ? `${revType}%2f${revID}` : revID}&diff=1`}
79-
>{commit.subject}</a
80-
>
79+
<a href={selected ? closeURL : revQueryParams}>{commit.subject}</a>
8180
{:else}
8281
{commit.subject}
8382
{/if}
@@ -90,7 +89,7 @@
9089
<td class="actions">
9190
{#if enableViewAtCommit}
9291
<Tooltip tooltip={selected && !diffEnabled ? `Close ${revType}` : `View at ${revType}`}>
93-
<a href={selected && !diffEnabled ? closeURL : `?rev=${commit.oid}`}
92+
<a href={selected && !diffEnabled ? closeURL : revQueryParams}
9493
><Icon icon={ILucideFileText} inline aria-hidden /></a
9594
>
9695
</Tooltip>
@@ -99,7 +98,7 @@
9998
<a
10099
href={replaceRevisionInURL(
101100
SourcegraphURL.from($page.url).deleteSearchParameter('rev', 'diff').toString(),
102-
isPerforceDepot ? `changelist/${revID}` : revID || ''
101+
revSlug
103102
)}><Icon icon={ILucideFolderGit} inline aria-hidden /></a
104103
>
105104
</Tooltip>

client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/(code)/-/blob/[...path]/+page.ts

+27-27
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,33 @@ async function loadDiffView({ params, url }: PageLoadEvent) {
3838

3939
assertNonNullable(revisionOverride, 'revisionOverride is set')
4040

41-
return cid
42-
? {
43-
type: 'DiffView' as const,
44-
enableInlineDiff: true,
45-
enableViewAtCommit: true,
46-
filePath,
47-
commit: client
48-
.query(BlobDiffViewChangelistQuery, {
49-
repoName,
50-
cid: cid,
51-
path: filePath,
52-
})
53-
.then(mapOrThrow(result => result.data?.repository?.changelist?.commit ?? null)),
54-
}
55-
: {
56-
type: 'DiffView' as const,
57-
enableInlineDiff: true,
58-
enableViewAtCommit: true,
59-
filePath,
60-
commit: client
61-
.query(BlobDiffViewCommitQuery, {
62-
repoName,
63-
revspec: revisionOverride,
64-
path: filePath,
65-
})
66-
.then(mapOrThrow(result => result.data?.repository?.commit ?? null)),
67-
}
41+
const getRevision = () => {
42+
if (cid) {
43+
return client
44+
.query(BlobDiffViewChangelistQuery, {
45+
repoName,
46+
cid: cid,
47+
path: filePath,
48+
})
49+
.then(mapOrThrow(result => result.data?.repository?.changelist?.commit ?? null))
50+
}
51+
52+
return client
53+
.query(BlobDiffViewCommitQuery, {
54+
repoName,
55+
revspec: revisionOverride,
56+
path: filePath,
57+
})
58+
.then(mapOrThrow(result => result.data?.repository?.commit ?? null))
59+
}
60+
61+
return {
62+
type: 'DiffView' as const,
63+
enableInlineDiff: true,
64+
enableViewAtCommit: true,
65+
filePath,
66+
commit: getRevision(),
67+
}
6868
}
6969

7070
async function fetchCodeGraphData(

0 commit comments

Comments
 (0)