Browse code

* fixed a problem in the parsing of the repositories file * embedded repositories can now be placed at an arbitrary position within your project tree * changes in deeply embedded repositories are now better tracked * fixed some path functions

Nat! authored on 21-09-2016 11:26:26
Showing 16 changed files
... ...
@@ -1,5 +1,10 @@
1 1
 # FAQ
2 2
 
3
+## Is mulle-bootstrap a package manager ?
4
+
5
+No it's a dependency manager.
6
+
7
+
3 8
 ## Where is what ?
4 9
 
5 10
 * `.bootstrap` is the bootstrap configuration of the repository.
... ...
@@ -130,6 +135,11 @@ Any setting can be overriden by the environment:
130 135
 MULLE_BOOTSTRAP_BUILD_PREFERENCES=cmake mulle-bootstrap build
131 136
 ```
132 137
 
138
+### My embedded_repoisitories .bootstrap folder is ignored ?
139
+
140
+Yes, this is by design. Embedded repositories are not built and therefore
141
+(should) have no dependencies.
142
+
133 143
 
134 144
 ### Is the order of the repositories important ?
135 145
 
... ...
@@ -46,7 +46,6 @@ projects and installs their output into a "dependencies" folder.
46 46
 libraries into an "addictions" folder (on participating platforms)
47 47
 * alerts to the presence of shell scripts in fetched dependencies
48 48
 
49
-
50 49
 ## A first use
51 50
 
52 51
 So you need a bunch of third party projects to build your own
... ...
@@ -1,3 +1,15 @@
1
+2.1
2
+===
3
+
4
+**The changes should be transparent, but to be safe `mulle-bootstrap dist clean`
5
+your projects**
6
+
7
+* fixed a problem in the parsing of the repositories file
8
+* embedded repositories can now be placed at an arbitrary position within your
9
+project tree
10
+* changes in deeply embedded repositories are now better tracked
11
+* fixed some as of yet unknown bugs, by improving some path functions
12
+
1 13
 2.0
2 14
 ===
3 15
 
... ...
@@ -5,6 +17,7 @@
5 17
 
6 18
 Do a `mulle-bootstrap dist clean`.
7 19
 
20
+
8 21
 ### YOUR OLD SETTINGS MAY NOT WORK ANYMORE!
9 22
 
10 23
 Move all repo specific setting directories from
... ...
@@ -318,7 +318,13 @@ bootstrap_main()
318 318
    if [ "${MULLE_BOOTSTRAP_SKIP_INITIAL_REFRESH}" != "YES" ]
319 319
    then
320 320
       case "${command}" in
321
-         bootstrap|nomagic|setup-xcode|xcode|tag|fetch)
321
+         bootstrap|nomagic|fetch)
322
+            MULLE_BOOTSTRAP_WILL_FETCH="YES"
323
+            . mulle-bootstrap-refresh.sh
324
+            refresh_main || exit 1
325
+         ;;
326
+
327
+         setup-xcode|xcode|tag)
322 328
            . mulle-bootstrap-refresh.sh
323 329
             refresh_main || exit 1
324 330
          ;;
... ...
@@ -39,8 +39,8 @@ array_value_check()
39 39
    local n
40 40
 
41 41
    n=`echo "$1" | wc -l  | awk '{ print $1}'`
42
-   [ $n -eq 0 ] && fail "empty value"
43
-   [ $n -ne 1 ] && fail "value \"$1\" has linebreaks"
42
+   [ $n -eq 0 ] && internal_fail "empty value"
43
+   [ $n -ne 1 ] && internal_fail "value \"$1\" has linebreaks"
44 44
 
45 45
    echo "$1"
46 46
 }
... ...
@@ -54,12 +54,12 @@ array_index_check()
54 54
    array="$1"
55 55
    i="$2"
56 56
 
57
-   [ -z "${i}" ] && fail "empty index"
57
+   [ -z "${i}" ] && internal_fail "empty index"
58 58
 
59 59
    local n
60 60
    n=`array_count "${array}"`
61 61
 
62
-   [ ${i} -ge ${n} ] && fail "index ${i} out of bounds ${n}"
62
+   [ ${i} -ge ${n} ] && internal_fail "index ${i} out of bounds ${n}"
63 63
 
64 64
    echo "${i}"
65 65
 }
... ...
@@ -139,10 +139,10 @@ array_insert()
139 139
    local tail_count
140 140
    local n
141 141
 
142
-   [ "${i}" = "" ] && fail "empty index"
142
+   [ "${i}" = "" ] && internal_fail "empty index"
143 143
 
144 144
    n=`array_count "${array}"`
145
-   [ ${i} -gt ${n} ] && fail "index ${i} out of bounds ${n}"
145
+   [ ${i} -gt ${n} ] && internal_fail "index ${i} out of bounds ${n}"
146 146
 
147 147
    head_count=$i
148 148
    tail_count=`expr $n - $i`
... ...
@@ -234,8 +234,8 @@ _assoc_array_key_check()
234 234
    local n
235 235
 
236 236
    n=`echo "$1" | wc -w`
237
-   [ $n -eq 0 ] && fail "empty value"
238
-   [ $n -ne 1 ] && fail "key \"$1\" has spaces"
237
+   [ $n -eq 0 ] && internal_fail "empty value"
238
+   [ $n -ne 1 ] && internal_fail "key \"$1\" has spaces"
239 239
 
240 240
    #
241 241
    # escape charactes
... ...
@@ -658,6 +658,7 @@ did_clone_repository()
658 658
 # checked out already it will use it, or ask
659 659
 # convention: .git suffix == repo to clone
660 660
 #          no .git suffix, try to symlink
661
+# return value 1 means: reread repositories, as it may have changed
661 662
 #
662 663
 checkout_repository()
663 664
 {
... ...
@@ -672,50 +673,48 @@ checkout_repository()
672 673
    branch="$4"
673 674
 
674 675
    local flag
676
+   local run_script
675 677
 
676
-   if [ ! -e "${dstdir}" ]
678
+   run_script=-1
679
+   flag=0
680
+
681
+   if [ -e "${dstdir}" ]
677 682
    then
683
+      ensure_clone_branch_is_correct "${dstdir}" "${branch}"
684
+
685
+      log_fluff "Repository \"${dstdir}\" already exists"
686
+   else
678 687
       if [ "${MULLE_BOOTSTRAP_IGNORE_GRAVEYARD}" != "YES" -a -d "${CLONESFETCH_SUBDIR}/.graveyard/${name}" ]
679 688
       then
680 689
          log_info "Restoring ${name} from graveyard"
681 690
          exekutor mv "${CLONESFETCH_SUBDIR}/.graveyard/${name}" "${CLONESFETCH_SUBDIR}" || fail "move failed"         ensure_clone_branch_is_correct "${dstdir}" "${branch}"
682 691
          ensure_clone_branch_is_correct "${dstdir}" "${branch}"
683
-         flag=0
684 692
       else
685 693
          checkout "$@"
686
-         flag=1
687
-
688
-         if [ "${COMMAND}" = "fetch" -a "${DONT_RECURSE}" = "" ]
689
-         then
690
-            local old_bootstrap
691
-
692
-            old_bootstrap="${BOOTSTRAP_SUBDIR}"
694
+         run_script=0  # yes, run it
693 695
 
694
-            BOOTSTRAP_SUBDIR="${dstdir}/.bootstrap"
695
-            clone_embedded_repositories "${dstdir}/"
696
-            BOOTSTRAP_SUBDIR="${old_bootstrap}"
696
+         bootstrap_auto_update "${name}" "${url}" "${dstdir}"
697
+         flag=$?
698
+      fi
699
+   fi
697 700
 
698
-            bootstrap_auto_update "${name}" "${url}" "${dstdir}"
699
-            flag=$?
700
-         fi
701
+   if [ "${COMMAND}" = "fetch" -a "${DONT_RECURSE}" = "" ]
702
+   then
703
+      local old_bootstrap
701 704
 
702
-         fetch__run_build_settings_script "${name}" "${url}" "${dstdir}" "post-${COMMAND}" "$@"
703
-      fi
705
+      old_bootstrap="${BOOTSTRAP_SUBDIR}"
704 706
 
705
-      #
706
-      # means we recursed and should start fetch from top
707
-      #
708
-      if [ ${flag} -eq 0 ]
709
-      then
710
-         return 1
711
-      fi
712
-   else
713
-      ensure_clone_branch_is_correct "${dstdir}" "${branch}"
707
+      BOOTSTRAP_SUBDIR="${dstdir}/.bootstrap"
708
+      clone_embedded_repositories "${dstdir}/"
709
+      BOOTSTRAP_SUBDIR="${old_bootstrap}"
710
+   fi
714 711
 
715
-      log_fluff "Repository \"${dstdir}\" already exists"
712
+   if $run_script
713
+   then
714
+      fetch__run_build_settings_script "${name}" "${url}" "${dstdir}" "post-${COMMAND}" "$@"
716 715
    fi
717 716
 
718
-   return 0
717
+   return $flag
719 718
 }
720 719
 
721 720
 
... ...
@@ -844,11 +843,12 @@ ${clone}"
844 843
 }
845 844
 
846 845
 
846
+#
847 847
 # return 0, all cool
848 848
 # return 1, is symlinked
849 849
 # return 2, .bootstrap/repositories changed
850 850
 # return 3, is symlinked and .bootstrap/repositories changed
851
-
851
+#
852 852
 update()
853 853
 {
854 854
    local name
... ...
@@ -1211,20 +1211,23 @@ clone_embedded_repository()
1211 1211
          fetch__run_build_settings_script "${name}" "${url}" "${dstdir}" "post-${COMMAND}" "$@"
1212 1212
       fi
1213 1213
 
1214
-      # memo that we did this with a symlink
1214
+      #
1215
+      # memorize how we embedded the repository, need URL to identify
1216
+      # and the subdir, where it was stored
1217
+      #
1215 1218
       # store it inside the possibly recursed dstprefix dependency
1216
-      local symlinkcontent
1217
-      local symlinkdir
1218
-      local symlinkrelative
1219
+      #
1220
+      local content
1221
+      local embeddeddir
1219 1222
 
1220
-      symlinkrelative=`compute_relative "${CLONESFETCH_SUBDIR}/.embedded"`
1221
-      symlinkdir="${dstprefix}${CLONESFETCH_SUBDIR}/.embedded"
1222
-      mkdir_if_missing "${symlinkdir}"
1223
-      symlinkcontent="${symlinkrelative}/${dstdir}"
1223
+      embeddeddir="${dstprefix}${CLONESFETCH_SUBDIR}/.embedded"
1224
+      mkdir_if_missing "${embeddeddir}"
1225
+      content="${subdir}
1226
+${url}"
1224 1227
 
1225 1228
       # dont't use symlinks anymore
1226
-      log_fluff "Remember embedded repository \"${name}\" via \"${symlinkdir}/${name}\""
1227
-      exekutor echo "${symlinkcontent}" > "${symlinkdir}/${name}"
1229
+      log_fluff "Remember embedded repository \"${name}\" via \"${embeddeddir}/${name}\""
1230
+      exekutor echo "${content}" > "${embeddeddir}/${name}"
1228 1231
    else
1229 1232
       ensure_clone_branch_is_correct "${dstdir}" "${branch}"
1230 1233
 
... ...
@@ -349,11 +349,15 @@ realpath()
349 349
 _relative_path_between()
350 350
 {
351 351
     [ $# -ge 1 ] && [ $# -le 2 ] || return 1
352
+
352 353
     current="${2:+"$1"}"
353 354
     target="${2:-"$1"}"
355
+
354 356
     [ "$target" != . ] || target=/
357
+
355 358
     target="/${target##/}"
356 359
     [ "$current" != . ] || current=/
360
+
357 361
     current="${current:="/"}"
358 362
     current="/${current##/}"
359 363
     appendix="${target##/}"
... ...
@@ -373,9 +377,90 @@ _relative_path_between()
373 377
 }
374 378
 
375 379
 
380
+#
381
+# $1 is the directory, that we want to access relative from root
382
+# $2 is the root
383
+#
384
+# ex.   /usr/include /usr,  -> include
385
+# ex.   /usr/include /  -> /usr/include
386
+#
387
+# the routine can not deal with ../ and ./
388
+#
376 389
 relative_path_between()
377 390
 {
378
-   _relative_path_between "$2" "$1"
391
+   local  a
392
+   local  b
393
+
394
+   # remove trailing '/' it upsets the code
395
+
396
+   a="`echo "$1" | sed -e 's|/$||g'`"
397
+   b="`echo "$2" | sed -e 's|/$||g'`"
398
+
399
+   # the function can't do mixed paths
400
+
401
+   case "${a}" in
402
+      "")
403
+         internal_fail "Empty path"
404
+      ;;
405
+
406
+      ../*|*/..|*/../*|..)
407
+         internal_fail "Path \"${a}\" mustn't contain ../"
408
+      ;;
409
+
410
+      ./*|*/.|*/./*|.)
411
+         internal_fail "Path \"${a}\" mustn't contain ./"
412
+      ;;
413
+
414
+
415
+      /*)
416
+         case "${b}" in
417
+            "")
418
+               internal_fail "Empty path"
419
+            ;;
420
+
421
+            ../*|*/..|*/../*|..)
422
+               internal_fail "Path \"${b}\" mustn't contain ../"
423
+            ;;
424
+
425
+            ./*|*/.|*/./*|.)
426
+               internal_fail "Path \"${b}\" mustn't contain ./"
427
+            ;;
428
+
429
+
430
+            /*)
431
+            ;;
432
+
433
+            *)
434
+               internal_fail "Mixing absolute path \"${a}\" and relative path \"${b}\""
435
+            ;;
436
+         esac
437
+      ;;
438
+
439
+      *)
440
+         case "${b}" in
441
+            "")
442
+               internal_fail "Empty path"
443
+            ;;
444
+
445
+            ../*|*/..|*/../*|..)
446
+               internal_fail "Path \"${b}\" mustn't contain ../"
447
+            ;;
448
+
449
+            ./*|*/.|*/./*|.)
450
+               internal_fail "Path \"${b}\" mustn't contain ./"
451
+            ;;
452
+
453
+            /*)
454
+               internal_fail "Mixing relative path \"${a}\" and absolute path \"${b}\""
455
+            ;;
456
+
457
+            *)
458
+            ;;
459
+         esac
460
+      ;;
461
+   esac
462
+
463
+   _relative_path_between "${b}" "${a}"
379 464
 }
380 465
 
381 466
 
... ...
@@ -572,10 +657,12 @@ simplify_path()
572 657
    local final_components
573 658
    local final_path
574 659
 
575
-   components="`echo "${path}" | tr '/' '\012' | sed -e 's|$|/|'`"
576
-   final_components="`_simplify_components  "${components}"`"
577
-   final_path="`_path_from_components "${final_components}"`"
578
-
660
+   if [ ! -z "${path}" ]
661
+   then
662
+      components="`echo "${path}" | tr '/' '\012' | sed -e 's|$|/|'`"
663
+      final_components="`_simplify_components  "${components}"`"
664
+      final_path="`_path_from_components "${final_components}"`"
665
+   fi
579 666
    echo "${final_path}"
580 667
 }
581 668
 
... ...
@@ -242,7 +242,7 @@ EOF
242 242
 
243 243
    if [ "${open}" = "ASK" ]
244 244
    then
245
-      user_say_yes "Edit the ${C_MAGENTA}${C_BOLD}repositories${C_RESET_BOLD} file now ?"
245
+      user_say_yes "Edit the ${C_MAGENTA}${C_BOLD}repositories${C_WARNING} file now ?"
246 246
       if [ $? -eq 0 ]
247 247
       then
248 248
           open="YES"
... ...
@@ -31,7 +31,6 @@
31 31
 
32 32
 MULLE_BOOTSTRAP_INSTALL_SH="included"
33 33
 
34
-[ -z "${MULLE_BOOTSTRAP_BUILD_ENVIRONMENT_SH}" ] && . mulle-bootstrap-build-environment.sh
35 34
 
36 35
 
37 36
 install_usage()
... ...
@@ -30,6 +30,7 @@
30 30
 #
31 31
 MULLE_BOOTSTRAP_PROJECT_SH="included"
32 32
 
33
+
33 34
 project_usage()
34 35
 {
35 36
    cat <<EOF >&2
... ...
@@ -295,10 +295,10 @@ bury_zombies()
295 295
    fi
296 296
 }
297 297
 
298
+
298 299
 #
299 300
 # ###
300 301
 #
301
-
302 302
 mark_all_embedded_repositories_zombies()
303 303
 {
304 304
    local i
... ...
@@ -318,9 +318,9 @@ mark_all_embedded_repositories_zombies()
318 318
 
319 319
       for symlink in `ls -1d "${path}/"*`
320 320
       do
321
-         i="`cat "$symlink" 2>/dev/null`" || fail "Old style mulle-bootstrap files detected, \`mulle-bootstrap dist clean\` it ($PWD/$symlink)"
322
-         name="`basename -- "$i"`"
323
-         exekutor touch "${zombiepath}/${name}"
321
+         i="`head -1 "$symlink" 2>/dev/null`" || fail "Old style mulle-bootstrap files detected, \`mulle-bootstrap dist clean\` it ($PWD/$symlink)"
322
+         name="`basename -- "${i}"`"
323
+         exekutor cp "${symlink}" "${zombiepath}/${name}"
324 324
       done
325 325
    fi
326 326
 }
... ...
@@ -344,9 +344,9 @@ mark_embedded_repository_alive()
344 344
 
345 345
 bury_embedded_zombies()
346 346
 {
347
-   local dst
347
+   local dstprefix
348 348
 
349
-   dst="$1"
349
+   dstprefix="$1"
350 350
 
351 351
    local i
352 352
    local name
... ...
@@ -356,8 +356,9 @@ bury_embedded_zombies()
356 356
    local gravepath
357 357
    local path2
358 358
 
359
-      # first mark all repos as stale
359
+   # first mark all repos as stale
360 360
    zombiepath="${CLONESFETCH_SUBDIR}/.embedded/.zombies"
361
+
361 362
    if dir_has_files "${zombiepath}"
362 363
    then
363 364
       log_fluff "Burying embedded zombies into graveyard"
... ...
@@ -369,11 +370,17 @@ bury_embedded_zombies()
369 370
       do
370 371
          if [ -f "${i}" ]
371 372
          then
372
-            name="`basename -- "${i}"`"
373
-            dstdir="${dst}${name}"
373
+            log_info "CLONESFETCH_SUBDIR=${CLONESFETCH_SUBDIR}"
374
+            log_info "pwd=${PWD}"
375
+            log_info "i=${i}"
376
+            dstdir="`embedded_repository_subdir_from_file "${i}" "${CLONESFETCH_SUBDIR}/.embedded"`"
377
+            dstdir="${dstprefix}${dstdir}"
378
+            log_info "dstdir=${dstdir}"
374 379
 
375 380
             if [ -d "${dstdir}" -o -L "${dstdir}" ]
376 381
             then
382
+               name="`basename -- "${i}"`"
383
+
377 384
                if [ -e "${gravepath}/${name}" ]
378 385
                then
379 386
                   exekutor rm -rf "${gravepath}/${name}"
... ...
@@ -391,7 +398,7 @@ bury_embedded_zombies()
391 398
                exekutor rm "${CLONESFETCH_SUBDIR}/.embedded/${name}"
392 399
                log_info "Removed unused embedded repository ${C_MAGENTA}${C_BOLD}${name}${C_INFO} from \"${dstdir}\""
393 400
             else
394
-               log_fluff "\"${dstdir}\" embedded zombie vanished or never existed ($PWD)"
401
+               log_fluff "Embedded zombie \"${dstdir}\" vanished or never existed ($PWD)"
395 402
             fi
396 403
          fi
397 404
       done
... ...
@@ -409,18 +416,21 @@ bury_embedded_zombies()
409 416
 
410 417
 refresh_repositories()
411 418
 {
412
-   local branch
413 419
    local clone
414 420
    local clones
415 421
    local dstdir
416
-   local name
417 422
    local old
418
-   local scm
419
-   local tag
420
-   local url
421 423
 
422 424
    mark_all_repositories_zombies
423 425
 
426
+   # local variables for __parse_clone
427
+   local name
428
+   local url
429
+   local branch
430
+   local scm
431
+   local tag
432
+   local subdir
433
+
424 434
    old="${IFS:-" "}"
425 435
 
426 436
    clones="`read_fetch_setting "repositories"`"
... ...
@@ -455,27 +465,31 @@ _refresh_embedded_repositories()
455 465
 
456 466
    dstprefix="$1"
457 467
 
458
-   local branch
459 468
    local clone
460 469
    local clones
461
-   local dstdir
462
-   local name
463
-   local old
464
-   local scm
465
-   local subdir
466
-   local olddir
467
-   local tag
468
-   local url
469 470
 
470 471
    MULLE_BOOTSTRAP_SETTINGS_NO_AUTO="YES"
471 472
 
472
-   old="${IFS:-" "}"
473
-
474 473
    clones="`read_fetch_setting "embedded_repositories"`"
475
-   if [ "${clones}" != "" ]
474
+   if [ ! -z "${clones}" ]
476 475
    then
476
+
477
+      local old
478
+
479
+      old="${IFS:-" "}"
477 480
       IFS="
478 481
 "
482
+      # local variables for __parse_embedded_clone
483
+      local name
484
+      local url
485
+      local branch
486
+      local scm
487
+      local tag
488
+      local subdir
489
+
490
+      local dstdir
491
+      local olddir
492
+
479 493
       for clone in ${clones}
480 494
       do
481 495
          IFS="${old}"
... ...
@@ -484,13 +498,18 @@ _refresh_embedded_repositories()
484 498
 
485 499
          __parse_embedded_clone "${clone}"
486 500
 
487
-         dstdir="${dstprefix}${subdir}"
488
-         olddir="`embedded_repository_directory_in_repos "${name}"`"
489
-         if [ "${dstdir}" != "${olddir}" ]
501
+         olddir="`find_embedded_repository_subdir_in_repos "${url}"`"
502
+         if [ ! -z "${olddir}" ]
490 503
          then
491
-            log_warning "Embedded repository ${name} moved from ${olddir} to ${dstdir}. Refetch needed."
492
-         else
493
-            mark_embedded_repository_alive "${name}" "${dstdir}"
504
+            if [ "${subdir}" != "${olddir}" ]
505
+            then
506
+               if [ -z "${MULLE_BOOTSTRAP_WILL_FETCH}" ]
507
+               then
508
+                  log_info "Embedded repository ${name} should move from ${olddir} to ${subdir}. A refetch is needed."
509
+               fi
510
+            else
511
+               mark_embedded_repository_alive "${name}" "${dstprefix}${subdir}"
512
+            fi
494 513
          fi
495 514
       done
496 515
    fi
... ...
@@ -66,7 +66,7 @@ canonical_clone_name()
66 66
 
67 67
 count_clone_components()
68 68
 {
69
-  echo "$@" | tr ';' '\012' | wc -l | awk '{ print $1 }'
69
+   echo "$@" | tr ';' '\012' | wc -l | awk '{ print $1 }'
70 70
 }
71 71
 
72 72
 
... ...
@@ -78,19 +78,19 @@ url_from_clone()
78 78
 
79 79
 _name_part_from_clone()
80 80
 {
81
-   echo "$@" | cut '-d;' -f 2
81
+   echo "$@" | cut -s '-d;' -f 2
82 82
 }
83 83
 
84 84
 
85 85
 _branch_part_from_clone()
86 86
 {
87
-   echo "$@" | cut '-d;' -f 3
87
+   echo "$@" | cut -s '-d;' -f 3
88 88
 }
89 89
 
90 90
 
91 91
 _scm_part_from_clone()
92 92
 {
93
-   echo "$@" | cut '-d;' -f 4
93
+   echo "$@" | cut -s '-d;' -f 4
94 94
 }
95 95
 
96 96
 
... ...
@@ -137,45 +137,106 @@ scm_from_clone()
137 137
 }
138 138
 
139 139
 
140
-embedded_repository_directory_in_repos()
140
+embedded_repository_subdir_from_file()
141
+{
142
+   local path
143
+
144
+   path="$1"
145
+
146
+   [ -z "${path}" ] && internal_fail "Empty parameter"
147
+
148
+   head -1 "${path}"
149
+}
150
+
151
+
152
+embedded_repository_subdir_in_repos()
141 153
 {
142 154
    local filename
143
-   local owd
144 155
 
145 156
    filename="$1"
146
-   owd="$2"
147 157
 
148
-   local embedded
149
-   local linkfile
158
+   [ -z "${filename}" ] && internal_fail "Empty parameter"
159
+
150 160
    local relpath
151
-   local old
152
-   local owd
153 161
 
154 162
    relpath="${CLONESFETCH_SUBDIR}/.embedded/${filename}"
155 163
    if [ -f "${relpath}" ]
156 164
    then
157
-      linkfile="`cat "${relpath}"`"
158
-      embedded="`(cd "${CLONESFETCH_SUBDIR}/.embedded" ; absolutepath "${linkfile}")`"
159
-      embedded="`simplify_path "${embedded}"`"
160
-      embedded="`relative_path_between "${embedded}" "${owd}"`"
161
-      if [ -d "${embedded}" ]
165
+      embedded_repository_subdir_from_file "${relpath}"
166
+   fi
167
+}
168
+
169
+
170
+embedded_repository_url_in_repos()
171
+{
172
+   local filename
173
+
174
+   filename="$1"
175
+
176
+   local url
177
+   local relpath
178
+
179
+   relpath="${CLONESFETCH_SUBDIR}/.embedded/${filename}"
180
+   if [ -f "${relpath}" ]
181
+   then
182
+      #
183
+      # if only one line present, will retrieve that
184
+      #
185
+      tail -1 "${relpath}"
186
+   fi
187
+}
188
+
189
+#
190
+# search by url, may actually not exist though
191
+# CLONESFETCH_SUBDIR must have the proper dstprefix set
192
+#
193
+find_embedded_repository_subdir_in_repos()
194
+{
195
+   local url
196
+
197
+   url="$1"
198
+
199
+   local filename
200
+   local old
201
+
202
+   old="${IFS}"
203
+   IFS="
204
+"
205
+
206
+   for i in `fgrep -l -x "${url}" "${CLONESFETCH_SUBDIR}/.embedded/"* 2> /dev/null`
207
+   do
208
+      IFS="${old}"
209
+
210
+      #
211
+      # ensure that it's the URL that matched
212
+      #
213
+      match_url="`tail -1 "${i}"`"
214
+      if [ "${match_url}" = "${url}" ]
162 215
       then
163
-         echo "${embedded}"
216
+         embedded_repository_subdir_from_file "${i}"
217
+         return
164 218
       fi
165
-   fi
219
+   done
220
+
221
+   IFS="${old}"
166 222
 }
167 223
 
168 224
 
225
+#
226
+# look through embedded repositories
227
+# CLONESFETCH_SUBDIR must have the proper dstprefix set
228
+# used by clean, don't need deeply embedded repos
229
+#
169 230
 embedded_repository_directories_from_repos()
170 231
 {
232
+   local dstprefix
233
+
234
+   dstprefix="$1"
235
+
171 236
    local filename
172
-   local embedded
173
-   local linkfile
174
-   local relpath
175 237
    local old
176
-   local owd
238
+   local embedded
177 239
 
178
-   owd="`pwd -P`"
179 240
 
180 241
    old="${IFS}"
181 242
    IFS="
... ...
@@ -184,7 +245,15 @@ embedded_repository_directories_from_repos()
184 245
    do
185 246
       IFS="${old}"
186 247
 
187
-      embedded_repository_directory_in_repos "${filename}" "${owd}"
248
+      embedded="`embedded_repository_subdir_in_repos "${filename}"`"
249
+      if [ ! -z "${embedded}" ]
250
+      then
251
+         embedded="${dstprefix}${embedded}"
252
+         if [ -d "${embedded}" ]
253
+         then
254
+            echo "${embedded}"
255
+         fi
256
+      fi
188 257
    done
189 258
 
190 259
    IFS="${old}"
... ...
@@ -199,16 +268,10 @@ repository_directories_from_repos()
199 268
    old="${IFS}"
200 269
    IFS="
201 270
 "
271
+
202 272
    for filename in `ls -1 "${CLONESFETCH_SUBDIR}" 2> /dev/null`
203 273
    do
204
-      case "${filename}" in
205
-         .*)
206
-         ;;
207
-
208
-         *)
209
-            echo "${CLONESFETCH_SUBDIR}/$filename"
210
-         ;;
211
-      esac
274
+      echo "${CLONESFETCH_SUBDIR}/$filename"
212 275
    done
213 276
 
214 277
    IFS="${old}"
... ...
@@ -239,7 +302,7 @@ __parse_expanded_clone()
239 302
 
240 303
    case "${name}" in
241 304
       /*|~*|..*|.*)
242
-         fail "destination name of ${clone} looks fishy"
305
+         fail "Destination name \"${name}\" of repository ${name} looks fishy"
243 306
       ;;
244 307
    esac
245 308
 }
... ...
@@ -275,9 +338,10 @@ __parse_embedded_clone()
275 338
 
276 339
    subdir="`_name_part_from_clone "${clone}"`"
277 340
    subdir="`simplify_path "${subdir}"`"
341
+
278 342
    case "${subdir}" in
279 343
       /*|~*|..*|.*)
280
-         fail "destination directory of ${clone} looks fishy"
344
+         fail "Destination directory \"${subdir}\" of repository ${name} looks fishy"
281 345
       ;;
282 346
 
283 347
       "")
284 348
new file mode 100755
... ...
@@ -0,0 +1,70 @@
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_compute_relative()
17
+{
18
+  run_test ""            compute_relative ""
19
+
20
+  run_test ""            compute_relative "/"
21
+  run_test ".."          compute_relative "/."
22
+  run_test ".."          compute_relative "/./"
23
+  run_test "../.."       compute_relative "/foo/.."
24
+  run_test "../.."       compute_relative "/foo/../"
25
+  run_test "../../.."    compute_relative "/foo/../../"
26
+
27
+  run_test "../.."       compute_relative "/foo/bar"
28
+  run_test "../../../.." compute_relative "foo/../../bar"
29
+
30
+  run_test ".."          compute_relative "foo"
31
+  run_test "../.."       compute_relative "foo/bar"
32
+}
33
+
34
+
35
+test_relative_path_between()
36
+{
37
+  run_test "."      relative_path_between /a /a
38
+  run_test "."      relative_path_between /a /a/
39
+  run_test "."      relative_path_between /a/ /a
40
+  run_test "."      relative_path_between /a/ /a
41
+  run_test "b"      relative_path_between /a/b /a
42
+  run_test "b/c"    relative_path_between /a/b/c /a
43
+  run_test "../b"   relative_path_between /b /a
44
+  run_test "../b/c" relative_path_between /b/c /a
45
+
46
+  run_test ".."     relative_path_between /a /a/b
47
+  run_test "."      relative_path_between /a/b /a/b
48
+  run_test "c"      relative_path_between /a/b/c /a/b
49
+
50
+  run_test "../../b/c" relative_path_between /b/c /a/b
51
+  run_test "../../c"   relative_path_between /c /a/b
52
+
53
+  run_test "../.."  relative_path_between /a /a/b/c
54
+
55
+  run_test "."      relative_path_between a a
56
+  run_test "b/c"    relative_path_between a/b/c a
57
+
58
+  run_test ".."     relative_path_between a a/b
59
+  run_test "c"      relative_path_between a/b/c a/b
60
+
61
+  run_test "../.."  relative_path_between a a/b/c
62
+  run_test ".."     relative_path_between a/b a/b/c
63
+  run_test "../../a/b"     relative_path_between a/b c/d
64
+
65
+  run_test "../../.repos/.embedded" relative_path_between .repos/c/.repos/.embedded .repos/c/src/b_1
66
+
67
+}
68
+
69
+test_compute_relative
70
+test_relative_path_between
... ...
@@ -15,6 +15,8 @@ run_test()
15 15
 
16 16
 test_simplify_path()
17 17
 {
18
+  run_test "" simplify_path ""
19
+
18 20
   run_test "/" simplify_path "/"
19 21
   run_test "/" simplify_path "/."
20 22
   run_test "/" simplify_path "/./"
21 23
new file mode 100755
... ...
@@ -0,0 +1,126 @@
1
+#! /bin/sh
2
+
3
+
4
+# embedded repositories are
5
+setup()
6
+{
7
+   [ -d a ] && rm -rf a
8
+   [ -d b ] && rm -rf b
9
+   [ -d c ] && rm -rf c
10
+   [ -d d ] && rm -rf d
11
+
12
+   mkdir a
13
+   mkdir b
14
+   mkdir c
15
+   mkdir d
16
+
17
+   cd a
18
+      echo "# a" > README.md
19
+      git init
20
+      git add README.md
21
+      git commit -m "Mercyful Release"
22
+      cd ..
23
+
24
+   cd b
25
+      mulle-bootstrap init -n
26
+      echo "../a;src/a_1" > .bootstrap/embedded_repositories
27
+      echo "# b" > README.md
28
+      git init
29
+      git add README.md .bootstrap/embedded_repositories
30
+      git commit -m "Mercyful Release"
31
+      cd ..
32
+
33
+
34
+   cd c
35
+      mulle-bootstrap init -n
36
+      echo "../b;src/b_1" > .bootstrap/embedded_repositories
37
+      echo "# c" > README.md
38
+      git init
39
+      git add README.md .bootstrap/embedded_repositories
40
+      git commit -m "Mercyful Release"
41
+      cd ..
42
+
43
+   cd d
44
+      mulle-bootstrap init -n
45
+      echo "../c" > .bootstrap/repositories
46
+      echo "# d" > README.md
47
+      git init
48
+      git add README.md .bootstrap/repositories
49
+      git commit -m "Mercyful Release"
50
+      cd ..
51
+
52
+}
53
+
54
+
55
+fail()
56
+{
57
+   echo "$@" >&2
58
+   exit 1
59
+}
60
+
61
+
62
+setup
63
+
64
+echo ""
65
+echo ""
66
+echo "=== setup done ==="
67
+echo ""
68
+echo ""
69
+
70
+(
71
+   cd c ;
72
+   mulle-bootstrap fetch
73
+
74
+   [ -d src/b_1 ] || fail "b as src/b_1 failed to be embedded"
75
+   [ -d src/b_1/src/a_1 ] && fail "a was wrongly embedded"
76
+)
77
+
78
+echo ""
79
+echo ""
80
+echo "=== test 1 done ==="
81
+echo ""
82
+echo ""
83
+
84
+
85
+(
86
+   cd c ;
87
+   echo "../b;src/b_2" > .bootstrap/embedded_repositories ;
88
+   mulle-bootstrap fetch
89
+   [ -d src/b_1 ] && fail "b as src/b_1 failed to be removed"
90
+   [ -d src/b_2 ] || fail "b as src/b_2 failed to be added"
91
+)
92
+
93
+echo ""
94
+echo ""
95
+echo "=== test 2 done ==="
96
+echo ""
97
+echo ""
98
+
99
+
100
+(
101
+   cd d ;
102
+   mulle-bootstrap -a fetch
103
+   [ -d .repos/c/src/b_1 ] || fail "b as .repos/c/src/b_1 failed to be fetched"
104
+)
105
+
106
+echo ""
107
+echo ""
108
+echo "=== test 3 done ==="
109
+echo ""
110
+echo ""
111
+
112
+
113
+(
114
+   cd d ;
115
+   echo "../b;src/b_2" > .repos/c/.bootstrap/embedded_repositories ;
116
+   mulle-bootstrap -vvv fetch
117
+   [ -d .repos/c/src/b_1 ] && fail "b as .repos/c/src/b_1 failed to be removed"
118
+   [ -d .repos/c/src/b_2 ] || fail "b as .repos/c/src/b_2 failed to be added"
119
+)
120
+
121
+echo ""
122
+echo ""
123
+echo "=== test 4 done ==="
124
+echo ""
125
+echo ""
126
+
0 127
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+I am **a**