libgit2 / libgit2/pygit2

Repository.create_note() does not accept bytes

Aperta
#1,021 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
1.7k
Fork
408
Merge medio
2g 57m
PR unite (30g)
7

Descrizione

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).

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da src/repository.c, intorno a Repository.create_note() alla riga 1677, e verifica come viene convertito il messaggio della nota prima di essere passato a Git. Il lavoro è completato quando bytes viene accettato insieme a str per il contenuto delle note non UTF-8, con un comportamento definito per i byte NUL incorporati, ad esempio rifiutandoli con ValueError.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
git, python
Ambito
devtools
Tipo di issue
Funzionalità
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.