From 8dc4c9a46574585af822bca637e5afe9a0fbaaaf Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sun, 7 May 2017 20:33:41 +0000 Subject: [PATCH] list-cvs-files.sh: Add support for -z options Signed-off-by: Jan Lindemann --- make/projects-dir.mk | 6 +++--- scripts/list-cvs-files.sh | 26 ++++++++++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/make/projects-dir.mk b/make/projects-dir.mk index 47063ba9..db99e8c0 100644 --- a/make/projects-dir.mk +++ b/make/projects-dir.mk @@ -249,15 +249,15 @@ clone.done: ssh-wrapper.sh list-files: @for p in $(PROJECTS); do \ - $(LIST_VCS_FILES) -nf $$p | sed "s/^/$$p\//" | \ - xargs realpath --relative-to=. \ + $(LIST_VCS_FILES) -znf $$p | sed -z "s/^/$$p\//" | \ + xargs -0 realpath --relative-to=. ;\ done list-text-files: @make --no-print-directory list-files | xargs file -N | grep ":.*text" | cut -d: -f1 loc-all: - @make --no-print-directory list-text-files \ + @make --no-print-directory list-text-files | \ grep -v "iow-standalone\|jux3\|ntv2/contrib\|\.dia$$\|\.dat\$$\|bootsrap\.css\|mpegplayer/contrib\|gitweb.cgi" | \ xargs wc -l diff --git a/scripts/list-cvs-files.sh b/scripts/list-cvs-files.sh index eb929257..3cf053d2 100644 --- a/scripts/list-cvs-files.sh +++ b/scripts/list-cvs-files.sh @@ -13,6 +13,15 @@ filter_deleted() done } +output() +{ + if [ "$zero_terminate" = 1 ]; then + echo -en "$*\x00" + else + echo "$*" + fi +} + list_dirents_cvs() { local dirs=`sed '/^D\// !d; s%^D/%%; s%/.*%%' $1/CVS/Entries` @@ -26,18 +35,18 @@ list_dirents_cvs() files="`filter_deleted $1/CVS/Entries $files`" local d f for f in $files; do - echo $1/$f + output "$1/$f" done for d in $dirs; do - [ "$opt_only_regular_files" != 1 ] && echo $1/$d + [ "$opt_only_regular_files" = 1 ] || output $1/$d list_dirents_cvs $1/$d done } list_dirents_git() { - git ls-files $1 - [ "$opt_no_submodules" = 1 ] || git submodule foreach 'git ls-files | sed "s|^|$path/|"' + git ls-files $git_ls_files_opts $1 + [ "$opt_no_submodules" = 1 ] || git submodule foreach "git ls-files $git_ls_files_opts | sed 's|^|\$path/|'" } list_dirents() @@ -53,7 +62,7 @@ list_dirents() list_dirents_git $1 } -set -- `getopt fn "$@"` +set -- `getopt fnz "$@"` while [ "$1" != -- ]; do case $1 in @@ -63,6 +72,11 @@ case $1 in -n) opt_no_submodules=1 ;; +-z) + zero_terminate=1 + git_ls_files_opts="$git_ls_files_opts -z" + opt_sort="$opt_sort -z" + ;; esac shift done @@ -71,5 +85,5 @@ shift proj_dir="$1" [ "$proj_dir" ] && cd $proj_dir -list_dirents . | sort +list_dirents . | sort $opt_sort