Handle large working copies in the desktop client

A working copy with 44,702 new files produced an 8.3 MB change list,
over the 1 MiB line limit on both sides of the service socket, so the
GUI dropped the connection and reconnected in a loop.

- Raise the limit to 256 MiB from the service and 64 MiB to it, and
  show an oversized message as an error instead of reconnecting.
- Draw only the visible rows of the CHANGES list, and build the lock
  list only when LOCK is pressed rather than every frame.
- Match the chosen paths in submit with a set.
- Treat sync on a repository with no revisions yet as up to date,
  rather than surfacing Lore's "No remote configured".
This commit is contained in:
Peterino 2026-11-26 20:53:08 -07:00
parent e230e4e7eb
commit 49a6c109b7
5 changed files with 47 additions and 15 deletions

View File

@ -906,14 +906,16 @@ void Explorer::DrawChanges(const model::Workspace &ws, model::Repo &repo, Explor
host.LoadChanges(); host.LoadChanges();
ImGui::SameLine(0, 12); ImGui::SameLine(0, 12);
// Files someone else has locked stay out of the submit whatever is chosen. // Files someone else has locked stay out of the submit whatever is chosen.
// Counted every frame over what may be tens of thousands of changes: no copies here.
int checked = 0, blocked = 0; int checked = 0, blocked = 0;
std::vector<std::string> to_lock; bool lockable = false;
auto can_lock = [](const model::Change &c) { return c.lock.empty() && c.action != model::Action::Delete; };
const bool none_unchecked = repo.unchecked.empty();
for (const auto &c : repo.changes) { for (const auto &c : repo.changes) {
bool on = !repo.unchecked.count(c.path) && !c.Blocked(); bool on = !c.Blocked() && (none_unchecked || !repo.unchecked.count(c.path));
checked += on; checked += on;
blocked += c.Blocked(); blocked += c.Blocked();
if (on && c.lock.empty() && c.action != model::Action::Delete) lockable = lockable || (on && can_lock(c));
to_lock.push_back(c.path);
} }
if (theme::Button("ALL", !repo.changes.empty())) if (theme::Button("ALL", !repo.changes.empty()))
repo.unchecked.clear(); repo.unchecked.clear();
@ -922,8 +924,13 @@ void Explorer::DrawChanges(const model::Workspace &ws, model::Repo &repo, Explor
for (const auto &c : repo.changes) for (const auto &c : repo.changes)
repo.unchecked.insert(c.path); repo.unchecked.insert(c.path);
ImGui::SameLine(0, 12); ImGui::SameLine(0, 12);
if (theme::Button("LOCK", connected && !busy && ws.signed_in && !to_lock.empty())) if (theme::Button("LOCK", connected && !busy && ws.signed_in && lockable)) {
std::vector<std::string> to_lock;
for (const auto &c : repo.changes)
if (!c.Blocked() && !repo.unchecked.count(c.path) && can_lock(c))
to_lock.push_back(c.path);
host.Lock(to_lock); host.Lock(to_lock);
}
if (ImGui::IsItemHovered()) if (ImGui::IsItemHovered())
ImGui::SetTooltip("lock the chosen files nobody holds yet"); ImGui::SetTooltip("lock the chosen files nobody holds yet");
ImGui::SameLine(0, 16); ImGui::SameLine(0, 16);
@ -943,7 +950,12 @@ void Explorer::DrawChanges(const model::Workspace &ws, model::Repo &repo, Explor
Note("scanning"); Note("scanning");
else if (repo.changes.empty()) else if (repo.changes.empty())
Note(ws.ahead ? "nothing changed here; unpushed revisions remain" : "nothing changed here"); Note(ws.ahead ? "nothing changed here; unpushed revisions remain" : "nothing changed here");
for (const auto &c : repo.changes) { // Only the rows in view are drawn: a first import lists every file in the tree.
ImGuiListClipper clipper;
clipper.Begin(int(repo.changes.size()), kRowH);
while (clipper.Step())
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; ++i) {
const model::Change &c = repo.changes[size_t(i)];
ImGui::PushID(c.path.c_str()); ImGui::PushID(c.path.c_str());
bool on = !repo.unchecked.count(c.path) && !c.Blocked(); bool on = !repo.unchecked.count(c.path) && !c.Blocked();
if (theme::Row("change", false, kRowH) && !c.Blocked()) { if (theme::Row("change", false, kRowH) && !c.Blocked()) {

View File

@ -861,6 +861,8 @@ void App::HandleIncoming() {
greeted_ = false; greeted_ = false;
break; break;
case ServiceClient::Incoming::Kind::Disconnected: case ServiceClient::Incoming::Kind::Disconnected:
if (incoming.detail != "connection closed")
error_ = "lost the service: " + incoming.detail;
greeted_ = false; greeted_ = false;
have_status_ = false; have_status_ = false;
pending_.clear(); pending_.clear();

View File

@ -22,7 +22,9 @@ constexpr int kStartWaitMs = 5000;
// How often to retry while unavailable, and to try starting it again. // How often to retry while unavailable, and to try starting it again.
constexpr int kRetryMs = 2000; constexpr int kRetryMs = 2000;
constexpr int kRespawnMs = 15000; constexpr int kRespawnMs = 15000;
constexpr size_t kMaxLine = 1u << 20; // The longest message taken from the service. A workspace's change list runs to about 190
// bytes a file, so this holds over a million changed files.
constexpr size_t kMaxLine = size_t(256) << 20;
int64_t NowMs() { int64_t NowMs() {
using namespace std::chrono; using namespace std::chrono;
@ -139,6 +141,7 @@ void ServiceClient::Run() {
if (Connect()) { if (Connect()) {
SetState(State::Connected); SetState(State::Connected);
Push({Incoming::Kind::Connected, {}, {}}); Push({Incoming::Kind::Connected, {}, {}});
closed_because_.clear();
Serve(); Serve();
Close(); Close();
if (stop_) if (stop_)
@ -147,8 +150,9 @@ void ServiceClient::Run() {
std::lock_guard<std::mutex> lock(mutex_); std::lock_guard<std::mutex> lock(mutex_);
outgoing_.clear(); outgoing_.clear();
} }
SetState(State::Connecting, "connection closed"); std::string why = closed_because_.empty() ? "connection closed" : closed_because_;
Push({Incoming::Kind::Disconnected, {}, "connection closed"}); SetState(State::Connecting, why);
Push({Incoming::Kind::Disconnected, {}, why});
if (!SleepUnlessStopped(300)) if (!SleepUnlessStopped(300))
break; break;
continue; continue;
@ -275,8 +279,10 @@ void ServiceClient::Serve() {
Push({Incoming::Kind::Message, std::move(message), {}}); Push({Incoming::Kind::Message, std::move(message), {}});
buffer.erase(0, newline + 1); buffer.erase(0, newline + 1);
} }
if (buffer.size() > kMaxLine) if (buffer.size() > kMaxLine) {
closed_because_ = "a message from the service was over " + std::to_string(kMaxLine >> 20) + " MiB";
break; break;
}
} else if (which == WAIT_OBJECT_0 + 1) { } else if (which == WAIT_OBJECT_0 + 1) {
std::deque<std::string> lines; std::deque<std::string> lines;
{ {
@ -404,10 +410,12 @@ void ServiceClient::Serve() {
Push({Incoming::Kind::Message, std::move(message), {}}); Push({Incoming::Kind::Message, std::move(message), {}});
buffer.erase(0, newline + 1); buffer.erase(0, newline + 1);
} }
if (buffer.size() > kMaxLine) if (buffer.size() > kMaxLine) {
closed_because_ = "a message from the service was over " + std::to_string(kMaxLine >> 20) + " MiB";
return; return;
} }
} }
} }
}
#endif #endif

View File

@ -81,6 +81,8 @@ class ServiceClient {
std::atomic<bool> restart_requested_{false}; std::atomic<bool> restart_requested_{false};
mutable std::mutex mutex_; mutable std::mutex mutex_;
// Set by the reading thread when it gives up on the connection, for the disconnect.
std::string closed_because_;
std::string detail_; std::string detail_;
std::deque<std::string> outgoing_; std::deque<std::string> outgoing_;
std::vector<Incoming> incoming_; std::vector<Incoming> incoming_;

View File

@ -77,8 +77,9 @@ mod watch;
use watch::Watches; use watch::Watches;
/// The longest message accepted from a frontend. /// The longest message accepted from a frontend. SUBMIT names every chosen file, about 60 bytes
const MAX_LINE: u64 = 1 << 20; /// each, so this takes over a million.
const MAX_LINE: u64 = 64 << 20;
/// How many branches `history` reads, and revisions per branch by default. /// How many branches `history` reads, and revisions per branch by default.
const MAX_BRANCHES: usize = 12; const MAX_BRANCHES: usize = 12;
const DEFAULT_HISTORY: u32 = 50; const DEFAULT_HISTORY: u32 = 50;
@ -680,7 +681,13 @@ impl Service {
match synced { match synced {
Ok(()) => Ok(Ok(outcome)), Ok(()) => Ok(Ok(outcome)),
Err(error) if lore::is_overlap(&error) => Ok(Err(lore::describe("sync", &error))), Err(error) if lore::is_overlap(&error) => Ok(Err(lore::describe("sync", &error))),
Err(error) => Err(lore_failure("sync", error)), // Lore refuses to sync a branch that has no revision here or on the remote, as
// a new repository's has until its first push, with "No remote configured".
// There is nothing to sync, which is not an error.
Err(error) => match lore::status(lore, &path, false) {
Ok(position) if position.status.local_number == 0 && position.status.remote_number == 0 => Ok(Ok(None)),
_ => Err(lore_failure("sync", error)),
},
} }
}) })
.await; .await;
@ -727,10 +734,11 @@ impl Service {
if !paths.is_empty() { if !paths.is_empty() {
// Leave staged only what was chosen. // Leave staged only what was chosen.
let position = lore::status(lore, &path, true).map_err(|error| lore_failure("status", error))?; let position = lore::status(lore, &path, true).map_err(|error| lore_failure("status", error))?;
let chosen: std::collections::HashSet<&String> = paths.iter().collect();
let unwanted: Vec<String> = position let unwanted: Vec<String> = position
.files .files
.iter() .iter()
.filter(|file| file.staged && !paths.contains(&file.path)) .filter(|file| file.staged && !chosen.contains(&file.path))
.map(|file| file.path.clone()) .map(|file| file.path.clone())
.collect(); .collect();
if !unwanted.is_empty() { if !unwanted.is_empty() {