From 7cec799c5ab4f3648ecfb03a3660cf0bbb1fb615 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@voidlinux.eu>
Date: Mon, 27 Jul 2015 09:49:58 +0200
Subject: [PATCH] xbps{,-static}: patch from git to fix an endless loop in
 xbps-checkvers(1).

---
 srcpkgs/xbps-static/patches                   |  1 +
 srcpkgs/xbps-static/template                  |  6 +-
 ...ixed-an-endless-loop-with-reverts-co.patch | 75 +++++++++++++++++++
 srcpkgs/xbps/template                         |  6 +-
 4 files changed, 82 insertions(+), 6 deletions(-)
 create mode 120000 srcpkgs/xbps-static/patches
 create mode 100644 srcpkgs/xbps/patches/0001-xbps-checkvers-fixed-an-endless-loop-with-reverts-co.patch

diff --git a/srcpkgs/xbps-static/patches b/srcpkgs/xbps-static/patches
new file mode 120000
index 00000000000..5bdbe051140
--- /dev/null
+++ b/srcpkgs/xbps-static/patches
@@ -0,0 +1 @@
+../xbps/patches
\ No newline at end of file
diff --git a/srcpkgs/xbps-static/template b/srcpkgs/xbps-static/template
index 4e901d10ce2..a89a3ca720c 100644
--- a/srcpkgs/xbps-static/template
+++ b/srcpkgs/xbps-static/template
@@ -3,12 +3,14 @@
 # NOTE: keep this package synchronized with "srcpkgs/xbps".
 pkgname=xbps-static
 version=0.47
-revision=1
+revision=2
 build_style=configure
 short_desc="The XBPS package system utilities - static binaries"
 maintainer="Juan RP <xtraeme@voidlinux.eu>"
 homepage="http://www.voidlinux.eu/xbps"
 license="2-clause-BSD"
+distfiles="https://github.com/voidlinux/xbps/archive/$version.tar.gz"
+checksum=34d8b69c006330426fcd00240f7d53425c5581d0635e18f7dfef55e1f7a917d2
 
 wrksrc="xbps-${version}"
 hostmakedepends="pkg-config"
@@ -16,8 +18,6 @@ makedepends="zlib-devel libressl-devel libarchive-devel"
 depends="xbps-triggers"
 
 only_for_archs="i686-musl x86_64-musl mips-musl mipsel-musl armv6l-musl armv7l-musl aarch64-musl"
-distfiles="https://github.com/voidlinux/xbps/archive/$version.tar.gz"
-checksum=34d8b69c006330426fcd00240f7d53425c5581d0635e18f7dfef55e1f7a917d2
 
 do_configure() {
 	HAVE_VASPRINTF=1 ./configure --prefix=/usr --sysconfdir=/etc --enable-static --enable-debug
diff --git a/srcpkgs/xbps/patches/0001-xbps-checkvers-fixed-an-endless-loop-with-reverts-co.patch b/srcpkgs/xbps/patches/0001-xbps-checkvers-fixed-an-endless-loop-with-reverts-co.patch
new file mode 100644
index 00000000000..4c4a07be016
--- /dev/null
+++ b/srcpkgs/xbps/patches/0001-xbps-checkvers-fixed-an-endless-loop-with-reverts-co.patch
@@ -0,0 +1,75 @@
+From 0d5385ad2b7873746b91526e4b19c783584359c2 Mon Sep 17 00:00:00 2001
+From: Juan RP <xtraeme@voidlinux.eu>
+Date: Mon, 27 Jul 2015 09:44:25 +0200
+Subject: [PATCH] xbps-checkvers: fixed an endless loop with "reverts"
+ containing extra alphanumeric chars.
+
+---
+ NEWS                                   |  4 ++++
+ bin/xbps-checkvers/main.c              |  2 +-
+ tests/xbps/xbps-checkvers/checkvers.sh | 31 +++++++++++++++++++++++++++++++
+ 3 files changed, 36 insertions(+), 1 deletion(-)
+
+diff --git a/bin/xbps-checkvers/main.c b/bin/xbps-checkvers/main.c
+index d74a157..896053c 100644
+--- bin/xbps-checkvers/main.c
++++ bin/xbps-checkvers/main.c
+@@ -533,7 +533,7 @@ check_reverts(const char *repover, const map_item_t reverts)
+ 		 * Check if it's the first character or the previous character is a
+ 		 * whitespace.
+ 		 */
+-		if (p > sreverts && !isspace(p[-1]))
++		if (p > sreverts && !isalpha(p[-1]) && !isspace(p[-1]))
+ 			continue;
+ 		p += strlen(repover);
+ 		/*
+diff --git a/tests/xbps/xbps-checkvers/checkvers.sh b/tests/xbps/xbps-checkvers/checkvers.sh
+index 4b834e3..b6d3be2 100755
+--- tests/xbps/xbps-checkvers/checkvers.sh
++++ tests/xbps/xbps-checkvers/checkvers.sh
+@@ -301,6 +301,36 @@ EOF
+ 	atf_check_equal "$out" "pkgname: A repover: 1.1_1 srcpkgver: 1.0_1"
+ }
+ 
++atf_test_case reverts_alpha
++
++reverts_alpha_head() {
++	atf_set "descr" "xbps-checkvers(8): test with reverts containing an alphanumeric character"
++}
++
++reverts_alpha_body() {
++	mkdir -p some_repo pkg_A void-packages/srcpkgs/fs-utils
++	touch pkg_A/file00
++	cat > void-packages/srcpkgs/fs-utils/template <<EOF
++pkgname=fs-utils
++reverts=v1.10_1
++version=1.10
++revision=1
++do_install() {
++	:
++}
++EOF
++	cd some_repo
++	xbps-create -A noarch -n fs-utils-1.10_1 -s "A pkg" ../pkg_A
++	atf_check_equal $? 0
++	xbps-rindex -d -a $PWD/*.xbps
++	atf_check_equal $? 0
++	cd ..
++	xbps-checkvers -R $PWD/some_repo -D $PWD/void-packages
++	out=`xbps-checkvers -R $PWD/some_repo -D $PWD/void-packages`
++	atf_check_equal $? 0
++	atf_check_equal "$out" "pkgname: fs-utils repover: 1.10_1 srcpkgver: 1.10_1"
++}
++
+ atf_init_test_cases() {
+ 	atf_add_test_case srcpkg_newer
+ 	atf_add_test_case srcpkg_newer_with_refs
+@@ -313,4 +343,5 @@ atf_init_test_cases() {
+ 	atf_add_test_case srcpkg_missing_pkgver
+ 	atf_add_test_case srcpkg_missing_pkgverrev
+ 	atf_add_test_case reverts
++	atf_add_test_case reverts_alpha
+ }
+-- 
+2.4.6
+
diff --git a/srcpkgs/xbps/template b/srcpkgs/xbps/template
index 91c176360b6..1bc2b446a91 100644
--- a/srcpkgs/xbps/template
+++ b/srcpkgs/xbps/template
@@ -1,13 +1,15 @@
 # Template file for 'xbps'
 pkgname=xbps
 version=0.47
-revision=1
+revision=2
 bootstrap=yes
 build_style=configure
 short_desc="The XBPS package system utilities"
 maintainer="Juan RP <xtraeme@voidlinux.eu>"
 homepage="https://github.com/voidlinux/xbps"
 license="2-clause-BSD"
+distfiles="https://github.com/voidlinux/xbps/archive/$version.tar.gz"
+checksum=34d8b69c006330426fcd00240f7d53425c5581d0635e18f7dfef55e1f7a917d2
 
 hostmakedepends="pkg-config"
 makedepends="zlib-devel libressl-devel libarchive-devel"
@@ -23,8 +25,6 @@ if [ "$CHROOT_READY" ]; then
 	}
 
 fi
-distfiles="https://github.com/voidlinux/xbps/archive/$version.tar.gz"
-checksum=34d8b69c006330426fcd00240f7d53425c5581d0635e18f7dfef55e1f7a917d2
 
 do_configure() {
 	CFLAGS+=" -Wno-error=redundant-decls"