Skip to content

[Support] Create Patch for new file from buffer #742

Closed
@brandonio21

Description

@brandonio21

Hello all,

I am working with the use case of creating diffs from buffers. Everything is going well as there is decent support for it, especially in the form of Blob.diff_to_buffer. The function works great when changing content and will soon work for deleting a file (In #741). However, I cannot figure out a proper way to add files using Blob.diff_to_buffer.

Do you guys have any suggestions? In libgit2, the proper way is to call git_diff_blob_to_buffer and set the Blob* argument to NULL. However, pygit2 does not have a static function to be able to do this. Do you guys have any suggestions? Here are things I can think of:

  1. Create a special "Empty" blob object (or give it an exists property) that can be used to signify a nonexistent blob and then do diff_to_buffer on that.

  2. Expose a static Patch.from_blob_to_buffer() which can then be called like Patch.from_blob_to_buffer(None, buf).

The other thing I can think of, which does not yet exist, is adding a Tree.diff_to_buffer()/Tree.diff_to_blob() to libgit2, which would solve this problem since the Tree would know whether the blob is being added or removed. (Of course, this would then have to be wrapped in pygit2)

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions