mononoke: add new methods to blobrepo

Summary:
These methods are
1) get_file_copy(node) -> returns copy info for a file (copyfrom revision and copyfrom filename). Can be None.
2) get_parents(node) -> returns parents of the node

It will be used in remotefilelog getfiles method to construct file history.

Reviewed By: jsgf

Differential Revision: D6913176

fbshipit-source-id: ba74a71926c5ca80249f8cc0f300a0aa20a65bbc
This commit is contained in:
Stanislau Hlebik 2018-02-13 08:46:50 -08:00 committed by Facebook Github Bot
parent 0ad9a311ff
commit 590b166d09
2 changed files with 33 additions and 9 deletions

View File

@ -11,7 +11,7 @@ use futures::future::Future;
use futures_ext::{BoxFuture, FutureExt};
use mercurial::file;
use mercurial_types::{Blob, MPath, MPathElement, ManifestId, NodeHash, Parents};
use mercurial_types::{Blob, BlobNode, MPath, MPathElement, ManifestId, NodeHash, Parents};
use mercurial_types::manifest::{Content, Entry, Manifest, Type};
use mercurial_types::nodehash::EntryId;
@ -30,21 +30,30 @@ pub struct BlobEntry {
ty: Type,
}
pub fn fetch_file_content_from_blobstore(
pub fn fetch_file_content_and_renames_from_blobstore(
blobstore: &Arc<Blobstore>,
nodeid: NodeHash,
) -> BoxFuture<Vec<u8>, Error> {
) -> BoxFuture<(Vec<u8>, Option<(MPath, NodeHash)>), Error> {
get_node(blobstore, nodeid)
.and_then({
let blobstore = blobstore.clone();
move |node| {
let key = format!("sha1-{}", node.blob.sha1());
let parents = node.parents;
blobstore.get(key).and_then(move |blob| {
blob.ok_or(ErrorKind::ContentMissing(nodeid, node.blob).into())
.map(|blob| {
let (_, off) = file::File::extract_meta(blob.as_ref());
Vec::from(&blob.as_ref()[off..])
.and_then(|blob| {
let blob = blob.as_ref();
let (p1, p2) = parents.get_nodes();
let blobnode = BlobNode::new(blob, p1, p2);
let file = file::File::new(blobnode);
file.copied_from().and_then(|from| {
file.content()
.ok_or(ErrorKind::ContentMissing(nodeid, node.blob).into())
.map(|content| (Vec::from(content), from))
})
})
})
}

View File

@ -28,7 +28,7 @@ use memblob::Memblob;
use membookmarks::MemBookmarks;
use memheads::MemHeads;
use memlinknodes::MemLinknodes;
use mercurial_types::{Changeset, Entry, Manifest, NodeHash, RepoPath};
use mercurial_types::{Changeset, Entry, MPath, Manifest, NodeHash, Parents, RepoPath};
use mercurial_types::nodehash::{ChangesetId, ManifestId};
use rocksblob::Rocksblob;
use storage_types::Version;
@ -37,7 +37,8 @@ use tokio_core::reactor::Remote;
use BlobChangeset;
use BlobManifest;
use errors::*;
use file::{fetch_file_content_from_blobstore, BlobEntry};
use file::{fetch_file_content_and_renames_from_blobstore, BlobEntry};
use utils::get_node;
pub struct BlobRepo {
blobstore: Arc<Blobstore>,
@ -125,7 +126,21 @@ impl BlobRepo {
}
pub fn get_file_content(&self, key: &NodeHash) -> BoxFuture<Vec<u8>, Error> {
fetch_file_content_from_blobstore(&self.blobstore, *key)
fetch_file_content_and_renames_from_blobstore(&self.blobstore, *key)
.map(|contentrename| contentrename.0)
.boxify()
}
pub fn get_parents(&self, key: &NodeHash) -> BoxFuture<Parents, Error> {
get_node(&self.blobstore, *key)
.map(|rawnode| rawnode.parents)
.boxify()
}
pub fn get_file_copy(&self, key: &NodeHash) -> BoxFuture<Option<(MPath, NodeHash)>, Error> {
fetch_file_content_and_renames_from_blobstore(&self.blobstore, *key)
.map(|contentrename| contentrename.1)
.boxify()
}
pub fn get_changesets(&self) -> BoxStream<NodeHash, Error> {