Commit Graph

9 Commits

Author SHA1 Message Date
Mark Thomas
2deae85b42 encoding: use Cow for returned types that may be references
Summary:
I broke the Windows build because the return type of `path_to_local_bytes` is
different on Windows and Unix, and so must be dealt with differently.  They are
different because on Windows we often need to make a copy, whereas on Unix we
can just use references to the byte data.  Cows to the rescue: unify them
behind a Cow type.

While we're here, tidy up and unify the docs.

Reviewed By: quark-zju, ikostia

Differential Revision: D12833091

fbshipit-source-id: e02e308e6f81dd3d8ddf33e76c3073f51d3eccc1
2018-10-30 04:07:02 -07:00
Jun Wu
3adc813687 codemod: add copyright headers
Summary: This is just the result of running `./contrib/fix-code.py $(hg files .)`

Reviewed By: ikostia

Differential Revision: D10213075

fbshipit-source-id: 88577c9b9588a5b44fcf1fe6f0082815dfeb363a
2018-10-26 15:09:12 -07:00
Kostia Balytskyi
59e00ccf47 hg: add some convenient panicking conversion to encoding
Summary:
Local bytes `&[u8]` or `Vec<u8>` is frequently wrapped into a `CString`,
because `CString` includes a trailing 0. Let's add a helper for that.

Reviewed By: quark-zju

Differential Revision: D9482435

fbshipit-source-id: 096ba725d83acc9c5fc1fe836dce509fe36e49e9
2018-08-30 04:42:11 -07:00
Kostia Balytskyi
8693c2d67b hg: improve encoding::path_to_local_bytes on Windows
Summary:
This improvement avoids an extra conversion to String (which can fail if
something cannot be encoded as UTF8).

Reviewed By: quark-zju

Differential Revision: D9447823

fbshipit-source-id: fa13ff9b833cc4edf9f5dc518b3f8712518c97fd
2018-08-30 02:51:13 -07:00
Kostia Balytskyi
819d195bc8 hg: add some platform-specific tests for encoding crate
Summary:
This just adds some more tests that in case of Windows try to execute the
string encoding APIs directly, while paying attention to the ANSI Code Page.

Reviewed By: quark-zju

Differential Revision: D9441406

fbshipit-source-id: c0873dca9fc8775839a62da60af46ff29e700634
2018-08-22 09:06:22 -07:00
Kostia Balytskyi
71baca5dfa hg: add osstring_to_local_bytes function to the encoding crate
Summary: Another convenience method that I plan to use in the `hgmain` later.

Reviewed By: quark-zju

Differential Revision: D9441426

fbshipit-source-id: 007e4932a344b9d1c8d4d654152bcca5c2362431
2018-08-22 09:06:22 -07:00
Kostia Balytskyi
1175b6b1c6 hg: extract platform-specific bits of encoding into separate files
Summary:
I think it's more readable to split the implementations into platform-specific
bits.

Reviewed By: quark-zju

Differential Revision: D9441424

fbshipit-source-id: 136d5a00aa4ed8cf4f0886bda0f77a40cba1f542
2018-08-22 09:06:21 -07:00
Kostia Balytskyi
fa882cf7da hg: make encoding create use ANSI code page, not OEM
Summary:
We almost never need an `OEM` code page: Windows API calls use ANSI-encoded
strings if they are `A` calls and Wide strings if they are `W` calls.

Reviewed By: quark-zju

Differential Revision: D9441425

fbshipit-source-id: 979697c349389ea4f7569be9949be3b636f6063c
2018-08-22 09:06:21 -07:00
Kostia Balytskyi
25a8ee686f hg: rename pathencoding into encoding
Summary:
In the later diffs I'll add some more functionality there, not strictly
related to encoding paths.

Reviewed By: quark-zju

Differential Revision: D9441427

fbshipit-source-id: 069ab30a24761038fa2c1a4f180bbc0699d38ef9
2018-08-22 09:06:20 -07:00