rust-lang / rust-lang/git2-rs

Support creating commits etc. with invalid utf-8

Open
#371 6 comments 1 reaction 0 assignees View on GitHub

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:

  1. Commits have message_bytes(&self) -> &[u8], but Repository::commit(...) only takes the message as &str
  2. Signatures have name_bytes and email_bytes, but Signature::new and Signature::now only accept &str
  3. Config has get_bytes, but no set_bytes
    • In addition, the keys cannot be bytes for get_* or set_* on Config, making non-utf8 keys non-settable from git2-rs.

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.