conflicts: add another helper for writing materialized conflict to store

This extracts a bit from `Transaction::check_out()` for taking a
Conflict, materializing it, and writing the resulting plain file to
the store. It will soon be reused.
This commit is contained in:
Martin von Zweigbergk 2020-12-25 23:55:18 -08:00
parent 9ade41078a
commit fa44ef8d1b
2 changed files with 21 additions and 15 deletions

View file

@ -16,7 +16,7 @@ use crate::files;
use crate::repo_path::RepoPath;
use crate::store::{Conflict, TreeValue};
use crate::store_wrapper::StoreWrapper;
use std::io::Write;
use std::io::{Cursor, Write};
pub fn materialize_conflict(
store: &StoreWrapper,
@ -99,3 +99,19 @@ pub fn materialize_conflict(
}
}
}
pub fn conflict_to_materialized_value(
store: &StoreWrapper,
path: &RepoPath,
conflict: &Conflict,
) -> TreeValue {
let mut buf = vec![];
materialize_conflict(store, &path, &conflict, &mut buf);
let file_id = store
.write_file(&path.to_file_repo_path(), &mut Cursor::new(&buf))
.unwrap();
TreeValue::Normal {
id: file_id,
executable: false,
}
}

View file

@ -21,10 +21,9 @@ use crate::operation::Operation;
use crate::repo::{ReadonlyRepo, Repo};
use crate::settings::UserSettings;
use crate::store;
use crate::store::{CommitId, Timestamp, TreeValue};
use crate::store::{CommitId, Timestamp};
use crate::store_wrapper::StoreWrapper;
use crate::view::{MutableView, ReadonlyView, View};
use std::io::Cursor;
use std::ops::Deref;
use std::sync::Arc;
@ -118,18 +117,9 @@ impl<'r> Transaction<'r> {
let mut tree_builder = store.tree_builder(commit.tree().id().clone());
for (path, conflict_id) in commit.tree().conflicts() {
let conflict = store.read_conflict(&conflict_id).unwrap();
let mut buf = vec![];
conflicts::materialize_conflict(store, &path, &conflict, &mut buf);
let file_id = store
.write_file(&path.to_file_repo_path(), &mut Cursor::new(&buf))
.unwrap();
tree_builder.set(
path,
TreeValue::Normal {
id: file_id,
executable: false,
},
);
let materialized_value =
conflicts::conflict_to_materialized_value(store, &path, &conflict);
tree_builder.set(path, materialized_value);
}
let tree_id = tree_builder.write_tree();
let open_commit;