Mercurial > hg-git
annotate hggit/overlay.py @ 1110:94aaea5c65f7
cleanup: fix incorrect indentation
author | Sean Farley <sean@farley.io> |
---|---|
date | Mon, 27 Nov 2017 18:22:34 -0500 |
parents | 6bb4c99362f0 |
children | f1c4e2ba8ff9 |
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): | |
1052
5821075b289a
context: update to work with upstream
Durham Goode <durham@fb.com>
parents:
1019
diff
changeset
|
177 self._repo = repo |
408 | 178 self._path = path |
179 self.fileid = fileid | |
180 | |
1052
5821075b289a
context: update to work with upstream
Durham Goode <durham@fb.com>
parents:
1019
diff
changeset
|
181 def repo(self): |
5821075b289a
context: update to work with upstream
Durham Goode <durham@fb.com>
parents:
1019
diff
changeset
|
182 return self._repo |
5821075b289a
context: update to work with upstream
Durham Goode <durham@fb.com>
parents:
1019
diff
changeset
|
183 |
408 | 184 # this is a hack to skip copy detection |
185 def ancestors(self): | |
186 return [self, self] | |
187 | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
188 def filenode(self): |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
189 return nullid |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
190 |
408 | 191 def rev(self): |
192 return -1 | |
193 | |
194 def path(self): | |
195 return self._path | |
196 | |
197 def filelog(self): | |
198 return self.fileid | |
199 | |
200 def data(self): | |
1052
5821075b289a
context: update to work with upstream
Durham Goode <durham@fb.com>
parents:
1019
diff
changeset
|
201 blob = self._repo.handler.git.get_object(_maybehex(self.fileid)) |
408 | 202 return blob.data |
203 | |
1019
d356f8479295
overlayfilectx: provide an isbinary() method
Jun Wu <quark@fb.com>
parents:
1011
diff
changeset
|
204 def isbinary(self): |
d356f8479295
overlayfilectx: provide an isbinary() method
Jun Wu <quark@fb.com>
parents:
1011
diff
changeset
|
205 return util.binary(self.data()) |
d356f8479295
overlayfilectx: provide an isbinary() method
Jun Wu <quark@fb.com>
parents:
1011
diff
changeset
|
206 |
408 | 207 class overlaychangectx(context.changectx): |
208 def __init__(self, repo, sha): | |
1052
5821075b289a
context: update to work with upstream
Durham Goode <durham@fb.com>
parents:
1019
diff
changeset
|
209 # Can't store this in self._repo because the base class uses that field |
5821075b289a
context: update to work with upstream
Durham Goode <durham@fb.com>
parents:
1019
diff
changeset
|
210 self._hgrepo = repo |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
211 if not isinstance(sha, basestring): |
896 | 212 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
|
213 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
|
214 self._overlay = getattr(repo, 'gitoverlay', repo) |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
215 self._rev = self._overlay.rev(bin(self.commit.id)) |
408 | 216 |
1052
5821075b289a
context: update to work with upstream
Durham Goode <durham@fb.com>
parents:
1019
diff
changeset
|
217 def repo(self): |
5821075b289a
context: update to work with upstream
Durham Goode <durham@fb.com>
parents:
1019
diff
changeset
|
218 return self._hgrepo |
5821075b289a
context: update to work with upstream
Durham Goode <durham@fb.com>
parents:
1019
diff
changeset
|
219 |
408 | 220 def node(self): |
221 return bin(self.commit.id) | |
222 | |
223 def rev(self): | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
224 return self._rev |
408 | 225 |
226 def date(self): | |
227 return self.commit.author_time, self.commit.author_timezone | |
228 | |
229 def branch(self): | |
230 return 'default' | |
231 | |
232 def user(self): | |
233 return self.commit.author | |
234 | |
235 def files(self): | |
236 return [] | |
237 | |
238 def extra(self): | |
239 return {} | |
240 | |
241 def description(self): | |
242 return self.commit.message | |
243 | |
244 def parents(self): | |
1052
5821075b289a
context: update to work with upstream
Durham Goode <durham@fb.com>
parents:
1019
diff
changeset
|
245 cl = self._hgrepo.changelog |
900
db308eba5251
overlaychangectx: use overlayrevlog logic to determine parents
Siddharth Agarwal <sid0@fb.com>
parents:
899
diff
changeset
|
246 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
|
247 if not parents: |
1052
5821075b289a
context: update to work with upstream
Durham Goode <durham@fb.com>
parents:
1019
diff
changeset
|
248 return [self._hgrepo['null']] |
900
db308eba5251
overlaychangectx: use overlayrevlog logic to determine parents
Siddharth Agarwal <sid0@fb.com>
parents:
899
diff
changeset
|
249 if parents[1] == nullid: |
db308eba5251
overlaychangectx: use overlayrevlog logic to determine parents
Siddharth Agarwal <sid0@fb.com>
parents:
899
diff
changeset
|
250 parents = parents[:-1] |
1052
5821075b289a
context: update to work with upstream
Durham Goode <durham@fb.com>
parents:
1019
diff
changeset
|
251 return [self._hgrepo[sha] for sha in parents] |
408 | 252 |
253 def manifestnode(self): | |
254 return bin(self.commit.tree) | |
255 | |
256 def hex(self): | |
257 return self.commit.id | |
258 | |
259 def tags(self): | |
260 return [] | |
261 | |
262 def bookmarks(self): | |
263 return [] | |
264 | |
265 def manifest(self): | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
266 return overlaymanifest(self._overlay, self.commit.tree) |
408 | 267 |
268 def filectx(self, path, filelog=None): | |
269 mf = self.manifest() | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
270 return overlayfilectx(self._overlay, path, mf[path]) |
408 | 271 |
272 def flags(self, path): | |
273 mf = self.manifest() | |
274 return mf.flags(path) | |
275 | |
276 def __nonzero__(self): | |
277 return True | |
278 | |
568
41f6e3df67b1
overlaychangectx: fix compatibility with mercurial 2.4-rc (no attribute _repo)
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
279 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
|
280 try: |
41f6e3df67b1
overlaychangectx: fix compatibility with mercurial 2.4-rc (no attribute _repo)
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
281 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
|
282 return phases.draft |
956
06385a2b30f3
init: handle AttributeError in addition to ImportError
timeless@gmail.com
parents:
900
diff
changeset
|
283 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
|
284 return 1 |
41f6e3df67b1
overlaychangectx: fix compatibility with mercurial 2.4-rc (no attribute _repo)
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
285 |
855
4538981d2c3f
overlaychangelog: return tuples for read()
Siddharth Agarwal <sid0@fb.com>
parents:
854
diff
changeset
|
286 def totuple(self): |
4538981d2c3f
overlaychangelog: return tuples for read()
Siddharth Agarwal <sid0@fb.com>
parents:
854
diff
changeset
|
287 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
|
288 self.description(), self.extra()) |
4538981d2c3f
overlaychangelog: return tuples for read()
Siddharth Agarwal <sid0@fb.com>
parents:
854
diff
changeset
|
289 |
408 | 290 class overlayrevlog(object): |
291 def __init__(self, repo, base): | |
292 self.repo = repo | |
293 self.base = base | |
294 | |
295 def parents(self, n): | |
296 gitrev = self.repo.revmap.get(n) | |
689
aa8519daf037
overlayrevlog: handle rev = 0 correctly
Siddharth Agarwal <sid0@fb.com>
parents:
684
diff
changeset
|
297 if gitrev is None: |
408 | 298 # we've reached a revision we have |
299 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
|
300 commit = self.repo.handler.git.get_object(_maybehex(n)) |
408 | 301 |
690
c99941ff2d28
overlayrevlog: handle root commits correctly
Siddharth Agarwal <sid0@fb.com>
parents:
689
diff
changeset
|
302 if not commit.parents: |
c99941ff2d28
overlayrevlog: handle root commits correctly
Siddharth Agarwal <sid0@fb.com>
parents:
689
diff
changeset
|
303 return [nullid, nullid] |
c99941ff2d28
overlayrevlog: handle root commits correctly
Siddharth Agarwal <sid0@fb.com>
parents:
689
diff
changeset
|
304 |
408 | 305 def gitorhg(n): |
306 hn = self.repo.handler.map_hg_get(hex(n)) | |
307 if hn is not None: | |
308 return bin(hn) | |
309 return n | |
310 | |
311 # currently ignores the octopus | |
312 p1 = gitorhg(bin(commit.parents[0])) | |
313 if len(commit.parents) > 1: | |
314 p2 = gitorhg(bin(commit.parents[1])) | |
315 else: | |
316 p2 = nullid | |
317 | |
318 return [p1, p2] | |
319 | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
320 def ancestor(self, a, b): |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
321 anode = self.repo.nodemap.get(a) |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
322 bnode = self.repo.nodemap.get(b) |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
323 if anode is None and bnode is None: |
896 | 324 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
|
325 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
|
326 if ancs: |
896 | 327 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
|
328 return nullid |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
329 |
408 | 330 def parentrevs(self, rev): |
331 return [self.rev(p) for p in self.parents(self.node(rev))] | |
332 | |
333 def node(self, rev): | |
334 gitnode = self.repo.nodemap.get(rev) | |
335 if gitnode is None: | |
336 return self.base.node(rev) | |
337 return gitnode | |
338 | |
339 def rev(self, n): | |
340 gitrev = self.repo.revmap.get(n) | |
341 if gitrev is None: | |
896 | 342 return self.base.rev(n) |
408 | 343 return gitrev |
344 | |
345 def __len__(self): | |
346 return len(self.repo.handler.repo) + len(self.repo.revmap) | |
347 | |
1001
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
348 class overlayoldmanifestlog(overlayrevlog): |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
349 def read(self, sha): |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
350 if sha == nullid: |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
351 return manifest.manifestdict() |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
352 return overlaymanifest(self.repo, sha) |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
353 |
997
7b11e6348810
overlay: add support for upstream manifestlog transition
Ryan McElroy <rmcelroy@fb.com>
parents:
988
diff
changeset
|
354 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
|
355 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
|
356 |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
357 class overlaymanifestrevlog(overlayrevlog): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
358 pass |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
359 |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
360 class overlaymanifestctx(object): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
361 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
|
362 self._repo = repo |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
363 self._node = node |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
364 |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
365 def read(self): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
366 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
|
367 |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
368 try: |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
369 class overlaymanifestlog(manifest.manifestlog): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
370 def __init__(self, repo): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
371 self._repo = repo |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
372 |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
373 # 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
|
374 # release. |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
375 def __getitem__(self, node): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
376 return self.get('', node) |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
377 |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
378 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
|
379 if dir: |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
380 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
|
381 if node == nullid: |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
382 return manifest.manifestctx() |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
383 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
|
384 except AttributeError: |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
385 # 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
|
386 pass |
997
7b11e6348810
overlay: add support for upstream manifestlog transition
Ryan McElroy <rmcelroy@fb.com>
parents:
988
diff
changeset
|
387 |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
388 class overlaychangelog(overlayrevlog): |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
389 def read(self, sha): |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
390 if isinstance(sha, int): |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
391 sha = self.node(sha) |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
392 if sha == nullid: |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
393 return (nullid, "", (0, 0), [], "", {}) |
855
4538981d2c3f
overlaychangelog: return tuples for read()
Siddharth Agarwal <sid0@fb.com>
parents:
854
diff
changeset
|
394 try: |
4538981d2c3f
overlaychangelog: return tuples for read()
Siddharth Agarwal <sid0@fb.com>
parents:
854
diff
changeset
|
395 return self.base.read(sha) |
4538981d2c3f
overlaychangelog: return tuples for read()
Siddharth Agarwal <sid0@fb.com>
parents:
854
diff
changeset
|
396 except LookupError: |
4538981d2c3f
overlaychangelog: return tuples for read()
Siddharth Agarwal <sid0@fb.com>
parents:
854
diff
changeset
|
397 return overlaychangectx(self.repo, sha).totuple() |
408 | 398 |
988
49e363aebdd0
overlay: add changelogrevision
Mateusz Kwapich <mitrandir@fb.com>
parents:
965
diff
changeset
|
399 def changelogrevision(self, noderev): |
1053
6bb4c99362f0
overlay: update changelogrevision
Durham Goode <durham@fb.com>
parents:
1052
diff
changeset
|
400 values = self.read(noderev) |
6bb4c99362f0
overlay: update changelogrevision
Durham Goode <durham@fb.com>
parents:
1052
diff
changeset
|
401 return changelog._changelogrevision( |
6bb4c99362f0
overlay: update changelogrevision
Durham Goode <durham@fb.com>
parents:
1052
diff
changeset
|
402 manifest=values[0], |
6bb4c99362f0
overlay: update changelogrevision
Durham Goode <durham@fb.com>
parents:
1052
diff
changeset
|
403 user=values[1], |
6bb4c99362f0
overlay: update changelogrevision
Durham Goode <durham@fb.com>
parents:
1052
diff
changeset
|
404 date=values[2], |
6bb4c99362f0
overlay: update changelogrevision
Durham Goode <durham@fb.com>
parents:
1052
diff
changeset
|
405 files=values[3], |
6bb4c99362f0
overlay: update changelogrevision
Durham Goode <durham@fb.com>
parents:
1052
diff
changeset
|
406 description=values[4], |
6bb4c99362f0
overlay: update changelogrevision
Durham Goode <durham@fb.com>
parents:
1052
diff
changeset
|
407 extra=values[5], |
6bb4c99362f0
overlay: update changelogrevision
Durham Goode <durham@fb.com>
parents:
1052
diff
changeset
|
408 ) |
988
49e363aebdd0
overlay: add changelogrevision
Mateusz Kwapich <mitrandir@fb.com>
parents:
965
diff
changeset
|
409 |
408 | 410 class overlayrepo(object): |
411 def __init__(self, handler, commits, refs): | |
412 self.handler = handler | |
413 | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
414 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
|
415 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
|
416 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
|
417 # 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
|
418 self.manifestlog = self.manifest |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
419 else: |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
420 # 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
|
421 self.manifestlog = overlaymanifestlog(self) |
408 | 422 |
423 # for incoming -p | |
424 self.root = handler.repo.root | |
425 self.getcwd = handler.repo.getcwd | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
426 # self.status = handler.repo.status |
408 | 427 self.ui = handler.repo.ui |
428 | |
429 self.revmap = None | |
430 self.nodemap = None | |
431 self.refmap = None | |
432 self.tagmap = None | |
433 | |
434 self._makemaps(commits, refs) | |
435 | |
854
eba7dcfab1bb
overlay: add namespace support to overlayrepo to support Mercurial >= 3.3
Siddharth Agarwal <sid0@fb.com>
parents:
829
diff
changeset
|
436 try: |
eba7dcfab1bb
overlay: add namespace support to overlayrepo to support Mercurial >= 3.3
Siddharth Agarwal <sid0@fb.com>
parents:
829
diff
changeset
|
437 # Mercurial >= 3.3 |
eba7dcfab1bb
overlay: add namespace support to overlayrepo to support Mercurial >= 3.3
Siddharth Agarwal <sid0@fb.com>
parents:
829
diff
changeset
|
438 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
|
439 self.names = namespaces.namespaces() |
956
06385a2b30f3
init: handle AttributeError in addition to ImportError
timeless@gmail.com
parents:
900
diff
changeset
|
440 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
|
441 pass |
eba7dcfab1bb
overlay: add namespace support to overlayrepo to support Mercurial >= 3.3
Siddharth Agarwal <sid0@fb.com>
parents:
829
diff
changeset
|
442 |
1001
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
443 def _constructmanifest(self): |
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
444 return overlaymanifestrevlog(self, |
1110
94aaea5c65f7
cleanup: fix incorrect indentation
Sean Farley <sean@farley.io>
parents:
1053
diff
changeset
|
445 self.handler.repo._constructmanifest()) |
1001
fa23c454c528
manifest: update to work with new manifest classes in core
Durham Goode <durham@fb.com>
parents:
997
diff
changeset
|
446 |
408 | 447 def __getitem__(self, n): |
448 if n not in self.revmap: | |
449 return self.handler.repo[n] | |
450 return overlaychangectx(self, n) | |
451 | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
452 def _handlerhack(self, method, *args, **kwargs): |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
453 nothing = object() |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
454 r = self.handler.repo |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
455 oldhandler = getattr(r, 'handler', nothing) |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
456 oldoverlay = getattr(r, 'gitoverlay', nothing) |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
457 r.handler = self.handler |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
458 r.gitoverlay = self |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
459 try: |
896 | 460 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
|
461 finally: |
896 | 462 if oldhandler is nothing: |
463 del r.handler | |
464 else: | |
465 r.handler = oldhandler | |
466 if oldoverlay is nothing: | |
467 del r.gitoverlay | |
468 else: | |
469 r.gitoverlay = oldoverlay | |
612
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
470 |
bf8518b09d57
overlays: fix incoming support for hg 2.8
Augie Fackler <raf@durin42.com>
parents:
597
diff
changeset
|
471 def status(self, *args, **kwargs): |
896 | 472 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
|
473 |
557
4f4ab2d89375
gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
474 def node(self, n): |
4f4ab2d89375
gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
475 """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
|
476 if bin(n) in self.revmap: |
4f4ab2d89375
gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
477 return n |
4f4ab2d89375
gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
478 return self.handler.map_hg_get(n) |
4f4ab2d89375
gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents:
466
diff
changeset
|
479 |
408 | 480 def nodebookmarks(self, n): |
481 return self.refmap.get(n, []) | |
482 | |
483 def nodetags(self, n): | |
484 return self.tagmap.get(n, []) | |
485 | |
486 def rev(self, n): | |
487 return self.revmap[n] | |
488 | |
489 def filectx(self, path, fileid=None): | |
490 return overlayfilectx(self, path, fileid=fileid) | |
491 | |
1004
6faa33912cd5
hotfix: add unfiltered() method to fix tests
Stanislau Hlebik <stash@fb.com>
parents:
1001
diff
changeset
|
492 def unfiltered(self): |
6faa33912cd5
hotfix: add unfiltered() method to fix tests
Stanislau Hlebik <stash@fb.com>
parents:
1001
diff
changeset
|
493 return self.handler.repo.unfiltered() |
6faa33912cd5
hotfix: add unfiltered() method to fix tests
Stanislau Hlebik <stash@fb.com>
parents:
1001
diff
changeset
|
494 |
408 | 495 def _makemaps(self, commits, refs): |
496 baserev = self.handler.repo['tip'].rev() | |
497 self.revmap = {} | |
498 self.nodemap = {} | |
499 for i, n in enumerate(commits): | |
500 rev = baserev + i + 1 | |
501 self.revmap[n] = rev | |
502 self.nodemap[rev] = n | |
503 | |
504 self.refmap = {} | |
505 self.tagmap = {} | |
506 for ref in refs: | |
507 if ref.startswith('refs/heads/'): | |
508 refname = ref[11:] | |
509 self.refmap.setdefault(bin(refs[ref]), []).append(refname) | |
510 elif ref.startswith('refs/tags/'): | |
511 tagname = ref[10:] | |
512 self.tagmap.setdefault(bin(refs[ref]), []).append(tagname) |