Show More
@@ -1,1900 +1,1900 b'' | |||||
1 | # localrepo.py - read/write repository class for mercurial |
|
1 | # localrepo.py - read/write repository class for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from node import bin, hex, nullid, nullrev, short |
|
8 | from node import bin, hex, nullid, nullrev, short | |
9 | from i18n import _ |
|
9 | from i18n import _ | |
10 | import repo, changegroup, subrepo, discovery, pushkey |
|
10 | import repo, changegroup, subrepo, discovery, pushkey | |
11 | import changelog, dirstate, filelog, manifest, context |
|
11 | import changelog, dirstate, filelog, manifest, context | |
12 | import lock, transaction, store, encoding |
|
12 | import lock, transaction, store, encoding | |
13 | import util, extensions, hook, error |
|
13 | import util, extensions, hook, error | |
14 | import match as matchmod |
|
14 | import match as matchmod | |
15 | import merge as mergemod |
|
15 | import merge as mergemod | |
16 | import tags as tagsmod |
|
16 | import tags as tagsmod | |
17 | import url as urlmod |
|
17 | import url as urlmod | |
18 | from lock import release |
|
18 | from lock import release | |
19 | import weakref, errno, os, time, inspect |
|
19 | import weakref, errno, os, time, inspect | |
20 | propertycache = util.propertycache |
|
20 | propertycache = util.propertycache | |
21 |
|
21 | |||
22 | class localrepository(repo.repository): |
|
22 | class localrepository(repo.repository): | |
23 | capabilities = set(('lookup', 'changegroupsubset', 'branchmap', 'pushkey')) |
|
23 | capabilities = set(('lookup', 'changegroupsubset', 'branchmap', 'pushkey')) | |
24 | supportedformats = set(('revlogv1', 'parentdelta')) |
|
24 | supportedformats = set(('revlogv1', 'parentdelta')) | |
25 | supported = supportedformats | set(('store', 'fncache', 'shared', |
|
25 | supported = supportedformats | set(('store', 'fncache', 'shared', | |
26 | 'dotencode')) |
|
26 | 'dotencode')) | |
27 |
|
27 | |||
28 | def __init__(self, baseui, path=None, create=0): |
|
28 | def __init__(self, baseui, path=None, create=0): | |
29 | repo.repository.__init__(self) |
|
29 | repo.repository.__init__(self) | |
30 | self.root = os.path.realpath(util.expandpath(path)) |
|
30 | self.root = os.path.realpath(util.expandpath(path)) | |
31 | self.path = os.path.join(self.root, ".hg") |
|
31 | self.path = os.path.join(self.root, ".hg") | |
32 | self.origroot = path |
|
32 | self.origroot = path | |
33 | self.auditor = util.path_auditor(self.root, self._checknested) |
|
33 | self.auditor = util.path_auditor(self.root, self._checknested) | |
34 | self.opener = util.opener(self.path) |
|
34 | self.opener = util.opener(self.path) | |
35 | self.wopener = util.opener(self.root) |
|
35 | self.wopener = util.opener(self.root) | |
36 | self.baseui = baseui |
|
36 | self.baseui = baseui | |
37 | self.ui = baseui.copy() |
|
37 | self.ui = baseui.copy() | |
38 |
|
38 | |||
39 | try: |
|
39 | try: | |
40 | self.ui.readconfig(self.join("hgrc"), self.root) |
|
40 | self.ui.readconfig(self.join("hgrc"), self.root) | |
41 | extensions.loadall(self.ui) |
|
41 | extensions.loadall(self.ui) | |
42 | except IOError: |
|
42 | except IOError: | |
43 | pass |
|
43 | pass | |
44 |
|
44 | |||
45 | if not os.path.isdir(self.path): |
|
45 | if not os.path.isdir(self.path): | |
46 | if create: |
|
46 | if create: | |
47 | if not os.path.exists(path): |
|
47 | if not os.path.exists(path): | |
48 | util.makedirs(path) |
|
48 | util.makedirs(path) | |
49 | os.mkdir(self.path) |
|
49 | os.mkdir(self.path) | |
50 | requirements = ["revlogv1"] |
|
50 | requirements = ["revlogv1"] | |
51 | if self.ui.configbool('format', 'usestore', True): |
|
51 | if self.ui.configbool('format', 'usestore', True): | |
52 | os.mkdir(os.path.join(self.path, "store")) |
|
52 | os.mkdir(os.path.join(self.path, "store")) | |
53 | requirements.append("store") |
|
53 | requirements.append("store") | |
54 | if self.ui.configbool('format', 'usefncache', True): |
|
54 | if self.ui.configbool('format', 'usefncache', True): | |
55 | requirements.append("fncache") |
|
55 | requirements.append("fncache") | |
56 | if self.ui.configbool('format', 'dotencode', True): |
|
56 | if self.ui.configbool('format', 'dotencode', True): | |
57 | requirements.append('dotencode') |
|
57 | requirements.append('dotencode') | |
58 | # create an invalid changelog |
|
58 | # create an invalid changelog | |
59 | self.opener("00changelog.i", "a").write( |
|
59 | self.opener("00changelog.i", "a").write( | |
60 | '\0\0\0\2' # represents revlogv2 |
|
60 | '\0\0\0\2' # represents revlogv2 | |
61 | ' dummy changelog to prevent using the old repo layout' |
|
61 | ' dummy changelog to prevent using the old repo layout' | |
62 | ) |
|
62 | ) | |
63 | if self.ui.configbool('format', 'parentdelta', False): |
|
63 | if self.ui.configbool('format', 'parentdelta', False): | |
64 | requirements.append("parentdelta") |
|
64 | requirements.append("parentdelta") | |
65 | else: |
|
65 | else: | |
66 | raise error.RepoError(_("repository %s not found") % path) |
|
66 | raise error.RepoError(_("repository %s not found") % path) | |
67 | elif create: |
|
67 | elif create: | |
68 | raise error.RepoError(_("repository %s already exists") % path) |
|
68 | raise error.RepoError(_("repository %s already exists") % path) | |
69 | else: |
|
69 | else: | |
70 | # find requirements |
|
70 | # find requirements | |
71 | requirements = set() |
|
71 | requirements = set() | |
72 | try: |
|
72 | try: | |
73 | requirements = set(self.opener("requires").read().splitlines()) |
|
73 | requirements = set(self.opener("requires").read().splitlines()) | |
74 | except IOError, inst: |
|
74 | except IOError, inst: | |
75 | if inst.errno != errno.ENOENT: |
|
75 | if inst.errno != errno.ENOENT: | |
76 | raise |
|
76 | raise | |
77 | for r in requirements - self.supported: |
|
77 | for r in requirements - self.supported: | |
78 | raise error.RepoError(_("requirement '%s' not supported") % r) |
|
78 | raise error.RepoError(_("requirement '%s' not supported") % r) | |
79 |
|
79 | |||
80 | self.sharedpath = self.path |
|
80 | self.sharedpath = self.path | |
81 | try: |
|
81 | try: | |
82 | s = os.path.realpath(self.opener("sharedpath").read()) |
|
82 | s = os.path.realpath(self.opener("sharedpath").read()) | |
83 | if not os.path.exists(s): |
|
83 | if not os.path.exists(s): | |
84 | raise error.RepoError( |
|
84 | raise error.RepoError( | |
85 | _('.hg/sharedpath points to nonexistent directory %s') % s) |
|
85 | _('.hg/sharedpath points to nonexistent directory %s') % s) | |
86 | self.sharedpath = s |
|
86 | self.sharedpath = s | |
87 | except IOError, inst: |
|
87 | except IOError, inst: | |
88 | if inst.errno != errno.ENOENT: |
|
88 | if inst.errno != errno.ENOENT: | |
89 | raise |
|
89 | raise | |
90 |
|
90 | |||
91 | self.store = store.store(requirements, self.sharedpath, util.opener) |
|
91 | self.store = store.store(requirements, self.sharedpath, util.opener) | |
92 | self.spath = self.store.path |
|
92 | self.spath = self.store.path | |
93 | self.sopener = self.store.opener |
|
93 | self.sopener = self.store.opener | |
94 | self.sjoin = self.store.join |
|
94 | self.sjoin = self.store.join | |
95 | self.opener.createmode = self.store.createmode |
|
95 | self.opener.createmode = self.store.createmode | |
96 | self._applyrequirements(requirements) |
|
96 | self._applyrequirements(requirements) | |
97 | if create: |
|
97 | if create: | |
98 | self._writerequirements() |
|
98 | self._writerequirements() | |
99 |
|
99 | |||
100 | # These two define the set of tags for this repository. _tags |
|
100 | # These two define the set of tags for this repository. _tags | |
101 | # maps tag name to node; _tagtypes maps tag name to 'global' or |
|
101 | # maps tag name to node; _tagtypes maps tag name to 'global' or | |
102 | # 'local'. (Global tags are defined by .hgtags across all |
|
102 | # 'local'. (Global tags are defined by .hgtags across all | |
103 | # heads, and local tags are defined in .hg/localtags.) They |
|
103 | # heads, and local tags are defined in .hg/localtags.) They | |
104 | # constitute the in-memory cache of tags. |
|
104 | # constitute the in-memory cache of tags. | |
105 | self._tags = None |
|
105 | self._tags = None | |
106 | self._tagtypes = None |
|
106 | self._tagtypes = None | |
107 |
|
107 | |||
108 | self._branchcache = None # in UTF-8 |
|
108 | self._branchcache = None # in UTF-8 | |
109 | self._branchcachetip = None |
|
109 | self._branchcachetip = None | |
110 | self.nodetagscache = None |
|
110 | self.nodetagscache = None | |
111 | self.filterpats = {} |
|
111 | self.filterpats = {} | |
112 | self._datafilters = {} |
|
112 | self._datafilters = {} | |
113 | self._transref = self._lockref = self._wlockref = None |
|
113 | self._transref = self._lockref = self._wlockref = None | |
114 |
|
114 | |||
115 | def _applyrequirements(self, requirements): |
|
115 | def _applyrequirements(self, requirements): | |
116 | self.requirements = requirements |
|
116 | self.requirements = requirements | |
117 | self.sopener.options = {} |
|
117 | self.sopener.options = {} | |
118 | if 'parentdelta' in requirements: |
|
118 | if 'parentdelta' in requirements: | |
119 | self.sopener.options['parentdelta'] = 1 |
|
119 | self.sopener.options['parentdelta'] = 1 | |
120 |
|
120 | |||
121 | def _writerequirements(self): |
|
121 | def _writerequirements(self): | |
122 | reqfile = self.opener("requires", "w") |
|
122 | reqfile = self.opener("requires", "w") | |
123 | for r in self.requirements: |
|
123 | for r in self.requirements: | |
124 | reqfile.write("%s\n" % r) |
|
124 | reqfile.write("%s\n" % r) | |
125 | reqfile.close() |
|
125 | reqfile.close() | |
126 |
|
126 | |||
127 | def _checknested(self, path): |
|
127 | def _checknested(self, path): | |
128 | """Determine if path is a legal nested repository.""" |
|
128 | """Determine if path is a legal nested repository.""" | |
129 | if not path.startswith(self.root): |
|
129 | if not path.startswith(self.root): | |
130 | return False |
|
130 | return False | |
131 | subpath = path[len(self.root) + 1:] |
|
131 | subpath = path[len(self.root) + 1:] | |
132 |
|
132 | |||
133 | # XXX: Checking against the current working copy is wrong in |
|
133 | # XXX: Checking against the current working copy is wrong in | |
134 | # the sense that it can reject things like |
|
134 | # the sense that it can reject things like | |
135 | # |
|
135 | # | |
136 | # $ hg cat -r 10 sub/x.txt |
|
136 | # $ hg cat -r 10 sub/x.txt | |
137 | # |
|
137 | # | |
138 | # if sub/ is no longer a subrepository in the working copy |
|
138 | # if sub/ is no longer a subrepository in the working copy | |
139 | # parent revision. |
|
139 | # parent revision. | |
140 | # |
|
140 | # | |
141 | # However, it can of course also allow things that would have |
|
141 | # However, it can of course also allow things that would have | |
142 | # been rejected before, such as the above cat command if sub/ |
|
142 | # been rejected before, such as the above cat command if sub/ | |
143 | # is a subrepository now, but was a normal directory before. |
|
143 | # is a subrepository now, but was a normal directory before. | |
144 | # The old path auditor would have rejected by mistake since it |
|
144 | # The old path auditor would have rejected by mistake since it | |
145 | # panics when it sees sub/.hg/. |
|
145 | # panics when it sees sub/.hg/. | |
146 | # |
|
146 | # | |
147 | # All in all, checking against the working copy seems sensible |
|
147 | # All in all, checking against the working copy seems sensible | |
148 | # since we want to prevent access to nested repositories on |
|
148 | # since we want to prevent access to nested repositories on | |
149 | # the filesystem *now*. |
|
149 | # the filesystem *now*. | |
150 | ctx = self[None] |
|
150 | ctx = self[None] | |
151 | parts = util.splitpath(subpath) |
|
151 | parts = util.splitpath(subpath) | |
152 | while parts: |
|
152 | while parts: | |
153 | prefix = os.sep.join(parts) |
|
153 | prefix = os.sep.join(parts) | |
154 | if prefix in ctx.substate: |
|
154 | if prefix in ctx.substate: | |
155 | if prefix == subpath: |
|
155 | if prefix == subpath: | |
156 | return True |
|
156 | return True | |
157 | else: |
|
157 | else: | |
158 | sub = ctx.sub(prefix) |
|
158 | sub = ctx.sub(prefix) | |
159 | return sub.checknested(subpath[len(prefix) + 1:]) |
|
159 | return sub.checknested(subpath[len(prefix) + 1:]) | |
160 | else: |
|
160 | else: | |
161 | parts.pop() |
|
161 | parts.pop() | |
162 | return False |
|
162 | return False | |
163 |
|
163 | |||
164 |
|
164 | |||
165 | @propertycache |
|
165 | @propertycache | |
166 | def changelog(self): |
|
166 | def changelog(self): | |
167 | c = changelog.changelog(self.sopener) |
|
167 | c = changelog.changelog(self.sopener) | |
168 | if 'HG_PENDING' in os.environ: |
|
168 | if 'HG_PENDING' in os.environ: | |
169 | p = os.environ['HG_PENDING'] |
|
169 | p = os.environ['HG_PENDING'] | |
170 | if p.startswith(self.root): |
|
170 | if p.startswith(self.root): | |
171 | c.readpending('00changelog.i.a') |
|
171 | c.readpending('00changelog.i.a') | |
172 | self.sopener.options['defversion'] = c.version |
|
172 | self.sopener.options['defversion'] = c.version | |
173 | return c |
|
173 | return c | |
174 |
|
174 | |||
175 | @propertycache |
|
175 | @propertycache | |
176 | def manifest(self): |
|
176 | def manifest(self): | |
177 | return manifest.manifest(self.sopener) |
|
177 | return manifest.manifest(self.sopener) | |
178 |
|
178 | |||
179 | @propertycache |
|
179 | @propertycache | |
180 | def dirstate(self): |
|
180 | def dirstate(self): | |
181 | return dirstate.dirstate(self.opener, self.ui, self.root) |
|
181 | return dirstate.dirstate(self.opener, self.ui, self.root) | |
182 |
|
182 | |||
183 | def __getitem__(self, changeid): |
|
183 | def __getitem__(self, changeid): | |
184 | if changeid is None: |
|
184 | if changeid is None: | |
185 | return context.workingctx(self) |
|
185 | return context.workingctx(self) | |
186 | return context.changectx(self, changeid) |
|
186 | return context.changectx(self, changeid) | |
187 |
|
187 | |||
188 | def __contains__(self, changeid): |
|
188 | def __contains__(self, changeid): | |
189 | try: |
|
189 | try: | |
190 | return bool(self.lookup(changeid)) |
|
190 | return bool(self.lookup(changeid)) | |
191 | except error.RepoLookupError: |
|
191 | except error.RepoLookupError: | |
192 | return False |
|
192 | return False | |
193 |
|
193 | |||
194 | def __nonzero__(self): |
|
194 | def __nonzero__(self): | |
195 | return True |
|
195 | return True | |
196 |
|
196 | |||
197 | def __len__(self): |
|
197 | def __len__(self): | |
198 | return len(self.changelog) |
|
198 | return len(self.changelog) | |
199 |
|
199 | |||
200 | def __iter__(self): |
|
200 | def __iter__(self): | |
201 | for i in xrange(len(self)): |
|
201 | for i in xrange(len(self)): | |
202 | yield i |
|
202 | yield i | |
203 |
|
203 | |||
204 | def url(self): |
|
204 | def url(self): | |
205 | return 'file:' + self.root |
|
205 | return 'file:' + self.root | |
206 |
|
206 | |||
207 | def hook(self, name, throw=False, **args): |
|
207 | def hook(self, name, throw=False, **args): | |
208 | return hook.hook(self.ui, self, name, throw, **args) |
|
208 | return hook.hook(self.ui, self, name, throw, **args) | |
209 |
|
209 | |||
210 | tag_disallowed = ':\r\n' |
|
210 | tag_disallowed = ':\r\n' | |
211 |
|
211 | |||
212 | def _tag(self, names, node, message, local, user, date, extra={}): |
|
212 | def _tag(self, names, node, message, local, user, date, extra={}): | |
213 | if isinstance(names, str): |
|
213 | if isinstance(names, str): | |
214 | allchars = names |
|
214 | allchars = names | |
215 | names = (names,) |
|
215 | names = (names,) | |
216 | else: |
|
216 | else: | |
217 | allchars = ''.join(names) |
|
217 | allchars = ''.join(names) | |
218 | for c in self.tag_disallowed: |
|
218 | for c in self.tag_disallowed: | |
219 | if c in allchars: |
|
219 | if c in allchars: | |
220 | raise util.Abort(_('%r cannot be used in a tag name') % c) |
|
220 | raise util.Abort(_('%r cannot be used in a tag name') % c) | |
221 |
|
221 | |||
222 | branches = self.branchmap() |
|
222 | branches = self.branchmap() | |
223 | for name in names: |
|
223 | for name in names: | |
224 | self.hook('pretag', throw=True, node=hex(node), tag=name, |
|
224 | self.hook('pretag', throw=True, node=hex(node), tag=name, | |
225 | local=local) |
|
225 | local=local) | |
226 | if name in branches: |
|
226 | if name in branches: | |
227 | self.ui.warn(_("warning: tag %s conflicts with existing" |
|
227 | self.ui.warn(_("warning: tag %s conflicts with existing" | |
228 | " branch name\n") % name) |
|
228 | " branch name\n") % name) | |
229 |
|
229 | |||
230 | def writetags(fp, names, munge, prevtags): |
|
230 | def writetags(fp, names, munge, prevtags): | |
231 | fp.seek(0, 2) |
|
231 | fp.seek(0, 2) | |
232 | if prevtags and prevtags[-1] != '\n': |
|
232 | if prevtags and prevtags[-1] != '\n': | |
233 | fp.write('\n') |
|
233 | fp.write('\n') | |
234 | for name in names: |
|
234 | for name in names: | |
235 | m = munge and munge(name) or name |
|
235 | m = munge and munge(name) or name | |
236 | if self._tagtypes and name in self._tagtypes: |
|
236 | if self._tagtypes and name in self._tagtypes: | |
237 | old = self._tags.get(name, nullid) |
|
237 | old = self._tags.get(name, nullid) | |
238 | fp.write('%s %s\n' % (hex(old), m)) |
|
238 | fp.write('%s %s\n' % (hex(old), m)) | |
239 | fp.write('%s %s\n' % (hex(node), m)) |
|
239 | fp.write('%s %s\n' % (hex(node), m)) | |
240 | fp.close() |
|
240 | fp.close() | |
241 |
|
241 | |||
242 | prevtags = '' |
|
242 | prevtags = '' | |
243 | if local: |
|
243 | if local: | |
244 | try: |
|
244 | try: | |
245 | fp = self.opener('localtags', 'r+') |
|
245 | fp = self.opener('localtags', 'r+') | |
246 | except IOError: |
|
246 | except IOError: | |
247 | fp = self.opener('localtags', 'a') |
|
247 | fp = self.opener('localtags', 'a') | |
248 | else: |
|
248 | else: | |
249 | prevtags = fp.read() |
|
249 | prevtags = fp.read() | |
250 |
|
250 | |||
251 | # local tags are stored in the current charset |
|
251 | # local tags are stored in the current charset | |
252 | writetags(fp, names, None, prevtags) |
|
252 | writetags(fp, names, None, prevtags) | |
253 | for name in names: |
|
253 | for name in names: | |
254 | self.hook('tag', node=hex(node), tag=name, local=local) |
|
254 | self.hook('tag', node=hex(node), tag=name, local=local) | |
255 | return |
|
255 | return | |
256 |
|
256 | |||
257 | try: |
|
257 | try: | |
258 | fp = self.wfile('.hgtags', 'rb+') |
|
258 | fp = self.wfile('.hgtags', 'rb+') | |
259 | except IOError: |
|
259 | except IOError: | |
260 | fp = self.wfile('.hgtags', 'ab') |
|
260 | fp = self.wfile('.hgtags', 'ab') | |
261 | else: |
|
261 | else: | |
262 | prevtags = fp.read() |
|
262 | prevtags = fp.read() | |
263 |
|
263 | |||
264 | # committed tags are stored in UTF-8 |
|
264 | # committed tags are stored in UTF-8 | |
265 | writetags(fp, names, encoding.fromlocal, prevtags) |
|
265 | writetags(fp, names, encoding.fromlocal, prevtags) | |
266 |
|
266 | |||
267 | if '.hgtags' not in self.dirstate: |
|
267 | if '.hgtags' not in self.dirstate: | |
268 | self[None].add(['.hgtags']) |
|
268 | self[None].add(['.hgtags']) | |
269 |
|
269 | |||
270 | m = matchmod.exact(self.root, '', ['.hgtags']) |
|
270 | m = matchmod.exact(self.root, '', ['.hgtags']) | |
271 | tagnode = self.commit(message, user, date, extra=extra, match=m) |
|
271 | tagnode = self.commit(message, user, date, extra=extra, match=m) | |
272 |
|
272 | |||
273 | for name in names: |
|
273 | for name in names: | |
274 | self.hook('tag', node=hex(node), tag=name, local=local) |
|
274 | self.hook('tag', node=hex(node), tag=name, local=local) | |
275 |
|
275 | |||
276 | return tagnode |
|
276 | return tagnode | |
277 |
|
277 | |||
278 | def tag(self, names, node, message, local, user, date): |
|
278 | def tag(self, names, node, message, local, user, date): | |
279 | '''tag a revision with one or more symbolic names. |
|
279 | '''tag a revision with one or more symbolic names. | |
280 |
|
280 | |||
281 | names is a list of strings or, when adding a single tag, names may be a |
|
281 | names is a list of strings or, when adding a single tag, names may be a | |
282 | string. |
|
282 | string. | |
283 |
|
283 | |||
284 | if local is True, the tags are stored in a per-repository file. |
|
284 | if local is True, the tags are stored in a per-repository file. | |
285 | otherwise, they are stored in the .hgtags file, and a new |
|
285 | otherwise, they are stored in the .hgtags file, and a new | |
286 | changeset is committed with the change. |
|
286 | changeset is committed with the change. | |
287 |
|
287 | |||
288 | keyword arguments: |
|
288 | keyword arguments: | |
289 |
|
289 | |||
290 | local: whether to store tags in non-version-controlled file |
|
290 | local: whether to store tags in non-version-controlled file | |
291 | (default False) |
|
291 | (default False) | |
292 |
|
292 | |||
293 | message: commit message to use if committing |
|
293 | message: commit message to use if committing | |
294 |
|
294 | |||
295 | user: name of user to use if committing |
|
295 | user: name of user to use if committing | |
296 |
|
296 | |||
297 | date: date tuple to use if committing''' |
|
297 | date: date tuple to use if committing''' | |
298 |
|
298 | |||
299 | for x in self.status()[:5]: |
|
299 | for x in self.status()[:5]: | |
300 | if '.hgtags' in x: |
|
300 | if '.hgtags' in x: | |
301 | raise util.Abort(_('working copy of .hgtags is changed ' |
|
301 | raise util.Abort(_('working copy of .hgtags is changed ' | |
302 | '(please commit .hgtags manually)')) |
|
302 | '(please commit .hgtags manually)')) | |
303 |
|
303 | |||
304 | self.tags() # instantiate the cache |
|
304 | self.tags() # instantiate the cache | |
305 | self._tag(names, node, message, local, user, date) |
|
305 | self._tag(names, node, message, local, user, date) | |
306 |
|
306 | |||
307 | def tags(self): |
|
307 | def tags(self): | |
308 | '''return a mapping of tag to node''' |
|
308 | '''return a mapping of tag to node''' | |
309 | if self._tags is None: |
|
309 | if self._tags is None: | |
310 | (self._tags, self._tagtypes) = self._findtags() |
|
310 | (self._tags, self._tagtypes) = self._findtags() | |
311 |
|
311 | |||
312 | return self._tags |
|
312 | return self._tags | |
313 |
|
313 | |||
314 | def _findtags(self): |
|
314 | def _findtags(self): | |
315 | '''Do the hard work of finding tags. Return a pair of dicts |
|
315 | '''Do the hard work of finding tags. Return a pair of dicts | |
316 | (tags, tagtypes) where tags maps tag name to node, and tagtypes |
|
316 | (tags, tagtypes) where tags maps tag name to node, and tagtypes | |
317 | maps tag name to a string like \'global\' or \'local\'. |
|
317 | maps tag name to a string like \'global\' or \'local\'. | |
318 | Subclasses or extensions are free to add their own tags, but |
|
318 | Subclasses or extensions are free to add their own tags, but | |
319 | should be aware that the returned dicts will be retained for the |
|
319 | should be aware that the returned dicts will be retained for the | |
320 | duration of the localrepo object.''' |
|
320 | duration of the localrepo object.''' | |
321 |
|
321 | |||
322 | # XXX what tagtype should subclasses/extensions use? Currently |
|
322 | # XXX what tagtype should subclasses/extensions use? Currently | |
323 | # mq and bookmarks add tags, but do not set the tagtype at all. |
|
323 | # mq and bookmarks add tags, but do not set the tagtype at all. | |
324 | # Should each extension invent its own tag type? Should there |
|
324 | # Should each extension invent its own tag type? Should there | |
325 | # be one tagtype for all such "virtual" tags? Or is the status |
|
325 | # be one tagtype for all such "virtual" tags? Or is the status | |
326 | # quo fine? |
|
326 | # quo fine? | |
327 |
|
327 | |||
328 | alltags = {} # map tag name to (node, hist) |
|
328 | alltags = {} # map tag name to (node, hist) | |
329 | tagtypes = {} |
|
329 | tagtypes = {} | |
330 |
|
330 | |||
331 | tagsmod.findglobaltags(self.ui, self, alltags, tagtypes) |
|
331 | tagsmod.findglobaltags(self.ui, self, alltags, tagtypes) | |
332 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) |
|
332 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) | |
333 |
|
333 | |||
334 | # Build the return dicts. Have to re-encode tag names because |
|
334 | # Build the return dicts. Have to re-encode tag names because | |
335 | # the tags module always uses UTF-8 (in order not to lose info |
|
335 | # the tags module always uses UTF-8 (in order not to lose info | |
336 | # writing to the cache), but the rest of Mercurial wants them in |
|
336 | # writing to the cache), but the rest of Mercurial wants them in | |
337 | # local encoding. |
|
337 | # local encoding. | |
338 | tags = {} |
|
338 | tags = {} | |
339 | for (name, (node, hist)) in alltags.iteritems(): |
|
339 | for (name, (node, hist)) in alltags.iteritems(): | |
340 | if node != nullid: |
|
340 | if node != nullid: | |
341 | tags[encoding.tolocal(name)] = node |
|
341 | tags[encoding.tolocal(name)] = node | |
342 | tags['tip'] = self.changelog.tip() |
|
342 | tags['tip'] = self.changelog.tip() | |
343 | tagtypes = dict([(encoding.tolocal(name), value) |
|
343 | tagtypes = dict([(encoding.tolocal(name), value) | |
344 | for (name, value) in tagtypes.iteritems()]) |
|
344 | for (name, value) in tagtypes.iteritems()]) | |
345 | return (tags, tagtypes) |
|
345 | return (tags, tagtypes) | |
346 |
|
346 | |||
347 | def tagtype(self, tagname): |
|
347 | def tagtype(self, tagname): | |
348 | ''' |
|
348 | ''' | |
349 | return the type of the given tag. result can be: |
|
349 | return the type of the given tag. result can be: | |
350 |
|
350 | |||
351 | 'local' : a local tag |
|
351 | 'local' : a local tag | |
352 | 'global' : a global tag |
|
352 | 'global' : a global tag | |
353 | None : tag does not exist |
|
353 | None : tag does not exist | |
354 | ''' |
|
354 | ''' | |
355 |
|
355 | |||
356 | self.tags() |
|
356 | self.tags() | |
357 |
|
357 | |||
358 | return self._tagtypes.get(tagname) |
|
358 | return self._tagtypes.get(tagname) | |
359 |
|
359 | |||
360 | def tagslist(self): |
|
360 | def tagslist(self): | |
361 | '''return a list of tags ordered by revision''' |
|
361 | '''return a list of tags ordered by revision''' | |
362 | l = [] |
|
362 | l = [] | |
363 | for t, n in self.tags().iteritems(): |
|
363 | for t, n in self.tags().iteritems(): | |
364 | try: |
|
364 | try: | |
365 | r = self.changelog.rev(n) |
|
365 | r = self.changelog.rev(n) | |
366 | except: |
|
366 | except: | |
367 | r = -2 # sort to the beginning of the list if unknown |
|
367 | r = -2 # sort to the beginning of the list if unknown | |
368 | l.append((r, t, n)) |
|
368 | l.append((r, t, n)) | |
369 | return [(t, n) for r, t, n in sorted(l)] |
|
369 | return [(t, n) for r, t, n in sorted(l)] | |
370 |
|
370 | |||
371 | def nodetags(self, node): |
|
371 | def nodetags(self, node): | |
372 | '''return the tags associated with a node''' |
|
372 | '''return the tags associated with a node''' | |
373 | if not self.nodetagscache: |
|
373 | if not self.nodetagscache: | |
374 | self.nodetagscache = {} |
|
374 | self.nodetagscache = {} | |
375 | for t, n in self.tags().iteritems(): |
|
375 | for t, n in self.tags().iteritems(): | |
376 | self.nodetagscache.setdefault(n, []).append(t) |
|
376 | self.nodetagscache.setdefault(n, []).append(t) | |
377 | for tags in self.nodetagscache.itervalues(): |
|
377 | for tags in self.nodetagscache.itervalues(): | |
378 | tags.sort() |
|
378 | tags.sort() | |
379 | return self.nodetagscache.get(node, []) |
|
379 | return self.nodetagscache.get(node, []) | |
380 |
|
380 | |||
381 | def _branchtags(self, partial, lrev): |
|
381 | def _branchtags(self, partial, lrev): | |
382 | # TODO: rename this function? |
|
382 | # TODO: rename this function? | |
383 | tiprev = len(self) - 1 |
|
383 | tiprev = len(self) - 1 | |
384 | if lrev != tiprev: |
|
384 | if lrev != tiprev: | |
385 | ctxgen = (self[r] for r in xrange(lrev + 1, tiprev + 1)) |
|
385 | ctxgen = (self[r] for r in xrange(lrev + 1, tiprev + 1)) | |
386 | self._updatebranchcache(partial, ctxgen) |
|
386 | self._updatebranchcache(partial, ctxgen) | |
387 | self._writebranchcache(partial, self.changelog.tip(), tiprev) |
|
387 | self._writebranchcache(partial, self.changelog.tip(), tiprev) | |
388 |
|
388 | |||
389 | return partial |
|
389 | return partial | |
390 |
|
390 | |||
391 | def updatebranchcache(self): |
|
391 | def updatebranchcache(self): | |
392 | tip = self.changelog.tip() |
|
392 | tip = self.changelog.tip() | |
393 | if self._branchcache is not None and self._branchcachetip == tip: |
|
393 | if self._branchcache is not None and self._branchcachetip == tip: | |
394 | return self._branchcache |
|
394 | return self._branchcache | |
395 |
|
395 | |||
396 | oldtip = self._branchcachetip |
|
396 | oldtip = self._branchcachetip | |
397 | self._branchcachetip = tip |
|
397 | self._branchcachetip = tip | |
398 | if oldtip is None or oldtip not in self.changelog.nodemap: |
|
398 | if oldtip is None or oldtip not in self.changelog.nodemap: | |
399 | partial, last, lrev = self._readbranchcache() |
|
399 | partial, last, lrev = self._readbranchcache() | |
400 | else: |
|
400 | else: | |
401 | lrev = self.changelog.rev(oldtip) |
|
401 | lrev = self.changelog.rev(oldtip) | |
402 | partial = self._branchcache |
|
402 | partial = self._branchcache | |
403 |
|
403 | |||
404 | self._branchtags(partial, lrev) |
|
404 | self._branchtags(partial, lrev) | |
405 | # this private cache holds all heads (not just tips) |
|
405 | # this private cache holds all heads (not just tips) | |
406 | self._branchcache = partial |
|
406 | self._branchcache = partial | |
407 |
|
407 | |||
408 | def branchmap(self): |
|
408 | def branchmap(self): | |
409 | '''returns a dictionary {branch: [branchheads]}''' |
|
409 | '''returns a dictionary {branch: [branchheads]}''' | |
410 | self.updatebranchcache() |
|
410 | self.updatebranchcache() | |
411 | return self._branchcache |
|
411 | return self._branchcache | |
412 |
|
412 | |||
413 | def branchtags(self): |
|
413 | def branchtags(self): | |
414 | '''return a dict where branch names map to the tipmost head of |
|
414 | '''return a dict where branch names map to the tipmost head of | |
415 | the branch, open heads come before closed''' |
|
415 | the branch, open heads come before closed''' | |
416 | bt = {} |
|
416 | bt = {} | |
417 | for bn, heads in self.branchmap().iteritems(): |
|
417 | for bn, heads in self.branchmap().iteritems(): | |
418 | tip = heads[-1] |
|
418 | tip = heads[-1] | |
419 | for h in reversed(heads): |
|
419 | for h in reversed(heads): | |
420 | if 'close' not in self.changelog.read(h)[5]: |
|
420 | if 'close' not in self.changelog.read(h)[5]: | |
421 | tip = h |
|
421 | tip = h | |
422 | break |
|
422 | break | |
423 | bt[bn] = tip |
|
423 | bt[bn] = tip | |
424 | return bt |
|
424 | return bt | |
425 |
|
425 | |||
426 |
|
426 | |||
427 | def _readbranchcache(self): |
|
427 | def _readbranchcache(self): | |
428 | partial = {} |
|
428 | partial = {} | |
429 | try: |
|
429 | try: | |
430 | f = self.opener("branchheads.cache") |
|
430 | f = self.opener("branchheads.cache") | |
431 | lines = f.read().split('\n') |
|
431 | lines = f.read().split('\n') | |
432 | f.close() |
|
432 | f.close() | |
433 | except (IOError, OSError): |
|
433 | except (IOError, OSError): | |
434 | return {}, nullid, nullrev |
|
434 | return {}, nullid, nullrev | |
435 |
|
435 | |||
436 | try: |
|
436 | try: | |
437 | last, lrev = lines.pop(0).split(" ", 1) |
|
437 | last, lrev = lines.pop(0).split(" ", 1) | |
438 | last, lrev = bin(last), int(lrev) |
|
438 | last, lrev = bin(last), int(lrev) | |
439 | if lrev >= len(self) or self[lrev].node() != last: |
|
439 | if lrev >= len(self) or self[lrev].node() != last: | |
440 | # invalidate the cache |
|
440 | # invalidate the cache | |
441 | raise ValueError('invalidating branch cache (tip differs)') |
|
441 | raise ValueError('invalidating branch cache (tip differs)') | |
442 | for l in lines: |
|
442 | for l in lines: | |
443 | if not l: |
|
443 | if not l: | |
444 | continue |
|
444 | continue | |
445 | node, label = l.split(" ", 1) |
|
445 | node, label = l.split(" ", 1) | |
446 | partial.setdefault(label.strip(), []).append(bin(node)) |
|
446 | partial.setdefault(label.strip(), []).append(bin(node)) | |
447 | except KeyboardInterrupt: |
|
447 | except KeyboardInterrupt: | |
448 | raise |
|
448 | raise | |
449 | except Exception, inst: |
|
449 | except Exception, inst: | |
450 | if self.ui.debugflag: |
|
450 | if self.ui.debugflag: | |
451 | self.ui.warn(str(inst), '\n') |
|
451 | self.ui.warn(str(inst), '\n') | |
452 | partial, last, lrev = {}, nullid, nullrev |
|
452 | partial, last, lrev = {}, nullid, nullrev | |
453 | return partial, last, lrev |
|
453 | return partial, last, lrev | |
454 |
|
454 | |||
455 | def _writebranchcache(self, branches, tip, tiprev): |
|
455 | def _writebranchcache(self, branches, tip, tiprev): | |
456 | try: |
|
456 | try: | |
457 | f = self.opener("branchheads.cache", "w", atomictemp=True) |
|
457 | f = self.opener("branchheads.cache", "w", atomictemp=True) | |
458 | f.write("%s %s\n" % (hex(tip), tiprev)) |
|
458 | f.write("%s %s\n" % (hex(tip), tiprev)) | |
459 | for label, nodes in branches.iteritems(): |
|
459 | for label, nodes in branches.iteritems(): | |
460 | for node in nodes: |
|
460 | for node in nodes: | |
461 | f.write("%s %s\n" % (hex(node), label)) |
|
461 | f.write("%s %s\n" % (hex(node), label)) | |
462 | f.rename() |
|
462 | f.rename() | |
463 | except (IOError, OSError): |
|
463 | except (IOError, OSError): | |
464 | pass |
|
464 | pass | |
465 |
|
465 | |||
466 | def _updatebranchcache(self, partial, ctxgen): |
|
466 | def _updatebranchcache(self, partial, ctxgen): | |
467 | # collect new branch entries |
|
467 | # collect new branch entries | |
468 | newbranches = {} |
|
468 | newbranches = {} | |
469 | for c in ctxgen: |
|
469 | for c in ctxgen: | |
470 | newbranches.setdefault(c.branch(), []).append(c.node()) |
|
470 | newbranches.setdefault(c.branch(), []).append(c.node()) | |
471 | # if older branchheads are reachable from new ones, they aren't |
|
471 | # if older branchheads are reachable from new ones, they aren't | |
472 | # really branchheads. Note checking parents is insufficient: |
|
472 | # really branchheads. Note checking parents is insufficient: | |
473 | # 1 (branch a) -> 2 (branch b) -> 3 (branch a) |
|
473 | # 1 (branch a) -> 2 (branch b) -> 3 (branch a) | |
474 | for branch, newnodes in newbranches.iteritems(): |
|
474 | for branch, newnodes in newbranches.iteritems(): | |
475 | bheads = partial.setdefault(branch, []) |
|
475 | bheads = partial.setdefault(branch, []) | |
476 | bheads.extend(newnodes) |
|
476 | bheads.extend(newnodes) | |
477 | if len(bheads) <= 1: |
|
477 | if len(bheads) <= 1: | |
478 | continue |
|
478 | continue | |
479 | # starting from tip means fewer passes over reachable |
|
479 | # starting from tip means fewer passes over reachable | |
480 | while newnodes: |
|
480 | while newnodes: | |
481 | latest = newnodes.pop() |
|
481 | latest = newnodes.pop() | |
482 | if latest not in bheads: |
|
482 | if latest not in bheads: | |
483 | continue |
|
483 | continue | |
484 | minbhrev = self[min([self[bh].rev() for bh in bheads])].node() |
|
484 | minbhrev = self[min([self[bh].rev() for bh in bheads])].node() | |
485 | reachable = self.changelog.reachable(latest, minbhrev) |
|
485 | reachable = self.changelog.reachable(latest, minbhrev) | |
486 | reachable.remove(latest) |
|
486 | reachable.remove(latest) | |
487 | bheads = [b for b in bheads if b not in reachable] |
|
487 | bheads = [b for b in bheads if b not in reachable] | |
488 | partial[branch] = bheads |
|
488 | partial[branch] = bheads | |
489 |
|
489 | |||
490 | def lookup(self, key): |
|
490 | def lookup(self, key): | |
491 | if isinstance(key, int): |
|
491 | if isinstance(key, int): | |
492 | return self.changelog.node(key) |
|
492 | return self.changelog.node(key) | |
493 | elif key == '.': |
|
493 | elif key == '.': | |
494 | return self.dirstate.parents()[0] |
|
494 | return self.dirstate.parents()[0] | |
495 | elif key == 'null': |
|
495 | elif key == 'null': | |
496 | return nullid |
|
496 | return nullid | |
497 | elif key == 'tip': |
|
497 | elif key == 'tip': | |
498 | return self.changelog.tip() |
|
498 | return self.changelog.tip() | |
499 | n = self.changelog._match(key) |
|
499 | n = self.changelog._match(key) | |
500 | if n: |
|
500 | if n: | |
501 | return n |
|
501 | return n | |
502 | if key in self.tags(): |
|
502 | if key in self.tags(): | |
503 | return self.tags()[key] |
|
503 | return self.tags()[key] | |
504 | if key in self.branchtags(): |
|
504 | if key in self.branchtags(): | |
505 | return self.branchtags()[key] |
|
505 | return self.branchtags()[key] | |
506 | n = self.changelog._partialmatch(key) |
|
506 | n = self.changelog._partialmatch(key) | |
507 | if n: |
|
507 | if n: | |
508 | return n |
|
508 | return n | |
509 |
|
509 | |||
510 | # can't find key, check if it might have come from damaged dirstate |
|
510 | # can't find key, check if it might have come from damaged dirstate | |
511 | if key in self.dirstate.parents(): |
|
511 | if key in self.dirstate.parents(): | |
512 | raise error.Abort(_("working directory has unknown parent '%s'!") |
|
512 | raise error.Abort(_("working directory has unknown parent '%s'!") | |
513 | % short(key)) |
|
513 | % short(key)) | |
514 | try: |
|
514 | try: | |
515 | if len(key) == 20: |
|
515 | if len(key) == 20: | |
516 | key = hex(key) |
|
516 | key = hex(key) | |
517 | except: |
|
517 | except: | |
518 | pass |
|
518 | pass | |
519 | raise error.RepoLookupError(_("unknown revision '%s'") % key) |
|
519 | raise error.RepoLookupError(_("unknown revision '%s'") % key) | |
520 |
|
520 | |||
521 | def lookupbranch(self, key, remote=None): |
|
521 | def lookupbranch(self, key, remote=None): | |
522 | repo = remote or self |
|
522 | repo = remote or self | |
523 | if key in repo.branchmap(): |
|
523 | if key in repo.branchmap(): | |
524 | return key |
|
524 | return key | |
525 |
|
525 | |||
526 | repo = (remote and remote.local()) and remote or self |
|
526 | repo = (remote and remote.local()) and remote or self | |
527 | return repo[key].branch() |
|
527 | return repo[key].branch() | |
528 |
|
528 | |||
529 | def local(self): |
|
529 | def local(self): | |
530 | return True |
|
530 | return True | |
531 |
|
531 | |||
532 | def join(self, f): |
|
532 | def join(self, f): | |
533 | return os.path.join(self.path, f) |
|
533 | return os.path.join(self.path, f) | |
534 |
|
534 | |||
535 | def wjoin(self, f): |
|
535 | def wjoin(self, f): | |
536 | return os.path.join(self.root, f) |
|
536 | return os.path.join(self.root, f) | |
537 |
|
537 | |||
538 | def file(self, f): |
|
538 | def file(self, f): | |
539 | if f[0] == '/': |
|
539 | if f[0] == '/': | |
540 | f = f[1:] |
|
540 | f = f[1:] | |
541 | return filelog.filelog(self.sopener, f) |
|
541 | return filelog.filelog(self.sopener, f) | |
542 |
|
542 | |||
543 | def changectx(self, changeid): |
|
543 | def changectx(self, changeid): | |
544 | return self[changeid] |
|
544 | return self[changeid] | |
545 |
|
545 | |||
546 | def parents(self, changeid=None): |
|
546 | def parents(self, changeid=None): | |
547 | '''get list of changectxs for parents of changeid''' |
|
547 | '''get list of changectxs for parents of changeid''' | |
548 | return self[changeid].parents() |
|
548 | return self[changeid].parents() | |
549 |
|
549 | |||
550 | def filectx(self, path, changeid=None, fileid=None): |
|
550 | def filectx(self, path, changeid=None, fileid=None): | |
551 | """changeid can be a changeset revision, node, or tag. |
|
551 | """changeid can be a changeset revision, node, or tag. | |
552 | fileid can be a file revision or node.""" |
|
552 | fileid can be a file revision or node.""" | |
553 | return context.filectx(self, path, changeid, fileid) |
|
553 | return context.filectx(self, path, changeid, fileid) | |
554 |
|
554 | |||
555 | def getcwd(self): |
|
555 | def getcwd(self): | |
556 | return self.dirstate.getcwd() |
|
556 | return self.dirstate.getcwd() | |
557 |
|
557 | |||
558 | def pathto(self, f, cwd=None): |
|
558 | def pathto(self, f, cwd=None): | |
559 | return self.dirstate.pathto(f, cwd) |
|
559 | return self.dirstate.pathto(f, cwd) | |
560 |
|
560 | |||
561 | def wfile(self, f, mode='r'): |
|
561 | def wfile(self, f, mode='r'): | |
562 | return self.wopener(f, mode) |
|
562 | return self.wopener(f, mode) | |
563 |
|
563 | |||
564 | def _link(self, f): |
|
564 | def _link(self, f): | |
565 | return os.path.islink(self.wjoin(f)) |
|
565 | return os.path.islink(self.wjoin(f)) | |
566 |
|
566 | |||
567 | def _loadfilter(self, filter): |
|
567 | def _loadfilter(self, filter): | |
568 | if filter not in self.filterpats: |
|
568 | if filter not in self.filterpats: | |
569 | l = [] |
|
569 | l = [] | |
570 | for pat, cmd in self.ui.configitems(filter): |
|
570 | for pat, cmd in self.ui.configitems(filter): | |
571 | if cmd == '!': |
|
571 | if cmd == '!': | |
572 | continue |
|
572 | continue | |
573 | mf = matchmod.match(self.root, '', [pat]) |
|
573 | mf = matchmod.match(self.root, '', [pat]) | |
574 | fn = None |
|
574 | fn = None | |
575 | params = cmd |
|
575 | params = cmd | |
576 | for name, filterfn in self._datafilters.iteritems(): |
|
576 | for name, filterfn in self._datafilters.iteritems(): | |
577 | if cmd.startswith(name): |
|
577 | if cmd.startswith(name): | |
578 | fn = filterfn |
|
578 | fn = filterfn | |
579 | params = cmd[len(name):].lstrip() |
|
579 | params = cmd[len(name):].lstrip() | |
580 | break |
|
580 | break | |
581 | if not fn: |
|
581 | if not fn: | |
582 | fn = lambda s, c, **kwargs: util.filter(s, c) |
|
582 | fn = lambda s, c, **kwargs: util.filter(s, c) | |
583 | # Wrap old filters not supporting keyword arguments |
|
583 | # Wrap old filters not supporting keyword arguments | |
584 | if not inspect.getargspec(fn)[2]: |
|
584 | if not inspect.getargspec(fn)[2]: | |
585 | oldfn = fn |
|
585 | oldfn = fn | |
586 | fn = lambda s, c, **kwargs: oldfn(s, c) |
|
586 | fn = lambda s, c, **kwargs: oldfn(s, c) | |
587 | l.append((mf, fn, params)) |
|
587 | l.append((mf, fn, params)) | |
588 | self.filterpats[filter] = l |
|
588 | self.filterpats[filter] = l | |
589 | return self.filterpats[filter] |
|
589 | return self.filterpats[filter] | |
590 |
|
590 | |||
591 | def _filter(self, filterpats, filename, data): |
|
591 | def _filter(self, filterpats, filename, data): | |
592 | for mf, fn, cmd in filterpats: |
|
592 | for mf, fn, cmd in filterpats: | |
593 | if mf(filename): |
|
593 | if mf(filename): | |
594 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) |
|
594 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) | |
595 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) |
|
595 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) | |
596 | break |
|
596 | break | |
597 |
|
597 | |||
598 | return data |
|
598 | return data | |
599 |
|
599 | |||
600 | @propertycache |
|
600 | @propertycache | |
601 | def _encodefilterpats(self): |
|
601 | def _encodefilterpats(self): | |
602 | return self._loadfilter('encode') |
|
602 | return self._loadfilter('encode') | |
603 |
|
603 | |||
604 | @propertycache |
|
604 | @propertycache | |
605 | def _decodefilterpats(self): |
|
605 | def _decodefilterpats(self): | |
606 | return self._loadfilter('decode') |
|
606 | return self._loadfilter('decode') | |
607 |
|
607 | |||
608 | def adddatafilter(self, name, filter): |
|
608 | def adddatafilter(self, name, filter): | |
609 | self._datafilters[name] = filter |
|
609 | self._datafilters[name] = filter | |
610 |
|
610 | |||
611 | def wread(self, filename): |
|
611 | def wread(self, filename): | |
612 | if self._link(filename): |
|
612 | if self._link(filename): | |
613 | data = os.readlink(self.wjoin(filename)) |
|
613 | data = os.readlink(self.wjoin(filename)) | |
614 | else: |
|
614 | else: | |
615 | data = self.wopener(filename, 'r').read() |
|
615 | data = self.wopener(filename, 'r').read() | |
616 | return self._filter(self._encodefilterpats, filename, data) |
|
616 | return self._filter(self._encodefilterpats, filename, data) | |
617 |
|
617 | |||
618 | def wwrite(self, filename, data, flags): |
|
618 | def wwrite(self, filename, data, flags): | |
619 | data = self._filter(self._decodefilterpats, filename, data) |
|
619 | data = self._filter(self._decodefilterpats, filename, data) | |
620 | try: |
|
620 | try: | |
621 | os.unlink(self.wjoin(filename)) |
|
621 | os.unlink(self.wjoin(filename)) | |
622 | except OSError: |
|
622 | except OSError: | |
623 | pass |
|
623 | pass | |
624 | if 'l' in flags: |
|
624 | if 'l' in flags: | |
625 | self.wopener.symlink(data, filename) |
|
625 | self.wopener.symlink(data, filename) | |
626 | else: |
|
626 | else: | |
627 | self.wopener(filename, 'w').write(data) |
|
627 | self.wopener(filename, 'w').write(data) | |
628 | if 'x' in flags: |
|
628 | if 'x' in flags: | |
629 | util.set_flags(self.wjoin(filename), False, True) |
|
629 | util.set_flags(self.wjoin(filename), False, True) | |
630 |
|
630 | |||
631 | def wwritedata(self, filename, data): |
|
631 | def wwritedata(self, filename, data): | |
632 | return self._filter(self._decodefilterpats, filename, data) |
|
632 | return self._filter(self._decodefilterpats, filename, data) | |
633 |
|
633 | |||
634 | def transaction(self, desc): |
|
634 | def transaction(self, desc): | |
635 | tr = self._transref and self._transref() or None |
|
635 | tr = self._transref and self._transref() or None | |
636 | if tr and tr.running(): |
|
636 | if tr and tr.running(): | |
637 | return tr.nest() |
|
637 | return tr.nest() | |
638 |
|
638 | |||
639 | # abort here if the journal already exists |
|
639 | # abort here if the journal already exists | |
640 | if os.path.exists(self.sjoin("journal")): |
|
640 | if os.path.exists(self.sjoin("journal")): | |
641 | raise error.RepoError( |
|
641 | raise error.RepoError( | |
642 | _("abandoned transaction found - run hg recover")) |
|
642 | _("abandoned transaction found - run hg recover")) | |
643 |
|
643 | |||
644 | # save dirstate for rollback |
|
644 | # save dirstate for rollback | |
645 | try: |
|
645 | try: | |
646 | ds = self.opener("dirstate").read() |
|
646 | ds = self.opener("dirstate").read() | |
647 | except IOError: |
|
647 | except IOError: | |
648 | ds = "" |
|
648 | ds = "" | |
649 | self.opener("journal.dirstate", "w").write(ds) |
|
649 | self.opener("journal.dirstate", "w").write(ds) | |
650 | self.opener("journal.branch", "w").write(self.dirstate.branch()) |
|
650 | self.opener("journal.branch", "w").write(self.dirstate.branch()) | |
651 | self.opener("journal.desc", "w").write("%d\n%s\n" % (len(self), desc)) |
|
651 | self.opener("journal.desc", "w").write("%d\n%s\n" % (len(self), desc)) | |
652 |
|
652 | |||
653 | renames = [(self.sjoin("journal"), self.sjoin("undo")), |
|
653 | renames = [(self.sjoin("journal"), self.sjoin("undo")), | |
654 | (self.join("journal.dirstate"), self.join("undo.dirstate")), |
|
654 | (self.join("journal.dirstate"), self.join("undo.dirstate")), | |
655 | (self.join("journal.branch"), self.join("undo.branch")), |
|
655 | (self.join("journal.branch"), self.join("undo.branch")), | |
656 | (self.join("journal.desc"), self.join("undo.desc"))] |
|
656 | (self.join("journal.desc"), self.join("undo.desc"))] | |
657 | tr = transaction.transaction(self.ui.warn, self.sopener, |
|
657 | tr = transaction.transaction(self.ui.warn, self.sopener, | |
658 | self.sjoin("journal"), |
|
658 | self.sjoin("journal"), | |
659 | aftertrans(renames), |
|
659 | aftertrans(renames), | |
660 | self.store.createmode) |
|
660 | self.store.createmode) | |
661 | self._transref = weakref.ref(tr) |
|
661 | self._transref = weakref.ref(tr) | |
662 | return tr |
|
662 | return tr | |
663 |
|
663 | |||
664 | def recover(self): |
|
664 | def recover(self): | |
665 | lock = self.lock() |
|
665 | lock = self.lock() | |
666 | try: |
|
666 | try: | |
667 | if os.path.exists(self.sjoin("journal")): |
|
667 | if os.path.exists(self.sjoin("journal")): | |
668 | self.ui.status(_("rolling back interrupted transaction\n")) |
|
668 | self.ui.status(_("rolling back interrupted transaction\n")) | |
669 | transaction.rollback(self.sopener, self.sjoin("journal"), |
|
669 | transaction.rollback(self.sopener, self.sjoin("journal"), | |
670 | self.ui.warn) |
|
670 | self.ui.warn) | |
671 | self.invalidate() |
|
671 | self.invalidate() | |
672 | return True |
|
672 | return True | |
673 | else: |
|
673 | else: | |
674 | self.ui.warn(_("no interrupted transaction available\n")) |
|
674 | self.ui.warn(_("no interrupted transaction available\n")) | |
675 | return False |
|
675 | return False | |
676 | finally: |
|
676 | finally: | |
677 | lock.release() |
|
677 | lock.release() | |
678 |
|
678 | |||
679 | def rollback(self, dryrun=False): |
|
679 | def rollback(self, dryrun=False): | |
680 | wlock = lock = None |
|
680 | wlock = lock = None | |
681 | try: |
|
681 | try: | |
682 | wlock = self.wlock() |
|
682 | wlock = self.wlock() | |
683 | lock = self.lock() |
|
683 | lock = self.lock() | |
684 | if os.path.exists(self.sjoin("undo")): |
|
684 | if os.path.exists(self.sjoin("undo")): | |
685 | try: |
|
685 | try: | |
686 | args = self.opener("undo.desc", "r").read().splitlines() |
|
686 | args = self.opener("undo.desc", "r").read().splitlines() | |
687 | if len(args) >= 3 and self.ui.verbose: |
|
687 | if len(args) >= 3 and self.ui.verbose: | |
688 | desc = _("rolling back to revision %s" |
|
688 | desc = _("rolling back to revision %s" | |
689 | " (undo %s: %s)\n") % ( |
|
689 | " (undo %s: %s)\n") % ( | |
690 | int(args[0]) - 1, args[1], args[2]) |
|
690 | int(args[0]) - 1, args[1], args[2]) | |
691 | elif len(args) >= 2: |
|
691 | elif len(args) >= 2: | |
692 | desc = _("rolling back to revision %s (undo %s)\n") % ( |
|
692 | desc = _("rolling back to revision %s (undo %s)\n") % ( | |
693 | int(args[0]) - 1, args[1]) |
|
693 | int(args[0]) - 1, args[1]) | |
694 | except IOError: |
|
694 | except IOError: | |
695 | desc = _("rolling back unknown transaction\n") |
|
695 | desc = _("rolling back unknown transaction\n") | |
696 | self.ui.status(desc) |
|
696 | self.ui.status(desc) | |
697 | if dryrun: |
|
697 | if dryrun: | |
698 | return |
|
698 | return | |
699 | transaction.rollback(self.sopener, self.sjoin("undo"), |
|
699 | transaction.rollback(self.sopener, self.sjoin("undo"), | |
700 | self.ui.warn) |
|
700 | self.ui.warn) | |
701 | util.rename(self.join("undo.dirstate"), self.join("dirstate")) |
|
701 | util.rename(self.join("undo.dirstate"), self.join("dirstate")) | |
702 | try: |
|
702 | try: | |
703 | branch = self.opener("undo.branch").read() |
|
703 | branch = self.opener("undo.branch").read() | |
704 | self.dirstate.setbranch(branch) |
|
704 | self.dirstate.setbranch(branch) | |
705 | except IOError: |
|
705 | except IOError: | |
706 | self.ui.warn(_("Named branch could not be reset, " |
|
706 | self.ui.warn(_("Named branch could not be reset, " | |
707 | "current branch still is: %s\n") |
|
707 | "current branch still is: %s\n") | |
708 | % encoding.tolocal(self.dirstate.branch())) |
|
708 | % encoding.tolocal(self.dirstate.branch())) | |
709 | self.invalidate() |
|
709 | self.invalidate() | |
710 | self.dirstate.invalidate() |
|
710 | self.dirstate.invalidate() | |
711 | self.destroyed() |
|
711 | self.destroyed() | |
712 | else: |
|
712 | else: | |
713 | self.ui.warn(_("no rollback information available\n")) |
|
713 | self.ui.warn(_("no rollback information available\n")) | |
714 | return 1 |
|
714 | return 1 | |
715 | finally: |
|
715 | finally: | |
716 | release(lock, wlock) |
|
716 | release(lock, wlock) | |
717 |
|
717 | |||
718 | def invalidatecaches(self): |
|
718 | def invalidatecaches(self): | |
719 | self._tags = None |
|
719 | self._tags = None | |
720 | self._tagtypes = None |
|
720 | self._tagtypes = None | |
721 | self.nodetagscache = None |
|
721 | self.nodetagscache = None | |
722 | self._branchcache = None # in UTF-8 |
|
722 | self._branchcache = None # in UTF-8 | |
723 | self._branchcachetip = None |
|
723 | self._branchcachetip = None | |
724 |
|
724 | |||
725 | def invalidate(self): |
|
725 | def invalidate(self): | |
726 | for a in "changelog manifest".split(): |
|
726 | for a in "changelog manifest".split(): | |
727 | if a in self.__dict__: |
|
727 | if a in self.__dict__: | |
728 | delattr(self, a) |
|
728 | delattr(self, a) | |
729 | self.invalidatecaches() |
|
729 | self.invalidatecaches() | |
730 |
|
730 | |||
731 | def _lock(self, lockname, wait, releasefn, acquirefn, desc): |
|
731 | def _lock(self, lockname, wait, releasefn, acquirefn, desc): | |
732 | try: |
|
732 | try: | |
733 | l = lock.lock(lockname, 0, releasefn, desc=desc) |
|
733 | l = lock.lock(lockname, 0, releasefn, desc=desc) | |
734 | except error.LockHeld, inst: |
|
734 | except error.LockHeld, inst: | |
735 | if not wait: |
|
735 | if not wait: | |
736 | raise |
|
736 | raise | |
737 | self.ui.warn(_("waiting for lock on %s held by %r\n") % |
|
737 | self.ui.warn(_("waiting for lock on %s held by %r\n") % | |
738 | (desc, inst.locker)) |
|
738 | (desc, inst.locker)) | |
739 | # default to 600 seconds timeout |
|
739 | # default to 600 seconds timeout | |
740 | l = lock.lock(lockname, int(self.ui.config("ui", "timeout", "600")), |
|
740 | l = lock.lock(lockname, int(self.ui.config("ui", "timeout", "600")), | |
741 | releasefn, desc=desc) |
|
741 | releasefn, desc=desc) | |
742 | if acquirefn: |
|
742 | if acquirefn: | |
743 | acquirefn() |
|
743 | acquirefn() | |
744 | return l |
|
744 | return l | |
745 |
|
745 | |||
746 | def lock(self, wait=True): |
|
746 | def lock(self, wait=True): | |
747 | '''Lock the repository store (.hg/store) and return a weak reference |
|
747 | '''Lock the repository store (.hg/store) and return a weak reference | |
748 | to the lock. Use this before modifying the store (e.g. committing or |
|
748 | to the lock. Use this before modifying the store (e.g. committing or | |
749 | stripping). If you are opening a transaction, get a lock as well.)''' |
|
749 | stripping). If you are opening a transaction, get a lock as well.)''' | |
750 | l = self._lockref and self._lockref() |
|
750 | l = self._lockref and self._lockref() | |
751 | if l is not None and l.held: |
|
751 | if l is not None and l.held: | |
752 | l.lock() |
|
752 | l.lock() | |
753 | return l |
|
753 | return l | |
754 |
|
754 | |||
755 | l = self._lock(self.sjoin("lock"), wait, None, self.invalidate, |
|
755 | l = self._lock(self.sjoin("lock"), wait, None, self.invalidate, | |
756 | _('repository %s') % self.origroot) |
|
756 | _('repository %s') % self.origroot) | |
757 | self._lockref = weakref.ref(l) |
|
757 | self._lockref = weakref.ref(l) | |
758 | return l |
|
758 | return l | |
759 |
|
759 | |||
760 | def wlock(self, wait=True): |
|
760 | def wlock(self, wait=True): | |
761 | '''Lock the non-store parts of the repository (everything under |
|
761 | '''Lock the non-store parts of the repository (everything under | |
762 | .hg except .hg/store) and return a weak reference to the lock. |
|
762 | .hg except .hg/store) and return a weak reference to the lock. | |
763 | Use this before modifying files in .hg.''' |
|
763 | Use this before modifying files in .hg.''' | |
764 | l = self._wlockref and self._wlockref() |
|
764 | l = self._wlockref and self._wlockref() | |
765 | if l is not None and l.held: |
|
765 | if l is not None and l.held: | |
766 | l.lock() |
|
766 | l.lock() | |
767 | return l |
|
767 | return l | |
768 |
|
768 | |||
769 | l = self._lock(self.join("wlock"), wait, self.dirstate.write, |
|
769 | l = self._lock(self.join("wlock"), wait, self.dirstate.write, | |
770 | self.dirstate.invalidate, _('working directory of %s') % |
|
770 | self.dirstate.invalidate, _('working directory of %s') % | |
771 | self.origroot) |
|
771 | self.origroot) | |
772 | self._wlockref = weakref.ref(l) |
|
772 | self._wlockref = weakref.ref(l) | |
773 | return l |
|
773 | return l | |
774 |
|
774 | |||
775 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): |
|
775 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): | |
776 | """ |
|
776 | """ | |
777 | commit an individual file as part of a larger transaction |
|
777 | commit an individual file as part of a larger transaction | |
778 | """ |
|
778 | """ | |
779 |
|
779 | |||
780 | fname = fctx.path() |
|
780 | fname = fctx.path() | |
781 | text = fctx.data() |
|
781 | text = fctx.data() | |
782 | flog = self.file(fname) |
|
782 | flog = self.file(fname) | |
783 | fparent1 = manifest1.get(fname, nullid) |
|
783 | fparent1 = manifest1.get(fname, nullid) | |
784 | fparent2 = fparent2o = manifest2.get(fname, nullid) |
|
784 | fparent2 = fparent2o = manifest2.get(fname, nullid) | |
785 |
|
785 | |||
786 | meta = {} |
|
786 | meta = {} | |
787 | copy = fctx.renamed() |
|
787 | copy = fctx.renamed() | |
788 | if copy and copy[0] != fname: |
|
788 | if copy and copy[0] != fname: | |
789 | # Mark the new revision of this file as a copy of another |
|
789 | # Mark the new revision of this file as a copy of another | |
790 | # file. This copy data will effectively act as a parent |
|
790 | # file. This copy data will effectively act as a parent | |
791 | # of this new revision. If this is a merge, the first |
|
791 | # of this new revision. If this is a merge, the first | |
792 | # parent will be the nullid (meaning "look up the copy data") |
|
792 | # parent will be the nullid (meaning "look up the copy data") | |
793 | # and the second one will be the other parent. For example: |
|
793 | # and the second one will be the other parent. For example: | |
794 | # |
|
794 | # | |
795 | # 0 --- 1 --- 3 rev1 changes file foo |
|
795 | # 0 --- 1 --- 3 rev1 changes file foo | |
796 | # \ / rev2 renames foo to bar and changes it |
|
796 | # \ / rev2 renames foo to bar and changes it | |
797 | # \- 2 -/ rev3 should have bar with all changes and |
|
797 | # \- 2 -/ rev3 should have bar with all changes and | |
798 | # should record that bar descends from |
|
798 | # should record that bar descends from | |
799 | # bar in rev2 and foo in rev1 |
|
799 | # bar in rev2 and foo in rev1 | |
800 | # |
|
800 | # | |
801 | # this allows this merge to succeed: |
|
801 | # this allows this merge to succeed: | |
802 | # |
|
802 | # | |
803 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 |
|
803 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 | |
804 | # \ / merging rev3 and rev4 should use bar@rev2 |
|
804 | # \ / merging rev3 and rev4 should use bar@rev2 | |
805 | # \- 2 --- 4 as the merge base |
|
805 | # \- 2 --- 4 as the merge base | |
806 | # |
|
806 | # | |
807 |
|
807 | |||
808 | cfname = copy[0] |
|
808 | cfname = copy[0] | |
809 | crev = manifest1.get(cfname) |
|
809 | crev = manifest1.get(cfname) | |
810 | newfparent = fparent2 |
|
810 | newfparent = fparent2 | |
811 |
|
811 | |||
812 | if manifest2: # branch merge |
|
812 | if manifest2: # branch merge | |
813 | if fparent2 == nullid or crev is None: # copied on remote side |
|
813 | if fparent2 == nullid or crev is None: # copied on remote side | |
814 | if cfname in manifest2: |
|
814 | if cfname in manifest2: | |
815 | crev = manifest2[cfname] |
|
815 | crev = manifest2[cfname] | |
816 | newfparent = fparent1 |
|
816 | newfparent = fparent1 | |
817 |
|
817 | |||
818 | # find source in nearest ancestor if we've lost track |
|
818 | # find source in nearest ancestor if we've lost track | |
819 | if not crev: |
|
819 | if not crev: | |
820 | self.ui.debug(" %s: searching for copy revision for %s\n" % |
|
820 | self.ui.debug(" %s: searching for copy revision for %s\n" % | |
821 | (fname, cfname)) |
|
821 | (fname, cfname)) | |
822 | for ancestor in self['.'].ancestors(): |
|
822 | for ancestor in self['.'].ancestors(): | |
823 | if cfname in ancestor: |
|
823 | if cfname in ancestor: | |
824 | crev = ancestor[cfname].filenode() |
|
824 | crev = ancestor[cfname].filenode() | |
825 | break |
|
825 | break | |
826 |
|
826 | |||
827 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) |
|
827 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) | |
828 | meta["copy"] = cfname |
|
828 | meta["copy"] = cfname | |
829 | meta["copyrev"] = hex(crev) |
|
829 | meta["copyrev"] = hex(crev) | |
830 | fparent1, fparent2 = nullid, newfparent |
|
830 | fparent1, fparent2 = nullid, newfparent | |
831 | elif fparent2 != nullid: |
|
831 | elif fparent2 != nullid: | |
832 | # is one parent an ancestor of the other? |
|
832 | # is one parent an ancestor of the other? | |
833 | fparentancestor = flog.ancestor(fparent1, fparent2) |
|
833 | fparentancestor = flog.ancestor(fparent1, fparent2) | |
834 | if fparentancestor == fparent1: |
|
834 | if fparentancestor == fparent1: | |
835 | fparent1, fparent2 = fparent2, nullid |
|
835 | fparent1, fparent2 = fparent2, nullid | |
836 | elif fparentancestor == fparent2: |
|
836 | elif fparentancestor == fparent2: | |
837 | fparent2 = nullid |
|
837 | fparent2 = nullid | |
838 |
|
838 | |||
839 | # is the file changed? |
|
839 | # is the file changed? | |
840 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: |
|
840 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: | |
841 | changelist.append(fname) |
|
841 | changelist.append(fname) | |
842 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) |
|
842 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) | |
843 |
|
843 | |||
844 | # are just the flags changed during merge? |
|
844 | # are just the flags changed during merge? | |
845 | if fparent1 != fparent2o and manifest1.flags(fname) != fctx.flags(): |
|
845 | if fparent1 != fparent2o and manifest1.flags(fname) != fctx.flags(): | |
846 | changelist.append(fname) |
|
846 | changelist.append(fname) | |
847 |
|
847 | |||
848 | return fparent1 |
|
848 | return fparent1 | |
849 |
|
849 | |||
850 | def commit(self, text="", user=None, date=None, match=None, force=False, |
|
850 | def commit(self, text="", user=None, date=None, match=None, force=False, | |
851 | editor=False, extra={}): |
|
851 | editor=False, extra={}): | |
852 | """Add a new revision to current repository. |
|
852 | """Add a new revision to current repository. | |
853 |
|
853 | |||
854 | Revision information is gathered from the working directory, |
|
854 | Revision information is gathered from the working directory, | |
855 | match can be used to filter the committed files. If editor is |
|
855 | match can be used to filter the committed files. If editor is | |
856 | supplied, it is called to get a commit message. |
|
856 | supplied, it is called to get a commit message. | |
857 | """ |
|
857 | """ | |
858 |
|
858 | |||
859 | def fail(f, msg): |
|
859 | def fail(f, msg): | |
860 | raise util.Abort('%s: %s' % (f, msg)) |
|
860 | raise util.Abort('%s: %s' % (f, msg)) | |
861 |
|
861 | |||
862 | if not match: |
|
862 | if not match: | |
863 | match = matchmod.always(self.root, '') |
|
863 | match = matchmod.always(self.root, '') | |
864 |
|
864 | |||
865 | if not force: |
|
865 | if not force: | |
866 | vdirs = [] |
|
866 | vdirs = [] | |
867 | match.dir = vdirs.append |
|
867 | match.dir = vdirs.append | |
868 | match.bad = fail |
|
868 | match.bad = fail | |
869 |
|
869 | |||
870 | wlock = self.wlock() |
|
870 | wlock = self.wlock() | |
871 | try: |
|
871 | try: | |
872 | wctx = self[None] |
|
872 | wctx = self[None] | |
873 | merge = len(wctx.parents()) > 1 |
|
873 | merge = len(wctx.parents()) > 1 | |
874 |
|
874 | |||
875 | if (not force and merge and match and |
|
875 | if (not force and merge and match and | |
876 | (match.files() or match.anypats())): |
|
876 | (match.files() or match.anypats())): | |
877 | raise util.Abort(_('cannot partially commit a merge ' |
|
877 | raise util.Abort(_('cannot partially commit a merge ' | |
878 | '(do not specify files or patterns)')) |
|
878 | '(do not specify files or patterns)')) | |
879 |
|
879 | |||
880 | changes = self.status(match=match, clean=force) |
|
880 | changes = self.status(match=match, clean=force) | |
881 | if force: |
|
881 | if force: | |
882 | changes[0].extend(changes[6]) # mq may commit unchanged files |
|
882 | changes[0].extend(changes[6]) # mq may commit unchanged files | |
883 |
|
883 | |||
884 | # check subrepos |
|
884 | # check subrepos | |
885 | subs = [] |
|
885 | subs = [] | |
886 | removedsubs = set() |
|
886 | removedsubs = set() | |
887 | for p in wctx.parents(): |
|
887 | for p in wctx.parents(): | |
888 | removedsubs.update(s for s in p.substate if match(s)) |
|
888 | removedsubs.update(s for s in p.substate if match(s)) | |
889 | for s in wctx.substate: |
|
889 | for s in wctx.substate: | |
890 | removedsubs.discard(s) |
|
890 | removedsubs.discard(s) | |
891 | if match(s) and wctx.sub(s).dirty(): |
|
891 | if match(s) and wctx.sub(s).dirty(): | |
892 | subs.append(s) |
|
892 | subs.append(s) | |
893 | if (subs or removedsubs): |
|
893 | if (subs or removedsubs): | |
894 | if (not match('.hgsub') and |
|
894 | if (not match('.hgsub') and | |
895 | '.hgsub' in (wctx.modified() + wctx.added())): |
|
895 | '.hgsub' in (wctx.modified() + wctx.added())): | |
896 | raise util.Abort(_("can't commit subrepos without .hgsub")) |
|
896 | raise util.Abort(_("can't commit subrepos without .hgsub")) | |
897 | if '.hgsubstate' not in changes[0]: |
|
897 | if '.hgsubstate' not in changes[0]: | |
898 | changes[0].insert(0, '.hgsubstate') |
|
898 | changes[0].insert(0, '.hgsubstate') | |
899 |
|
899 | |||
900 | # make sure all explicit patterns are matched |
|
900 | # make sure all explicit patterns are matched | |
901 | if not force and match.files(): |
|
901 | if not force and match.files(): | |
902 | matched = set(changes[0] + changes[1] + changes[2]) |
|
902 | matched = set(changes[0] + changes[1] + changes[2]) | |
903 |
|
903 | |||
904 | for f in match.files(): |
|
904 | for f in match.files(): | |
905 | if f == '.' or f in matched or f in wctx.substate: |
|
905 | if f == '.' or f in matched or f in wctx.substate: | |
906 | continue |
|
906 | continue | |
907 | if f in changes[3]: # missing |
|
907 | if f in changes[3]: # missing | |
908 | fail(f, _('file not found!')) |
|
908 | fail(f, _('file not found!')) | |
909 | if f in vdirs: # visited directory |
|
909 | if f in vdirs: # visited directory | |
910 | d = f + '/' |
|
910 | d = f + '/' | |
911 | for mf in matched: |
|
911 | for mf in matched: | |
912 | if mf.startswith(d): |
|
912 | if mf.startswith(d): | |
913 | break |
|
913 | break | |
914 | else: |
|
914 | else: | |
915 | fail(f, _("no match under directory!")) |
|
915 | fail(f, _("no match under directory!")) | |
916 | elif f not in self.dirstate: |
|
916 | elif f not in self.dirstate: | |
917 | fail(f, _("file not tracked!")) |
|
917 | fail(f, _("file not tracked!")) | |
918 |
|
918 | |||
919 | if (not force and not extra.get("close") and not merge |
|
919 | if (not force and not extra.get("close") and not merge | |
920 | and not (changes[0] or changes[1] or changes[2]) |
|
920 | and not (changes[0] or changes[1] or changes[2]) | |
921 | and wctx.branch() == wctx.p1().branch()): |
|
921 | and wctx.branch() == wctx.p1().branch()): | |
922 | return None |
|
922 | return None | |
923 |
|
923 | |||
924 | ms = mergemod.mergestate(self) |
|
924 | ms = mergemod.mergestate(self) | |
925 | for f in changes[0]: |
|
925 | for f in changes[0]: | |
926 | if f in ms and ms[f] == 'u': |
|
926 | if f in ms and ms[f] == 'u': | |
927 | raise util.Abort(_("unresolved merge conflicts " |
|
927 | raise util.Abort(_("unresolved merge conflicts " | |
928 | "(see hg resolve)")) |
|
928 | "(see hg resolve)")) | |
929 |
|
929 | |||
930 | cctx = context.workingctx(self, text, user, date, extra, changes) |
|
930 | cctx = context.workingctx(self, text, user, date, extra, changes) | |
931 | if editor: |
|
931 | if editor: | |
932 | cctx._text = editor(self, cctx, subs) |
|
932 | cctx._text = editor(self, cctx, subs) | |
933 | edited = (text != cctx._text) |
|
933 | edited = (text != cctx._text) | |
934 |
|
934 | |||
935 | # commit subs |
|
935 | # commit subs | |
936 | if subs or removedsubs: |
|
936 | if subs or removedsubs: | |
937 | state = wctx.substate.copy() |
|
937 | state = wctx.substate.copy() | |
938 | for s in sorted(subs): |
|
938 | for s in sorted(subs): | |
939 | sub = wctx.sub(s) |
|
939 | sub = wctx.sub(s) | |
940 | self.ui.status(_('committing subrepository %s\n') % |
|
940 | self.ui.status(_('committing subrepository %s\n') % | |
941 | subrepo.subrelpath(sub)) |
|
941 | subrepo.subrelpath(sub)) | |
942 | sr = sub.commit(cctx._text, user, date) |
|
942 | sr = sub.commit(cctx._text, user, date) | |
943 | state[s] = (state[s][0], sr) |
|
943 | state[s] = (state[s][0], sr) | |
944 | subrepo.writestate(self, state) |
|
944 | subrepo.writestate(self, state) | |
945 |
|
945 | |||
946 | # Save commit message in case this transaction gets rolled back |
|
946 | # Save commit message in case this transaction gets rolled back | |
947 | # (e.g. by a pretxncommit hook). Leave the content alone on |
|
947 | # (e.g. by a pretxncommit hook). Leave the content alone on | |
948 | # the assumption that the user will use the same editor again. |
|
948 | # the assumption that the user will use the same editor again. | |
949 | msgfile = self.opener('last-message.txt', 'wb') |
|
949 | msgfile = self.opener('last-message.txt', 'wb') | |
950 | msgfile.write(cctx._text) |
|
950 | msgfile.write(cctx._text) | |
951 | msgfile.close() |
|
951 | msgfile.close() | |
952 |
|
952 | |||
953 | p1, p2 = self.dirstate.parents() |
|
953 | p1, p2 = self.dirstate.parents() | |
954 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') |
|
954 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') | |
955 | try: |
|
955 | try: | |
956 | self.hook("precommit", throw=True, parent1=hookp1, parent2=hookp2) |
|
956 | self.hook("precommit", throw=True, parent1=hookp1, parent2=hookp2) | |
957 | ret = self.commitctx(cctx, True) |
|
957 | ret = self.commitctx(cctx, True) | |
958 | except: |
|
958 | except: | |
959 | if edited: |
|
959 | if edited: | |
960 | msgfn = self.pathto(msgfile.name[len(self.root)+1:]) |
|
960 | msgfn = self.pathto(msgfile.name[len(self.root)+1:]) | |
961 | self.ui.write( |
|
961 | self.ui.write( | |
962 | _('note: commit message saved in %s\n') % msgfn) |
|
962 | _('note: commit message saved in %s\n') % msgfn) | |
963 | raise |
|
963 | raise | |
964 |
|
964 | |||
965 | # update dirstate and mergestate |
|
965 | # update dirstate and mergestate | |
966 | for f in changes[0] + changes[1]: |
|
966 | for f in changes[0] + changes[1]: | |
967 | self.dirstate.normal(f) |
|
967 | self.dirstate.normal(f) | |
968 | for f in changes[2]: |
|
968 | for f in changes[2]: | |
969 | self.dirstate.forget(f) |
|
969 | self.dirstate.forget(f) | |
970 | self.dirstate.setparents(ret) |
|
970 | self.dirstate.setparents(ret) | |
971 | ms.reset() |
|
971 | ms.reset() | |
972 | finally: |
|
972 | finally: | |
973 | wlock.release() |
|
973 | wlock.release() | |
974 |
|
974 | |||
975 | self.hook("commit", node=hex(ret), parent1=hookp1, parent2=hookp2) |
|
975 | self.hook("commit", node=hex(ret), parent1=hookp1, parent2=hookp2) | |
976 | return ret |
|
976 | return ret | |
977 |
|
977 | |||
978 | def commitctx(self, ctx, error=False): |
|
978 | def commitctx(self, ctx, error=False): | |
979 | """Add a new revision to current repository. |
|
979 | """Add a new revision to current repository. | |
980 | Revision information is passed via the context argument. |
|
980 | Revision information is passed via the context argument. | |
981 | """ |
|
981 | """ | |
982 |
|
982 | |||
983 | tr = lock = None |
|
983 | tr = lock = None | |
984 | removed = ctx.removed() |
|
984 | removed = list(ctx.removed()) | |
985 | p1, p2 = ctx.p1(), ctx.p2() |
|
985 | p1, p2 = ctx.p1(), ctx.p2() | |
986 | m1 = p1.manifest().copy() |
|
986 | m1 = p1.manifest().copy() | |
987 | m2 = p2.manifest() |
|
987 | m2 = p2.manifest() | |
988 | user = ctx.user() |
|
988 | user = ctx.user() | |
989 |
|
989 | |||
990 | lock = self.lock() |
|
990 | lock = self.lock() | |
991 | try: |
|
991 | try: | |
992 | tr = self.transaction("commit") |
|
992 | tr = self.transaction("commit") | |
993 | trp = weakref.proxy(tr) |
|
993 | trp = weakref.proxy(tr) | |
994 |
|
994 | |||
995 | # check in files |
|
995 | # check in files | |
996 | new = {} |
|
996 | new = {} | |
997 | changed = [] |
|
997 | changed = [] | |
998 | linkrev = len(self) |
|
998 | linkrev = len(self) | |
999 | for f in sorted(ctx.modified() + ctx.added()): |
|
999 | for f in sorted(ctx.modified() + ctx.added()): | |
1000 | self.ui.note(f + "\n") |
|
1000 | self.ui.note(f + "\n") | |
1001 | try: |
|
1001 | try: | |
1002 | fctx = ctx[f] |
|
1002 | fctx = ctx[f] | |
1003 | new[f] = self._filecommit(fctx, m1, m2, linkrev, trp, |
|
1003 | new[f] = self._filecommit(fctx, m1, m2, linkrev, trp, | |
1004 | changed) |
|
1004 | changed) | |
1005 | m1.set(f, fctx.flags()) |
|
1005 | m1.set(f, fctx.flags()) | |
1006 | except OSError, inst: |
|
1006 | except OSError, inst: | |
1007 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
1007 | self.ui.warn(_("trouble committing %s!\n") % f) | |
1008 | raise |
|
1008 | raise | |
1009 | except IOError, inst: |
|
1009 | except IOError, inst: | |
1010 | errcode = getattr(inst, 'errno', errno.ENOENT) |
|
1010 | errcode = getattr(inst, 'errno', errno.ENOENT) | |
1011 | if error or errcode and errcode != errno.ENOENT: |
|
1011 | if error or errcode and errcode != errno.ENOENT: | |
1012 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
1012 | self.ui.warn(_("trouble committing %s!\n") % f) | |
1013 | raise |
|
1013 | raise | |
1014 | else: |
|
1014 | else: | |
1015 | removed.append(f) |
|
1015 | removed.append(f) | |
1016 |
|
1016 | |||
1017 | # update manifest |
|
1017 | # update manifest | |
1018 | m1.update(new) |
|
1018 | m1.update(new) | |
1019 | removed = [f for f in sorted(removed) if f in m1 or f in m2] |
|
1019 | removed = [f for f in sorted(removed) if f in m1 or f in m2] | |
1020 | drop = [f for f in removed if f in m1] |
|
1020 | drop = [f for f in removed if f in m1] | |
1021 | for f in drop: |
|
1021 | for f in drop: | |
1022 | del m1[f] |
|
1022 | del m1[f] | |
1023 | mn = self.manifest.add(m1, trp, linkrev, p1.manifestnode(), |
|
1023 | mn = self.manifest.add(m1, trp, linkrev, p1.manifestnode(), | |
1024 | p2.manifestnode(), (new, drop)) |
|
1024 | p2.manifestnode(), (new, drop)) | |
1025 |
|
1025 | |||
1026 | # update changelog |
|
1026 | # update changelog | |
1027 | self.changelog.delayupdate() |
|
1027 | self.changelog.delayupdate() | |
1028 | n = self.changelog.add(mn, changed + removed, ctx.description(), |
|
1028 | n = self.changelog.add(mn, changed + removed, ctx.description(), | |
1029 | trp, p1.node(), p2.node(), |
|
1029 | trp, p1.node(), p2.node(), | |
1030 | user, ctx.date(), ctx.extra().copy()) |
|
1030 | user, ctx.date(), ctx.extra().copy()) | |
1031 | p = lambda: self.changelog.writepending() and self.root or "" |
|
1031 | p = lambda: self.changelog.writepending() and self.root or "" | |
1032 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' |
|
1032 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' | |
1033 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, |
|
1033 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, | |
1034 | parent2=xp2, pending=p) |
|
1034 | parent2=xp2, pending=p) | |
1035 | self.changelog.finalize(trp) |
|
1035 | self.changelog.finalize(trp) | |
1036 | tr.close() |
|
1036 | tr.close() | |
1037 |
|
1037 | |||
1038 | if self._branchcache: |
|
1038 | if self._branchcache: | |
1039 | self.updatebranchcache() |
|
1039 | self.updatebranchcache() | |
1040 | return n |
|
1040 | return n | |
1041 | finally: |
|
1041 | finally: | |
1042 | if tr: |
|
1042 | if tr: | |
1043 | tr.release() |
|
1043 | tr.release() | |
1044 | lock.release() |
|
1044 | lock.release() | |
1045 |
|
1045 | |||
1046 | def destroyed(self): |
|
1046 | def destroyed(self): | |
1047 | '''Inform the repository that nodes have been destroyed. |
|
1047 | '''Inform the repository that nodes have been destroyed. | |
1048 | Intended for use by strip and rollback, so there's a common |
|
1048 | Intended for use by strip and rollback, so there's a common | |
1049 | place for anything that has to be done after destroying history.''' |
|
1049 | place for anything that has to be done after destroying history.''' | |
1050 | # XXX it might be nice if we could take the list of destroyed |
|
1050 | # XXX it might be nice if we could take the list of destroyed | |
1051 | # nodes, but I don't see an easy way for rollback() to do that |
|
1051 | # nodes, but I don't see an easy way for rollback() to do that | |
1052 |
|
1052 | |||
1053 | # Ensure the persistent tag cache is updated. Doing it now |
|
1053 | # Ensure the persistent tag cache is updated. Doing it now | |
1054 | # means that the tag cache only has to worry about destroyed |
|
1054 | # means that the tag cache only has to worry about destroyed | |
1055 | # heads immediately after a strip/rollback. That in turn |
|
1055 | # heads immediately after a strip/rollback. That in turn | |
1056 | # guarantees that "cachetip == currenttip" (comparing both rev |
|
1056 | # guarantees that "cachetip == currenttip" (comparing both rev | |
1057 | # and node) always means no nodes have been added or destroyed. |
|
1057 | # and node) always means no nodes have been added or destroyed. | |
1058 |
|
1058 | |||
1059 | # XXX this is suboptimal when qrefresh'ing: we strip the current |
|
1059 | # XXX this is suboptimal when qrefresh'ing: we strip the current | |
1060 | # head, refresh the tag cache, then immediately add a new head. |
|
1060 | # head, refresh the tag cache, then immediately add a new head. | |
1061 | # But I think doing it this way is necessary for the "instant |
|
1061 | # But I think doing it this way is necessary for the "instant | |
1062 | # tag cache retrieval" case to work. |
|
1062 | # tag cache retrieval" case to work. | |
1063 | self.invalidatecaches() |
|
1063 | self.invalidatecaches() | |
1064 |
|
1064 | |||
1065 | def walk(self, match, node=None): |
|
1065 | def walk(self, match, node=None): | |
1066 | ''' |
|
1066 | ''' | |
1067 | walk recursively through the directory tree or a given |
|
1067 | walk recursively through the directory tree or a given | |
1068 | changeset, finding all files matched by the match |
|
1068 | changeset, finding all files matched by the match | |
1069 | function |
|
1069 | function | |
1070 | ''' |
|
1070 | ''' | |
1071 | return self[node].walk(match) |
|
1071 | return self[node].walk(match) | |
1072 |
|
1072 | |||
1073 | def status(self, node1='.', node2=None, match=None, |
|
1073 | def status(self, node1='.', node2=None, match=None, | |
1074 | ignored=False, clean=False, unknown=False, |
|
1074 | ignored=False, clean=False, unknown=False, | |
1075 | listsubrepos=False): |
|
1075 | listsubrepos=False): | |
1076 | """return status of files between two nodes or node and working directory |
|
1076 | """return status of files between two nodes or node and working directory | |
1077 |
|
1077 | |||
1078 | If node1 is None, use the first dirstate parent instead. |
|
1078 | If node1 is None, use the first dirstate parent instead. | |
1079 | If node2 is None, compare node1 with working directory. |
|
1079 | If node2 is None, compare node1 with working directory. | |
1080 | """ |
|
1080 | """ | |
1081 |
|
1081 | |||
1082 | def mfmatches(ctx): |
|
1082 | def mfmatches(ctx): | |
1083 | mf = ctx.manifest().copy() |
|
1083 | mf = ctx.manifest().copy() | |
1084 | for fn in mf.keys(): |
|
1084 | for fn in mf.keys(): | |
1085 | if not match(fn): |
|
1085 | if not match(fn): | |
1086 | del mf[fn] |
|
1086 | del mf[fn] | |
1087 | return mf |
|
1087 | return mf | |
1088 |
|
1088 | |||
1089 | if isinstance(node1, context.changectx): |
|
1089 | if isinstance(node1, context.changectx): | |
1090 | ctx1 = node1 |
|
1090 | ctx1 = node1 | |
1091 | else: |
|
1091 | else: | |
1092 | ctx1 = self[node1] |
|
1092 | ctx1 = self[node1] | |
1093 | if isinstance(node2, context.changectx): |
|
1093 | if isinstance(node2, context.changectx): | |
1094 | ctx2 = node2 |
|
1094 | ctx2 = node2 | |
1095 | else: |
|
1095 | else: | |
1096 | ctx2 = self[node2] |
|
1096 | ctx2 = self[node2] | |
1097 |
|
1097 | |||
1098 | working = ctx2.rev() is None |
|
1098 | working = ctx2.rev() is None | |
1099 | parentworking = working and ctx1 == self['.'] |
|
1099 | parentworking = working and ctx1 == self['.'] | |
1100 | match = match or matchmod.always(self.root, self.getcwd()) |
|
1100 | match = match or matchmod.always(self.root, self.getcwd()) | |
1101 | listignored, listclean, listunknown = ignored, clean, unknown |
|
1101 | listignored, listclean, listunknown = ignored, clean, unknown | |
1102 |
|
1102 | |||
1103 | # load earliest manifest first for caching reasons |
|
1103 | # load earliest manifest first for caching reasons | |
1104 | if not working and ctx2.rev() < ctx1.rev(): |
|
1104 | if not working and ctx2.rev() < ctx1.rev(): | |
1105 | ctx2.manifest() |
|
1105 | ctx2.manifest() | |
1106 |
|
1106 | |||
1107 | if not parentworking: |
|
1107 | if not parentworking: | |
1108 | def bad(f, msg): |
|
1108 | def bad(f, msg): | |
1109 | if f not in ctx1: |
|
1109 | if f not in ctx1: | |
1110 | self.ui.warn('%s: %s\n' % (self.dirstate.pathto(f), msg)) |
|
1110 | self.ui.warn('%s: %s\n' % (self.dirstate.pathto(f), msg)) | |
1111 | match.bad = bad |
|
1111 | match.bad = bad | |
1112 |
|
1112 | |||
1113 | if working: # we need to scan the working dir |
|
1113 | if working: # we need to scan the working dir | |
1114 | subrepos = [] |
|
1114 | subrepos = [] | |
1115 | if '.hgsub' in self.dirstate: |
|
1115 | if '.hgsub' in self.dirstate: | |
1116 | subrepos = ctx1.substate.keys() |
|
1116 | subrepos = ctx1.substate.keys() | |
1117 | s = self.dirstate.status(match, subrepos, listignored, |
|
1117 | s = self.dirstate.status(match, subrepos, listignored, | |
1118 | listclean, listunknown) |
|
1118 | listclean, listunknown) | |
1119 | cmp, modified, added, removed, deleted, unknown, ignored, clean = s |
|
1119 | cmp, modified, added, removed, deleted, unknown, ignored, clean = s | |
1120 |
|
1120 | |||
1121 | # check for any possibly clean files |
|
1121 | # check for any possibly clean files | |
1122 | if parentworking and cmp: |
|
1122 | if parentworking and cmp: | |
1123 | fixup = [] |
|
1123 | fixup = [] | |
1124 | # do a full compare of any files that might have changed |
|
1124 | # do a full compare of any files that might have changed | |
1125 | for f in sorted(cmp): |
|
1125 | for f in sorted(cmp): | |
1126 | if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f) |
|
1126 | if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f) | |
1127 | or ctx1[f].cmp(ctx2[f])): |
|
1127 | or ctx1[f].cmp(ctx2[f])): | |
1128 | modified.append(f) |
|
1128 | modified.append(f) | |
1129 | else: |
|
1129 | else: | |
1130 | fixup.append(f) |
|
1130 | fixup.append(f) | |
1131 |
|
1131 | |||
1132 | # update dirstate for files that are actually clean |
|
1132 | # update dirstate for files that are actually clean | |
1133 | if fixup: |
|
1133 | if fixup: | |
1134 | if listclean: |
|
1134 | if listclean: | |
1135 | clean += fixup |
|
1135 | clean += fixup | |
1136 |
|
1136 | |||
1137 | try: |
|
1137 | try: | |
1138 | # updating the dirstate is optional |
|
1138 | # updating the dirstate is optional | |
1139 | # so we don't wait on the lock |
|
1139 | # so we don't wait on the lock | |
1140 | wlock = self.wlock(False) |
|
1140 | wlock = self.wlock(False) | |
1141 | try: |
|
1141 | try: | |
1142 | for f in fixup: |
|
1142 | for f in fixup: | |
1143 | self.dirstate.normal(f) |
|
1143 | self.dirstate.normal(f) | |
1144 | finally: |
|
1144 | finally: | |
1145 | wlock.release() |
|
1145 | wlock.release() | |
1146 | except error.LockError: |
|
1146 | except error.LockError: | |
1147 | pass |
|
1147 | pass | |
1148 |
|
1148 | |||
1149 | if not parentworking: |
|
1149 | if not parentworking: | |
1150 | mf1 = mfmatches(ctx1) |
|
1150 | mf1 = mfmatches(ctx1) | |
1151 | if working: |
|
1151 | if working: | |
1152 | # we are comparing working dir against non-parent |
|
1152 | # we are comparing working dir against non-parent | |
1153 | # generate a pseudo-manifest for the working dir |
|
1153 | # generate a pseudo-manifest for the working dir | |
1154 | mf2 = mfmatches(self['.']) |
|
1154 | mf2 = mfmatches(self['.']) | |
1155 | for f in cmp + modified + added: |
|
1155 | for f in cmp + modified + added: | |
1156 | mf2[f] = None |
|
1156 | mf2[f] = None | |
1157 | mf2.set(f, ctx2.flags(f)) |
|
1157 | mf2.set(f, ctx2.flags(f)) | |
1158 | for f in removed: |
|
1158 | for f in removed: | |
1159 | if f in mf2: |
|
1159 | if f in mf2: | |
1160 | del mf2[f] |
|
1160 | del mf2[f] | |
1161 | else: |
|
1161 | else: | |
1162 | # we are comparing two revisions |
|
1162 | # we are comparing two revisions | |
1163 | deleted, unknown, ignored = [], [], [] |
|
1163 | deleted, unknown, ignored = [], [], [] | |
1164 | mf2 = mfmatches(ctx2) |
|
1164 | mf2 = mfmatches(ctx2) | |
1165 |
|
1165 | |||
1166 | modified, added, clean = [], [], [] |
|
1166 | modified, added, clean = [], [], [] | |
1167 | for fn in mf2: |
|
1167 | for fn in mf2: | |
1168 | if fn in mf1: |
|
1168 | if fn in mf1: | |
1169 | if (mf1.flags(fn) != mf2.flags(fn) or |
|
1169 | if (mf1.flags(fn) != mf2.flags(fn) or | |
1170 | (mf1[fn] != mf2[fn] and |
|
1170 | (mf1[fn] != mf2[fn] and | |
1171 | (mf2[fn] or ctx1[fn].cmp(ctx2[fn])))): |
|
1171 | (mf2[fn] or ctx1[fn].cmp(ctx2[fn])))): | |
1172 | modified.append(fn) |
|
1172 | modified.append(fn) | |
1173 | elif listclean: |
|
1173 | elif listclean: | |
1174 | clean.append(fn) |
|
1174 | clean.append(fn) | |
1175 | del mf1[fn] |
|
1175 | del mf1[fn] | |
1176 | else: |
|
1176 | else: | |
1177 | added.append(fn) |
|
1177 | added.append(fn) | |
1178 | removed = mf1.keys() |
|
1178 | removed = mf1.keys() | |
1179 |
|
1179 | |||
1180 | r = modified, added, removed, deleted, unknown, ignored, clean |
|
1180 | r = modified, added, removed, deleted, unknown, ignored, clean | |
1181 |
|
1181 | |||
1182 | if listsubrepos: |
|
1182 | if listsubrepos: | |
1183 | for subpath, sub in subrepo.itersubrepos(ctx1, ctx2): |
|
1183 | for subpath, sub in subrepo.itersubrepos(ctx1, ctx2): | |
1184 | if working: |
|
1184 | if working: | |
1185 | rev2 = None |
|
1185 | rev2 = None | |
1186 | else: |
|
1186 | else: | |
1187 | rev2 = ctx2.substate[subpath][1] |
|
1187 | rev2 = ctx2.substate[subpath][1] | |
1188 | try: |
|
1188 | try: | |
1189 | submatch = matchmod.narrowmatcher(subpath, match) |
|
1189 | submatch = matchmod.narrowmatcher(subpath, match) | |
1190 | s = sub.status(rev2, match=submatch, ignored=listignored, |
|
1190 | s = sub.status(rev2, match=submatch, ignored=listignored, | |
1191 | clean=listclean, unknown=listunknown, |
|
1191 | clean=listclean, unknown=listunknown, | |
1192 | listsubrepos=True) |
|
1192 | listsubrepos=True) | |
1193 | for rfiles, sfiles in zip(r, s): |
|
1193 | for rfiles, sfiles in zip(r, s): | |
1194 | rfiles.extend("%s/%s" % (subpath, f) for f in sfiles) |
|
1194 | rfiles.extend("%s/%s" % (subpath, f) for f in sfiles) | |
1195 | except error.LookupError: |
|
1195 | except error.LookupError: | |
1196 | self.ui.status(_("skipping missing subrepository: %s\n") |
|
1196 | self.ui.status(_("skipping missing subrepository: %s\n") | |
1197 | % subpath) |
|
1197 | % subpath) | |
1198 |
|
1198 | |||
1199 | [l.sort() for l in r] |
|
1199 | [l.sort() for l in r] | |
1200 | return r |
|
1200 | return r | |
1201 |
|
1201 | |||
1202 | def heads(self, start=None): |
|
1202 | def heads(self, start=None): | |
1203 | heads = self.changelog.heads(start) |
|
1203 | heads = self.changelog.heads(start) | |
1204 | # sort the output in rev descending order |
|
1204 | # sort the output in rev descending order | |
1205 | heads = [(-self.changelog.rev(h), h) for h in heads] |
|
1205 | heads = [(-self.changelog.rev(h), h) for h in heads] | |
1206 | return [n for (r, n) in sorted(heads)] |
|
1206 | return [n for (r, n) in sorted(heads)] | |
1207 |
|
1207 | |||
1208 | def branchheads(self, branch=None, start=None, closed=False): |
|
1208 | def branchheads(self, branch=None, start=None, closed=False): | |
1209 | '''return a (possibly filtered) list of heads for the given branch |
|
1209 | '''return a (possibly filtered) list of heads for the given branch | |
1210 |
|
1210 | |||
1211 | Heads are returned in topological order, from newest to oldest. |
|
1211 | Heads are returned in topological order, from newest to oldest. | |
1212 | If branch is None, use the dirstate branch. |
|
1212 | If branch is None, use the dirstate branch. | |
1213 | If start is not None, return only heads reachable from start. |
|
1213 | If start is not None, return only heads reachable from start. | |
1214 | If closed is True, return heads that are marked as closed as well. |
|
1214 | If closed is True, return heads that are marked as closed as well. | |
1215 | ''' |
|
1215 | ''' | |
1216 | if branch is None: |
|
1216 | if branch is None: | |
1217 | branch = self[None].branch() |
|
1217 | branch = self[None].branch() | |
1218 | branches = self.branchmap() |
|
1218 | branches = self.branchmap() | |
1219 | if branch not in branches: |
|
1219 | if branch not in branches: | |
1220 | return [] |
|
1220 | return [] | |
1221 | # the cache returns heads ordered lowest to highest |
|
1221 | # the cache returns heads ordered lowest to highest | |
1222 | bheads = list(reversed(branches[branch])) |
|
1222 | bheads = list(reversed(branches[branch])) | |
1223 | if start is not None: |
|
1223 | if start is not None: | |
1224 | # filter out the heads that cannot be reached from startrev |
|
1224 | # filter out the heads that cannot be reached from startrev | |
1225 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) |
|
1225 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) | |
1226 | bheads = [h for h in bheads if h in fbheads] |
|
1226 | bheads = [h for h in bheads if h in fbheads] | |
1227 | if not closed: |
|
1227 | if not closed: | |
1228 | bheads = [h for h in bheads if |
|
1228 | bheads = [h for h in bheads if | |
1229 | ('close' not in self.changelog.read(h)[5])] |
|
1229 | ('close' not in self.changelog.read(h)[5])] | |
1230 | return bheads |
|
1230 | return bheads | |
1231 |
|
1231 | |||
1232 | def branches(self, nodes): |
|
1232 | def branches(self, nodes): | |
1233 | if not nodes: |
|
1233 | if not nodes: | |
1234 | nodes = [self.changelog.tip()] |
|
1234 | nodes = [self.changelog.tip()] | |
1235 | b = [] |
|
1235 | b = [] | |
1236 | for n in nodes: |
|
1236 | for n in nodes: | |
1237 | t = n |
|
1237 | t = n | |
1238 | while 1: |
|
1238 | while 1: | |
1239 | p = self.changelog.parents(n) |
|
1239 | p = self.changelog.parents(n) | |
1240 | if p[1] != nullid or p[0] == nullid: |
|
1240 | if p[1] != nullid or p[0] == nullid: | |
1241 | b.append((t, n, p[0], p[1])) |
|
1241 | b.append((t, n, p[0], p[1])) | |
1242 | break |
|
1242 | break | |
1243 | n = p[0] |
|
1243 | n = p[0] | |
1244 | return b |
|
1244 | return b | |
1245 |
|
1245 | |||
1246 | def between(self, pairs): |
|
1246 | def between(self, pairs): | |
1247 | r = [] |
|
1247 | r = [] | |
1248 |
|
1248 | |||
1249 | for top, bottom in pairs: |
|
1249 | for top, bottom in pairs: | |
1250 | n, l, i = top, [], 0 |
|
1250 | n, l, i = top, [], 0 | |
1251 | f = 1 |
|
1251 | f = 1 | |
1252 |
|
1252 | |||
1253 | while n != bottom and n != nullid: |
|
1253 | while n != bottom and n != nullid: | |
1254 | p = self.changelog.parents(n)[0] |
|
1254 | p = self.changelog.parents(n)[0] | |
1255 | if i == f: |
|
1255 | if i == f: | |
1256 | l.append(n) |
|
1256 | l.append(n) | |
1257 | f = f * 2 |
|
1257 | f = f * 2 | |
1258 | n = p |
|
1258 | n = p | |
1259 | i += 1 |
|
1259 | i += 1 | |
1260 |
|
1260 | |||
1261 | r.append(l) |
|
1261 | r.append(l) | |
1262 |
|
1262 | |||
1263 | return r |
|
1263 | return r | |
1264 |
|
1264 | |||
1265 | def pull(self, remote, heads=None, force=False): |
|
1265 | def pull(self, remote, heads=None, force=False): | |
1266 | lock = self.lock() |
|
1266 | lock = self.lock() | |
1267 | try: |
|
1267 | try: | |
1268 | tmp = discovery.findcommonincoming(self, remote, heads=heads, |
|
1268 | tmp = discovery.findcommonincoming(self, remote, heads=heads, | |
1269 | force=force) |
|
1269 | force=force) | |
1270 | common, fetch, rheads = tmp |
|
1270 | common, fetch, rheads = tmp | |
1271 | if not fetch: |
|
1271 | if not fetch: | |
1272 | self.ui.status(_("no changes found\n")) |
|
1272 | self.ui.status(_("no changes found\n")) | |
1273 | return 0 |
|
1273 | return 0 | |
1274 |
|
1274 | |||
1275 | if heads is None and fetch == [nullid]: |
|
1275 | if heads is None and fetch == [nullid]: | |
1276 | self.ui.status(_("requesting all changes\n")) |
|
1276 | self.ui.status(_("requesting all changes\n")) | |
1277 | elif heads is None and remote.capable('changegroupsubset'): |
|
1277 | elif heads is None and remote.capable('changegroupsubset'): | |
1278 | # issue1320, avoid a race if remote changed after discovery |
|
1278 | # issue1320, avoid a race if remote changed after discovery | |
1279 | heads = rheads |
|
1279 | heads = rheads | |
1280 |
|
1280 | |||
1281 | if heads is None: |
|
1281 | if heads is None: | |
1282 | cg = remote.changegroup(fetch, 'pull') |
|
1282 | cg = remote.changegroup(fetch, 'pull') | |
1283 | else: |
|
1283 | else: | |
1284 | if not remote.capable('changegroupsubset'): |
|
1284 | if not remote.capable('changegroupsubset'): | |
1285 | raise util.Abort(_("partial pull cannot be done because " |
|
1285 | raise util.Abort(_("partial pull cannot be done because " | |
1286 | "other repository doesn't support " |
|
1286 | "other repository doesn't support " | |
1287 | "changegroupsubset.")) |
|
1287 | "changegroupsubset.")) | |
1288 | cg = remote.changegroupsubset(fetch, heads, 'pull') |
|
1288 | cg = remote.changegroupsubset(fetch, heads, 'pull') | |
1289 | return self.addchangegroup(cg, 'pull', remote.url(), lock=lock) |
|
1289 | return self.addchangegroup(cg, 'pull', remote.url(), lock=lock) | |
1290 | finally: |
|
1290 | finally: | |
1291 | lock.release() |
|
1291 | lock.release() | |
1292 |
|
1292 | |||
1293 | def push(self, remote, force=False, revs=None, newbranch=False): |
|
1293 | def push(self, remote, force=False, revs=None, newbranch=False): | |
1294 | '''Push outgoing changesets (limited by revs) from the current |
|
1294 | '''Push outgoing changesets (limited by revs) from the current | |
1295 | repository to remote. Return an integer: |
|
1295 | repository to remote. Return an integer: | |
1296 | - 0 means HTTP error *or* nothing to push |
|
1296 | - 0 means HTTP error *or* nothing to push | |
1297 | - 1 means we pushed and remote head count is unchanged *or* |
|
1297 | - 1 means we pushed and remote head count is unchanged *or* | |
1298 | we have outgoing changesets but refused to push |
|
1298 | we have outgoing changesets but refused to push | |
1299 | - other values as described by addchangegroup() |
|
1299 | - other values as described by addchangegroup() | |
1300 | ''' |
|
1300 | ''' | |
1301 | # there are two ways to push to remote repo: |
|
1301 | # there are two ways to push to remote repo: | |
1302 | # |
|
1302 | # | |
1303 | # addchangegroup assumes local user can lock remote |
|
1303 | # addchangegroup assumes local user can lock remote | |
1304 | # repo (local filesystem, old ssh servers). |
|
1304 | # repo (local filesystem, old ssh servers). | |
1305 | # |
|
1305 | # | |
1306 | # unbundle assumes local user cannot lock remote repo (new ssh |
|
1306 | # unbundle assumes local user cannot lock remote repo (new ssh | |
1307 | # servers, http servers). |
|
1307 | # servers, http servers). | |
1308 |
|
1308 | |||
1309 | lock = None |
|
1309 | lock = None | |
1310 | unbundle = remote.capable('unbundle') |
|
1310 | unbundle = remote.capable('unbundle') | |
1311 | if not unbundle: |
|
1311 | if not unbundle: | |
1312 | lock = remote.lock() |
|
1312 | lock = remote.lock() | |
1313 | try: |
|
1313 | try: | |
1314 | ret = discovery.prepush(self, remote, force, revs, newbranch) |
|
1314 | ret = discovery.prepush(self, remote, force, revs, newbranch) | |
1315 | if ret[0] is None: |
|
1315 | if ret[0] is None: | |
1316 | # and here we return 0 for "nothing to push" or 1 for |
|
1316 | # and here we return 0 for "nothing to push" or 1 for | |
1317 | # "something to push but I refuse" |
|
1317 | # "something to push but I refuse" | |
1318 | return ret[1] |
|
1318 | return ret[1] | |
1319 |
|
1319 | |||
1320 | cg, remote_heads = ret |
|
1320 | cg, remote_heads = ret | |
1321 | if unbundle: |
|
1321 | if unbundle: | |
1322 | # local repo finds heads on server, finds out what revs it must |
|
1322 | # local repo finds heads on server, finds out what revs it must | |
1323 | # push. once revs transferred, if server finds it has |
|
1323 | # push. once revs transferred, if server finds it has | |
1324 | # different heads (someone else won commit/push race), server |
|
1324 | # different heads (someone else won commit/push race), server | |
1325 | # aborts. |
|
1325 | # aborts. | |
1326 | if force: |
|
1326 | if force: | |
1327 | remote_heads = ['force'] |
|
1327 | remote_heads = ['force'] | |
1328 | # ssh: return remote's addchangegroup() |
|
1328 | # ssh: return remote's addchangegroup() | |
1329 | # http: return remote's addchangegroup() or 0 for error |
|
1329 | # http: return remote's addchangegroup() or 0 for error | |
1330 | return remote.unbundle(cg, remote_heads, 'push') |
|
1330 | return remote.unbundle(cg, remote_heads, 'push') | |
1331 | else: |
|
1331 | else: | |
1332 | # we return an integer indicating remote head count change |
|
1332 | # we return an integer indicating remote head count change | |
1333 | return remote.addchangegroup(cg, 'push', self.url(), lock=lock) |
|
1333 | return remote.addchangegroup(cg, 'push', self.url(), lock=lock) | |
1334 | finally: |
|
1334 | finally: | |
1335 | if lock is not None: |
|
1335 | if lock is not None: | |
1336 | lock.release() |
|
1336 | lock.release() | |
1337 |
|
1337 | |||
1338 | def changegroupinfo(self, nodes, source): |
|
1338 | def changegroupinfo(self, nodes, source): | |
1339 | if self.ui.verbose or source == 'bundle': |
|
1339 | if self.ui.verbose or source == 'bundle': | |
1340 | self.ui.status(_("%d changesets found\n") % len(nodes)) |
|
1340 | self.ui.status(_("%d changesets found\n") % len(nodes)) | |
1341 | if self.ui.debugflag: |
|
1341 | if self.ui.debugflag: | |
1342 | self.ui.debug("list of changesets:\n") |
|
1342 | self.ui.debug("list of changesets:\n") | |
1343 | for node in nodes: |
|
1343 | for node in nodes: | |
1344 | self.ui.debug("%s\n" % hex(node)) |
|
1344 | self.ui.debug("%s\n" % hex(node)) | |
1345 |
|
1345 | |||
1346 | def changegroupsubset(self, bases, heads, source, extranodes=None): |
|
1346 | def changegroupsubset(self, bases, heads, source, extranodes=None): | |
1347 | """Compute a changegroup consisting of all the nodes that are |
|
1347 | """Compute a changegroup consisting of all the nodes that are | |
1348 | descendents of any of the bases and ancestors of any of the heads. |
|
1348 | descendents of any of the bases and ancestors of any of the heads. | |
1349 | Return a chunkbuffer object whose read() method will return |
|
1349 | Return a chunkbuffer object whose read() method will return | |
1350 | successive changegroup chunks. |
|
1350 | successive changegroup chunks. | |
1351 |
|
1351 | |||
1352 | It is fairly complex as determining which filenodes and which |
|
1352 | It is fairly complex as determining which filenodes and which | |
1353 | manifest nodes need to be included for the changeset to be complete |
|
1353 | manifest nodes need to be included for the changeset to be complete | |
1354 | is non-trivial. |
|
1354 | is non-trivial. | |
1355 |
|
1355 | |||
1356 | Another wrinkle is doing the reverse, figuring out which changeset in |
|
1356 | Another wrinkle is doing the reverse, figuring out which changeset in | |
1357 | the changegroup a particular filenode or manifestnode belongs to. |
|
1357 | the changegroup a particular filenode or manifestnode belongs to. | |
1358 |
|
1358 | |||
1359 | The caller can specify some nodes that must be included in the |
|
1359 | The caller can specify some nodes that must be included in the | |
1360 | changegroup using the extranodes argument. It should be a dict |
|
1360 | changegroup using the extranodes argument. It should be a dict | |
1361 | where the keys are the filenames (or 1 for the manifest), and the |
|
1361 | where the keys are the filenames (or 1 for the manifest), and the | |
1362 | values are lists of (node, linknode) tuples, where node is a wanted |
|
1362 | values are lists of (node, linknode) tuples, where node is a wanted | |
1363 | node and linknode is the changelog node that should be transmitted as |
|
1363 | node and linknode is the changelog node that should be transmitted as | |
1364 | the linkrev. |
|
1364 | the linkrev. | |
1365 | """ |
|
1365 | """ | |
1366 |
|
1366 | |||
1367 | # Set up some initial variables |
|
1367 | # Set up some initial variables | |
1368 | # Make it easy to refer to self.changelog |
|
1368 | # Make it easy to refer to self.changelog | |
1369 | cl = self.changelog |
|
1369 | cl = self.changelog | |
1370 | # Compute the list of changesets in this changegroup. |
|
1370 | # Compute the list of changesets in this changegroup. | |
1371 | # Some bases may turn out to be superfluous, and some heads may be |
|
1371 | # Some bases may turn out to be superfluous, and some heads may be | |
1372 | # too. nodesbetween will return the minimal set of bases and heads |
|
1372 | # too. nodesbetween will return the minimal set of bases and heads | |
1373 | # necessary to re-create the changegroup. |
|
1373 | # necessary to re-create the changegroup. | |
1374 | if not bases: |
|
1374 | if not bases: | |
1375 | bases = [nullid] |
|
1375 | bases = [nullid] | |
1376 | msng_cl_lst, bases, heads = cl.nodesbetween(bases, heads) |
|
1376 | msng_cl_lst, bases, heads = cl.nodesbetween(bases, heads) | |
1377 |
|
1377 | |||
1378 | if extranodes is None: |
|
1378 | if extranodes is None: | |
1379 | # can we go through the fast path ? |
|
1379 | # can we go through the fast path ? | |
1380 | heads.sort() |
|
1380 | heads.sort() | |
1381 | allheads = self.heads() |
|
1381 | allheads = self.heads() | |
1382 | allheads.sort() |
|
1382 | allheads.sort() | |
1383 | if heads == allheads: |
|
1383 | if heads == allheads: | |
1384 | return self._changegroup(msng_cl_lst, source) |
|
1384 | return self._changegroup(msng_cl_lst, source) | |
1385 |
|
1385 | |||
1386 | # slow path |
|
1386 | # slow path | |
1387 | self.hook('preoutgoing', throw=True, source=source) |
|
1387 | self.hook('preoutgoing', throw=True, source=source) | |
1388 |
|
1388 | |||
1389 | self.changegroupinfo(msng_cl_lst, source) |
|
1389 | self.changegroupinfo(msng_cl_lst, source) | |
1390 |
|
1390 | |||
1391 | # We assume that all ancestors of bases are known |
|
1391 | # We assume that all ancestors of bases are known | |
1392 | commonrevs = set(cl.ancestors(*[cl.rev(n) for n in bases])) |
|
1392 | commonrevs = set(cl.ancestors(*[cl.rev(n) for n in bases])) | |
1393 |
|
1393 | |||
1394 | # Make it easy to refer to self.manifest |
|
1394 | # Make it easy to refer to self.manifest | |
1395 | mnfst = self.manifest |
|
1395 | mnfst = self.manifest | |
1396 | # We don't know which manifests are missing yet |
|
1396 | # We don't know which manifests are missing yet | |
1397 | msng_mnfst_set = {} |
|
1397 | msng_mnfst_set = {} | |
1398 | # Nor do we know which filenodes are missing. |
|
1398 | # Nor do we know which filenodes are missing. | |
1399 | msng_filenode_set = {} |
|
1399 | msng_filenode_set = {} | |
1400 |
|
1400 | |||
1401 | junk = mnfst.index[len(mnfst) - 1] # Get around a bug in lazyindex |
|
1401 | junk = mnfst.index[len(mnfst) - 1] # Get around a bug in lazyindex | |
1402 | junk = None |
|
1402 | junk = None | |
1403 |
|
1403 | |||
1404 | # A changeset always belongs to itself, so the changenode lookup |
|
1404 | # A changeset always belongs to itself, so the changenode lookup | |
1405 | # function for a changenode is identity. |
|
1405 | # function for a changenode is identity. | |
1406 | def identity(x): |
|
1406 | def identity(x): | |
1407 | return x |
|
1407 | return x | |
1408 |
|
1408 | |||
1409 | # A function generating function that sets up the initial environment |
|
1409 | # A function generating function that sets up the initial environment | |
1410 | # the inner function. |
|
1410 | # the inner function. | |
1411 | def filenode_collector(changedfiles): |
|
1411 | def filenode_collector(changedfiles): | |
1412 | # This gathers information from each manifestnode included in the |
|
1412 | # This gathers information from each manifestnode included in the | |
1413 | # changegroup about which filenodes the manifest node references |
|
1413 | # changegroup about which filenodes the manifest node references | |
1414 | # so we can include those in the changegroup too. |
|
1414 | # so we can include those in the changegroup too. | |
1415 | # |
|
1415 | # | |
1416 | # It also remembers which changenode each filenode belongs to. It |
|
1416 | # It also remembers which changenode each filenode belongs to. It | |
1417 | # does this by assuming the a filenode belongs to the changenode |
|
1417 | # does this by assuming the a filenode belongs to the changenode | |
1418 | # the first manifest that references it belongs to. |
|
1418 | # the first manifest that references it belongs to. | |
1419 | def collect_msng_filenodes(mnfstnode): |
|
1419 | def collect_msng_filenodes(mnfstnode): | |
1420 | r = mnfst.rev(mnfstnode) |
|
1420 | r = mnfst.rev(mnfstnode) | |
1421 | if mnfst.deltaparent(r) in mnfst.parentrevs(r): |
|
1421 | if mnfst.deltaparent(r) in mnfst.parentrevs(r): | |
1422 | # If the previous rev is one of the parents, |
|
1422 | # If the previous rev is one of the parents, | |
1423 | # we only need to see a diff. |
|
1423 | # we only need to see a diff. | |
1424 | deltamf = mnfst.readdelta(mnfstnode) |
|
1424 | deltamf = mnfst.readdelta(mnfstnode) | |
1425 | # For each line in the delta |
|
1425 | # For each line in the delta | |
1426 | for f, fnode in deltamf.iteritems(): |
|
1426 | for f, fnode in deltamf.iteritems(): | |
1427 | # And if the file is in the list of files we care |
|
1427 | # And if the file is in the list of files we care | |
1428 | # about. |
|
1428 | # about. | |
1429 | if f in changedfiles: |
|
1429 | if f in changedfiles: | |
1430 | # Get the changenode this manifest belongs to |
|
1430 | # Get the changenode this manifest belongs to | |
1431 | clnode = msng_mnfst_set[mnfstnode] |
|
1431 | clnode = msng_mnfst_set[mnfstnode] | |
1432 | # Create the set of filenodes for the file if |
|
1432 | # Create the set of filenodes for the file if | |
1433 | # there isn't one already. |
|
1433 | # there isn't one already. | |
1434 | ndset = msng_filenode_set.setdefault(f, {}) |
|
1434 | ndset = msng_filenode_set.setdefault(f, {}) | |
1435 | # And set the filenode's changelog node to the |
|
1435 | # And set the filenode's changelog node to the | |
1436 | # manifest's if it hasn't been set already. |
|
1436 | # manifest's if it hasn't been set already. | |
1437 | ndset.setdefault(fnode, clnode) |
|
1437 | ndset.setdefault(fnode, clnode) | |
1438 | else: |
|
1438 | else: | |
1439 | # Otherwise we need a full manifest. |
|
1439 | # Otherwise we need a full manifest. | |
1440 | m = mnfst.read(mnfstnode) |
|
1440 | m = mnfst.read(mnfstnode) | |
1441 | # For every file in we care about. |
|
1441 | # For every file in we care about. | |
1442 | for f in changedfiles: |
|
1442 | for f in changedfiles: | |
1443 | fnode = m.get(f, None) |
|
1443 | fnode = m.get(f, None) | |
1444 | # If it's in the manifest |
|
1444 | # If it's in the manifest | |
1445 | if fnode is not None: |
|
1445 | if fnode is not None: | |
1446 | # See comments above. |
|
1446 | # See comments above. | |
1447 | clnode = msng_mnfst_set[mnfstnode] |
|
1447 | clnode = msng_mnfst_set[mnfstnode] | |
1448 | ndset = msng_filenode_set.setdefault(f, {}) |
|
1448 | ndset = msng_filenode_set.setdefault(f, {}) | |
1449 | ndset.setdefault(fnode, clnode) |
|
1449 | ndset.setdefault(fnode, clnode) | |
1450 | return collect_msng_filenodes |
|
1450 | return collect_msng_filenodes | |
1451 |
|
1451 | |||
1452 | # If we determine that a particular file or manifest node must be a |
|
1452 | # If we determine that a particular file or manifest node must be a | |
1453 | # node that the recipient of the changegroup will already have, we can |
|
1453 | # node that the recipient of the changegroup will already have, we can | |
1454 | # also assume the recipient will have all the parents. This function |
|
1454 | # also assume the recipient will have all the parents. This function | |
1455 | # prunes them from the set of missing nodes. |
|
1455 | # prunes them from the set of missing nodes. | |
1456 | def prune(revlog, missingnodes): |
|
1456 | def prune(revlog, missingnodes): | |
1457 | hasset = set() |
|
1457 | hasset = set() | |
1458 | # If a 'missing' filenode thinks it belongs to a changenode we |
|
1458 | # If a 'missing' filenode thinks it belongs to a changenode we | |
1459 | # assume the recipient must have, then the recipient must have |
|
1459 | # assume the recipient must have, then the recipient must have | |
1460 | # that filenode. |
|
1460 | # that filenode. | |
1461 | for n in missingnodes: |
|
1461 | for n in missingnodes: | |
1462 | clrev = revlog.linkrev(revlog.rev(n)) |
|
1462 | clrev = revlog.linkrev(revlog.rev(n)) | |
1463 | if clrev in commonrevs: |
|
1463 | if clrev in commonrevs: | |
1464 | hasset.add(n) |
|
1464 | hasset.add(n) | |
1465 | for n in hasset: |
|
1465 | for n in hasset: | |
1466 | missingnodes.pop(n, None) |
|
1466 | missingnodes.pop(n, None) | |
1467 | for r in revlog.ancestors(*[revlog.rev(n) for n in hasset]): |
|
1467 | for r in revlog.ancestors(*[revlog.rev(n) for n in hasset]): | |
1468 | missingnodes.pop(revlog.node(r), None) |
|
1468 | missingnodes.pop(revlog.node(r), None) | |
1469 |
|
1469 | |||
1470 | # Add the nodes that were explicitly requested. |
|
1470 | # Add the nodes that were explicitly requested. | |
1471 | def add_extra_nodes(name, nodes): |
|
1471 | def add_extra_nodes(name, nodes): | |
1472 | if not extranodes or name not in extranodes: |
|
1472 | if not extranodes or name not in extranodes: | |
1473 | return |
|
1473 | return | |
1474 |
|
1474 | |||
1475 | for node, linknode in extranodes[name]: |
|
1475 | for node, linknode in extranodes[name]: | |
1476 | if node not in nodes: |
|
1476 | if node not in nodes: | |
1477 | nodes[node] = linknode |
|
1477 | nodes[node] = linknode | |
1478 |
|
1478 | |||
1479 | # Now that we have all theses utility functions to help out and |
|
1479 | # Now that we have all theses utility functions to help out and | |
1480 | # logically divide up the task, generate the group. |
|
1480 | # logically divide up the task, generate the group. | |
1481 | def gengroup(): |
|
1481 | def gengroup(): | |
1482 | # The set of changed files starts empty. |
|
1482 | # The set of changed files starts empty. | |
1483 | changedfiles = set() |
|
1483 | changedfiles = set() | |
1484 | collect = changegroup.collector(cl, msng_mnfst_set, changedfiles) |
|
1484 | collect = changegroup.collector(cl, msng_mnfst_set, changedfiles) | |
1485 |
|
1485 | |||
1486 | # Create a changenode group generator that will call our functions |
|
1486 | # Create a changenode group generator that will call our functions | |
1487 | # back to lookup the owning changenode and collect information. |
|
1487 | # back to lookup the owning changenode and collect information. | |
1488 | group = cl.group(msng_cl_lst, identity, collect) |
|
1488 | group = cl.group(msng_cl_lst, identity, collect) | |
1489 | for cnt, chnk in enumerate(group): |
|
1489 | for cnt, chnk in enumerate(group): | |
1490 | yield chnk |
|
1490 | yield chnk | |
1491 | self.ui.progress(_('bundling changes'), cnt, unit=_('chunks')) |
|
1491 | self.ui.progress(_('bundling changes'), cnt, unit=_('chunks')) | |
1492 | self.ui.progress(_('bundling changes'), None) |
|
1492 | self.ui.progress(_('bundling changes'), None) | |
1493 |
|
1493 | |||
1494 | prune(mnfst, msng_mnfst_set) |
|
1494 | prune(mnfst, msng_mnfst_set) | |
1495 | add_extra_nodes(1, msng_mnfst_set) |
|
1495 | add_extra_nodes(1, msng_mnfst_set) | |
1496 | msng_mnfst_lst = msng_mnfst_set.keys() |
|
1496 | msng_mnfst_lst = msng_mnfst_set.keys() | |
1497 | # Sort the manifestnodes by revision number. |
|
1497 | # Sort the manifestnodes by revision number. | |
1498 | msng_mnfst_lst.sort(key=mnfst.rev) |
|
1498 | msng_mnfst_lst.sort(key=mnfst.rev) | |
1499 | # Create a generator for the manifestnodes that calls our lookup |
|
1499 | # Create a generator for the manifestnodes that calls our lookup | |
1500 | # and data collection functions back. |
|
1500 | # and data collection functions back. | |
1501 | group = mnfst.group(msng_mnfst_lst, |
|
1501 | group = mnfst.group(msng_mnfst_lst, | |
1502 | lambda mnode: msng_mnfst_set[mnode], |
|
1502 | lambda mnode: msng_mnfst_set[mnode], | |
1503 | filenode_collector(changedfiles)) |
|
1503 | filenode_collector(changedfiles)) | |
1504 | for cnt, chnk in enumerate(group): |
|
1504 | for cnt, chnk in enumerate(group): | |
1505 | yield chnk |
|
1505 | yield chnk | |
1506 | self.ui.progress(_('bundling manifests'), cnt, unit=_('chunks')) |
|
1506 | self.ui.progress(_('bundling manifests'), cnt, unit=_('chunks')) | |
1507 | self.ui.progress(_('bundling manifests'), None) |
|
1507 | self.ui.progress(_('bundling manifests'), None) | |
1508 |
|
1508 | |||
1509 | # These are no longer needed, dereference and toss the memory for |
|
1509 | # These are no longer needed, dereference and toss the memory for | |
1510 | # them. |
|
1510 | # them. | |
1511 | msng_mnfst_lst = None |
|
1511 | msng_mnfst_lst = None | |
1512 | msng_mnfst_set.clear() |
|
1512 | msng_mnfst_set.clear() | |
1513 |
|
1513 | |||
1514 | if extranodes: |
|
1514 | if extranodes: | |
1515 | for fname in extranodes: |
|
1515 | for fname in extranodes: | |
1516 | if isinstance(fname, int): |
|
1516 | if isinstance(fname, int): | |
1517 | continue |
|
1517 | continue | |
1518 | msng_filenode_set.setdefault(fname, {}) |
|
1518 | msng_filenode_set.setdefault(fname, {}) | |
1519 | changedfiles.add(fname) |
|
1519 | changedfiles.add(fname) | |
1520 | # Go through all our files in order sorted by name. |
|
1520 | # Go through all our files in order sorted by name. | |
1521 | cnt = 0 |
|
1521 | cnt = 0 | |
1522 | for fname in sorted(changedfiles): |
|
1522 | for fname in sorted(changedfiles): | |
1523 | filerevlog = self.file(fname) |
|
1523 | filerevlog = self.file(fname) | |
1524 | if not len(filerevlog): |
|
1524 | if not len(filerevlog): | |
1525 | raise util.Abort(_("empty or missing revlog for %s") % fname) |
|
1525 | raise util.Abort(_("empty or missing revlog for %s") % fname) | |
1526 | # Toss out the filenodes that the recipient isn't really |
|
1526 | # Toss out the filenodes that the recipient isn't really | |
1527 | # missing. |
|
1527 | # missing. | |
1528 | missingfnodes = msng_filenode_set.pop(fname, {}) |
|
1528 | missingfnodes = msng_filenode_set.pop(fname, {}) | |
1529 | prune(filerevlog, missingfnodes) |
|
1529 | prune(filerevlog, missingfnodes) | |
1530 | add_extra_nodes(fname, missingfnodes) |
|
1530 | add_extra_nodes(fname, missingfnodes) | |
1531 | # If any filenodes are left, generate the group for them, |
|
1531 | # If any filenodes are left, generate the group for them, | |
1532 | # otherwise don't bother. |
|
1532 | # otherwise don't bother. | |
1533 | if missingfnodes: |
|
1533 | if missingfnodes: | |
1534 | yield changegroup.chunkheader(len(fname)) |
|
1534 | yield changegroup.chunkheader(len(fname)) | |
1535 | yield fname |
|
1535 | yield fname | |
1536 | # Sort the filenodes by their revision # (topological order) |
|
1536 | # Sort the filenodes by their revision # (topological order) | |
1537 | nodeiter = list(missingfnodes) |
|
1537 | nodeiter = list(missingfnodes) | |
1538 | nodeiter.sort(key=filerevlog.rev) |
|
1538 | nodeiter.sort(key=filerevlog.rev) | |
1539 | # Create a group generator and only pass in a changenode |
|
1539 | # Create a group generator and only pass in a changenode | |
1540 | # lookup function as we need to collect no information |
|
1540 | # lookup function as we need to collect no information | |
1541 | # from filenodes. |
|
1541 | # from filenodes. | |
1542 | group = filerevlog.group(nodeiter, |
|
1542 | group = filerevlog.group(nodeiter, | |
1543 | lambda fnode: missingfnodes[fnode]) |
|
1543 | lambda fnode: missingfnodes[fnode]) | |
1544 | for chnk in group: |
|
1544 | for chnk in group: | |
1545 | self.ui.progress( |
|
1545 | self.ui.progress( | |
1546 | _('bundling files'), cnt, item=fname, unit=_('chunks')) |
|
1546 | _('bundling files'), cnt, item=fname, unit=_('chunks')) | |
1547 | cnt += 1 |
|
1547 | cnt += 1 | |
1548 | yield chnk |
|
1548 | yield chnk | |
1549 | # Signal that no more groups are left. |
|
1549 | # Signal that no more groups are left. | |
1550 | yield changegroup.closechunk() |
|
1550 | yield changegroup.closechunk() | |
1551 | self.ui.progress(_('bundling files'), None) |
|
1551 | self.ui.progress(_('bundling files'), None) | |
1552 |
|
1552 | |||
1553 | if msng_cl_lst: |
|
1553 | if msng_cl_lst: | |
1554 | self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source) |
|
1554 | self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source) | |
1555 |
|
1555 | |||
1556 | return changegroup.unbundle10(util.chunkbuffer(gengroup()), 'UN') |
|
1556 | return changegroup.unbundle10(util.chunkbuffer(gengroup()), 'UN') | |
1557 |
|
1557 | |||
1558 | def changegroup(self, basenodes, source): |
|
1558 | def changegroup(self, basenodes, source): | |
1559 | # to avoid a race we use changegroupsubset() (issue1320) |
|
1559 | # to avoid a race we use changegroupsubset() (issue1320) | |
1560 | return self.changegroupsubset(basenodes, self.heads(), source) |
|
1560 | return self.changegroupsubset(basenodes, self.heads(), source) | |
1561 |
|
1561 | |||
1562 | def _changegroup(self, nodes, source): |
|
1562 | def _changegroup(self, nodes, source): | |
1563 | """Compute the changegroup of all nodes that we have that a recipient |
|
1563 | """Compute the changegroup of all nodes that we have that a recipient | |
1564 | doesn't. Return a chunkbuffer object whose read() method will return |
|
1564 | doesn't. Return a chunkbuffer object whose read() method will return | |
1565 | successive changegroup chunks. |
|
1565 | successive changegroup chunks. | |
1566 |
|
1566 | |||
1567 | This is much easier than the previous function as we can assume that |
|
1567 | This is much easier than the previous function as we can assume that | |
1568 | the recipient has any changenode we aren't sending them. |
|
1568 | the recipient has any changenode we aren't sending them. | |
1569 |
|
1569 | |||
1570 | nodes is the set of nodes to send""" |
|
1570 | nodes is the set of nodes to send""" | |
1571 |
|
1571 | |||
1572 | self.hook('preoutgoing', throw=True, source=source) |
|
1572 | self.hook('preoutgoing', throw=True, source=source) | |
1573 |
|
1573 | |||
1574 | cl = self.changelog |
|
1574 | cl = self.changelog | |
1575 | revset = set([cl.rev(n) for n in nodes]) |
|
1575 | revset = set([cl.rev(n) for n in nodes]) | |
1576 | self.changegroupinfo(nodes, source) |
|
1576 | self.changegroupinfo(nodes, source) | |
1577 |
|
1577 | |||
1578 | def identity(x): |
|
1578 | def identity(x): | |
1579 | return x |
|
1579 | return x | |
1580 |
|
1580 | |||
1581 | def gennodelst(log): |
|
1581 | def gennodelst(log): | |
1582 | for r in log: |
|
1582 | for r in log: | |
1583 | if log.linkrev(r) in revset: |
|
1583 | if log.linkrev(r) in revset: | |
1584 | yield log.node(r) |
|
1584 | yield log.node(r) | |
1585 |
|
1585 | |||
1586 | def lookuplinkrev_func(revlog): |
|
1586 | def lookuplinkrev_func(revlog): | |
1587 | def lookuplinkrev(n): |
|
1587 | def lookuplinkrev(n): | |
1588 | return cl.node(revlog.linkrev(revlog.rev(n))) |
|
1588 | return cl.node(revlog.linkrev(revlog.rev(n))) | |
1589 | return lookuplinkrev |
|
1589 | return lookuplinkrev | |
1590 |
|
1590 | |||
1591 | def gengroup(): |
|
1591 | def gengroup(): | |
1592 | '''yield a sequence of changegroup chunks (strings)''' |
|
1592 | '''yield a sequence of changegroup chunks (strings)''' | |
1593 | # construct a list of all changed files |
|
1593 | # construct a list of all changed files | |
1594 | changedfiles = set() |
|
1594 | changedfiles = set() | |
1595 | mmfs = {} |
|
1595 | mmfs = {} | |
1596 | collect = changegroup.collector(cl, mmfs, changedfiles) |
|
1596 | collect = changegroup.collector(cl, mmfs, changedfiles) | |
1597 |
|
1597 | |||
1598 | for cnt, chnk in enumerate(cl.group(nodes, identity, collect)): |
|
1598 | for cnt, chnk in enumerate(cl.group(nodes, identity, collect)): | |
1599 | self.ui.progress(_('bundling changes'), cnt, unit=_('chunks')) |
|
1599 | self.ui.progress(_('bundling changes'), cnt, unit=_('chunks')) | |
1600 | yield chnk |
|
1600 | yield chnk | |
1601 | self.ui.progress(_('bundling changes'), None) |
|
1601 | self.ui.progress(_('bundling changes'), None) | |
1602 |
|
1602 | |||
1603 | mnfst = self.manifest |
|
1603 | mnfst = self.manifest | |
1604 | nodeiter = gennodelst(mnfst) |
|
1604 | nodeiter = gennodelst(mnfst) | |
1605 | for cnt, chnk in enumerate(mnfst.group(nodeiter, |
|
1605 | for cnt, chnk in enumerate(mnfst.group(nodeiter, | |
1606 | lookuplinkrev_func(mnfst))): |
|
1606 | lookuplinkrev_func(mnfst))): | |
1607 | self.ui.progress(_('bundling manifests'), cnt, unit=_('chunks')) |
|
1607 | self.ui.progress(_('bundling manifests'), cnt, unit=_('chunks')) | |
1608 | yield chnk |
|
1608 | yield chnk | |
1609 | self.ui.progress(_('bundling manifests'), None) |
|
1609 | self.ui.progress(_('bundling manifests'), None) | |
1610 |
|
1610 | |||
1611 | cnt = 0 |
|
1611 | cnt = 0 | |
1612 | for fname in sorted(changedfiles): |
|
1612 | for fname in sorted(changedfiles): | |
1613 | filerevlog = self.file(fname) |
|
1613 | filerevlog = self.file(fname) | |
1614 | if not len(filerevlog): |
|
1614 | if not len(filerevlog): | |
1615 | raise util.Abort(_("empty or missing revlog for %s") % fname) |
|
1615 | raise util.Abort(_("empty or missing revlog for %s") % fname) | |
1616 | nodeiter = gennodelst(filerevlog) |
|
1616 | nodeiter = gennodelst(filerevlog) | |
1617 | nodeiter = list(nodeiter) |
|
1617 | nodeiter = list(nodeiter) | |
1618 | if nodeiter: |
|
1618 | if nodeiter: | |
1619 | yield changegroup.chunkheader(len(fname)) |
|
1619 | yield changegroup.chunkheader(len(fname)) | |
1620 | yield fname |
|
1620 | yield fname | |
1621 | lookup = lookuplinkrev_func(filerevlog) |
|
1621 | lookup = lookuplinkrev_func(filerevlog) | |
1622 | for chnk in filerevlog.group(nodeiter, lookup): |
|
1622 | for chnk in filerevlog.group(nodeiter, lookup): | |
1623 | self.ui.progress( |
|
1623 | self.ui.progress( | |
1624 | _('bundling files'), cnt, item=fname, unit=_('chunks')) |
|
1624 | _('bundling files'), cnt, item=fname, unit=_('chunks')) | |
1625 | cnt += 1 |
|
1625 | cnt += 1 | |
1626 | yield chnk |
|
1626 | yield chnk | |
1627 | self.ui.progress(_('bundling files'), None) |
|
1627 | self.ui.progress(_('bundling files'), None) | |
1628 |
|
1628 | |||
1629 | yield changegroup.closechunk() |
|
1629 | yield changegroup.closechunk() | |
1630 |
|
1630 | |||
1631 | if nodes: |
|
1631 | if nodes: | |
1632 | self.hook('outgoing', node=hex(nodes[0]), source=source) |
|
1632 | self.hook('outgoing', node=hex(nodes[0]), source=source) | |
1633 |
|
1633 | |||
1634 | return changegroup.unbundle10(util.chunkbuffer(gengroup()), 'UN') |
|
1634 | return changegroup.unbundle10(util.chunkbuffer(gengroup()), 'UN') | |
1635 |
|
1635 | |||
1636 | def addchangegroup(self, source, srctype, url, emptyok=False, lock=None): |
|
1636 | def addchangegroup(self, source, srctype, url, emptyok=False, lock=None): | |
1637 | """Add the changegroup returned by source.read() to this repo. |
|
1637 | """Add the changegroup returned by source.read() to this repo. | |
1638 | srctype is a string like 'push', 'pull', or 'unbundle'. url is |
|
1638 | srctype is a string like 'push', 'pull', or 'unbundle'. url is | |
1639 | the URL of the repo where this changegroup is coming from. |
|
1639 | the URL of the repo where this changegroup is coming from. | |
1640 |
|
1640 | |||
1641 | Return an integer summarizing the change to this repo: |
|
1641 | Return an integer summarizing the change to this repo: | |
1642 | - nothing changed or no source: 0 |
|
1642 | - nothing changed or no source: 0 | |
1643 | - more heads than before: 1+added heads (2..n) |
|
1643 | - more heads than before: 1+added heads (2..n) | |
1644 | - fewer heads than before: -1-removed heads (-2..-n) |
|
1644 | - fewer heads than before: -1-removed heads (-2..-n) | |
1645 | - number of heads stays the same: 1 |
|
1645 | - number of heads stays the same: 1 | |
1646 | """ |
|
1646 | """ | |
1647 | def csmap(x): |
|
1647 | def csmap(x): | |
1648 | self.ui.debug("add changeset %s\n" % short(x)) |
|
1648 | self.ui.debug("add changeset %s\n" % short(x)) | |
1649 | return len(cl) |
|
1649 | return len(cl) | |
1650 |
|
1650 | |||
1651 | def revmap(x): |
|
1651 | def revmap(x): | |
1652 | return cl.rev(x) |
|
1652 | return cl.rev(x) | |
1653 |
|
1653 | |||
1654 | if not source: |
|
1654 | if not source: | |
1655 | return 0 |
|
1655 | return 0 | |
1656 |
|
1656 | |||
1657 | self.hook('prechangegroup', throw=True, source=srctype, url=url) |
|
1657 | self.hook('prechangegroup', throw=True, source=srctype, url=url) | |
1658 |
|
1658 | |||
1659 | changesets = files = revisions = 0 |
|
1659 | changesets = files = revisions = 0 | |
1660 | efiles = set() |
|
1660 | efiles = set() | |
1661 |
|
1661 | |||
1662 | # write changelog data to temp files so concurrent readers will not see |
|
1662 | # write changelog data to temp files so concurrent readers will not see | |
1663 | # inconsistent view |
|
1663 | # inconsistent view | |
1664 | cl = self.changelog |
|
1664 | cl = self.changelog | |
1665 | cl.delayupdate() |
|
1665 | cl.delayupdate() | |
1666 | oldheads = len(cl.heads()) |
|
1666 | oldheads = len(cl.heads()) | |
1667 |
|
1667 | |||
1668 | tr = self.transaction("\n".join([srctype, urlmod.hidepassword(url)])) |
|
1668 | tr = self.transaction("\n".join([srctype, urlmod.hidepassword(url)])) | |
1669 | try: |
|
1669 | try: | |
1670 | trp = weakref.proxy(tr) |
|
1670 | trp = weakref.proxy(tr) | |
1671 | # pull off the changeset group |
|
1671 | # pull off the changeset group | |
1672 | self.ui.status(_("adding changesets\n")) |
|
1672 | self.ui.status(_("adding changesets\n")) | |
1673 | clstart = len(cl) |
|
1673 | clstart = len(cl) | |
1674 | class prog(object): |
|
1674 | class prog(object): | |
1675 | step = _('changesets') |
|
1675 | step = _('changesets') | |
1676 | count = 1 |
|
1676 | count = 1 | |
1677 | ui = self.ui |
|
1677 | ui = self.ui | |
1678 | total = None |
|
1678 | total = None | |
1679 | def __call__(self): |
|
1679 | def __call__(self): | |
1680 | self.ui.progress(self.step, self.count, unit=_('chunks'), |
|
1680 | self.ui.progress(self.step, self.count, unit=_('chunks'), | |
1681 | total=self.total) |
|
1681 | total=self.total) | |
1682 | self.count += 1 |
|
1682 | self.count += 1 | |
1683 | pr = prog() |
|
1683 | pr = prog() | |
1684 | source.callback = pr |
|
1684 | source.callback = pr | |
1685 |
|
1685 | |||
1686 | if (cl.addgroup(source, csmap, trp) is None |
|
1686 | if (cl.addgroup(source, csmap, trp) is None | |
1687 | and not emptyok): |
|
1687 | and not emptyok): | |
1688 | raise util.Abort(_("received changelog group is empty")) |
|
1688 | raise util.Abort(_("received changelog group is empty")) | |
1689 | clend = len(cl) |
|
1689 | clend = len(cl) | |
1690 | changesets = clend - clstart |
|
1690 | changesets = clend - clstart | |
1691 | for c in xrange(clstart, clend): |
|
1691 | for c in xrange(clstart, clend): | |
1692 | efiles.update(self[c].files()) |
|
1692 | efiles.update(self[c].files()) | |
1693 | efiles = len(efiles) |
|
1693 | efiles = len(efiles) | |
1694 | self.ui.progress(_('changesets'), None) |
|
1694 | self.ui.progress(_('changesets'), None) | |
1695 |
|
1695 | |||
1696 | # pull off the manifest group |
|
1696 | # pull off the manifest group | |
1697 | self.ui.status(_("adding manifests\n")) |
|
1697 | self.ui.status(_("adding manifests\n")) | |
1698 | pr.step = _('manifests') |
|
1698 | pr.step = _('manifests') | |
1699 | pr.count = 1 |
|
1699 | pr.count = 1 | |
1700 | pr.total = changesets # manifests <= changesets |
|
1700 | pr.total = changesets # manifests <= changesets | |
1701 | # no need to check for empty manifest group here: |
|
1701 | # no need to check for empty manifest group here: | |
1702 | # if the result of the merge of 1 and 2 is the same in 3 and 4, |
|
1702 | # if the result of the merge of 1 and 2 is the same in 3 and 4, | |
1703 | # no new manifest will be created and the manifest group will |
|
1703 | # no new manifest will be created and the manifest group will | |
1704 | # be empty during the pull |
|
1704 | # be empty during the pull | |
1705 | self.manifest.addgroup(source, revmap, trp) |
|
1705 | self.manifest.addgroup(source, revmap, trp) | |
1706 | self.ui.progress(_('manifests'), None) |
|
1706 | self.ui.progress(_('manifests'), None) | |
1707 |
|
1707 | |||
1708 | needfiles = {} |
|
1708 | needfiles = {} | |
1709 | if self.ui.configbool('server', 'validate', default=False): |
|
1709 | if self.ui.configbool('server', 'validate', default=False): | |
1710 | # validate incoming csets have their manifests |
|
1710 | # validate incoming csets have their manifests | |
1711 | for cset in xrange(clstart, clend): |
|
1711 | for cset in xrange(clstart, clend): | |
1712 | mfest = self.changelog.read(self.changelog.node(cset))[0] |
|
1712 | mfest = self.changelog.read(self.changelog.node(cset))[0] | |
1713 | mfest = self.manifest.readdelta(mfest) |
|
1713 | mfest = self.manifest.readdelta(mfest) | |
1714 | # store file nodes we must see |
|
1714 | # store file nodes we must see | |
1715 | for f, n in mfest.iteritems(): |
|
1715 | for f, n in mfest.iteritems(): | |
1716 | needfiles.setdefault(f, set()).add(n) |
|
1716 | needfiles.setdefault(f, set()).add(n) | |
1717 |
|
1717 | |||
1718 | # process the files |
|
1718 | # process the files | |
1719 | self.ui.status(_("adding file changes\n")) |
|
1719 | self.ui.status(_("adding file changes\n")) | |
1720 | pr.step = 'files' |
|
1720 | pr.step = 'files' | |
1721 | pr.count = 1 |
|
1721 | pr.count = 1 | |
1722 | pr.total = efiles |
|
1722 | pr.total = efiles | |
1723 | source.callback = None |
|
1723 | source.callback = None | |
1724 |
|
1724 | |||
1725 | while 1: |
|
1725 | while 1: | |
1726 | f = source.chunk() |
|
1726 | f = source.chunk() | |
1727 | if not f: |
|
1727 | if not f: | |
1728 | break |
|
1728 | break | |
1729 | self.ui.debug("adding %s revisions\n" % f) |
|
1729 | self.ui.debug("adding %s revisions\n" % f) | |
1730 | pr() |
|
1730 | pr() | |
1731 | fl = self.file(f) |
|
1731 | fl = self.file(f) | |
1732 | o = len(fl) |
|
1732 | o = len(fl) | |
1733 | if fl.addgroup(source, revmap, trp) is None: |
|
1733 | if fl.addgroup(source, revmap, trp) is None: | |
1734 | raise util.Abort(_("received file revlog group is empty")) |
|
1734 | raise util.Abort(_("received file revlog group is empty")) | |
1735 | revisions += len(fl) - o |
|
1735 | revisions += len(fl) - o | |
1736 | files += 1 |
|
1736 | files += 1 | |
1737 | if f in needfiles: |
|
1737 | if f in needfiles: | |
1738 | needs = needfiles[f] |
|
1738 | needs = needfiles[f] | |
1739 | for new in xrange(o, len(fl)): |
|
1739 | for new in xrange(o, len(fl)): | |
1740 | n = fl.node(new) |
|
1740 | n = fl.node(new) | |
1741 | if n in needs: |
|
1741 | if n in needs: | |
1742 | needs.remove(n) |
|
1742 | needs.remove(n) | |
1743 | if not needs: |
|
1743 | if not needs: | |
1744 | del needfiles[f] |
|
1744 | del needfiles[f] | |
1745 | self.ui.progress(_('files'), None) |
|
1745 | self.ui.progress(_('files'), None) | |
1746 |
|
1746 | |||
1747 | for f, needs in needfiles.iteritems(): |
|
1747 | for f, needs in needfiles.iteritems(): | |
1748 | fl = self.file(f) |
|
1748 | fl = self.file(f) | |
1749 | for n in needs: |
|
1749 | for n in needs: | |
1750 | try: |
|
1750 | try: | |
1751 | fl.rev(n) |
|
1751 | fl.rev(n) | |
1752 | except error.LookupError: |
|
1752 | except error.LookupError: | |
1753 | raise util.Abort( |
|
1753 | raise util.Abort( | |
1754 | _('missing file data for %s:%s - run hg verify') % |
|
1754 | _('missing file data for %s:%s - run hg verify') % | |
1755 | (f, hex(n))) |
|
1755 | (f, hex(n))) | |
1756 |
|
1756 | |||
1757 | newheads = len(cl.heads()) |
|
1757 | newheads = len(cl.heads()) | |
1758 | heads = "" |
|
1758 | heads = "" | |
1759 | if oldheads and newheads != oldheads: |
|
1759 | if oldheads and newheads != oldheads: | |
1760 | heads = _(" (%+d heads)") % (newheads - oldheads) |
|
1760 | heads = _(" (%+d heads)") % (newheads - oldheads) | |
1761 |
|
1761 | |||
1762 | self.ui.status(_("added %d changesets" |
|
1762 | self.ui.status(_("added %d changesets" | |
1763 | " with %d changes to %d files%s\n") |
|
1763 | " with %d changes to %d files%s\n") | |
1764 | % (changesets, revisions, files, heads)) |
|
1764 | % (changesets, revisions, files, heads)) | |
1765 |
|
1765 | |||
1766 | if changesets > 0: |
|
1766 | if changesets > 0: | |
1767 | p = lambda: cl.writepending() and self.root or "" |
|
1767 | p = lambda: cl.writepending() and self.root or "" | |
1768 | self.hook('pretxnchangegroup', throw=True, |
|
1768 | self.hook('pretxnchangegroup', throw=True, | |
1769 | node=hex(cl.node(clstart)), source=srctype, |
|
1769 | node=hex(cl.node(clstart)), source=srctype, | |
1770 | url=url, pending=p) |
|
1770 | url=url, pending=p) | |
1771 |
|
1771 | |||
1772 | # make changelog see real files again |
|
1772 | # make changelog see real files again | |
1773 | cl.finalize(trp) |
|
1773 | cl.finalize(trp) | |
1774 |
|
1774 | |||
1775 | tr.close() |
|
1775 | tr.close() | |
1776 | finally: |
|
1776 | finally: | |
1777 | tr.release() |
|
1777 | tr.release() | |
1778 | if lock: |
|
1778 | if lock: | |
1779 | lock.release() |
|
1779 | lock.release() | |
1780 |
|
1780 | |||
1781 | if changesets > 0: |
|
1781 | if changesets > 0: | |
1782 | # forcefully update the on-disk branch cache |
|
1782 | # forcefully update the on-disk branch cache | |
1783 | self.ui.debug("updating the branch cache\n") |
|
1783 | self.ui.debug("updating the branch cache\n") | |
1784 | self.updatebranchcache() |
|
1784 | self.updatebranchcache() | |
1785 | self.hook("changegroup", node=hex(cl.node(clstart)), |
|
1785 | self.hook("changegroup", node=hex(cl.node(clstart)), | |
1786 | source=srctype, url=url) |
|
1786 | source=srctype, url=url) | |
1787 |
|
1787 | |||
1788 | for i in xrange(clstart, clend): |
|
1788 | for i in xrange(clstart, clend): | |
1789 | self.hook("incoming", node=hex(cl.node(i)), |
|
1789 | self.hook("incoming", node=hex(cl.node(i)), | |
1790 | source=srctype, url=url) |
|
1790 | source=srctype, url=url) | |
1791 |
|
1791 | |||
1792 | # never return 0 here: |
|
1792 | # never return 0 here: | |
1793 | if newheads < oldheads: |
|
1793 | if newheads < oldheads: | |
1794 | return newheads - oldheads - 1 |
|
1794 | return newheads - oldheads - 1 | |
1795 | else: |
|
1795 | else: | |
1796 | return newheads - oldheads + 1 |
|
1796 | return newheads - oldheads + 1 | |
1797 |
|
1797 | |||
1798 |
|
1798 | |||
1799 | def stream_in(self, remote, requirements): |
|
1799 | def stream_in(self, remote, requirements): | |
1800 | fp = remote.stream_out() |
|
1800 | fp = remote.stream_out() | |
1801 | l = fp.readline() |
|
1801 | l = fp.readline() | |
1802 | try: |
|
1802 | try: | |
1803 | resp = int(l) |
|
1803 | resp = int(l) | |
1804 | except ValueError: |
|
1804 | except ValueError: | |
1805 | raise error.ResponseError( |
|
1805 | raise error.ResponseError( | |
1806 | _('Unexpected response from remote server:'), l) |
|
1806 | _('Unexpected response from remote server:'), l) | |
1807 | if resp == 1: |
|
1807 | if resp == 1: | |
1808 | raise util.Abort(_('operation forbidden by server')) |
|
1808 | raise util.Abort(_('operation forbidden by server')) | |
1809 | elif resp == 2: |
|
1809 | elif resp == 2: | |
1810 | raise util.Abort(_('locking the remote repository failed')) |
|
1810 | raise util.Abort(_('locking the remote repository failed')) | |
1811 | elif resp != 0: |
|
1811 | elif resp != 0: | |
1812 | raise util.Abort(_('the server sent an unknown error code')) |
|
1812 | raise util.Abort(_('the server sent an unknown error code')) | |
1813 | self.ui.status(_('streaming all changes\n')) |
|
1813 | self.ui.status(_('streaming all changes\n')) | |
1814 | l = fp.readline() |
|
1814 | l = fp.readline() | |
1815 | try: |
|
1815 | try: | |
1816 | total_files, total_bytes = map(int, l.split(' ', 1)) |
|
1816 | total_files, total_bytes = map(int, l.split(' ', 1)) | |
1817 | except (ValueError, TypeError): |
|
1817 | except (ValueError, TypeError): | |
1818 | raise error.ResponseError( |
|
1818 | raise error.ResponseError( | |
1819 | _('Unexpected response from remote server:'), l) |
|
1819 | _('Unexpected response from remote server:'), l) | |
1820 | self.ui.status(_('%d files to transfer, %s of data\n') % |
|
1820 | self.ui.status(_('%d files to transfer, %s of data\n') % | |
1821 | (total_files, util.bytecount(total_bytes))) |
|
1821 | (total_files, util.bytecount(total_bytes))) | |
1822 | start = time.time() |
|
1822 | start = time.time() | |
1823 | for i in xrange(total_files): |
|
1823 | for i in xrange(total_files): | |
1824 | # XXX doesn't support '\n' or '\r' in filenames |
|
1824 | # XXX doesn't support '\n' or '\r' in filenames | |
1825 | l = fp.readline() |
|
1825 | l = fp.readline() | |
1826 | try: |
|
1826 | try: | |
1827 | name, size = l.split('\0', 1) |
|
1827 | name, size = l.split('\0', 1) | |
1828 | size = int(size) |
|
1828 | size = int(size) | |
1829 | except (ValueError, TypeError): |
|
1829 | except (ValueError, TypeError): | |
1830 | raise error.ResponseError( |
|
1830 | raise error.ResponseError( | |
1831 | _('Unexpected response from remote server:'), l) |
|
1831 | _('Unexpected response from remote server:'), l) | |
1832 | self.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size))) |
|
1832 | self.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size))) | |
1833 | # for backwards compat, name was partially encoded |
|
1833 | # for backwards compat, name was partially encoded | |
1834 | ofp = self.sopener(store.decodedir(name), 'w') |
|
1834 | ofp = self.sopener(store.decodedir(name), 'w') | |
1835 | for chunk in util.filechunkiter(fp, limit=size): |
|
1835 | for chunk in util.filechunkiter(fp, limit=size): | |
1836 | ofp.write(chunk) |
|
1836 | ofp.write(chunk) | |
1837 | ofp.close() |
|
1837 | ofp.close() | |
1838 | elapsed = time.time() - start |
|
1838 | elapsed = time.time() - start | |
1839 | if elapsed <= 0: |
|
1839 | if elapsed <= 0: | |
1840 | elapsed = 0.001 |
|
1840 | elapsed = 0.001 | |
1841 | self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') % |
|
1841 | self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') % | |
1842 | (util.bytecount(total_bytes), elapsed, |
|
1842 | (util.bytecount(total_bytes), elapsed, | |
1843 | util.bytecount(total_bytes / elapsed))) |
|
1843 | util.bytecount(total_bytes / elapsed))) | |
1844 |
|
1844 | |||
1845 | # new requirements = old non-format requirements + new format-related |
|
1845 | # new requirements = old non-format requirements + new format-related | |
1846 | # requirements from the streamed-in repository |
|
1846 | # requirements from the streamed-in repository | |
1847 | requirements.update(set(self.requirements) - self.supportedformats) |
|
1847 | requirements.update(set(self.requirements) - self.supportedformats) | |
1848 | self._applyrequirements(requirements) |
|
1848 | self._applyrequirements(requirements) | |
1849 | self._writerequirements() |
|
1849 | self._writerequirements() | |
1850 |
|
1850 | |||
1851 | self.invalidate() |
|
1851 | self.invalidate() | |
1852 | return len(self.heads()) + 1 |
|
1852 | return len(self.heads()) + 1 | |
1853 |
|
1853 | |||
1854 | def clone(self, remote, heads=[], stream=False): |
|
1854 | def clone(self, remote, heads=[], stream=False): | |
1855 | '''clone remote repository. |
|
1855 | '''clone remote repository. | |
1856 |
|
1856 | |||
1857 | keyword arguments: |
|
1857 | keyword arguments: | |
1858 | heads: list of revs to clone (forces use of pull) |
|
1858 | heads: list of revs to clone (forces use of pull) | |
1859 | stream: use streaming clone if possible''' |
|
1859 | stream: use streaming clone if possible''' | |
1860 |
|
1860 | |||
1861 | # now, all clients that can request uncompressed clones can |
|
1861 | # now, all clients that can request uncompressed clones can | |
1862 | # read repo formats supported by all servers that can serve |
|
1862 | # read repo formats supported by all servers that can serve | |
1863 | # them. |
|
1863 | # them. | |
1864 |
|
1864 | |||
1865 | # if revlog format changes, client will have to check version |
|
1865 | # if revlog format changes, client will have to check version | |
1866 | # and format flags on "stream" capability, and use |
|
1866 | # and format flags on "stream" capability, and use | |
1867 | # uncompressed only if compatible. |
|
1867 | # uncompressed only if compatible. | |
1868 |
|
1868 | |||
1869 | if stream and not heads: |
|
1869 | if stream and not heads: | |
1870 | # 'stream' means remote revlog format is revlogv1 only |
|
1870 | # 'stream' means remote revlog format is revlogv1 only | |
1871 | if remote.capable('stream'): |
|
1871 | if remote.capable('stream'): | |
1872 | return self.stream_in(remote, set(('revlogv1',))) |
|
1872 | return self.stream_in(remote, set(('revlogv1',))) | |
1873 | # otherwise, 'streamreqs' contains the remote revlog format |
|
1873 | # otherwise, 'streamreqs' contains the remote revlog format | |
1874 | streamreqs = remote.capable('streamreqs') |
|
1874 | streamreqs = remote.capable('streamreqs') | |
1875 | if streamreqs: |
|
1875 | if streamreqs: | |
1876 | streamreqs = set(streamreqs.split(',')) |
|
1876 | streamreqs = set(streamreqs.split(',')) | |
1877 | # if we support it, stream in and adjust our requirements |
|
1877 | # if we support it, stream in and adjust our requirements | |
1878 | if not streamreqs - self.supportedformats: |
|
1878 | if not streamreqs - self.supportedformats: | |
1879 | return self.stream_in(remote, streamreqs) |
|
1879 | return self.stream_in(remote, streamreqs) | |
1880 | return self.pull(remote, heads) |
|
1880 | return self.pull(remote, heads) | |
1881 |
|
1881 | |||
1882 | def pushkey(self, namespace, key, old, new): |
|
1882 | def pushkey(self, namespace, key, old, new): | |
1883 | return pushkey.push(self, namespace, key, old, new) |
|
1883 | return pushkey.push(self, namespace, key, old, new) | |
1884 |
|
1884 | |||
1885 | def listkeys(self, namespace): |
|
1885 | def listkeys(self, namespace): | |
1886 | return pushkey.list(self, namespace) |
|
1886 | return pushkey.list(self, namespace) | |
1887 |
|
1887 | |||
1888 | # used to avoid circular references so destructors work |
|
1888 | # used to avoid circular references so destructors work | |
1889 | def aftertrans(files): |
|
1889 | def aftertrans(files): | |
1890 | renamefiles = [tuple(t) for t in files] |
|
1890 | renamefiles = [tuple(t) for t in files] | |
1891 | def a(): |
|
1891 | def a(): | |
1892 | for src, dest in renamefiles: |
|
1892 | for src, dest in renamefiles: | |
1893 | util.rename(src, dest) |
|
1893 | util.rename(src, dest) | |
1894 | return a |
|
1894 | return a | |
1895 |
|
1895 | |||
1896 | def instance(ui, path, create): |
|
1896 | def instance(ui, path, create): | |
1897 | return localrepository(ui, util.drop_scheme('file', path), create) |
|
1897 | return localrepository(ui, util.drop_scheme('file', path), create) | |
1898 |
|
1898 | |||
1899 | def islocal(path): |
|
1899 | def islocal(path): | |
1900 | return True |
|
1900 | return True |
General Comments 0
You need to be logged in to leave comments.
Login now