mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 18:20:30 +08:00
Load the peer selector after render
Listing remotes verifies signed refs for every peer and took seconds on large repositories, blocking navigation. Resolve revisions from the canonical refs already on the repo object, fetching a single remote when the route names a peer, and load the full listing after render. Tags living only on a remote no longer resolve as bare revisions.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
import type {
|
||||
BaseUrl,
|
||||
CommitHeader,
|
||||
PeerRefs,
|
||||
Repo,
|
||||
SeedingPolicy,
|
||||
Tree,
|
||||
@@ -31,7 +30,6 @@
|
||||
export let commit: string;
|
||||
export let commitHeaders: CommitHeader[];
|
||||
export let peer: string | undefined;
|
||||
export let peers: PeerRefs[];
|
||||
export let repo: Repo;
|
||||
export let repoId: string;
|
||||
export let revision: string | undefined;
|
||||
@@ -132,7 +130,6 @@
|
||||
<Header
|
||||
{baseRoute}
|
||||
{commit}
|
||||
{peers}
|
||||
{peer}
|
||||
{repo}
|
||||
{repoId}
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<script lang="ts">
|
||||
import type {
|
||||
BaseUrl,
|
||||
PeerRefs,
|
||||
Repo,
|
||||
SeedingPolicy,
|
||||
Tree,
|
||||
} from "@http-client";
|
||||
import type { BaseUrl, Repo, SeedingPolicy, Tree } from "@http-client";
|
||||
import type { BlobResult, RepoRoute } from "./router";
|
||||
|
||||
import { HttpdClient } from "@http-client";
|
||||
@@ -28,7 +22,6 @@
|
||||
export let commit: string;
|
||||
export let path: string;
|
||||
export let peer: string | undefined;
|
||||
export let peers: PeerRefs[];
|
||||
export let repo: Repo;
|
||||
export let repoId: string;
|
||||
export let rawPath: (commit?: string) => string;
|
||||
@@ -159,7 +152,6 @@
|
||||
node={baseUrl}
|
||||
{commit}
|
||||
{baseRoute}
|
||||
{peers}
|
||||
{peer}
|
||||
{repo}
|
||||
{repoId}
|
||||
|
||||
@@ -1,15 +1,31 @@
|
||||
<script lang="ts" context="module">
|
||||
import type { BaseUrl, PeerRefs } from "@http-client";
|
||||
|
||||
import { HttpdClient } from "@http-client";
|
||||
import { cached } from "@app/lib/cache";
|
||||
import { peerHasBranches, remoteToPeerRefs } from "../router";
|
||||
|
||||
// Cache commit counts across component remounts (tab navigation).
|
||||
const commitCountCache: Record<string, number> = {};
|
||||
|
||||
// The remote listing behind the peer selector is expensive on repositories
|
||||
// with many peers. Going through `cached` shares a single request across
|
||||
// every Header instance for the same repo, including instances that mount
|
||||
// while the request is still in flight.
|
||||
const getPeers = cached(
|
||||
async (baseUrl: BaseUrl, rid: string) => {
|
||||
const remotes = await new HttpdClient(baseUrl).repo.getAllRemotes(rid);
|
||||
return remotes.map(remoteToPeerRefs).filter(peerHasBranches);
|
||||
},
|
||||
(...args) => JSON.stringify(args),
|
||||
);
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type { RepoRoute } from "../router";
|
||||
import type { BaseUrl, PeerRefs, Repo, Tree } from "@http-client";
|
||||
import type { Repo, Tree } from "@http-client";
|
||||
import type { ComponentProps } from "svelte";
|
||||
|
||||
import { HttpdClient } from "@http-client";
|
||||
|
||||
import Button from "@app/components/Button.svelte";
|
||||
import CommitButton from "../components/CommitButton.svelte";
|
||||
import Icon from "@app/components/Icon.svelte";
|
||||
@@ -23,7 +39,6 @@
|
||||
export let historyLinkActive: boolean;
|
||||
export let node: BaseUrl;
|
||||
export let peer: string | undefined;
|
||||
export let peers: PeerRefs[];
|
||||
export let repo: Repo;
|
||||
export let repoId: string;
|
||||
export let baseRoute: Extract<
|
||||
@@ -50,6 +65,34 @@
|
||||
|
||||
$: fetchCommitCount(repo.rid, commit);
|
||||
|
||||
// Enumerating remotes requires reading and verifying signed refs for every
|
||||
// peer, which is slow on large repositories. It only feeds the peer selector
|
||||
// dropdown, so it loads after render instead of blocking navigation.
|
||||
let peers: PeerRefs[] | undefined = undefined;
|
||||
let peersRid: string | undefined;
|
||||
|
||||
function fetchPeers(rid: string) {
|
||||
if (peersRid === rid) {
|
||||
return;
|
||||
}
|
||||
peersRid = rid;
|
||||
peers = undefined;
|
||||
void getPeers(node, rid)
|
||||
.then(result => {
|
||||
if (peersRid === rid) {
|
||||
peers = result;
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
if (peersRid === rid) {
|
||||
peersRid = undefined;
|
||||
}
|
||||
console.error("Failed to load repo remotes", error);
|
||||
});
|
||||
}
|
||||
|
||||
$: fetchPeers(repo.rid);
|
||||
|
||||
let selectedBranch: string | undefined;
|
||||
let commitButtonVariant: ComponentProps<CommitButton>["variant"] | undefined;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
import HoverPopover from "@app/components/HoverPopover.svelte";
|
||||
import Icon from "@app/components/Icon.svelte";
|
||||
import Link from "@app/components/Link.svelte";
|
||||
import Loading from "@app/components/Loading.svelte";
|
||||
import Peer from "./PeerBranchSelector/Peer.svelte";
|
||||
import Popover from "@app/components/Popover.svelte";
|
||||
import TextInput from "@app/components/TextInput.svelte";
|
||||
@@ -31,7 +32,10 @@
|
||||
>;
|
||||
export let onCanonical: boolean;
|
||||
export let peer: string | undefined;
|
||||
export let peers: PeerRefs[];
|
||||
// Undefined until the remotes request resolves. Enumerating them is
|
||||
// expensive on repositories with many peers, so the selector renders first
|
||||
// and fills in afterwards.
|
||||
export let peers: PeerRefs[] | undefined = undefined;
|
||||
export let repo: Repo;
|
||||
export let selectedBranch: string | undefined;
|
||||
|
||||
@@ -51,6 +55,7 @@
|
||||
type: "branch" | "tag";
|
||||
};
|
||||
|
||||
$: peerList = peers ?? [];
|
||||
$: canonicalBranchesMap = getBranchesFromRefs(repo.refs?.refs ?? {});
|
||||
$: canonicalTagsInfo = Object.fromEntries(
|
||||
Object.entries(repo.refs?.tags ?? {}).map(([name, info]) => [
|
||||
@@ -78,7 +83,7 @@
|
||||
head,
|
||||
type: "branch",
|
||||
})),
|
||||
...peers.flatMap(peer => {
|
||||
...peerList.flatMap(peer => {
|
||||
const peerBranches = getBranchesFromRefs(peer.refs);
|
||||
return Object.entries(peerBranches).map(([name, head]) => ({
|
||||
peer: { id: peer.id, alias: peer.alias, delegate: peer.delegate },
|
||||
@@ -96,7 +101,7 @@
|
||||
head: info.commit,
|
||||
type: "tag",
|
||||
})),
|
||||
...peers.flatMap(peer => {
|
||||
...peerList.flatMap(peer => {
|
||||
const peerTags = getTagsFromRefs(peer.refs);
|
||||
return Object.entries(peerTags).map(([name, head]) => ({
|
||||
peer: { id: peer.id, alias: peer.alias, delegate: peer.delegate },
|
||||
@@ -108,7 +113,13 @@
|
||||
] as SearchElement[];
|
||||
|
||||
$: searchElements = selectedTab === "branches" ? branchElements : tagElements;
|
||||
$: selectedPeer = peers.find(p => p.id === peer);
|
||||
// Until the remotes load, fall back to the bare node id from the route so
|
||||
// the toggle can render the selected peer straight away.
|
||||
$: selectedPeer =
|
||||
peerList.find(p => p.id === peer) ??
|
||||
(peer !== undefined
|
||||
? { id: peer, alias: undefined, delegate: false }
|
||||
: undefined);
|
||||
$: searchResults = fuzzysort.go(searchInput, searchElements, {
|
||||
keys: ["peer.alias", "revision"],
|
||||
scoreFn: r =>
|
||||
@@ -131,13 +142,13 @@
|
||||
);
|
||||
$: hasTags =
|
||||
Object.keys(canonicalTagsInfo).length > 0 ||
|
||||
peers.some(p => Object.keys(getTagsFromRefs(p.refs)).length > 0);
|
||||
peerList.some(p => Object.keys(getTagsFromRefs(p.refs)).length > 0);
|
||||
|
||||
$: selectedTag = (() => {
|
||||
if (!selectedBranch) return undefined;
|
||||
|
||||
if (peer) {
|
||||
const p = peers.find(x => x.id === peer);
|
||||
const p = peerList.find(x => x.id === peer);
|
||||
if (!p) return undefined;
|
||||
const peerTags = getTagsFromRefs(p.refs);
|
||||
for (const [tagName, oid] of Object.entries(peerTags)) {
|
||||
@@ -167,8 +178,14 @@
|
||||
$: selectedTagPeer = selectedTag?.peer;
|
||||
|
||||
let lastSelectedBranch: string | undefined;
|
||||
// A tag belonging to a peer is only recognized once the remotes arrive, so
|
||||
// the selected tag is tracked too rather than the branch alone.
|
||||
let lastSelectedTagName: string | undefined;
|
||||
$: {
|
||||
if (selectedBranch !== lastSelectedBranch) {
|
||||
if (
|
||||
selectedBranch !== lastSelectedBranch ||
|
||||
selectedTagName !== lastSelectedTagName
|
||||
) {
|
||||
if (selectedTagName) {
|
||||
selectedTab = "tags";
|
||||
} else if (!selectedBranch) {
|
||||
@@ -176,6 +193,8 @@
|
||||
}
|
||||
// eslint-disable-next-line no-useless-assignment
|
||||
lastSelectedBranch = selectedBranch;
|
||||
// eslint-disable-next-line no-useless-assignment
|
||||
lastSelectedTagName = selectedTagName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,6 +202,11 @@
|
||||
selectedTab = "branches";
|
||||
}
|
||||
|
||||
// The absence of tags is only certain once the nodes have loaded, since any
|
||||
// of them may carry tags of its own. Until then the tab stays available
|
||||
// rather than claiming there are none.
|
||||
$: tagsTabDisabled = !hasTags && peers !== undefined;
|
||||
|
||||
$: isSelectedBranchCanonical = (() => {
|
||||
if (onCanonical) return true;
|
||||
if (!selectedBranch || peer) return false;
|
||||
@@ -241,6 +265,13 @@
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.tags-tab {
|
||||
display: flex;
|
||||
}
|
||||
/* Let the hover fall through to the wrapper, which carries the tooltip. */
|
||||
.tags-tab.disabled > :global(button) {
|
||||
pointer-events: none;
|
||||
}
|
||||
.sticky-header {
|
||||
position: sticky;
|
||||
top: -0.25rem;
|
||||
@@ -268,6 +299,16 @@
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
}
|
||||
.loading-peers {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
grid-column: span 2;
|
||||
padding: 0.5rem 0.375rem;
|
||||
font: var(--txt-body-m-regular);
|
||||
color: var(--color-text-tertiary);
|
||||
}
|
||||
.tag-message {
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
@@ -294,8 +335,7 @@
|
||||
styleBorderRadius="var(--border-radius-sm) 0 0 var(--border-radius-sm)"
|
||||
styleWidth="100%"
|
||||
on:click={toggle}
|
||||
title={hasTags ? "Change branch or tag" : "Change branch"}
|
||||
disabled={!peers}>
|
||||
title={hasTags ? "Change branch or tag" : "Change branch"}>
|
||||
{@const displayPeer = selectedPeer || selectedTagPeer}
|
||||
{#if displayPeer}
|
||||
<div class="global-flex-item">
|
||||
@@ -341,19 +381,25 @@
|
||||
|
||||
<div slot="popover" class="dropdown" let:toggle>
|
||||
<div class="sticky-header">
|
||||
{#if hasTags}
|
||||
<div class="tabs">
|
||||
<Button
|
||||
variant={selectedTab === "branches" ? "selected" : "background"}
|
||||
on:click={() => {
|
||||
selectedTab = "branches";
|
||||
searchInput = "";
|
||||
}}>
|
||||
<Icon name="branch" />
|
||||
Branches
|
||||
</Button>
|
||||
<div class="tabs">
|
||||
<Button
|
||||
variant={selectedTab === "branches" ? "selected" : "background"}
|
||||
on:click={() => {
|
||||
selectedTab = "branches";
|
||||
searchInput = "";
|
||||
}}>
|
||||
<Icon name="branch" />
|
||||
Branches
|
||||
</Button>
|
||||
<!-- The tooltip sits on the wrapper because a disabled button
|
||||
receives no pointer events of its own. -->
|
||||
<span
|
||||
class="tags-tab"
|
||||
class:disabled={tagsTabDisabled}
|
||||
title={tagsTabDisabled ? "This repository has no tags" : undefined}>
|
||||
<Button
|
||||
variant={selectedTab === "tags" ? "selected" : "background"}
|
||||
disabled={tagsTabDisabled}
|
||||
on:click={() => {
|
||||
selectedTab = "tags";
|
||||
searchInput = "";
|
||||
@@ -361,36 +407,27 @@
|
||||
<Icon name="label" />
|
||||
Tags
|
||||
</Button>
|
||||
<div class="global-hide-on-mobile-down" style:flex="1">
|
||||
<TextInput
|
||||
size="small"
|
||||
showKeyHint={false}
|
||||
placeholder={selectedTab === "branches"
|
||||
? "Filter branches"
|
||||
: "Filter tags"}
|
||||
bind:value={searchInput} />
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div style="margin-bottom: 0.5rem;">
|
||||
<TextInput
|
||||
showKeyHint={false}
|
||||
placeholder="Filter branches"
|
||||
bind:value={searchInput} />
|
||||
</div>
|
||||
{/if}
|
||||
{#if hasTags}
|
||||
<div
|
||||
class="global-hide-on-small-desktop-up"
|
||||
style="margin-bottom: 0.5rem;">
|
||||
</span>
|
||||
<div class="global-hide-on-mobile-down" style:flex="1">
|
||||
<TextInput
|
||||
size="small"
|
||||
showKeyHint={false}
|
||||
placeholder={selectedTab === "branches"
|
||||
? "Filter branches"
|
||||
: "Filter tags"}
|
||||
bind:value={searchInput} />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div
|
||||
class="global-hide-on-small-desktop-up"
|
||||
style="margin-bottom: 0.5rem;">
|
||||
<TextInput
|
||||
showKeyHint={false}
|
||||
placeholder={selectedTab === "branches"
|
||||
? "Filter branches"
|
||||
: "Filter tags"}
|
||||
bind:value={searchInput} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="dropdown-grid">
|
||||
<div class="dropdown-header">
|
||||
@@ -471,12 +508,14 @@
|
||||
</DropdownListItem>
|
||||
</Link>
|
||||
{:else}
|
||||
<div
|
||||
style="padding: 0.5rem 0.375rem;"
|
||||
class="subgrid-item txt-body-m-regular"
|
||||
style:color="var(--color-text-tertiary)">
|
||||
No entries found
|
||||
</div>
|
||||
{#if peers !== undefined}
|
||||
<div
|
||||
style="padding: 0.5rem 0.375rem;"
|
||||
class="subgrid-item txt-body-m-regular"
|
||||
style:color="var(--color-text-tertiary)">
|
||||
No entries found
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
{:else if selectedTab === "branches"}
|
||||
<Link
|
||||
@@ -531,7 +570,7 @@
|
||||
</DropdownListItem>
|
||||
</Link>
|
||||
{/each}
|
||||
{#each orderBy(peers, ["delegate", o => o.alias?.toLowerCase()], ["desc", "asc"]) as peer}
|
||||
{#each orderBy(peerList, ["delegate", o => o.alias?.toLowerCase()], ["desc", "asc"]) as peer}
|
||||
<Peer
|
||||
{baseRoute}
|
||||
revision={selectedBranch}
|
||||
@@ -605,7 +644,7 @@
|
||||
</Link>
|
||||
{/each}
|
||||
{/if}
|
||||
{#each orderBy(peers, ["delegate", o => o.alias?.toLowerCase()], ["desc", "asc"]).filter(p => Object.keys(getTagsFromRefs(p.refs)).length > 0) as peer}
|
||||
{#each orderBy(peerList, ["delegate", o => o.alias?.toLowerCase()], ["desc", "asc"]).filter(p => Object.keys(getTagsFromRefs(p.refs)).length > 0) as peer}
|
||||
<Peer
|
||||
{baseRoute}
|
||||
revision={selectedBranch}
|
||||
@@ -617,6 +656,13 @@
|
||||
}} />
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
{#if peers === undefined}
|
||||
<div class="loading-peers">
|
||||
<Loading small noDelay />
|
||||
Loading nodes…
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</Popover>
|
||||
|
||||
+58
-102
@@ -40,7 +40,7 @@ import { nodePath } from "@app/views/nodes/router";
|
||||
export const PATCHES_PER_PAGE = 10;
|
||||
export const ISSUES_PER_PAGE = 10;
|
||||
|
||||
function peerHasBranches(peer: PeerRefs): boolean {
|
||||
export function peerHasBranches(peer: PeerRefs): boolean {
|
||||
return Object.keys(peer.refs).some(name => name.startsWith("refs/heads/"));
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ function canonicalOids(
|
||||
];
|
||||
}
|
||||
|
||||
function remoteToPeerRefs(remote: Remote): PeerRefs {
|
||||
export function remoteToPeerRefs(remote: Remote): PeerRefs {
|
||||
if (remote.refs) {
|
||||
return {
|
||||
id: remote.id,
|
||||
@@ -168,7 +168,6 @@ export type RepoLoadedRoute =
|
||||
commit: string;
|
||||
repo: Repo;
|
||||
repoId: string;
|
||||
peers: PeerRefs[];
|
||||
peer: string | undefined;
|
||||
revision: string | undefined;
|
||||
tree: Tree;
|
||||
@@ -187,7 +186,6 @@ export type RepoLoadedRoute =
|
||||
commit: string;
|
||||
repo: Repo;
|
||||
repoId: string;
|
||||
peers: PeerRefs[];
|
||||
peer: string | undefined;
|
||||
revision: string | undefined;
|
||||
tree: Tree;
|
||||
@@ -480,9 +478,6 @@ async function loadTreeView(
|
||||
nodePromise,
|
||||
]);
|
||||
|
||||
const remotes = await api.repo.getAllRemotes(route.repo);
|
||||
const peers: PeerRefs[] = remotes.map(remoteToPeerRefs);
|
||||
|
||||
if (!repo["payloads"]["xyz.radicle.project"]) {
|
||||
throw new Error(
|
||||
`Repository ${repo.rid} does not have a xyz.radicle.project payload.`,
|
||||
@@ -490,41 +485,19 @@ async function loadTreeView(
|
||||
}
|
||||
|
||||
const project = repo["payloads"]["xyz.radicle.project"];
|
||||
let branchMap: Record<string, string> = {
|
||||
[project.data.defaultBranch]: project.meta.head,
|
||||
};
|
||||
|
||||
for (const [refName, oid] of canonicalOids(repo.refs)) {
|
||||
const shortName = refName.startsWith("refs/heads/")
|
||||
? refName.slice("refs/heads/".length)
|
||||
: refName.startsWith("refs/tags/")
|
||||
? refName.slice("refs/tags/".length)
|
||||
: refName;
|
||||
branchMap[shortName] = oid;
|
||||
branchMap[encodeURIComponent(shortName)] = oid;
|
||||
}
|
||||
|
||||
for (const peer of peers) {
|
||||
const tags = getTagsFromRefs(peer.refs);
|
||||
for (const [tagName, oid] of Object.entries(tags)) {
|
||||
branchMap[tagName] = oid;
|
||||
branchMap[encodeURIComponent(tagName)] = oid;
|
||||
}
|
||||
}
|
||||
let branchMap = canonicalBranchMap(repo);
|
||||
|
||||
if (route.peer) {
|
||||
const peer = peers.find(peer => peer.id === route.peer);
|
||||
if (!peer) {
|
||||
return {
|
||||
resource: "notFound",
|
||||
params: { title: `Peer ${route.peer} could not be found` },
|
||||
};
|
||||
} else {
|
||||
branchMap = { ...getBranchesFromRefs(peer.refs) };
|
||||
for (const [tagName, oid] of Object.entries(getTagsFromRefs(peer.refs))) {
|
||||
branchMap[tagName] = oid;
|
||||
branchMap[encodeURIComponent(tagName)] = oid;
|
||||
try {
|
||||
branchMap = await getPeerBranchMap(api, route.repo, route.peer);
|
||||
} catch (e) {
|
||||
if (e instanceof ResponseError) {
|
||||
return {
|
||||
resource: "notFound",
|
||||
params: { title: `Peer ${route.peer} could not be found` },
|
||||
};
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -552,7 +525,6 @@ async function loadTreeView(
|
||||
seedingPolicy,
|
||||
commit,
|
||||
repo,
|
||||
peers: peers.filter(peerHasBranches),
|
||||
peer: route.peer,
|
||||
rawPath,
|
||||
revision: route.revision,
|
||||
@@ -649,16 +621,9 @@ async function loadHistoryView(
|
||||
nodePromise,
|
||||
]);
|
||||
|
||||
const remotes = await api.repo.getAllRemotes(route.repo);
|
||||
const peers: PeerRefs[] = remotes.map(remoteToPeerRefs);
|
||||
|
||||
const branchMap = await getPeerBranches(
|
||||
api,
|
||||
route.repo,
|
||||
route.peer,
|
||||
repo,
|
||||
peers,
|
||||
);
|
||||
const branchMap = route.peer
|
||||
? await getPeerBranchMap(api, route.repo, route.peer)
|
||||
: canonicalBranchMap(repo);
|
||||
|
||||
if (!repo["payloads"]["xyz.radicle.project"]) {
|
||||
throw new Error(
|
||||
@@ -667,12 +632,10 @@ async function loadHistoryView(
|
||||
}
|
||||
|
||||
const project = repo["payloads"]["xyz.radicle.project"];
|
||||
let commitId;
|
||||
if (route.revision && isOid(route.revision)) {
|
||||
commitId = route.revision;
|
||||
} else if (branchMap) {
|
||||
commitId = branchMap[route.revision || project.data.defaultBranch];
|
||||
}
|
||||
const commitId =
|
||||
route.revision && isOid(route.revision)
|
||||
? route.revision
|
||||
: branchMap[route.revision || project.data.defaultBranch];
|
||||
|
||||
if (!commitId) {
|
||||
throw new Error(
|
||||
@@ -712,7 +675,6 @@ async function loadHistoryView(
|
||||
seedingPolicy,
|
||||
commit: commitId,
|
||||
repo,
|
||||
peers: peers.filter(peerHasBranches),
|
||||
peer: route.peer,
|
||||
revision: route.revision,
|
||||
tree,
|
||||
@@ -861,54 +823,48 @@ async function loadPatchView(
|
||||
};
|
||||
}
|
||||
|
||||
async function getPeerBranches(
|
||||
// Revision names resolvable without consulting any remote: the default branch
|
||||
// plus the delegate-approved canonical refs, both already carried on the `Repo`
|
||||
// object.
|
||||
function canonicalBranchMap(repo: Repo): Record<string, string> {
|
||||
const branchMap: Record<string, string> = {};
|
||||
|
||||
const project = repo.payloads["xyz.radicle.project"];
|
||||
if (project) {
|
||||
branchMap[project.data.defaultBranch] = project.meta.head;
|
||||
branchMap[encodeURIComponent(project.data.defaultBranch)] =
|
||||
project.meta.head;
|
||||
}
|
||||
|
||||
for (const [refName, oid] of canonicalOids(repo.refs)) {
|
||||
const shortName = refName.startsWith("refs/heads/")
|
||||
? refName.slice("refs/heads/".length)
|
||||
: refName.startsWith("refs/tags/")
|
||||
? refName.slice("refs/tags/".length)
|
||||
: refName;
|
||||
branchMap[shortName] = oid;
|
||||
branchMap[encodeURIComponent(shortName)] = oid;
|
||||
}
|
||||
|
||||
return branchMap;
|
||||
}
|
||||
|
||||
// Revision names published by a single remote. Fetching just that remote keeps
|
||||
// the full remote listing, which is expensive on repositories with many peers,
|
||||
// off the navigation path.
|
||||
async function getPeerBranchMap(
|
||||
api: HttpdClient,
|
||||
repoId: string,
|
||||
peer?: string,
|
||||
repo?: Repo,
|
||||
loadedPeers?: PeerRefs[],
|
||||
) {
|
||||
if (peer) {
|
||||
const remote = await api.repo.getRemoteByPeer(repoId, peer);
|
||||
const refs = remoteToPeerRefs(remote).refs;
|
||||
const map: Record<string, string> = { ...getBranchesFromRefs(refs) };
|
||||
for (const [tagName, oid] of Object.entries(getTagsFromRefs(refs))) {
|
||||
map[tagName] = oid;
|
||||
map[encodeURIComponent(tagName)] = oid;
|
||||
}
|
||||
return map;
|
||||
} else if (repo) {
|
||||
const branchMap: Record<string, string> = {};
|
||||
const peers = loadedPeers ?? [];
|
||||
|
||||
const project = repo.payloads["xyz.radicle.project"];
|
||||
if (project) {
|
||||
branchMap[project.data.defaultBranch] = project.meta.head;
|
||||
branchMap[encodeURIComponent(project.data.defaultBranch)] =
|
||||
project.meta.head;
|
||||
}
|
||||
|
||||
for (const [refName, oid] of canonicalOids(repo.refs)) {
|
||||
const shortName = refName.startsWith("refs/heads/")
|
||||
? refName.slice("refs/heads/".length)
|
||||
: refName.startsWith("refs/tags/")
|
||||
? refName.slice("refs/tags/".length)
|
||||
: refName;
|
||||
branchMap[shortName] = oid;
|
||||
branchMap[encodeURIComponent(shortName)] = oid;
|
||||
}
|
||||
|
||||
for (const p of peers) {
|
||||
const tags = getTagsFromRefs(p.refs);
|
||||
for (const [tagName, oid] of Object.entries(tags)) {
|
||||
branchMap[tagName] = oid;
|
||||
branchMap[encodeURIComponent(tagName)] = oid;
|
||||
}
|
||||
}
|
||||
return branchMap;
|
||||
} else {
|
||||
return undefined;
|
||||
peer: string,
|
||||
): Promise<Record<string, string>> {
|
||||
const remote = await api.repo.getRemoteByPeer(repoId, peer);
|
||||
const refs = remoteToPeerRefs(remote).refs;
|
||||
const map: Record<string, string> = { ...getBranchesFromRefs(refs) };
|
||||
for (const [tagName, oid] of Object.entries(getTagsFromRefs(refs))) {
|
||||
map[tagName] = oid;
|
||||
map[encodeURIComponent(tagName)] = oid;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
// Detects branch names and commit IDs at the start of `input` and extract it.
|
||||
|
||||
Reference in New Issue
Block a user