smira/aptly — pull request #70 by simonaquino (2014-06-27 02:18:13+00:00)
Title: Pulling all matching packages from a snapshot

When performing an *aptly snapshot pull*, users might list dependency
versions that can potentially match multiple packages in the source snapshot. However,
the current implementation of the 'snapshot pull' command only allows one package
to be pulled from a snapshot at a time for a given dependency.

The newly implemented all-matches flag allows users to pull all the
matching packages from a source snapshot, provided that they satisfy the
version requirements indicated by the dependencies.

The all-matches flag defaults to false and only produces the described
behaviour when it is explicitly set to true.

For example, I created a *source_snap* snapshot from a *sensu* mirror:
```
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
...
```
The **current behaviour** of *aptly snapshot pull* is shown below.
Only one package satisfying dependency *sensu > 0.11* is added to *dest_snap*.
```
root@sim-tst-lb1:~# aptly snapshot pull -architectures=amd64 --dry-run empty sensu-snap dest_snap 'sensu (> 0.11)'
Dependencies would be pulled into snapshot:
[empty]: Created as empty
from snapshot:
[sensu-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.12.1-1_amd64 added

Not creating snapshot, as dry run was requested.
```

The **proposed** *all-matches* flag **behaviour** is shown below.
All the packages that satisfy dependency *sensu > 0.11* are added to *dest_snap*.
```
root@sim-tst-lb1:~# aptly snapshot pull -architectures=amd64 --all-matches --dry-run empty sensu-snap dest_snap 'sensu (> 0.11)'
Dependencies would be pulled into snapshot:
[empty]: Created as empty
from snapshot:
[sensu-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.beta.3-1_amd64 added
[+] sensu_0.11.0.beta.2-1_amd64 added
[+] sensu_0.11.3-1_amd64 added
[+] sensu_0.11.0-1_amd64 added
[+] sensu_0.11.0.beta.4-1_amd64 added
[+] sensu_0.11.0.beta.1-1_amd64 added
[+] sensu_0.12.0-1_amd64 added
[+] sensu_0.12.3-1_amd64 added
[+] sensu_0.11.1-1_amd64 added
[+] sensu_0.12.1-1_amd64 added
[+] sensu_0.12.4-1_amd64 added
[+] sensu_0.12.6-4_amd64 added
[+] sensu_0.12.2-1_amd64 added
[+] sensu_0.12.6-5_amd64 added
[+] sensu_0.12.5-1_amd64 added
[+] sensu_0.12.6-2_amd64 added
[+] sensu_0.12.6-3_amd64 added
[+] sensu_0.12.6-1_amd64 added
[+] sensu_0.11.0.beta-1_amd64 added

Not creating snapshot, as dry run was requested.
```
When the dependency listed is:
* equal to a set version, for example *(= 0.11)*
**and**
* the *all-matches* flag is set to *true*

under the proposed changes aptly returns all the versions between *0.11* and *0.12* (effectively 0.11.*):
```
root@sim-tst-lb1:~# aptly snapshot pull -architectures=amd64 --all-matches --dry-run empty sensu-snap dest_snap 'sensu (= 0.11)'
Dependencies would be pulled into snapshot:
[empty]: Created as empty
from snapshot:
[sensu-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.beta.4-1_amd64 added
[+] sensu_0.11.0.beta.1-1_amd64 added
[+] sensu_0.11.0.beta.2-1_amd64 added
[+] sensu_0.11.1-1_amd64 added
[+] sensu_0.11.0.beta-1_amd64 added
[+] sensu_0.11.0.beta.3-1_amd64 added
[+] sensu_0.11.0-1_amd64 added
[+] sensu_0.11.3-1_amd64 added

Not creating snapshot, as dry run was requested.
```