Skip to content

Instantly share code, notes, and snippets.

@mapio mapio/hg_archive.sh
Last active Aug 29, 2015

Embed
What would you like to do?
How to "archive" an initial segment of a Mercurial repository history.
# let's assume that we have an "original" repo and that we want to
# create a new "archvied" repo with a first release corresponding to what
# happened in the original repo in revisions O:ARCHIVE, plus all the
# releases (ARCHIVE+1):tip in the original repo.
# first remove the cruft from the previous run
rm -rf original archived
# now create the "original" repository that will contain a
# single file, the content of such file will be a number
# ranging from 0 to 10, committed at every change
hg init original
cd original
for i in $(seq 0 10); do echo $i > file.txt; hg ci -Am"V $i" ; done
cd ..
# now we want to archive the first ARCHIVE releases...
ARCHIVE=5
# first export all the changes $(( $ARCHIVE + 1 )):tip to a patchfile
hg -R original export --git -r $(( $ARCHIVE + 1 )):tip > patch
# then archive the repo at revision $ARCHIVE in the archived directory
hg -R original archive -r $ARCHIVE archived
# turn now such directory to a repo
cd archived
rm -f .hg_archival.txt # this is created by the archive command
hg init
# if we now commit the repo content, this first commit will
# correspond to the changesets 0:$ARCHIVE in the original repo
hg ci -Am"V 0-$ARCHIVE"
# finally, we import the remaining changesets
hg import ../patch
# as a check, let's see what is the history of the archived repo
hg log -r 0:tip --template '{desc}\n'
# the last step gives the following output
$ hg log -r 0:tip --template '{desc}\n'
V 0-5
V 6
V 7
V 8
V 9
V 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.