mirror of
https://github.com/facebook/sapling.git
synced 2024-12-26 14:34:34 +03:00
convert to bytes 0.5
Summary: The bytes 0.5 is a depencency of newer tokio, it's also newer, and thus better. Staying on 0.4 means that copies between Bytes 0.4 and 0.5 need to be done, this will be especially bad in the LFS code since 10+MB buffer will have to be copied... One main API change is for the configparser. The code used to take Into<Bytes> for the keys, I switched it to AsRef<[u8]>. For hg_memcache_client, an extra copy is performed to build a Delta, since this code uses an old tokio, and is being replaced right now, the effort of switching to a new tokio and new bytes was not deemed worth it, the copy will do for now. Reviewed By: dtolnay Differential Revision: D20043137 fbshipit-source-id: 395bfc3749a3b1bdfea652262019ac6a086e61e0
This commit is contained in:
parent
91abb7b7c7
commit
934b64397b
@ -17,6 +17,7 @@ use blobrepo::{file_history::get_file_history, BlobRepo};
|
||||
use blobrepo_factory::{open_blobrepo, BlobstoreOptions, Caching, ReadOnlyStorage};
|
||||
use blobstore::Loadable;
|
||||
use bookmarks::BookmarkName;
|
||||
use bytes_ext::copy_from_old;
|
||||
use cloned::cloned;
|
||||
use context::CoreContext;
|
||||
use derived_data::BonsaiDerived;
|
||||
@ -949,7 +950,8 @@ impl MononokeRepo {
|
||||
debug!(&logger, "fetching data for key: {}", &key);
|
||||
|
||||
get_parents.and_then(move |parents| {
|
||||
get_content.map(move |bytes| DataEntry::new(key, bytes, parents.into()))
|
||||
get_content
|
||||
.map(move |bytes| DataEntry::new(key, copy_from_old(bytes), parents.into()))
|
||||
})
|
||||
});
|
||||
|
||||
@ -1033,7 +1035,7 @@ impl MononokeRepo {
|
||||
|
||||
get_parents.and_then(move |parents| {
|
||||
get_content.map(move |content| {
|
||||
DataEntry::new(key, content.into_inner(), parents.into())
|
||||
DataEntry::new(key, copy_from_old(content.into_inner()), parents.into())
|
||||
})
|
||||
})
|
||||
});
|
||||
@ -1075,7 +1077,7 @@ impl MononokeRepo {
|
||||
let content = envelope.contents().clone();
|
||||
let (p1, p2) = envelope.parents();
|
||||
let parents = HgParents::new(p1, p2);
|
||||
DataEntry::new(key, content, parents.into())
|
||||
DataEntry::new(key, copy_from_old(content), parents.into())
|
||||
})
|
||||
.boxify()
|
||||
},
|
||||
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
bytes = "0.4.11"
|
||||
bytes = "0.5"
|
||||
configparser = { path = "../../../../lib/configparser" }
|
||||
cpython = { version = "0.4", default-features = false }
|
||||
cpython-ext = { path = "../../../../lib/cpython-ext", default-features = false }
|
||||
|
@ -89,7 +89,7 @@ py_class!(pub class config |py| {
|
||||
let file = source.location().map(|(path, range)| {
|
||||
// Calculate the line number - count "\n" till range.start
|
||||
let file = source.file_content().unwrap();
|
||||
let line = 1 + file.slice(0, range.start).iter().filter(|ch| **ch == b'\n').count();
|
||||
let line = 1 + file.slice(0..range.start).iter().filter(|ch| **ch == b'\n').count();
|
||||
|
||||
let pypath = if path.as_os_str().is_empty() {
|
||||
PyPathBuf::from(String::from("<builtin>"))
|
||||
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
bytes = "0.4"
|
||||
bytes = "0.5"
|
||||
cpython-ext = { path = "../../../../lib/cpython-ext", default-features = false }
|
||||
cpython = { version = "0.4", default-features = false }
|
||||
edenapi = { path = "../../../../lib/edenapi" }
|
||||
|
@ -5,7 +5,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.20"
|
||||
bytes = { version = "0.4.11" }
|
||||
bytes = { version = "0.5" }
|
||||
cpython-ext = { path = "../../../../lib/cpython-ext", default-features = false }
|
||||
cpython = { version = "0.4", default-features = false }
|
||||
manifest = { path = "../../../../lib/manifest" }
|
||||
|
@ -5,7 +5,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.20"
|
||||
bytes = "0.4.12"
|
||||
bytes = "0.5"
|
||||
configparser = { path = "../configparser" }
|
||||
indexmap = "1.0.1"
|
||||
url = "2.1.0"
|
||||
|
@ -13,7 +13,7 @@ manifest-tree = { path = "../manifest-tree" }
|
||||
revisionstore = { path = "../revisionstore" }
|
||||
types = { path = "../types" }
|
||||
anyhow = "1.0.20"
|
||||
bytes = "0.4.12"
|
||||
bytes = "0.5"
|
||||
libc = "0.2.62"
|
||||
env_logger = "0.7"
|
||||
|
||||
|
@ -6,7 +6,6 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.20"
|
||||
bytes = "0.4.10"
|
||||
blackbox = { path = "../blackbox" }
|
||||
configparser = { path = "../configparser" }
|
||||
cliparser = { path = "../cliparser" }
|
||||
|
@ -11,7 +11,6 @@ use crate::global_flags::HgGlobalOpts;
|
||||
use crate::io::IO;
|
||||
use crate::repo::OptionalRepo;
|
||||
use anyhow::Error;
|
||||
use bytes::Bytes;
|
||||
use cliparser::alias::{expand_aliases, find_command_name};
|
||||
use cliparser::parser::{ParseError, ParseOptions, ParseOutput, StructFlags};
|
||||
use configparser::config::ConfigSet;
|
||||
@ -59,7 +58,7 @@ where
|
||||
let section = §ion_name_pair[..dot_pos];
|
||||
let name = §ion_name_pair[dot_pos + 1..];
|
||||
|
||||
config.set(section, name, Some(Bytes::from(value)), &"--config".into());
|
||||
config.set(section, name, Some(value), &"--config".into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -5,7 +5,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.19"
|
||||
bytes = "0.4.10"
|
||||
bytes = "0.5"
|
||||
dirs = "1.0.4"
|
||||
indexmap = "1.0.1"
|
||||
parking_lot = "0.9"
|
||||
|
@ -122,20 +122,20 @@ impl ConfigSet {
|
||||
}
|
||||
|
||||
/// Get config names in the given section. Sorted by insertion order.
|
||||
pub fn keys<S: Into<Bytes>>(&self, section: S) -> Vec<Bytes> {
|
||||
pub fn keys(&self, section: impl AsRef<[u8]>) -> Vec<Bytes> {
|
||||
self.sections
|
||||
.get(§ion.into())
|
||||
.get(section.as_ref())
|
||||
.map(|section| section.items.keys().cloned().collect())
|
||||
.unwrap_or(Vec::new())
|
||||
}
|
||||
|
||||
/// Get config value for a given config.
|
||||
/// Return `None` if the config item does not exist or is unset.
|
||||
pub fn get<S: Into<Bytes>, N: Into<Bytes>>(&self, section: S, name: N) -> Option<Bytes> {
|
||||
self.sections.get(§ion.into()).and_then(|section| {
|
||||
pub fn get(&self, section: impl AsRef<[u8]>, name: impl AsRef<[u8]>) -> Option<Bytes> {
|
||||
self.sections.get(section.as_ref()).and_then(|section| {
|
||||
section
|
||||
.items
|
||||
.get(&name.into())
|
||||
.get(name.as_ref())
|
||||
.and_then(|values| values.last().and_then(|value| value.value.clone()))
|
||||
})
|
||||
}
|
||||
@ -144,29 +144,34 @@ impl ConfigSet {
|
||||
/// The last item in the returned vector is the latest value that is considered effective.
|
||||
///
|
||||
/// Return an emtpy vector if the config does not exist.
|
||||
pub fn get_sources<S: Into<Bytes>, N: Into<Bytes>>(
|
||||
pub fn get_sources(
|
||||
&self,
|
||||
section: S,
|
||||
name: N,
|
||||
section: impl AsRef<[u8]>,
|
||||
name: impl AsRef<[u8]>,
|
||||
) -> Vec<ValueSource> {
|
||||
self.sections
|
||||
.get(§ion.into())
|
||||
.and_then(|section| section.items.get(&name.into()).map(|values| values.clone()))
|
||||
.get(section.as_ref())
|
||||
.and_then(|section| {
|
||||
section
|
||||
.items
|
||||
.get(name.as_ref())
|
||||
.map(|values| values.clone())
|
||||
})
|
||||
.unwrap_or(Vec::new())
|
||||
}
|
||||
|
||||
/// Set a config item directly. `section`, `name` locates the config. `value` is the new value.
|
||||
/// `source` is some annotation about who set it, ex. "reporc", "userrc", "--config", etc.
|
||||
pub fn set<T: Into<Bytes>, N: Into<Bytes>, V: Into<Bytes>>(
|
||||
pub fn set(
|
||||
&mut self,
|
||||
section: T,
|
||||
name: N,
|
||||
value: Option<V>,
|
||||
section: impl AsRef<[u8]>,
|
||||
name: impl AsRef<[u8]>,
|
||||
value: Option<impl AsRef<[u8]>>,
|
||||
opts: &Options,
|
||||
) {
|
||||
let section = section.into();
|
||||
let name = name.into();
|
||||
let value = value.map(|v| v.into());
|
||||
let section = Bytes::copy_from_slice(section.as_ref());
|
||||
let name = Bytes::copy_from_slice(name.as_ref());
|
||||
let value = value.map(|v| Bytes::copy_from_slice(v.as_ref()));
|
||||
self.set_internal(section, name, value, None, &opts)
|
||||
}
|
||||
|
||||
@ -284,7 +289,7 @@ impl ConfigSet {
|
||||
};
|
||||
|
||||
let (start, end) = strip_offsets(&value, 0, value.len());
|
||||
let value = value.slice(start, end);
|
||||
let value = value.slice(start..end);
|
||||
|
||||
this.set_internal(section, name, value.into(), location.into(), opts)
|
||||
};
|
||||
@ -504,7 +509,7 @@ fn strip_offsets(buf: &Bytes, start: usize, end: usize) -> (usize, usize) {
|
||||
#[inline]
|
||||
fn extract<'a>(buf: &Bytes, span: Span<'a>) -> Bytes {
|
||||
let (start, end) = strip_offsets(buf, span.start(), span.end());
|
||||
buf.slice(start, end)
|
||||
buf.slice(start..end)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -272,7 +272,7 @@ impl ConfigSetHgExt for ConfigSet {
|
||||
self.set(
|
||||
"ui",
|
||||
"editor",
|
||||
Some(editor.as_bytes()),
|
||||
Some(editor),
|
||||
&Options::new().source(format!("${}", name)),
|
||||
);
|
||||
break;
|
||||
@ -281,12 +281,7 @@ impl ConfigSetHgExt for ConfigSet {
|
||||
|
||||
// Convert $HGPROF to profiling.type
|
||||
if let Ok(profiling_type) = env::var("HGPROF") {
|
||||
self.set(
|
||||
"profiling",
|
||||
"type",
|
||||
Some(profiling_type.as_bytes()),
|
||||
&"$HGPROF".into(),
|
||||
);
|
||||
self.set("profiling", "type", Some(profiling_type), &"$HGPROF".into());
|
||||
}
|
||||
|
||||
let opts = Options::new().source("user").process_hgplain();
|
||||
@ -902,7 +897,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_parse_list() {
|
||||
fn b<B: AsRef<[u8]>>(bytes: B) -> Bytes {
|
||||
Bytes::from(bytes.as_ref())
|
||||
Bytes::copy_from_slice(bytes.as_ref())
|
||||
}
|
||||
|
||||
// From test-ui-config.py
|
||||
|
@ -7,7 +7,7 @@ edition = "2018"
|
||||
anyhow = "1.0.20"
|
||||
auth = { path = "../auth" }
|
||||
blackbox = { path = "../blackbox" }
|
||||
bytes = "0.4.11"
|
||||
bytes = "0.5"
|
||||
configparser = { path = "../configparser" }
|
||||
curl = { version = "0.4.20", features = ["http2"] }
|
||||
http = "0.1.17"
|
||||
|
@ -10,7 +10,7 @@ for-tests = ["quickcheck", "rand", "parking_lot"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.20"
|
||||
bytes = { version = "0.4.11", features = ["serde"] }
|
||||
bytes = { version = "0.5", features = ["serde"] }
|
||||
manifest = { path = "../manifest" }
|
||||
once_cell = "1.0.2"
|
||||
pathmatcher = { path = "../pathmatcher" }
|
||||
|
@ -1013,7 +1013,9 @@ mod tests {
|
||||
|
||||
use bytes::Bytes;
|
||||
for (path, hgid, raw, _, _) in tree_changed.iter() {
|
||||
store.insert(&path, *hgid, Bytes::from(&raw[..])).unwrap();
|
||||
store
|
||||
.insert(&path, *hgid, Bytes::copy_from_slice(&raw[..]))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let mut update = tree.clone();
|
||||
|
@ -10,7 +10,7 @@ for-tests = []
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.20"
|
||||
bytes = { version = "0.4.11", features = ["serde"] }
|
||||
bytes = { version = "0.5", features = ["serde"] }
|
||||
byteorder = "1.2.7"
|
||||
configparser = { path = "../configparser" }
|
||||
edenapi = { path = "../edenapi" }
|
||||
|
@ -247,7 +247,7 @@ impl<'a> fmt::Debug for DataEntry<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let delta = self
|
||||
.delta()
|
||||
.unwrap_or_else(|e| Bytes::from(format!("{:?}", e).as_bytes()));
|
||||
.unwrap_or_else(|e| Bytes::copy_from_slice(format!("{:?}", e).as_bytes()));
|
||||
write!(
|
||||
f,
|
||||
"DataEntry {{\n offset: {:?}\n filename: {:?}\n \
|
||||
|
@ -91,7 +91,7 @@ impl Entry {
|
||||
Ok(Entry {
|
||||
key,
|
||||
content: None,
|
||||
compressed_content: Some(compressed.into()),
|
||||
compressed_content: Some(Bytes::copy_from_slice(compressed)),
|
||||
metadata,
|
||||
})
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ fn strip_metadata(data: &Bytes) -> Result<(Bytes, Option<Key>)> {
|
||||
(Some(path), Some(hgid)) => Some(Key::new(path, hgid)),
|
||||
};
|
||||
|
||||
Ok((data.slice(2 + pos + 2, data.len()), key))
|
||||
Ok((data.slice(2 + pos + 2..), key))
|
||||
} else {
|
||||
Ok((data.clone(), None))
|
||||
}
|
||||
@ -495,7 +495,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_strip_metadata() -> Result<()> {
|
||||
let key = key("foo/bar/baz", "1234");
|
||||
let data = Bytes::from(
|
||||
let data = Bytes::copy_from_slice(
|
||||
format!(
|
||||
"\x01\ncopy: {}\ncopyrev: {}\n\x01\nthis is a blob",
|
||||
key.path, key.hgid
|
||||
@ -544,7 +544,7 @@ mod tests {
|
||||
|
||||
let k1 = key("a", "2");
|
||||
let delta = Delta {
|
||||
data: Bytes::from(
|
||||
data: Bytes::copy_from_slice(
|
||||
format!(
|
||||
"\x01\ncopy: {}\ncopyrev: {}\n\x01\nthis is a blob",
|
||||
k1.path, k1.hgid
|
||||
|
@ -22,7 +22,7 @@ use crate::{
|
||||
|
||||
pub fn delta(data: &str, base: Option<Key>, key: Key) -> Delta {
|
||||
Delta {
|
||||
data: Bytes::from(data),
|
||||
data: Bytes::copy_from_slice(data.as_bytes()),
|
||||
base,
|
||||
key,
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ for-tests = ["rand", "quickcheck", "lazy_static"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.20"
|
||||
bytes = { version = "0.4.11", features = ["serde"] }
|
||||
bytes = { version = "0.5", features = ["serde"] }
|
||||
lazy_static = { version = "1.4.0", optional = true }
|
||||
log = "0.4.6"
|
||||
quickcheck = { version = "0.9", optional = true }
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use bytes::Bytes;
|
||||
use quickcheck::{Arbitrary, Gen};
|
||||
use rand::Rng;
|
||||
|
||||
@ -69,7 +70,7 @@ pub fn null_key(path: &str) -> Key {
|
||||
}
|
||||
|
||||
pub fn data_entry(key: Key, data: impl AsRef<[u8]>) -> DataEntry {
|
||||
DataEntry::new(key, data.as_ref().into(), Parents::None)
|
||||
DataEntry::new(key, Bytes::copy_from_slice(data.as_ref()), Parents::None)
|
||||
}
|
||||
|
||||
pub fn generate_repo_paths<G: Gen>(count: usize, qc_gen: &mut G) -> Vec<RepoPathBuf> {
|
||||
|
Loading…
Reference in New Issue
Block a user