OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
3.3 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: bin/sde-list-files
  6. # Copyright (C) 2007 The OpenSDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  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 ---
  15. # This script returns a list of locations in SDEROOT relative form
  16. #
  17. [ -n "$SDEROOT" ] ||
  18. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  19. . $SDEROOT/lib/libsde.in
  20. list_usage() {
  21. local progname=${0##*/}
  22. cat <<EOT
  23. Usage: $progname [--absolute] [--roots] [FILES...]
  24. EOT
  25. }
  26. shortopts='a'
  27. longopts='roots,absolute'
  28. options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
  29. if [ $? -ne 0 ]; then
  30. list_usage
  31. exit -1
  32. fi
  33. # load new arguments list
  34. eval set -- "$options"
  35. show_roots=
  36. show_absolute_path=
  37. while [ $# -gt 0 ]; do
  38. case "$1" in
  39. --roots) show_roots=1 ;;
  40. -a|--absolute) show_absolute_path=1 ;;
  41. --) shift; break ;;
  42. *) echo_abort 1 "Unknown argument '$1', aborting."
  43. esac
  44. shift
  45. done
  46. print_error() { echo "$@" >&2; }
  47. # prints an absolute path $SDEROOT relative if wanted
  48. print_file() {
  49. local file="$1"
  50. if [ "$file" == "$SDEROOT" ]; then
  51. [ -n "$show_absolute_path" ] || file="."
  52. else
  53. [ -n "$show_absolute_path" ] || file="${file#$SDEROOT/}"
  54. fi
  55. echo "$file"
  56. }
  57. # prints a roota relative path
  58. print_file_root() {
  59. local file="$1" root="$2" # $file arrives relative
  60. if [ "$root" == "." -a -n "$show_absolute_path" ]; then
  61. root="$SDEROOT"
  62. fi
  63. echo "$root $file"
  64. }
  65. for x; do
  66. y=
  67. if [ "${x:0:1}" == "/" -a -e "$x" ]; then
  68. # absolute
  69. y="$x"
  70. elif [ -e "$SDEROOT/package"/*/"$x" ]; then
  71. # package name
  72. y=$( echo "$SDEROOT/package"/*/"$x" )
  73. elif [ -e "$SDEROOT/target/$x" ]; then
  74. # target name
  75. y="$SDEROOT/target/$x"
  76. elif [ -e "$SDEROOT/$x" ]; then
  77. # $SDEROOT relative
  78. y="$SDEROOT/$x"
  79. else [ -e "$x" ]
  80. # $PWD relative
  81. y="$PWD/$x"
  82. fi
  83. # canonicalize
  84. [ -z "$y" ] || y=$( readlink -f "$y" )
  85. # analyse
  86. if [ -z "$y" ]; then
  87. # missing
  88. print_error "$x: not found."
  89. elif [ "$y" == "$SDEROOT" ]; then
  90. # uh, the root itself
  91. if [ -n "$show_roots" ]; then
  92. print_file_root "." "."
  93. else
  94. print_file "$SDEROOT"
  95. fi
  96. elif ! expr "$y" : "$SDEROOT/*" > /dev/null; then
  97. # missing
  98. print_error "$x: outside the tree."
  99. elif [ -n "$show_roots" ]; then
  100. # detect the right VCS roots and split the output accordingly
  101. file="${y#$SDEROOT/}"
  102. root=.
  103. case "$file" in
  104. target/*) # targets may be their own svn or git repository
  105. root=$( echo "$file" | cut -d/ -f'1,2' )
  106. [ -e "$SDEROOT/$root/.svn" -o -e "$SDEROOT/$root/.git" ] || root=.
  107. ;;
  108. package) # package is an standalone git repo
  109. root="package" file="." ;;
  110. package/*) # each package/* may be it's own svn or git repo
  111. root=$( echo "$file" | cut -d/ -f'1,2' )
  112. [ -e "$SDEROOT/$root/.svn" -o -e "$SDEROOT/$root/.git" ] || root=package
  113. ;;
  114. esac
  115. # trim filename to be $root relative
  116. case "$root" in
  117. .) ;;
  118. $file) file=. ;;
  119. *) file="${file#$root/}"
  120. esac
  121. print_file_root "$file" "$root"
  122. else
  123. # just output the list
  124. print_file "$y"
  125. fi
  126. done