Support creating commits etc. with invalid utf-8
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 2.1k
- Forks
- 450
- Avg merge
- 11m
- Merged PRs (30d)
- 1
Description
Currently there are a few object types which provide getters for retrieving data as &[u8], as the data may be invalid utf-8, but don't provide the equivalent setters or constructors, for example:
- Commits have
message_bytes(&self) -> &[u8], butRepository::commit(...)only takes the message as&str - Signatures have
name_bytesandemail_bytes, butSignature::newandSignature::nowonly accept&str - Config has
get_bytes, but noset_bytes- In addition, the keys cannot be bytes for
get_*orset_*on Config, making non-utf8 keys non-settable from git2-rs.
- In addition, the keys cannot be bytes for
This seems to apply to most objects. For example, it also affects References, Reflogs, etc.
The main reason why this seems good to handle is to support round-tripping an object through git2 and back into git. If an object can exist in the repository, it seems like there should be some mechanism for creating that object through the git2 API.
For a small project I'm working on I'm mostly impacted by commits and signatures, in that while I can support reading invalid utf-8, once I try to modify one of these objects, I cannot recreate certain properties faithfully without using libgit2-sys directly, so I'm currently falling back to doing lossy utf-8 conversions.
I imagine the easiest/best(?) solution here might be to follow CString's API, and change these methods to take S: Into<Vec<u8>> rather than &str, but I think that would be a breaking change due to type inference(?)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing byte getters and string-based entry points named in the issue: Repository::commit, Signature::new, Signature::now, and Config get_bytes/set methods. Compare the affected commit, signature, config, reference, and reflog APIs, then define a consistent way to create or update invalid UTF-8 data while preserving compatibility. Done means the relevant objects can be round-tripped without lossy UTF-8 conversion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, rust
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100