##// END OF EJS Templates
revsetbenchmark: add more example for roots usages...
revsetbenchmark: add more example for roots usages We test the `roots` revset in setting similar to our test for `heads`. Note that the algorithm used for roots can give result without consuming the full input set. This provides a significant speedup when testing or accessing a single value. We can't just replace it with simple, full algorithm like we did for `heads`. See performance number below: 0) roots((tip~100::) - (tip~100::tip)) 1) roots((0::) - (0::tip)) 2) roots(tip~100:) 3) roots(:42) 4) roots(not public()) 5) roots((0:tip)::) 6) roots(0::tip) 7) 42:68 and roots(42:tip) 8) roots(0:tip) 9) roots((:42) + (tip~42:)) 10) roots(all()) 11) roots(-10000:-1) 12) (-5000:-1000) and roots(-10000:-1) 13) roots(matching(tip, "author")) 14) roots(matching(tip, "author")) and -10000:-1 15) (-10000:-1) and roots(matching(tip, "author")) plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast 00) 0.000789 0.000801 0.000801 0.000819 0.000784 0.000774 0.000793 0.000816 0.000815 0.000831 0.000799 01) 0.097610 0.002717 0.096706 0.002615 0.059189 0.089033 0.059862 0.002644 0.098058 0.002640 0.058992 02) 0.000709 0.000117 0.000382 0.000136 0.000384 0.000724 0.000412 0.000133 0.000733 0.000159 0.000416 03) 0.000075 0.000064 0.000093 0.000080 0.000097 0.000089 0.000123 0.000079 0.000105 0.000102 0.000126 04) 0.000055 0.000071 0.000070 0.000087 0.000075 0.000066 0.000100 0.000085 0.000082 0.000110 0.000102 05) 0.088043 0.001084 0.087816 0.001097 0.048049 0.072454 0.047673 0.001089 0.088491 0.001163 0.047824 06) 0.058761 0.001727 0.059324 0.001850 0.058562 0.059198 0.058998 0.001743 0.058556 0.001874 0.059420 07) 0.000131 0.000121 0.000145 0.000138 0.000150 0.000142 0.000178 0.000135 0.000160 0.000163 0.000179 08) 0.058003 0.000077 0.032327 0.000093 0.031966 0.056812 0.031753 0.000092 0.057113 0.000116 0.031933 09) 0.000503 0.000145 0.000469 0.000161 0.000476 0.000564 0.000502 0.000160 0.000537 0.000187 0.000500 10) 0.056654 0.000058 0.033104 0.000073 0.032157 0.056598 0.031877 0.000071 0.056433 0.000094 0.031819 11) 0.005842 0.000081 0.001907 0.000101 0.001883 0.005868 0.001915 0.000099 0.005836 0.000122 0.001896 12) 0.003237 0.000634 0.001784 0.000655 0.001803 0.003245 0.001837 0.000649 0.003231 0.000680 0.001858

File last commit:

r39813:b63dee7b default
r41314:41f14e8f default
Show More
pointer.py
83 lines | 2.8 KiB | text/x-python | PythonLexer
# pointer.py - Git-LFS pointer serialization
#
# Copyright 2017 Facebook, Inc.
#
# 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
import re
from mercurial.i18n import _
from mercurial import (
error,
pycompat,
)
from mercurial.utils import (
stringutil,
)
class InvalidPointer(error.StorageError):
pass
class gitlfspointer(dict):
VERSION = 'https://git-lfs.github.com/spec/v1'
def __init__(self, *args, **kwargs):
self['version'] = self.VERSION
super(gitlfspointer, self).__init__(*args)
self.update(pycompat.byteskwargs(kwargs))
@classmethod
def deserialize(cls, text):
try:
return cls(l.split(' ', 1) for l in text.splitlines()).validate()
except ValueError: # l.split returns 1 item instead of 2
raise InvalidPointer(_('cannot parse git-lfs text: %s')
% stringutil.pprint(text))
def serialize(self):
sortkeyfunc = lambda x: (x[0] != 'version', x)
items = sorted(self.validate().iteritems(), key=sortkeyfunc)
return ''.join('%s %s\n' % (k, v) for k, v in items)
def oid(self):
return self['oid'].split(':')[-1]
def size(self):
return int(self['size'])
# regular expressions used by _validate
# see https://github.com/git-lfs/git-lfs/blob/master/docs/spec.md
_keyre = re.compile(br'\A[a-z0-9.-]+\Z')
_valuere = re.compile(br'\A[^\n]*\Z')
_requiredre = {
'size': re.compile(br'\A[0-9]+\Z'),
'oid': re.compile(br'\Asha256:[0-9a-f]{64}\Z'),
'version': re.compile(br'\A%s\Z' % stringutil.reescape(VERSION)),
}
def validate(self):
"""raise InvalidPointer on error. return self if there is no error"""
requiredcount = 0
for k, v in self.iteritems():
if k in self._requiredre:
if not self._requiredre[k].match(v):
raise InvalidPointer(
_('unexpected lfs pointer value: %s=%s')
% (k, stringutil.pprint(v)))
requiredcount += 1
elif not self._keyre.match(k):
raise InvalidPointer(_('unexpected lfs pointer key: %s') % k)
if not self._valuere.match(v):
raise InvalidPointer(_('unexpected lfs pointer value: %s=%s')
% (k, stringutil.pprint(v)))
if len(self._requiredre) != requiredcount:
miss = sorted(set(self._requiredre.keys()).difference(self.keys()))
raise InvalidPointer(_('missing lfs pointer keys: %s')
% ', '.join(miss))
return self
deserialize = gitlfspointer.deserialize