Browse code

Improved simplify_path Allow embededed repositories to be placed and an arbitrary location within the project (experimental) Move code related to "repostitories" and "embedded_repositories" into its own file.

Nat! authored on 16-09-2016 14:38:07
Showing 12 changed files
... ...
@@ -28,7 +28,7 @@ Checkout this repository then run
28 28
 
29 29
 ## How to install with homebrew
30 30
 
31
-If you have brew you can get the lastest released version with
31
+If you have brew you can get the latest released version with
32 32
 
33 33
 ```console
34 34
 brew tap mulle-kybernetik/software
... ...
@@ -4,7 +4,7 @@
4 4
 
5 5
 ... for C, C++, Objective-C
6 6
 
7
-... certainly not a "minimal" or lightweight" project with ca. 10000 lines of
7
+... certainly not a "minimal" or "lightweight" project with ca. 10000 lines of
8 8
   shell script code
9 9
 
10 10
 ## Why you may want it
11 11
similarity index 100%
12 12
rename from generate-brew-formula.sh
13 13
rename to bin/generate-brew-formula.sh
14 14
similarity index 90%
15 15
rename from release.sh
16 16
rename to bin/release.sh
... ...
@@ -37,7 +37,7 @@ git push public master
37 37
 git tag "${TAG}"
38 38
 git push public master --tags
39 39
 
40
-./generate-brew-formula.sh  > ../homebrew-software/mulle-bootstrap.rb
40
+./bin/generate-brew-formula.sh  > ../homebrew-software/mulle-bootstrap.rb
41 41
 (
42 42
 	cd ../homebrew-software ; \
43 43
  	git commit -m "${TAG} release of mulle-bootstrap" mulle-bootstrap.rb ; \
... ...
@@ -29,7 +29,7 @@
29 29
 #   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 30
 #   POSSIBILITY OF SUCH DAMAGE.
31 31
 
32
-MULLE_BOOTSTRAP_VERSION="2.0"
32
+MULLE_BOOTSTRAP_VERSION="2.1"
33 33
 
34 34
 #
35 35
 # This is the main user interface to mulle-bootstrap
... ...
@@ -38,7 +38,7 @@ array_value_check()
38 38
 {
39 39
    local n
40 40
 
41
-   n=`echo "$1" | wc -l`
41
+   n=`echo "$1" | wc -l  | awk '{ print $1}'`
42 42
    [ $n -eq 0 ] && fail "empty value"
43 43
    [ $n -ne 1 ] && fail "value \"$1\" has linebreaks"
44 44
 
... ...
@@ -57,26 +57,7 @@ array_index_check()
57 57
    [ -z "${i}" ] && fail "empty index"
58 58
 
59 59
    local n
60
-   n="`array_count "${array}"`"
61
-
62
-   [ ${i} -ge ${n} ] && fail "index ${i} out of bounds ${n}"
63
-
64
-   echo "${i}"
65
-}
66
-
67
-
68
-array_index_check()
69
-{
70
-   local array
71
-   local i
72
-
73
-   array="$1"
74
-   i="$2"
75
-
76
-   [ -z "${i}" ] && fail "empty index"
77
-
78
-   local n
79
-   n="`array_count "${array}"`"
60
+   n=`array_count "${array}"`
80 61
 
81 62
    [ ${i} -ge ${n} ] && fail "index ${i} out of bounds ${n}"
82 63
 
... ...
@@ -84,7 +65,6 @@ array_index_check()
84 65
 }
85 66
 
86 67
 
87
-
88 68
 array_add()
89 69
 {
90 70
    local array
... ...
@@ -117,7 +97,7 @@ array_count()
117 97
 
118 98
    local n
119 99
 
120
-   n=`echo "${array}" | wc -l`
100
+   n=`echo "${array}" | wc -l | awk '{ print $1}'`
121 101
    echo ${n}
122 102
 }
123 103
 
... ...
@@ -135,6 +115,16 @@ array_get()
135 115
 }
136 116
 
137 117
 
118
+array_get_last()
119
+{
120
+   local array
121
+
122
+   array="$1"
123
+
124
+   echo "${array}" | tail -1
125
+}
126
+
127
+
138 128
 array_insert()
139 129
 {
140 130
    local array
... ...
@@ -171,28 +161,46 @@ array_insert()
171 161
 }
172 162
 
173 163
 
174
-array_get_last()
164
+array_remove()
175 165
 {
176 166
    local array
167
+   local value
177 168
 
178 169
    array="$1"
170
+   value="`array_value_check "$2"`"
179 171
 
180
-   echo "${array}" | tail -1
172
+   if [ ! -z "${array}" ]
173
+   then
174
+       echo "${array}" | fgrep -v -x "${value}"
175
+   fi
181 176
 }
182 177
 
183 178
 
184
-array_remove()
179
+
180
+array_remove_last()
185 181
 {
186 182
    local array
187
-   local value
188 183
 
189 184
    array="$1"
190
-   value="`array_value_check "$2"`"
191 185
 
192
-   if [ ! -z "${array}" ]
193
-   then
194
-       echo "${array}" | fgrep -v -x "${value}"
195
-   fi
186
+   local n
187
+
188
+   n=`array_count "${array}"`
189
+   case $n in
190
+      0)
191
+         fail "remove from empty array"
192
+      ;;
193
+
194
+      1)
195
+         return
196
+      ;;
197
+
198
+      *)
199
+         n="`expr $n - 1`"
200
+      ;;
201
+   esac
202
+
203
+   echo "${array}" | head -$n
196 204
 }
197 205
 
198 206
 
... ...
@@ -30,7 +30,6 @@
30 30
 #   POSSIBILITY OF SUCH DAMAGE.
31 31
 MULLE_BOOTSTRAP_CLEAN_SH="included"
32 32
 
33
-[ -z "${MULLE_BOOTSTRAP_BUILD_ENVIRONMENT_SH}" ] && . mulle-bootstrap-build-environment.sh
34 33
 
35 34
 
36 35
 clean_usage()
... ...
@@ -66,40 +65,6 @@ EOF
66 65
 }
67 66
 
68 67
 
69
-embedded_repositories()
70
-{
71
-   local clones
72
-   local clone
73
-   local dir
74
-   local name
75
-
76
-   [ -z "${MULLE_BOOTSTRAP_REFRESH_SH}" ] && . mulle-bootstrap-refresh.sh
77
-
78
-   refresh_main refresh_if_bare
79
-
80
-   clones="`read_fetch_setting "embedded_repositories"`"
81
-   if [ "${clones}" != "" ]
82
-   then
83
-      local old
84
-
85
-      old="${IFS:-" "}"
86
-      IFS="
87
-"
88
-      for clone in ${clones}
89
-      do
90
-         IFS="${old}"
91
-
92
-         clone="`expanded_setting "${clone}"`"
93
-
94
-         name="`canonical_name_from_clone "${clone}"`"
95
-         dir="${name}"
96
-         echo "${dir}"
97
-      done
98
-      IFS="${old}"
99
-   fi
100
-}
101
-
102
-
103 68
 clean_asserted_folder()
104 69
 {
105 70
    if [ -d "$1" ]
... ...
@@ -179,8 +144,7 @@ clean_directories()
179 144
 # to have other tools provide stuff besides /include and /lib
180 145
 # and sometimes  projects install other stuff into /share
181 146
 # for mingw its easier if we have separate clean functions
182
-
183
-
147
+#
184 148
 _clean_execute()
185 149
 {
186 150
    local flag
... ...
@@ -235,7 +199,7 @@ ${DEPENDENCY_SUBDIR}/tmp"`"
235 199
          DIST_CLEANABLE_SUBDIRS="`read_sane_config_path_setting "dist_clean_folders" "${CLONES_SUBDIR}
236 200
 ${ADDICTION_SUBDIR}
237 201
 .bootstrap.auto"`"
238
-         EMBEDDED="`embedded_repositories`"
202
+         EMBEDDED="`embedded_repository_directories_from_repos`"
239 203
 
240 204
          if [ ! -z "$EMBEDDED" ]
241 205
          then
... ...
@@ -271,6 +235,7 @@ clean_main()
271 235
 
272 236
    [ -z "${MULLE_BOOTSTRAP_BUILD_ENVIRONMENT_SH}" ] && . mulle-bootstrap-build-environment.sh
273 237
    [ -z "${MULLE_BOOTSTRAP_SETTINGS_SH}" ] && . mulle-bootstrap-settings.sh
238
+   [ -z "${MULLE_BOOTSTRAP_REPOSITORIES_SH}" ] && . mulle-bootstrap-repositories.sh
274 239
 
275 240
    COMMAND=${1:-"output"}
276 241
    [ $# -eq 0 ] || shift
... ...
@@ -819,6 +819,12 @@ ${clone}"
819 819
                branch="`branch_from_clone "${clone}"`"
820 820
                scm="`scm_from_clone "${clone}"`"
821 821
 
822
+               case "${name}" in
823
+                  /|~|..)
824
+                     fail "destination directory of ${clone} looks fishy"
825
+                  ;;
826
+               esac
827
+
822 828
                clone_repository "${name}" "${url}" "${branch}" "${scm}"
823 829
 
824 830
                if [ $? -eq 1 ]
... ...
@@ -1163,16 +1169,30 @@ clone_embedded_repository()
1163 1169
    local name
1164 1170
    local url
1165 1171
    local dstdir
1172
+   local subdir
1166 1173
    local branch
1167 1174
    local tag
1168 1175
    local scm
1169 1176
 
1177
+   subdir="`_name_part_from_clone "${clone}"`"
1170 1178
    name="`canonical_name_from_clone "${clone}"`"
1171 1179
    url="`url_from_clone "${clone}"`"
1172 1180
    branch="`branch_from_clone "${clone}"`"
1173 1181
    scm="`scm_from_clone "${clone}"`"
1174 1182
    tag="`read_repo_setting "${name}" "tag"`" #repo (sic)
1175
-   dstdir="${dstprefix}${name}"
1183
+
1184
+   subdir="`simplify_path "${subdir}"`"
1185
+   case "${subdir}" in
1186
+      /*|~*|..*)
1187
+         fail "destination directory of ${clone} looks fishy"
1188
+      ;;
1189
+
1190
+      "")
1191
+         subdir="${name}"
1192
+      ;;
1193
+   esac
1194
+
1195
+   dstdir="${dstprefix}${subdir}"
1176 1196
 
1177 1197
    log_fetch_action "${url}" "${dstdir}"
1178 1198
 
... ...
@@ -1182,7 +1202,19 @@ clone_embedded_repository()
1182 1202
 
1183 1203
       if [ "${MULLE_BOOTSTRAP_IGNORE_GRAVEYARD}" != "YES" -a -d "${CLONESFETCH_SUBDIR}/.embedded/.graveyard/${name}" ]
1184 1204
       then
1205
+         local parent
1206
+
1185 1207
          log_info "Restoring ${name} from embedded graveyard"
1208
+         parent="`dirname "${dstdir}"`"
1209
+         case "${parent}" in
1210
+            .)
1211
+            ;;
1212
+
1213
+            *)
1214
+               mkdir_if_missing "${parent}"
1215
+            ;;
1216
+         esac
1217
+
1186 1218
          exekutor mv "${CLONESFETCH_SUBDIR}/.embedded/.graveyard/${name}" "${dstdir}" || fail "move failed"
1187 1219
          ensure_clone_branch_is_correct "${dstdir}" "${branch}"
1188 1220
       else
... ...
@@ -1394,6 +1426,7 @@ _common_main()
1394 1426
    [ -z "${MULLE_BOOTSTRAP_SCRIPTS_SH}" ] && . mulle-bootstrap-scripts.sh
1395 1427
    [ -z "${MULLE_BOOTSTRAP_WARN_SCRIPTS_SH}" ] && . mulle-bootstrap-warn-scripts.sh
1396 1428
    [ -z "${MULLE_BOOTSTRAP_AUTO_UPDATE_SH}" ] && . mulle-bootstrap-auto-update.sh
1429
+   [ -z "${MULLE_BOOTSTRAP_REPOSITORIES_SH}" ] && . mulle-bootstrap-repositories.sh
1397 1430
 
1398 1431
    #
1399 1432
    # should we check for '/usr/local/include/<name>' and don't fetch if
... ...
@@ -472,75 +472,111 @@ combined_escaped_search_path()
472 472
 }
473 473
 
474 474
 
475
-#
476
-# simplify path works on paths that may or may not exist
477
-# it makes prettier relative or absolute paths
478
-#
479
-simplify_path()
475
+_simplify_components()
480 476
 {
481
-   local file
477
+   local i
478
+   local old
482 479
 
483
-   file="$1"
484 480
 
485
-   local modification
481
+   local components
486 482
 
487
-   # foo/ -> foo
488
-   modification="`echo "$1" | sed 's|^\(.*\)/$|\1|'`"
489
-   if  [ "${modification}" != "${file}" ]
490
-   then
491
-      simplify_path "${modification}"
492
-      return
493
-   fi
483
+   old="${IFS}"
484
+   IFS="
485
+"
486
+   for i in $*
487
+   do
488
+      IFS="${old}"
494 489
 
495
-   # ./foo -> foo
496
-   modification="`echo "$1" | sed 's|^\./\(.*\)$|\1|'`"
497
-   if  [ "${modification}" != "${file}" ]
498
-   then
499
-      simplify_path "${modification}"
500
-      return
501
-   fi
490
+      case "${i}" in
491
+         # ./foo -> foo
492
+         ./)
493
+         ;;
502 494
 
503
-   # foo/. -> foo
504
-   modification="`echo "$1" | sed 's|^\(.*\)/\.$|\1|'`"
505
-   if  [ "${modification}" != "${file}" ]
506
-   then
507
-      simplify_path "${modification}"
508
-      return
509
-   fi
495
+         # bar/.. -> ""
496
+         ../)
497
+            if [ -z "${components}" ]
498
+            then
499
+               components="`array_add "${components}" "../"`"
500
+            else
501
+               if [ "${components}" != "/" ]
502
+               then
503
+                  components="`array_remove_last "${components}"`"
504
+               fi
505
+               # /.. -> /
506
+            fi
507
+         ;;
510 508
 
511
-   # bar/./foo -> bar/foo
512
-   modification="`echo "$1" | sed 's|^\(.*\)/\./\(.*\)$|\1/\2|'`"
513
-   if  [ "${modification}" != "${file}" ]
514
-   then
515
-      simplify_path "${modification}"
516
-      return
517
-   fi
518 509
 
519
-   # bar/.. -> ""
520
-   modification="`echo "$1" | sed 's|^\([^/]*\)/\.\.$||'`"
521
-   if  [ "${modification}" != "${file}" ]
522
-   then
523
-      simplify_path "${modification}"
524
-      return
525
-   fi
510
+         # foo/ -> foo
511
+         "/")
512
+            if [ -z "${components}" ]
513
+            then
514
+               components="${i}"
515
+            fi
516
+         ;;
526 517
 
527
-   # bar/../foo -> foo
528
-   modification="`echo "$1" | sed 's|^\([^/]*\)/\.\./\(.*\)$|\2|'`"
529
-   if  [ "${modification}" != "${file}" ]
530
-   then
531
-      simplify_path "${modification}"
532
-      return
533
-   fi
518
+         *)
519
+            components="`array_add "${components}" "${i}"`"
520
+         ;;
521
+      esac
522
+   done
523
+
524
+   IFS="${old}"
525
+
526
+   echo "${components}"
527
+}
534 528
 
535
-   # bar/baz/../foo -> bar/foo
536
-   modification="`echo "$1" | sed 's|^\(.*\)/\([^/]*\)/\.\./\(.*\)$|\1/\3|'`"
537
-   if  [ "${modification}" != "${file}" ]
529
+
530
+_path_from_components()
531
+{
532
+   local components
533
+
534
+   components="$1"
535
+
536
+   local i
537
+   local old
538
+   local path
539
+
540
+   old="${IFS}"
541
+   IFS="
542
+"
543
+
544
+   for i in $components
545
+   do
546
+      path="${path}${i}"
547
+   done
548
+
549
+
550
+   IFS="${old}"
551
+
552
+   if [ -z "${path}" ]
538 553
    then
539
-      simplify_path "${modification}"
540
-      return
554
+      echo "."
555
+   else
556
+      echo "$path" | sed 's|^\(..*\)/$|\1|'
541 557
    fi
558
+}
559
+
560
+
561
+#
562
+# simplify path works on paths that may or may not exist
563
+# it makes prettier relative or absolute paths
564
+#
565
+simplify_path()
566
+{
567
+   local path
568
+
569
+   path="$1"
570
+
571
+   local components
572
+   local final_components
573
+   local final_path
574
+
575
+   components="`echo "${path}" | tr '/' '\012' | sed -e 's|$|/|'`"
576
+   final_components="`_simplify_components  "${components}"`"
577
+   final_path="`_path_from_components "${final_components}"`"
542 578
 
543
-   echo "${modification}"
579
+   echo "${final_path}"
544 580
 }
545 581
 
546 582
 
... ...
@@ -843,6 +879,7 @@ write_protect_directory()
843 879
 functions_initialize()
844 880
 {
845 881
    [ -z "${MULLE_BOOTSTRAP_LOGGING_SH}" ] && . mulle-bootstrap-logging.sh
882
+   [ -z "${MULLE_BOOTSTRAP_ARRAY_SH}" ] && . mulle-bootstrap-array.sh
846 883
 
847 884
    log_fluff ":functions_initialize:"
848 885
 }
849 886
new file mode 100644
... ...
@@ -0,0 +1,220 @@
1
+#! /bin/sh
2
+#
3
+#   Copyright (c) 2016 Nat! - Mulle kybernetiK
4
+#   All rights reserved.
5
+#
6
+#   Redistribution and use in source and binary forms, with or without
7
+#   modification, are permitted provided that the following conditions are met:
8
+#
9
+#   Redistributions of source code must retain the above copyright notice, this
10
+#   list of conditions and the following disclaimer.
11
+#
12
+#   Redistributions in binary form must reproduce the above copyright notice,
13
+#   this list of conditions and the following disclaimer in the documentation
14
+#   and/or other materials provided with the distribution.
15
+#
16
+#   Neither the name of Mulle kybernetiK nor the names of its contributors
17
+#   may be used to endorse or promote products derived from this software
18
+#   without specific prior written permission.
19
+#
20
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+#   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+#   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24
+#   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+#   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+#   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+#   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+#   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+#   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+#   POSSIBILITY OF SUCH DAMAGE.
31
+#
32
+
33
+MULLE_BOOTSTRAP_REPOSITORIES_SH="included"
34
+
35
+
36
+
37
+# ####################################################################
38
+#                       repository file
39
+# ####################################################################
40
+#
41
+
42
+# deal with stuff like
43
+# foo
44
+# https://www./foo.git
45
+# host:foo
46
+#
47
+
48
+canonical_clone_name()
49
+{
50
+   local  url
51
+
52
+   url="$1"
53
+
54
+
55
+   # cut off scheme part
56
+
57
+   case "$url" in
58
+      *:*)
59
+         url="`echo "$@" | sed 's/^\(.*\):\(.*\)/\2/'`"
60
+         ;;
61
+   esac
62
+
63
+   extension_less_basename "$url"
64
+}
65
+
66
+
67
+count_clone_components()
68
+{
69
+  echo "$@" | tr ';' '\012' | wc -l | awk '{ print $1 }'
70
+}
71
+
72
+
73
+url_from_clone()
74
+{
75
+   echo "$@" | cut '-d;' -f 1
76
+}
77
+
78
+
79
+_name_part_from_clone()
80
+{
81
+   echo "$@" | cut '-d;' -f 2
82
+}
83
+
84
+
85
+_branch_part_from_clone()
86
+{
87
+   echo "$@" | cut '-d;' -f 3
88
+}
89
+
90
+
91
+_scm_part_from_clone()
92
+{
93
+   echo "$@" | cut '-d;' -f 4
94
+}
95
+
96
+
97
+canonical_name_from_clone()
98
+{
99
+   local url
100
+   local name
101
+   local branch
102
+
103
+   url="`url_from_clone "$@"`"
104
+   name="`_name_part_from_clone "$@"`"
105
+
106
+   if [ ! -z "${name}" -a "${name}" != "${url}" ]
107
+   then
108
+      canonical_clone_name "${name}"
109
+      return
110
+   fi
111
+
112
+   canonical_clone_name "${url}"
113
+}
114
+
115
+
116
+branch_from_clone()
117
+{
118
+   local count
119
+
120
+   count="`count_clone_components "$@"`"
121
+   if [ "$count" -ge 3 ]
122
+   then
123
+      _branch_part_from_clone "$@"
124
+   fi
125
+}
126
+
127
+
128
+scm_from_clone()
129
+{
130
+   local count
131
+
132
+   count="`count_clone_components "$@"`"
133
+   if [ "$count" -ge 4 ]
134
+   then
135
+      _scm_part_from_clone "$@"
136
+   fi
137
+}
138
+
139
+
140
+embedded_repository_directories_from_repos()
141
+{
142
+   local filename
143
+   local embedded
144
+   local linkfile
145
+   local relpath
146
+   local old
147
+   local owd
148
+
149
+   owd="`pwd -P`"
150
+
151
+   old="${IFS}"
152
+   IFS="
153
+"
154
+   for filename in `ls -1 "${CLONES_SUBDIR}/.embedded/" 2> /dev/null`
155
+   do
156
+      relpath="${CLONES_SUBDIR}/.embedded/${filename}"
157
+      if [ -f "${relpath}" ]
158
+      then
159
+         linkfile="`cat "${relpath}"`"
160
+         embedded="`(cd "${CLONES_SUBDIR}/.embedded" ; absolutepath "${linkfile}")`"
161
+         embedded="`simplify_path "${embedded}"`"
162
+         log_fluff "embedded: ${embedded}"
163
+         log_fluff "owd: ${owd}"
164
+         embedded="`relative_path_between "${embedded}" "${owd}"`"
165
+         if [ -d "${embedded}" ]
166
+         then
167
+            echo "${embedded}"
168
+         fi
169
+      fi
170
+   done
171
+
172
+   IFS="${old}"
173
+}
174
+
175
+
176
+repository_directories_from_repos()
177
+{
178
+   local filename
179
+   local old
180
+
181
+   old="${IFS}"
182
+   IFS="
183
+"
184
+   for filename in `ls -1 "${CLONES_SUBDIR}" 2> /dev/null`
185
+   do
186
+      case "${filename}" in
187
+         .*)
188
+         ;;
189
+
190
+         *)
191
+            echo "${CLONES_SUBDIR}/$filename"
192
+         ;;
193
+      esac
194
+   done
195
+
196
+   IFS="${old}"
197
+}
198
+
199
+
200
+ensure_clones_directory()
201
+{
202
+   if [ ! -d "${CLONESFETCH_SUBDIR}" ]
203
+   then
204
+      if [ "${COMMAND}" = "update" ]
205
+      then
206
+         fail "install first before upgrading"
207
+      fi
208
+      mkdir_if_missing "${CLONESFETCH_SUBDIR}"
209
+   fi
210
+}
211
+
212
+
213
+mulle_repositories_inititalize()
214
+{
215
+  [ -z "${MULLE_BOOTSTRAP_BUILD_ENVIRONMENT_SH}" ] && . mulle-bootstrap-build-environment.sh
216
+  [ -z "${MULLE_BOOTSTRAP_SETTINGS_SH}" ] && . mulle-bootstrap-settings.sh
217
+  [ -z "${MULLE_BOOTSTRAP_FUNCTIONS_SH}" ] && . mulle-bootstrap-functions.sh
218
+}
219
+
220
+mulle_repositories_inititalize
... ...
@@ -681,122 +681,6 @@ ${keys6}" | sort | sort -u | egrep -v '^[ ]*$'
681 681
 }
682 682
 
683 683
 
684
-# ####################################################################
685
-#                       repository file
686
-# ####################################################################
687
-#
688
-
689
-# deal with stuff like
690
-# foo
691
-# https://www./foo.git
692
-# host:foo
693
-#
694
-
695
-canonical_clone_name()
696
-{
697
-   local  url
698
-
699
-   url="$1"
700
-
701
-
702
-   # cut off scheme part
703
-
704
-   case "$url" in
705
-      *:*)
706
-         url="`echo "$@" | sed 's/^\(.*\):\(.*\)/\2/'`"
707
-         ;;
708
-   esac
709
-
710
-   extension_less_basename "$url"
711
-}
712
-
713
-
714
-count_clone_components()
715
-{
716
-  echo "$@" | tr ';' '\012' | wc -l | awk '{ print $1 }'
717
-}
718
-
719
-
720
-url_from_clone()
721
-{
722
-   echo "$@" | cut '-d;' -f 1
723
-}
724
-
725
-
726
-_name_part_from_clone()
727
-{
728
-   echo "$@" | cut '-d;' -f 2
729
-}
730
-
731
-
732
-_branch_part_from_clone()
733
-{
734
-   echo "$@" | cut '-d;' -f 3
735
-}
736
-
737
-
738
-_scm_part_from_clone()
739
-{
740
-   echo "$@" | cut '-d;' -f 4
741
-}
742
-
743
-
744
-canonical_name_from_clone()
745
-{
746
-   local url
747
-   local name
748
-   local branch
749
-
750
-   url="`url_from_clone "$@"`"
751
-   name="`_name_part_from_clone "$@"`"
752
-
753
-   if [ ! -z "${name}" -a "${name}" != "${url}" ]
754
-   then
755
-      canonical_clone_name "${name}"
756
-      return
757
-   fi
758
-
759
-   canonical_clone_name "${url}"
760
-}
761
-
762
-
763
-branch_from_clone()
764
-{
765
-   local count
766
-
767
-   count="`count_clone_components "$@"`"
768
-   if [ "$count" -ge 3 ]
769
-   then
770
-      _branch_part_from_clone "$@"
771
-   fi
772
-}
773
-
774
-
775
-scm_from_clone()
776
-{
777
-   local count
778
-
779
-   count="`count_clone_components "$@"`"
780
-   if [ "$count" -ge 4 ]
781
-   then
782
-      _scm_part_from_clone "$@"
783
-   fi
784
-}
785
-
786
-
787
-ensure_clones_directory()
788
-{
789
-   if [ ! -d "${CLONESFETCH_SUBDIR}" ]
790
-   then
791
-      if [ "${COMMAND}" = "update" ]
792
-      then
793
-         fail "install first before upgrading"
794
-      fi
795
-      mkdir_if_missing "${CLONESFETCH_SUBDIR}"
796
-   fi
797
-}
798
-
799
-
800 684
 # read some config stuff now
801 685
 
802 686
 settings_initialize()
803 687
new file mode 100755
... ...
@@ -0,0 +1,52 @@
1
+#! /bin/sh
2
+
3
+. mulle-bootstrap-functions.sh
4
+
5
+run_test()
6
+{
7
+  expect="$1"
8
+  shift
9
+
10
+  result="`eval "$@"`"
11
+
12
+  [ "${result}" != "${expect}" ] && fail "test:" "$@" "failed with \"${result}\", expected \"${expect}\""
13
+}
14
+
15
+
16
+test_simplify_path()
17
+{
18
+  run_test "/" simplify_path "/"
19
+  run_test "/" simplify_path "/."
20
+  run_test "/" simplify_path "/./"
21
+  run_test "/" simplify_path "/.."     # return /
22
+  run_test "/" simplify_path "/../"
23
+  run_test "/" simplify_path "/foo/.."
24
+  run_test "/" simplify_path "/foo/../"
25
+  run_test "/" simplify_path "/foo/./.."
26
+  run_test "/" simplify_path "/foo/../."
27
+  run_test "/" simplify_path "/foo/../.."
28
+  run_test "/"  simplify_path "/foo/../."
29
+  run_test "/"  simplify_path "/foo/.././"
30
+  run_test "/"  simplify_path "/foo/../.."
31
+  run_test "/"  simplify_path "/foo/../../"
32
+
33
+  run_test "/foo" simplify_path "/foo"
34
+  run_test "/foo" simplify_path "/foo/"
35
+  run_test "/foo" simplify_path "/foo/."
36
+  run_test "/foo" simplify_path "/foo/./"
37
+
38
+  run_test "/foo/bar" simplify_path "/foo/bar"
39
+  run_test "/foo/bar" simplify_path "/foo/bar/"
40
+  run_test "/foo/bar" simplify_path "/foo/./bar"
41
+  run_test "/bar"     simplify_path "/foo/../bar"
42
+  run_test "/bar"     simplify_path "/foo/../../bar"
43
+
44
+  run_test "foo/bar" simplify_path "foo/bar"
45
+  run_test "foo/bar" simplify_path "foo/bar/"
46
+  run_test "foo/bar" simplify_path "foo/./bar"
47
+  run_test "bar"     simplify_path "foo/../bar"
48
+  run_test "."       simplify_path "foo/.."
49
+}
50
+
51
+
52
+test_simplify_path