Skip to content
Merged
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
30 changes: 16 additions & 14 deletions v5/client/src/api/commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ function holdsCommits(query: Query): boolean {
}

/**
* Mark stale what shows a commit of `suite`, after a change to its ordinal, tag or fields: every
* query about commits, every list that holds its commits' display values, and every trend, which
* ordinals place and window (E9). Nothing is fetched again until it is shown. What names a commit
* only by its value is left alone, such as a run's samples, which never change and would otherwise
* all be fetched again when next shown.
* Mark stale what shows a commit of `suite`, after a change to its ordinal, branch, tag or fields:
* every query about commits, every list that holds its commits' display values, and every trend,
* which ordinals and branches place and window (E9). Nothing is fetched again until it is shown.
* What names a commit only by its value is left alone, such as a run's samples, which never change
* and would otherwise all be fetched again when next shown.
*/
export async function commitChanged(queryClient: QueryClient, suite: SuiteRef): Promise<void> {
await queryClient.invalidateQueries({
Expand Down Expand Up @@ -206,23 +206,25 @@ export type PreviousCommit =
| { state: 'failed'; error: unknown }
/** The run's commit has no ordinal, so no commit comes before it. */
| { state: 'unordered' }
/** The machine has no run at an earlier commit. */
| { state: 'none' }
/** The machine has no run at an earlier commit of `branch`, the run's commit's. */
| { state: 'none'; branch: string | null }
| { state: 'found'; commit: Commit }

/**
* The commit before `value` at which `machine` has runs: the one with the nearest lower ordinal
* among the machine's commits (DT2), which the commit's own `previous` neighbour need not be. The
* commit is resolved first, since only one with an ordinal has a commit before it (the API refuses
* the others). The lookup is cached per machine, commit and ordinal, so that runs of the same
* machine at the same commit share it, and a new ordinal looks it up again.
* The commit before `value` at which `machine` has runs: the one of its branch with the nearest
* lower ordinal among the machine's commits (DT2), which the commit's own `previous` neighbour need
* not be. The commit is resolved first, since only one with an ordinal has a commit before it (the
* API refuses the others). The lookup is cached per machine, commit, ordinal and branch, so that
* runs of the same machine at the same commit share it, and a new ordinal or branch looks it up
* again.
*/
export function usePreviousCommit(suite: SuiteRef, value: string, machine: string): PreviousCommit {
const commit = useResolvedCommit(suite, value)
const ordinal = commit.data?.ordinal
const branch = commit.data?.branch ?? null
const ordered = ordinal != null
const lookup = useQuery({
queryKey: [...queryKeys.commits(suite), 'previous', { machine, commit: value, ordinal }],
queryKey: [...queryKeys.commits(suite), 'previous', { machine, commit: value, ordinal, branch }],
queryFn: ({ signal }) =>
firstCommit(suite, { machine, before_commit: value, sort: '-ordinal' }, signal),
enabled: ordered,
Expand All @@ -236,5 +238,5 @@ export function usePreviousCommit(suite: SuiteRef, value: string, machine: strin
if (!ordered) return { state: 'unordered' }
if (lookup.isError) return { state: 'failed', error: lookup.error }
if (lookup.isPending) return { state: 'pending' }
return lookup.data ? { state: 'found', commit: lookup.data } : { state: 'none' }
return lookup.data ? { state: 'found', commit: lookup.data } : { state: 'none', branch }
}
1 change: 1 addition & 0 deletions v5/client/src/components/commit-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function CommitSummary({ schema, commit, headingId }: ContentProps & { commit: C
<CommitString suite={refOf(schema)} value={commit.value} />
</InfoRow>
{commit.ordinal !== null && <InfoRow label="Ordinal">{commit.ordinal}</InfoRow>}
{commit.branch !== null && <InfoRow label="Branch">{commit.branch}</InfoRow>}
{fields.map(({ field, value }) => (
<InfoRow key={field.name} label={labelOf(field)}>
{/* Cut to two lines, but whole to assistive technology, which ignores the cut. */}
Expand Down
17 changes: 10 additions & 7 deletions v5/client/src/components/commit-link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const FIELDS_SUITE: Suite = {
const FULL = commit(HASH, {
ordinal: 593922,
tag: 'llvm-22.0',
branch: 'release/22.x',
fields: {
svn_revision: 'r593922',
commit_info: '[libc++] Optimize std::find\n\nA long description.',
Expand Down Expand Up @@ -527,7 +528,7 @@ describe('a ⓘ', () => {
})

describe('the content', () => {
it('shows the commit, its ordinal and every field it has a value for, in schema order', async () => {
it('shows the commit, its ordinal, its branch and every field it has a value for, in schema order', async () => {
await renderLink({ schema: FIELDS_SUITE })
// After `renderLink`, whose `userEvent.setup` installs a clipboard of its own.
const writeText = mockClipboard()
Expand All @@ -541,6 +542,7 @@ describe('the content', () => {
expect(labels).toEqual([
'Commit',
'Ordinal',
'Branch',
'svn_revision',
'commit_info',
'review',
Expand All @@ -556,22 +558,23 @@ describe('the content', () => {
const copy = within(values[0]).getByRole('button', { name: 'Copy commit' })
expect(copy).toHaveAttribute('title', 'Copy commit')
expect(values[1]).toHaveTextContent('593922')
expect(values[2]).toHaveTextContent('r593922')
expect(values[2]).toHaveTextContent('release/22.x')
expect(values[3]).toHaveTextContent('r593922')
// Cut to two lines, but whole in the page.
expect(values[3].firstElementChild).toHaveClass('clamped')
expect(values[3]).toHaveTextContent('[libc++] Optimize std::find A long description.')
expect(within(values[4]).getByRole('link')).toHaveAttribute(
expect(values[4].firstElementChild).toHaveClass('clamped')
expect(values[4]).toHaveTextContent('[libc++] Optimize std::find A long description.')
expect(within(values[5]).getByRole('link')).toHaveAttribute(
'href',
'https://github.com/llvm/llvm-project/pull/1',
)
expect(values[5]).toHaveTextContent('2026-08-25, 2:22:41 PM')
expect(values[6]).toHaveTextContent('2026-08-25, 2:22:41 PM')

await user.click(copy)
expect(writeText).toHaveBeenCalledWith(HASH)
await waitFor(() => expect(copy).toHaveAccessibleName('Copied.'))
})

it('has no ordinal row for a commit without one, and its commit string as its heading', async () => {
it('has no ordinal or branch row for a commit without them, and its commit string as its heading', async () => {
await renderLink({ given: commit(HASH) })
await open()
expect(card()).toHaveAccessibleName(HASH)
Expand Down
7 changes: 5 additions & 2 deletions v5/client/src/components/commit-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ export interface CommitSuggestion extends Suggestion {
commit: Commit
}

/** A commit as a suggestion: shown by its display value, and entered by its commit string too. */
/**
* A commit as a suggestion: shown by its display value, followed by its branch in muted text when
* it has one (AR15), and entered by its commit string too.
*/
export function suggestionOf(commit: Commit, schema: Suite): CommitSuggestion {
const text = commitDisplayValue(commit, schema)
const aliases = text === commit.value ? undefined : [commit.value]
return { key: commit.value, text, aliases, commit }
return { key: commit.value, text, aliases, note: commit.branch ?? undefined, commit }
}

/** The query key of the lookup of `commit` among the suite's commits under `filters`. */
Expand Down
50 changes: 50 additions & 0 deletions v5/client/src/components/commit-picker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,56 @@ describe('CommitPicker', () => {
expect(lookups(queries)).toEqual([])
})

describe('on several branches', () => {
const MAIN = commit('main300', { fields: { svn_revision: 'r300', commit_info: null } })
const RELEASE = commit('rel300', {
branch: 'release/19.x',
fields: { svn_revision: 'r300', commit_info: null },
})

it('shows the branch of a suggestion that has one, but not in the input once picked', async () => {
mockCommits(() => cursorPage([RELEASE, PLAIN]))
const user = userEvent.setup()
const { input } = renderPicker()

await openList(user)
await waitFor(() => expect(options()).toEqual(['r300 release/19.x', 'abc456']))
await user.click(screen.getByRole('option', { name: 'r300 release/19.x' }))

expect(value()).toBe('rel300')
expect(input).toHaveValue('r300')
})

it('searches for a branch, but does not pick a commit by Enter on it', async () => {
const queries = mockCommits(() => cursorPage([RELEASE]))
const user = userEvent.setup()
const { input } = renderPicker()

await user.type(input, 'release/19.x{Enter}')
await waitFor(() =>
expect(queries.some((query) => query.get('search') === 'release/19.x')).toBe(true),
)
expect(await screen.findByRole('option', { name: 'r300 release/19.x' })).toBeInTheDocument()
await settle()

expect(value()).toBe('none')
expect(input).toHaveValue('release/19.x')
})

it('does not pick by Enter a display value that commits of two branches share', async () => {
const queries = mockCommits(() => cursorPage([RELEASE, MAIN]))
const user = userEvent.setup()
const { input } = renderPicker()

await user.type(input, 'r300{Enter}')
await waitFor(() => expect(queries.some((query) => query.get('search') === 'r300')).toBe(true))
await settle()

expect(value()).toBe('none')
expect(input).toHaveValue('r300')
})
})

it('picks a commit by its commit string, entered with Enter', async () => {
serveCommits()
const user = userEvent.setup()
Expand Down
Loading
Loading