Skip to content

Commit

Permalink
merge op heads before snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
gulbanana committed Mar 19, 2024
1 parent 9e2ce1b commit af9d609
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Git remotes in the status bar, with push & fetch commands.
- "Create branch" command on revisions.
- Display edges to commits that aren't in the queried revset, by drawing a line to nowhere.
- Detect changes made by other Jujutsu clients and merge the operation log automatically.
- Window title includes the repository path.
- New config option gg.queries.log-page-size.
- Miscellaneous design improvements.
Expand Down
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ These changes may or may not be implemented in the future.
* bug: open menu command sometimes opens multiple dialogues
* bug: does not work when core.fsmonitor is true (watchman support not compiled in?)
* bug: appimage breaks cwd(). look at the OWD envar
* edge case: what happens when we snapshot after the CLI does? when there's nothing *to* snapshot, we don't refresh the ui...
* edge case: mutations can fail due to ambiguity due to other writers; this should update the UI. maybe use a special From on resolve_change
* perf: optimise revdetail loads - we already have the header
* perf: better solution to slow immutability check - jj-lib will have a revset contains cache soon
Expand Down
91 changes: 51 additions & 40 deletions src-tauri/src/worker/gui_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl WorkerSession {
&workspace::default_working_copy_factories(),
)?;

let operation = Self::load_at_head(&settings, &workspace)?;
let operation = load_at_head(&settings, &workspace)?;

let index_store = workspace.repo_loader().index_store();
let index = index_store
Expand All @@ -124,40 +124,6 @@ impl WorkerSession {
is_colocated
})
}

fn load_at_head(
settings: &UserSettings,
workspace: &Workspace,
) -> Result<SessionOperation> {
let loader = workspace.repo_loader();

let op = op_heads_store::resolve_op_heads(
loader.op_heads_store().as_ref(),
loader.op_store(),
|op_heads| {
let base_repo = loader.load_at(&op_heads[0])?;
// might want to set some tags
let mut tx = base_repo.start_transaction(settings);
for other_op_head in op_heads.into_iter().skip(1) {
tx.merge_operation(other_op_head)?;
tx.mut_repo().rebase_descendants(settings)?;
}
Ok::<Operation, RepoLoaderError>(
tx.write("resolve concurrent operations")
.leave_unpublished()
.operation()
.clone(),
)
},
)?;

let repo: Arc<ReadonlyRepo> = workspace
.repo_loader()
.load_at(&op)
.context("load op head")?;

Ok(SessionOperation::new(repo, workspace.workspace_id()))
}
}

impl WorkspaceSession<'_> {
Expand All @@ -168,6 +134,11 @@ impl WorkspaceSession<'_> {
pub fn wc_id(&self) -> &CommitId {
&self.operation.wc_id
}

// XXX maybe: hunt down uses and make nonpub
pub fn repo(&self) -> &ReadonlyRepo {
self.operation.repo.as_ref()
}

pub fn view(&self) -> &View {
self.operation.repo.view()
Expand All @@ -176,11 +147,6 @@ impl WorkspaceSession<'_> {
pub fn get_commit(&self, id: &CommitId) -> Result<Commit> {
Ok(self.operation.repo.store().get_commit(&id)?)
}

// XXX maybe: hunt down uses and make nonpub
pub fn repo(&self) -> &ReadonlyRepo {
self.operation.repo.as_ref()
}

pub fn git_repo(&self) -> Result<Option<Repository>> {
match self.operation.git_backend() {
Expand All @@ -193,6 +159,16 @@ impl WorkspaceSession<'_> {
self.settings.query_check_immutable().unwrap_or(!self.is_large)
}

pub fn load_at_head(&mut self) -> Result<bool> {
let head = load_at_head(&self.settings, &self.workspace)?;
if head.repo.op_id() != self.operation.repo.op_id() {
self.operation = head;
Ok(true)
} else {
Ok(false)
}
}

/***********************************************************/
/* Functions for evaluating revset expressions */
/* unfortunately parse_context and resolver are not cached */
Expand Down Expand Up @@ -965,3 +941,38 @@ fn build_branches_index(repo: &ReadonlyRepo) -> BranchIndex {
}
index
}


fn load_at_head(
settings: &UserSettings,
workspace: &Workspace,
) -> Result<SessionOperation> {
let loader = workspace.repo_loader();

let op = op_heads_store::resolve_op_heads(
loader.op_heads_store().as_ref(),
loader.op_store(),
|op_heads| {
let base_repo = loader.load_at(&op_heads[0])?;
// might want to set some tags
let mut tx = base_repo.start_transaction(settings);
for other_op_head in op_heads.into_iter().skip(1) {
tx.merge_operation(other_op_head)?;
tx.mut_repo().rebase_descendants(settings)?;
}
Ok::<Operation, RepoLoaderError>(
tx.write("resolve concurrent operations")
.leave_unpublished()
.operation()
.clone(),
)
},
)?;

let repo: Arc<ReadonlyRepo> = workspace
.repo_loader()
.load_at(&op)
.context("load op head")?;

Ok(SessionOperation::new(repo, workspace.workspace_id()))
}
3 changes: 2 additions & 1 deletion src-tauri/src/worker/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ impl Session for WorkspaceSession<'_> {
handle_query(&mut state, &self, tx, rx, revset_string, None)?;
}
SessionEvent::ExecuteSnapshot { tx } => {
if self.import_and_snapshot(false).is_ok_and(|updated| updated) {
let updated_head = self.load_at_head()?;
if self.import_and_snapshot(false)? || updated_head {
tx.send(Some(self.format_status()))?;
} else {
tx.send(None)?;
Expand Down

0 comments on commit af9d609

Please sign in to comment.