#!/bin/bash set -eou pipefail # Example: # ./workspace-pack-hg-base.sh https://hg.openjdk.java.net/jmc/jmc jmc-jmc URL=$1 NAME=$2 UPSTREAM_NAME=$NAME-upstream # Enable aggressive repository format for Mercurial. Cloning the repository into # this format would take a while. This is mostly convenient for the CI jobs that # repackage the workspaces, but not for user clones HG_OPTS="--config=format.generaldelta=1 --config=format.aggressivemergedeltas=1" # Clone the repository, if it does not exist yet. if [ ! -d $UPSTREAM_NAME ]; then hg $HG_OPTS clone $URL $UPSTREAM_NAME fi # Perform the very first pull of the repository. This would already merge some # metadata using general+aggressive deltas. Make sure repository does not have # working copy checked up, only the metadata itself. cd $UPSTREAM_NAME hg $HG_OPTS pull hg update null cd .. # Perform the *second* clone of the repository. This apparently repackages the # manifest and metadata to a much more compact form. Make sure working copy is # not materialized, an that we use the non-local clone that actually rewires # metadata. This clone would record the "local" repo as parent, overwrite it # with the upstream repo URL. rm -rf $NAME hg $HG_OPTS clone --pull --uncompressed -U $UPSTREAM_NAME $NAME echo -e "[paths]\ndefault = $URL" > $NAME/.hg/hgrc # Package the repository. tar -c -f $NAME.tar $NAME # Finally, compress the whole thing with the max compression available. This # probably clashes with Mercurial's own storage compression, and it would be # interesting to somehow request the metadata compressor to unpack the repository # internal metadata for this compressor to work on raw stream. That is what # "hg bundle" apparently does? We are working with the repository copy itself, # so we have to be content with whatever compression we can get. pxz -9 $NAME.tar # Verification: unpack the resulting tarball and check repository is still fine rm -rf temp mkdir -p temp cd temp tar xJf ../$NAME.tar.xz cd $NAME hg update hg verify cd ../../ rm -rf temp # Cleanup temporary file rm -rf $NAME