mercurial/filelog.py
changeset 39765 3e801ffd7269
parent 39283 71575a1e197e
child 39778 a6b3c4c1019f
equal deleted inserted replaced
39764:e4e881572382 39765:3e801ffd7269
   223     def compress(self, data):
   223     def compress(self, data):
   224         return self._revlog.compress(data)
   224         return self._revlog.compress(data)
   225 
   225 
   226     def _addrevision(self, *args, **kwargs):
   226     def _addrevision(self, *args, **kwargs):
   227         return self._revlog._addrevision(*args, **kwargs)
   227         return self._revlog._addrevision(*args, **kwargs)
       
   228 
       
   229 class narrowfilelog(filelog):
       
   230     """Filelog variation to be used with narrow stores."""
       
   231 
       
   232     def __init__(self, opener, path, narrowmatch):
       
   233         super(narrowfilelog, self).__init__(opener, path)
       
   234         self._narrowmatch = narrowmatch
       
   235 
       
   236     def renamed(self, node):
       
   237         res = super(narrowfilelog, self).renamed(node)
       
   238 
       
   239         # Renames that come from outside the narrowspec are problematic
       
   240         # because we may lack the base text for the rename. This can result
       
   241         # in code attempting to walk the ancestry or compute a diff
       
   242         # encountering a missing revision. We address this by silently
       
   243         # removing rename metadata if the source file is outside the
       
   244         # narrow spec.
       
   245         #
       
   246         # A better solution would be to see if the base revision is available,
       
   247         # rather than assuming it isn't.
       
   248         #
       
   249         # An even better solution would be to teach all consumers of rename
       
   250         # metadata that the base revision may not be available.
       
   251         #
       
   252         # TODO consider better ways of doing this.
       
   253         if res and not self._narrowmatch(res[0]):
       
   254             return None
       
   255 
       
   256         return res
       
   257 
       
   258     def size(self, rev):
       
   259         # Because we have a custom renamed() that may lie, we need to call
       
   260         # the base renamed() to report accurate results.
       
   261         node = self.node(rev)
       
   262         if super(narrowfilelog, self).renamed(node):
       
   263             return len(self.read(node))
       
   264         else:
       
   265             return super(narrowfilelog, self).size(rev)
       
   266 
       
   267     def cmp(self, node, text):
       
   268         different = super(narrowfilelog, self).cmp(node, text)
       
   269 
       
   270         # Because renamed() may lie, we may get false positives for
       
   271         # different content. Check for this by comparing against the original
       
   272         # renamed() implementation.
       
   273         if different:
       
   274             if super(narrowfilelog, self).renamed(node):
       
   275                 t2 = self.read(node)
       
   276                 return t2 != text
       
   277 
       
   278         return different