From 8d66590157763d4491f85fd2eaeb9da59465d5e8 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 29 Oct 2014 09:59:57 +0100
Subject: [PATCH] xbps: merge patch from master to fix xbps-query --fulldeptree
 with some pkgs.

---
 srcpkgs/xbps-static/template                  | 11 +--
 ...ulldeptree-with-multiple-pkgs-using-.patch | 85 +++++++++++++++++++
 srcpkgs/xbps/template                         | 19 ++---
 3 files changed, 94 insertions(+), 21 deletions(-)
 create mode 100644 srcpkgs/xbps/patches/0004-xbps-query-fix-fulldeptree-with-multiple-pkgs-using-.patch

diff --git a/srcpkgs/xbps-static/template b/srcpkgs/xbps-static/template
index 5f24f1f8d08..19fec0c7305 100644
--- a/srcpkgs/xbps-static/template
+++ b/srcpkgs/xbps-static/template
@@ -3,12 +3,15 @@
 # NOTE: keep this package synchronized with "srcpkgs/xbps".
 pkgname=xbps-static
 version=0.41
-revision=3
+revision=5
 bootstrap=yes
+build_style=configure
 short_desc="The XBPS package system utilities - static binaries"
 maintainer="Juan RP <xtraeme@gmail.com>"
 homepage="http://www.voidlinux.eu/xbps"
 license="Simplified BSD"
+distfiles="https://github.com/voidlinux/xbps/archive/${version}.tar.gz"
+checksum=e9d7d9a50e549be7069d328277dfae466acf53cbda59ef99eae7bbe9a096ee76
 hostmakedepends="which pkg-config git"
 makedepends="zlib-devel libressl-devel libarchive-devel>=3.1.2"
 depends="xbps-triggers"
@@ -19,15 +22,9 @@ case "$XBPS_TARGET_MACHINE" in
 	i686-musl) CFLAGS+=" -fno-stack-protector";;
 esac
 
-do_fetch() {
-	git clone -b${version} git://github.com/voidlinux/xbps.git ${pkgname}-${version}
-}
 do_configure() {
 	HAVE_VASPRINTF=1 ./configure --prefix=/usr --sysconfdir=/etc --enable-static --enable-debug
 }
-do_build() {
-	make ${makejobs}
-}
 do_install() {
 	make DESTDIR=${wrksrc}/static-install install
 	vmkdir usr/sbin
diff --git a/srcpkgs/xbps/patches/0004-xbps-query-fix-fulldeptree-with-multiple-pkgs-using-.patch b/srcpkgs/xbps/patches/0004-xbps-query-fix-fulldeptree-with-multiple-pkgs-using-.patch
new file mode 100644
index 00000000000..6259ee4ac57
--- /dev/null
+++ b/srcpkgs/xbps/patches/0004-xbps-query-fix-fulldeptree-with-multiple-pkgs-using-.patch
@@ -0,0 +1,85 @@
+commit 15943d990caf40a77c255ee5bc7e7935ebf0673d
+Author: Juan RP <xtraeme@gmail.com>
+Date:   Wed Oct 29 09:46:54 2014 +0100
+
+    xbps-query: fix --fulldeptree with multiple pkgs using vpkgs and non vpkgs.
+
+--- bin/xbps-query/show-deps.c	2014-09-29 15:54:15.000000000 +0200
++++ bin/xbps-query/show-deps.c	2014-10-29 09:56:03.142653297 +0100
+@@ -43,6 +43,8 @@ struct pkgdep {
+ static SLIST_HEAD(pkgdep_head, pkgdep) pkgdep_list =
+     SLIST_HEAD_INITIALIZER(pkgdep_list);
+ 
++static xbps_dictionary_t pkgdep_pvmap;
++
+ static void
+ print_rdeps(struct xbps_handle *xhp, xbps_array_t rdeps, bool full, bool repo)
+ {
+@@ -53,7 +55,6 @@ print_rdeps(struct xbps_handle *xhp, xbp
+ 	for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
+ 		struct pkgdep *pd;
+ 		const char *pkgver;
+-		char *vpkg;
+ 		bool virtual = false, found = false;
+ 
+ 		xbps_array_get_cstring_nocopy(rdeps, i, &curdep);
+@@ -83,16 +84,15 @@ print_rdeps(struct xbps_handle *xhp, xbp
+ 				p = xbps_pkg_name(curdep);
+ 
+ 			assert(p);
+-			vpkg = xbps_xasprintf("%s-%s", p, xbps_pkg_version(pkgver));
+-			assert(vpkg);
++			if (pkgdep_pvmap == NULL)
++				pkgdep_pvmap = xbps_dictionary_create();
++
++			xbps_dictionary_set_cstring_nocopy(pkgdep_pvmap, p, pkgver);
+ 			free(p);
+ 		}
+ 		/* uniquify dependencies, sorting will be done later */
+ 		SLIST_FOREACH(pd, &pkgdep_list, pkgdep_entries) {
+-			if (virtual && strcmp(pd->pkg, vpkg) == 0) {
+-				found = true;
+-				break;
+-			} else if (strcmp(pd->pkg, pkgver) == 0) {
++			if (strcmp(pd->pkg, pkgver) == 0) {
+ 				found = true;
+ 				break;
+ 			}
+@@ -100,11 +100,7 @@ print_rdeps(struct xbps_handle *xhp, xbp
+ 		if (!found) {
+ 			pd = malloc(sizeof(*pd));
+ 			assert(pd);
+-			if (virtual)
+-				pd->pkg = vpkg;
+-			else
+ 				pd->pkg = pkgver;
+-
+ 			pd->rdeps = xbps_array_copy(currdeps);
+ 			SLIST_INSERT_HEAD(&pkgdep_list, pd, pkgdep_entries);
+ 			//printf("Added %s into the slist\n", pd->pkg);
+@@ -143,13 +139,21 @@ sort_rdeps(void)
+ 				char *pkgname;
+ 
+ 				xbps_array_get_cstring_nocopy(pd->rdeps, i, &pkgdep);
+-				pkgname = xbps_pkgpattern_name(pkgdep);
+-				if (pkgname == NULL)
++				if ((pkgname = xbps_pkgpattern_name(pkgdep)) == NULL)
+ 					pkgname = xbps_pkg_name(pkgdep);
+ 
+-				if (xbps_match_pkgname_in_array(result, pkgname))
++				assert(pkgname);
++				if (xbps_match_pkgname_in_array(result, pkgname)) {
+ 					mdeps++;
+-
++					free(pkgname);
++					continue;
++				}
++				if (xbps_dictionary_get(pkgdep_pvmap, pkgname)) {
++					mdeps++;
++					free(pkgname);
++					continue;
++				}
++				//printf("%s: missing dep %s\n", pd->pkg, pkgdep);
+ 				free(pkgname);
+ 			}
+ 			if (mdeps == rdeps) {
diff --git a/srcpkgs/xbps/template b/srcpkgs/xbps/template
index 2577e351028..e36179a4965 100644
--- a/srcpkgs/xbps/template
+++ b/srcpkgs/xbps/template
@@ -1,12 +1,15 @@
 # Template file for 'xbps'
 pkgname=xbps
 version=0.41
-revision=4
+revision=5
 bootstrap=yes
+build_style=configure
 short_desc="The XBPS package system utilities"
 maintainer="Juan RP <xtraeme@gmail.com>"
 homepage="http://www.voidlinux.eu/xbps"
 license="Simplified BSD"
+distfiles="https://github.com/voidlinux/xbps/archive/${version}.tar.gz"
+checksum=e9d7d9a50e549be7069d328277dfae466acf53cbda59ef99eae7bbe9a096ee76
 
 makedepends="zlib-devel libressl-devel libarchive-devel>=3.1.2"
 depends="xbps-triggers>=0.75"
@@ -16,7 +19,7 @@ if [ -z "$CHROOT_READY" ]; then
 	CFLAGS+=" -idirafter ${XBPS_MASTERDIR}/usr/include"
 	LDFLAGS+=" -L${XBPS_MASTERDIR}/usr/lib"
 else
-	hostmakedepends="pkg-config git"
+	hostmakedepends="pkg-config"
 	makedepends+=" atf-devel>=0.21"
 
 	xbps-tests_package() {
@@ -33,10 +36,6 @@ if [ "$XBPS_TARGET_MACHINE" = "i686-musl" ]; then
 	CFLAGS+=" -fno-stack-protector"
 fi
 
-do_fetch() {
-	git clone -b${version} git://github.com/voidlinux/xbps.git xbps-${version}
-}
-
 do_configure() {
 	if [ "$CHROOT_READY" ]; then
 		_args="--enable-tests"
@@ -44,14 +43,6 @@ do_configure() {
 	HAVE_VASPRINTF=1 ./configure --prefix=/usr --sysconfdir=/etc --enable-debug ${_args}
 }
 
-do_build() {
-	make ${makejobs}
-}
-
-do_install() {
-	make DESTDIR=${DESTDIR} install
-}
-
 libxbps_package() {
 	short_desc+=" - runtime library"
 	pkg_install() {