Better merge_choose: prefer new.

GitOrigin-RevId: 9d737eeda18ece2cceb98f6e9f1dd95c0bd8294a
This commit is contained in:
levlam 2018-06-01 01:21:35 +03:00
parent 56d2beedc4
commit df900c867c

View File

@ -961,6 +961,8 @@ Result<FileId> FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sy
FileNodePtr nodes[] = {x_node, y_node, x_node};
FileNodeId node_ids[] = {get_file_id_info(x_file_id)->node_id_, get_file_id_info(y_file_id)->node_id_};
int trusted_by_source =
static_cast<int>(static_cast<int8>(x_node->remote_source_) < static_cast<int8>(y_node->remote_source_));
int local_i = merge_choose(x_node->local_, y_node->local_);
int remote_i = merge_choose(x_node->remote_, static_cast<int8>(x_node->remote_source_), y_node->remote_,
@ -989,6 +991,17 @@ Result<FileId> FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sy
return Status::Error("Can't merge files. Different encryption keys");
}
}
if (trusted_by_source == 0) { // if new is more trusted
if (remote_name_i == 2) {
remote_name_i = 0;
}
if (url_i == 2) {
url_i = 0;
}
if (expected_size_i == 2) {
expected_size_i = 0;
}
}
int node_i = std::make_tuple(y_node->pmc_id_ != 0, x_node->pmc_id_, y_node->file_ids_.size(), main_file_id_i == 1) >
std::make_tuple(x_node->pmc_id_ != 0, y_node->pmc_id_, x_node->file_ids_.size(), main_file_id_i == 0);