Skip to content

Commit a4a047d

Browse files
lmvasquezgfacebook-github-bot
authored andcommitted
modern sync: safer parent handling when casting file changes
Differential Revision: D67885460 fbshipit-source-id: 7ba83f2d08865f5cf76cac33b87f8c612466b096
1 parent 3f5cf53 commit a4a047d

File tree

1 file changed

+8
-6
lines changed
  • eden/mononoke/modern_sync/src/sender/edenapi

1 file changed

+8
-6
lines changed

eden/mononoke/modern_sync/src/sender/edenapi/util.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use anyhow::Result;
1111
use blobstore::Loadable;
1212
use bytes::Bytes;
1313
use bytes::BytesMut;
14+
use cloned::cloned;
1415
use context::CoreContext;
1516
use edenapi_service::utils::to_hg_path;
1617
use edenapi_types::commit::BonsaiExtra;
@@ -158,7 +159,7 @@ pub fn to_identical_changeset(
158159
.collect(),
159160
};
160161

161-
let bonsai_parents = BonsaiParents::from_iter(parents.iter().map(|p| (*p).into()));
162+
let bonsai_parents = BonsaiParents::from_iter(parents.clone().iter().map(|p| (*p).into()));
162163

163164
// Ensure items are indeed equivalent between bonsai and hg changeset
164165
ensure!(author.as_bytes() == hg_cs.user(), "Author mismatch");
@@ -188,7 +189,7 @@ pub fn to_identical_changeset(
188189
value: value.to_vec(),
189190
})
190191
.collect(),
191-
file_changes: to_file_change(&file_changes, bcs.parents())?,
192+
file_changes: to_file_change(&file_changes, parents.iter().copied())?,
192193
message: message.to_string(),
193194
is_snapshot,
194195
hg_info,
@@ -197,7 +198,7 @@ pub fn to_identical_changeset(
197198

198199
fn to_file_change(
199200
map: &SortedVectorMap<NonRootMPath, FileChange>,
200-
mut parents: impl Iterator<Item = ChangesetId>,
201+
parents: impl Iterator<Item = ChangesetId> + Clone,
201202
) -> Result<Vec<(RepoPathBuf, BonsaiFileChange)>> {
202203
let res = map
203204
.into_iter()
@@ -216,9 +217,10 @@ fn to_file_change(
216217
file_type: tc.file_type().try_into()?,
217218
copy_info: match tc.copy_from() {
218219
Some((path, cs_id)) => {
219-
let index = parents.position(|parent| parent == *cs_id).ok_or(
220-
anyhow::anyhow!("Error: Copy from info doesn't match parents"),
221-
)?;
220+
cloned!(mut parents);
221+
let index = parents
222+
.position(|parent| parent == *cs_id)
223+
.ok_or(anyhow::anyhow!("Copy from info doesn't match parents"))?;
222224
Some((to_hg_path(path)?, index))
223225
}
224226
None => None,

0 commit comments

Comments
 (0)