summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2012-11-02 23:20:39 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2012-11-02 23:20:39 -0400
commit6a55fd31d6983b6e44276d0472cbe51677d977e3 (patch)
treeff50764ad1de93ef403d9773fc88c0325ac64631
parent06fbc63477803a7323e57fd3663937dd1be88d39 (diff)
clean up pbs-absrepo-convert
-rwxr-xr-xpbs-absrepo-convert137
-rwxr-xr-xpbs-absrepo-convert--list2
2 files changed, 95 insertions, 44 deletions
diff --git a/pbs-absrepo-convert b/pbs-absrepo-convert
index 16349ad..0b34980 100755
--- a/pbs-absrepo-convert
+++ b/pbs-absrepo-convert
@@ -10,7 +10,7 @@ trap cleanup EXIT
. /usr/bin/libremessages
abort() {
- echo
+ echo # force a fresh line
error "$(gettext "Aborting...")"
cleanup
}
@@ -32,17 +32,23 @@ collect-data-gc() {(
done
mv packages.new packages
mv repo-arch.new repo-arch
+ rm -f collect-data-filter-branch.done
)}
##
# Usage: collect-data
# Assumptions:
-# 1. Currently in a working copy of the repo
-# 2. git branch "master" exists and is untouched
-# 3. TMPDIR is set and exists
+# - currently in a working copy of the repo
+# - git branch "master" exists and is untouched
+# - TMPDIR is set and exists
+# Effects:
+# - creates file "${TMPDIR}/packages"
+# - creates file "${TMPDIR}/repo-arch"
+# - creates file "${TMPDIR}/architectures"
##
collect-data() {
msg "$(gettext "Collecting package data...")"
+ [[ $# = 0 ]] || { usage; return 1; }
collect-data-gc &
git filter-branch --tree-filter pbs-absrepo-convert--list master
# notify collect-data-gc that filter-branch is done
@@ -52,72 +58,113 @@ collect-data() {
sleep 10;
done
# extract some data from those files
- < "${TMPDIR}/repo-arch" sed -e 's/.*/-/' -e '/^any$/d' | sort -u > "${TMPDIR}/arches"
- { echo master; cat "${TMPDIR}/arches"; } > "${TMPDIR}/arches.all"
+ {
+ echo master
+ < "${TMPDIR}/repo-arch" sed -e 's/.*/-/' -e '/^any$/d'
+ } | sort -u > "${TMPDIR}/architectures"
+}
+
+##
+# Usage: convert-package SOURCE PACKAGE
+# Assumptions:
+# - currently in a working copy of the repo
+# - TMPDIR is set
+# Effects:
+# - creates git branch "packages/${SOURCE}/${PACKAGE}"
+# - creates file "${TMPDIR}/packages-${PACKAGE}.commits"
+# Side effects:
+# - changes git working tree
+# - prints output of git commands
+##
+convert-package() {
+ [[ $# = 2 ]] || { usage; return 1; }
+ local source=$1
+ local package=$2
+
+ local branch="packages/${source}/${package}"
+ local dir
+
+ if git checkout "packages/${package}" &>/dev/null; then
+ # special case (common; optimization)
+ git checkout -b "$branch"
+ git branch -D "packages/${package}"
+ dir=trunk
+ else
+ # general case (uncommon)
+ git checkout -b "$branch" orig
+ dir="${package}/trunk"
+ fi
+ git filter-branch -f --prune-empty --subdirectory-filter "$dir" "$branch"
+
+ git log --pretty=format:'%T %H' > "${TMPDIR}/packages-${package}.commits"
}
##
# Usage: convert-packages SOURCE
# Assumptions:
-# 1. Currently in a working copy of the repo
-# 2. TMPDIR is set, and collect-data has been run on it
+# - meets assumptions of `convert-package`
+# - TMPDIR is set
+# - file "${TMPDIR}/packages" contains a newline-separated list of packages
+# Effects:
+# - runs `convert-package` for every package listed in "${TMPDIR}/packages"
+# - prints status updates about what it is doing
##
convert-packages() {
msg "$(gettext "Converting packages...")"
- [[ $# != 1 ]] && { usage; return 1; }
+ [[ $# = 1 ]] || { usage; return 1; }
local source=$1
- local ibranch
- local obranch
- local dir
-
local count="$(wc -l < "${TMPDIR}/packages")"
cat -n "${TMPDIR}/packages" | while read n package; do
msg2 "$(gettext "(%d/%d) %s")" "$n" "$count" "$package"
- if git checkout "packages/${package}" &>/dev/null; then
- # common case (optimization)
- ibranch=orig
- obranch="packages/${package}"
- dir=trunk
- else
- # general (uncommon) case
- ibranch="packages/${package}"
- obranch="packages/${source}/${package}"
- dir="${package}/trunk"
- fi
- git checkout -b "$obranch" "$ibranch"
- if [[ $ibranch != orig ]]; then
- git branch -D "$ibranch"
- fi
- git filter-branch -f --prune-empty --subdirectory-filter "$dir" "$obranch"
-
- git log --pretty=format:'%T %H' > "${TMPDIR}/packages-${package}.commits"
+ convert-package "$source" "$package"
done
}
##
+# Usage: convert-arch ARCH
+# Assumptions:
+# - currently in a working copy of the repo
+# Effects:
+# - creates git branch "${ARCH}"
+# Side effects:
+# - changes git working tree
+# - prints output of git commands
+##
+convert-arch() {
+ [[ $# = 1 ]] || { usage; return 1; }
+ local arch=$1
+
+ git checkout orig
+ git checkout -b "$arch"
+ git filter-branch -f --tree-filter \
+ "pbs-absrepo-convert--treefilter $arch" "$arch"
+}
+
+##
# Usage: convert-arches
# Assumptions:
-# 1. Currently in a working copy of the repo
-# 2. TMPDIR is set, and collect-data has been run on it
-# 3. ${TMPDIR}/packages-PACKAGE.commits exists for every package
+# - meets assumptions of `convert-arch`
+# - file "${TMPDIR}/architectures" contains a newline-separated list of arches
+# - file "${TMPDIR}/packages-${PACKAGE}.commits" exists for every package
+# Effects:
+# - runs `convert-arch` for every arch listed in "${TMPDIR}/architectures"
+# - prints status updates about what it is doing
##
convert-arches() {
msg "$(gettext "Converting architectures...")"
+ [[ $# = 0 ]] || { usage; return 1; }
- local count="$(wc -l < "${TMPDIR}/arches.all")"
- cat -n "${TMPDIR}/arches.all" | while read n arch; do
+ local count="$(wc -l < "${TMPDIR}/architectures")"
+ cat -n "${TMPDIR}/architectures" | while read n arch; do
msg2 "$(gettext "(%d/%d) %s")" "$n" "$count" "$arch"
- git checkout orig
- git checkout -b "$arch"
- git filter-branch -f --tree-filter \
- "pbs-absrepo-convert--treefilter $arch" "$arch"
+ convert-arch "$arch"
done
}
main() {
trap abort EXIT
- [[ $# != 1 ]] && { usage; return 1; }
+ [[ $# = 1 ]] || { usage; return 1; }
local source=$1
local cachedir="$(pbs-plumb-config get core.cachedir)"
@@ -141,9 +188,13 @@ main() {
msg "$(gettext "Copying into source directory...")"
[[ -d "$sourcedir" ]] || mkdir -p "$sourcedir"
git clone --mirror "${TMPDIR}/repo" "${sourcedir}/${source}.new.git"
- [[ -d "${sourcedir}/${source}.git" ]] && mv "${sourcedir}/${source}"{,.old}.git
+ if [[ -d "${sourcedir}/${source}.git" ]]; then
+ mv "${sourcedir}/${source}"{,.old}.git
+ fi
mv "${sourcedir}/${source}"{.new,}.git
- [[ -d "${sourcedir}/${source}.old.git" ]] && rm -rf "${sourcedir}/${source}".old.git
+ if [[ ! -d "${sourcedir}/${source}.old.git" ]]; then
+ rm -rf "${sourcedir}/${source}".old.git
+ fi
trap cleanup EXIT
}
diff --git a/pbs-absrepo-convert--list b/pbs-absrepo-convert--list
index 527568a..645c351 100755
--- a/pbs-absrepo-convert--list
+++ b/pbs-absrepo-convert--list
@@ -1,6 +1,6 @@
#!/bin/bash
-ls -1 > "${TMPDIR}/packages.tmp.${GIT_COMMIT}"
+printf '%s\n' * > "${TMPDIR}/packages.tmp.${GIT_COMMIT}"
find */repos/* -type d -printf '%f\n' >> "${TMPDIR}/repo-arch.tmp.${GIT_COMMIT}"
mv "${TMPDIR}/packages.tmp.${GIT_COMMIT}" "${TMPDIR}/packages.new.${GIT_COMMIT}"