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

Include both the changelist and commit in the query #64501

Open
wants to merge 2 commits into
base: jhh/perforce-history-panel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/web-sveltekit/src/lib/repo/HistoryPanel.gql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ fragment HistoryPanel_HistoryConnection on GitCommitConnection {
...Avatar_Person
}
}
perforceChangelist {
cid
canonicalURL
}
canonicalURL
}
pageInfo {
Expand Down
12 changes: 8 additions & 4 deletions client/web-sveltekit/src/lib/repo/HistoryPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@
<tbody>
{#each $history.data as commit (commit.id)}
{@const selected = commit.abbreviatedOID === selectedRev || commit.oid === selectedRev}
{@const isPerforceDepot = commit.perforceChangelist !== null}
{@const revURL = isPerforceDepot ? commit.perforceChangelist?.canonicalURL : commit.canonicalURL}
{@const revID = isPerforceDepot ? commit.perforceChangelist?.cid : commit.abbreviatedOID}

<tr class:selected use:scrollIntoViewOnMount={selected}>
<td class="revision">
<Badge variant="link"><a href={commit.canonicalURL}>{commit.abbreviatedOID}</a></Badge>
<Badge variant="link"><a href={revURL}>{revID}</a></Badge>
</td>
<td class="subject">
{#if enableInlineDiff}
<a href={selected ? closeURL : `?rev=${commit.oid}&diff=1`}>{commit.subject}</a>
<a href={selected ? closeURL : `?rev=${revID}&diff=1`}>{commit.subject}</a>
{:else}
{commit.subject}
{/if}
Expand All @@ -78,7 +82,7 @@
</td>
<td class="timestamp"><Timestamp date={new Date(commit.author.date)} strict /></td>
<td class="actions">
{#if enableViewAtCommit}
{#if enableViewAtCommit && !isPerforceDepot}
<Tooltip tooltip={selected && !diffEnabled ? 'Close commit' : 'View at commit'}>
<a href={selected && !diffEnabled ? closeURL : `?rev=${commit.oid}`}
><Icon icon={ILucideFileText} inline aria-hidden /></a
Expand All @@ -89,7 +93,7 @@
<a
href={replaceRevisionInURL(
SourcegraphURL.from($page.url).deleteSearchParameter('rev', 'diff').toString(),
commit.oid
isPerforceDepot ? `changelist/${revID}` : revID || ''
)}><Icon icon={ILucideFolderGit} inline aria-hidden /></a
>
</Tooltip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ async function loadDiffView({ params, url }: PageLoadEvent) {
revspec: revisionOverride,
path: filePath,
})
.then(mapOrThrow(result => result.data?.repository?.commit ?? null)),
.then(
mapOrThrow(
result => result.data?.repository?.changelist?.commit ?? result.data?.repository?.commit ?? null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the commit from the changelist if it exists. Otherwise, use the top-level commit. Fallback to null

)
),
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
query BlobDiffViewCommitQuery($repoName: String!, $revspec: String!, $path: String!) {
repository(name: $repoName) {
id
changelist(cid: $revspec) {
commit {
id
perforceChangelist {
cid
canonicalURL
}

blob(path: $path) {
...DiffViewGitBlob
}

...DiffViewCommit
}
}
Comment on lines +4 to +18
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just copy/paste the commit structure into the changelist structure. One or the other will be populated, depending on the structure of revspec: if it's a CID, then changelist.commit will be populated. If it's a GH hash, then commit will be popultated.

commit(rev: $revspec) {
id
perforceChangelist {
Expand Down
Loading