Fix wrong sorting of remotes when using -J

It was sorting by uuid, rather than cost!

Avoid future bugs of this kind by changing the Ord to primarily compare
by cost, with uuid only used when the cost is the same.

This commit was supported by the NSF-funded DataLad project.
This commit is contained in:
Joey Hess 2018-08-03 13:06:06 -04:00
parent 178ab762eb
commit 1a02fc1159
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 18 additions and 2 deletions

View file

@ -146,8 +146,13 @@ instance Show (RemoteA a) where
instance Eq (RemoteA a) where
x == y = uuid x == uuid y
-- Order by cost since that is the important order of remotes
-- when deciding which to use. But since remotes often have the same cost
-- and Ord must be total, do a secondary ordering by uuid.
instance Ord (RemoteA a) where
compare = comparing uuid
compare a b
| cost a == cost b = comparing uuid a b
| otherwise = comparing cost a b
instance ToUUID (RemoteA a) where
toUUID = uuid