Commit Graph

29 Commits

Author SHA1 Message Date
Jun Wu
a501869b9e dispatch: make Repo::shared_path non-optional
Summary:
This is consistent with the Python code `repo.sharedvfs` and makes it easier to
use.

Reviewed By: xavierd

Differential Revision: D17467215

fbshipit-source-id: 4284ae602ffa4ea55a58dd8f102bf9d35ff244ad
2019-09-20 18:32:37 -07:00
Jun Wu
ad62662ae5 hgcommands: log process tree
Summary: This will help figuring out "who called this command".

Reviewed By: singhsrb

Differential Revision: D17467214

fbshipit-source-id: f691fce5b5d3da765c4ce14fec7722accb2816b4
2019-09-20 18:32:37 -07:00
Jun Wu
11c712b09c hgcommands: log command finish event
Summary:
This has a bunch of benefits:
- "duration_ms" counts Python startup overhead, and does not count the missing
  "chg pager blocked" at the end of chg process.
  It's more desirable than other kinds of "duration"s.
- Max RSS is logged. So we might get rid of a seprate wrapper eventually.

Reviewed By: singhsrb

Differential Revision: D17423799

fbshipit-source-id: 94121787506d435875a22cc03d638297120dad00
2019-09-20 18:32:36 -07:00
Jun Wu
7d149487c0 hgcommands: log process start event
Summary:
This will provide the "fullargs" information needed by telemetry.

Log in "hgcommands", instead of "hgmain", or "clidispatch", because:
- "clidispatch" does not have  argv[0], and might be called multiple times
  (from Rust, then from the fallback Python -> bindings)
- Logs in "hgmain" won't be written to disk if chg is used.

I removed "env", since "hgcommands" does not have access to hgrc to decide what
env to log. It seems desirable if the "env" logging is move to a fb-only
backgroud logging binary.

Reviewed By: singhsrb

Differential Revision: D17423796

fbshipit-source-id: da3c54e916203f8368f8389fc7eed91e5299a75d
2019-09-20 18:32:36 -07:00
Jun Wu
484939a75d hgmain: make bindings a builtin module
Summary:
Global states (For example, the global blackbox instance, potentially some
logging / tracing libraries) are separate in the Rust and Python worlds.

That is because related code gets compiled separately:

  bindings.so (top-level)
   \_ blackbox

  hgmain (top-level)
   \_ blackbox (have a different global instance than the above blackbox)

To address it, make `bindings` a builtin module in `hgmain`.

The builtin module was renamed from `edenscmnative.bindings` to `bindings` so
it does not require importing anything else (For example, `edenscmnative`).

This unfortunately makes `hg` 100+ MB. Fortunately it can be compressed well
(gzip: 31MB).

Reviewed By: singhsrb

Differential Revision: D17429688

fbshipit-source-id: bf16910d7a260ca58db0d272fc95d8071d47bbc6
2019-09-20 18:32:36 -07:00
Jun Wu
33216d5840 commands: add a command to run Python interpreter
Summary:
This makes it possible to use `hg debugpython -- ...` to replace `python ...`.
An upcoming change makes `edenscmnative.bindings` non-importable. To continue
support Python tests, we need an alternative way to run Python.

Reviewed By: singhsrb

Differential Revision: D17423797

fbshipit-source-id: 21ece4d35c2fdc09c281b10d5a07ee8af2e78384
2019-09-20 18:32:34 -07:00
David Tolnay
97c13edcc7 Delete lines of the form "use [a-z_]+;"
Summary: I think these are left over from pre-2018 code where they may have been necessary. In 2018 edition, import paths in `use` always begin with a crate name or `crate`/`super`/`self`, so `use $ident;` always refers to a crate. Since extern crates are always in scope in every module, `use $ident` does nothing.

Reviewed By: Imxset21

Differential Revision: D17290473

fbshipit-source-id: 23d86e5d0dcd5c2d4e53c7a36b4267101dd4b45c
2019-09-10 15:06:37 -07:00
Xavier Deguillard
cf64b3dc99 revisionstore: allow a PackStore to ignore corrupted packfiles
Summary:
While a corrupted packfile can be safely removed from the shared hgcache, the
same isn't true for local packfile. When building the packstore, let's allow
the behavior on corrupted packfile to be chosen. This is voluntarily made as an
explicit argument to DataPackStore and HistoryPackStore constructor so the
caller can take this into account.

Reviewed By: quark-zju

Differential Revision: D17187155

fbshipit-source-id: 658fce401f8902a74cfd92780013d1b96e20a590
2019-09-05 10:21:26 -07:00
Jun Wu
30f293314c clidispatch: support explicitly named arguments in define_flags!
Summary:
This makes it possible to use explicitly named arguments. It can simplify the
code a bit by moving the error handling (incorrect number of arguments) to the
derived code.

Reviewed By: xavierd

Differential Revision: D16905460

fbshipit-source-id: 93dc58d684bb52cd2f9bddc25108ef0c500f81db
2019-08-28 19:26:28 -07:00
Jun Wu
ed3f36bb85 cliparser: return errors if unexpected arguments are provided
Summary:
If there is no `#[args]` field set, the command does not need arguments. In
that case, just error out directly. This can simplify command implementations.

Reviewed By: xavierd

Differential Revision: D16905461

fbshipit-source-id: f4a2d03cf032f34d1b5794010774ff80eb88e1cd
2019-08-28 19:26:28 -07:00
Jun Wu
3c881c88d7 clidispatch: change From to TryFrom for flags parsing
Summary: This make it possible for the flags parsing to return an error.

Reviewed By: xavierd

Differential Revision: D16905462

fbshipit-source-id: 06a70ee7c72132ebb2df453a740b58e6b46dfba2
2019-08-28 19:26:27 -07:00
Jun Wu
06ff75a799 cliparser: add #[command_name] to define_flags!
Summary:
Most commands do not care about the "command name" (aka. arg0). Only commands
sharing a similar implementation (ex. hg up/down/bottom/top) would need it.
Make it optional and make `args` not containing the command name.

Reviewed By: xavierd

Differential Revision: D16905459

fbshipit-source-id: 0a786731ebce2580e116fd50aad75062b03a1fa3
2019-08-28 19:26:27 -07:00
Jun Wu
60008634e7 hgcommands: pass args and io to Python
Summary:
This makes it possible to capture output of a Python command via the Rust
hgcommands crate.

Reviewed By: xavierd

Differential Revision: D16866467

fbshipit-source-id: e64feece9b31196fabfea110015d5c45cb548046
2019-08-28 19:26:25 -07:00
Jun Wu
0bf732777a hgcommands: move the actual "run_command" logic from hgmain to hgcommands
Summary:
Expose a simple method in hgcommands to run the actual (Rust or Python) command.
This makes it easier to expose the "runcommand" API via bindings.

I have to disable chg temporarily since `hg root` with chg stops working at present.
chg will be re-enabled in a later diff.

Reviewed By: xavierd

Differential Revision: D16866461

fbshipit-source-id: 46c5df9a577d748fab302a8c7157d8aa62d6f1bd
2019-08-28 19:26:24 -07:00
Jun Wu
16613a894d hgpython: make HgPython take the arguments
Summary:
Previously, HgPython hardcodes the arguments to be std::env::args().
This diff makes that an configurable argument.

Reviewed By: xavierd

Differential Revision: D16866464

fbshipit-source-id: 3a37dd89793e0813732ea9b088ff22c9a4c6b125
2019-08-28 19:26:23 -07:00
Jun Wu
f654b6ebd9 hgcommands: do not call Py_Finalize if Python was not initialized by us
Summary:
`Py_Finalize` is not recursive. It unconditionally destroys the Python interpreter
state. To make `hgcommands` usable in a library (ex. bindings), detect the case
where the interpreter was initialized, and skip `Py_Finalize` in that case.

Reviewed By: markbt

Differential Revision: D16866454

fbshipit-source-id: ea6bb6a83bc0b0fe7b5c2ce21158ae9d9e2a779d
2019-08-28 16:36:21 -07:00
Jun Wu
8f349dbb17 clidispatch: make repo.shared_path non-lazy
Summary:
Move `repo.shared_path` handling to repo initialization time and store it in
the repo structure.

This makes `repo.shared_path()` cheap if it gets used frequently.

Reviewed By: sfilipco

Differential Revision: D16796401

fbshipit-source-id: e19f3381cc87b55500ea1d27fd918ccb16a71972
2019-08-21 12:59:28 -07:00
Jun Wu
08a80a4bcc clidispatch: move repo specific logic to repo.rs
Summary:
Some functions in `dispatch.rs` are about the "repo". Move them to a better
place - `repo.rs`.

The repo and config logic is coupled. A new enum `OptionalRepo` was added, to
make code easier to write - `Some(repo)` means the repo exists, and `repo` owns
the config. `None(config)` means the repo is missing, but the config is still
available.

Reviewed By: sfilipco

Differential Revision: D16796403

fbshipit-source-id: 2f4017a52296b629e990f85437b2cfdd7263b9e6
2019-08-21 12:59:28 -07:00
Jun Wu
b6101a12e0 clidispatch: rework error handling
Summary:
Change error type in clidispatch from `DispatchError` to `failure::Error`.

Pros:
- `failure` will attach a backtrace for free. (otherwise, backtrace handling is
  manual)
- Wrapping other errors (ex. `io::Error`, `cliparser::Error`) is optional.
  (otherwise, wrapping other errors is mandatory, and needs to be careful to
  not lose information)

Cons:
- No longer able to enumerate *all* possible error types. (but can still
  downcast to specific errors)

This seems to be a good tradeoff especially because of the backtrace handling - I
ran into a few issues where the location where the error happened really helped
debugging.

Since we can no longer enumerate all possible error types, the enum was changed
to individual structs to make the code shorter (ex. the struct can be downcasted
directly, instead of down-casting to the enum, then matching its variant).

The `HighLevelError` handling was simplified and moved to `hgmain`.

The new code path falls back to Python less aggressively, therefore some behaviors
were tweaked (ex. `-R` takes a bundle path).

Reviewed By: sfilipco

Differential Revision: D16796400

fbshipit-source-id: 1b17eb8d62503644b118c6b799778182bf222538
2019-08-21 12:59:28 -07:00
Jun Wu
210bf49f5e clidispatch: replace Dispatcher with CommandTable
Summary:
The `Dispatcher` provides lots of features but its internal state only contains
the command table. Replace it with `CommandTable` and make the methods free
functions.

This makes function dependencies more cleaner, for example things like "locating
a repo", "getting the args" etc. won't require a `Dispatcher`.

A side effect of this change is the non-utf8 command line arguments are no longer
supported. This is already broken since our hg wrapper (accidentally) enforced
utf-8 command line. Therefore related tests are removed.

Reviewed By: sfilipco

Differential Revision: D16796395

fbshipit-source-id: a793ce7b8befe7caf62405c582fc932eb3daa099
2019-08-21 12:16:35 -07:00
Jun Wu
775ee9c0c9 root: normalize the repo path before printing it out
Summary:
Change `root` to normalize the repo path so it strips `\\?\` UNC prefix that
might break some (ex. Python) scripts.

Reviewed By: DurhamG

Differential Revision: D16928880

fbshipit-source-id: 9691b712f1ba0a07815d025e083d0cbd90b7d6a3
2019-08-20 16:40:25 -07:00
Jun Wu
36f974ebae clidispatch: register commands without CommandDefinition
Summary:
Previously, the command table state in `Dispatcher` is confusing:

    command_table: BTreeMap<String, CommandFunc>,
    commands: BTreeMap<String, CommandDefinition>,

Question: In what case do these BTreeMaps have different keys?

It does not make much sense. Therefore merge `CommandFunc` into
`CommandDefinition`, and remove the `command_table` field.

This affects the `register` API:

		fn register(&mut self, command: CommandDefinition, f: FN)

`f` is part of `CommandFunc`, which duplicates with `CommandDefinition`.

`CommandDefinition` contains 3 things: name, doc, and flags.

In the new `define_flags!` world, `flags` can be inferred from the type
of the function, so only `name` and `doc` are needed. Therefore change
the register function to:

		fn register(&mut self, f: FN, name: &str, doc: &str)

Update `hgcommands` to use the newer APIs. Commands can now be registered
without going through `CommandDefinition` explicitly.

Reviewed By: sfilipco

Differential Revision: D16733275

fbshipit-source-id: 68e404a5b271b72aad52f640123b1c083f31d76c
2019-08-19 19:27:31 -07:00
Jun Wu
ebde0168a2 clidispatch: remove load_python_commands
Summary:
The only actual use of the function is to get Python command names (not
functions) so it can do prefix matching.

Just change the prefix matching logic to load the config and drop concepts
about "python" in CommandDefinition.

The Rust command table now only contains Rust commands.

Reviewed By: sfilipco

Differential Revision: D16733265

fbshipit-source-id: 7c680ef77874e9a136befc286cd26663ba82b09f
2019-08-19 19:27:31 -07:00
Jun Wu
8ec9e492ff clidispatch: initial migration to define_flags!
Summary:
Use `define_flags!` to auto generate conversion from `ParseOutput`.
A side effect is `args` is moved to the struct, and function signature becomes simpler.

Currently, `args` will also include the command name itself. This might be
useful when multiple commands share a similar implementation (ex. `next`, `prev`).

Reviewed By: sfilipco

Differential Revision: D16733269

fbshipit-source-id: fe32e41fe48a97d2d2f5a122522a17fa3c5f5f82
2019-08-19 19:27:30 -07:00
Carolyn Busch
09ceebfcac Debugstore command
Summary: New degbugstore command prints contents of blob in store give filenname and hash.

Reviewed By: xavierd

Differential Revision: D16791780

fbshipit-source-id: d4529f3f368677b4f65a5772f82a1655552fefa5
2019-08-15 19:36:31 -07:00
Jun Wu
2ee74da41f cliparser: rename ParseOutput::get to pick and make it do the unwrap
Summary:
Previously, `get` returns an `Option<T>`. Almost all callers use `unwrap`
immediately, since they know what flag names are available. Let's just
move the `unwrap` inside the function. `get` in the Rust (and Python)
eco-system is considered nullable and panic-free. Rename it to `pick`
to make the difference more obvious.

I considered using the `Index` trait, but it has to return a reference,
which does not fit into this use-case.

Reviewed By: sfilipco

Differential Revision: D16715453

fbshipit-source-id: f754d208c4a1b0adeddaee82c7db82c790d6436c
2019-08-14 16:58:29 -07:00
Jun Wu
9fbefb5981 cliparser: remove ParseOutput::get_or_default
Summary:
The default value of a flag is already provided with the flag. Therefore
`get_or_default` requiring another `default` does not make much sense.
Remove it.

Reviewed By: farnz

Differential Revision: D16713531

fbshipit-source-id: 95a55289077b7308083b6685f013d1058419a675
2019-08-14 16:58:29 -07:00
Jun Wu
f5e6c0a966 hgcommands: move commands from hgmain
Summary:
Move commands.rs from hgmain to hgcommands so it can be reused in other places
(ex. bindings)

Reviewed By: farnz

Differential Revision: D16713532

fbshipit-source-id: f3ff66796df8c8e775f62a707f4c582d48fdd1ad
2019-08-08 22:54:10 -07:00
Jun Wu
3a7f54dffe lib: rename hgpython to hgcommands
Summary:
Upcoming patches will move hg command implementations from exec/hgmain to
lib/hgcommands. That has two benefits:

- The `bindings` crate can use `hgcommands` to call Rust commands from Python.
- Solve a link issue about CPython APIs. Right now, if `hgmain` depend
  on *multiple* libraries that depend on `cpython`, there will be a link error
  with `cargo build` complaining about lots of CPython APIs do not exist.
  With this change, `hgcommands` will be the only crate that `hgmain` depends
  on, therefore no such link issues.

Reviewed By: farnz

Differential Revision: D16713538

fbshipit-source-id: 3b0def6eec4870858cdb74ad1b3099dc4cbc42b2
2019-08-08 22:54:09 -07:00