makechrootpkg -I a package with multiple-choice dependencies leads to an endless loop

(Originally reported at https://bugs.archlinux.org/task/64265)

Description:

In makechrootpkg -I foo.pkg.tar.xz, if foo depends on something that can be provided by multiple packages (e.g., ttf-font), then the whole stuff ends up in a endless loop:

Enter a number (default=1): error: invalid number: y

Enter a number (default=1): error: invalid number: y

...

Additional info: extra/devtools 20191016-1

The relevant commit is b7893a2c

Steps to reproduce:

Create two PKGBUILDs:

# foo/PKGBUILD
pkgname=foo
pkgver=0.1
pkgrel=1
arch=(any)
depends=(ttf-font)

package() {
  true
}
# bar/PKGBUILD
pkgname=bar
pkgver=0.1
pkgrel=1
arch=(any)
depends=(foo)

package() {
  true
}

Then build foo and bar:

$ pushd foo && extra-x86_64-build && popd
$ pushd bar && extra-x86_64-build -- -I ../foo/foo-0.1-1-any.pkg.tar.xz

A real-life reproducer is the python-pytorch-lightning at archlinuxcn, which is built with:

archlinuxcn-x86_64-build -- -I ../python-av/python-av-6.2.0-2-x86_64.pkg.tar.xz -I ../python-torchvision/python-torchvision-0.4.0-4-x86_64.pkg.tar.xz

The first package, python-av, depends on ffmpeg, which depends on libjpeg indirectly, and there is another package mozjpeg in [archlinuxcn] that also provides libjpeg.