]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - po/update-potfiles
scriptreplay: check for EOF
[thirdparty/util-linux.git] / po / update-potfiles
index fe957f87e00e38187dfd5727cd07c5758c8419c0..1cbfdc4705294134c425d95d84c0bb40e560647c 100755 (executable)
@@ -3,17 +3,41 @@
 # Copyright (C) 2009 Karel Zak <kzak@redhat.com>
 #
 
-# find all *.c files, 
+# find all git-tracked and existing *.c and *.h files
+# exclude some (sub)directories
 # sort the list
-# exclude /samples/ subdirectories
-# exclude ./tests/ from the list 
-#         and remove "./" prefix
 
-[ ! -f "po/Makevars" ] && \
-       echo "You must run this script in the top-level directory"
+if [ ! -f "po/Makevars" ]; then
+       echo "error: update-potfiles must run in the top-level directory" >&2
+       exit 1
+fi
 
-find -name "*.c" -or -name "*.h" | \
-  sort | \
-  sed ':/samples/:d' | \
-  gawk '! /^\.\/tests\// { print gensub(/^\.\//, "", 1) }' \
-  > po/POTFILES.in
+# find all git-tracked files
+source_files=$(git ls-files . 2>/dev/null)
+if [ $? -ne 0 ] || [ -z "$source_files" ]; then
+       # we still go through the rest of this script to provide at least an empty
+       # list or remove non-existing (deleted) files
+       source_files=$(cat po/POTFILES.in 2>/dev/null)
+fi
+if [ $? -ne 0 ] || [ -z "$source_files" ]; then
+       source_files=$(find . -type f -printf "%P\\n" 2>/dev/null)
+fi
+
+# apply include/exclude patterns
+source_files=$(
+       echo "$source_files" \
+       | sed \
+               -e '/\(\.h\|\.c\)$/!d' \
+               -e '/^tests\//d' \
+               -e '/\/samples\//d' \
+               -e '/^Documentation\//d' \
+)
+
+# throw away non-existing files (dirty git repo)
+echo "$source_files" \
+       | xargs -r find 2>/dev/null \
+       | sort \
+       > po/POTFILES.in
+
+# if this script is broken then we have probably an empty list
+[ -s po/POTFILES.in ] || echo "$0: warning: po/POTFILES.in is empty" >&2