#!/usr/bin/env bash # Copyright (c) 2005, Intel Corporation, James Ketrenos function die() { ret=$1 shift echo -e $@>&2 exit $ret } function copy-object() { dir=$(echo $1 | sed -e 's#\(..\).*#\1/#') obj=$(echo $1 | sed -e 's#..\(.*\)#\1#') [ ! -e ${2}objects/${dir}${obj} ] && \ return 1 if [ -e ${3}objects/${dir}${obj} ]; then [ "$warn" ] && echo "$1 already exists in $3." return 0 fi [ ! -d ${3}objects/${dir} ] && \ (mkdir -p ${3}objects/${dir} || return 1) cp -a ${2}objects/${dir}${obj} ${3}objects/${dir} || return 1 } [ "$1" ] || die 1 \ "usage: git-make-overlay dst-repo [SHA1]\n\n"\ "Where dst-repo is the target directory to store the overlay\n"\ "repository and SHA1 is the 'base' of the tree you want to create the\n"\ "delta against.\n"\ "\n"\ "If not provided, the script will compute the merge base between\n"\ "the parent (.git/refs/heads/parent) and the current HEAD (which would\n"\ "typically be the same).\n"\ "\n"\ "For example:\n"\ " % child=\$(cat .git/HEAD)\n"\ " % parent=\$(cat .git/refs/heads/parent)\n"\ " % git-make-overlay ../overlay \$(git-merge-base \$child \$parent)\n"\ "\n"\ "The resulting overlay will be populated with the following files:\n"\ "\n"\ " .git/objects\t\tContaining all objects not contained in parent.\n"\ " .git/refs/ancestors\tParental lineage to root repository.\n"\ " .git/refs/heads/master\tSHA for the tip of this overlay.\n"\ "\n" [ -d ".git" ] || die 2 ".git repository not found." dst=$1 echo $dst | grep -ne "/\$" || dst="$1/" echo $dst | grep -ne "\.git/\$" || dst="${dst}.git/" [ ! -d $dst ] && (mkdir -p $dst || die 3 "mkdir: error creating '$dst'") shift if [ "$1" ]; then base="$1" else base="$(git-merge-base $(cat .git/HEAD) $(cat .git/refs/heads/parent))" fi head=$(cat .git/HEAD) echo -e \ "Creating overlay from:\n"\ "\t$base ->\n"\ "\t\t$head (HEAD)\nin\n"\ "\t$dst\n" (git-rev-list --objects $head ^$base || die 2 "git-rev-list failed!") | while read sha rest; do copy-object $sha .git/ $dst || die 5 "copy-object failed on $sha!" type=$(git-cat-file -t $sha) echo -e "$sha\t$type\t$rest" done mkdir -p ${dst}refs/heads || die 5 "Error creating refs/heads" cat .git/HEAD > ${dst}refs/heads/master ln -sf refs/heads/master ${dst}HEAD cp .git/refs/ancestors ${dst}refs/ancestors echo "done."