Feature request: Create blobs in-memory

未關閉
#2,050 0 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
35/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
csharp, git
領域
devtools

研究方向

首先,追蹤 libgit2sharp API 中 Blob 的建構、ObjectDatabase.Write 和 Diff.Compare。所要求的行為是從字串或串流建立 blob,並將它們傳遞給記憶體中的 diff,而不寫入磁碟或要求使用以磁碟為基礎的儲存庫;使用 issue 中顯示的舊內容和新內容進行驗證。

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
C#
星號
3.5k
分支
925
PR 合併指標
30 天內沒有已合併 PR

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

libgit2/libgit2sharp 的其他 Issue

查看 libgit2/libgit2sharp 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。