vc-list-files 3.2 KB
Newer Older
1
#!/bin/sh
2
# List version-controlled file names.
3

J
Jim Meyering 已提交
4
# Print a version string.
5
scriptversion=2008-05-01.10
J
Jim Meyering 已提交
6

7
# Copyright (C) 2006-2008 Free Software Foundation, Inc.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


# List the specified version-controlled files.
24 25
# With no argument, list them all.  With a single DIRECTORY argument,
# list the version-controlled files in that directory.
26 27 28 29

# If there's an argument, it must be a single, "."-relative directory name.
# cvsu is part of the cvsutils package: http://www.red-bean.com/cvsutils/

J
Jim Meyering 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
postprocess=
case $1 in
  --help) cat <<EOF
Usage: $0 [-C SRCDIR] [DIR]

Output a list of version-controlled files in DIR (default .), relative to
SRCDIR (default .).  SRCDIR must be the top directory of a checkout.

Options:
  --help     print this help, then exit
  --version  print version number, then exit
  -C SRCDIR  change directory to SRCDIR before generating list

Report bugs and patches to <bug-gnulib@gnu.org>.
EOF
    exit ;;

  --version)
    year=`echo "$scriptversion" | sed 's/[^0-9].*//'`
    cat <<EOF
vc-list-files $scriptversion
Copyright (C) $year Free Software Foundation, Inc,
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
EOF
    exit ;;

  -C)
    test "$2" = . || postprocess="| sed 's|^|$2/|'"
    cd "$2" || exit 1
    shift; shift ;;
esac

64 65 66 67
dir=
case $# in
  0) ;;
  1) dir=$1 ;;
68
  *) echo "$0: too many arguments" 1>&2
J
Jim Meyering 已提交
69
     echo "Usage: $0 [-C srcdir] [DIR]" 1>&2; exit 1;;
70 71 72 73
esac

test "x$dir" = x && dir=.

74
if test -d .git; then
J
Jim Meyering 已提交
75
  eval exec git ls-files '"$dir"' $postprocess
76
elif test -d .hg; then
J
Jim Meyering 已提交
77
  eval exec hg locate '"$dir/*"' $postprocess
78 79 80
elif test -d .bzr; then
  test "$postprocess" = '' && postprocess="| sed 's|^\./||'"
  eval exec bzr ls --versioned '"$dir"' $postprocess
81
elif test -d CVS; then
J
Jim Meyering 已提交
82
  test "$postprocess" = '' && postprocess="| sed 's|^\./||'"
83
  if test -x build-aux/cvsu; then
J
Jim Meyering 已提交
84 85 86
    eval build-aux/cvsu --find --types=AFGM '"$dir"' $postprocess
  elif (cvsu --help) >/dev/null 2>&1; then
    eval cvsu --find --types=AFGM '"$dir"' $postprocess
87
  else
J
Jim Meyering 已提交
88
    eval awk -F/ \''{			\
89 90 91 92
	if (!$1 && $3 !~ /^-/) {	\
	  f=FILENAME;			\
	  sub(/CVS\/Entries/, "", f);	\
	  print f $2;			\
J
Jim Meyering 已提交
93
	}}'\''				\
94
      `find "$dir" -name Entries -print` /dev/null' $postprocess
95 96
  fi
else
J
Jim Meyering 已提交
97
  echo "$0: Failed to determine type of version control used in `pwd`" 1>&2
98
  exit 1
99
fi
J
Jim Meyering 已提交
100 101 102 103 104 105 106

# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End: