From fa44ef8d1b32440d79928a911e21dbbf47e661b1 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 25 Dec 2020 23:55:18 -0800 Subject: [PATCH] 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. --- lib/src/conflicts.rs | 18 +++++++++++++++++- lib/src/transaction.rs | 18 ++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/src/conflicts.rs b/lib/src/conflicts.rs index 98f71c636..5c12e5add 100644 --- a/lib/src/conflicts.rs +++ b/lib/src/conflicts.rs @@ -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, + } +} diff --git a/lib/src/transaction.rs b/lib/src/transaction.rs index d9e9a0d16..2bee205d4 100644 --- a/lib/src/transaction.rs +++ b/lib/src/transaction.rs @@ -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;