mirror of
https://github.com/facebook/sapling.git
synced 2024-12-27 15:13:37 +03:00
revisionstore: add an is_lfs method to Metadata
Summary: Instead of having the magic number 0x2000 all over the place, let's move the logic to this method. Reviewed By: DurhamG Differential Revision: D20637749 fbshipit-source-id: bf666f8787e37e6d6c58ad8982a5679b7e3e717b
This commit is contained in:
parent
7a8653cb2e
commit
6372a4a4fc
@ -77,10 +77,8 @@ impl BackingStore {
|
||||
// Return None for LFS blobs
|
||||
// TODO: LFS support
|
||||
if let Ok(Some(metadata)) = self.blobstore.get_meta(&key) {
|
||||
if let Some(flag) = metadata.flags {
|
||||
if flag == 0x2000 {
|
||||
return Ok(None);
|
||||
}
|
||||
if metadata.is_lfs() {
|
||||
return Ok(None);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,6 +133,16 @@ impl<T: ContentDataStore + ?Sized, U: Deref<Target = T> + Send + Sync> ContentDa
|
||||
}
|
||||
|
||||
impl Metadata {
|
||||
pub const LFS_FLAG: u64 = 0x2000;
|
||||
|
||||
/// Returns true if the blob retrieved from `DataStore::get` is an LFS pointer.
|
||||
pub fn is_lfs(&self) -> bool {
|
||||
match self.flags {
|
||||
None => false,
|
||||
Some(flag) => (flag & Metadata::LFS_FLAG) == Metadata::LFS_FLAG,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write<T: Write>(&self, writer: &mut T) -> Result<()> {
|
||||
let mut buf = vec![];
|
||||
if let Some(flags) = self.flags {
|
||||
|
@ -563,13 +563,11 @@ impl HgIdMutableDeltaStore for LfsMultiplexer {
|
||||
/// Depending on whether the blob represents an LFS pointer, or if it is large enough, it will
|
||||
/// be added either to the lfs store, or to the non-lfs store.
|
||||
fn add(&self, delta: &Delta, metadata: &Metadata) -> Result<()> {
|
||||
if let Some(flag) = metadata.flags {
|
||||
if (flag & 0x2000) == 0x2000 {
|
||||
// This is an lfs pointer blob. Let's parse it and extract what matters.
|
||||
let pointer = LfsPointersEntry::from_bytes(&delta.data, delta.key.hgid.clone())?;
|
||||
if metadata.is_lfs() {
|
||||
// This is an lfs pointer blob. Let's parse it and extract what matters.
|
||||
let pointer = LfsPointersEntry::from_bytes(&delta.data, delta.key.hgid.clone())?;
|
||||
|
||||
return self.lfs.inner.write().pointers.add(pointer);
|
||||
}
|
||||
return self.lfs.inner.write().pointers.add(pointer);
|
||||
}
|
||||
|
||||
if delta.data.len() > self.threshold {
|
||||
@ -1071,7 +1069,7 @@ mod tests {
|
||||
&delta,
|
||||
&Metadata {
|
||||
size: None,
|
||||
flags: Some(0x2000),
|
||||
flags: Some(Metadata::LFS_FLAG),
|
||||
},
|
||||
)?;
|
||||
assert_eq!(
|
||||
@ -1133,7 +1131,7 @@ mod tests {
|
||||
&delta,
|
||||
&Metadata {
|
||||
size: None,
|
||||
flags: Some(0x2000),
|
||||
flags: Some(Metadata::LFS_FLAG),
|
||||
},
|
||||
)?;
|
||||
assert_eq!(
|
||||
@ -1195,7 +1193,7 @@ mod tests {
|
||||
&delta,
|
||||
&Metadata {
|
||||
size: Some(size.try_into()?),
|
||||
flags: Some(0x2000),
|
||||
flags: Some(Metadata::LFS_FLAG),
|
||||
},
|
||||
)?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user