mercurial/revlog.py
changeset 14251 258fbccf22f5
parent 14219 c33427080671
child 14252 19067884c5f5
equal deleted inserted replaced
14250:34ec9b313638 14251:258fbccf22f5
    25 
    25 
    26 # revlog header flags
    26 # revlog header flags
    27 REVLOGV0 = 0
    27 REVLOGV0 = 0
    28 REVLOGNG = 1
    28 REVLOGNG = 1
    29 REVLOGNGINLINEDATA = (1 << 16)
    29 REVLOGNGINLINEDATA = (1 << 16)
    30 REVLOGSHALLOW = (1 << 17)
       
    31 REVLOG_DEFAULT_FLAGS = REVLOGNGINLINEDATA
    30 REVLOG_DEFAULT_FLAGS = REVLOGNGINLINEDATA
    32 REVLOG_DEFAULT_FORMAT = REVLOGNG
    31 REVLOG_DEFAULT_FORMAT = REVLOGNG
    33 REVLOG_DEFAULT_VERSION = REVLOG_DEFAULT_FORMAT | REVLOG_DEFAULT_FLAGS
    32 REVLOG_DEFAULT_VERSION = REVLOG_DEFAULT_FORMAT | REVLOG_DEFAULT_FLAGS
    34 REVLOGNG_FLAGS = REVLOGNGINLINEDATA | REVLOGSHALLOW
    33 REVLOGNG_FLAGS = REVLOGNGINLINEDATA
    35 
    34 
    36 # revlog index flags
    35 # revlog index flags
    37 REVIDX_KNOWN_FLAGS = 0
    36 REVIDX_KNOWN_FLAGS = 0
    38 
    37 
    39 # max size of revlog with inline data
    38 # max size of revlog with inline data
   205     Both pieces of the revlog are written to in an append-only
   204     Both pieces of the revlog are written to in an append-only
   206     fashion, which means we never need to rewrite a file to insert or
   205     fashion, which means we never need to rewrite a file to insert or
   207     remove data, and can use some simple techniques to avoid the need
   206     remove data, and can use some simple techniques to avoid the need
   208     for locking while reading.
   207     for locking while reading.
   209     """
   208     """
   210     def __init__(self, opener, indexfile, shallowroot=None):
   209     def __init__(self, opener, indexfile):
   211         """
   210         """
   212         create a revlog object
   211         create a revlog object
   213 
   212 
   214         opener is a function that abstracts the file opening operation
   213         opener is a function that abstracts the file opening operation
   215         and can be used to implement COW semantics or the like.
   214         and can be used to implement COW semantics or the like.
   218         self.datafile = indexfile[:-2] + ".d"
   217         self.datafile = indexfile[:-2] + ".d"
   219         self.opener = opener
   218         self.opener = opener
   220         self._cache = None
   219         self._cache = None
   221         self._chunkcache = (0, '')
   220         self._chunkcache = (0, '')
   222         self.index = []
   221         self.index = []
   223         self._shallowroot = shallowroot
       
   224         self._pcache = {}
   222         self._pcache = {}
   225         self._nodecache = {nullid: nullrev}
   223         self._nodecache = {nullid: nullrev}
   226         self._nodepos = None
   224         self._nodepos = None
   227 
   225 
   228         v = REVLOG_DEFAULT_VERSION
   226         v = REVLOG_DEFAULT_VERSION
   229         if hasattr(opener, 'options') and 'defversion' in opener.options:
   227         if hasattr(opener, 'options') and 'defversion' in opener.options:
   230             v = opener.options['defversion']
   228             v = opener.options['defversion']
   231             if v & REVLOGNG:
   229             if v & REVLOGNG:
   232                 v |= REVLOGNGINLINEDATA
   230                 v |= REVLOGNGINLINEDATA
   233 
       
   234         if shallowroot:
       
   235             v |= REVLOGSHALLOW
       
   236 
   231 
   237         i = ''
   232         i = ''
   238         try:
   233         try:
   239             f = self.opener(self.indexfile)
   234             f = self.opener(self.indexfile)
   240             i = f.read()
   235             i = f.read()
   245             if inst.errno != errno.ENOENT:
   240             if inst.errno != errno.ENOENT:
   246                 raise
   241                 raise
   247 
   242 
   248         self.version = v
   243         self.version = v
   249         self._inline = v & REVLOGNGINLINEDATA
   244         self._inline = v & REVLOGNGINLINEDATA
   250         self._shallow = v & REVLOGSHALLOW
       
   251         flags = v & ~0xFFFF
   245         flags = v & ~0xFFFF
   252         fmt = v & 0xFFFF
   246         fmt = v & 0xFFFF
   253         if fmt == REVLOGV0 and flags:
   247         if fmt == REVLOGV0 and flags:
   254             raise RevlogError(_("index %s unknown flags %#04x for format v0")
   248             raise RevlogError(_("index %s unknown flags %#04x for format v0")
   255                               % (self.indexfile, flags >> 16))
   249                               % (self.indexfile, flags >> 16))