Subject: Re: Proposal: Sort order for MASTER_SITES
To: None <tech-pkg@netbsd.org>
From: Martin J. Laubach <mjl@emsi.priv.at>
List: tech-pkg
Date: 06/19/1999 23:47:47
  Okay, so here is the reworked patch that incorporates Hubert's
idea of having a "simple format".

  We now have two variables MASTER_SORT and MASTER_SORT_REGEX.
The first is internally transformed into regexps that match in
the hostname part. Of course the real power user can still
write his preferences in regexps by using the second variable :)

	mjl



Index: bsd.pkg.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.pkg.mk,v
retrieving revision 1.282
diff -a -b -u -r1.282 bsd.pkg.mk
--- bsd.pkg.mk	1999/06/14 01:56:52	1.282
+++ bsd.pkg.mk	1999/06/19 21:41:47
@@ -836,11 +836,27 @@
 		exit 1;							\
 	fi
 
+#
+# Sort the master site list according to the patterns in MASTER_SORT
+#
+MASTER_SORT= .at.netbsd.org .ac.at .at .de
+
+MASTER_SORT?=
+MASTER_SORT_REGEX?=
+MASTER_SORT_REGEX+= ${MASTER_SORT:S/./\\./g:C/.*/:\/\/.*&\//}
+
+MASTER_SORT_AWK= BEGIN { RS = " "; ORS = " "; IGNORECASE = 1 ; gl = "${MASTER_SORT_REGEX}"; }
+.for srt in ${MASTER_SORT_REGEX}
+MASTER_SORT_AWK+= /${srt:C/\//\\\//g}/ { good["${srt}"] = good["${srt}"] " " $$0 ; next; } 
+.endfor
+MASTER_SORT_AWK+= { rest = rest " " $$0; } END { n=split(gl, gla); for(i=1;i<=n;i++) { print good[gla[i]]; } print rest; } 
+SORTED_MASTER_SITES!= echo '${MASTER_SITES}' | awk '${MASTER_SORT_AWK}'
+
 .if !target(do-fetch)
 do-fetch:
 	${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${_DISTDIR}
 	${_PKG_SILENT}(${_PKG_DEBUG}cd ${_DISTDIR};			\
-	 sites="${MASTER_SITES}";					\
+	 sites="${SORTED_MASTER_SITES}";				\
 	 for file in "" ${_DISTFILES}; do				\
 		if [ "X$$file" = X"" ]; then continue; fi;		\
 		${_FETCH_FILE}						\