Last active
December 11, 2015 23:38
-
-
Save mshroyer/4677591 to your computer and use it in GitHub Desktop.
Script to create and update an OpenWrt Mercurial mirror from its existing git trunk and branch mirrors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| branches="attitude_adjustment backfire" | |
| # Destination repostiory location | |
| destination=/var/hg/mirrors/openwrt | |
| # Source repository locations | |
| source_dir=/var/git/mirrors/openwrt | |
| source_trunk="${source_dir}/trunk.git" | |
| source_attitude_adjustment="${source_dir}/attitude_adjustment.git" | |
| source_backfire="${source_dir}/backfire.git" | |
| # Intermediate cache repositories | |
| cache_dir=/home/mshroyer/openwrt_mirror | |
| cache_git_combined="${cache_dir}/git_combined" | |
| cache_hg_git="${cache_dir}/hg_git" | |
| cache_convert="${cache_dir}/hg_convert" | |
| cache_convert_branchmap="${cache_dir}/convert.branchmap" | |
| # Commit IDs on the trunk repo to which each branch is anchored | |
| parent_attitude_adjustment=684e620b003f605578e9bc575f09cfd8cb4ac9e2 | |
| parent_backfire=daa84485d8188ae882a985c39f062e6c3a8b1c92 | |
| # OpenWrt branch name | |
| branch_name=openwrt | |
| # Program names | |
| git=/usr/local/bin/git | |
| hg=/usr/local/bin/hg | |
| fetch_git_combined() { | |
| if [ ! -d "${cache_git_combined}" ]; then | |
| $git clone "${source_trunk}" "${cache_git_combined}" | |
| cd "${cache_git_combined}" | |
| $git branch -m master trunk | |
| for branch in $branches; do | |
| branch_source=`eval "echo \\\$source_\${branch}"` | |
| $git remote add $branch $branch_source | |
| $git remote update $branch | |
| branch_root=`$git rev-list --max-parents=0 ${branch}/master` | |
| branch_parent=`eval "echo \\\$parent_\${branch}"` | |
| echo "${branch_root} ${branch_parent}" >>.git/info/grafts | |
| $git checkout -b $branch --no-track "${branch}/master" | |
| done | |
| else | |
| cd "${cache_git_combined}" | |
| $git checkout trunk | |
| $git pull | |
| for branch in $branches; do | |
| $git branch -D $branch | |
| $git remote update $branch | |
| $git checkout -b $branch --no-track "${branch}/master" | |
| $git checkout trunk | |
| done | |
| fi | |
| for branch in $branches; do | |
| branch_parent=`eval "echo \\\$parent_\${branch}"` | |
| $git filter-branch -f "${branch_parent}..${branch}" | |
| done | |
| } | |
| fetch_hg_git() { | |
| if [ ! -d "${cache_hg_git}" ]; then | |
| $hg clone -U "${cache_git_combined}" "${cache_hg_git}" | |
| else | |
| cd "${cache_hg_git}" | |
| $hg pull "${cache_git_combined}" | |
| fi | |
| } | |
| fetch_hg_convert() { | |
| cat >"${cache_convert_branchmap}" <<EOF | |
| default $branch_name | |
| EOF | |
| $hg convert --config convert.hg.tagsbranch=0 \ | |
| --branchmap="${cache_convert_branchmap}" \ | |
| "${cache_hg_git}" "${cache_convert}" | |
| } | |
| fetch_hg_clone() { | |
| if [ ! -d "${destination}" ]; then | |
| $hg clone -U -b $branch_name "${cache_convert}" "${destination}" | |
| else | |
| cd "${destination}" | |
| $hg pull -b $branch_name "${cache_convert}" | |
| fi | |
| } | |
| fetch_git_combined | |
| fetch_hg_git | |
| fetch_hg_convert | |
| fetch_hg_clone |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment