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