Mercurial > hg-git
annotate hggit/overlay.py @ 1019:d356f8479295
overlayfilectx: provide an isbinary() method
Upstream hg (e62cf13e0858) now requires isbinary() from a filecontext.
hg-git's overlayfilectx needs to be updated accordingly.
author | Jun Wu <quark@fb.com> |
---|---|
date | Fri, 12 May 2017 13:14:21 -0700 |
parents | 438b2fc58701 |
children | 5821075b289a |
rev | line source |
---|---|
408 | 1 # overlay classes for repositories |
2 # unifies access to unimported git objects and committed hg objects | |
3 # designed to support incoming | |
4 # | |
5 # incomplete, implemented on demand | |
6 | |
964
b867b5f0a63a
overlay: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents:
900
diff
changeset
|
7 from mercurial import ( |
b867b5f0a63a
overlay: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents:
900
diff
changeset
|
8 ancestor, |
988
49e363aebdd0
overlay: add changelogrevision
Mateusz Kwapich <mitrandir@fb.com>
parents:
965
diff
changeset
|
9 changelog, |
964
b867b5f0a63a
overlay: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents:
900
diff
changeset
|
10 manifest, |
1011
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
11 match as matchmod, |
964
b867b5f0a63a
overlay: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents:
900
diff
changeset
|
12 context, |
1001
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
13 util, |
964
b867b5f0a63a
overlay: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents:
900
diff
changeset
|
14 ) |
408 | 15 from mercurial.node import bin, hex, nullid |
16 | |
620
0a514e303a06
overlay: add kludge to make sure we only ever give hexshas to dulwich
Augie Fackler <raf@durin42.com>
parents:
612
diff
changeset
|
17 def _maybehex(n): |
0a514e303a06
overlay: add kludge to make sure we only ever give hexshas to dulwich
Augie Fackler <raf@durin42.com>
parents:
612
diff
changeset
|
18 if len(n) == 20: |
0a514e303a06
overlay: add kludge to make sure we only ever give hexshas to dulwich
Augie Fackler <raf@durin42.com>
parents:
612
diff
changeset
|
19 return hex(n) |
0a514e303a06
overlay: add kludge to make sure we only ever give hexshas to dulwich
Augie Fackler <raf@durin42.com>
parents:
612
diff
changeset
|
20 return n |
0a514e303a06
overlay: add kludge to make sure we only ever give hexshas to dulwich
Augie Fackler <raf@durin42.com>
parents:
612
diff
changeset
|
21 |
408 | 22 class overlaymanifest(object): |
23 def __init__(self, repo, sha): | |
24 self.repo = repo | |
25 self.tree = repo.handler.git.get_object(sha) | |
26 self._map = None | |
856
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
27 self._flags = None |
408 | 28 |
466
ac16efd25cc4
overlaymanifest: add the withflags method introduced in hg change a1dcd842ce17
Augie Fackler <raf@durin42.com>
parents:
423
diff
changeset
|
29 def withflags(self): |
ac16efd25cc4
overlaymanifest: add the withflags method introduced in hg change a1dcd842ce17
Augie Fackler <raf@durin42.com>
parents:
423
diff
changeset
|
30 self.load() |
856
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
31 return set([path for path, flag in self._flags.iteritems() |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
32 if flag != '']) |
466
ac16efd25cc4
overlaymanifest: add the withflags method introduced in hg change a1dcd842ce17
Augie Fackler <raf@durin42.com>
parents:
423
diff
changeset
|
33 |
408 | 34 def copy(self): |
35 return overlaymanifest(self.repo, self.tree.id) | |
36 | |
37 def keys(self): | |
38 self.load() | |
39 return self._map.keys() | |
40 | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
41 def iterkeys(self): |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
42 return iter(self.keys()) |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
43 |
856
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
44 def load(self): |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
45 if self._map is not None: |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
46 return |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
47 |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
48 self._map = {} |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
49 self._flags = {} |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
50 |
408 | 51 def hgflag(gitflag): |
52 if gitflag & 0100: | |
53 return 'x' | |
54 elif gitflag & 020000: | |
55 return 'l' | |
56 else: | |
57 return '' | |
58 | |
59 def addtree(tree, dirname): | |
423
f29401590803
overlay: stop using deprecated tree.entries() method
Augie Fackler <durin42@gmail.com>
parents:
408
diff
changeset
|
60 for entry in tree.iteritems(): |
f29401590803
overlay: stop using deprecated tree.entries() method
Augie Fackler <durin42@gmail.com>
parents:
408
diff
changeset
|
61 if entry.mode & 040000: |
408 | 62 # expand directory |
423
f29401590803
overlay: stop using deprecated tree.entries() method
Augie Fackler <durin42@gmail.com>
parents:
408
diff
changeset
|
63 subtree = self.repo.handler.git.get_object(entry.sha) |
f29401590803
overlay: stop using deprecated tree.entries() method
Augie Fackler <durin42@gmail.com>
parents:
408
diff
changeset
|
64 addtree(subtree, dirname + entry.path + '/') |
408 | 65 else: |
423
f29401590803
overlay: stop using deprecated tree.entries() method
Augie Fackler <durin42@gmail.com>
parents:
408
diff
changeset
|
66 path = dirname + entry.path |
f29401590803
overlay: stop using deprecated tree.entries() method
Augie Fackler <durin42@gmail.com>
parents:
408
diff
changeset
|
67 self._map[path] = bin(entry.sha) |
856
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
68 self._flags[path] = hgflag(entry.mode) |
408 | 69 |
70 addtree(self.tree, '') | |
71 | |
829
64fa5ea18b89
manifest: add matches() to overlay
Durham Goode <durham@fb.com>
parents:
690
diff
changeset
|
72 def matches(self, match): |
64fa5ea18b89
manifest: add matches() to overlay
Durham Goode <durham@fb.com>
parents:
690
diff
changeset
|
73 '''generate a new manifest filtered by the match argument''' |
64fa5ea18b89
manifest: add matches() to overlay
Durham Goode <durham@fb.com>
parents:
690
diff
changeset
|
74 if match.always(): |
64fa5ea18b89
manifest: add matches() to overlay
Durham Goode <durham@fb.com>
parents:
690
diff
changeset
|
75 return self.copy() |
64fa5ea18b89
manifest: add matches() to overlay
Durham Goode <durham@fb.com>
parents:
690
diff
changeset
|
76 |
64fa5ea18b89
manifest: add matches() to overlay
Durham Goode <durham@fb.com>
parents:
690
diff
changeset
|
77 mf = self.copy() |
64fa5ea18b89
manifest: add matches() to overlay
Durham Goode <durham@fb.com>
parents:
690
diff
changeset
|
78 for fn in mf.keys(): |
64fa5ea18b89
manifest: add matches() to overlay
Durham Goode <durham@fb.com>
parents:
690
diff
changeset
|
79 if not match(fn): |
64fa5ea18b89
manifest: add matches() to overlay
Durham Goode <durham@fb.com>
parents:
690
diff
changeset
|
80 del mf[fn] |
64fa5ea18b89
manifest: add matches() to overlay
Durham Goode <durham@fb.com>
parents:
690
diff
changeset
|
81 return mf |
64fa5ea18b89
manifest: add matches() to overlay
Durham Goode <durham@fb.com>
parents:
690
diff
changeset
|
82 |
597
3964de9961ec
overlaymanifest: add iteritems(), used by recent hg versions
Augie Fackler <raf@durin42.com>
parents:
570
diff
changeset
|
83 def iteritems(self): |
3964de9961ec
overlaymanifest: add iteritems(), used by recent hg versions
Augie Fackler <raf@durin42.com>
parents:
570
diff
changeset
|
84 self.load() |
3964de9961ec
overlaymanifest: add iteritems(), used by recent hg versions
Augie Fackler <raf@durin42.com>
parents:
570
diff
changeset
|
85 return self._map.iteritems() |
3964de9961ec
overlaymanifest: add iteritems(), used by recent hg versions
Augie Fackler <raf@durin42.com>
parents:
570
diff
changeset
|
86 |
408 | 87 def __iter__(self): |
88 self.load() | |
89 return self._map.__iter__() | |
90 | |
91 def __getitem__(self, path): | |
92 self.load() | |
93 return self._map[path] | |
94 | |
856
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
95 def __contains__(self, path): |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
96 self.load() |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
97 return path in self._map |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
98 |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
99 def get(self, path, default=None): |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
100 self.load() |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
101 return self._map.get(path, default) |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
102 |
1011
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
103 def diff(self, m2, match=None, clean=False): |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
104 # Older mercurial clients used diff(m2, clean=False). If a caller failed |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
105 # to specify clean as a keyword arg, it might get passed as match here. |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
106 if isinstance(match, bool): |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
107 clean = match |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
108 match = None |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
109 |
856
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
110 self.load() |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
111 if isinstance(m2, overlaymanifest): |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
112 m2.load() |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
113 |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
114 # below code copied from manifest.py:manifestdict.diff |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
115 diff = {} |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
116 |
899
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
117 try: |
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
118 m2flagget = m2.flags |
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
119 except AttributeError: |
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
120 # Mercurial <= 3.3 |
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
121 m2flagget = m2._flags.get |
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
122 |
1011
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
123 if match is None: |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
124 match = matchmod.always('', '') |
856
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
125 for fn, n1 in self.iteritems(): |
1011
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
126 if not match(fn): |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
127 continue |
856
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
128 fl1 = self._flags.get(fn, '') |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
129 n2 = m2.get(fn, None) |
899
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
130 fl2 = m2flagget(fn, '') |
856
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
131 if n2 is None: |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
132 fl2 = '' |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
133 if n1 != n2 or fl1 != fl2: |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
134 diff[fn] = ((n1, fl1), (n2, fl2)) |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
135 elif clean: |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
136 diff[fn] = None |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
137 |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
138 for fn, n2 in m2.iteritems(): |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
139 if fn not in self: |
1011
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
140 if not match(fn): |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
141 continue |
899
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
142 fl2 = m2flagget(fn, '') |
856
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
143 diff[fn] = ((None, ''), (n2, fl2)) |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
144 |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
145 return diff |
15d2b119ca99
overlaymanifest: implement more methods for Mercurial 3.3 compatibility
Siddharth Agarwal <sid0@fb.com>
parents:
855
diff
changeset
|
146 |
408 | 147 def __delitem__(self, path): |
148 del self._map[path] | |
149 | |
1011
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
150 def wrapmanifestdictdiff(orig, self, m2, match=None, clean=False): |
899
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
151 '''avoid calling into lazymanifest code if m2 is an overlaymanifest''' |
1011
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
152 # Older mercurial clients used diff(m2, clean=False). If a caller failed |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
153 # to specify clean as a keyword arg, it might get passed as match here. |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
154 if isinstance(match, bool): |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
155 clean = match |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
156 match = None |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
157 |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
158 kwargs = { |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
159 'clean' : clean |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
160 } |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
161 # Older versions of mercurial don't support the match arg, so only add it if |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
162 # it exists. |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
163 if match is not None: |
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
164 kwargs['match'] = match |
899
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
165 if isinstance(m2, overlaymanifest): |
1011
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
166 diff = m2.diff(self, **kwargs) |
899
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
167 # since we calculated the diff with m2 vs m1, flip it around |
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
168 for fn in diff: |
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
169 c1, c2 = diff[fn] |
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
170 diff[fn] = c2, c1 |
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
171 return diff |
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
172 else: |
1011
438b2fc58701
manifest: update matcher to match core api
Durham Goode <durham@fb.com>
parents:
1004
diff
changeset
|
173 return orig(self, m2, **kwargs) |
899
11ca21820a95
overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents:
896
diff
changeset
|
174 |
408 | 175 class overlayfilectx(object): |
176 def __init__(self, repo, path, fileid=None): | |
177 self.repo = repo | |
178 self._path = path | |
179 self.fileid = fileid | |
180 | |
181 # this is a hack to skip copy detection | |
182 def ancestors(self): | |
183 return [self, self] | |
184 | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
185 def filenode(self): |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
186 return nullid |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
187 |
408 | 188 def rev(self): |
189 return -1 | |
190 | |
191 def path(self): | |
192 return self._path | |
193 | |
194 def filelog(self): | |
195 return self.fileid | |
196 | |
197 def data(self): | |
620
0a514e303a06
overlay: add kludge to make sure we only ever give hexshas to dulwich
Augie Fackler <raf@durin42.com>
parents:
612
diff
changeset
|
198 blob = self.repo.handler.git.get_object(_maybehex(self.fileid)) |
408 | 199 return blob.data |
200 | |
1019
d356f8479295
overlayfilectx: provide an isbinary() method
Jun Wu <quark@fb.com>
parents:
1011
diff
changeset
|
201 def isbinary(self): |
d356f8479295
overlayfilectx: provide an isbinary() method
Jun Wu <quark@fb.com>
parents:
1011
diff
changeset
|
202 return util.binary(self.data()) |
d356f8479295
overlayfilectx: provide an isbinary() method
Jun Wu <quark@fb.com>
parents:
1011
diff
changeset
|
203 |
408 | 204 class overlaychangectx(context.changectx): |
205 def __init__(self, repo, sha): | |
206 self.repo = repo | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
207 if not isinstance(sha, basestring): |
896 | 208 sha = sha.hex() |
620
0a514e303a06
overlay: add kludge to make sure we only ever give hexshas to dulwich
Augie Fackler <raf@durin42.com>
parents:
612
diff
changeset
|
209 self.commit = repo.handler.git.get_object(_maybehex(sha)) |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
210 self._overlay = getattr(repo, 'gitoverlay', repo) |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
211 self._rev = self._overlay.rev(bin(self.commit.id)) |
408 | 212 |
213 def node(self): | |
214 return bin(self.commit.id) | |
215 | |
216 def rev(self): | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
217 return self._rev |
408 | 218 |
219 def date(self): | |
220 return self.commit.author_time, self.commit.author_timezone | |
221 | |
222 def branch(self): | |
223 return 'default' | |
224 | |
225 def user(self): | |
226 return self.commit.author | |
227 | |
228 def files(self): | |
229 return [] | |
230 | |
231 def extra(self): | |
232 return {} | |
233 | |
234 def description(self): | |
235 return self.commit.message | |
236 | |
237 def parents(self): | |
900
db308eba5251
overlaychangectx: use overlayrevlog logic to determine parents
Siddharth Agarwal <sid0@fb.com>
parents:
899
diff
changeset
|
238 cl = self.repo.changelog |
db308eba5251
overlaychangectx: use overlayrevlog logic to determine parents
Siddharth Agarwal <sid0@fb.com>
parents:
899
diff
changeset
|
239 parents = cl.parents(cl.node(self._rev)) |
873
517cf1b5e626
overlaychangectx: return nullrev if commit has no parents
Siddharth Agarwal <sid0@fb.com>
parents:
856
diff
changeset
|
240 if not parents: |
517cf1b5e626
overlaychangectx: return nullrev if commit has no parents
Siddharth Agarwal <sid0@fb.com>
parents:
856
diff
changeset
|
241 return [self.repo['null']] |
900
db308eba5251
overlaychangectx: use overlayrevlog logic to determine parents
Siddharth Agarwal <sid0@fb.com>
parents:
899
diff
changeset
|
242 if parents[1] == nullid: |
db308eba5251
overlaychangectx: use overlayrevlog logic to determine parents
Siddharth Agarwal <sid0@fb.com>
parents:
899
diff
changeset
|
243 parents = parents[:-1] |
db308eba5251
overlaychangectx: use overlayrevlog logic to determine parents
Siddharth Agarwal <sid0@fb.com>
parents:
899
diff
changeset
|
244 return [self.repo[sha] for sha in parents] |
408 | 245 |
246 def manifestnode(self): | |
247 return bin(self.commit.tree) | |
248 | |
249 def hex(self): | |
250 return self.commit.id | |
251 | |
252 def tags(self): | |
253 return [] | |
254 | |
255 def bookmarks(self): | |
256 return [] | |
257 | |
258 def manifest(self): | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
259 return overlaymanifest(self._overlay, self.commit.tree) |
408 | 260 |
261 def filectx(self, path, filelog=None): | |
262 mf = self.manifest() | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
263 return overlayfilectx(self._overlay, path, mf[path]) |
408 | 264 |
265 def flags(self, path): | |
266 mf = self.manifest() | |
267 return mf.flags(path) | |
268 | |
269 def __nonzero__(self): | |
270 return True | |
271 | |
568
41f6e3df67b1
overlaychangectx: fix compatibility with mercurial 2.4-rc (no attribute _repo)
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
272 def phase(self): |
41f6e3df67b1
overlaychangectx: fix compatibility with mercurial 2.4-rc (no attribute _repo)
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
273 try: |
41f6e3df67b1
overlaychangectx: fix compatibility with mercurial 2.4-rc (no attribute _repo)
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
274 from mercurial import phases |
41f6e3df67b1
overlaychangectx: fix compatibility with mercurial 2.4-rc (no attribute _repo)
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
275 return phases.draft |
956
06385a2b30f3
init: handle AttributeError in addition to ImportError
timeless@gmail.com
parents:
900
diff
changeset
|
276 except (AttributeError, ImportError): |
568
41f6e3df67b1
overlaychangectx: fix compatibility with mercurial 2.4-rc (no attribute _repo)
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
277 return 1 |
41f6e3df67b1
overlaychangectx: fix compatibility with mercurial 2.4-rc (no attribute _repo)
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
278 |
855
4538981d2c3f
overlaychangelog: return tuples for read()
Siddharth Agarwal <sid0@fb.com>
parents:
854
diff
changeset
|
279 def totuple(self): |
4538981d2c3f
overlaychangelog: return tuples for read()
Siddharth Agarwal <sid0@fb.com>
parents:
854
diff
changeset
|
280 return (self.commit.tree, self.user(), self.date(), self.files(), |
4538981d2c3f
overlaychangelog: return tuples for read()
Siddharth Agarwal <sid0@fb.com>
parents:
854
diff
changeset
|
281 self.description(), self.extra()) |
4538981d2c3f
overlaychangelog: return tuples for read()
Siddharth Agarwal <sid0@fb.com>
parents:
854
diff
changeset
|
282 |
408 | 283 class overlayrevlog(object): |
284 def __init__(self, repo, base): | |
285 self.repo = repo | |
286 self.base = base | |
287 | |
288 def parents(self, n): | |
289 gitrev = self.repo.revmap.get(n) | |
689
aa8519daf037
overlayrevlog: handle rev = 0 correctly
Siddharth Agarwal <sid0@fb.com>
parents:
684
diff
changeset
|
290 if gitrev is None: |
408 | 291 # we've reached a revision we have |
292 return self.base.parents(n) | |
620
0a514e303a06
overlay: add kludge to make sure we only ever give hexshas to dulwich
Augie Fackler <raf@durin42.com>
parents:
612
diff
changeset
|
293 commit = self.repo.handler.git.get_object(_maybehex(n)) |
408 | 294 |
690
c99941ff2d28
overlayrevlog: handle root commits correctly
Siddharth Agarwal <sid0@fb.com>
parents:
689
diff
changeset
|
295 if not commit.parents: |
c99941ff2d28
overlayrevlog: handle root commits correctly
Siddharth Agarwal <sid0@fb.com>
parents:
689
diff
changeset
|
296 return [nullid, nullid] |
c99941ff2d28
overlayrevlog: handle root commits correctly
Siddharth Agarwal <sid0@fb.com>
parents:
689
diff
changeset
|
297 |
408 | 298 def gitorhg(n): |
299 hn = self.repo.handler.map_hg_get(hex(n)) | |
300 if hn is not None: | |
301 return bin(hn) | |
302 return n | |
303 | |
304 # currently ignores the octopus | |
305 p1 = gitorhg(bin(commit.parents[0])) | |
306 if len(commit.parents) > 1: | |
307 p2 = gitorhg(bin(commit.parents[1])) | |
308 else: | |
309 p2 = nullid | |
310 | |
311 return [p1, p2] | |
312 | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
313 def ancestor(self, a, b): |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
314 anode = self.repo.nodemap.get(a) |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
315 bnode = self.repo.nodemap.get(b) |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
316 if anode is None and bnode is None: |
896 | 317 return self.base.ancestor(a, b) |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
318 ancs = ancestor.ancestors(self.parentrevs, a, b) |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
319 if ancs: |
896 | 320 return min(map(self.node, ancs)) |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
321 return nullid |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
322 |
408 | 323 def parentrevs(self, rev): |
324 return [self.rev(p) for p in self.parents(self.node(rev))] | |
325 | |
326 def node(self, rev): | |
327 gitnode = self.repo.nodemap.get(rev) | |
328 if gitnode is None: | |
329 return self.base.node(rev) | |
330 return gitnode | |
331 | |
332 def rev(self, n): | |
333 gitrev = self.repo.revmap.get(n) | |
334 if gitrev is None: | |
896 | 335 return self.base.rev(n) |
408 | 336 return gitrev |
337 | |
338 def __len__(self): | |
339 return len(self.repo.handler.repo) + len(self.repo.revmap) | |
340 | |
1001
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
341 class overlayoldmanifestlog(overlayrevlog): |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
342 def read(self, sha): |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
343 if sha == nullid: |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
344 return manifest.manifestdict() |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
345 return overlaymanifest(self.repo, sha) |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
346 |
997
7b11e6348810
overlay: add support for upstream manifestlog transition
Ryan McElroy <rmcelroy@fb.com>
parents:
988
diff
changeset
|
347 def __getitem__(self, sha): |
1001
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
348 return overlaymanifestctx(self.repo, sha) |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
349 |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
350 class overlaymanifestrevlog(overlayrevlog): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
351 pass |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
352 |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
353 class overlaymanifestctx(object): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
354 def __init__(self, repo, node): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
355 self._repo = repo |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
356 self._node = node |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
357 |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
358 def read(self): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
359 return overlaymanifest(self._repo, self._node) |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
360 |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
361 try: |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
362 class overlaymanifestlog(manifest.manifestlog): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
363 def __init__(self, repo): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
364 self._repo = repo |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
365 |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
366 # Needed for 4.0, since __getitem__ did not redirect to get() in that |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
367 # release. |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
368 def __getitem__(self, node): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
369 return self.get('', node) |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
370 |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
371 def get(self, dir, node): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
372 if dir: |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
373 raise RuntimeError("hggit doesn't support treemanifests") |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
374 if node == nullid: |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
375 return manifest.manifestctx() |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
376 return overlaymanifestctx(self._repo, node) |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
377 except AttributeError: |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
378 # manifestlog did not exist prior to 4.0 |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
379 pass |
997
7b11e6348810
overlay: add support for upstream manifestlog transition
Ryan McElroy <rmcelroy@fb.com>
parents:
988
diff
changeset
|
380 |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
381 class overlaychangelog(overlayrevlog): |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
382 def read(self, sha): |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
383 if isinstance(sha, int): |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
384 sha = self.node(sha) |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
385 if sha == nullid: |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
386 return (nullid, "", (0, 0), [], "", {}) |
855
4538981d2c3f
overlaychangelog: return tuples for read()
Siddharth Agarwal <sid0@fb.com>
parents:
854
diff
changeset
|
387 try: |
4538981d2c3f
overlaychangelog: return tuples for read()
Siddharth Agarwal <sid0@fb.com>
parents:
854
diff
changeset
|
388 return self.base.read(sha) |
4538981d2c3f
overlaychangelog: return tuples for read()
Siddharth Agarwal <sid0@fb.com>
parents:
854
diff
changeset
|
389 except LookupError: |
4538981d2c3f
overlaychangelog: return tuples for read()
Siddharth Agarwal <sid0@fb.com>
parents:
854
diff
changeset
|
390 return overlaychangectx(self.repo, sha).totuple() |
408 | 391 |
988
49e363aebdd0
overlay: add changelogrevision
Mateusz Kwapich <mitrandir@fb.com>
parents:
965
diff
changeset
|
392 def changelogrevision(self, noderev): |
49e363aebdd0
overlay: add changelogrevision
Mateusz Kwapich <mitrandir@fb.com>
parents:
965
diff
changeset
|
393 return changelog._changelogrevision(*self.read(noderev)) |
49e363aebdd0
overlay: add changelogrevision
Mateusz Kwapich <mitrandir@fb.com>
parents:
965
diff
changeset
|
394 |
408 | 395 class overlayrepo(object): |
396 def __init__(self, handler, commits, refs): | |
397 self.handler = handler | |
398 | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
399 self.changelog = overlaychangelog(self, handler.repo.changelog) |
1001
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
400 if util.safehasattr(handler.repo, 'manifest'): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
401 self.manifest = overlayoldmanifestlog(self, handler.repo.manifest) |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
402 # new as of mercurial 3.9+ |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
403 self.manifestlog = self.manifest |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
404 else: |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
405 # no more manifest class as of 4.1 |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
406 self.manifestlog = overlaymanifestlog(self) |
408 | 407 |
408 # for incoming -p | |
409 self.root = handler.repo.root | |
410 self.getcwd = handler.repo.getcwd | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
411 # self.status = handler.repo.status |
408 | 412 self.ui = handler.repo.ui |
413 | |
414 self.revmap = None | |
415 self.nodemap = None | |
416 self.refmap = None | |
417 self.tagmap = None | |
418 | |
419 self._makemaps(commits, refs) | |
420 | |
854
eba7dcfab1bb
overlay: add namespace support to overlayrepo to support Mercurial >= 3.3
Siddharth Agarwal <sid0@fb.com>
parents:
829
diff
changeset
|
421 try: |
eba7dcfab1bb
overlay: add namespace support to overlayrepo to support Mercurial >= 3.3
Siddharth Agarwal <sid0@fb.com>
parents:
829
diff
changeset
|
422 # Mercurial >= 3.3 |
eba7dcfab1bb
overlay: add namespace support to overlayrepo to support Mercurial >= 3.3
Siddharth Agarwal <sid0@fb.com>
parents:
829
diff
changeset
|
423 from mercurial import namespaces |
eba7dcfab1bb
overlay: add namespace support to overlayrepo to support Mercurial >= 3.3
Siddharth Agarwal <sid0@fb.com>
parents:
829
diff
changeset
|
424 self.names = namespaces.namespaces() |
956
06385a2b30f3
init: handle AttributeError in addition to ImportError
timeless@gmail.com
parents:
900
diff
changeset
|
425 except (AttributeError, ImportError): |
854
eba7dcfab1bb
overlay: add namespace support to overlayrepo to support Mercurial >= 3.3
Siddharth Agarwal <sid0@fb.com>
parents:
829
diff
changeset
|
426 pass |
eba7dcfab1bb
overlay: add namespace support to overlayrepo to support Mercurial >= 3.3
Siddharth Agarwal <sid0@fb.com>
parents:
829
diff
changeset
|
427 |
1001
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
428 def _constructmanifest(self): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
429 return overlaymanifestrevlog(self, |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
430 self.handler.repo._constructmanifest()) |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
431 |
408 | 432 def __getitem__(self, n): |
433 if n not in self.revmap: | |
434 return self.handler.repo[n] | |
435 return overlaychangectx(self, n) | |
436 | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
437 def _handlerhack(self, method, *args, **kwargs): |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
438 nothing = object() |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
439 r = self.handler.repo |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
440 oldhandler = getattr(r, 'handler', nothing) |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
441 oldoverlay = getattr(r, 'gitoverlay', nothing) |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
442 r.handler = self.handler |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
443 r.gitoverlay = self |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
444 try: |
896 | 445 return getattr(r, method)(*args, **kwargs) |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
446 finally: |
896 | 447 if oldhandler is nothing: |
448 del r.handler | |
449 else: | |
450 r.handler = oldhandler | |
451 if oldoverlay is nothing: | |
452 del r.gitoverlay | |
453 else: | |
454 r.gitoverlay = oldoverlay | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
455 |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
456 def status(self, *args, **kwargs): |
896 | 457 return self._handlerhack('status', *args, **kwargs) |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
458 |
557
4f4ab2d89375
gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
459 def node(self, n): |
4f4ab2d89375
gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
460 """Returns an Hg or Git hash for the specified Git hash""" |
4f4ab2d89375
gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
461 if bin(n) in self.revmap: |
4f4ab2d89375
gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
462 return n |
4f4ab2d89375
gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
463 return self.handler.map_hg_get(n) |
4f4ab2d89375
gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
464 |
408 | 465 def nodebookmarks(self, n): |
466 return self.refmap.get(n, []) | |
467 | |
468 def nodetags(self, n): | |
469 return self.tagmap.get(n, []) | |
470 | |
471 def rev(self, n): | |
472 return self.revmap[n] | |
473 | |
474 def filectx(self, path, fileid=None): | |
475 return overlayfilectx(self, path, fileid=fileid) | |
476 | |
1004
6faa33912cd5
hotfix: add unfiltered() method to fix tests
Stanislau Hlebik <stash@fb.com>
parents:
1001
diff
changeset
|
477 def unfiltered(self): |
6faa33912cd5
hotfix: add unfiltered() method to fix tests
Stanislau Hlebik <stash@fb.com>
parents:
1001
diff
changeset
|
478 return self.handler.repo.unfiltered() |
6faa33912cd5
hotfix: add unfiltered() method to fix tests
Stanislau Hlebik <stash@fb.com>
parents:
1001
diff
changeset
|
479 |
408 | 480 def _makemaps(self, commits, refs): |
481 baserev = self.handler.repo['tip'].rev() | |
482 self.revmap = {} | |
483 self.nodemap = {} | |
484 for i, n in enumerate(commits): | |
485 rev = baserev + i + 1 | |
486 self.revmap[n] = rev | |
487 self.nodemap[rev] = n | |
488 | |
489 self.refmap = {} | |
490 self.tagmap = {} | |
491 for ref in refs: | |
492 if ref.startswith('refs/heads/'): | |
493 refname = ref[11:] | |
494 self.refmap.setdefault(bin(refs[ref]), []).append(refname) | |
495 elif ref.startswith('refs/tags/'): | |
496 tagname = ref[10:] | |
497 self.tagmap.setdefault(bin(refs[ref]), []).append(tagname) |