Mercurial > hg
view tests/test-githelp.t @ 40326:fed697fa1734
sqlitestore: file storage backend using SQLite
This commit provides an extension which uses SQLite to store file
data (as opposed to revlogs).
As the inline documentation describes, there are still several
aspects to the extension that are incomplete. But it's a start.
The extension does support basic clone, checkout, and commit
workflows, which makes it suitable for simple use cases.
One notable missing feature is support for "bundlerepos." This is
probably responsible for the most test failures when the extension
is activated as part of the test suite.
All revision data is stored in SQLite. Data is stored as zstd
compressed chunks (default if zstd is available), zlib compressed
chunks (default if zstd is not available), or raw chunks (if
configured or if a compressed delta is not smaller than the raw
delta). This makes things very similar to revlogs.
Unlike revlogs, the extension doesn't yet enforce a limit on delta
chain length. This is an obvious limitation and should be addressed.
This is somewhat mitigated by the use of zstd, which is much faster
than zlib to decompress.
There is a dedicated table for storing deltas. Deltas are stored
by the SHA-1 hash of their uncompressed content. The "fileindex" table
has columns that reference the delta for each revision and the base
delta that delta should be applied against. A recursive SQL query
is used to resolve the delta chain along with the delta data.
By storing deltas by hash, we are able to de-duplicate delta storage!
With revlogs, the same deltas in different revlogs would result in
duplicate storage of that delta. In this scheme, inserting the
duplicate delta is a no-op and delta chains simply reference the
existing delta.
When initially implementing this extension, I did not have
content-indexed deltas and deltas could be duplicated across files
(just like revlogs). When I implemented content-indexed deltas, the
size of the SQLite database for a full clone of mozilla-unified
dropped:
before: 2,554,261,504 bytes
after: 2,488,754,176 bytes
Surprisingly, this is still larger than the bytes size of revlog
files:
revlog files: 2,104,861,230 bytes
du -b: 2,254,381,614
I would have expected storage to be smaller since we're not limiting
delta chain length and since we're using zstd instead of zlib. I
suspect the SQLite indexes and per-column overhead account for the
bulk of the differences. (Keep in mind that revlog uses a 64-byte
packed struct for revision index data and deltas are stored without
padding. Aside from the 12 unused bytes in the 32 byte node field,
revlogs are pretty efficient.) Another source of overhead is file
name storage. With revlogs, file names are stored in the filesystem.
But with SQLite, we need to store file names in the database. This is
roughly equivalent to the size of the fncache file, which for the
mozilla-unified repository is ~34MB.
Since the SQLite database isn't append-only and since delta chains
can reference any delta, this opens some interesting possibilities.
For example, we could store deltas in reverse, such that fulltexts
are stored for newer revisions and deltas are applied to reconstruct
older revisions. This is likely a more optimal storage strategy for
version control, as new data tends to be more frequently accessed
than old data. We would obviously need wire protocol support for
transferring revision data from newest to oldest. And we would
probably need some kind of mechanism for "re-encoding" stores. But
it should be doable.
This extension is very much experimental quality. There are a handful
of features that don't work. It probably isn't suitable for day-to-day
use. But it could be used in limited cases (e.g. read-only checkouts
like in CI). And it is also a good proving ground for alternate
storage backends. As we continue to define interfaces for all things
storage, it will be useful to have a viable alternate storage backend
to see how things shake out in practice.
test-storage.py passes on Python 2 and introduces no new test failures on
Python 3. Having the storage-level unit tests has proved to be insanely
useful when developing this extension. Those tests caught numerous bugs
during development and I'm convinced this style of testing is the way
forward for ensuring alternate storage backends work as intended. Of
course, test coverage isn't close to what it needs to be. But it is
a start. And what coverage we have gives me confidence that basic store
functionality is implemented properly.
Differential Revision: https://phab.mercurial-scm.org/D4928
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 09 Oct 2018 08:50:13 -0700 |
parents | cfa93fbbe9b4 |
children | eddff539f5be |
line wrap: on
line source
$ cat >> $HGRCPATH << EOF > [extensions] > githelp = > EOF $ hg init repo $ cd repo $ echo foo > test_file $ mkdir dir $ echo foo > dir/file $ echo foo > removed_file $ echo foo > deleted_file $ hg add -q . $ hg commit -m 'bar' $ hg bookmark both $ touch both $ touch untracked_file $ hg remove removed_file $ rm deleted_file githelp on a single command should succeed $ hg githelp -- commit hg commit $ hg githelp -- git commit hg commit githelp should fail nicely if we don't give it arguments $ hg githelp abort: missing git command - usage: hg githelp -- <git command> [255] $ hg githelp -- git abort: missing git command - usage: hg githelp -- <git command> [255] githelp on a command with options should succeed $ hg githelp -- commit -pm "abc" hg commit --interactive -m 'abc' githelp on a command with standalone unrecognized option should succeed with warning $ hg githelp -- commit -p -v ignoring unknown option -v hg commit --interactive githelp on a command with unrecognized option packed with other options should fail with error $ hg githelp -- commit -pv abort: unknown option 'v' packed with other options (please try passing the option as its own flag: -v) [255] githelp for git rebase --skip $ hg githelp -- git rebase --skip hg revert --all -r . hg rebase --continue githelp for git commit --amend (hg commit --amend pulls up an editor) $ hg githelp -- commit --amend hg commit --amend githelp for git commit --amend --no-edit (hg amend does not pull up an editor) $ hg githelp -- commit --amend --no-edit hg amend githelp for git checkout -- . (checking out a directory) $ hg githelp -- checkout -- . note: use --no-backup to avoid creating .orig files hg revert . githelp for git checkout "HEAD^" (should still work to pass a rev) $ hg githelp -- checkout "HEAD^" hg update .^ githelp checkout: args after -- should be treated as paths no matter what $ hg githelp -- checkout -- HEAD note: use --no-backup to avoid creating .orig files hg revert HEAD githelp for git checkout with rev and path $ hg githelp -- checkout "HEAD^" -- file.txt note: use --no-backup to avoid creating .orig files hg revert -r .^ file.txt githelp for git with rev and path, without separator $ hg githelp -- checkout "HEAD^" file.txt note: use --no-backup to avoid creating .orig files hg revert -r .^ file.txt githelp for checkout with a file as first argument $ hg githelp -- checkout test_file note: use --no-backup to avoid creating .orig files hg revert test_file githelp for checkout with a removed file as first argument $ hg githelp -- checkout removed_file note: use --no-backup to avoid creating .orig files hg revert removed_file githelp for checkout with a deleted file as first argument $ hg githelp -- checkout deleted_file note: use --no-backup to avoid creating .orig files hg revert deleted_file githelp for checkout with a untracked file as first argument $ hg githelp -- checkout untracked_file note: use --no-backup to avoid creating .orig files hg revert untracked_file githelp for checkout with a directory as first argument $ hg githelp -- checkout dir note: use --no-backup to avoid creating .orig files hg revert dir githelp for checkout when not in repo root $ cd dir $ hg githelp -- checkout file note: use --no-backup to avoid creating .orig files hg revert file $ cd .. githelp for checkout with an argument that is both a file and a revision $ hg githelp -- checkout both hg update both githelp for checkout with the -p option $ hg githelp -- git checkout -p xyz hg revert -i -r xyz $ hg githelp -- git checkout -p xyz -- abc note: use --no-backup to avoid creating .orig files hg revert -i -r xyz abc githelp for checkout with the -f option and a rev $ hg githelp -- git checkout -f xyz hg update -C xyz $ hg githelp -- git checkout --force xyz hg update -C xyz githelp for checkout with the -f option without an arg $ hg githelp -- git checkout -f hg revert --all $ hg githelp -- git checkout --force hg revert --all githelp for grep with pattern and path $ hg githelp -- grep shrubbery flib/intern/ hg grep shrubbery flib/intern/ githelp for reset, checking ~ in git becomes ~1 in mercurial $ hg githelp -- reset HEAD~ hg update .~1 $ hg githelp -- reset "HEAD^" hg update .^ $ hg githelp -- reset HEAD~3 hg update .~3 $ hg githelp -- reset --mixed HEAD note: --mixed has no meaning since Mercurial has no staging area hg update . $ hg githelp -- reset --soft HEAD note: --soft has no meaning since Mercurial has no staging area hg update . $ hg githelp -- reset --hard HEAD hg update --clean . githelp for git show --name-status $ hg githelp -- git show --name-status hg log --style status -r . githelp for git show --pretty=format: --name-status $ hg githelp -- git show --pretty=format: --name-status hg status --change . githelp for show with no arguments $ hg githelp -- show hg export githelp for show with a path $ hg githelp -- show test_file hg cat test_file githelp for show with not a path: $ hg githelp -- show rev hg export rev githelp for show with many arguments $ hg githelp -- show argone argtwo hg export argone argtwo $ hg githelp -- show test_file argone argtwo hg cat test_file argone argtwo githelp for show with --unified options $ hg githelp -- show --unified=10 hg export --config diff.unified=10 $ hg githelp -- show -U100 hg export --config diff.unified=100 githelp for show with a path and --unified $ hg githelp -- show -U20 test_file hg cat test_file --config diff.unified=20 githelp for stash drop without name $ hg githelp -- git stash drop hg shelve -d <shelve name> githelp for stash drop with name $ hg githelp -- git stash drop xyz hg shelve -d xyz githelp for whatchanged should show deprecated message $ hg githelp -- whatchanged -p this command has been deprecated in the git project, thus isn't supported by this tool githelp for git branch -m renaming $ hg githelp -- git branch -m old new hg bookmark -m old new When the old name is omitted, git branch -m new renames the current branch. $ hg githelp -- git branch -m new hg bookmark -m `hg log -T"{activebookmark}" -r .` new Branch deletion in git strips commits $ hg githelp -- git branch -d hg strip -B $ hg githelp -- git branch -d feature hg strip -B feature -B $ hg githelp -- git branch --delete experiment1 experiment2 hg strip -B experiment1 -B experiment2 -B githelp for reuse message using the shorthand $ hg githelp -- git commit -C deadbeef hg commit -M deadbeef githelp for reuse message using the the long version $ hg githelp -- git commit --reuse-message deadbeef hg commit -M deadbeef githelp for apply with no options $ hg githelp -- apply hg import --no-commit githelp for apply with directory strip custom $ hg githelp -- apply -p 5 hg import --no-commit -p 5 git merge-base $ hg githelp -- git merge-base --is-ancestor ignoring unknown option --is-ancestor note: ancestors() is part of the revset language (learn more about revsets with 'hg help revsets') hg log -T '{node}\n' -r 'ancestor(A,B)' githelp for git blame $ hg githelp -- git blame hg annotate -udl githelp for add $ hg githelp -- git add hg add $ hg githelp -- git add -p note: Mercurial will commit when complete, as there is no staging area in Mercurial hg commit --interactive $ hg githelp -- git add --all note: use hg addremove to remove files that have been deleted hg add githelp for reflog $ hg githelp -- git reflog hg journal note: in hg commits can be deleted from repo but we always have backups $ hg githelp -- git reflog --all hg journal --all note: in hg commits can be deleted from repo but we always have backups