Mercurial > hg
view contrib/python-hook-examples.py @ 30350:358cda0af6ee
util: create new abstraction for compression engines
Currently, util.py has "compressors" and "decompressors" dicts
mapping compression algorithms to callables returning objects that
perform well-defined operations. In addition, revlog.py has code
for calling into a compressor or decompressor explicitly. And, there
is code in the wire protocol for performing zlib compression.
The 3rd party lz4revlog extension has demonstrated the utility of
supporting alternative compression formats for revlog storage. But
it stops short of supporting lz4 for bundles and the wire protocol.
There are also plans to support zstd as a general compression
replacement.
So, there appears to be a market for a unified API for registering
compression engines. This commit starts the process of establishing
one.
This commit establishes a base class/interface for defining
compression engines and how they will be used. A collection class
to hold references to registered compression engines has also been
introduced.
The built-in zlib, bz2, truncated bz2, and no-op compression engines
are registered with a singleton instance of the collection class.
The compression engine API will change once consumers are ported
to the new API and some common patterns can be simplified at the
engine API level. So don't get too attached to the API...
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 07 Nov 2016 18:31:39 -0800 |
parents | 2b585677220e |
children | 1a184b727aff |
line wrap: on
line source
''' Examples of useful python hooks for Mercurial. ''' from __future__ import absolute_import from mercurial import ( patch, util, ) def diffstat(ui, repo, **kwargs): '''Example usage: [hooks] commit.diffstat = python:/path/to/this/file.py:diffstat changegroup.diffstat = python:/path/to/this/file.py:diffstat ''' if kwargs.get('parent2'): return node = kwargs['node'] first = repo[node].p1().node() if 'url' in kwargs: last = repo['tip'].node() else: last = node diff = patch.diff(repo, first, last) ui.write(patch.diffstat(util.iterlines(diff)))