Lots of fixes to package version comparisons and repository handling.

Too many fixes to count, but in general a lot of fixes on the sign of
comparisons (flipping less-than for greater-than, and vice versa), as
well as a lot of places where the comparison was reset wrongly.

Also made better verbose messages for package comparisons.

Fixes issue #3314, although a change to the update policy will still
be needed.