1 |
commit: 78802b1270bf48bea2e39039877096c4867afbb3 |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Sep 27 06:31:11 2021 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Sep 27 06:31:11 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=78802b12 |
7 |
|
8 |
skip duplicate locales when normalized |
9 |
|
10 |
If you try to generate "en_US.UTF-8 UTF-8" and "en_US.UTF8 UTF-8", we |
11 |
end up generating the locale twice even though it normalizes down to |
12 |
the same value (or, in the case of --update, we skip the 1st and then |
13 |
always generate the 2nd). Keep track of all locales we've processed |
14 |
so we can dedupe as we go. |
15 |
|
16 |
Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org> |
17 |
|
18 |
locale-gen | 33 +++++++++++++++++++++------------ |
19 |
1 file changed, 21 insertions(+), 12 deletions(-) |
20 |
|
21 |
diff --git a/locale-gen b/locale-gen |
22 |
index d313c23..d4417d8 100755 |
23 |
--- a/locale-gen |
24 |
+++ b/locale-gen |
25 |
@@ -192,9 +192,9 @@ if [[ -z ${locales_to_generate} ]] && [[ -e ${CONFIG} ]] ; then |
26 |
fi |
27 |
fi |
28 |
|
29 |
-# Transform the name in locales.gen to the name used when storing |
30 |
-# the locale data in /usr/lib/locale/ ... this normalize algo is |
31 |
-# taken out of the glibc localedef source code ... |
32 |
+# Transform the name in locales.gen to the name used when storing the locale data in |
33 |
+# /usr/lib/locale/. This normalize algo is taken out of the glibc localedef source: |
34 |
+# https://sourceware.org/git/?p=glibc.git;a=blob;f=locale/programs/localedef.c;hb=glibc-2.34#l562 |
35 |
normalize() { |
36 |
if [[ $1 == *.* ]] ; then |
37 |
local ret=$(echo ${1##*.} | tr '[[:upper:]]' '[[:lower:]]') |
38 |
@@ -316,6 +316,10 @@ JOB_IDX_S=0 |
39 |
JOB_IDX_E=0 |
40 |
cnt=0 |
41 |
lidx=0 |
42 |
+# Keep track of (normalized) locales generated in case the request has different inputs that |
43 |
+# normalize down to the same value. We trim $existing_locales as we go for later use which |
44 |
+# prevents its direct use. |
45 |
+generated_locales=" " |
46 |
while [[ -n ${locales_to_generate[${lidx}]} ]] ; do |
47 |
: $(( ++cnt )) |
48 |
locale=${locales_to_generate[$((lidx++))]} |
49 |
@@ -334,16 +338,21 @@ while [[ -n ${locales_to_generate[${lidx}]} ]] ; do |
50 |
|
51 |
disp=${locales_disp[$(( cnt - 1 ))]} |
52 |
|
53 |
- if [[ -n ${UPDATE} ]] ; then |
54 |
- normalized_locale=$(normalize ${locale}) |
55 |
- if [[ ${existing_locales} == *" ${normalized_locale} "* ]] ; then |
56 |
- existing_locales=${existing_locales/ ${normalized_locale} / } |
57 |
- if [[ ${QUIET} -eq 0 ]] ; then |
58 |
- cnt_fmt=$(printf "%${#total}i" ${cnt}) |
59 |
- einfo " (${cnt_fmt}/${total}) Skipping ${disp}" |
60 |
- fi |
61 |
- continue |
62 |
+ normalized_locale=$(normalize ${locale}) |
63 |
+ if [[ ${generated_locales} == *" ${normalized_locale} "* ]] ; then |
64 |
+ already_generated="true" |
65 |
+ else |
66 |
+ already_generated="false" |
67 |
+ fi |
68 |
+ generated_locales+="${normalized_locale} " |
69 |
+ if ${already_generated} || \ |
70 |
+ [[ -n ${UPDATE} && ${existing_locales} == *" ${normalized_locale} "* ]] ; then |
71 |
+ existing_locales=${existing_locales/ ${normalized_locale} / } |
72 |
+ if [[ ${QUIET} -eq 0 ]] ; then |
73 |
+ cnt_fmt=$(printf "%${#total}i" ${cnt}) |
74 |
+ einfo " (${cnt_fmt}/${total}) Skipping ${disp}" |
75 |
fi |
76 |
+ continue |
77 |
fi |
78 |
|
79 |
# If the locale is like 'en_US.UTF8', then we really want 'en_US' |