-
-
Notifications
You must be signed in to change notification settings - Fork 386
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
Split TreeEntry's equality and sorting #488
Conversation
Tests failing with Python 3 |
Ah, they removed sort's 'cmp'. I guess I'll just go with just using richcompare. |
5c792e3
to
5b4c355
Compare
I removed |
Hello, you have fixed the equal and not-equal cases, but it is still using Then (Sorry for not reviewing the code before and just stop at the failing test.) |
I don't see what making Two entries would also not be equal just because they point to the same object. The entries for file "a" and "b" are not equal just because the contents of the files they represent happent to be the same. |
With this commit we will run into this situation:
|
In other words this is breaking the order relation (the antisymmetry property to be specific). The issue #458 which spawned this PR says the current behaviour as counter intuitive, or surprising. But breaking the order relation is just as surprising. This commit is trying to do two different things in the same API. On the other hand I am not certain which would be the best solution. Maybe some use cases could help shed some light: @ssadler ? |
The function we were using `git_tree_entry_cmp()` is only meant for git-compatible sorting in a tree and thus does not take the id into account. This is however important in order to keep value equality. In order to avoid issues with assymetry, we compare the id any time when two entries are equal according to their position in a tree.
5b4c355
to
c099655
Compare
Ah yes, I hadn't thought about the I've updated the commit to always compare the ids when they would sort as equal. As having duplicate entries would be a bug when you're creating a tree (and might thus care about comparing inequality for entries) it doesn't detract from the ability to sort, and it keeps the result consistent, which the previous version did not. |
nice solution, sorting by name then by id |
The value equality for TreeEntry needs to take the id into account. The
function we were using
git_tree_entry_cmp()
is only meant forgit-compatible sorting in a tree and thus does not take that into
account. Change
_richcompare()
to do so.We then leave the git-copmatible sorting method as
TreeEntry.sortcmp()
which can be used to ask python to use that as the comparison function
in
sorted()
and friends.It might just be good enough to leave out
TreeEntry.sortcmp()
and just rely on richcompare, since the extra checking only comes in when they're otherwise equal.