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