Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,22 @@ Diff_len(Diff *self)
return (Py_ssize_t)git_diff_num_deltas(self->diff);
}

PyDoc_STRVAR(Diff_patchid__doc__,
"Corresponding patchid.");

PyObject *
Diff_patchid__get__(Diff *self)
{
git_oid oid;
int err;

err = git_diff_patchid(&oid, self->diff, NULL);
if (err < 0)
return Error_set(err);
return git_oid_to_python(&oid);
}


PyDoc_STRVAR(Diff_deltas__doc__, "Iterate over the diff deltas.");

PyObject *
Expand Down Expand Up @@ -1024,6 +1040,7 @@ PyGetSetDef Diff_getsetters[] = {
GETTER(Diff, deltas),
GETTER(Diff, patch),
GETTER(Diff, stats),
GETTER(Diff, patchid),
{NULL}
};

Expand Down
1 change: 1 addition & 0 deletions src/diff.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

PyObject* Diff_changes(Diff *self);
PyObject* Diff_patch(Diff *self);
PyObject* Diff_patchid(Diff *self);

PyObject* wrap_diff(git_diff *diff, Repository *repo);
PyObject* wrap_diff_delta(const git_diff_delta *delta);
Expand Down
9 changes: 9 additions & 0 deletions test/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
-c/d contents
"""

PATCHID = 'f31412498a17e6c3fbc635f2c5f9aa3ef4c1a9b7'

PATCH_BINARY = """diff --git a/binary_file b/binary_file
index 86e5c10..b835d73 100644
Binary files a/binary_file and b/binary_file differ
Expand Down Expand Up @@ -279,6 +281,13 @@ def test_diff_ids(self):
assert delta.old_file.id.hex == '7f129fd57e31e935c6d60a0c794efe4e6927664b'
assert delta.new_file.id.hex == 'af431f20fc541ed6d5afede3e2dc7160f6f01f16'

def test_diff_patchid(self):
commit_a = self.repo[COMMIT_SHA1_1]
commit_b = self.repo[COMMIT_SHA1_2]
diff = commit_a.tree.diff_to_tree(commit_b.tree)
assert diff.patch == PATCH
assert diff.patchid.hex == PATCHID

def test_hunk_content(self):
commit_a = self.repo[COMMIT_SHA1_1]
commit_b = self.repo[COMMIT_SHA1_2]
Expand Down