Skip to content

Commit 5cfd4a1

Browse files
authored
Merge pull request #12080 from gitbutlerapp/kv-branch-89
feat(oplog): Refactor virtual branches metadata handling and insertion
2 parents 8cd384c + 8f1a3d5 commit 5cfd4a1

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

crates/gitbutler-oplog/src/oplog.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,6 @@ pub fn prepare_snapshot(
379379
let default_target_commit = repo.find_commit(vb_state.get_default_target()?.sha)?;
380380
let target_tree_id = default_target_commit.tree_id();
381381

382-
// Create a blob out of `.git/gitbutler/virtual_branches.toml`
383-
let vb_path = repo.path().join("gitbutler").join("virtual_branches.toml");
384-
let vb_content = fs::read(vb_path)?;
385-
let vb_blob_id = repo.blob(&vb_content)?;
386-
387382
// Create a tree out of the conflicts state if present
388383
let conflicts_tree_id = write_conflicts_tree(&repo)?;
389384

@@ -396,7 +391,6 @@ pub fn prepare_snapshot(
396391
tree_builder.insert("index", index_tree_oid, FileMode::Tree.into())?;
397392
tree_builder.insert("target_tree", target_tree_id, FileMode::Tree.into())?;
398393
tree_builder.insert("conflicts", conflicts_tree_id, FileMode::Tree.into())?;
399-
tree_builder.insert("virtual_branches.toml", vb_blob_id, FileMode::Blob.into())?;
400394

401395
// go through all virtual branches and create a subtree for each with the tree and any commits encoded
402396
let mut branches_tree_builder = repo.treebuilder(None)?;
@@ -450,6 +444,14 @@ pub fn prepare_snapshot(
450444
)?;
451445
}
452446

447+
// The loop above may update the toml file in the stack.sync_heads_with_references call so write the virtual_branches.toml after
448+
// It may be the case that with the refactoring through `but-meta` the head value is no longer in sync so sync_heads_with_references is the final attempt to sync it
449+
// This is relevant only for snapshot restore.
450+
// Create a blob out of `.git/gitbutler/virtual_branches.toml`
451+
let vb_path = repo.path().join("gitbutler").join("virtual_branches.toml");
452+
let vb_content = fs::read(vb_path)?;
453+
let vb_blob_id = repo.blob(&vb_content)?;
454+
tree_builder.insert("virtual_branches.toml", vb_blob_id, FileMode::Blob.into())?;
453455
// Add the worktree tree
454456
let worktree = repo.create_wd_tree(AUTO_TRACK_LIMIT_BYTES)?;
455457
tree_builder.insert("worktree", worktree.id(), FileMode::Tree.into())?;

0 commit comments

Comments
 (0)