Commit Graph

59 Commits

Author SHA1 Message Date
Simon Farnsworth
ebafde00b0 Remove Repo trait completely
Summary:
We're never going to serve RevlogRepo in production, and we're down to
a single BlobRepo type that will have different backing stores. Remove the
unused trait, and use BlobRepo everywhere bar blobimport and repo_config
(because we previously hardcoded revlog here - we want to change to a BlobRepo
once blobimport is full-fidelity).

Reviewed By: jsgf

Differential Revision: D6596164

fbshipit-source-id: ba6e76e78c495720792cbe77ae6037f7802ec126
2018-01-15 06:37:27 -08:00
Siddharth Agarwal
af8e56d459 wirepack: support for verifying data entries
Summary:
The only verification that needs to be done is for if the delta base
is null.

Also move a rustfmt_skip attribute to the smallest piece of code that it needs to
apply to.

Reviewed By: jsgf

Differential Revision: D6589118

fbshipit-source-id: 287c94871ed30d196c9eaa673cfd7c7f0dd6ed93
2017-12-18 22:08:37 -08:00
Siddharth Agarwal
e46ec63724 mercurial-types: allow converting strs to MPaths and RepoPaths
Summary:
This allows (actually forces) us to drop a bunch of `as_ref` calls. It also
makes upcoming diffs look cleaner.

Reviewed By: jsgf

Differential Revision: D6585202

fbshipit-source-id: a53902696cf12050a851c30b557aeefe09c41903
2017-12-18 22:08:37 -08:00
Siddharth Agarwal
b19c342737 mercurial-types: add a way to generate non-empty paths
Summary:
Add an intrinsic method that acts as an `Arbitrary::arbitrary` implementation
with parameters. The one parameter we have for now is `empty_allowed`, which stands
for whether empty components can be generated.

Reviewed By: jsgf

Differential Revision: D6584040

fbshipit-source-id: 2005e1a77b1bd53294c4386259847a3a113f8f8f
2017-12-18 22:08:37 -08:00
Jeremy Fitzhardinge
ac31713c84 rust: failure cleanup pass
Summary:
Don't use failure's bail!() and ensure!() macros.

Instead, failure_ext provides:
- bail_err!(err) - Converts its single parameter to the expected error and returns; ie `return Err(From::from(err));`
- bail_msg!(fmt, ...) - takes format string parameters and returns a `failure::err_msg()` error
- ensure_err!(), ensure_msg!() - corresponding changes

Also:
- remove all stray references to error-chain
- remove direct references to failure_derive (it's reexported via failure and failure_ext)
- replace uses of `Err(foo)?;` with `bail_err!()` (since `bail_err` unconditionally returns, but `Err(x)?` does not in principle, which can affect type inference)

Reviewed By: kulshrax

Differential Revision: D6507717

fbshipit-source-id: 635fb6f8c96d185b195dff171ea9c8db9e83af10
2017-12-07 14:10:17 -08:00
Arun Kulshreshtha
40339c1f89 Upgrade to Rust 1.22.1
Summary:
This diff upgrades the version of rustc in fbcode to version 1.22.1,
including the requisite third-party2 symlink updates for  the `rust` and
`rust-crates-io` projects, config.py changes in the third-party2 and
third-party-buck directories, and code fixes for Rust targets in common/rust
and scm/mononoke.

Reviewed By: jsgf

Differential Revision: D6489808

fbshipit-source-id: 48377ea937916beb7dae7a3806de1fce1e29dd24
2017-12-05 18:57:32 -08:00
Jeremy Fitzhardinge
dc5e78c1c1 rust: mass convert scm/mononoke/... to use failure
Summary:
Convert scm/mononoke to use failure, and update common/rust crates it depends on as well.

What it looks like is a lot of deleted code...

General strategy:
- common/rust/failure_ext adds some things that are in git failure that aren't yet in crates.io (`bail!` and `ensure!`, `Result<T, Error>`)
- everything returns `Result<T, failure::Error>`
- crates with real error get an error type, with a derived Fail implementation
  - replicate error-chain by defining an `enum ErrorKind` where the fields match the declared errors in the error! macro
- crates with dummy error-chain (no local errors) lose it
- `.chain_err()` -> `.context()` or `.with_context()`

So far the only place I've needed to extract an error is in a unit test.
Having a single unified error type has simplified a lot of things, and removed a lot of error type parameters, error conversion, etc, etc.

Reviewed By: sid0

Differential Revision: D6446584

fbshipit-source-id: 744640ca2997d4a85513c4519017f2e2e78a73f5
2017-12-05 18:11:13 -08:00
Stanislau Hlebik
3130f826c3 mononoke: add simple_fsencode
Summary:
There is a complex logic of path encoding in mercurial. Previously only one
case was implemented, when both 'fncache' and 'store' requirements are present.
This commit adds implementation for the case when 'store' requirement is
present, but 'fncache' is not.

Reviewed By: jsgf

Differential Revision: D6405322

fbshipit-source-id: 3b4a0c5b0fd22f43593ffff54dfe748589294012
2017-12-03 08:37:01 -08:00
Stanislau Hlebik
c98c151de2 mononoke: rename fsencode to fncache_fsencode
Summary:
There are a few different path encodings in mercurial. Next diff will add
another one, so in this let's rename fsencode to fncache_fsencode

Reviewed By: jsgf

Differential Revision: D6405324

fbshipit-source-id: 3e67d972b02ca41f29fe24250fb227dd384ea0da
2017-12-03 08:37:01 -08:00
Simon Farnsworth
5519eae489 Make Bookmarks a parameterless trait
Summary:
As part of removing excess genericism, make Bookmarks a trait with no
associated types or type parameters. I will revisit error types here once I
have removed the Repo trait - these are not ideal, but enough to get things
going

Reviewed By: StanislavGlebik

Differential Revision: D6405315

fbshipit-source-id: 814c106612a061e1766f1ea9a9428a13a73bd007
2017-11-27 08:05:02 -08:00
Simon Farnsworth
36de85eb2e Stop repo returning Bookmarks objects directly
Summary:
Returning the bookmarks object gets in the way of degenericising
bookmarks. It's also not in line with other methods on the Repo trait - the
repo handles querying the underlying storage, not the user.

Switch to providing pass-through interfaces for bookmarks.

Reviewed By: StanislavGlebik

Differential Revision: D6408644

fbshipit-source-id: 2808850a070b7bcc478cd40d824bdc8d3acb8b0f
2017-11-27 04:21:05 -08:00
Siddharth Agarwal
6215ef17b9 mercurial-bundles: add support for wire packs
Summary:
The wire pack format is quite similar to the changegroup format so we can reuse
much of the same code (like deltas).

Reviewed By: jsgf

Differential Revision: D6356906

fbshipit-source-id: 887a5f79c5cf0cf6733a7ef4fcdd2f0592a1c459
2017-11-22 01:07:07 -08:00
Simon Farnsworth
ade48bee19 Make Repo trait Send + Sync
Summary:
We can't serve a repo that isn't Send + Sync; make the trait
implicitly Send + Sync so that we don't get caught by this when trying to use
a Repo implementation from the server code

Reviewed By: jsgf

Differential Revision: D6232591

fbshipit-source-id: 199798043e0718831f63b313255830b7f98ed8ca
2017-11-06 17:21:20 -08:00
Siddharth Agarwal
ed298889af filelinknodes: also write out path and node info
Summary: Needed for the generate_memblob script.

Reviewed By: jsgf

Differential Revision: D6214835

fbshipit-source-id: 130f8946748490c31a38dc7530fec8f4027379f1
2017-11-02 13:10:56 -07:00
Jeremy Fitzhardinge
c3a0dc052f mononoke: impl Repo for Box<Repo + Sync + Send>
Summary:
Rust doesn't do variant typing except for lifetimes, so an impl of
Repo for Box<Repo> doesn't apply to Box<Repo + Sync + Send>. Since in practice
all our Repos are Sync + Send, just implement it for that.

(AFAICT implementing it for both would result in a big chunk of copied code,
and it doesn't seem worth doing that or introducing a macro since we don't seem
to be using the non-Sync+Send version.)

Reviewed By: farnz

Differential Revision: D6208968

fbshipit-source-id: a039a31e360255ca104ac2de833ec3d61e8128d7
2017-11-01 10:36:09 -07:00
Siddharth Agarwal
c8d6e7f954 use RepoPath instead of MPath in a few places
Summary:
`RepoPath` represents any absolute path -- root, directory or file. There's a
lot of code that manually switches between directory and file entries --
abstract all of that away.

Reviewed By: farnz

Differential Revision: D6201383

fbshipit-source-id: 0047023a67a5484ddbdd00bb57bca3bfb7d4dd3f
2017-10-31 14:26:39 -07:00
Siddharth Agarwal
e2405a5ffa mercurial-types: add a new type for MPath with root/file/dir info
Summary:
This is going to be useful for linknodes, where we must differentiate between a
linknode obtained from a directory (tree) and a linknode obtained from a file.

In this case we must disallow empty `MPath` instances because `FilePath("")` in
particular should not be allowed. Also disallow `DirectoryPath("")` for
symmetry.

Reviewed By: StanislavGlebik

Differential Revision: D6097838

fbshipit-source-id: 302aed1cb03b549787e30e3f0db8c089c9ea67fa
2017-10-19 09:39:17 -07:00
Siddharth Agarwal
7a2b4f12ea mercurial-types: add a couple of TryFrom impls for MPath
Summary: This is going to be useful in upcoming patches.

Reviewed By: StanislavGlebik

Differential Revision: D6097837

fbshipit-source-id: 0952aa47354b9e9956f934914e73def35d1af3d1
2017-10-19 09:39:17 -07:00
Siddharth Agarwal
6e8f1e962c mercurial-types: make MPath serializable
Summary: We're going to use this in upcoming patches.

Reviewed By: StanislavGlebik

Differential Revision: D6097839

fbshipit-source-id: 1abdc62d5c81dce7b5fa3b8f0a264932dded02b8
2017-10-19 09:39:17 -07:00
Siddharth Agarwal
ea5ac94e10 mercurial-types: make the InvalidPath error also take the path
Summary: This is useful while trying to figure out what path's having issues.

Reviewed By: StanislavGlebik

Differential Revision: D6059219

fbshipit-source-id: 0205a5519f0ea1c9e24944eed5d61907639d46f2
2017-10-17 00:36:28 -07:00
Siddharth Agarwal
5aa44fcfed add length function to manifest paths
Summary: A future iteration might involve caching the value once it's computed once.

Reviewed By: jsgf

Differential Revision: D6059221

fbshipit-source-id: 33377de9ac00aa1b8b165ca75f21c3e74fcfa87f
2017-10-17 00:36:28 -07:00
Siddharth Agarwal
9f8476c839 mercurial-types: make Arbitrary for MPaths also generate empty paths
Summary: Also include zero-length paths in quickcheck tests.

Reviewed By: jsgf

Differential Revision: D6071605

fbshipit-source-id: 027ffd7bc2b92cc466613f19870ef5a240fbecbb
2017-10-17 00:36:28 -07:00
Siddharth Agarwal
86f4489e7c move bookmarks::Version into a separate crate
Summary:
This Version type is going to form the basis for other key-value
stores like linknodes, so it needs to be moved into a separate crate.

I've chosen `storage_types` as the name because it seems to be the most obvious
candidate.

Reviewed By: jsgf

Differential Revision: D6015772

fbshipit-source-id: 52de7866d68fdec2a4908626679a6f08c5f73402
2017-10-10 07:29:30 -07:00
Stanislau Hlebik
7a9c2df173 mononoke: remove combine_chain optimization
Summary:
In some cases applying delta chain to a big binary file can cause an OOM. The problem was in the `Vec::split_off()` method. It creates two vectors with the same capacity. So if we have 30Mb binary that has 1000 fragments applied to it, it results in 30 Gb memory usage.

The easy fix was to run shrink_to_fit() method after Vec::split_off(). While that would work, it seems that `combine_chain()` optimization doesn't really help - I ran parsing of a huge revlog, and performance was similar. So instead of adding shrink_to_fit() method I suggest to remove `combine_chain()` optimization completely.

Reviewed By: lukaspiatkowski

Differential Revision: D5953806

fbshipit-source-id: 93111a2b6db0b76da235cf7ada727b325600d25c
2017-10-03 11:50:46 -07:00
Siddharth Agarwal
286b04bbd6 add mock hashes
Summary:
These get pretty annoying to construct in tests.
`mercurial-types-mocks` seems like a great place to have them.

I ended up using the `const_fn` feature for convenience.

Reviewed By: StanislavGlebik

Differential Revision: D5898773

fbshipit-source-id: f9ead4e7720ed8ffb0535826603656ff7115b6e4
2017-09-26 04:35:12 -07:00
Siddharth Agarwal
a79b8267ae rename Path to MPath
Summary:
`Path` has the potential to be confused with `std::path::Path`.
`MPath` is nice, concise, and clearly different from `Path`.

Reviewed By: jsgf

Differential Revision: D5895665

fbshipit-source-id: dc5ed5c3866b227d753c6d904d3c6d213c882cd7
2017-09-22 17:27:03 -07:00
Jonathan Gray
b4e04cfb29 remove BoxFuture and BoxStream from mercurial-types-mocks
Summary: Switch to implementations in futures-ext

Reviewed By: sid0

Differential Revision: D5846396

fbshipit-source-id: dc42526a9c9052bcbde9cf9418d303eee973a998
2017-09-18 12:07:49 -07:00
Siddharth Agarwal
de4b1f6c93 use BlobHash in RawNodeBlob
Summary: Also ensure that `blobimport` doesn't use its own copy.

Reviewed By: jsgf

Differential Revision: D5847604

fbshipit-source-id: 5390848cd5fab8abd967ef9701720491d703c0f1
2017-09-18 00:35:52 -07:00
Stanislau Hlebik
1d54db8218 mononoke: add hashencode to fsencode
Summary:
Finally use hashencode to hash long path.
This is basically a translation of core mercurial python code to rust.
Tests are also copied from core mercurial

Reviewed By: jsgf

Differential Revision: D5719573

fbshipit-source-id: a53bdeafe22cc9f492b8c08d4ae302a393f9b8fb
2017-09-17 12:15:08 -07:00
Stanislau Hlebik
6372225acf mononoke: add separate fsencode function instead of fsencode_dir and fsencode_file
Summary:
Let's use separate function fsencode instead of two methods fsencode_dir and fsencode_file.

There are a few reasons for that:
1) This is similar to upsteram mercurial code - it also uses separate function, not a method of the class.
2) Path is supposed to represent a file in the mercurial vfs. Previously we joined this file with "00manifest.i" - it creates a file that doesn't exist in mercurial vfs. This point is debatable though, so I'm fine with making it a method of the class. But probably it doesn't matter that much.
2) We never actually need to encode directory - even in tree manifest case we use fsencode to find location of`00manifest.*` files. That means, that we don't really need to have separate fsencode_dir function, so I was wrong when I added them in the first place.
3) Special hash encoding is used to encode paths that are longer than 120 chars (will be added in the next diff). `00manifest.i` and `00manifest.d` are used in the hash digest, and that means that one fsencode_dir() method is not enough - we'd need to add separate methods to fsencode idx file and separate method to fsencode data file.

Reviewed By: jsgf

Differential Revision: D5719576

fbshipit-source-id: ca6b38dd7d0c6c0c5a345d8fcbe1b0d6fa10a062
2017-09-17 12:15:07 -07:00
Jeremy Fitzhardinge
e18043ac54 mononoke: impl Repo for Arc<R> where R: Repo
Summary:
Allow Arc<R> where R: Repo to be used more generally. Also Box for
completeness.

Reviewed By: farnz

Differential Revision: D5846659

fbshipit-source-id: e101647badfb18a4a59d595ee9b21814b332fe34
2017-09-15 16:06:59 -07:00
Siddharth Agarwal
e1570669d4 remove BoxFuture and BoxStream from mercurial-types
Summary: Switch to the implementations in `futures-ext` added in the previous diff.

Reviewed By: jsgf

Differential Revision: D5799732

fbshipit-source-id: f5d54afe5847bb09f0231d5b3c58c0e2e54c391f
2017-09-13 21:52:37 -07:00
Siddharth Agarwal
e5b075b8ec rustfmt mercurial and mercurial-types
Summary: Going to be making significant changes to these files soon.

Reviewed By: kulshrax

Differential Revision: D5796735

fbshipit-source-id: 879fbca3fc936a538c95e50a3333fc2c312de15b
2017-09-12 11:50:20 -07:00
Lukas Piatkowski
58a94a73fa metaconfig: add simple parsing of content of a repo config using Serde and Toml
Summary: This parsing is only to check that the modules work together. The metaconfig module still needs to have some proper parsing implemented, Error handling and tests

Reviewed By: jsgf

Differential Revision: D5698544

fbshipit-source-id: 8cd3254c10f977a17ddc31ac2199ee4c9fa98355
2017-09-12 04:05:14 -07:00
Lukas Piatkowski
0a86d53090 vfs: add Virtual File System for manifest
Reviewed By: jsgf

Differential Revision: D5755499

fbshipit-source-id: 5942c73698df54be28d2d601d062c238bb789f90
2017-09-12 04:05:14 -07:00
Siddharth Agarwal
a74542da60 update and pull in uuid + subprocess
Summary:
Finally got an update working by removing the `mysql_async` crate.

Some notes:

* The `mysql_async` crate was responsible in this case: see https://github.com/rust-lang/cargo/issues/4066#issuecomment-328210204 for why.
* tokio/futures deprecated a bunch of stuff. I've filed a TODO for now.
* We finally pulled in error-chain 0.11, which has a bunch of nice improvements.

Reviewed By: kulshrax

Differential Revision: D5798282

fbshipit-source-id: a38a7b17ee0205428e2ea63334722aa408582493
2017-09-08 17:05:38 -07:00
Lukas Piatkowski
2a035f6fc7 mercurial-types: add mocks for types in manifest.rs
Reviewed By: jsgf

Differential Revision: D5775718

fbshipit-source-id: 243eae8f82505d1c4b374ca13029065646605e36
2017-09-08 10:36:40 -07:00
Lukas Piatkowski
7aa6bdad43 mercurial-types: impl IntoIterator for Path and improve Debug for PathElement
Reviewed By: jsgf

Differential Revision: D5775500

fbshipit-source-id: 80d0b5b765e6034eb90970b46c5c0a85b2e0a44a
2017-09-08 10:36:40 -07:00
Lukas Piatkowski
8ee6a5df7e mercurial_types: add a convienient From impl from PathElement to Path
Reviewed By: jsgf

Differential Revision: D5698545

fbshipit-source-id: 497963dcad0e9240f6938a81e37c8c7a3589c866
2017-09-01 04:28:26 -07:00
Siddharth Agarwal
c1a30e25c9 make repo error types require std::error::Error
Summary: This gets us `Display` support as well.

Reviewed By: lukaspiatkowski

Differential Revision: D5734383

fbshipit-source-id: 1485cf80bb310cdd282b4546bed56c60082be8ec
2017-08-31 13:51:24 -07:00
Siddharth Agarwal
8202a344b4 rustfmt mercurial-types and blobimport
Summary: Just a few minor changes that make our lives easier overall.

Reviewed By: lukaspiatkowski

Differential Revision: D5737854

fbshipit-source-id: da951d7872433bffa8fc64d15cd0e917f77144b5
2017-08-31 13:51:24 -07:00
Stanislau Hlebik
feaa4ef541 path: fix auxencode
Summary: auxencode panicked on path with like ' ' or '.'.

Reviewed By: jsgf

Differential Revision: D5706325

fbshipit-source-id: d2ecca2bc983e8adc581cac4e39c314002c171b6
2017-08-28 05:37:31 -07:00
Lukas Piatkowski
b640e00f02 metaconfig_types: add as_bytes to PathElement
Summary:
PathElement is a blackbox now and it is hard to read inside it.
as_bytes() should at least enable reading the content of it and allow an attempt to create a string out of it. Alternative would be to create a Path using Path::join(&[PathElement]), but that is a bit too much.

Reviewed By: jsgf

Differential Revision: D5688868

fbshipit-source-id: f30879251e3da7e6b90c70bfbadb901a3d818dd7
2017-08-24 02:49:37 -07:00
Lukas Piatkowski
936be76e75 mercurial_types: Added Sync to Box<Entry + Sync>
Summary: Would be nice to be able to return future that references a boxed Entry

Reviewed By: jsgf

Differential Revision: D5688859

fbshipit-source-id: acb7bcc461f886bca08b84f31dbebe4f692187f1
2017-08-24 02:49:37 -07:00
Stanislau Hlebik
679729b5e5 mononoke: fix com/lpt encoding auxencoding
Summary: I checked mercurial pathencode, and 'com3x', 'xcom3', 'auxx' etc shouldn't be encoded.

Reviewed By: jsgf

Differential Revision: D5679798

fbshipit-source-id: f2de60a81cbba95d06d1afea6dee72295fb9ac00
2017-08-23 05:13:50 -07:00
Stanislau Hlebik
48776b34a3 mononoke: move data/ and meta/ prefixes to fsencode_* functions
Summary:
Core mercurial takes "data/" and "meta/" prefixes into account when does
fsencode.
It doesn't make a difference now, but it will make a difference when we'll add
hashencode to the fsencode() function.

Reviewed By: jsgf

Differential Revision: D5670748

fbshipit-source-id: 661974c25e00979eedffb30b432518135f0dc631
2017-08-23 05:13:50 -07:00
Stanislau Hlebik
b72949e3d1 mononoke: blob importing of tree manifest repo
Summary: Main part is `get_stream_of_manifest_entries` that creates a stream of all tree manifest entries by recursively going through all of them.

Reviewed By: jsgf

Differential Revision: D5622490

fbshipit-source-id: 4a8b2707df0300a37931c465bafb1ed54d6d4d25
2017-08-18 09:51:17 -07:00
Stanislau Hlebik
5849f4687d mononoke: better fsencode in mercurial_types::Path
Summary:
Previously `fsencode()` worked incorrectly if Path was a directory. We didn't notice it before because we've never used Path to store directories, but we will use it for TreeManifest.

I considered two options when implementing it.
1) Put some kind of flag `isDir` inside Path struct. But that would create complications with `join()`  method. For example, you can't join anything to the file - what should we do in this case? panic? return result?
2) and another `fsencode_dir()` method. Clients need to know what kind of Path they have. I choose this option because it requires less changes and brings less complications compared to the option 1

Reviewed By: sid0

Differential Revision: D5574847

fbshipit-source-id: c4c476a7fc3b884de847c431a56ff5f313c1389f
2017-08-18 04:40:23 -07:00
Stanislau Hlebik
ee917edf1b mononoke: add path join method
Summary:
Adds method similar to https://doc.rust-lang.org/std/path/struct.Path.html#method.join.
Will be used in the next diff to prepend path prefix to the tree manifest entries

Reviewed By: jsgf

Differential Revision: D5563808

fbshipit-source-id: 3637275093c301bf159083cb9bfedaa0e490a75e
2017-08-18 04:40:23 -07:00
Stanislau Hlebik
91d587e052 mononoke: change Path implementation
Summary:
Instead of storing `Vec<u8>`, let's store `Vec<PathComponent>`, where PathComponent is Vec<u8> without b'\'.
To make sure len() is still `O(1)` let's store it too.

Reviewed By: sid0

Differential Revision: D5573721

fbshipit-source-id: 91967809284d79bf0fcdcabcae9fd787a37c318b
2017-08-10 05:24:42 -07:00