git-list-tor-branches.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/usr/bin/env bash
  2. # Script to be used by other git scripts, and provide a single place
  3. # that lists our supported branches. To change which branches are
  4. # supported, look at the end of the file that says 'edit here'.
  5. SCRIPT_NAME=$(basename "$0")
  6. function usage()
  7. {
  8. echo "$SCRIPT_NAME [-h] [-l|-s|-b|-m] [-R|-M]"
  9. echo
  10. echo " arguments:"
  11. echo " -h: show this help text"
  12. echo
  13. echo " -l: list the active tor branches (default)"
  14. echo " -s: list the suffixes to be used with the active tor branches"
  15. echo " -b: write bash code setting WORKTREE to an array of ( branch path ) arrays"
  16. echo " -m: write bash code setting WORKTREE to an array of"
  17. echo " ( branch parent path suffix parent_suffix ) arrays"
  18. echo
  19. echo " -R: omit release branches."
  20. echo " -M: omit maint branches."
  21. }
  22. # list : just a list of branch names.
  23. # branch_path : For git-setup-dirs.sh and git-pull-all.sh
  24. # suffix: write a list of suffixes.
  25. # merge: branch, upstream, path, suffix, upstream suffix.
  26. mode="list"
  27. skip_maint_branches="no"
  28. skip_release_branches="no"
  29. while getopts "hblmsRM" opt ; do
  30. case "$opt" in
  31. h) usage
  32. exit 0
  33. ;;
  34. b) mode="branch_path"
  35. ;;
  36. l) mode="list"
  37. ;;
  38. s) mode="suffix"
  39. ;;
  40. m) mode="merge"
  41. ;;
  42. M) skip_maint_branches="yes"
  43. ;;
  44. R) skip_release_branches="yes"
  45. ;;
  46. *) echo "Unknown option"
  47. exit 1
  48. ;;
  49. esac
  50. done
  51. all_branch_vars=()
  52. prev_maint_branch=""
  53. prev_maint_suffix=""
  54. branch() {
  55. # The name of the branch. (Supplied by caller) Ex: maint-0.4.3
  56. brname="$1"
  57. # The name of the branch with no dots. Ex: maint-043
  58. brname_nodots="${brname//./}"
  59. # The name of the branch with no dots, and _ instead of -. Ex: maint_043
  60. brname_nodots_uscore="${brname_nodots//-/_}"
  61. # Name to use for a variable to represent the branch. Ex: MAINT_043
  62. varname="${brname_nodots_uscore^^}"
  63. is_maint="no"
  64. # suffix: a suffix to place at the end of branches we generate with respect
  65. # to this branch. Ex: _043
  66. # location: where the branch can be found.
  67. if [[ "$brname" == "main" ]]; then
  68. suffix="_main"
  69. location="\$GIT_PATH/\$TOR_MASTER_NAME"
  70. elif [[ "$brname" =~ ^maint- ]]; then
  71. suffix="_${brname_nodots#maint-}"
  72. location="\$GIT_PATH/\$TOR_WKT_NAME/$brname"
  73. is_maint="yes"
  74. if [[ "$skip_maint_branches" = "yes" ]]; then
  75. return
  76. fi
  77. elif [[ "$brname" =~ ^release- ]]; then
  78. suffix="_r${brname_nodots#release-}"
  79. location="\$GIT_PATH/\$TOR_WKT_NAME/$brname"
  80. if [[ "$skip_release_branches" = "yes" ]]; then
  81. return
  82. fi
  83. else
  84. echo "Unrecognized branch type '${brname}'" >&2
  85. exit 1
  86. fi
  87. all_branch_vars+=("$varname")
  88. # Now emit the per-branch information
  89. if [[ "$mode" == "branch_path" ]]; then
  90. echo "${varname}=( \"$brname\" \"$location\" )"
  91. elif [[ "$mode" == "merge" ]]; then
  92. echo "${varname}=( \"$brname\" \"$prev_maint_branch\" \"$location\" \"$suffix\" \"$prev_maint_suffix\" )"
  93. elif [[ "$mode" == "list" ]]; then
  94. echo "$brname"
  95. elif [[ "$mode" == "suffix" ]]; then
  96. echo "$suffix"
  97. else
  98. echo "unknown mode $mode" >&2
  99. exit 1
  100. fi
  101. if [[ "$is_maint" == "yes" ]]; then
  102. prev_maint_branch="$brname"
  103. prev_maint_suffix="$suffix"
  104. fi
  105. }
  106. finish() {
  107. if [[ "$mode" == branch_path ]] || [[ "$mode" == merge ]]; then
  108. echo "WORKTREE=("
  109. for v in "${all_branch_vars[@]}"; do
  110. echo " ${v}[@]"
  111. done
  112. echo ")"
  113. elif [[ "$mode" == list ]] || [[ "$mode" == suffix ]]; then
  114. # nothing to do
  115. :
  116. else
  117. echo "unknown mode $mode" >&2
  118. exit 1
  119. fi
  120. }
  121. # ==============================
  122. # EDIT HERE
  123. # ==============================
  124. # List of all branches. These must be in order, from oldest to newest, with
  125. # maint before release.
  126. branch maint-0.4.7
  127. branch release-0.4.7
  128. branch maint-0.4.8
  129. branch release-0.4.8
  130. branch main
  131. finish