sapling/eden/mononoke/mononoke_api/src/legacy.rs
David Tolnay fe65402e46 rust: Move futures-old rdeps to renamed futures-old
Summary:
In targets that depend on *both* 0.1 and 0.3 futures, this codemod renames the 0.1 dependency to be exposed as futures_old::. This is in preparation for flipping the 0.3 dependencies from futures_preview:: to plain futures::.

rs changes performed by:

```
rg \
    --files-with-matches \
    --type-add buck:TARGETS \
    --type buck \
    --glob '!/experimental' \
    --regexp '(_|\b)rust(_|\b)' \
| sed 's,TARGETS$,:,' \
| xargs \
    -x \
    buck query "labels(srcs,
        rdeps(%Ss, fbsource//third-party/rust:futures-old, 1)
        intersect
        rdeps(%Ss, //common/rust/renamed:futures-preview, 1)
    )" \
| xargs sed -i 's/\bfutures::/futures_old::/'
```

Reviewed By: jsgf

Differential Revision: D20168958

fbshipit-source-id: d2c099f9170c427e542975bc22fd96138a7725b0
2020-03-02 21:02:50 -08:00

79 lines
2.6 KiB
Rust

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
use anyhow::Error;
use blobrepo::BlobRepo;
use blobstore::Loadable;
use cloned::cloned;
use context::CoreContext;
use futures_ext::{FutureExt, StreamExt};
use futures_old::{future, Future, Stream};
use manifest::{Entry, ManifestOps};
use mercurial_types::HgChangesetId;
use mercurial_types::{manifest::Content, FileBytes};
use mononoke_types::MPath;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum ErrorKind {
#[error("{0} not found")]
NotFound(String),
}
// This method is deprecated. It will eventually be replaced by something more like:
// let mononoke = Mononoke::new(...);
// mononoke.repo(repo_name).changeset(changeset_id).file(path).read();
pub fn get_content_by_path(
ctx: CoreContext,
repo: BlobRepo,
changesetid: HgChangesetId,
path: Option<MPath>,
) -> impl Future<Item = Content, Error = Error> {
changesetid
.load(ctx.clone(), repo.blobstore())
.from_err()
.and_then({
cloned!(repo, ctx);
move |changeset| {
changeset
.manifestid()
.find_entry(ctx, repo.get_blobstore(), path.clone())
.and_then(move |entry| {
entry.ok_or_else(|| {
ErrorKind::NotFound(MPath::display_opt(path.as_ref()).to_string())
.into()
})
})
}
})
.and_then(move |entry| match entry {
Entry::Tree(manifest_id) => manifest_id
.load(ctx.clone(), repo.blobstore())
.from_err()
.map(|manifest| Content::Tree(Box::new(manifest)))
.left_future(),
Entry::Leaf((file_type, filenode_id)) => {
let stream = filenode_id
.load(ctx.clone(), repo.blobstore())
.from_err()
.map(move |envelope| {
filestore::fetch_stream(
repo.blobstore(),
ctx.clone(),
envelope.content_id(),
)
})
.flatten_stream()
.map(FileBytes)
.boxify();
let content = Content::new_file(file_type, stream);
future::ok(content).right_future()
}
})
}