##// END OF EJS Templates
narrow: remove custom filelog type...
Gregory Szorc -
r39802:9358f506 default
parent child Browse files
Show More
@@ -1,36 +1,30 b''
1 # narrowrepo.py - repository which supports narrow revlogs, lazy loading
1 # narrowrepo.py - repository which supports narrow revlogs, lazy loading
2 #
2 #
3 # Copyright 2017 Google, Inc.
3 # Copyright 2017 Google, Inc.
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 from . import (
10 from . import (
11 narrowdirstate,
11 narrowdirstate,
12 narrowrevlog,
13 narrowwirepeer,
12 narrowwirepeer,
14 )
13 )
15
14
16 def wraprepo(repo):
15 def wraprepo(repo):
17 """Enables narrow clone functionality on a single local repository."""
16 """Enables narrow clone functionality on a single local repository."""
18
17
19 class narrowrepository(repo.__class__):
18 class narrowrepository(repo.__class__):
20
19
21 def file(self, f):
22 fl = super(narrowrepository, self).file(f)
23 narrowrevlog.makenarrowfilelog(fl, self.narrowmatch())
24 return fl
25
26 def _makedirstate(self):
20 def _makedirstate(self):
27 dirstate = super(narrowrepository, self)._makedirstate()
21 dirstate = super(narrowrepository, self)._makedirstate()
28 return narrowdirstate.wrapdirstate(self, dirstate)
22 return narrowdirstate.wrapdirstate(self, dirstate)
29
23
30 def peer(self):
24 def peer(self):
31 peer = super(narrowrepository, self).peer()
25 peer = super(narrowrepository, self).peer()
32 peer._caps.add(narrowwirepeer.NARROWCAP)
26 peer._caps.add(narrowwirepeer.NARROWCAP)
33 peer._caps.add(narrowwirepeer.ELLIPSESCAP)
27 peer._caps.add(narrowwirepeer.ELLIPSESCAP)
34 return peer
28 return peer
35
29
36 repo.__class__ = narrowrepository
30 repo.__class__ = narrowrepository
@@ -1,80 +1,29 b''
1 # narrowrevlog.py - revlog storing irrelevant nodes as "ellipsis" nodes
1 # narrowrevlog.py - revlog storing irrelevant nodes as "ellipsis" nodes
2 #
2 #
3 # Copyright 2017 Google, Inc.
3 # Copyright 2017 Google, Inc.
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 from mercurial import (
10 from mercurial import (
11 revlog,
11 revlog,
12 util,
13 )
12 )
14
13
15 def readtransform(self, text):
14 def readtransform(self, text):
16 return text, False
15 return text, False
17
16
18 def writetransform(self, text):
17 def writetransform(self, text):
19 return text, False
18 return text, False
20
19
21 def rawtransform(self, text):
20 def rawtransform(self, text):
22 return False
21 return False
23
22
24 revlog.addflagprocessor(revlog.REVIDX_ELLIPSIS,
23 revlog.addflagprocessor(revlog.REVIDX_ELLIPSIS,
25 (readtransform, writetransform, rawtransform))
24 (readtransform, writetransform, rawtransform))
26
25
27 def setup():
26 def setup():
28 # We just wanted to add the flag processor, which is done at module
27 # We just wanted to add the flag processor, which is done at module
29 # load time.
28 # load time.
30 pass
29 pass
31
32 def makenarrowfilelog(fl, narrowmatch):
33 class narrowfilelog(fl.__class__):
34 def renamed(self, node):
35 # Renames that come from outside the narrowspec are
36 # problematic at least for git-diffs, because we lack the
37 # base text for the rename. This logic was introduced in
38 # 3cd72b1 of narrowhg (authored by martinvonz, reviewed by
39 # adgar), but that revision doesn't have any additional
40 # commentary on what problems we can encounter.
41 m = super(narrowfilelog, self).renamed(node)
42 if m and not narrowmatch(m[0]):
43 return None
44 return m
45
46 def size(self, rev):
47 # We take advantage of the fact that remotefilelog
48 # lacks a node() method to just skip the
49 # rename-checking logic when on remotefilelog. This
50 # might be incorrect on other non-revlog-based storage
51 # engines, but for now this seems to be fine.
52 #
53 # TODO: when remotefilelog is in core, improve this to
54 # explicitly look for remotefilelog instead of cheating
55 # with a hasattr check.
56 if util.safehasattr(self, 'node'):
57 node = self.node(rev)
58 # Because renamed() is overridden above to
59 # sometimes return None even if there is metadata
60 # in the revlog, size can be incorrect for
61 # copies/renames, so we need to make sure we call
62 # the super class's implementation of renamed()
63 # for the purpose of size calculation.
64 if super(narrowfilelog, self).renamed(node):
65 return len(self.read(node))
66 return super(narrowfilelog, self).size(rev)
67
68 def cmp(self, node, text):
69 different = super(narrowfilelog, self).cmp(node, text)
70 if different:
71 # Similar to size() above, if the file was copied from
72 # a file outside the narrowspec, the super class's
73 # would have returned True because we tricked it into
74 # thinking that the file was not renamed.
75 if super(narrowfilelog, self).renamed(node):
76 t2 = self.read(node)
77 return t2 != text
78 return different
79
80 fl.__class__ = narrowfilelog
General Comments 0
You need to be logged in to leave comments. Login now