Move Generation struct to mononoke-types

Summary: Moved the Generation struct, which is a u64 wrapper, from repogen to mononoke-types, and updated the according usages. This should make it easier to phase out RepoGenCache.

Reviewed By: farnz

Differential Revision: D8725538

fbshipit-source-id: cfd39be03bae56d2288053b7b5e212e6d547c833
This commit is contained in:
Matthew Dippel 2018-07-04 13:38:39 -07:00 committed by Facebook Github Bot
parent 38b66202cb
commit d5541e465d
13 changed files with 60 additions and 41 deletions

View File

@ -0,0 +1,34 @@
// Copyright (c) 2017-present, Facebook, Inc.
// All Rights Reserved.
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
use std::{usize, u64};
use std::mem;
use asyncmemo::Weight;
/// Generation number
///
/// The generation number for a changeset is defined as the max of the changeset's parents'
/// generation number plus 1; if there are no parents then it's 1.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, HeapSizeOf)]
pub struct Generation(u64);
impl Weight for Generation {
fn get_weight(&self) -> usize {
mem::size_of::<Self>()
}
}
impl Generation {
/// Creates new generation number
pub fn new(gen: u64) -> Self {
Generation(gen)
}
/// Create a maximum possible generation number
pub fn max_gen() -> Self {
Generation(u64::MAX)
}
}

View File

@ -47,12 +47,14 @@ pub mod file_contents;
pub mod hash;
pub mod path;
pub mod typed_hash;
pub mod generation;
pub use blob::{Blob, BlobstoreBytes, BlobstoreValue, ChangesetBlob, ContentBlob};
pub use bonsai_changeset::BonsaiChangeset;
pub use datetime::DateTime;
pub use file_change::{FileChange, FileType};
pub use file_contents::FileContents;
pub use generation::Generation;
pub use path::{MPath, MPathElement, RepoPath};
pub use typed_hash::{ChangesetId, ContentId, MononokeId};

View File

@ -9,9 +9,8 @@
//! A generation number for a changeset is 1 + max(parents, 0). This number is computed for each
//! changeset and memoized for efficiency.
use std::{usize, u64};
use std::mem;
use std::sync::Arc;
use std::usize;
use failure::{err_msg, Error};
use futures::IntoFuture;
@ -19,37 +18,13 @@ use futures::future::{Either, Future};
use futures_ext::FutureExt;
use asyncmemo::{Asyncmemo, Filler, Weight};
use asyncmemo::{Asyncmemo, Filler};
use blobrepo::BlobRepo;
use mercurial_types::{HgChangesetId, HgNodeHash, NULL_HASH};
use mononoke_types::Generation;
use nodehashkey::Key;
/// Generation number
///
/// The generation number for a changeset is defined as the max of the changeset's parents'
/// generation number plus 1; if there are no parents then it's 1.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, HeapSizeOf)]
pub struct Generation(u64);
impl Weight for Generation {
fn get_weight(&self) -> usize {
mem::size_of::<Self>()
}
}
impl Generation {
/// Creates new generation number
pub fn new(gen: u64) -> Self {
Generation(gen)
}
/// Create a maximum possible generation number
pub fn max_gen() -> Self {
Generation(u64::MAX)
}
}
/// Cache of generation numbers
///
/// Allows generation numbers for a changeset to be computed lazily and cached.
@ -80,7 +55,7 @@ impl RepoGenCache {
nodeid: HgNodeHash,
) -> impl Future<Item = Generation, Error = Error> + Send {
if nodeid == NULL_HASH {
Either::A(Ok(Generation(0)).into_future())
Either::A(Ok(Generation::new(0)).into_future())
} else {
Either::B(self.cache.get((repo, nodeid.clone())))
}
@ -107,7 +82,7 @@ impl Filler for GenFiller {
let cs = HgChangesetId::new(*nodeid);
repo.get_generation_number(&cs)
.and_then(move |genopt| genopt.ok_or_else(|| err_msg(format!("{} not found", cs))))
.map(|gen| Generation(gen))
.map(|gen| Generation::new(gen))
.boxify()
}
}

View File

@ -16,12 +16,11 @@ extern crate changesets;
extern crate failure;
extern crate futures;
extern crate heapsize;
#[macro_use]
extern crate heapsize_derive;
extern crate blobrepo;
extern crate futures_ext;
extern crate mercurial_types;
extern crate mononoke_types;
mod gen;
mod nodehashkey;
@ -29,4 +28,4 @@ mod ptrwrap;
pub use ptrwrap::PtrWrap;
pub use gen::{Generation, RepoGenCache};
pub use gen::RepoGenCache;

View File

@ -19,7 +19,8 @@ use futures::stream::{iter_ok, Stream};
use blobrepo::BlobRepo;
use mercurial_types::{Changeset, HgNodeHash};
use mercurial_types::nodehash::HgChangesetId;
use repoinfo::{Generation, RepoGenCache};
use mononoke_types::Generation;
use repoinfo::RepoGenCache;
use IntersectNodeStream;
use NodeStream;

View File

@ -35,7 +35,8 @@ use futures_ext::{SelectAll, StreamExt};
use blobrepo::BlobRepo;
use mercurial_types::HgNodeHash;
use mercurial_types::nodehash::HgChangesetId;
use repoinfo::{Generation, RepoGenCache};
use mononoke_types::Generation;
use repoinfo::RepoGenCache;
use NodeStream;
use UniqueHeap;

View File

@ -9,7 +9,8 @@ use futures::Async;
use futures::Poll;
use futures::stream::Stream;
use mercurial_types::HgNodeHash;
use repoinfo::{Generation, RepoGenCache};
use mononoke_types::Generation;
use repoinfo::RepoGenCache;
use std::boxed::Box;
use std::collections::HashMap;
use std::collections::hash_map::IntoIter;

View File

@ -14,6 +14,7 @@ extern crate futures_ext;
#[macro_use]
extern crate maplit;
extern crate mercurial_types;
extern crate mononoke_types;
extern crate repoinfo;
use futures::stream::Stream;

View File

@ -17,7 +17,8 @@ use futures::stream::{self, iter_ok, Stream};
use blobrepo::BlobRepo;
use mercurial_types::{Changeset, HgNodeHash};
use mercurial_types::nodehash::HgChangesetId;
use repoinfo::{Generation, RepoGenCache};
use mononoke_types::Generation;
use repoinfo::RepoGenCache;
use NodeStream;
use errors::*;

View File

@ -8,7 +8,8 @@ use blobrepo::BlobRepo;
use futures::future::Future;
use futures::stream::Stream;
use mercurial_types::HgNodeHash;
use repoinfo::{Generation, RepoGenCache};
use mononoke_types::Generation;
use repoinfo::RepoGenCache;
use std::boxed::Box;
use std::sync::Arc;

View File

@ -8,7 +8,8 @@ use blobrepo::BlobRepo;
use futures::{Async, Poll};
use futures::stream::Stream;
use mercurial_types::HgNodeHash;
use repoinfo::{Generation, RepoGenCache};
use mononoke_types::Generation;
use repoinfo::RepoGenCache;
use std::boxed::Box;
use std::collections::HashSet;
use std::sync::Arc;

View File

@ -9,7 +9,8 @@ use futures::Async;
use futures::Poll;
use futures::stream::Stream;
use mercurial_types::HgNodeHash;
use repoinfo::{Generation, RepoGenCache};
use mononoke_types::Generation;
use repoinfo::RepoGenCache;
use std::boxed::Box;
use std::collections::HashSet;
use std::collections::hash_set::IntoIter;

View File

@ -12,7 +12,8 @@ use failure::Error;
use futures::{Async, Poll};
use futures::stream::Stream;
use mercurial_types::HgNodeHash;
use repoinfo::{Generation, RepoGenCache};
use mononoke_types::Generation;
use repoinfo::RepoGenCache;
use NodeStream;
use setcommon::{add_generations, InputStream};