comparison mercurial/filelog.py @ 11541:ab9fa7a85dd9 stable

filelog: cmp: don't read data if hashes are identical (issue2273) filelog.renamed() is an expensive call as it reads the filelog if p1 == nullid. It's more efficient to first compute the hash, and to bail early if the computed hash is the same as the stored nodeid. 'samehashes' variable is not strictly necessary, but helps for comprehension.
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Mon, 05 Jul 2010 19:49:54 +0900
parents 2370e270a29a
children e5060aa22043
comparison
equal deleted inserted replaced
11540:2370e270a29a 11541:ab9fa7a85dd9
60 """compare text with a given file revision 60 """compare text with a given file revision
61 61
62 returns True if text is different than what is stored. 62 returns True if text is different than what is stored.
63 """ 63 """
64 64
65 # for renames, we have to go the slow way 65 t = text
66 if text.startswith('\1\n') or self.renamed(node): 66 if text.startswith('\1\n'):
67 t = '\1\n\1\n' + text
68
69 samehashes = not revlog.revlog.cmp(self, node, t)
70 if samehashes:
71 return False
72
73 # renaming a file produces a different hash, even if the data
74 # remains unchanged. Check if it's the case (slow):
75 if self.renamed(node):
67 t2 = self.read(node) 76 t2 = self.read(node)
68 return t2 != text 77 return t2 != text
69 78
70 return revlog.revlog.cmp(self, node, text) 79 return True