Skip to content

Commit

Permalink
Fixes libgit2#962: First create a git_patch to get delta->flags corre…
Browse files Browse the repository at this point in the history
…ctly
  • Loading branch information
yoichi committed Oct 23, 2021
1 parent 98e3d1f commit 6a58b97
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,17 @@ PyTypeObject DiffIterType = {
PyObject *
diff_get_delta_byindex(git_diff *diff, size_t idx)
{
git_patch *patch = NULL;
int err;

/* create a git_patch in order to store delta->flags */
err = git_patch_from_diff(&patch, diff, idx);
if (err < 0) {
PyErr_SetObject(PyExc_IndexError, PyLong_FromSize_t(idx));
return NULL;
}
git_patch_free(patch);

const git_diff_delta *delta = git_diff_get_delta(diff, idx);
if (delta == NULL) {
PyErr_SetObject(PyExc_IndexError, PyLong_FromSize_t(idx));
Expand Down
4 changes: 1 addition & 3 deletions test/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ def test_deltas(barerepo):
assert delta.nfiles == patch_delta.nfiles
assert delta.old_file.id == patch_delta.old_file.id
assert delta.new_file.id == patch_delta.new_file.id

# As explained in the libgit2 documentation, flags are not set
#assert delta.flags == patch_delta.flags
assert delta.flags == patch_delta.flags

def test_diff_parse(barerepo):
diff = pygit2.Diff.parse_diff(PATCH)
Expand Down

0 comments on commit 6a58b97

Please sign in to comment.