vc-list-files 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/sh
  2. # List version-controlled file names.
  3. # Print a version string.
  4. scriptversion=2010-04-23.22; # UTC
  5. # Copyright (C) 2006-2011 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 <http://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: http://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 <http://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. dir=
  50. case $# in
  51. 0) ;;
  52. 1) dir=$1 ;;
  53. *) echo "$0: too many arguments" 1>&2
  54. echo "Usage: $0 [-C srcdir] [DIR]" 1>&2; exit 1;;
  55. esac
  56. test "x$dir" = x && dir=.
  57. if test -d .git; then
  58. test "x$dir" = x. \
  59. && dir= sed_esc= \
  60. || { dir="$dir/"; sed_esc=`echo "$dir"|env sed 's,\([\\/]\),\\\\\1,g'`; }
  61. # Ignore git symlinks - either they point into the tree, in which case
  62. # we don't need to visit the target twice, or they point somewhere
  63. # else (often into a submodule), in which case the content does not
  64. # belong to this package.
  65. eval exec git ls-tree -r 'HEAD:"$dir"' \
  66. \| sed -n '"s/^100[^ ]*./$sed_esc/p"' $postprocess
  67. elif test -d .hg; then
  68. eval exec hg locate '"$dir/*"' $postprocess
  69. elif test -d .bzr; then
  70. test "$postprocess" = '' && postprocess="| sed 's|^\./||'"
  71. eval exec bzr ls -R --versioned '"$dir"' $postprocess
  72. elif test -d CVS; then
  73. test "$postprocess" = '' && postprocess="| sed 's|^\./||'"
  74. if test -x build-aux/cvsu; then
  75. eval build-aux/cvsu --find --types=AFGM '"$dir"' $postprocess
  76. elif (cvsu --help) >/dev/null 2>&1; then
  77. eval cvsu --find --types=AFGM '"$dir"' $postprocess
  78. else
  79. eval awk -F/ \''{ \
  80. if (!$1 && $3 !~ /^-/) { \
  81. f=FILENAME; \
  82. if (f ~ /CVS\/Entries$/) \
  83. f = substr(f, 1, length(f)-11); \
  84. print f $2; \
  85. }}'\'' \
  86. `find "$dir" -name Entries -print` /dev/null' $postprocess
  87. fi
  88. elif test -d .svn; then
  89. eval exec svn list -R '"$dir"' $postprocess
  90. else
  91. echo "$0: Failed to determine type of version control used in `pwd`" 1>&2
  92. exit 1
  93. fi
  94. # Local variables:
  95. # eval: (add-hook 'write-file-hooks 'time-stamp)
  96. # time-stamp-start: "scriptversion="
  97. # time-stamp-format: "%:y-%02m-%02d.%02H"
  98. # time-stamp-time-zone: "UTC"
  99. # time-stamp-end: "; # UTC"
  100. # End: