Mercurial > hg
view mercurial/cffi/mpatch.py @ 46335:25be21ec6c65
share: rework config options to be much clearer and easier
Recently I implemented various boolean configs which control how to behave when
there is a share-safe mismatch between source and share repository. Mismatch
means that source supports share-safe where as share does not or vice versa.
However, while discussion and documentation we realized that it's too
complicated and there are some combinations of values which makes no sense.
We decided to introduce a config option with 4 possible values which
makes controlling and understanding things easier.
The config option `share.safe-mismatch.source-{not-}safe` can have
following 4 values:
* abort (default): error out if there is mismatch
* allow: allow to work with respecting share source configuration
* {up|down}grade-abort: try to {up|down}grade, if it fails, abort
* {up|down}grade-allow: try to {up|down}grade, if it fails, continue in allow
mode
I am not sure if I can explain 3 config options which I deleted right now in
just 5 lines which is a sign of how complex they became.
No test changes demonstrate that functionality is same, only names have changed.
Differential Revision: https://phab.mercurial-scm.org/D9785
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Mon, 18 Jan 2021 21:37:20 +0530 |
parents | 687b865b95ad |
children | 521ac0d7047f |
line wrap: on
line source
# mpatch.py - CFFI implementation of mpatch.c # # Copyright 2016 Maciej Fijalkowski <fijall@gmail.com> # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. from __future__ import absolute_import from ..pure.mpatch import * from ..pure.mpatch import mpatchError # silence pyflakes from . import _mpatch ffi = _mpatch.ffi lib = _mpatch.lib @ffi.def_extern() def cffi_get_next_item(arg, pos): all, bins = ffi.from_handle(arg) container = ffi.new(b"struct mpatch_flist*[1]") to_pass = ffi.new(b"char[]", str(bins[pos])) all.append(to_pass) r = lib.mpatch_decode(to_pass, len(to_pass) - 1, container) if r < 0: return ffi.NULL return container[0] def patches(text, bins): lgt = len(bins) all = [] if not lgt: return text arg = (all, bins) patch = lib.mpatch_fold(ffi.new_handle(arg), lib.cffi_get_next_item, 0, lgt) if not patch: raise mpatchError(b"cannot decode chunk") outlen = lib.mpatch_calcsize(len(text), patch) if outlen < 0: lib.mpatch_lfree(patch) raise mpatchError(b"inconsistency detected") buf = ffi.new(b"char[]", outlen) if lib.mpatch_apply(buf, text, len(text), patch) < 0: lib.mpatch_lfree(patch) raise mpatchError(b"error applying patches") res = ffi.buffer(buf, outlen)[:] lib.mpatch_lfree(patch) return res