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
59 changes: 52 additions & 7 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,9 @@ or removing a command fails until the table changes in the same commit.
| `git.historyLocate` | Append bounded history pages until one commit is found and report the budget, window cursor, and exhaustion |
| `git.branchNamePreview` | Clean and validate a new branch name against already loaded references without running Git |
| `git.repositoryColorAssignments` | Assign color slots to a bounded page of ordered repository identities |
| `git.workspaceRepositorySelection` | Choose the workspace repository a view acts on and the others it lists for switching, from discovery entries and the previous pick |
| `git.workspaceRepositorySelection` | Choose the workspace repository, or the set of repositories, a view acts on and the others it lists for switching, from discovery entries and the previous pick |
| `git.workspaceChangeGroups` | Group every workspace repository's status changes, plan each group's and the workspace line's staging, and report what a listed ancestor records for a submodule |
| `git.workspaceHistoryMerge` | Interleave the loaded history pages of several workspace repositories into one stable newest-first list with collision-safe commit keys, and name the repositories whose next page it waits on |
| `git.updatePlan` | Route a branch Update and gate a Pull from facts the host collected: blockers, strategy default, whether to ask, and the expected checkout |
| `git.historyWindow` | Plan a history refresh window, page merge, and selection retention over commit identities |
| `git.graphProjection` | Project a loaded history window into commit-graph lanes, color IDs, routes, print elements, and labels, optionally filtered |
Expand Down Expand Up @@ -1794,7 +1795,8 @@ Each visible row carries `commitHash`, integer `lane` and `laneCount`, a signed
`printElements` (the up and down half-edges with `position`, `adjacentPosition`,
`colorId`, `isDotted`, `isMissing`, `hasArrow`, `isTerminal`, `targetHash`). Hosts own
pixels, curves, and the mapping from a color ID to a theme color; `colorId` `0` means
an unreferenced fragment. Requests over 20,000 commits fail with `invalid_request`.
an unreferenced fragment. Requests over 100,000 commits, the largest Git Log a
`git.historyPage` stream reads, fail with `invalid_request`.
`rust/fixtures/git/graph-projection-v1.json` defines the rules and
`rust/fixtures/git/graph-idea/` holds the pinned IntelliJ oracles.

Expand Down Expand Up @@ -1958,7 +1960,7 @@ core clamps it to `1...5000`). It remains the compatibility command that
combines `git.references` with the first `git.historyPage`. New clients use
`git.references` with `{ "root": string }` and request commits separately with
`git.historyPage` using `root`, optional full `reference`, nullable opaque
`cursor`, `limit`, and optional `order` (`"topo"` or `"date"`). Omitted
`cursor`, `limit`, optional `maxCommits`, and optional `order` (`"topo"` or `"date"`). Omitted
`order` preserves the original `git log --topo-order` behavior. `"date"` uses
`git log --date-order`: committer date descending whenever the child-before-
parent constraint permits, independently of the displayed author date. macOS
Expand All @@ -1969,9 +1971,17 @@ continuations must repeat the same order. A mismatched order returns
`rust/fixtures/git/history-page-date-request-v1.json`.
The first request omits `cursor`; each later request
returns the prior page's `nextCursor`. Core keeps one bounded, backpressured
`git log` stream behind that cursor and clamps the stream to the first 5,000
commits, so later pages continue traversal instead of replaying earlier commits.
A history page returns `commits`, nullable `nextCursor`, and `hasMore`. Clients
`git log` stream behind that cursor and clamps the stream to the first
`maxCommits` commits, so later pages continue traversal instead of replaying earlier
commits. `maxCommits` is 1 to 100,000 and defaults to 5,000; the first page fixes it
for the cursor, a continuation omits it or repeats the same value, and a different
value returns `invalid_request` without consuming the cursor. `maxCommits` with
`offset`, or out of range, fails with `invalid_request`; the deprecated offset pages
keep the 5,000 bound.
A history page returns `commits`, nullable `nextCursor`, and `hasMore`. When the
stream stops at `maxCommits` while the history goes on, the last page also returns
`limitReached: true` with `hasMore: false`, so a client can tell a bounded log from
a finished one and offer a larger bound; the field is omitted otherwise. Clients
call `git.historyCursorClose` with `root` and `cursor` when abandoning an
unfinished stream, and discard and close a late page when its repository,
selected reference, or owning `operationId` is stale. Core also expires idle
Expand Down Expand Up @@ -2041,12 +2051,47 @@ for an empty list; `fellBack` is `true` only when `selected` was given and is no
longer listed, so the view drops state that belonged to it such as an open
history cursor or a reference filter; `others` are the remaining IDs in
discovery order, the groups the branch popup and the Git Log list for switching.
A view that acts on several repositories at once, such as a Git Log that shows
the histories of a chosen set in one list, sends `chosen`, the IDs it picked
before in any order, instead of `selected`; an empty list is no pick. The
response then also carries `chosen`: the listed picks in discovery order, or
`[active]` when none is listed (`[]` for an empty workspace). `active` is the
first of them, `others` are every ID outside them, and `fellBack` is `true` when
any pick is no longer listed. Without `chosen` in the request the response has
no `chosen` field.
The list holds at most 10,000 entries. An ID that is empty, longer than 4,096
bytes, starts with `/`, or contains `\` or NUL, an empty path or name, a repeated
ID or path, more than one `workspace` role, an unknown role, an empty `selected`,
or an unknown field fails with `invalid_request`. See
both `selected` and `chosen`, a `chosen` ID that is invalid or repeated, or an
unknown field fails with `invalid_request`. See
`rust/fixtures/git/workspace-repository-selection-v1.json`.

`git.workspaceHistoryMerge` is pure. It accepts `{ repositories }`, the
repositories a log walks in the order the view lists them, each
`{ id, commits, complete }`: `id` is the `workspace.repositories` ID, `commits`
are every commit loaded so far in the order Git walked them as
`{ hash, parentHashes?, timestamp? }` (`timestamp` is the `git.historyPage`
`dateUnixSeconds`), and `complete` is `true` once no page is left. The response
is `{ entries, pending }`. `entries` is the merged list newest first, each
`{ repository, index, key, parentKeys }`: `repository` indexes the request's
`repositories`, `index` that repository's `commits`. Each repository keeps its
own order; among the next commits of the repositories the newest timestamp goes
first, a commit without one takes the timestamp placed before it in its
repository, and equal timestamps go in request order. The merge stops as soon as
a repository that is not `complete` has no loaded commit left, because its next
page may hold a newer commit than every one still unplaced; `pending` lists those
repositories' indices in request order, and is empty when every loaded commit is
placed and no page is left. A view loads the next page of each pending repository
and asks again; the earlier entries stay the same, so rows only grow at the end.
`key` is the commit's hash, except that a hash more than one repository names,
as a commit or as a parent, is keyed `<hash>@<id>` in each of them; `parentKeys`
apply the same rule, so `git.graphProjection` laid out over the keys never joins
two repositories. At most 10,000 repositories and 100,000 commits in total,
the bound of `git.graphProjection`, are accepted. An invalid or repeated `id`, a hash or parent that is not 1 to 64
hexadecimal digits, a commit repeated within one repository, a missing
`complete`, or an unknown field fails with `invalid_request`. See
`rust/fixtures/git/workspace-history-merge-v1.json`.

`git.workspaceChangeGroups` is pure and validates `repositories` the same way;
each entry also carries `changes`, the `git.status` changes read for that
repository, passed through unchanged. Core reads `path`, `originalPath`,
Expand Down
5 changes: 4 additions & 1 deletion rust/crates/core/src/protocol/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,10 +844,12 @@ pub enum GitCommand {
BranchNamePreview,
/// Assigns palette slots to a page of ordered repository identities.
RepositoryColorAssignments,
/// Chooses the workspace repository a view acts on (`git.workspaceRepositorySelection`).
/// Chooses the workspace repositories a view acts on (`git.workspaceRepositorySelection`).
WorkspaceRepositorySelection,
/// Groups workspace repositories' changes and plans their staging (`git.workspaceChangeGroups`).
WorkspaceChangeGroups,
/// Interleaves the loaded histories of workspace repositories (`git.workspaceHistoryMerge`).
WorkspaceHistoryMerge,
/// Plans a branch Update or Pull from collected facts (`git.updatePlan`).
UpdatePlan,
/// Plans history refresh windows, page merges, and selection retention (`git.historyWindow`).
Expand Down Expand Up @@ -1472,6 +1474,7 @@ impl CoreCommand {
Some(Self::Git(GitCommand::WorkspaceRepositorySelection))
}
"git.workspaceChangeGroups" => Some(Self::Git(GitCommand::WorkspaceChangeGroups)),
"git.workspaceHistoryMerge" => Some(Self::Git(GitCommand::WorkspaceHistoryMerge)),
"git.updatePlan" => Some(Self::Git(GitCommand::UpdatePlan)),
"git.historyWindow" => Some(Self::Git(GitCommand::HistoryWindow)),
"git.graphProjection" => Some(Self::Git(GitCommand::GraphProjection)),
Expand Down
3 changes: 3 additions & 0 deletions rust/crates/core/src/runtime/dispatcher/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ pub(super) fn dispatch(command: GitCommand, id: Option<String>, payload: Value)
GitCommand::WorkspaceChangeGroups => {
plugin_response(id, payload, lithe_git::workspace_change_groups_command)
}
GitCommand::WorkspaceHistoryMerge => {
plugin_response(id, payload, lithe_git::workspace_history_merge_command)
}
GitCommand::UpdatePlan => plugin_response(id, payload, lithe_git::update_plan_command),
GitCommand::HistoryWindow => {
plugin_response(id, payload, lithe_git::history_window_command)
Expand Down
72 changes: 71 additions & 1 deletion rust/crates/core/src/tests/git_workspace_repositories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn check_fixture(command: &str, fixture: &str) {
}

#[test]
fn selection_and_change_groups_match_their_shared_fixtures() {
fn selection_change_groups_and_history_merge_match_their_shared_fixtures() {
check_fixture(
"git.workspaceRepositorySelection",
include_str!("../../../../fixtures/git/workspace-repository-selection-v1.json"),
Expand All @@ -72,6 +72,10 @@ fn selection_and_change_groups_match_their_shared_fixtures() {
"git.workspaceChangeGroups",
include_str!("../../../../fixtures/git/workspace-change-groups-v1.json"),
);
check_fixture(
"git.workspaceHistoryMerge",
include_str!("../../../../fixtures/git/workspace-history-merge-v1.json"),
);
}

/// Discovery entries with the status each repository reports, as hosts send them.
Expand Down Expand Up @@ -169,3 +173,69 @@ fn discovery_and_status_pass_through_to_selection_and_change_groups() {
"{groups}"
);
}

/// Commits `message` in `root` with `date` as both the author and the committer date.
fn commit_at(root: &Path, message: &str, date: &str) {
fs::write(root.join("file.txt"), message).unwrap();
git(root, &["add", "file.txt"]);
git(root, &["commit", "-qm", message, "--date", date]);
}

/// One `git.historyPage` page of `root` as the merge takes it.
fn history_page(root: &Path, id: &str, limit: usize) -> Value {
let page = data(
"git.historyPage",
json!({"root": root, "order": "date", "limit": limit}),
);
let commits = page["commits"]
.as_array()
.unwrap()
.iter()
.map(|commit| {
json!({
"hash": commit["hash"],
"parentHashes": commit["parentHashes"],
"timestamp": commit["dateUnixSeconds"],
})
})
.collect::<Vec<_>>();
json!({"id": id, "complete": page["hasMore"] == false, "commits": commits})
}

#[test]
fn history_pages_pass_through_to_the_history_merge() {
let folder = Folder(temporary_root("workspace-history-merge"));
let backend = folder.0.join("backend");
let frontend = folder.0.join("frontend");
init(&backend);
init(&frontend);
commit_at(&backend, "backend one", "2026-01-01T10:00:00+00:00");
commit_at(&frontend, "frontend one", "2026-01-02T10:00:00+00:00");
commit_at(&backend, "backend two", "2026-01-03T10:00:00+00:00");

// A first page that leaves backend's older commit unread stops after it.
let merged = data(
"git.workspaceHistoryMerge",
json!({"repositories": [history_page(&backend, "backend", 1), history_page(&frontend, "frontend", 100)]}),
);
assert_eq!(merged["pending"], json!([0]), "{merged}");
assert_eq!(merged["entries"].as_array().unwrap().len(), 1, "{merged}");

let merged = data(
"git.workspaceHistoryMerge",
json!({"repositories": [history_page(&backend, "backend", 100), history_page(&frontend, "frontend", 100)]}),
);
let order = merged["entries"]
.as_array()
.unwrap()
.iter()
.map(|entry| {
(
entry["repository"].as_u64().unwrap(),
entry["index"].as_u64().unwrap(),
)
})
.collect::<Vec<_>>();
assert_eq!(order, [(0, 0), (1, 0), (0, 1)], "{merged}");
assert_eq!(merged["pending"], json!([]), "{merged}");
}
3 changes: 3 additions & 0 deletions rust/crates/git/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ pub struct GitHistoryPageResponse {
#[serde(skip_serializing_if = "Option::is_none")]
pub next_offset: Option<usize>,
pub(crate) has_more: bool,
/// The stream stopped at its `maxCommits` while the history goes on; omitted when false.
#[serde(skip_serializing_if = "std::ops::Not::not")]
pub(crate) limit_reached: bool,
}

#[derive(Debug, Clone, Serialize)]
Expand Down
5 changes: 3 additions & 2 deletions rust/crates/git/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ use std::cmp::Ordering;
use std::collections::{HashMap, HashSet};

const GRAPH_PROJECTION_VERSION: u32 = 1;
/// Largest commit list (scoped window or repository context) one request may carry.
const MAX_COMMITS: usize = 20_000;
/// Largest commit list (scoped window or repository context) one request may carry: the
/// largest Git Log a view may read.
const MAX_COMMITS: usize = crate::history::MAX_LOG_COMMITS;
/// IntelliJ samples at most this many rows when recommending a graph width.
const RECOMMENDED_WIDTH_SAMPLE_SIZE: usize = 20_000;
const RECOMMENDED_WIDTH_WEIGHT_RATIO: f64 = 0.1;
Expand Down
Loading
Loading