pygit2
pygit2 copied to clipboard
Repository.create_note() does not accept bytes
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).
Sure, this is already done in some places, check calls to pgit_encode* (this is defined in src/utils.c)
PRs welcome.