libgit2 / libgit2/libgit2sharp

Feature request: Create blobs in-memory

Offen
#2,050 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
C#
Sterne
3.5k
Forks
925
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

I would like to make a diff between two strings with libgit2sharp. The strings hold file contents loaded elsewhere. The diff.Compare-methods only take blobs, and the constructors of the Blobclass don't accept strings or streams and are marked internal. This prevents me from creating blobs directly. I have to write to disk first.

    var oldFileContents = @"
        Line 1
        Line 2
        Line 3
    ";

    var newFileContents = @"
        Line 1
        Line 2 has changed
    ";

    
    var path = Repository.Init("C:\\tmp");
    var repo = new Repository(path);

    var oldObjectId = repo.ObjectDatabase.Write<Blob>(Encoding.UTF8.GetBytes(oldFileContents));
    var newObjectId = repo.ObjectDatabase.Write<Blob>(Encoding.UTF8.GetBytes(newFileContents));
    var oldBlob = repo.Lookup<Blob>(oldObjectId);
    var newBlob = repo.Lookup<Blob>(newObjectId);
    var diff = repo.Diff.Compare(oldBlob, newBlob);  // Works as expected

    // git repo for in-memory operations
    var in_memory_repo = new Repository();

    // This line failes with the LibGit2SharpException "path cannot exist in repository". As far as I can see this is intentional.
    var in_memory_blob = in_memory_repo.ObjectDatabase.Write<Blob>(Encoding.UTF8.GetBytes(oldFileContents));

Seeing that libgit2sharp already supports working with diffs and patches in-memory, it would be nice to be able to create blobs from strings or streams.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie damit, die Erstellung von Blob, ObjectDatabase.Write und Diff.Compare in der libgit2sharp API nachzuverfolgen. Das gewünschte Verhalten besteht darin, Blobs aus Zeichenfolgen oder Streams zu erstellen und sie an In-Memory-Diffs zu übergeben, ohne auf die Festplatte zu schreiben oder ein festplattenbasiertes Repository zu benötigen; validieren Sie dies mit den im Issue gezeigten alten und neuen Inhalten.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp, git
Bereich
devtools
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.