-
-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Patch does not have a reference to underlying blob(s) #754
Comments
Could you post a simple script that produces the problem, so I can start investigating? |
@jdavid : Well that seems like an extremely reasonable suggestion. Consider the following: old = self.repo[self.repo.create_blob(OLD_CONTENT)]
new = self.repo[self.repo.create_blob(NEW_CONTENT)]
patch = old.diff(new)
print(patch.patch) The expected outcome is something like:
Actual output is sometimes as expected, sometimes unprintable due to unicode/ascii conversion errors, and sometimes mangled as such:
|
@jdavid : Looking a little more into it, if I patch.c
Then a crash occurs instead of this "corruption" due to a utf-8 conversion error. I don't know if this helps at all. This either says that If I further:
I get similar behavior. Maybe this helps. If you have any information or any insight, I'd love to hear it! |
Okay, I started doing some I thought this meant that we were missing a Hopefully this aids in progress towards a solution |
Hi @brandonio21 , thanks for your research. Everything works here, including the news tests in #758 , but it may be pure luck. I am reviewing |
Pushed a commit, could you try? The error may be that |
Great news! I've tracked down the problem. The repro code is: def test_patch_delete_blob(self):
blob = self.repo[BLOB_OLD_SHA]
patch = pygit2.Patch.create_from(
blob,
None,
old_as_path=BLOB_OLD_PATH,
new_as_path=BLOB_NEW_PATH,
)
# Make sure that even after deleting the blob the patch still has the
# necessary references to generate its patch
del blob
self.assertEqual(patch.patch, BLOB_PATCH_DELETED) Alternatively, def test_patch_delete_blob(self):
blob = self.repo[BLOB_OLD_SHA]
patch = blob.diff_to_buffer(None)
# Make sure that even after deleting the blob the patch still has the
# necessary references to generate its patch
del blob
self.assertEqual(patch.patch, BLOB_PATCH_DELETED) I will submit a patch to fix it now :^) |
Now that I understand the problem more fully, I added more tests to #758 which fail in CI due to the problem described in this issue. |
Great job @brandonio21 ! Now that's something I can reproduce. Unfortunately the fix in #760 is not correct, |
Below is the equivalent C code reproducing the same behaviour. This surprises me a little bit, but I don't know so much about libgit2 internals. Maybe @carlosmn or @ethomson could enlighten us a bit? I thought objects in libgit2 were reference counted, if
|
@jdavid Thanks for posting that. Now that we know more about the issue, I'm going to rename all the corresponding PRs and issues. |
While waiting for the issue to be resolved on the libgit2 level, the following Python-level patch can be applied: https://github.com/brandonio21/pygit2/commit/c0eaa698d648af33a72c743ba296dd1427bcb81f |
That looks good! Could you make a PR please? |
Please feel free to comment with your thoughts, investigations, inquiries, etc. I'm not sure if what I am reporting is expected behavior or a bug, but I'd like to get to the cause anyway.
In #744 , tests were added which were broken for some users, as reported #748. In #753 I fixed the problem by not using
create_blob
, ascreate_blob
causes the issue.What happened? Why did this happen?
The text was updated successfully, but these errors were encountered: