Skip to content

Commit 8cddf0b

Browse files
committed
BREAKING CHANGE: Change structure of package directory, by adding a site parent directory
So, for example, `tj/git-extras` will now be cloned to `$BPM_PACKAGES_PATH/github.com/tj/git-extras` instead of `$BPM_PACKAGES_PATH/tj/git-extras`. Not only does this prevent cross-site conflicts (albeit, they would be quite uncommon), this also makes the repositories site-addressable (without performing a Git command to check the remote URL). This makes it possible to efficiently implement #14 and address bug #36
1 parent ff8aac2 commit 8cddf0b

26 files changed

+409
-311
lines changed

pkg/lib/commands/do-add.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ do-add() {
2727
local ref="$REPLY4"
2828

2929
log.info "Installing '$repoSpec'"
30-
do-plumbing-clone "$uri" "$package" $ref
31-
do-plumbing-add-deps "$package"
32-
do-plumbing-link-bins "$package"
33-
do-plumbing-link-completions "$package"
34-
do-plumbing-link-man "$package"
30+
do-plumbing-clone "$uri" "$site/$package" $ref
31+
do-plumbing-add-deps "$site/$package"
32+
do-plumbing-link-bins "$site/$package"
33+
do-plumbing-link-completions "$site/$package"
34+
do-plumbing-link-man "$site/$package"
3535
done
3636
}

pkg/lib/commands/do-list.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ do-list() {
3131
fi
3232
done
3333
else
34-
for package_path in "$BPM_PACKAGES_PATH"/*/*; do
34+
for package_path in "$BPM_PACKAGES_PATH"/*/*/*; do
35+
local site="${package_path%/*}"; site="${site%/*}"; site="${site##*/}"
3536
local user="${package_path%/*}"; user="${user##*/}"
3637
local repository="${package_path##*/}"
37-
printf "%s\n" "$user/$repository"
38+
local package="$user/$repository"
39+
40+
printf "%s\n" "$site/$package"
3841
done
3942
fi
4043
}

pkg/lib/commands/do-package-path.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# shellcheck shell=bash
22

33
bpm-package-path() {
4-
local package="$1"
5-
ensure.non_zero 'package' "$package"
4+
local pkg="$1"
5+
ensure.non_zero 'package' "$pkg"
66

7-
printf "%s\n" "$BPM_PACKAGES_PATH/$package"
7+
printf "%s\n" "$BPM_PACKAGES_PATH/$site/$pkg"
88
}

pkg/lib/commands/do-plumbing-add-deps.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
# Example: DEPS=username/repo1:otheruser/repo2
88

99
do-plumbing-add-deps() {
10-
local package="$1"
11-
ensure.non_zero 'package' "$package"
12-
ensure.package_exists "$package"
10+
local id="$1"
11+
ensure.non_zero 'id' "$id"
12+
ensure.package_exists "$id"
1313

1414
local -a deps=()
1515

16-
local bpm_toml_file="$BPM_PACKAGES_PATH/$package/bpm.toml"
17-
local package_sh_file="$BPM_PACKAGES_PATH/$package/package.sh"
16+
local bpm_toml_file="$BPM_PACKAGES_PATH/$id/bpm.toml"
17+
local package_sh_file="$BPM_PACKAGES_PATH/$id/package.sh"
1818

1919
if [ -f "$bpm_toml_file" ]; then
2020
if util.get_toml_array "$bpm_toml_file" 'dependencies'; then
@@ -26,7 +26,7 @@ do-plumbing-add-deps() {
2626
fi
2727
fi
2828

29-
log.info "Installing dependencies for '$package'"
29+
log.info "Installing dependencies for '$id'"
3030
for dep in "${deps[@]}"; do
3131
do-add "$dep"
3232
done

pkg/lib/commands/do-plumbing-clone.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
do-plumbing-clone() {
44
local uri="$1"
5-
local package="$2"
5+
local id="$2"
66
local ref="$3"
77

88
ensure.non_zero 'uri' "$uri"
9+
# TODO: ensure.non_zero 'id'
910

10-
if [ -e "$BPM_PACKAGES_PATH/$package" ]; then
11-
die "Package '$package' is already present"
11+
if [ -e "$BPM_PACKAGES_PATH/$id" ]; then
12+
die "Package '$id' is already present"
1213
fi
1314

1415
local -a git_args=(--recursive)
@@ -22,8 +23,8 @@ do-plumbing-clone() {
2223
fi
2324

2425
git_args+=("$uri")
25-
git_args+=("$BPM_PACKAGES_PATH/$package")
26+
git_args+=("$BPM_PACKAGES_PATH/$id")
2627

27-
log.info "Cloning package '$package'"
28+
log.info "Cloning package '$id'"
2829
git clone "${git_args[@]}"
2930
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# shellcheck shell=bash
22

33
do-plumbing-link-bins() {
4-
local pkg="$1"
5-
ensure.non_zero 'pkg' "$pkg"
4+
local id="$1"
5+
ensure.non_zero 'id' "$id"
66

7-
abstract.bins 'link' "$pkg"
7+
abstract.bins 'link' "$id"
88
}

pkg/lib/commands/do-remove.sh

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,49 @@ do-remove() {
77

88
for repoSpec; do
99
# If is local directory
10+
# TODO: do this for upgrade as well
1011
if [ -d "$repoSpec" ]; then
1112
local fullPath=
1213
fullPath="$(util.readlink "$repoSpec")"
1314
fullPath="${fullPath%/}"
1415

16+
# TODO: make this a funcion, share it with do-list
17+
local site="${fullPath%/*}"; site="${site%/*}"; site="${site##*/}"
1518
local user="${fullPath%/*}"; user="${user##*/}"
1619
local repository="${fullPath##*/}"
17-
if [ "$fullPath" = "$BPM_PACKAGES_PATH/$user/$repository" ]; then
18-
do_actual_removal "$user/$repository"
20+
local package="$user/$repository"
21+
22+
if [ "$fullPath" = "$BPM_PACKAGES_PATH/$site/$package" ]; then
23+
do_actual_removal "$site/$package"
1924
fi
2025
else
21-
local site= user= repository= ref=
22-
util.parse_package_full "$repoSpec"
23-
IFS=':' read -r site user repository ref <<< "$REPLY"
24-
25-
if [ -d "$BPM_PACKAGES_PATH/$user/$repository" ]; then
26-
do_actual_removal "$user/$repository"
27-
elif [ -e "$BPM_PACKAGES_PATH/$user/$repository" ]; then
28-
rm -f "$BPM_PACKAGES_PATH/$user/$repository"
26+
util.construct_clone_url "$repoSpec"
27+
local uri="$REPLY1"
28+
local site="$REPLY2"
29+
local package="$REPLY3"
30+
local ref="$REPLY4"
31+
32+
if [ -d "$BPM_PACKAGES_PATH/$site/$package" ]; then
33+
do_actual_removal "$site/$package"
34+
elif [ -e "$BPM_PACKAGES_PATH/$site/$package" ]; then
35+
rm -f "$BPM_PACKAGES_PATH/$site/$package"
2936
else
30-
die "Package '$user/$repository' is not installed"
37+
die "Package '$site/$package' is not installed"
3138
fi
3239
fi
3340
done
3441
}
3542

3643
do_actual_removal() {
37-
local package="$1"
44+
local id="$1"
3845

39-
log.info "Uninstalling '$package'"
40-
do-plumbing-unlink-man "$package"
41-
do-plumbing-unlink-bins "$package"
42-
do-plumbing-unlink-completions "$package"
46+
log.info "Uninstalling '$id'"
47+
do-plumbing-unlink-man "$id"
48+
do-plumbing-unlink-bins "$id"
49+
do-plumbing-unlink-completions "$id"
4350

44-
rm -rf "${BPM_PACKAGES_PATH:?}/$package"
45-
if ! rmdir "${BPM_PACKAGES_PATH:?}/${package%/*}"; then
51+
rm -rf "${BPM_PACKAGES_PATH:?}/$id"
52+
if ! rmdir -p "${BPM_PACKAGES_PATH:?}/$id"; then
4653
# Do not exit on failure
4754
:
4855
fi

pkg/lib/commands/do-upgrade.sh

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,21 @@ do-upgrade() {
3434
fi
3535

3636
for repoSpec; do
37-
local site= user= repository= ref=
38-
util.parse_package_full "$repoSpec"
39-
IFS=':' read -r site user repository ref <<< "$REPLY"
40-
local package="$user/$repository"
37+
util.construct_clone_url "$repoSpec"
38+
local uri="$REPLY1"
39+
local site="$REPLY2"
40+
local package="$REPLY3"
41+
local ref="$REPLY4"
4142

4243
log.info "Upgrading '$repoSpec'"
43-
do-plumbing-remove-deps "$package"
44-
do-plumbing-unlink-bins "$package"
45-
do-plumbing-unlink-completions "$package"
46-
do-plumbing-unlink-man "$package"
47-
git -C "$BPM_PACKAGES_PATH/$user/$repository" pull
48-
do-plumbing-add-deps "$package"
49-
do-plumbing-link-bins "$package"
50-
do-plumbing-link-completions "$package"
51-
do-plumbing-link-man "$package"
44+
do-plumbing-remove-deps "$site/$package"
45+
do-plumbing-unlink-bins "$site/$package"
46+
do-plumbing-unlink-completions "$site/$package"
47+
do-plumbing-unlink-man "$site/$package"
48+
git -C "$BPM_PACKAGES_PATH/$site/$package" pull
49+
do-plumbing-add-deps "$site/$package"
50+
do-plumbing-link-bins "$site/$package"
51+
do-plumbing-link-completions "$site/$package"
52+
do-plumbing-link-man "$site/$package"
5253
done
5354
}

pkg/lib/util/abstract-bins.sh

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22

33
abstract.bins() {
44
local action="$1"
5-
local package="$2"
5+
local id="$2"
66
ensure.non_zero 'action' "$action"
7-
ensure.non_zero 'package' "$package"
7+
ensure.non_zero 'id' "$id"
88

99
case "$action" in
1010
link)
11-
log.info "Linking bin files for '$package'"
11+
log.info "Linking bin files for '$id'"
1212
;;
1313
unlink)
14-
log.info "Unlinking bin files for '$package'"
14+
log.info "Unlinking bin files for '$id'"
1515
;;
1616
esac
1717

1818
local -a bins=()
1919
local remove_extension=
2020

21-
local bpm_toml_file="$BPM_PACKAGES_PATH/$package/bpm.toml"
22-
local package_sh_file="$BPM_PACKAGES_PATH/$package/package.sh"
21+
local bpm_toml_file="$BPM_PACKAGES_PATH/$id/bpm.toml"
22+
local package_sh_file="$BPM_PACKAGES_PATH/$id/package.sh"
2323

2424
if [ -f "$bpm_toml_file" ]; then
2525
if util.get_toml_string "$bpm_toml_file" 'binRemoveExtensions'; then
@@ -30,15 +30,15 @@ abstract.bins() {
3030

3131
if util.get_toml_array "$bpm_toml_file" 'binDirs'; then
3232
for dir in "${REPLIES[@]}"; do
33-
for file in "$BPM_PACKAGES_PATH/$package/$dir"/*; do
33+
for file in "$BPM_PACKAGES_PATH/$id/$dir"/*; do
3434
abstract.bins_do_action "$action" "$file" "$remove_extensions"
3535
done
3636
done
3737

3838
return
3939
fi
4040

41-
abstract.bins_search_heuristics "$action" "$package" "$remove_extensions"
41+
abstract.bins_search_heuristics "$action" "$id" "$remove_extensions"
4242
elif [ -f "$package_sh_file" ]; then
4343
if util.extract_shell_variable "$package_sh_file" 'REMOVE_EXTENSION'; then
4444
remove_extensions="$REPLY"
@@ -48,13 +48,13 @@ abstract.bins() {
4848
IFS=':' read -ra bins <<< "$REPLY"
4949

5050
for file in "${bins[@]}"; do
51-
abstract.bins_do_action "$action" "$BPM_PACKAGES_PATH/$package/$file" "$remove_extensions"
51+
abstract.bins_do_action "$action" "$BPM_PACKAGES_PATH/$id/$file" "$remove_extensions"
5252
done
5353
else
54-
abstract.bins_search_heuristics "$action" "$package" "$remove_extensions"
54+
abstract.bins_search_heuristics "$action" "$id" "$remove_extensions"
5555
fi
5656
else
57-
abstract.bins_search_heuristics "$action" "$package" "$remove_extensions"
57+
abstract.bins_search_heuristics "$action" "$id" "$remove_extensions"
5858
fi
5959
}
6060

@@ -64,19 +64,19 @@ abstract.bins() {
6464
# @arg $2 Whether to remove extensions
6565
abstract.bins_search_heuristics() {
6666
local action="$1"
67-
local package="$2"
67+
local id="$2"
6868
local remove_extensions="$3"
6969

70-
if [ -d "$BPM_PACKAGES_PATH/$package/bin" ]; then
71-
for file in "$BPM_PACKAGES_PATH/$package"/bin/*; do
70+
if [ -d "$BPM_PACKAGES_PATH/$id/bin" ]; then
71+
for file in "$BPM_PACKAGES_PATH/$id"/bin/*; do
7272
abstract.bins_do_action "$action" "$file" "$remove_extensions"
7373
done
74-
elif [ -d "$BPM_PACKAGES_PATH/$package/bins" ]; then
75-
for file in "$BPM_PACKAGES_PATH/$package"/bins/*; do
74+
elif [ -d "$BPM_PACKAGES_PATH/$id/bins" ]; then
75+
for file in "$BPM_PACKAGES_PATH/$id"/bins/*; do
7676
abstract.bins_do_action "$action" "$file" "$remove_extensions"
7777
done
7878
else
79-
for file in "$BPM_PACKAGES_PATH/$package"/*; do
79+
for file in "$BPM_PACKAGES_PATH/$id"/*; do
8080
if [ -x "$file" ]; then
8181
abstract.bins_do_action "$action" "$file" "$remove_extensions"
8282
fi

pkg/lib/util/abstract-completions.sh

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22

33
abstract.completions() {
44
local action="$1"
5-
local package="$2"
5+
local id="$2"
66
ensure.non_zero 'action' "$action"
7-
ensure.non_zero 'package' "$package"
8-
ensure.package_exists "$package"
7+
ensure.non_zero 'id' "$id"
8+
ensure.package_exists "$id"
99

1010
case "$action" in
1111
link)
12-
log.info "Linking completion files for '$package'"
12+
log.info "Linking completion files for '$id'"
1313
;;
1414
unlink)
15-
log.info "Unlinking completion files for '$package'"
15+
log.info "Unlinking completion files for '$id'"
1616
;;
1717
esac
1818

19-
local bpm_toml_file="$BPM_PACKAGES_PATH/$package/bpm.toml"
20-
local package_sh_file="$BPM_PACKAGES_PATH/$package/package.sh"
19+
local bpm_toml_file="$BPM_PACKAGES_PATH/$id/bpm.toml"
20+
local package_sh_file="$BPM_PACKAGES_PATH/$id/package.sh"
2121

2222
# Get completion directories
2323
if [ -f "$bpm_toml_file" ]; then
2424
if util.get_toml_array "$bpm_toml_file" 'completionDirs'; then
2525
for dir in "${REPLIES[@]}"; do
26-
for file in "$BPM_PACKAGES_PATH/$package/$dir"/*; do
26+
for file in "$BPM_PACKAGES_PATH/$id/$dir"/*; do
2727
local fileName="${file##*/}"
2828

2929
if [[ $fileName == *.@(sh|bash) ]]; then
@@ -34,7 +34,7 @@ abstract.completions() {
3434
done
3535
done
3636
else
37-
abstract.completions_search_heuristics "$action" "$package" 'all'
37+
abstract.completions_search_heuristics "$action" "$id" 'all'
3838
fi
3939
elif [ -f "$package_sh_file" ]; then
4040
local -a bash_completion_files=() zsh_completion_files=()
@@ -43,33 +43,33 @@ abstract.completions() {
4343
IFS=':' read -ra bash_completion_files <<< "$REPLY"
4444

4545
for file in "${bash_completion_files[@]}"; do
46-
abstract.completions_do_action_bash "$action" "$BPM_PACKAGES_PATH/$package/$file"
46+
abstract.completions_do_action_bash "$action" "$BPM_PACKAGES_PATH/$id/$file"
4747
done
4848
else
49-
abstract.completions_search_heuristics "$action" "$package" 'bash'
49+
abstract.completions_search_heuristics "$action" "$id" 'bash'
5050
fi
5151

5252
if util.extract_shell_variable "$package_sh_file" 'ZSH_COMPLETIONS'; then
5353
IFS=':' read -ra zsh_completion_files <<< "$REPLY"
5454

5555
for file in "${zsh_completion_files[@]}"; do
56-
abstract.completions_do_action_zsh "$action" "$BPM_PACKAGES_PATH/$package/$file"
56+
abstract.completions_do_action_zsh "$action" "$BPM_PACKAGES_PATH/$id/$file"
5757
done
5858
else
59-
abstract.completions_search_heuristics "$action" "$package" 'zsh'
59+
abstract.completions_search_heuristics "$action" "$id" 'zsh'
6060
fi
6161
else
62-
abstract.completions_search_heuristics "$action" "$package" 'all'
62+
abstract.completions_search_heuristics "$action" "$id" 'all'
6363
fi
6464
}
6565

6666
abstract.completions_search_heuristics() {
6767
local action="$1"
68-
local package="$2"
68+
local id="$2"
6969
local type="$3"
7070

7171
for completion_dir in completion completions contrib/completion contrib/completions; do
72-
for file in "$BPM_PACKAGES_PATH/$package/$completion_dir"/*; do
72+
for file in "$BPM_PACKAGES_PATH/$id/$completion_dir"/*; do
7373
local fileName="${file##*/}"
7474

7575
if [[ $fileName == *.@(sh|bash) ]] && [[ $type == all || $type == bash ]]; then

0 commit comments

Comments
 (0)