|
|
#!/bin/sh # --- SDE-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # Filename: bin/sde-list-files # Copyright (C) 2007 - 2009 The OpenSDE Project # # More information can be found in the files COPYING and README. # # 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; version 2 of the License. A copy of the # GNU General Public License can be found in the file COPYING. # --- SDE-COPYRIGHT-NOTE-END ---
# This script returns a list of locations in SDEROOT relative form #
[ -n "$SDEROOT" ] || export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
. $SDEROOT/lib/libsde.in
list_usage() { local progname=${0##*/} cat <<EOT Usage: $progname [--absolute] [--roots] [FILES...] EOT }
shortopts='a' longopts='roots,absolute' options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" ) if [ $? -ne 0 ]; then list_usage exit -1 fi
# load new arguments list eval set -- "$options"
show_roots= show_absolute_path=
while [ $# -gt 0 ]; do case "$1" in --roots) show_roots=1 ;; -a|--absolute) show_absolute_path=1 ;;
--) shift; break ;; *) echo_abort 1 "Unknown argument '$1', aborting." esac shift done
print_error() { echo "$@" >&2; }
# prints an absolute path $SDEROOT relative if wanted print_file() { local file="$1"
if [ "$file" = "$SDEROOT" ]; then [ -n "$show_absolute_path" ] || file="." else [ -n "$show_absolute_path" ] || file="${file#$SDEROOT/}" fi
echo "$file" }
# prints a roota relative path print_file_root() { local file="$1" root="$2" # $file arrives relative
if [ "$root" = "." -a -n "$show_absolute_path" ]; then root="$SDEROOT" fi
echo "$root $file" }
for x; do y= if [ "$x" = "." ]; then # $PWD, explicitly y="$PWD" elif [ -e "$PWD/$x" ]; then # $PWD relative y="$PWD/$x" elif [ "$(echo "$x" | cut -c1)" = "/" -a -e "$x" ]; then # absolute y="$x" elif [ -e "$SDEROOT/package"/*/"$x" ]; then # package name y=$( echo "$SDEROOT/package"/*/"$x" ) elif [ -e "$SDEROOT/target/$x" ]; then # target name y="$SDEROOT/target/$x" elif [ -e "$SDEROOT/$x" ]; then # $SDEROOT relative y="$SDEROOT/$x" fi
# canonicalize [ -z "$y" ] || y=$( readlink -f "$y" )
# analyse if [ -z "$y" ]; then # missing print_error "$x: not found." elif [ "$y" = "$SDEROOT" ]; then # uh, the root itself if [ -n "$show_roots" ]; then print_file_root "." "." else print_file "$SDEROOT" fi elif ! expr "$y" : "$SDEROOT/*" > /dev/null; then # missing print_error "$x: outside the tree." elif [ -n "$show_roots" ]; then # detect the right VCS roots and split the output accordingly file="${y#$SDEROOT/}" root=. case "$file" in target/*) # targets may be their own svn or git repository root=$( echo "$file" | cut -d/ -f'1,2' ) [ -e "$SDEROOT/$root/.svn" -o -e "$SDEROOT/$root/.git" ] || root=. ;; package) # package is an standalone git repo root="package" file="." ;; package/*) # each package/* may be it's own svn or git repo root=$( echo "$file" | cut -d/ -f'1,2' ) [ -e "$SDEROOT/$root/.svn" -o -e "$SDEROOT/$root/.git" ] || root=package ;; esac
# trim filename to be $root relative case "$root" in .) ;; $file) file=. ;; *) file="${file#$root/}" esac
print_file_root "$file" "$root" else # just output the list print_file "$y" fi done
|