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

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

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

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

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

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

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