On Thu, May 9, 2013 at 11:40 AM, Martin Langhoff
wrote:
> With the exaction of the final destination, I want to expire reports
> that are old and successfully transferred.
OK, that took some effort to make work. Make sure you are not using
reflogs (or that reflogs are promptly expired).
# right after a successful push of all heads to the receiving server...
for head in $(git branch|sed 's/^..//'); do
# FIXME period
graft_sha1=$(git log --until=one.month.ago -n1 --pretty=format:%H ${head})
if [[ -z "$graft_sha1" ]]; then
# nothing to prune
continue
fi
# is it already grafted?
if grep -q "^${graft_sha1} " "${GIT_DIR}/info/grafts" &>/dev/null ; then
# don't duplicate the graft
continue
fi
some_grafted='true'
# prep empty commit
# skip git read-tree --empty, we get the same with
export GIT_INDEX_FILE=/tmp/ppg-emptytree.$$
empty_tree="$(git write-tree)"
rm ${GIT_INDEX_FILE}
unset GIT_INDEX_FILE
empty_commit=$(git commit-tree -m empty ${empty_tree})
echo "${graft_sha1} ${empty_commit}" >> ${GIT_DIR}/info/grafts
done
if [[ -z "$some_grafted" ]]; then
# nothing to do
exit 0
fi
# ppg-repack makes the unreachable objects "loose"
# (it is git-repack hacked to remove --keep-true-parents),
# git prune --expire actually deletes them
$PPG_EXEC_PATH/ppg-repack -AFfd
git prune --expire=now
### Cleanup stale grafts
# current grafts points are reachable,
# pruned graft points (made obsolete by a newer graft)
# cannot be retrieved and git cat-file exit code is 128
touch ${GIT_DIR}/info/grafts.tmp.$$
while read line; do
graftpoint=$(echo "${line}" | cut -d' ' -f1)
if git cat-file commit ${graftpoint} &>/dev/null ; then
echo ${line} >> ${GIT_DIR}/info/grafts.tmp.$$
fi
done < "${GIT_DIR}/info/grafts"
if [ -s ${GIT_DIR}/info/grafts.tmp.$$ ]; then
mv ${GIT_DIR}/info/grafts.tmp.$$ ${GIT_DIR}/info/grafts
fi
Perhaps it helps someone else trying to run git as a spooler :-)
cheers,
m
--
martin.langh...@gmail.com
- ask interesting questions
- don't get distracted with shiny stuff - working code first
~ http://docs.moodle.org/en/User:Martin_Langhoff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html