rust: add encoding.rs
This is based on encoding.py. It reads the environment variables HGENCODING, HGENCODINGMODE, and HGENCODINGAMBIGUOUS. Currently it only supports UTF-8 and ascii, but it could be extended to support other local encodings. Unlike Python, it assumes all internal strings are UTF-8 and does not attempt to fallback to latin-1 (or ui.fallbackencoding). Nothing is using this now, but in the future command output and error messages should transition to using it. I replaced existing calls to `utf8_to_local` and `local_to_uf8` with direct String/bytes methods since they were not logically converting between internal and local encodings. Instead, they were used (for example) when an error message happened to be stored as String but needed to be passed somewhere as bytes. The proper fix for this will be to avoid String in the first place.
parent
1b7a57a5b47a
No related branches found
No related tags found
Showing
- rust/Cargo.lock 1 addition, 0 deletionsrust/Cargo.lock
- rust/hg-core/Cargo.toml 1 addition, 0 deletionsrust/hg-core/Cargo.toml
- rust/hg-core/src/encoding.rs 291 additions, 0 deletionsrust/hg-core/src/encoding.rs
- rust/hg-core/src/lib.rs 1 addition, 0 deletionsrust/hg-core/src/lib.rs
- rust/rhg/src/error.rs 4 additions, 5 deletionsrust/rhg/src/error.rs
- rust/rhg/src/main.rs 2 additions, 2 deletionsrust/rhg/src/main.rs
- rust/rhg/src/ui.rs 10 additions, 14 deletionsrust/rhg/src/ui.rs
- tests/test-rhg.t 6 additions, 0 deletionstests/test-rhg.t
Loading
Please register or sign in to comment