Commit Graph

54 Commits

Author SHA1 Message Date
Kostia Balytskyi
2ea25308ab commit_rewriting: use is_empty() where possible
Summary: `clippy` often complains about the use of `.len() != 0`, `.len() > 0` or `.len() == 0`and proposes to use `.is_empty()` instead. This diff does that across Mononoke.

Reviewed By: aslpavel

Differential Revision: D24099427

fbshipit-source-id: 1bba2f958485b7efb3f41bf3eae820879c92b0e5
2020-10-04 10:03:42 -07:00
Jan Mazur
88bf94aacb move interngraph token from disk to keychain service
Summary:
Interngraph token is already stored within keychain service. We should make use of that.

I'll need to remove related config option in convigerator in a separate diff.

Reviewed By: krallin

Differential Revision: D24015463

fbshipit-source-id: 9e8246e2cc252f0c42669140de7b50410a15709c
2020-10-02 06:56:49 -07:00
Johan Schuijt-Li
deb57a25ed mononoke: deprecate preamble in favor of metadata
Summary:
In preparation of moving away from SSH as an intermediate entry point for
Mononoke, let Mononoke work with newly introduced Metadata. This removes any
assumptions we now make about how certain data is presented to us, making the
current "ssh preamble" no longer central.

Metadata is primarily based around identities and provides some
backwards-compatible entry points to make sure we can satisfy downstream
consumers of commits like hooks and logs.

Simarly we now do our own reverse DNS resolving instead of relying on what's
been provided by the client. This is done in an async matter and we don't rely
on the result, so Mononoke can keep functioning in case DNS is offline.

Reviewed By: farnz

Differential Revision: D23596262

fbshipit-source-id: 3a4e97a429b13bae76ae1cdf428de0246e684a27
2020-09-15 10:28:38 -07:00
David Tolnay
0cb8a052f5 Update formatter to rustfmt 2.0
Reviewed By: zertosh

Differential Revision: D23591021

fbshipit-source-id: e664aa2fdd3aaa457796a59080be6b94f604a112
2020-09-09 07:52:33 -07:00
David Tolnay
be0786f14b Prepare for rustfmt 2.0
Summary:
Generated by formatting with rustfmt 2.0.0-rc.2 and then a second time with fbsource's current rustfmt (1.4.14).

This results in formatting for which rustfmt 1.4 is idempotent but is closer to the style of rustfmt 2.0, reducing the amount of code that will need to change atomically in that upgrade.

 ---

*Why now?* **:** The 1.x branch is no longer being developed and fixes like https://github.com/rust-lang/rustfmt/issues/4159 (which we need in fbcode) only land to the 2.0 branch.

 ---

Reviewed By: StanislavGlebik

Differential Revision: D23568780

fbshipit-source-id: b4b4a0aa683d236e2fdeb5b96d723ac2d84b9faf
2020-09-08 07:33:16 -07:00
Lukas Piatkowski
12c684afcd mononoke/hooks: make deny_files public
Reviewed By: aslpavel

Differential Revision: D23537799

fbshipit-source-id: 58c9568e30982f682b00faae42bc3a3f3595890f
2020-09-04 12:23:35 -07:00
Lukas Piatkowski
67a71d1f98 mononoke/hooks: make limit_commitsize and limit_filesize public
Reviewed By: aslpavel

Differential Revision: D23502908

fbshipit-source-id: 8b9070cfaa28af7b808d02548c0fb7c5d344550d
2020-09-04 04:23:05 -07:00
Lukas Piatkowski
462cb96cc2 mononoke/hooks: make no_questionable_filenames public
Reviewed By: aslpavel

Differential Revision: D23478259

fbshipit-source-id: 642948c2685690298a71fbe7177c4bd6a6e43f85
2020-09-04 04:23:05 -07:00
Lukas Piatkowski
a4af730541 monononke/hooks: make no_bad_filenames public
Reviewed By: aslpavel

Differential Revision: D23474524

fbshipit-source-id: 5f7826346500b1acc7450791dd1e7806c4e623d6
2020-09-03 02:40:43 -07:00
Lukas Piatkowski
81d9338100 mononoke/hooks: make few generic hooks public
Summary: More hooks will come in next diffs.

Reviewed By: aslpavel

Differential Revision: D23449755

fbshipit-source-id: 451fdb7a759140f2d6df8f3a18493c700fa2b761
2020-09-03 02:40:43 -07:00
Mark Thomas
f15976637e bookmarks_movement: restrict bookmarks that are marked allow_only_external_sync
Reviewed By: StanislavGlebik

Differential Revision: D23294907

fbshipit-source-id: ed89e5fd841e7d516b5d259c1f5de4e9f8f40ee3
2020-08-25 09:14:09 -07:00
Mark Thomas
a2bbb7e259 metaconfig_parser: parse hooks_skip_ancestors_of
Differential Revision: D23222560

fbshipit-source-id: 928f35be98682298f2891fefe82c3ed4f6e63097
2020-08-25 09:14:08 -07:00
Mark Thomas
889e84f8d5 bookmarks_movement: move hook running into bookmarks_movement
Summary:
Move the running of hooks from in `repo_client` to in `bookmarks_movement`.

For pushrebase and plain push we still only run hooks on the new commits the client has sent.
Bookmark-only pushrebases, or moves where some commits were already known, do not run
the hooks on the omitted changesets.  That will be addressed next.

The push-redirector currently runs hooks in the large repo.  Since hook running has now been moved
to later on, they will automatically be run on the large repo, and instead the push-redirector runs them on
the small repo, to ensure they are run on both.

There's some additional complication with translating hook rejections in the push-redirector.  Since a
bookmark-only push can result in hook rejections for commits that are not translated, we fall back to
using the large-repo commit hash in those scenarios.

Reviewed By: StanislavGlebik

Differential Revision: D23077551

fbshipit-source-id: 07f66a96eaca4df08fc534e335e6d9f6b028730d
2020-08-25 09:14:07 -07:00
Mark Thomas
053abf7919 hook_manager_factory: extract construction of the hook manager
Summary:
Extract construction of the hook manager to its own crate, so that we can re-use it.

Eventually the hook manager will become a repo attribute and will be constructed by
the repo attribute factory, but for now it needs its own factory method.

Differential Revision: D23129407

fbshipit-source-id: 302fde4d1ae38c6f61032a32c880018ebf84dee2
2020-08-17 09:09:07 -07:00
Mark Thomas
563137e6f7 hooks: create HookRejection struct
Summary:
Convert hook rejections from a tuple to a named struct.  This will be used in
the bookmarks_movement public interface.

Reviewed By: krallin

Differential Revision: D23077550

fbshipit-source-id: a35476817660c38b8df879ba603b927a7e39be21
2020-08-17 09:09:07 -07:00
Mark Thomas
3afceb0e2c bookmarks: extract BundleReplayData from BookmarkUpdateReason
Summary:
Separate out the `BundleReplayData` from the `BookmarkUpdateReason` enum.  There's
no real need for this to be part of the reason, and removing it means we can
abstract away the remaining dependency on Mercurial changeset IDs from
the main bookmarks traits.

Reviewed By: mitrandir77, ikostia

Differential Revision: D22417659

fbshipit-source-id: c8e5af7ba57d10a90c86437b59c0d48e587e730e
2020-07-10 04:50:24 -07:00
Arun Kulshreshtha
5f0181f48c Regenerate all Cargo.tomls after upgrade to futures 0.3.5
Summary: D22381744 updated the version of `futures` in third-party/rust to 0.3.5, but did not regenerate the autocargo-managed Cargo.toml files in the repo. Although this is a semver-compatible change (and therefore should not break anything), it means that affected projects would see changes to all of their Cargo.toml files the next time they ran `cargo autocargo`.

Reviewed By: dtolnay

Differential Revision: D22403809

fbshipit-source-id: eb1fdbaf69c99549309da0f67c9bebcb69c1131b
2020-07-06 20:49:43 -07:00
Mark Thomas
160936b732 bookmarks: convert to new-style BoxFutures and BoxStreams
Summary: Convert the bookmarks traits to use new-style `BoxFuture<'static>` and `BoxStream<'static>`.  This is a step along the path to full `async`/`await`.

Reviewed By: farnz

Differential Revision: D22244489

fbshipit-source-id: b1bcb65a6d9e63bc963d9faf106db61cd507e452
2020-06-30 02:37:34 -07:00
Simon Farnsworth
454de31134 Switch Loadable and Storable interfaces to new-style futures
Summary:
Eventually, we want everything to be `async`/`await`; as a stepping stone in that direction, switch some of the blobstore interfaces to new-style `BoxFuture` with a `'static` lifetime.

This does not enable any fixes at this point, but does mean that `.compat()` moves to the places that need old-style futures instead of new. It also means that the work needed to make the transition fully complete is changed from a full conversion to new futures, to simply changing the lifetimes involved and fixing the resulting compile failures.

Reviewed By: krallin

Differential Revision: D22164315

fbshipit-source-id: dc655c36db4711d84d42d1e81b76e5dddd16f59d
2020-06-25 08:45:37 -07:00
Jeremy Fitzhardinge
1b4edb5567 eden: remove unused Rust dependencies
Summary:
Remove unused dependencies for Rust targets.

This failed to remove the dependencies in eden/scm/edenscmnative/bindings
because of the extra macro layer.

Manual edits (named_deps) and misc output in P133451794

Reviewed By: dtolnay

Differential Revision: D22083498

fbshipit-source-id: 170bbaf3c6d767e52e86152d0f34bf6daa198283
2020-06-17 17:55:03 -07:00
Egor Tkachenko
d72c2b0b60 mononoke: opsfiles: Port deny_from_corp.sh hook
Summary: Ported deny_from_corp hook into mononoke.

Reviewed By: krallin

Differential Revision: D21329467

fbshipit-source-id: f5fa7a745b09a83b2624dd074155901f0bd31a55
2020-06-10 19:29:47 -07:00
Mark Thomas
0780f00ef9 metaconfig/parser: wrap regexes in a newtype for comparisons
Summary:
Regexes stored in config need to be comparable so that config is comparable.

Normally regexes are not comparable, so wrap them in a newtype wrapper that
implements comparison, rather than manually implemented PartialEq and Eq for
anything that contains them.

Reviewed By: mitrandir77

Differential Revision: D21886533

fbshipit-source-id: 1fb39c0874daed383624eeda61c903a4731b9cb8
2020-06-10 19:29:31 -07:00
Stefan Filip
60966c93e7 autocargo: regenerate
Summary: maintenance

Reviewed By: StanislavGlebik

Differential Revision: D21640322

fbshipit-source-id: d0b2ce604735c05d540d06835c8e4c8a940fbf5c
2020-05-19 16:08:40 -07:00
Thomas Orozco
58dd2370bb mononoke/hooks: log hook rejections to Scuba
Summary:
Right now we're only logging hooks that outright fail, which isn't great. Let's
log rejections as well.

Reviewed By: johansglock

Differential Revision: D21522804

fbshipit-source-id: 6bfc6b12394099b04faa9d23f164b436935f9fb3
2020-05-12 06:12:36 -07:00
Thomas Orozco
6df567f7ca mononoke/repo_client: log when hooks finished (and how many were rejected)
Summary:
This updates repo_client to log when hooks finished, and how many were rejecte,
if any. This required a bit of refactoring to avoid iterating twice over
whether hooks are rejected or not (and instead just filter-maps outcomes to a
rejection), but it's probably for the better since it removes a bit of
un-necessary cloning (notably of the hook name).

Reviewed By: farnz

Differential Revision: D21379690

fbshipit-source-id: 53c8368d3871620ec61db76dc35b47dd17276ac4
2020-05-04 09:54:59 -07:00
Simon Farnsworth
fafe8802b4 Clean up Lua-only hook config requirements
Summary:
Make all the things that only Lua hooks needed (hook type etc) optional.

With this done, configs can be cleaned up to not contain redundant data.

Reviewed By: ikostia

Differential Revision: D21349614

fbshipit-source-id: 1c72c2082b8c002e3feb41d1d720a41d21afaae5
2020-05-01 12:13:07 -07:00
Lukas Piatkowski
8bba936e5f mononoke/permission_checker: introduce MembershipChecker and its first usage in hooks
Summary: The new MembershipChecker and PermissionChecker traits will generalize access to various permission/acl systems (like LDAP) and leave the implementation details hidden behind an object trait.

Reviewed By: StanislavGlebik

Differential Revision: D21067811

fbshipit-source-id: 3bccd931f8acdb6c1e0cff4cb71917c9711b590b
2020-04-23 03:44:09 -07:00
Lukas Piatkowski
449594be46 mononoke/hooks: fix to panic the server when AclChecker is unreachable
Summary:
In next diffs with permission_checker the panic is changed to anyhow::Error.

The previous behavior of this code was that when AclChecker updated failed
after 10s this fact was ignored and the hooks were simply not using ACLs. This
diff fixes it so that the server exits when AclChecheker update is timing out.

Reviewed By: johansglock

Differential Revision: D21155944

fbshipit-source-id: ab4a5071acbe6a1282a7bc5fdbf301b4bd53a347
2020-04-22 02:45:03 -07:00
Egor Tkachenko
ba141a2d70 mononoke: opsfiles: Port chef_chef_test.sh hook
Summary: Porting chef_chef_test.sh hook into mononoke rust hooks

Reviewed By: HarveyHunt

Differential Revision: D21040287

fbshipit-source-id: 663d79f6d1e467be57fd82c7e06660971c8bd90d
2020-04-16 16:46:02 -07:00
Thomas Orozco
fec12c95f1 mononoke/hooks: compute the changeset id once, be O(N) as opposed to O(N^2)
Summary:
Unfortunately, `BonsaiChangeset::get_changeset_id()` is a fairly expensive
operation, since it'll clone, serialize, and hash the changeset. In hooks in
particular, since we run this once per hook execution (and therefore once per
file), that can be come a problem.

Indeed, on a commit with 1K file changes, hooks run for ~30 seconds
(P129058164). According to perf, the overwhelming majority of that time is
spent in computing hashes of bonsai changesets. For a commit with 10K changes,
it spends time there as well, it took 3.5 hours.

This diff updates hooks to compute the changeset id just once, which brings our
time down to O(N) (where N = file changes).

Reviewed By: StanislavGlebik

Differential Revision: D21039811

fbshipit-source-id: 73f9939ffc7d095e717bdb5efc46dbf4ad312c65
2020-04-15 06:29:50 -07:00
Thomas Orozco
5186d4e694 mononoke/metaconfig: include the repository hgsql name in the config
Summary:
This parses out the Hgsql name out of the repo config. While in there, I also
noticed that our tests force us to have a default impl right now (there are
otherwise waaaay to many fields to specify), but at the same time we don't use
it everywhere. So, in an effort to clean up, I updated hooks to use a default.

I added a newtype wrapper for the hgsql name, since this will let me update the
globalrev syncer and SQL repo lock implementation to require a HgsqlName
instead of a string and have the compiler prove that all callsites are doing
so.

Reviewed By: farnz

Differential Revision: D20942177

fbshipit-source-id: bfbba6ba17cf3e3cad0be0f8406e41e5a6e6c3d4
2020-04-14 10:26:10 -07:00
Simon Farnsworth
f8cc1c6e97 Delete HgChangeset hook handling completely
Summary: Not in use any more - all hooks are now Bonsai form - so remove it.

Reviewed By: krallin

Differential Revision: D20891164

fbshipit-source-id: b92f169a0ec3a4832f8e9ec8dc9696ce81f7edb3
2020-04-11 04:26:37 -07:00
Simon Farnsworth
25b29257a3 Port hooks which now run on modified, not just added files
Summary: These hooks now run on modified files, not just added files, after porting to Bonsai form.

Reviewed By: krallin

Differential Revision: D20891166

fbshipit-source-id: 93a142f91c0bea7f5fe5e541530c644d215dce3a
2020-04-11 04:26:37 -07:00
Simon Farnsworth
4135c567a8 Port over all hooks whose behaviour doesn't change from Mercurial form to Bonsai form
Summary: These hooks behave the same way in Mercurial and Bonsai form. Port them over to operating on Bonsai form

Reviewed By: krallin

Differential Revision: D20891165

fbshipit-source-id: cbcdf217398714642d2f2d6669376defe8b944d7
2020-04-08 08:59:01 -07:00
Simon Farnsworth
c59ae3274b Teach hook loader to load new (Bonsai) form hooks
Summary: To use Bonsai-based hooks, we ned to be able to load them. Make it possible.

Reviewed By: krallin

Differential Revision: D20879135

fbshipit-source-id: 9b44d7ca83257c8fc30809b4b65ec27a8e9a8209
2020-04-08 08:59:00 -07:00
Simon Farnsworth
b66d875fa5 Move hooks over from an internal representation based on HgChangesets to BonsaiChangesets
Summary: We want all hooks to run against the Bonsai form, not a Mercurial form. Create a second form of hooks (currently not used) which acts on Bonsai hooks. Later diffs in the stack will move us over to Bonsai only, and remove support for Mercurial changeset derived hooks

Reviewed By: krallin

Differential Revision: D20604846

fbshipit-source-id: 61eece8bc4ec5dcc262059c19a434d5966a8d550
2020-04-08 08:59:00 -07:00
Mark Thomas
640f272598 migrate from sql_ext::SqlConstructors to sql_construct
Summary:
Migrate the configuration of sql data managers from the old configuration using `sql_ext::SqlConstructors` to the new configuration using `sql_construct::SqlConstruct`.

In the old configuration, sharded filenodes were included in the configuration of remote databases, even when that made no sense:
```
[storage.db.remote]
db_address = "main_database"
sharded_filenodes = { shard_map = "sharded_database", shard_num = 100 }

[storage.blobstore.multiplexed]
queue_db = { remote = {
    db_address = "queue_database",
    sharded_filenodes = { shard_map = "valid_config_but_meaningless", shard_num = 100 }
}
```

This change separates out:
* **DatabaseConfig**, which describes a single local or remote connection to a database, used in configuration like the queue database.
* **MetadataDatabaseConfig**, which describes the multiple databases used for repo metadata.

**MetadataDatabaseConfig** is either:
* **Local**, which is a local sqlite database, the same as for **DatabaseConfig**; or
* **Remote**, which contains:
    * `primary`, the database used for main metadata.
    * `filenodes`, the database used for filenodes, which may be sharded or unsharded.

More fields can be added to **RemoteMetadataDatabaseConfig** when we want to add new databases.

New configuration looks like:
```
[storage.metadata.remote]
primary = { db_address = "main_database" }
filenodes = { sharded = { shard_map = "sharded_database", shard_num = 100 } }

[storage.blobstore.multiplexed]
queue_db = { remote = { db_address = "queue_database" } }
```

The `sql_construct` crate facilitates this by providing the following traits:

* **SqlConstruct** defines the basic rules for construction, and allows construction based on a local sqlite database.
* **SqlShardedConstruct** defines the basic rules for construction based on sharded databases.
* **FbSqlConstruct** and **FbShardedSqlConstruct** allow construction based on unsharded and sharded remote databases on Facebook infra.
* **SqlConstructFromDatabaseConfig** allows construction based on the database defined in **DatabaseConfig**.
* **SqlConstructFromMetadataDatabaseConfig** allows construction based on the appropriate database defined in **MetadataDatabaseConfig**.
* **SqlShardableConstructFromMetadataDatabaseConfig** allows construction based on the appropriate shardable databases defined in **MetadataDatabaseConfig**.

Sql database managers should implement:

* **SqlConstruct** in order to define how to construct an unsharded instance from a single set of `SqlConnections`.
* **SqlShardedConstruct**, if they are shardable, in order to define how to construct a sharded instance.
* If the database is part of the repository metadata database config, either of:
    * **SqlConstructFromMetadataDatabaseConfig** if they are not shardable.  By default they will use the primary metadata database, but this can be overridden by implementing `remote_database_config`.
    * **SqlShardableConstructFromMetadataDatabaseConfig** if they are shardable.  They must implement `remote_database_config` to specify where to get the sharded or unsharded configuration from.

Reviewed By: StanislavGlebik

Differential Revision: D20734883

fbshipit-source-id: bb2f4cb3806edad2bbd54a47558a164e3190c5d1
2020-04-02 05:27:16 -07:00
Simon Farnsworth
d2cba5a169 Centralise hook running in the HookManager
Summary: We had hooks logic scattered around the place - move it all into the hooks crate, so that it's easier to refactor to use Bonsai changesets instead of hg.

Reviewed By: StanislavGlebik

Differential Revision: D20198725

fbshipit-source-id: fb8bdc2cdbd1714c7181a5a0562c1dacce9fcc7d
2020-03-18 09:17:17 -07:00
Simon Farnsworth
a908be34b3 Modernise hooks support
Summary: Migrate hooks to new futures and thus modern tokio. In the process, replace Lua hooks with Rust hooks, and add fixes for the few cases where Lua was too restrictive about what could be done.

Reviewed By: StanislavGlebik

Differential Revision: D20165425

fbshipit-source-id: 7bdc6820144f2fdaed653a34ff7c998913007ca2
2020-03-18 09:17:17 -07:00
Thomas Orozco
999333424e mononoke/server: add support for logging Scuba to a file
Summary:
This is convenient because it makes it possible to tell what is going on within
Mononoke from the outside (e.g. introspect perf counters).

I'll land this after D20387115.

Reviewed By: farnz

Differential Revision: D20387125

fbshipit-source-id: ee070c4d658a0ec8f232152fe8b34bd0b56e6888
2020-03-12 11:16:07 -07:00
David Tolnay
e988a88be9 rust: Rename futures_preview:: to futures::
Summary:
Context: https://fb.workplace.com/groups/rust.language/permalink/3338940432821215/

This codemod replaces *all* dependencies on `//common/rust/renamed:futures-preview` with `fbsource//third-party/rust:futures-preview` and their uses in Rust code from `futures_preview::` to `futures::`.

This does not introduce any collisions with `futures::` meaning 0.1 futures because D20168958 previously renamed all of those to `futures_old::` in crates that depend on *both* 0.1 and 0.3 futures.

Codemod 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, //common/rust/renamed:futures-preview, 1))" \
| xargs sed -i 's,\bfutures_preview::,futures::,'

rg \
    --files-with-matches \
    --type-add buck:TARGETS \
    --type buck \
    --glob '!/experimental' \
    --regexp '(_|\b)rust(_|\b)' \
| xargs sed -i 's,//common/rust/renamed:futures-preview,fbsource//third-party/rust:futures-preview,'
```

Reviewed By: k21

Differential Revision: D20213432

fbshipit-source-id: 07ee643d350c5817cda1f43684d55084f8ac68a6
2020-03-03 11:01:20 -08:00
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
Thomas Orozco
c680696e40 mononoke: defer hook loading
Summary:
Most binaries don't need hooks. Let's not require them. This might not be very
long lived since Simon is working on removing lua hooks, but this was a trivial
fix.

Reviewed By: johansglock

Differential Revision: D20140026

fbshipit-source-id: cc74b37459f63c5dd550c5779b72aa1d6531202c
2020-02-28 02:03:07 -08:00
Thomas Orozco
f1121ccef6 mononoke: add a @nocommit hook
Reviewed By: HarveyHunt

Differential Revision: D20139540

fbshipit-source-id: 0be6d1aa8ad7ad1197197ec886f0cf44bd6b864d
2020-02-27 08:28:05 -08:00
Thomas Orozco
26ae726af5 mononoke: update internals to Bytes 0.5
Summary:
The Bytes 0.5 update left us in a somewhat undesirable position where every
access to our blobstore incurs an extra copy whenever we fetch data out of our
cache (by turning it from Bytes 0.5 into Bytes 0.4) — we also have quite a few
place where we convert in one direction then immediately into the other.

Internally, we can start using Bytes 0.5 now. For example, this is useful when
pulling data out of our blobstore and deserializing as Thrift (or conversely,
when serializing and putting it into our blobstore).

However, when we interface with Tokio (i.e. decoders & encoders), we still have
to use Bytes 0.4.  So, when needed, we convert our Bytes 0.5 to 0.4 there.

The tradeoff idea is that we deal with more bytes internally than we end up
sending to clients, so doing the Bytes conversion closer to the point of
sending data to clients means less copies.

We can also start removing those once we migrate to Tokio 0.2 (and newer
versions of Hyper for HTTP services).

Changes that were required:

- You can't extend new bytes (because that implicitly copies). You need to use
  BytesMut instead, which I did where that was necessary (I also added calls in
  the Filestore to do that efficiently).
- You can't create bytes from a `&'a [u8]`, unless `'a` is  `'static`. You need
  to use `copy_from_slice` instead.
- `slice_to` and `slice_from` have been replaced by a `slice()` function that
  takes ranges.

Reviewed By: StanislavGlebik

Differential Revision: D20121350

fbshipit-source-id: eb31af2051fd8c9d31c69b502e2f6f1ce2190cb1
2020-02-27 08:08:28 -08:00
Thomas Orozco
7698cded43 mononoke/hooks: add a signed source hook
Reviewed By: HarveyHunt

Differential Revision: D20139152

fbshipit-source-id: a0a48d447444cf969162f5f9655ab003e7ca2f76
2020-02-27 08:05:14 -08:00
Thomas Orozco
4ca1333b8a mononoke/hooks: use a smaller test group for faster tests
Reviewed By: ikostia

Differential Revision: D20115985

fbshipit-source-id: 4f69fc84eee352bcc689918527c6d460fcf672ba
2020-02-26 04:44:39 -08:00
Harvey Hunt
0ecac65ac4 mononoke: Remove restrict_users hook
Summary:
This hook was implemented to prevent incorrect users from moving a
bookmark. However, it doesn't work and the functionality is now implemented by
`is_allowed_user` in the pushrebase pipeline.

Remove the unused hook.

Reviewed By: johansglock

Differential Revision: D20030479

fbshipit-source-id: bcbc9508eebe77cffbc7936382ba4d345b76f74f
2020-02-21 09:46:38 -08:00
Thomas Orozco
8086dc29c7 mononoke: add a limit_commit_message_length hook
Summary:
We're working towards sharding Bonsais. Let's make them easier to cache by also
not allowing arbitrarily large commit messages.

Reviewed By: StanislavGlebik

Differential Revision: D20002994

fbshipit-source-id: b2319ac9d5709e968121d4299396e03a90df4a06
2020-02-21 07:18:15 -08:00
Thomas Orozco
614fa33af2 mononoke: add a limit_path_length hook
Summary:
This adds a file hook to limit the file length we are willing to allow in
commits. This is necessary for now since Mercurial does have a limit on its
end, and we shouldn't allow commits that we cannot sync to Mercurial.

Reviewed By: HarveyHunt

Differential Revision: D19969689

fbshipit-source-id: 1da8a62d54e98b047d381a9d073ac148c9af84b0
2020-02-20 02:49:38 -08:00