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