patches 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/env bash
  2. # General tools for manipulating patches
  3. # and dealing with patches.
  4. lookup_patchset()
  5. {
  6. \typeset paths lookup_path
  7. if [[ -z "$1" ]]
  8. then
  9. echo "Usage: rvm patchset show name"
  10. return 1
  11. fi
  12. paths=($(__rvm_ruby_string_paths_under "$rvm_path/patchsets" | sort -r))
  13. for lookup_path in "${paths[@]}"
  14. do
  15. if [[ -s "$lookup_path/$1" ]]
  16. then
  17. \command \cat "$lookup_path/$1"
  18. return 0
  19. fi
  20. done
  21. return 1
  22. }
  23. # Returns the path used to look for a patch given a specific name.
  24. __rvm_patch_lookup_path()
  25. {
  26. echo "/"
  27. [[ -z "${rvm_patch_original_pwd:-""}" ]] || echo "$rvm_patch_original_pwd/"
  28. echo "$PWD/"
  29. __rvm_ruby_string_paths_under "$rvm_patches_path" | __rvm_sed 's/$/\//' | sort -r
  30. return $?
  31. }
  32. __rvm_expand_patch_name()
  33. {
  34. \typeset name level expanded_patch_name not_required_patches
  35. not_required_patches="optional default ${_system_name_lowercase}"
  36. name="${1:-""}"
  37. level="${2:-}"
  38. [[ -n "$name" ]] || return 0
  39. if
  40. expanded_patch_name="$(
  41. rvm_ruby_string="${rvm_ruby_string}" lookup_patchset "$name"
  42. )"
  43. then
  44. echo "${expanded_patch_name}"
  45. elif
  46. [[ " $not_required_patches " != *" $name "* ]]
  47. then
  48. echo "${name}${level:+%}${level:-}"
  49. fi
  50. }
  51. # Return the full patch for a given patch.
  52. __rvm_lookup_full_patch_path()
  53. {
  54. \typeset extension patch_path directory directories __old_IFS
  55. # Absolute path, pwd and then finally the rvm patches path.
  56. __old_IFS="$IFS"
  57. IFS=$'\n'
  58. directories=($( __rvm_patch_lookup_path ))
  59. IFS="$__old_IFS"
  60. for directory in "${directories[@]}"
  61. do
  62. for extension in "" .patch .diff
  63. do
  64. patch_path="${directory}${1}${extension}"
  65. # -s reports directories too - so additional check -f needed
  66. if
  67. [[ -s "$patch_path" && -f "$patch_path" ]]
  68. then
  69. echo "$patch_path"
  70. return 0
  71. fi
  72. done
  73. done
  74. if
  75. __rvm_string_match "$1" "http://*" "https://*" &&
  76. file_exists_at_url "$1"
  77. then
  78. echo "$1"
  79. fi
  80. }