Commit Graph

6 Commits

Author SHA1 Message Date
Jun Wu
94c114e021 test-configparser: fix failure on Windows
Summary:
The test fails like:

```
    --- test-configparser.t
    +++ test-configparser.t.err
    @@ -21,7 +21,7 @@
       >>> from mercurial.rust import config
       >>> cfg = config.config()
       >>> cfg.readpath("a.rc", "readpath", None, None, None)
    -  ['"$TESTTMP/broken.rc":\n --> 1:2\n  |\n1 | %not-implemented\n  |  ^---\n  |\n  = expected include or unset']
    +  ['"\\\\\\\\\\\\\\\\?\\\\\\\\C:\\\\\\\\cygwin\\\\\\\\data\\\\\\\\sandcastle\\\\\\\\temp\\\\\\\\hgtests.ta2wor\\\\\\\\child187\\\\\\\\test-configparser.t\\\\\\\\broken.rc":\\n --> 1:2\\n  |\\n1 | %not-implemented\\n  |  ^---\\n  |\\n  = expected include or unset']\r (esc)
       >>> cfg.parse("[c]\nx=1", "parse")
       []
       >>> cfg.set("d", "y", "2", "set1")
```

Not sure how `$TESTTMP` works. But let's repalce all of them to glob pattern as
an attempt to fix the test.

See https://fburl.com/sandcastle/pmirvy8a for full log.

Reviewed By: DurhamG

Differential Revision: D9281760

fbshipit-source-id: bb7319511bc8ffecba139bd608f47d7204853076
2018-08-10 18:25:21 -07:00
Jun Wu
3e4c952d62 configparser: translate byte range to line number at Python land
Summary:
The configsource line number is exposed in a bunch of UI and tests.  Therefore
translate the bytes range to line numbers in the Python wrapper.

The Rust config parser does not track line numbers explicitly, as that adds
complexity to the parser.

The implemenation is inefficient. However, configsource is not used in
common code paths, so it'd be fine.

Reviewed By: DurhamG

Differential Revision: D8960868

fbshipit-source-id: 55e9f5170177e7cb4c8ef55ed17c1f85eb70a192
2018-08-09 21:21:49 -07:00
Jun Wu
cb58cd0d26 configparser: return errors instead of keeping them
Summary:
Change the API to return parse errors directly, instead of keeping them in
ConfigSet struct. This makes it easier to get errors related to one of the
"parse" calls.

Reviewed By: DurhamG

Differential Revision: D8960869

fbshipit-source-id: fbd571f264415e788c5ac44961149d1498826a6d
2018-08-09 21:21:49 -07:00
Jun Wu
a4129f8d53 configparser: use pest to parse config files
Summary:
[pest](https://github.com/pest-parser/pest) is an elegant Rust library for
parsing text.

A navie benchmark on a 1MB config file shows pest is about 1.5 to 2x slower.
But the better error message and cleaner code seems worth it.

Practically, in a VirtualBox VM, parsing a set of our config files takes 3-7ms.
The overhead seems to be opening too many files. Reducing it to one file makes
parsing complete in 2-4ms.

Unfortunately the buck build has issues with the elegant syntax
`#[grammar = "spec.pest"]`, because "spec.pest" cannot be located by pest_derive.
Therefore a workaround is used to generate the parser.

The motivation behind this is because I noticed multi-line value can not be
taken as a plain Bytes slice. For example:

  [section]
  foo = line1
    line2

"foo" should be "line1\nline2", instead of "line1\n  line2". It does not make a
difference on configlist. But it affects templates. Rather than making the
parser more complex, it seems better to just adopt a reasonbly fast parsing
library.

Reviewed By: DurhamG

Differential Revision: D8960876

fbshipit-source-id: 2fa04e38b706f7126008512732c9efa168f84cc7
2018-08-08 17:20:00 -07:00
Jun Wu
4f6c9b1a5e configparser: add a way to clone configs
Summary: Mercurial's ui.py needs a way to copy configs.

Reviewed By: DurhamG

Differential Revision: D8886245

fbshipit-source-id: b936edf5e215ecae078d992a344bcecef7fcd7f3
2018-08-08 17:20:00 -07:00
Jun Wu
ec34cbf739 configparser: expose interface to Python world
Summary: This allows the Python world to access its features.

Reviewed By: DurhamG

Differential Revision: D8790922

fbshipit-source-id: e7e561c86596159c3766d6da8e0834c6fe441cbd
2018-08-08 17:20:00 -07:00