smira/aptly — pull request #67 by simonaquino (2014-06-13 12:52:58+00:00)
Title: Deterministic PackageList search

We have noticed non-deterministic behaviour when pulling a package without specifying a version from a snapshot.
In fact, we would expect to always pull the latest version of a package, but what we were seeing was that a random version was being chosen instead.

For example, we created a *sensu* mirror and created a snapshot *source_snap* from it:
```
root@sim-tst-lb1:~# aptly mirror create sensu http://repos.sensuapp.org/apt sensu
...
root@sim-tst-lb1:~# aptly mirror update sensu
...
root@sim-tst-lb1:~# aptly snapshot create source_snap from mirror sensu
...
root@sim-tst-lb1:~# aptly snapshot create empty empty
...
root@sim-tst-lb1:~# aptly snapshot pull --dry-run -architectures=amd64 empty source_snap dest_snap 'sensu'
Dependencies would be pulled into snapshot:
[empty]: Created as empty
from snapshot:
[source_snap]: Snapshot from mirror [sensu]: http://repos.sensuapp.org/apt/ sensu
and result would be saved as new snapshot dest_snap.
Loading packages (154)...
Building indexes...
[+] sensu_0.11.0-1_amd64 added

Not creating snapshot, as dry run was requested.
root@sim-tst-lb1:~# aptly snapshot pull --dry-run -architectures=amd64 empty source_snap dest_snap 'sensu'
Dependencies would be pulled into snapshot:
[empty]: Created as empty
from snapshot:
[source_snap]: Snapshot from mirror [sensu]: http://repos.sensuapp.org/apt/ sensu
and result would be saved as new snapshot dest_snap.
Loading packages (154)...
Building indexes...
[+] sensu_0.9.12.beta.5-2_amd64 added

Not creating snapshot, as dry run was requested.
root@sim-tst-lb1:~# aptly snapshot pull --dry-run -architectures=amd64 empty source_snap dest_snap 'sensu'
Dependencies would be pulled into snapshot:
[empty]: Created as empty
from snapshot:
[source_snap]: Snapshot from mirror [sensu]: http://repos.sensuapp.org/apt/ sensu
and result would be saved as new snapshot dest_snap.
Loading packages (154)...
Building indexes...
[+] sensu_0.9.9.beta.3-1_amd64 added
```

Whenever we pull the *sensu* package from *source_snap*, aptly returns a random version of it.

The changes we have made to the code order the PackageList by version (latest first) as well as name so that the search function returns a consistent result.