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

@ -279,4 +279,4 @@ pickRemote l a = go l =<< Annex.getState Annex.concurrency
lessActiveFirst :: M.Map Remote Integer -> Remote -> Remote -> Ordering
lessActiveFirst active a b
| Remote.cost a == Remote.cost b = comparing (`M.lookup` active) a b
| otherwise = compare a b
| otherwise = comparing Remote.cost a b

View file

@ -8,6 +8,8 @@ git-annex (6.20180720) UNRELEASED; urgency=medium
* Added --accessedwithin matching option.
* Added annex.commitmessage config that can specify a commit message
for the git-annex branch instead of the usual "update".
* Fix wrong sorting of remotes when using -J, it was sorting by uuid,
rather than cost.
-- Joey Hess <id@joeyh.name> Tue, 31 Jul 2018 12:14:11 -0400

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

View file

@ -0,0 +1,9 @@
[[!comment format=mdwn
username="joey"
subject="""comment 9"""
date="2018-08-03T16:30:35Z"
content="""
The -J2 web bug was not related to caching remotes at all
but was an accidental sort by remote uuid rather than cost.
I've fixed it.
"""]]