Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revlog.py @ 6144:08e0825b8106
revlog.revision: avoid opening the datafile without need.
If there's no inline data, revlog.revision opens the data file every
time it's called. This is useful if we're going to call chunk many
times, but, if we're going to call it only once, it's better to let
chunk open the file - if we're lucky, all the data we're going to need
is already cached and we won't need to even look at the file.
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Tue, 19 Feb 2008 19:20:10 -0300 |
parents | b9a830fa10f6 |
children | f89fd07fc51d |
comparison
equal
deleted
inserted
replaced
6143:5b159ebb19cf | 6144:08e0825b8106 |
---|---|
931 # check rev flags | 931 # check rev flags |
932 if self.index[rev][0] & 0xFFFF: | 932 if self.index[rev][0] & 0xFFFF: |
933 raise RevlogError(_('incompatible revision flag %x') % | 933 raise RevlogError(_('incompatible revision flag %x') % |
934 (self.index[rev][0] & 0xFFFF)) | 934 (self.index[rev][0] & 0xFFFF)) |
935 | 935 |
936 if self._inline: | 936 df = None |
937 # we probably have the whole chunk cached | |
938 df = None | |
939 else: | |
940 df = self.opener(self.datafile) | |
941 | 937 |
942 # do we have useful data cached? | 938 # do we have useful data cached? |
943 if self._cache and self._cache[1] >= base and self._cache[1] < rev: | 939 if self._cache and self._cache[1] >= base and self._cache[1] < rev: |
944 base = self._cache[1] | 940 base = self._cache[1] |
945 text = str(self._cache[2]) | 941 text = str(self._cache[2]) |
946 self._loadindex(base, rev + 1) | 942 self._loadindex(base, rev + 1) |
943 if not self._inline and rev > base + 1: | |
944 df = self.opener(self.datafile) | |
947 else: | 945 else: |
948 self._loadindex(base, rev + 1) | 946 self._loadindex(base, rev + 1) |
947 if not self._inline and rev > base: | |
948 df = self.opener(self.datafile) | |
949 text = self.chunk(base, df=df) | 949 text = self.chunk(base, df=df) |
950 | 950 |
951 bins = [self.chunk(r, df) for r in xrange(base + 1, rev + 1)] | 951 bins = [self.chunk(r, df) for r in xrange(base + 1, rev + 1)] |
952 text = mdiff.patches(text, bins) | 952 text = mdiff.patches(text, bins) |
953 p1, p2 = self.parents(node) | 953 p1, p2 = self.parents(node) |