def readfromstore(self, text): """Read filelog content from local blobstore transform for flagprocessor. Default tranform for flagprocessor, returning contents from blobstore. Returns a 2-typle (text, validatehash) where validatehash is True as the contents of the blobstore should be checked using checkhash. """ p = pointer.deserialize(text) oid = p.oid() store = self.opener.lfslocalblobstore if not store.has(oid): p.filename = self.filename self.opener.lfsremoteblobstore.readbatch([p], store) # The caller will validate the content text = store.read(oid, verify=False) # pack hg filelog metadata hgmeta = {} for k in p.keys(): if k.startswith(b'x-hg-'): name = k[len(b'x-hg-'):] hgmeta[name] = p[k] if hgmeta or text.startswith(b'\1\n'): text = storageutil.packmeta(hgmeta, text) return (text, True, {})
def createrevlogtext(text, copyfrom=None, copyrev=None): """returns a string that matches the revlog contents in a traditional revlog """ meta = {} if copyfrom or text.startswith('\1\n'): if copyfrom: meta['copy'] = copyfrom meta['copyrev'] = copyrev text = storageutil.packmeta(meta, text) return text
def censorrevision(self, tr, censornode, tombstone=b''): tombstone = storageutil.packmeta({b'censored': tombstone}, b'') # This restriction is cargo culted from revlogs and makes no sense for # SQLite, since columns can be resized at will. if len(tombstone) > len(self.rawdata(censornode)): raise error.Abort( _(b'censor tombstone must be no longer than censored data') ) # We need to replace the censored revision's data with the tombstone. # But replacing that data will have implications for delta chains that # reference it. # # While "better," more complex strategies are possible, we do something # simple: we find delta chain children of the censored revision and we # replace those incremental deltas with fulltexts of their corresponding # revision. Then we delete the now-unreferenced delta and original # revision and insert a replacement. # Find the delta to be censored. censoreddeltaid = self._db.execute( 'SELECT deltaid FROM fileindex WHERE id=?', (self._revisions[censornode].rid,), ).fetchone()[0] # Find all its delta chain children. # TODO once we support storing deltas for !files, we'll need to look # for those delta chains too. rows = list( self._db.execute( 'SELECT id, pathid, node FROM fileindex ' 'WHERE deltabaseid=? OR deltaid=?', (censoreddeltaid, censoreddeltaid), ) ) for row in rows: rid, pathid, node = row fulltext = resolvedeltachain( self._db, pathid, node, {}, {-1: None}, zstddctx=self._dctx ) deltahash = hashutil.sha1(fulltext).digest() if self._compengine == b'zstd': deltablob = self._cctx.compress(fulltext) compression = COMPRESSION_ZSTD elif self._compengine == b'zlib': deltablob = zlib.compress(fulltext) compression = COMPRESSION_ZLIB elif self._compengine == b'none': deltablob = fulltext compression = COMPRESSION_NONE else: raise error.ProgrammingError( b'unhandled compression engine: %s' % self._compengine ) if len(deltablob) >= len(fulltext): deltablob = fulltext compression = COMPRESSION_NONE deltaid = insertdelta(self._db, compression, deltahash, deltablob) self._db.execute( 'UPDATE fileindex SET deltaid=?, deltabaseid=NULL ' 'WHERE id=?', (deltaid, rid), ) # Now create the tombstone delta and replace the delta on the censored # node. deltahash = hashutil.sha1(tombstone).digest() tombstonedeltaid = insertdelta( self._db, COMPRESSION_NONE, deltahash, tombstone ) flags = self._revisions[censornode].flags flags |= FLAG_CENSORED self._db.execute( 'UPDATE fileindex SET flags=?, deltaid=?, deltabaseid=NULL ' 'WHERE pathid=? AND node=?', (flags, tombstonedeltaid, self._pathid, censornode), ) self._db.execute('DELETE FROM delta WHERE id=?', (censoreddeltaid,)) self._refreshindex() self._revisioncache.clear()
def add(self, filedata, meta, transaction, linkrev, p1, p2): if meta or filedata.startswith(b'\x01\n'): filedata = storageutil.packmeta(meta, filedata) return self.addrevision(filedata, transaction, linkrev, p1, p2)
def add(self, text, meta, transaction, linkrev, p1, p2): if meta or text.startswith(b'\1\n'): text = storageutil.packmeta(meta, text) return self.addrevision(text, transaction, linkrev, p1, p2)