Skip to content

Commit a7b01bd

Browse files
committed
Keep using get_workspace_head() when no cached result is used.
That way, the application will not run into unexpected cases.
1 parent 79798c7 commit a7b01bd

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

crates/gitbutler-branch-actions/src/integration.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ use crate::{branch_manager::BranchManagerExt, conflicts, VirtualBranchesExt};
1919
const WORKSPACE_HEAD: &str = "Workspace Head";
2020
const GITBUTLER_INTEGRATION_COMMIT_TITLE: &str = "GitButler Integration Commit";
2121

22-
// Creates and returns a merge commit of all active branch heads.
23-
//
24-
// This is the base against which we diff the working directory to understand
25-
// what files have been modified.
22+
/// Creates and returns a merge commit of all active branch heads.
23+
///
24+
/// This is the base against which we diff the working directory to understand
25+
/// what files have been modified.
26+
///
27+
/// This should be used to update the `gitbutler/workspace` ref with, which is usually
28+
/// done from [`update_gitbutler_integration()`], after any of its input changes.
29+
/// This is namely the conflicting state, or any head of the virtual branches.
2630
#[instrument(level = tracing::Level::DEBUG, skip(ctx))]
2731
pub(crate) fn get_workspace_head(ctx: &CommandContext) -> Result<git2::Oid> {
2832
let vb_state = ctx.project().virtual_branches();

crates/gitbutler-branch-actions/src/status.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{collections::HashMap, path::PathBuf, vec};
22

3+
use crate::integration::get_workspace_head;
34
use crate::{
45
conflicts::RepoConflictsExt,
56
file::{virtual_hunks_into_virtual_files, VirtualBranchFile},
@@ -16,7 +17,6 @@ use gitbutler_command_context::CommandContext;
1617
use gitbutler_diff::{diff_files_into_hunks, GitHunk, Hunk, HunkHash};
1718
use gitbutler_operating_modes::assure_open_workspace_mode;
1819
use gitbutler_project::access::WorktreeWritePermission;
19-
use gitbutler_repo::RepositoryExt;
2020
use tracing::instrument;
2121

2222
/// Represents the uncommitted status of the applied virtual branches in the workspace.
@@ -52,11 +52,10 @@ pub fn get_applied_status_cached(
5252
.virtual_branches()
5353
.list_branches_in_workspace()?;
5454
let base_file_diffs = worktree_changes.map(Ok).unwrap_or_else(|| {
55-
// TODO(ST): this was `get_workspace_head()`, which is slow and ideally, we don't dynamically
56-
// calculate which should already be 'fixed' - why do we have the integration branch
57-
// if we can't assume it's in the right state? So ideally, we assure that the code
58-
// that affects the integration branch also updates it?
59-
let integration_commit_id = ctx.repository().head_commit()?.id();
55+
// TODO(ST): Ideally, we can avoid calling `get_workspace_head()` as everyone who modifies
56+
// any of its inputs will update the intragration commit right away.
57+
// It's for another day though - right now the integration commit may be slightly stale.
58+
let integration_commit_id = get_workspace_head(ctx)?;
6059
gitbutler_diff::workdir(ctx.repository(), &integration_commit_id.to_owned())
6160
.context("failed to diff workdir")
6261
})?;

0 commit comments

Comments
 (0)