vc-list-files 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/sh
  2. # List version-controlled file names.
  3. # Print a version string.
  4. scriptversion=2018-03-07.03; # UTC
  5. # Copyright (C) 2006-2023 Free Software Foundation, Inc.
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. # List the specified version-controlled files.
  17. # With no argument, list them all. With a single DIRECTORY argument,
  18. # list the version-controlled files in that directory.
  19. # If there's an argument, it must be a single, "."-relative directory name.
  20. # cvsu is part of the cvsutils package: https://www.red-bean.com/cvsutils/
  21. postprocess=
  22. case $1 in
  23. --help) cat <<EOF
  24. Usage: $0 [-C SRCDIR] [DIR...]
  25. Output a list of version-controlled files in DIR (default .), relative to
  26. SRCDIR (default .). SRCDIR must be the top directory of a checkout.
  27. Options:
  28. --help print this help, then exit
  29. --version print version number, then exit
  30. -C SRCDIR change directory to SRCDIR before generating list
  31. Report bugs and patches to <bug-gnulib@gnu.org>.
  32. EOF
  33. exit ;;
  34. --version)
  35. year=`echo "$scriptversion" | sed 's/[^0-9].*//'`
  36. cat <<EOF
  37. vc-list-files $scriptversion
  38. Copyright (C) $year Free Software Foundation, Inc,
  39. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
  40. This is free software: you are free to change and redistribute it.
  41. There is NO WARRANTY, to the extent permitted by law.
  42. EOF
  43. exit ;;
  44. -C)
  45. test "$2" = . || postprocess="| sed 's|^|$2/|'"
  46. cd "$2" || exit 1
  47. shift; shift ;;
  48. esac
  49. test $# = 0 && set .
  50. for dir
  51. do
  52. if test -d .git || test -f .git; then
  53. test "x$dir" = x. \
  54. && dir= sed_esc= \
  55. || { dir="$dir/"; sed_esc=`echo "$dir"|env sed 's,\([\\/]\),\\\\\1,g'`; }
  56. # Ignore git symlinks - either they point into the tree, in which case
  57. # we don't need to visit the target twice, or they point somewhere
  58. # else (often into a submodule), in which case the content does not
  59. # belong to this package.
  60. eval exec git ls-tree -r 'HEAD:"$dir"' \
  61. \| sed -n '"s/^100[^ ]*./$sed_esc/p"' $postprocess
  62. elif test -d .hg; then
  63. eval exec hg locate '"$dir/*"' $postprocess
  64. elif test -d .bzr; then
  65. test "$postprocess" = '' && postprocess="| sed 's|^\./||'"
  66. eval exec bzr ls -R --versioned '"$dir"' $postprocess
  67. elif test -d CVS; then
  68. test "$postprocess" = '' && postprocess="| sed 's|^\./||'"
  69. if test -x build-aux/cvsu; then
  70. eval build-aux/cvsu --find --types=AFGM '"$dir"' $postprocess
  71. elif (cvsu --help) >/dev/null 2>&1; then
  72. eval cvsu --find --types=AFGM '"$dir"' $postprocess
  73. else
  74. eval awk -F/ \''{ \
  75. if (!$1 && $3 !~ /^-/) { \
  76. f=FILENAME; \
  77. if (f ~ /CVS\/Entries$/) \
  78. f = substr(f, 1, length(f)-11); \
  79. print f $2; \
  80. }}'\'' \
  81. `find "$dir" -name Entries -print` /dev/null' $postprocess
  82. fi
  83. elif test -d .svn; then
  84. eval exec svn list -R '"$dir"' $postprocess
  85. else
  86. echo "$0: Failed to determine type of version control used in `pwd`" 1>&2
  87. exit 1
  88. fi
  89. done
  90. # Local variables:
  91. # eval: (add-hook 'before-save-hook 'time-stamp)
  92. # time-stamp-start: "scriptversion="
  93. # time-stamp-format: "%:y-%02m-%02d.%02H"
  94. # time-stamp-time-zone: "UTC0"
  95. # time-stamp-end: "; # UTC"
  96. # End: