summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2012-11-26 15:08:16 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2012-11-26 15:08:16 -0500
commit217fb1c7ac68b70d7961546b59e04fee76031845 (patch)
treed3fdef8d97e0a06d506143d3765f3d99e17f75a2
parente34aed84b17c99fcf286e5d5f212374f335902e4 (diff)
work on pbs-absrepo-convert
-rw-r--r--config1
-rwxr-xr-xpbs-absrepo-convert150
-rwxr-xr-xpbs-absrepo-convert--filterarch2
3 files changed, 75 insertions, 78 deletions
diff --git a/config b/config
index e97e3e6..85c8003 100644
--- a/config
+++ b/config
@@ -1,6 +1,7 @@
[core]
cachedir = /var/cache/pbs
sourcedir = /var/pbs-sources
+ rewritedir = /var/pbs-rewrite
treedir = /var/pbs
[source "arch-packages"]
diff --git a/pbs-absrepo-convert b/pbs-absrepo-convert
index 97ef936..c03d58e 100755
--- a/pbs-absrepo-convert
+++ b/pbs-absrepo-convert
@@ -1,4 +1,4 @@
-#!/bin/bash -eu
+#!/bin/bash -euE
export TMPDIR="`mktemp -d --tmpdir pbs-absrepo-convert.XXXXXXXXXX`"
cleanup() {
@@ -16,19 +16,36 @@ abort() {
}
##
+# Usage: trailing-newline FILE
+#
+# Adds a trailing newline to ${FILE} if there isn't one.
+#
+# Useful because different versions of git are inconsistent about
+# when there is one on output.
+###
+trailing-newline() {
+ local file=$1
+ if [[ "`sed -n '$p' "$file"|wc -l`" = 0 ]]; then
+ echo >> "$file"
+ fi
+}
+
+##
# Usage: collect-data MODE
# MODE is either 'correct' or 'fast'
#
+# 'fast' may omit some packages that have been deleted.
+#
# Assumptions:
-# - currently in a working copy of the repo
-# - git branch "master" exists and is untouched
-# - TMPDIR is set
-# - file(s) exist in "${TMPDIR}/missing-packages.in/"
+# - currently in the working repo
+# Effected by:
+# - file ../missing-packages
# Effects:
+# - creates file "../find"
+# - creates file "../packages"
+# - creates file "../architectures"
+# Side effects:
# - creates file "${TMPDIR}/commits"
-# - creates file "${TMPDIR}/find"
-# - creates file "${TMPDIR}/packages"
-# - creates file "${TMPDIR}/architectures"
##
collect-data() {
msg "$(gettext "Collecting package data...")"
@@ -36,45 +53,44 @@ collect-data() {
local mode=$1
case "$mode" in
- correct)
- git log --pretty=format:'%H' master > "${TMPDIR}/commits";;
- fast)
- echo master > "${TMPDIR}/commits";;
- *)
- usage; return 1;;
+ correct) git log --pretty=format:'%H' master > "${TMPDIR}/commits";;
+ fast) git log -n1 --pretty=format:'%H' master > "${TMPDIR}/commits";;
+ *) usage; return 1;;
esac
+ trailing-newline "${TMPDIR}/commits"
# actual data collection ###############################################
local count="$(wc -l < "${TMPDIR}/commits")"
cat -n "${TMPDIR}/commits" | while read n commit; do
- printf '\rscanning commit %s (%d/%d)' "$commit" "$n" "$count" >> /dev/tty
+ printf "\\r$(gettext "Scanning commit %s (%d/%d)")" "$commit" "$n" "$count" >> /dev/tty
git ls-tree -rd --name-only "$commit"
- done | fgrep /repos/ | sort -u > "${TMPDIR}/find"
+ done | fgrep /repos/ | sort -u > ../find
echo # newline
# extract some things ##################################################
# packages
{
if [[ $mode = fast ]]; then
- cat "${TMPDIR}"/{packages,missing-packages}.in
+ cat ../{packages,missing-packages} 2>/dev/null || true
fi
- < "${TMPDIR}/find" sed -e 's|^\.||' -e 's|/.*||'
- } | sort -u > "${TMPDIR}/packages"
+ < ../find sed -e 's|^\.||' -e 's|/.*||'
+ } | sort -u > ../packages.tmp
+ mv ../packages{.tmp,}
# architectures
{
echo master
- < "${TMPDIR}/find" sed -e 's/.*-//' -e '/^any$/d'
- } | sort -u > "${TMPDIR}/architectures"
+ < ../find sed -e 's/.*-//' -e '/^any$/d'
+ } | sort -u > ../architectures
}
##
# Usage: convert-package SOURCE PACKAGE
+#
# Assumptions:
-# - currently in a working copy of the repo
-# - TMPDIR is set
+# - currently in the working repo
# Effects:
# - creates git branch "packages/${SOURCE}/${PACKAGE}"
-# - creates file "${TMPDIR}/packages-${PACKAGE}.commits"
+# - creates file "../packages-${PACKAGE}.commits"
# Side effects:
# - changes git working tree
# - prints output of git commands
@@ -84,32 +100,37 @@ convert-package() {
local source=$1
local package=$2
- local branch="packages/${source}/${package}"
+ local obranch="packages/${source}/${package}"
+ local ibranch
local dir
-
if git checkout "packages/${package}" &>/dev/null; then
# special case (common; optimization)
- git checkout -b "$branch"
- git branch -D "packages/${package}"
+ ibranch="packages/${package}"
dir=trunk
else
# general case (uncommon)
- git checkout -b "$branch" orig
+ ibranch=master
dir="${package}/trunk"
fi
- git filter-branch -f --prune-empty --subdirectory-filter "$dir" "$branch"
- git log --pretty=format:'%T %H' > "${TMPDIR}/packages-${package}.commits"
+ git rewrite-branch --svn "$ibranch" "$obranch" \
+ --prune-empty --subdirectory-filter "$dir"
+
+ if [[ $ibranch != master ]]; then
+ git branch -D "$ibranch"
+ fi
+
+ git log "$obranch" --pretty=format:'%T %H' \
+ > "../packages-${package}.commits"
}
##
-# Usage: convert-packages SOURCE
+# Usage: convert-packages SOURCENAME
# Assumptions:
-# - meets assumptions of `convert-package`
-# - TMPDIR is set
-# - file "${TMPDIR}/packages" contains a newline-separated list of packages
+# - currently in the working repo
+# - file "../packages" contains a newline-separated list of packages
# Effects:
-# - runs `convert-package` for every package listed in "${TMPDIR}/packages"
+# - runs `convert-package` for every package listed in "../packages"
# - prints status updates about what it is doing
##
convert-packages() {
@@ -117,8 +138,8 @@ convert-packages() {
[[ $# = 1 ]] || { usage; return 1; }
local source=$1
- local count="$(wc -l < "${TMPDIR}/packages")"
- cat -n "${TMPDIR}/packages" | while read n package; do
+ local count="$(wc -l < ../packages)"
+ cat -n ../packages | while read n package; do
msg2 "$(gettext "(%d/%d) %s")" "$n" "$count" "$package"
convert-package "$source" "$package"
done
@@ -127,10 +148,10 @@ convert-packages() {
##
# Usage: convert-arch ARCH
# Assumptions:
-# - currently in a working copy of the repo
+# - currently in the working repo
+# - file "../packages-${PACKAGE}.commits" exists for every package
# Effects:
# - creates git branch "${ARCH}"
-# - TMPDIR is set
# - creates file "${TMPDIR}/missing-packages/${ARCH}"
# Side effects:
# - changes git working tree
@@ -143,10 +164,8 @@ convert-arch() {
mkdir -p "${TMPDIR}/missing-packages"
touch "${TMPDIR}/missing-packages/${arch}.tmp"
- git checkout orig
- git checkout -b "$arch"
- git filter-branch -f --tree-filter \
- "pbs-absrepo-convert--filterarch $arch" "$arch"
+ git rewrite-branch master "$arch" \
+ --tree-filter "pbs-absrepo-convert--filterarch $arch" "$arch"
sort -u \
< "${TMPDIR}/missing-packages/${arch}.tmp" \
@@ -157,9 +176,8 @@ convert-arch() {
##
# Usage: convert-arches
# Assumptions:
-# - meets assumptions of `convert-arch`
+# - currently in the working repo
# - 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
@@ -175,47 +193,25 @@ convert-arches() {
done
}
-##
-# Usage: copy-metatada SOURCEDIR SOURCE FILE
-# Assumptions:
-# - TMPDIR is set
-# Effects:
-# - creates "${TMPDIR}/${FILE}.in"
-##
-copy-metadata() {
- [[ $# = 3 ]] || { usage; return 1; }
- local sourcedir=$1
- local source=$2
- local file=$3
-
- if [[ -f "${sourcedir}/${source}.${file}" ]]; then
- cp "${sourcedir}/${source}.${file}" "${TMPDIR}/${file}.in"
- else
- touch "${TMPDIR}/${file}.in"
- fi
-}
-
main() {
trap abort EXIT
[[ $# = 1 ]] || { usage; return 1; }
local source=$1
- local cachedir="$(pbs-plumb-config get core.cachedir)"
+ local cache="$(pbs-plumb-config get core.cachedir)/${source}.git"
+ local workdir="$(pbs-plumb-config get core.rewritedir)/${source}"
local sourcedir="$(pbs-plumb-config get core.sourcedir)"
- # init #################################################################
- copy-metadata "$sourcedir" "$source" missing-packages
- copy-metadata "$sourcedir" "$source" packages
-
- msg "$(gettext "Creating working copy...")"
- git clone "${cachedir}/${source}.git" "${TMPDIR}/repo"
- cd "${TMPDIR}/repo"
- git checkout -b orig
- collect-data fast
- git branch -D master
+ # init ###################################d##############################
+ if [[ ! -d "${workdir}" ]]; then
+ msg "$(gettext "Creating working copy...")"
+ git clone "$cache" "${workdir}/repo"
+ fi
+ cd "${workdir}/repo"
# main #################################################################
+ collect-data fast
convert-packages "$source"
convert-arches
diff --git a/pbs-absrepo-convert--filterarch b/pbs-absrepo-convert--filterarch
index 4288014..5940fa0 100755
--- a/pbs-absrepo-convert--filterarch
+++ b/pbs-absrepo-convert--filterarch
@@ -20,7 +20,7 @@ rm -rf *
cat "$tree" | while read mode type treehash path; do
package="${path%%/*}"
repo="$(sed -n "s/^${package} //p" "$repos")"
- commithash="$(sed -n "s/^${treehash} //p" "${TMPDIR}/packages-${package}.commits")"
+ commithash="$(sed -n "s/^${treehash} //p" "../packages-${package}.commits")"
if [[ -n "$commithash" ]]; then
mkdir -p "$repo"
git submodule add ./ "${repo}/${package}"