libgit2 / pygit2

Python bindings for libgit2
https://www.pygit2.org/
Other
1.58k stars 382 forks source link

Fixes #962: First create a git_patch to get delta->flags correctly #1100

Open yoichi opened 2 years ago

yoichi commented 2 years ago

diff_get_delta_byindex() may result incorrect value of delta->flags as described in the comment of git_diff_get_delta() (git2/diff.h)

Note that the flags on the delta related to whether it has binary
content or not may not be set if there are no attributes set for the
file and there has been no reason to load the file data at this point.
For now, if you need those flags to be up to date, your only option is
to either use `git_diff_foreach` or create a `git_patch`.

this pull request fixes #962

jdavid commented 2 years ago

My concern is that building the patch would be a waste of time if the flags are not used later. The alternative would be to build the patch lazily, when the flags are asked for, but this may not be easy.

I've done the related commit 464836c7 , if none of GIT_DIFF_FLAG_BINARY and GIT_DIFF_FLAG_NOT_BINARY have been set then the flags have not been loaded and the patch should be built.