def get(self, name, node): """Fetches the full text revision contents of the given name+node pair. If the full text doesn't exist, throws a KeyError. Under the hood, this uses getdeltachain() across all the stores to build up a full chain to produce the full text. """ assert isinstance(name, str) assert isinstance(node, bytes) chain = self.getdeltachain(name, node) if chain[-1][ChainIndicies.BASENODE] != nullid: # If we didn't receive a full chain, throw raise KeyError((name, hex(node))) # The last entry in the chain is a full text, so we start our delta # applies with that. fulltext = chain.pop()[ChainIndicies.DATA] text = fulltext while chain: delta = chain.pop()[ChainIndicies.DATA] text = mdiff.patches(text, [delta]) return text
def test1(a, b): d = mdiff.textdiff(a, b) if not d: raise ValueError("empty") c = mdiff.patches(a, [d]) if c != b: raise ValueError("bad")
def assert_bdiff_applies(self, a, b): d = mdiff.textdiff(a, b) c = a if d: c = mdiff.patches(a, [d]) self.assertEqual( c, b, ("bad diff+patch result from\n %r to\n " "%r: \nbdiff: %r\npatched: %r" % (a, b, d, c[:200])), )
def dopatch(text, bins): if not cache: r.clearcaches() mdiff.patches(text, bins)
def perfrevlogrevision(ui, repo, file_, rev=None, cache=None, **opts): """Benchmark obtaining a revlog revision. Obtaining a revlog revision consists of roughly the following steps: 1. Compute the delta chain 2. Obtain the raw chunks for that delta chain 3. Decompress each raw chunk 4. Apply binary patches to obtain fulltext 5. Verify hash of fulltext This command measures the time spent in each of these phases. """ if opts.get("changelog") or opts.get("manifest"): file_, rev = None, file_ elif rev is None: raise error.CommandError("perfrevlogrevision", "invalid arguments") r = cmdutil.openrevlog(repo, "perfrevlogrevision", file_, opts) # _chunkraw was renamed to _getsegmentforrevs. try: segmentforrevs = r._getsegmentforrevs except AttributeError: segmentforrevs = r._chunkraw node = r.lookup(rev) rev = r.rev(node) def getrawchunks(data, chain): start = r.start length = r.length inline = r._inline iosize = r._io.size buffer = util.buffer offset = start(chain[0]) chunks = [] ladd = chunks.append for rev in chain: chunkstart = start(rev) if inline: chunkstart += (rev + 1) * iosize chunklength = length(rev) ladd(buffer(data, chunkstart - offset, chunklength)) return chunks def dodeltachain(rev): if not cache: r.clearcaches() r._deltachain(rev) def doread(chain): if not cache: r.clearcaches() segmentforrevs(chain[0], chain[-1]) def dorawchunks(data, chain): if not cache: r.clearcaches() getrawchunks(data, chain) def dodecompress(chunks): decomp = r.decompress for chunk in chunks: decomp(chunk) def dopatch(text, bins): if not cache: r.clearcaches() mdiff.patches(text, bins) def dohash(text): if not cache: r.clearcaches() r.checkhash(text, node, rev=rev) def dorevision(): if not cache: r.clearcaches() r.revision(node) chain = r._deltachain(rev)[0] data = segmentforrevs(chain[0], chain[-1])[1] rawchunks = getrawchunks(data, chain) bins = r._chunks(chain) text = str(bins[0]) bins = bins[1:] text = mdiff.patches(text, bins) benches = [ (lambda: dorevision(), "full"), (lambda: dodeltachain(rev), "deltachain"), (lambda: doread(chain), "read"), (lambda: dorawchunks(data, chain), "rawchunks"), (lambda: dodecompress(rawchunks), "decompress"), (lambda: dopatch(text, bins), "patch"), (lambda: dohash(text), "hash"), ] for fn, title in benches: timer, fm = gettimer(ui, opts) timer(fn, title=title) fm.end()