Skip to content
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

hotfix for repo.py in guess_is_binary(newblob) where 'newblob' could … #186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions klaus/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def commit_diff(self, commit):
dulwich_changes = self.object_store.tree_changes(parent_tree, commit.tree)
for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in dulwich_changes:
summary['nfiles'] += 1
newblob = oldblob = Blob.from_string(b'')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for the patch! I'd prefer this to be expressed in a more explicit way, and without the redundant Blob.from_string below.

How about something along the lines of:

if oldsha is None:
    # File was newly created [newsha: deleted]
    oldblob = Blob.from_string(b'')
elif oldsha not in self.object_store:
    # newsha/oldsha are probably related to submodules.
    # Dulwich will handle that.
    oldblob = Blob.from_string(b'')
else:
    oldblob = self.object_store[oldsha]

And the same duplicated for newsha/newblob.

(Note: Not sure if None is the only false-y value the `sha variables can have?)

try:
oldblob = self.object_store[oldsha] if oldsha else Blob.from_string(b'')
newblob = self.object_store[newsha] if newsha else Blob.from_string(b'')
Expand Down