treedirstate: move non-Python part to a separate crate

Summary:
This makes it easier to modify and test the core logic without coupling with
the Python logic.

Reviewed By: markbt

Differential Revision: D7734012

fbshipit-source-id: 0d7b19198d85f6ca7314611256e9271be60070d1
This commit is contained in:
Jun Wu 2018-04-24 15:36:19 -07:00 committed by Facebook Github Bot
parent b66618d8c5
commit d15213f6f5
14 changed files with 64 additions and 51 deletions

View File

@ -11,14 +11,7 @@ name = "treedirstate"
crate-type = ["cdylib"]
[dependencies]
byteorder = "*"
error-chain = "*"
vlqencoding = { version = "*", path = "../../../lib/vlqencoding" }
[dev-dependencies]
itertools = "*"
quickcheck = "*"
tempdir = "*"
treestate = { path = "../../../lib/treestate" }
[dependencies.cpython]
version = "0.2"

View File

@ -12,37 +12,10 @@
//! The directory state also stores files that are in the working copy parent manifest but have
//! been marked as removed.
extern crate byteorder;
#[cfg(not(test))]
#[macro_use]
extern crate cpython;
extern crate treestate;
#[macro_use]
extern crate error_chain;
#[cfg(test)]
extern crate itertools;
#[cfg(test)]
#[macro_use]
extern crate quickcheck;
#[cfg(test)]
extern crate tempdir;
extern crate vlqencoding;
pub mod treedirstate;
pub mod errors;
pub mod filestate;
pub mod filestore;
#[cfg(not(test))]
#[allow(non_camel_case_types)]
pub mod python;
pub mod serialization;
pub mod store;
pub mod tree;
pub mod vecmap;
pub use errors::*;

View File

@ -2,15 +2,13 @@
//! Python bindings for treedirstate.
use cpython::*;
use cpython::exc;
use errors;
use errors::ErrorKind;
use filestate::FileState;
use std::cell::RefCell;
use std::path::PathBuf;
use store::BlockId;
use tree::{Key, KeyRef};
use treedirstate::TreeDirstate;
use treestate::errors::{self, ErrorKind};
use treestate::filestate::FileState;
use treestate::store::BlockId;
use treestate::tree::{Key, KeyRef};
use treestate::treedirstate::TreeDirstate;
py_module_initializer!(
treedirstate,

14
lib/treestate/Cargo.toml Normal file
View File

@ -0,0 +1,14 @@
[package]
name = "treestate"
version = "0.1.0"
authors = ["Facebook Source Control Team <sourcecontrol-dev@fb.com>"]
[dependencies]
byteorder = "*"
error-chain = "*"
vlqencoding = { version = "*", path = "../vlqencoding" }
[dev-dependencies]
itertools = "*"
quickcheck = "*"
tempdir = "*"

View File

@ -209,11 +209,11 @@ impl StoreView for FileStore {
#[cfg(test)]
mod tests {
use tempdir::TempDir;
use filestore::FileStore;
use store::{BlockId, Store, StoreView};
use std::fs;
use std::io::Write;
use store::{BlockId, Store, StoreView};
use tempdir::TempDir;
#[test]
fn goodpath() {

35
lib/treestate/src/lib.rs Normal file
View File

@ -0,0 +1,35 @@
// Copyright Facebook, Inc. 2017
//! treestate - Tree-based State.
//!
//! The tree state stores a map from paths to a lightweight structure, and provides efficient
//! lookups. In particular, for each file in the tree, it stores the mode flags, size, mtime, and
//! whether deleted or not, etc. These can be useful for source control to determine if the file
//! is tracked, or has changed, etc.
extern crate byteorder;
#[macro_use]
extern crate error_chain;
#[cfg(test)]
extern crate itertools;
#[cfg(test)]
#[macro_use]
extern crate quickcheck;
#[cfg(test)]
extern crate tempdir;
extern crate vlqencoding;
pub mod errors;
pub mod filestate;
pub mod filestore;
pub mod serialization;
pub mod store;
pub mod tree;
pub mod treedirstate;
pub mod vecmap;
pub use errors::*;

View File

@ -43,10 +43,10 @@ impl StoreView for NullStore {
#[cfg(test)]
pub mod tests {
use std::collections::HashMap;
use errors::*;
use store::{BlockId, Store, StoreView};
use std::borrow::Cow;
use std::collections::HashMap;
use store::{BlockId, Store, StoreView};
/// Define a Store to be used in tests. This doesn't store the data on disk, but rather
/// keeps it in memory in a hash map.

View File

@ -1,11 +1,11 @@
// Copyright Facebook, Inc. 2017
//! Ordered map implementation using a sorted vector
use std::mem;
use std::borrow::Borrow;
use std::slice::{Iter as VecIter, IterMut as VecIterMut};
use std::collections::Bound;
use std::collections::Bound::*;
use std::mem;
use std::slice::{Iter as VecIter, IterMut as VecIterMut};
#[derive(Debug)]
pub struct VecMap<K, V> {
@ -217,10 +217,10 @@ impl<'a, K: 'a, V: 'a> Iterator for IterMut<'a, K, V> {
#[cfg(test)]
mod tests {
use vecmap::{Iter, VecMap};
use itertools;
use std::collections::Bound::*;
use std::collections::BTreeMap;
use std::collections::Bound::*;
use vecmap::{Iter, VecMap};
#[test]
fn insert_get_remove() {