Skip to content

Commit

Permalink
Make rev_chunk methods return HgObjectId instead of hg_object_id
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Nov 4, 2023
1 parent 501f6f1 commit 426d7b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
27 changes: 12 additions & 15 deletions src/hg_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,20 @@ pub struct rev_diff_part<'a> {
}

impl rev_chunk {
pub fn node(&self) -> &hg_object_id {
unsafe { self.node.as_ref() }
pub fn node(&self) -> HgObjectId {
unsafe { self.node.as_ref() }.clone().into()
}

pub fn parent1(&self) -> &hg_object_id {
unsafe { self.parent1.as_ref() }
pub fn parent1(&self) -> HgObjectId {
unsafe { self.parent1.as_ref() }.clone().into()
}

pub fn parent2(&self) -> &hg_object_id {
unsafe { self.parent2.as_ref() }
pub fn parent2(&self) -> HgObjectId {
unsafe { self.parent2.as_ref() }.clone().into()
}

pub fn delta_node(&self) -> &hg_object_id {
unsafe { self.delta_node.as_ref() }
pub fn delta_node(&self) -> HgObjectId {
unsafe { self.delta_node.as_ref() }.clone().into()
}

pub fn iter_diff(&self) -> RevDiffIter {
Expand Down Expand Up @@ -855,13 +855,10 @@ impl<R: Read> BundleConnection<R> {
for chunk in
RevChunkIter::new(version, part).progress(|n| format!("Analyzing {n} changesets"))
{
let node = HgChangesetId::from_unchecked(HgObjectId::from(chunk.node().clone()));
let parent1 =
HgChangesetId::from_unchecked(HgObjectId::from(chunk.parent1().clone()));
let parent2 =
HgChangesetId::from_unchecked(HgObjectId::from(chunk.parent2().clone()));
let delta_node =
HgChangesetId::from_unchecked(HgObjectId::from(chunk.delta_node().clone()));
let node = HgChangesetId::from_unchecked(chunk.node());
let parent1 = HgChangesetId::from_unchecked(chunk.parent1());
let parent2 = HgChangesetId::from_unchecked(chunk.parent2());
let delta_node = HgChangesetId::from_unchecked(chunk.delta_node());
let parents = [parent1, parent2];
let parents = parents
.into_iter()
Expand Down
21 changes: 9 additions & 12 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::cinnabar::{
};
use crate::git::{BlobId, CommitId, GitObjectId, TreeId, TreeIsh};
use crate::graft::{graft, grafted, GraftError};
use crate::hg::{HgChangesetId, HgFileId, HgManifestId, HgObjectId};
use crate::hg::{HgChangesetId, HgFileId, HgManifestId};
use crate::hg_bundle::{
read_rev_chunk, rev_chunk, BundlePartInfo, BundleSpec, BundleWriter, RevChunkIter,
};
Expand Down Expand Up @@ -1419,9 +1419,8 @@ pub fn store_changegroup<R: Read>(input: R, version: u8) {
for manifest in RevChunkIter::new(version, &mut input)
.progress(|n| format!("Reading and importing {n} manifests"))
{
let mid = HgManifestId::from_unchecked(HgObjectId::from(manifest.node().clone()));
let delta_node =
HgManifestId::from_unchecked(HgObjectId::from(manifest.delta_node().clone()));
let mid = HgManifestId::from_unchecked(manifest.node());
let delta_node = HgManifestId::from_unchecked(manifest.delta_node());
let reference_mn = if delta_node.is_null() {
RawHgManifest::empty()
} else {
Expand Down Expand Up @@ -1476,10 +1475,10 @@ pub fn store_changegroup<R: Read>(input: R, version: u8) {
} {
files.set(files.get() + 1);
for (file, ()) in RevChunkIter::new(version, &mut input).zip(&mut progress) {
let node = HgFileId::from_unchecked(HgObjectId::from(file.node().clone()));
let node = HgFileId::from_unchecked(file.node());
let parents = [
HgFileId::from_unchecked(HgObjectId::from(file.parent1().clone())),
HgFileId::from_unchecked(HgObjectId::from(file.parent2().clone())),
HgFileId::from_unchecked(file.parent1()),
HgFileId::from_unchecked(file.parent2()),
];
// Try to detect issue #207 as early as possible.
// Keep track of file roots of files with metadata and at least
Expand Down Expand Up @@ -1517,14 +1516,12 @@ pub fn store_changegroup<R: Read>(input: R, version: u8) {
.drain(..)
.progress(|n| format!("Importing {n} changesets"))
{
let delta_node =
HgChangesetId::from_unchecked(HgObjectId::from(changeset.delta_node().clone()));
let changeset_id =
HgChangesetId::from_unchecked(HgObjectId::from(changeset.node().clone()));
let delta_node = HgChangesetId::from_unchecked(changeset.delta_node());
let changeset_id = HgChangesetId::from_unchecked(changeset.node());
let parents = [changeset.parent1(), changeset.parent2()]
.into_iter()
.filter_map(|p| {
let p = HgChangesetId::from_unchecked(HgObjectId::from(p.clone()));
let p = HgChangesetId::from_unchecked(p);
(!p.is_null()).then_some(p)
})
.collect::<Vec<_>>();
Expand Down

0 comments on commit 426d7b5

Please sign in to comment.