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
Summary: This will help figuring out "who called this command".
Reviewed By: singhsrb
Differential Revision: D17467214
fbshipit-source-id: f691fce5b5d3da765c4ce14fec7722accb2816b4
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
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
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
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
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
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
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
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
Summary: This make it possible for the flags parsing to return an error.
Reviewed By: xavierd
Differential Revision: D16905462
fbshipit-source-id: 06a70ee7c72132ebb2df453a740b58e6b46dfba2
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
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
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
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
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
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
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
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
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
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
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
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
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
Summary: New degbugstore command prints contents of blob in store give filenname and hash.
Reviewed By: xavierd
Differential Revision: D16791780
fbshipit-source-id: d4529f3f368677b4f65a5772f82a1655552fefa5
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
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
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
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