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.

150 lines
3.4 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 - 2009 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" = "." ]; then
  68. # $PWD, explicitly
  69. y="$PWD"
  70. elif [ -e "$PWD/$x" ]; then
  71. # $PWD relative
  72. y="$PWD/$x"
  73. elif [ "$(echo "$x" | cut -c1)" = "/" -a -e "$x" ]; then
  74. # absolute
  75. y="$x"
  76. elif [ -e "$SDEROOT/package"/*/"$x" ]; then
  77. # package name
  78. y=$( echo "$SDEROOT/package"/*/"$x" )
  79. elif [ -e "$SDEROOT/target/$x" ]; then
  80. # target name
  81. y="$SDEROOT/target/$x"
  82. elif [ -e "$SDEROOT/$x" ]; then
  83. # $SDEROOT relative
  84. y="$SDEROOT/$x"
  85. fi
  86. # canonicalize
  87. [ -z "$y" ] || y=$( readlink -f "$y" )
  88. # analyse
  89. if [ -z "$y" ]; then
  90. # missing
  91. print_error "$x: not found."
  92. elif [ "$y" = "$SDEROOT" ]; then
  93. # uh, the root itself
  94. if [ -n "$show_roots" ]; then
  95. print_file_root "." "."
  96. else
  97. print_file "$SDEROOT"
  98. fi
  99. elif ! expr "$y" : "$SDEROOT/*" > /dev/null; then
  100. # missing
  101. print_error "$x: outside the tree."
  102. elif [ -n "$show_roots" ]; then
  103. # detect the right VCS roots and split the output accordingly
  104. file="${y#$SDEROOT/}"
  105. root=.
  106. case "$file" in
  107. target/*) # targets may be their own svn or git repository
  108. root=$( echo "$file" | cut -d/ -f'1,2' )
  109. [ -e "$SDEROOT/$root/.svn" -o -e "$SDEROOT/$root/.git" ] || root=.
  110. ;;
  111. package) # package is an standalone git repo
  112. root="package" file="." ;;
  113. package/*) # each package/* may be it's own svn or git repo
  114. root=$( echo "$file" | cut -d/ -f'1,2' )
  115. [ -e "$SDEROOT/$root/.svn" -o -e "$SDEROOT/$root/.git" ] || root=package
  116. ;;
  117. esac
  118. # trim filename to be $root relative
  119. case "$root" in
  120. .) ;;
  121. $file) file=. ;;
  122. *) file="${file#$root/}"
  123. esac
  124. print_file_root "$file" "$root"
  125. else
  126. # just output the list
  127. print_file "$y"
  128. fi
  129. done