Browse Source

Naming convention: Prefix internal functions with _

Alois Mahdal 9 years ago
parent
commit
de35ae9ae1
4 changed files with 63 additions and 63 deletions
  1. 14
    14
      src/include/build.sh
  2. 8
    8
      src/include/deploy.sh
  3. 3
    3
      src/include/mkit.sh
  4. 38
    38
      src/include/release.sh

+ 14
- 14
src/include/build.sh View File

@@ -11,11 +11,11 @@ build() {
11 11
     find src -type f -name '*.skel' \
12 12
      | while read srcpath;
13 13
        do
14
-           build1 "$srcpath"
14
+           _build1 "$srcpath"
15 15
        done
16 16
 }
17 17
 
18
-build1() {
18
+_build1() {
19 19
     #
20 20
     # Process one skeleton
21 21
     #
@@ -23,14 +23,14 @@ build1() {
23 23
     local dstpath="$2"
24 24
     local ftype="$3"
25 25
     test -n "$dstpath"  || dstpath=${srcpath%.skel}
26
-    test -n "$ftype"    || ftype=$(guess_ftype "$dstpath")
26
+    test -n "$ftype"    || ftype=$(_guess_ftype "$dstpath")
27 27
     debug_var srcpath dstpath ftype
28
-    <"$srcpath" build1_ftype "$ftype" >"$dstpath"
28
+    <"$srcpath" _build1_ftype "$ftype" >"$dstpath"
29 29
     mkdir -p "$MKIT_LOCAL"
30 30
     echo "$dstpath" >> "$MKIT_LOCAL/built.lst"
31 31
 }
32 32
 
33
-guess_ftype() {
33
+_guess_ftype() {
34 34
     #
35 35
     # Guess file type from destination path $1
36 36
     #
@@ -41,15 +41,15 @@ guess_ftype() {
41 41
     esac
42 42
 }
43 43
 
44
-build1_ftype() {
44
+_build1_ftype() {
45 45
     #
46 46
     # Build a file of type $1
47 47
     #
48 48
     local ftype="$1"
49 49
     case $ftype in
50
-        MKIT_COMMON)    expand_variables "vars" ;;
51
-        markdown)       expand_includes | expand_variables "vars" ;;
52
-        rpmstuff)       expand_variables "vars" "rpmstuff:vars" ;;
50
+        MKIT_COMMON)    _expand_variables "vars" ;;
51
+        markdown)       _expand_includes | _expand_variables "vars" ;;
52
+        rpmstuff)       _expand_variables "vars" "rpmstuff:vars" ;;
53 53
         *)              die "unknown file type: $ftype" ;;
54 54
     esac
55 55
 }
@@ -129,7 +129,7 @@ debstuff() {
129 129
         do
130 130
             dftgt="debian/${dfsrc#$debian_skel}"
131 131
             mkdir -p "$(dirname "$dftgt")"
132
-            build1 "$dfsrc" "$dftgt"
132
+            _build1 "$dfsrc" "$dftgt"
133 133
         done
134 134
     echo debian >> "$MKIT_LOCAL/built.lst"
135 135
 }
@@ -142,10 +142,10 @@ rpmstuff() {
142 142
     local specsrc="$(ini 1value "rpmstuff:spec_skel")"
143 143
     test -n "$specsrc" || die "rpmstuff:spec_skel not specified"
144 144
     test -f "$specsrc" || die "specfile template not found: $specsrc"
145
-    build1 "$specsrc" "$specname"
145
+    _build1 "$specsrc" "$specname"
146 146
 }
147 147
 
148
-expand_includes() {
148
+_expand_includes() {
149 149
     #
150 150
     # Expand include directives
151 151
     #
@@ -170,7 +170,7 @@ expand_includes() {
170 170
     '
171 171
 }
172 172
 
173
-expand_variables() {
173
+_expand_variables() {
174 174
     #
175 175
     # Expand variables from sections $@
176 176
     #
@@ -195,7 +195,7 @@ expand_variables() {
195 195
         echo "s|__MKIT_PROJ_VERSION__|$(get_version)|g;"
196 196
         echo "s|__MKIT_SELF_VERSION__|$MKIT_VERSION|g;"
197 197
     } >> "$script"
198
-    perl -wp "$script" || die "expand_variables failed"
198
+    perl -wp "$script" || die "_expand_variables failed"
199 199
     rm "$script"
200 200
 }
201 201
 

+ 8
- 8
src/include/deploy.sh View File

@@ -14,11 +14,11 @@ _maybe() {
14 14
     esac
15 15
 }
16 16
 
17
-deploy_item() {
17
+_deploy_item() {
18 18
     #
19 19
     # Deploy item and make it look like wanted
20 20
     #
21
-    # usage: deploy_item src dst [mode]
21
+    # usage: _deploy_item src dst [mode]
22 22
     #
23 23
     # Both src and dst must be names of actual items[1],
24 24
     # whereas dst must not exist.  On update, dst is
@@ -54,16 +54,16 @@ deploy_item() {
54 54
     fi
55 55
 }
56 56
 
57
-get_dst() {
57
+_get_dst() {
58 58
     #
59 59
     # Find out target path for src file $2 of group $1
60 60
     #
61 61
     local grp=$1
62 62
     local src=$2
63
-    echo "$(get_root "$grp")/$(ini 1value "files:$grp:$src")"
63
+    echo "$(_get_root "$grp")/$(ini 1value "files:$grp:$src")"
64 64
 }
65 65
 
66
-get_root() {
66
+_get_root() {
67 67
     #
68 68
     # Find out target rooot for group $1
69 69
     #
@@ -90,8 +90,8 @@ install() {
90 90
             ini lskeys "files:$group" \
91 91
               | while read src;
92 92
                 do
93
-                    dst=$(get_dst "$group" "$src")
94
-                    deploy_item "$src" "$dst" "$mode"
93
+                    dst=$(_get_dst "$group" "$src")
94
+                    _deploy_item "$src" "$dst" "$mode"
95 95
                 done
96 96
         done
97 97
     test -f "$MKIT_LOCAL/autoclean" && clean
@@ -109,7 +109,7 @@ uninstall() {
109 109
             ini lskeys "files:$group" \
110 110
               | while read src;
111 111
                 do
112
-                    dst=$(get_dst "$group" "$src")
112
+                    dst=$(_get_dst "$group" "$src")
113 113
                     _maybe rm -vrf "$dst"
114 114
                 done
115 115
         done

+ 3
- 3
src/include/mkit.sh View File

@@ -87,7 +87,7 @@ route() {
87 87
     #
88 88
     # Call correct function based on $1
89 89
     #
90
-    if valid_targets | grep -qwx "^$1";
90
+    if _valid_targets | grep -qwx "^$1";
91 91
     then
92 92
         "$1"
93 93
     else
@@ -95,12 +95,12 @@ route() {
95 95
             echo "usage: $(basename "$0") TARGET"
96 96
             echo
97 97
             echo "valid targets:"
98
-            valid_targets | sed 's/^/    /'
98
+            _valid_targets | sed 's/^/    /'
99 99
         } >&2
100 100
     fi
101 101
 }
102 102
 
103
-valid_targets() {
103
+_valid_targets() {
104 104
     #
105 105
     # List valid routes
106 106
     #

+ 38
- 38
src/include/release.sh View File

@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-__die_if() {
3
+_die_if() {
4 4
     #
5 5
     # Die if blocking condition $1 is detected
6 6
     #
@@ -13,7 +13,7 @@ __die_if() {
13 13
             ;;
14 14
         norelbr)
15 15
             local relsrc=$(ini 1value project:relsrc)
16
-            __git_info curbranch \
16
+            _git_info curbranch \
17 17
               | grep -qFx "$relsrc" \
18 18
              || die "you are not on release source branch: $relsrc"
19 19
             ;;
@@ -23,7 +23,7 @@ __die_if() {
23 23
              && die "tree is dirty: $dirt"
24 24
             ;;
25 25
         novertag)
26
-            __git_info lasttag \
26
+            _git_info lasttag \
27 27
               | grep -q . \
28 28
              || die "cannot find last tag"
29 29
             ;;
@@ -33,20 +33,20 @@ __die_if() {
33 33
              || die "last change must be version bump in mkit.ini"
34 34
             ;;
35 35
         wip)
36
-            __git_info reldiff \
36
+            _git_info reldiff \
37 37
               | grep '^....... WIP ' \
38
-             && die "WIP commit since $(__git_info lasttag)"
38
+             && die "WIP commit since $(_git_info lasttag)"
39 39
             ;;
40 40
         old_c)
41
-            x=$(__ver_info nextver_g)
42
-            __ver_info currver_c \
41
+            x=$(_ver_info nextver_g)
42
+            _ver_info currver_c \
43 43
               | grep -qFx "$x" \
44 44
              || die "new version not in mkit.ini: $x"
45 45
             ;;
46 46
     esac
47 47
 }
48 48
 
49
-__git_info() {
49
+_git_info() {
50 50
     #
51 51
     # Get git info $1
52 52
     #
@@ -54,24 +54,24 @@ __git_info() {
54 54
     case "$info" in
55 55
         lasttag)    git tag | grep ^v | sort -V | tail -n1  ;;
56 56
         curbranch)  git rev-parse --abbrev-ref HEAD         ;;
57
-        reldiff)    git log --oneline "$(__git_info lasttag)..HEAD" --name-only ;;
57
+        reldiff)    git log --oneline "$(_git_info lasttag)..HEAD" --name-only ;;
58 58
     esac
59 59
 }
60 60
 
61
-__ver_info() {
61
+_ver_info() {
62 62
     #
63 63
     # Get git info $1
64 64
     #
65 65
     local info="$1"
66 66
     case "$info" in
67
-        lastver_g)  __git_info lasttag | sed s/^v// ;;
68
-        nextver_g)  __make_ver "$level" "$(__ver_info lastver_g)" ;;
67
+        lastver_g)  _git_info lasttag | sed s/^v// ;;
68
+        nextver_g)  _make_ver "$level" "$(_ver_info lastver_g)" ;;
69 69
         currver_c)  ini 1value project:version ;;
70
-        nextver_c)  __make_ver "$level" "$(__ver_info currver_c)" ;;
70
+        nextver_c)  _make_ver "$level" "$(_ver_info currver_c)" ;;
71 71
     esac
72 72
 }
73 73
 
74
-__make_ver() {
74
+_make_ver() {
75 75
     local level=$1
76 76
     local old=$2
77 77
     local oldx=${old%.*.*}
@@ -87,7 +87,7 @@ __make_ver() {
87 87
     echo "$new"
88 88
 }
89 89
 
90
-__release() {
90
+_release() {
91 91
     #
92 92
     # Prepare release
93 93
     #
@@ -100,15 +100,15 @@ __release() {
100 100
     local level=$1
101 101
     local newtag
102 102
 
103
-    __die_if nogit
104
-    __die_if norelbr
105
-    __die_if dirty
106
-    __die_if novertag
107
-    __die_if nobump
108
-    __die_if wip
109
-    __die_if old_c
103
+    _die_if nogit
104
+    _die_if norelbr
105
+    _die_if dirty
106
+    _die_if novertag
107
+    _die_if nobump
108
+    _die_if wip
109
+    _die_if old_c
110 110
 
111
-    newtag=v$(__ver_info nextver_g)
111
+    newtag=v$(_ver_info nextver_g)
112 112
     set -e
113 113
     debug_var newtag
114 114
     $MKIT_DRY && return
@@ -116,12 +116,12 @@ __release() {
116 116
     git branch -f "$(ini 1value project:reldst)" "$newtag"
117 117
 }
118 118
 
119
-__git_msg_vbump() {
119
+_git_msg_vbump() {
120 120
     echo "Bump version"
121 121
     echo ""
122 122
     echo "Overview of changes:"
123 123
     echo ""
124
-    __git_info reldiff \
124
+    _git_info reldiff \
125 125
       | sed '
126 126
             s/^[a-f0-9]\{7\} / *  &/; t PATHS
127 127
             s/^/        /
@@ -129,44 +129,44 @@ __git_msg_vbump() {
129 129
         '
130 130
 }
131 131
 
132
-__vbump() {
132
+_vbump() {
133 133
     local level="$1"
134 134
     local lastver   # current from mkit.ini
135 135
     local nextver   # after the bump
136
-    __die_if nogit
137
-    __die_if norelbr
138
-    __die_if dirty
139
-    lastver=$(__ver_info currver_c)
140
-    nextver=$(__ver_info nextver_c)
136
+    _die_if nogit
137
+    _die_if norelbr
138
+    _die_if dirty
139
+    lastver=$(_ver_info currver_c)
140
+    nextver=$(_ver_info nextver_c)
141 141
     debug_var lastver nextver
142 142
     $MKIT_DRY && return
143 143
     update_version "$nextver" mkit.ini \
144 144
       || die "failed to update version in mkit.ini"
145 145
     git add mkit.ini \
146 146
       || die "failed to add mkit.ini to the index"
147
-    git commit -e -m "$(__git_msg_vbump)"
147
+    git commit -e -m "$(_git_msg_vbump)"
148 148
 }
149 149
 
150 150
 vbump_x() {
151
-    __vbump x
151
+    _vbump x
152 152
 }
153 153
 
154 154
 vbump_y() {
155
-    __vbump y
155
+    _vbump y
156 156
 }
157 157
 
158 158
 vbump_z() {
159
-    __vbump z
159
+    _vbump z
160 160
 }
161 161
 
162 162
 release_x() {
163
-    __release x
163
+    _release x
164 164
 }
165 165
 
166 166
 release_y() {
167
-    __release y
167
+    _release y
168 168
 }
169 169
 
170 170
 release_z() {
171
-    __release z
171
+    _release z
172 172
 }