libgit2 / libgit2/pygit2

Repository.create_note() does not accept bytes

Open
#1,021 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.7k
Forks
408
Avg merge
2d 57m
Merged PRs (30d)
7

Description

Hi,

Thank you for pygit2! I'm using it heavily in a project to present all Ubuntu source package history as git repositories.

Any chance Repository.create_note() could be adjusted to accept bytes as well as str? An issue I just hit is when I'm trying to create git notes that contain text that is not UTF-8 encoded. This happened historically in Debian/Ubuntu packaging history and I'd like to represent that in git notes that get created by just "passing through" the unknown encoding. As git doesn't care about the encoding of a note, I think this should work OK.

The relevant code is here: https://github.com/libgit2/pygit2/blob/58da6bb2b958139dab285e183ca6616509960587/src/repository.c#L1677

It looks like this could just be tweaked slightly to also accept a bytes, as it's all being converted into a C-string to hand to git anyway. There might be an edge case to consider when the bytes contains NULs. That might have to be unacceptable, tested for and result in a ValueError. It might also make sense to adjust behaviour everywhere pygit2 accepts a string to hand to git, so I appreciate it's a bit of a rabbit hole.

This isn't essential so I can work around this and don't want to get into testing a patch right now, but I thought it might be worth noting this in your issue tracker (and I can now link to this from my workaround).

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 at src/repository.c around Repository.create_note() at line 1677 and inspect how the note message is converted before being passed to Git. The work is done when bytes are accepted alongside str for non-UTF-8 note content, with a defined outcome for embedded NUL bytes, such as rejecting them with ValueError.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, python
Domain
devtools
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.