2 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 # Filename: bin/sde-list-files
6 # Copyright (C) 2007 - 2008 The OpenSDE Project
8 # More information can be found in the files COPYING and README.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- SDE-COPYRIGHT-NOTE-END ---
16 # This script returns a list of locations in SDEROOT relative form
20 export SDEROOT
=$
( cd "${0%/*}/.."; pwd -P )
22 .
$SDEROOT/lib
/libsde.
in
25 local progname
=${0##*/}
27 Usage: $progname [--absolute] [--roots] [FILES...]
32 longopts
='roots,absolute'
33 options
=$
( getopt
-o "$shortopts" -l "$longopts" -- "$@" )
39 # load new arguments list
40 eval set -- "$options"
45 while [ $# -gt 0 ]; do
47 --roots) show_roots
=1 ;;
48 -a|
--absolute) show_absolute_path
=1 ;;
51 *) echo_abort
1 "Unknown argument '$1', aborting."
56 print_error
() { echo "$@" >&2; }
58 # prints an absolute path $SDEROOT relative if wanted
62 if [ "$file" = "$SDEROOT" ]; then
63 [ -n "$show_absolute_path" ] ||
file="."
65 [ -n "$show_absolute_path" ] ||
file="${file#$SDEROOT/}"
71 # prints a roota relative path
73 local file="$1" root
="$2" # $file arrives relative
75 if [ "$root" = "." -a -n "$show_absolute_path" ]; then
84 if [ "$x" = "." ]; then
87 elif [ -e "$PWD/$x" ]; then
90 elif [ "${x:0:1}" = "/" -a -e "$x" ]; then
93 elif [ -e "$SDEROOT/package"/*/"$x" ]; then
95 y
=$
( echo "$SDEROOT/package"/*/"$x" )
96 elif [ -e "$SDEROOT/target/$x" ]; then
98 y
="$SDEROOT/target/$x"
99 elif [ -e "$SDEROOT/$x" ]; then
105 [ -z "$y" ] || y
=$
( readlink
-f "$y" )
110 print_error
"$x: not found."
111 elif [ "$y" = "$SDEROOT" ]; then
112 # uh, the root itself
113 if [ -n "$show_roots" ]; then
114 print_file_root
"." "."
116 print_file
"$SDEROOT"
118 elif ! expr "$y" : "$SDEROOT/*" > /dev
/null
; then
120 print_error
"$x: outside the tree."
121 elif [ -n "$show_roots" ]; then
122 # detect the right VCS roots and split the output accordingly
123 file="${y#$SDEROOT/}"
126 target
/*) # targets may be their own svn or git repository
127 root
=$
( echo "$file" | cut
-d/ -f'1,2' )
128 [ -e "$SDEROOT/$root/.svn" -o -e "$SDEROOT/$root/.git" ] || root
=.
130 package
) # package is an standalone git repo
131 root
="package" file="." ;;
132 package
/*) # each package/* may be it's own svn or git repo
133 root
=$
( echo "$file" | cut
-d/ -f'1,2' )
134 [ -e "$SDEROOT/$root/.svn" -o -e "$SDEROOT/$root/.git" ] || root
=package
138 # trim filename to be $root relative
142 *) file="${file#$root/}"
145 print_file_root
"$file" "$root"
147 # just output the list