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