summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2021-09-27 02:31:11 -0400
committerMike Frysinger <vapier@gentoo.org>2021-09-27 02:31:11 -0400
commit78802b1270bf48bea2e39039877096c4867afbb3 (patch)
tree09d4f47b5771104743c60f7a5836e8c8f522991d
parentomit more spam when in quiet mode (diff)
downloadlocale-gen-78802b1270bf48bea2e39039877096c4867afbb3.tar.gz
locale-gen-78802b1270bf48bea2e39039877096c4867afbb3.tar.bz2
locale-gen-78802b1270bf48bea2e39039877096c4867afbb3.zip
skip duplicate locales when normalized
If you try to generate "en_US.UTF-8 UTF-8" and "en_US.UTF8 UTF-8", we end up generating the locale twice even though it normalizes down to the same value (or, in the case of --update, we skip the 1st and then always generate the 2nd). Keep track of all locales we've processed so we can dedupe as we go. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rwxr-xr-xlocale-gen33
1 files changed, 21 insertions, 12 deletions
diff --git a/locale-gen b/locale-gen
index d313c23..d4417d8 100755
--- a/locale-gen
+++ b/locale-gen
@@ -192,9 +192,9 @@ if [[ -z ${locales_to_generate} ]] && [[ -e ${CONFIG} ]] ; then
fi
fi
-# Transform the name in locales.gen to the name used when storing
-# the locale data in /usr/lib/locale/ ... this normalize algo is
-# taken out of the glibc localedef source code ...
+# Transform the name in locales.gen to the name used when storing the locale data in
+# /usr/lib/locale/. This normalize algo is taken out of the glibc localedef source:
+# https://sourceware.org/git/?p=glibc.git;a=blob;f=locale/programs/localedef.c;hb=glibc-2.34#l562
normalize() {
if [[ $1 == *.* ]] ; then
local ret=$(echo ${1##*.} | tr '[[:upper:]]' '[[:lower:]]')
@@ -316,6 +316,10 @@ JOB_IDX_S=0
JOB_IDX_E=0
cnt=0
lidx=0
+# Keep track of (normalized) locales generated in case the request has different inputs that
+# normalize down to the same value. We trim $existing_locales as we go for later use which
+# prevents its direct use.
+generated_locales=" "
while [[ -n ${locales_to_generate[${lidx}]} ]] ; do
: $(( ++cnt ))
locale=${locales_to_generate[$((lidx++))]}
@@ -334,16 +338,21 @@ while [[ -n ${locales_to_generate[${lidx}]} ]] ; do
disp=${locales_disp[$(( cnt - 1 ))]}
- if [[ -n ${UPDATE} ]] ; then
- normalized_locale=$(normalize ${locale})
- if [[ ${existing_locales} == *" ${normalized_locale} "* ]] ; then
- existing_locales=${existing_locales/ ${normalized_locale} / }
- if [[ ${QUIET} -eq 0 ]] ; then
- cnt_fmt=$(printf "%${#total}i" ${cnt})
- einfo " (${cnt_fmt}/${total}) Skipping ${disp}"
- fi
- continue
+ normalized_locale=$(normalize ${locale})
+ if [[ ${generated_locales} == *" ${normalized_locale} "* ]] ; then
+ already_generated="true"
+ else
+ already_generated="false"
+ fi
+ generated_locales+="${normalized_locale} "
+ if ${already_generated} || \
+ [[ -n ${UPDATE} && ${existing_locales} == *" ${normalized_locale} "* ]] ; then
+ existing_locales=${existing_locales/ ${normalized_locale} / }
+ if [[ ${QUIET} -eq 0 ]] ; then
+ cnt_fmt=$(printf "%${#total}i" ${cnt})
+ einfo " (${cnt_fmt}/${total}) Skipping ${disp}"
fi
+ continue
fi
# If the locale is like 'en_US.UTF8', then we really want 'en_US'