sapling/tests/library-infinitepush.sh
Stanislau Hlebik 7dc24c7c82 infinitepush: backup local heads and bookmarks
Summary:
Backuping changesets is not enougn for restore. We also want to backup heads
and bookmarks to completely capture the state of the repo.

This diff is the first step in implementing this functionality. It adds new
bundle2 part which contains encoded dict (simple json encoding is used).
If value in the dict is empty then key is the bookmark pattern to delete.
If value is not empty then key is the bookmark name to save and value is a
node hash. The reason to put them in the same part is to make it possible to
delete and insert into indexapi in one transaction. It's also possible to pass
patterns to delete in part parameters but there is a bug in upstream hg that
limits parameters' size to 256 and we can potentially have longer bookmarks.

Local bookmarks are saved in infinitepush in the following form:
  infinitepush/backups/USERNAME/HOSTNAME/REPOROOT/bookmarks/LOCAL_BOOKMARK_NAME

Local heads are saved in infintiepush in the following form:
  infinitepush/backups/USERNAME/HOSTNAME/REPOROOTheads/HEAD_HASH

Hostname, username and repo root is necessary to distinguish different backups.

Test Plan: Run `test-infinitepush-*`

Reviewers: durham, rmcelroy, mitrandir, quark

Reviewed By: quark

Subscribers: quark, mjpieters, #sourcecontrol

Differential Revision: https://phabricator.intern.facebook.com/D4245080

Tasks: 12479677

Signature: t1:4245080:1480518959:aa199d67fac4e2cd2f543651ff56fdd649dac729
2016-12-01 08:44:57 -08:00

100 lines
2.3 KiB
Bash

scratchnodes() {
for node in `find ../repo/.hg/scratchbranches/index/nodemap/* | sort`; do
echo ${node##*/} `cat $node`
done
}
scratchbookmarks() {
for bookmark in `find ../repo/.hg/scratchbranches/index/bookmarkmap/* -type f | sort`; do
echo "${bookmark##*/bookmarkmap/} `cat $bookmark`"
done
}
setupcommon() {
extpath=`dirname $TESTDIR`
cp -r $extpath/infinitepush $TESTTMP
cp -r $extpath/infinitepush $TESTTMP
cat >> $HGRCPATH << EOF
[extensions]
infinitepush=$TESTTMP/infinitepush
[ui]
ssh = python "$TESTDIR/dummyssh"
[infinitepush]
branchpattern=re:scratch/.*
EOF
}
setupserver() {
cat >> .hg/hgrc << EOF
[infinitepush]
server=yes
indextype=disk
storetype=disk
EOF
}
setupsqlclienthgrc() {
cat << EOF > .hg/hgrc
[ui]
ssh=python "$TESTDIR/dummyssh"
[extensions]
infinitepush=$TESTTMP/infinitepush
[infinitepush]
branchpattern=re:scratch/.+
server=False
[paths]
default = ssh://user@dummy/server
EOF
}
setupsqlserverhgrc() {
cat << EOF > .hg/hgrc
[ui]
ssh=python "$TESTDIR/dummyssh"
[extensions]
infinitepush=$TESTTMP/infinitepush
[infinitepush]
branchpattern=re:scratch/.+
server=True
indextype=sql
storetype=disk
EOF
}
createdb() {
mysql -h $DBHOST -P $DBPORT -u $DBUSER -p"$DBPASS" -e "CREATE DATABASE IF NOT EXISTS $DBNAME;" 2>/dev/null
mysql -h $DBHOST -P $DBPORT -D $DBNAME -u $DBUSER -p"$DBPASS" -e '
DROP TABLE IF EXISTS nodestobundle;
DROP TABLE IF EXISTS bookmarkstonode;
DROP TABLE IF EXISTS bundles;
CREATE TABLE IF NOT EXISTS nodestobundle(
node CHAR(40) BINARY NOT NULL,
bundle VARCHAR(512) BINARY NOT NULL,
reponame CHAR(255) BINARY NOT NULL,
PRIMARY KEY(node, reponame));
CREATE TABLE IF NOT EXISTS bookmarkstonode(
node CHAR(40) BINARY NOT NULL,
bookmark VARCHAR(512) BINARY NOT NULL,
reponame CHAR(255) BINARY NOT NULL,
PRIMARY KEY(reponame, bookmark));
CREATE TABLE IF NOT EXISTS bundles(
bundle VARCHAR(512) BINARY NOT NULL,
reponame CHAR(255) BINARY NOT NULL,
PRIMARY KEY(bundle, reponame));' 2>/dev/null
}
setupdb() {
DBHOSTPORT=`$TESTDIR/getdb.sh` || exit 1
echo "sqlhost=$DBHOSTPORT" >> .hg/hgrc
echo "reponame=babar" >> .hg/hgrc
DBHOST=`echo $DBHOSTPORT | cut -d : -f 1`
DBPORT=`echo $DBHOSTPORT | cut -d : -f 2`
DBNAME=`echo $DBHOSTPORT | cut -d : -f 3`
DBUSER=`echo $DBHOSTPORT | cut -d : -f 4`
DBPASS=`echo $DBHOSTPORT | cut -d : -f 5-`
createdb
}