##// END OF EJS Templates
Revert almost all of 5be434785317; add a test...
Alexis S. L. Carvalho -
r3675:6990e499 default
parent child Browse files
Show More
@@ -0,0 +1,14 b''
1 #!/bin/sh
2
3 hg init dir
4 cd dir
5 echo bleh > bar
6 hg add bar
7 hg ci -m 'add bar'
8
9 hg cp bar foo
10 echo >> bar
11 hg ci -m 'cp bar foo; change bar'
12
13 hg debugrename foo
14 hg debugindex .hg/data/bar.i
@@ -0,0 +1,4 b''
1 foo renamed from bar:26d3ca0dfd18e44d796b564e38dd173c9668d3a9
2 rev offset length base linkrev nodeid p1 p2
3 0 0 6 0 0 26d3ca0dfd18 000000000000 000000000000
4 1 6 7 1 1 d267bddd54f7 26d3ca0dfd18 000000000000
@@ -1,1868 +1,1871 b''
1 # localrepo.py - read/write repository class for mercurial
1 # localrepo.py - read/write repository class for mercurial
2 #
2 #
3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms
5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, incorporated herein by reference.
7
7
8 from node import *
8 from node import *
9 from i18n import gettext as _
9 from i18n import gettext as _
10 from demandload import *
10 from demandload import *
11 import repo
11 import repo
12 demandload(globals(), "appendfile changegroup")
12 demandload(globals(), "appendfile changegroup")
13 demandload(globals(), "changelog dirstate filelog manifest context")
13 demandload(globals(), "changelog dirstate filelog manifest context")
14 demandload(globals(), "re lock transaction tempfile stat mdiff errno ui")
14 demandload(globals(), "re lock transaction tempfile stat mdiff errno ui")
15 demandload(globals(), "os revlog time util")
15 demandload(globals(), "os revlog time util")
16
16
17 class localrepository(repo.repository):
17 class localrepository(repo.repository):
18 capabilities = ('lookup', 'changegroupsubset')
18 capabilities = ('lookup', 'changegroupsubset')
19
19
20 def __del__(self):
20 def __del__(self):
21 self.transhandle = None
21 self.transhandle = None
22 def __init__(self, parentui, path=None, create=0):
22 def __init__(self, parentui, path=None, create=0):
23 repo.repository.__init__(self)
23 repo.repository.__init__(self)
24 if not path:
24 if not path:
25 p = os.getcwd()
25 p = os.getcwd()
26 while not os.path.isdir(os.path.join(p, ".hg")):
26 while not os.path.isdir(os.path.join(p, ".hg")):
27 oldp = p
27 oldp = p
28 p = os.path.dirname(p)
28 p = os.path.dirname(p)
29 if p == oldp:
29 if p == oldp:
30 raise repo.RepoError(_("There is no Mercurial repository"
30 raise repo.RepoError(_("There is no Mercurial repository"
31 " here (.hg not found)"))
31 " here (.hg not found)"))
32 path = p
32 path = p
33 self.path = os.path.join(path, ".hg")
33 self.path = os.path.join(path, ".hg")
34
34
35 if not os.path.isdir(self.path):
35 if not os.path.isdir(self.path):
36 if create:
36 if create:
37 if not os.path.exists(path):
37 if not os.path.exists(path):
38 os.mkdir(path)
38 os.mkdir(path)
39 os.mkdir(self.path)
39 os.mkdir(self.path)
40 os.mkdir(self.join("data"))
40 os.mkdir(self.join("data"))
41 else:
41 else:
42 raise repo.RepoError(_("repository %s not found") % path)
42 raise repo.RepoError(_("repository %s not found") % path)
43 elif create:
43 elif create:
44 raise repo.RepoError(_("repository %s already exists") % path)
44 raise repo.RepoError(_("repository %s already exists") % path)
45
45
46 self.root = os.path.realpath(path)
46 self.root = os.path.realpath(path)
47 self.origroot = path
47 self.origroot = path
48 self.ui = ui.ui(parentui=parentui)
48 self.ui = ui.ui(parentui=parentui)
49 self.opener = util.opener(self.path)
49 self.opener = util.opener(self.path)
50 self.sopener = util.opener(self.path)
50 self.sopener = util.opener(self.path)
51 self.wopener = util.opener(self.root)
51 self.wopener = util.opener(self.root)
52
52
53 try:
53 try:
54 self.ui.readconfig(self.join("hgrc"), self.root)
54 self.ui.readconfig(self.join("hgrc"), self.root)
55 except IOError:
55 except IOError:
56 pass
56 pass
57
57
58 v = self.ui.configrevlog()
58 v = self.ui.configrevlog()
59 self.revlogversion = int(v.get('format', revlog.REVLOG_DEFAULT_FORMAT))
59 self.revlogversion = int(v.get('format', revlog.REVLOG_DEFAULT_FORMAT))
60 self.revlogv1 = self.revlogversion != revlog.REVLOGV0
60 self.revlogv1 = self.revlogversion != revlog.REVLOGV0
61 fl = v.get('flags', None)
61 fl = v.get('flags', None)
62 flags = 0
62 flags = 0
63 if fl != None:
63 if fl != None:
64 for x in fl.split():
64 for x in fl.split():
65 flags |= revlog.flagstr(x)
65 flags |= revlog.flagstr(x)
66 elif self.revlogv1:
66 elif self.revlogv1:
67 flags = revlog.REVLOG_DEFAULT_FLAGS
67 flags = revlog.REVLOG_DEFAULT_FLAGS
68
68
69 v = self.revlogversion | flags
69 v = self.revlogversion | flags
70 self.manifest = manifest.manifest(self.sopener, v)
70 self.manifest = manifest.manifest(self.sopener, v)
71 self.changelog = changelog.changelog(self.sopener, v)
71 self.changelog = changelog.changelog(self.sopener, v)
72
72
73 # the changelog might not have the inline index flag
73 # the changelog might not have the inline index flag
74 # on. If the format of the changelog is the same as found in
74 # on. If the format of the changelog is the same as found in
75 # .hgrc, apply any flags found in the .hgrc as well.
75 # .hgrc, apply any flags found in the .hgrc as well.
76 # Otherwise, just version from the changelog
76 # Otherwise, just version from the changelog
77 v = self.changelog.version
77 v = self.changelog.version
78 if v == self.revlogversion:
78 if v == self.revlogversion:
79 v |= flags
79 v |= flags
80 self.revlogversion = v
80 self.revlogversion = v
81
81
82 self.tagscache = None
82 self.tagscache = None
83 self.branchcache = None
83 self.branchcache = None
84 self.nodetagscache = None
84 self.nodetagscache = None
85 self.encodepats = None
85 self.encodepats = None
86 self.decodepats = None
86 self.decodepats = None
87 self.transhandle = None
87 self.transhandle = None
88
88
89 self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root)
89 self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root)
90
90
91 def url(self):
91 def url(self):
92 return 'file:' + self.root
92 return 'file:' + self.root
93
93
94 def hook(self, name, throw=False, **args):
94 def hook(self, name, throw=False, **args):
95 def callhook(hname, funcname):
95 def callhook(hname, funcname):
96 '''call python hook. hook is callable object, looked up as
96 '''call python hook. hook is callable object, looked up as
97 name in python module. if callable returns "true", hook
97 name in python module. if callable returns "true", hook
98 fails, else passes. if hook raises exception, treated as
98 fails, else passes. if hook raises exception, treated as
99 hook failure. exception propagates if throw is "true".
99 hook failure. exception propagates if throw is "true".
100
100
101 reason for "true" meaning "hook failed" is so that
101 reason for "true" meaning "hook failed" is so that
102 unmodified commands (e.g. mercurial.commands.update) can
102 unmodified commands (e.g. mercurial.commands.update) can
103 be run as hooks without wrappers to convert return values.'''
103 be run as hooks without wrappers to convert return values.'''
104
104
105 self.ui.note(_("calling hook %s: %s\n") % (hname, funcname))
105 self.ui.note(_("calling hook %s: %s\n") % (hname, funcname))
106 d = funcname.rfind('.')
106 d = funcname.rfind('.')
107 if d == -1:
107 if d == -1:
108 raise util.Abort(_('%s hook is invalid ("%s" not in a module)')
108 raise util.Abort(_('%s hook is invalid ("%s" not in a module)')
109 % (hname, funcname))
109 % (hname, funcname))
110 modname = funcname[:d]
110 modname = funcname[:d]
111 try:
111 try:
112 obj = __import__(modname)
112 obj = __import__(modname)
113 except ImportError:
113 except ImportError:
114 try:
114 try:
115 # extensions are loaded with hgext_ prefix
115 # extensions are loaded with hgext_ prefix
116 obj = __import__("hgext_%s" % modname)
116 obj = __import__("hgext_%s" % modname)
117 except ImportError:
117 except ImportError:
118 raise util.Abort(_('%s hook is invalid '
118 raise util.Abort(_('%s hook is invalid '
119 '(import of "%s" failed)') %
119 '(import of "%s" failed)') %
120 (hname, modname))
120 (hname, modname))
121 try:
121 try:
122 for p in funcname.split('.')[1:]:
122 for p in funcname.split('.')[1:]:
123 obj = getattr(obj, p)
123 obj = getattr(obj, p)
124 except AttributeError, err:
124 except AttributeError, err:
125 raise util.Abort(_('%s hook is invalid '
125 raise util.Abort(_('%s hook is invalid '
126 '("%s" is not defined)') %
126 '("%s" is not defined)') %
127 (hname, funcname))
127 (hname, funcname))
128 if not callable(obj):
128 if not callable(obj):
129 raise util.Abort(_('%s hook is invalid '
129 raise util.Abort(_('%s hook is invalid '
130 '("%s" is not callable)') %
130 '("%s" is not callable)') %
131 (hname, funcname))
131 (hname, funcname))
132 try:
132 try:
133 r = obj(ui=self.ui, repo=self, hooktype=name, **args)
133 r = obj(ui=self.ui, repo=self, hooktype=name, **args)
134 except (KeyboardInterrupt, util.SignalInterrupt):
134 except (KeyboardInterrupt, util.SignalInterrupt):
135 raise
135 raise
136 except Exception, exc:
136 except Exception, exc:
137 if isinstance(exc, util.Abort):
137 if isinstance(exc, util.Abort):
138 self.ui.warn(_('error: %s hook failed: %s\n') %
138 self.ui.warn(_('error: %s hook failed: %s\n') %
139 (hname, exc.args[0]))
139 (hname, exc.args[0]))
140 else:
140 else:
141 self.ui.warn(_('error: %s hook raised an exception: '
141 self.ui.warn(_('error: %s hook raised an exception: '
142 '%s\n') % (hname, exc))
142 '%s\n') % (hname, exc))
143 if throw:
143 if throw:
144 raise
144 raise
145 self.ui.print_exc()
145 self.ui.print_exc()
146 return True
146 return True
147 if r:
147 if r:
148 if throw:
148 if throw:
149 raise util.Abort(_('%s hook failed') % hname)
149 raise util.Abort(_('%s hook failed') % hname)
150 self.ui.warn(_('warning: %s hook failed\n') % hname)
150 self.ui.warn(_('warning: %s hook failed\n') % hname)
151 return r
151 return r
152
152
153 def runhook(name, cmd):
153 def runhook(name, cmd):
154 self.ui.note(_("running hook %s: %s\n") % (name, cmd))
154 self.ui.note(_("running hook %s: %s\n") % (name, cmd))
155 env = dict([('HG_' + k.upper(), v) for k, v in args.iteritems()])
155 env = dict([('HG_' + k.upper(), v) for k, v in args.iteritems()])
156 r = util.system(cmd, environ=env, cwd=self.root)
156 r = util.system(cmd, environ=env, cwd=self.root)
157 if r:
157 if r:
158 desc, r = util.explain_exit(r)
158 desc, r = util.explain_exit(r)
159 if throw:
159 if throw:
160 raise util.Abort(_('%s hook %s') % (name, desc))
160 raise util.Abort(_('%s hook %s') % (name, desc))
161 self.ui.warn(_('warning: %s hook %s\n') % (name, desc))
161 self.ui.warn(_('warning: %s hook %s\n') % (name, desc))
162 return r
162 return r
163
163
164 r = False
164 r = False
165 hooks = [(hname, cmd) for hname, cmd in self.ui.configitems("hooks")
165 hooks = [(hname, cmd) for hname, cmd in self.ui.configitems("hooks")
166 if hname.split(".", 1)[0] == name and cmd]
166 if hname.split(".", 1)[0] == name and cmd]
167 hooks.sort()
167 hooks.sort()
168 for hname, cmd in hooks:
168 for hname, cmd in hooks:
169 if cmd.startswith('python:'):
169 if cmd.startswith('python:'):
170 r = callhook(hname, cmd[7:].strip()) or r
170 r = callhook(hname, cmd[7:].strip()) or r
171 else:
171 else:
172 r = runhook(hname, cmd) or r
172 r = runhook(hname, cmd) or r
173 return r
173 return r
174
174
175 tag_disallowed = ':\r\n'
175 tag_disallowed = ':\r\n'
176
176
177 def tag(self, name, node, message, local, user, date):
177 def tag(self, name, node, message, local, user, date):
178 '''tag a revision with a symbolic name.
178 '''tag a revision with a symbolic name.
179
179
180 if local is True, the tag is stored in a per-repository file.
180 if local is True, the tag is stored in a per-repository file.
181 otherwise, it is stored in the .hgtags file, and a new
181 otherwise, it is stored in the .hgtags file, and a new
182 changeset is committed with the change.
182 changeset is committed with the change.
183
183
184 keyword arguments:
184 keyword arguments:
185
185
186 local: whether to store tag in non-version-controlled file
186 local: whether to store tag in non-version-controlled file
187 (default False)
187 (default False)
188
188
189 message: commit message to use if committing
189 message: commit message to use if committing
190
190
191 user: name of user to use if committing
191 user: name of user to use if committing
192
192
193 date: date tuple to use if committing'''
193 date: date tuple to use if committing'''
194
194
195 for c in self.tag_disallowed:
195 for c in self.tag_disallowed:
196 if c in name:
196 if c in name:
197 raise util.Abort(_('%r cannot be used in a tag name') % c)
197 raise util.Abort(_('%r cannot be used in a tag name') % c)
198
198
199 self.hook('pretag', throw=True, node=hex(node), tag=name, local=local)
199 self.hook('pretag', throw=True, node=hex(node), tag=name, local=local)
200
200
201 if local:
201 if local:
202 self.opener('localtags', 'a').write('%s %s\n' % (hex(node), name))
202 self.opener('localtags', 'a').write('%s %s\n' % (hex(node), name))
203 self.hook('tag', node=hex(node), tag=name, local=local)
203 self.hook('tag', node=hex(node), tag=name, local=local)
204 return
204 return
205
205
206 for x in self.status()[:5]:
206 for x in self.status()[:5]:
207 if '.hgtags' in x:
207 if '.hgtags' in x:
208 raise util.Abort(_('working copy of .hgtags is changed '
208 raise util.Abort(_('working copy of .hgtags is changed '
209 '(please commit .hgtags manually)'))
209 '(please commit .hgtags manually)'))
210
210
211 self.wfile('.hgtags', 'ab').write('%s %s\n' % (hex(node), name))
211 self.wfile('.hgtags', 'ab').write('%s %s\n' % (hex(node), name))
212 if self.dirstate.state('.hgtags') == '?':
212 if self.dirstate.state('.hgtags') == '?':
213 self.add(['.hgtags'])
213 self.add(['.hgtags'])
214
214
215 self.commit(['.hgtags'], message, user, date)
215 self.commit(['.hgtags'], message, user, date)
216 self.hook('tag', node=hex(node), tag=name, local=local)
216 self.hook('tag', node=hex(node), tag=name, local=local)
217
217
218 def tags(self):
218 def tags(self):
219 '''return a mapping of tag to node'''
219 '''return a mapping of tag to node'''
220 if not self.tagscache:
220 if not self.tagscache:
221 self.tagscache = {}
221 self.tagscache = {}
222
222
223 def parsetag(line, context):
223 def parsetag(line, context):
224 if not line:
224 if not line:
225 return
225 return
226 s = l.split(" ", 1)
226 s = l.split(" ", 1)
227 if len(s) != 2:
227 if len(s) != 2:
228 self.ui.warn(_("%s: cannot parse entry\n") % context)
228 self.ui.warn(_("%s: cannot parse entry\n") % context)
229 return
229 return
230 node, key = s
230 node, key = s
231 key = key.strip()
231 key = key.strip()
232 try:
232 try:
233 bin_n = bin(node)
233 bin_n = bin(node)
234 except TypeError:
234 except TypeError:
235 self.ui.warn(_("%s: node '%s' is not well formed\n") %
235 self.ui.warn(_("%s: node '%s' is not well formed\n") %
236 (context, node))
236 (context, node))
237 return
237 return
238 if bin_n not in self.changelog.nodemap:
238 if bin_n not in self.changelog.nodemap:
239 self.ui.warn(_("%s: tag '%s' refers to unknown node\n") %
239 self.ui.warn(_("%s: tag '%s' refers to unknown node\n") %
240 (context, key))
240 (context, key))
241 return
241 return
242 self.tagscache[key] = bin_n
242 self.tagscache[key] = bin_n
243
243
244 # read the tags file from each head, ending with the tip,
244 # read the tags file from each head, ending with the tip,
245 # and add each tag found to the map, with "newer" ones
245 # and add each tag found to the map, with "newer" ones
246 # taking precedence
246 # taking precedence
247 f = None
247 f = None
248 for rev, node, fnode in self._hgtagsnodes():
248 for rev, node, fnode in self._hgtagsnodes():
249 f = (f and f.filectx(fnode) or
249 f = (f and f.filectx(fnode) or
250 self.filectx('.hgtags', fileid=fnode))
250 self.filectx('.hgtags', fileid=fnode))
251 count = 0
251 count = 0
252 for l in f.data().splitlines():
252 for l in f.data().splitlines():
253 count += 1
253 count += 1
254 parsetag(l, _("%s, line %d") % (str(f), count))
254 parsetag(l, _("%s, line %d") % (str(f), count))
255
255
256 try:
256 try:
257 f = self.opener("localtags")
257 f = self.opener("localtags")
258 count = 0
258 count = 0
259 for l in f:
259 for l in f:
260 count += 1
260 count += 1
261 parsetag(l, _("localtags, line %d") % count)
261 parsetag(l, _("localtags, line %d") % count)
262 except IOError:
262 except IOError:
263 pass
263 pass
264
264
265 self.tagscache['tip'] = self.changelog.tip()
265 self.tagscache['tip'] = self.changelog.tip()
266
266
267 return self.tagscache
267 return self.tagscache
268
268
269 def _hgtagsnodes(self):
269 def _hgtagsnodes(self):
270 heads = self.heads()
270 heads = self.heads()
271 heads.reverse()
271 heads.reverse()
272 last = {}
272 last = {}
273 ret = []
273 ret = []
274 for node in heads:
274 for node in heads:
275 c = self.changectx(node)
275 c = self.changectx(node)
276 rev = c.rev()
276 rev = c.rev()
277 try:
277 try:
278 fnode = c.filenode('.hgtags')
278 fnode = c.filenode('.hgtags')
279 except repo.LookupError:
279 except repo.LookupError:
280 continue
280 continue
281 ret.append((rev, node, fnode))
281 ret.append((rev, node, fnode))
282 if fnode in last:
282 if fnode in last:
283 ret[last[fnode]] = None
283 ret[last[fnode]] = None
284 last[fnode] = len(ret) - 1
284 last[fnode] = len(ret) - 1
285 return [item for item in ret if item]
285 return [item for item in ret if item]
286
286
287 def tagslist(self):
287 def tagslist(self):
288 '''return a list of tags ordered by revision'''
288 '''return a list of tags ordered by revision'''
289 l = []
289 l = []
290 for t, n in self.tags().items():
290 for t, n in self.tags().items():
291 try:
291 try:
292 r = self.changelog.rev(n)
292 r = self.changelog.rev(n)
293 except:
293 except:
294 r = -2 # sort to the beginning of the list if unknown
294 r = -2 # sort to the beginning of the list if unknown
295 l.append((r, t, n))
295 l.append((r, t, n))
296 l.sort()
296 l.sort()
297 return [(t, n) for r, t, n in l]
297 return [(t, n) for r, t, n in l]
298
298
299 def nodetags(self, node):
299 def nodetags(self, node):
300 '''return the tags associated with a node'''
300 '''return the tags associated with a node'''
301 if not self.nodetagscache:
301 if not self.nodetagscache:
302 self.nodetagscache = {}
302 self.nodetagscache = {}
303 for t, n in self.tags().items():
303 for t, n in self.tags().items():
304 self.nodetagscache.setdefault(n, []).append(t)
304 self.nodetagscache.setdefault(n, []).append(t)
305 return self.nodetagscache.get(node, [])
305 return self.nodetagscache.get(node, [])
306
306
307 def branchtags(self):
307 def branchtags(self):
308 if self.branchcache != None:
308 if self.branchcache != None:
309 return self.branchcache
309 return self.branchcache
310
310
311 self.branchcache = {} # avoid recursion in changectx
311 self.branchcache = {} # avoid recursion in changectx
312
312
313 partial, last, lrev = self._readbranchcache()
313 partial, last, lrev = self._readbranchcache()
314
314
315 tiprev = self.changelog.count() - 1
315 tiprev = self.changelog.count() - 1
316 if lrev != tiprev:
316 if lrev != tiprev:
317 self._updatebranchcache(partial, lrev+1, tiprev+1)
317 self._updatebranchcache(partial, lrev+1, tiprev+1)
318 self._writebranchcache(partial, self.changelog.tip(), tiprev)
318 self._writebranchcache(partial, self.changelog.tip(), tiprev)
319
319
320 self.branchcache = partial
320 self.branchcache = partial
321 return self.branchcache
321 return self.branchcache
322
322
323 def _readbranchcache(self):
323 def _readbranchcache(self):
324 partial = {}
324 partial = {}
325 try:
325 try:
326 f = self.opener("branches.cache")
326 f = self.opener("branches.cache")
327 lines = f.read().split('\n')
327 lines = f.read().split('\n')
328 f.close()
328 f.close()
329 last, lrev = lines.pop(0).rstrip().split(" ", 1)
329 last, lrev = lines.pop(0).rstrip().split(" ", 1)
330 last, lrev = bin(last), int(lrev)
330 last, lrev = bin(last), int(lrev)
331 if (lrev < self.changelog.count() and
331 if (lrev < self.changelog.count() and
332 self.changelog.node(lrev) == last): # sanity check
332 self.changelog.node(lrev) == last): # sanity check
333 for l in lines:
333 for l in lines:
334 if not l: continue
334 if not l: continue
335 node, label = l.rstrip().split(" ", 1)
335 node, label = l.rstrip().split(" ", 1)
336 partial[label] = bin(node)
336 partial[label] = bin(node)
337 else: # invalidate the cache
337 else: # invalidate the cache
338 last, lrev = nullid, nullrev
338 last, lrev = nullid, nullrev
339 except IOError:
339 except IOError:
340 last, lrev = nullid, nullrev
340 last, lrev = nullid, nullrev
341 return partial, last, lrev
341 return partial, last, lrev
342
342
343 def _writebranchcache(self, branches, tip, tiprev):
343 def _writebranchcache(self, branches, tip, tiprev):
344 try:
344 try:
345 f = self.opener("branches.cache", "w")
345 f = self.opener("branches.cache", "w")
346 f.write("%s %s\n" % (hex(tip), tiprev))
346 f.write("%s %s\n" % (hex(tip), tiprev))
347 for label, node in branches.iteritems():
347 for label, node in branches.iteritems():
348 f.write("%s %s\n" % (hex(node), label))
348 f.write("%s %s\n" % (hex(node), label))
349 except IOError:
349 except IOError:
350 pass
350 pass
351
351
352 def _updatebranchcache(self, partial, start, end):
352 def _updatebranchcache(self, partial, start, end):
353 for r in xrange(start, end):
353 for r in xrange(start, end):
354 c = self.changectx(r)
354 c = self.changectx(r)
355 b = c.branch()
355 b = c.branch()
356 if b:
356 if b:
357 partial[b] = c.node()
357 partial[b] = c.node()
358
358
359 def lookup(self, key):
359 def lookup(self, key):
360 if key == '.':
360 if key == '.':
361 key = self.dirstate.parents()[0]
361 key = self.dirstate.parents()[0]
362 if key == nullid:
362 if key == nullid:
363 raise repo.RepoError(_("no revision checked out"))
363 raise repo.RepoError(_("no revision checked out"))
364 n = self.changelog._match(key)
364 n = self.changelog._match(key)
365 if n:
365 if n:
366 return n
366 return n
367 if key in self.tags():
367 if key in self.tags():
368 return self.tags()[key]
368 return self.tags()[key]
369 if key in self.branchtags():
369 if key in self.branchtags():
370 return self.branchtags()[key]
370 return self.branchtags()[key]
371 n = self.changelog._partialmatch(key)
371 n = self.changelog._partialmatch(key)
372 if n:
372 if n:
373 return n
373 return n
374 raise repo.RepoError(_("unknown revision '%s'") % key)
374 raise repo.RepoError(_("unknown revision '%s'") % key)
375
375
376 def dev(self):
376 def dev(self):
377 return os.lstat(self.path).st_dev
377 return os.lstat(self.path).st_dev
378
378
379 def local(self):
379 def local(self):
380 return True
380 return True
381
381
382 def join(self, f):
382 def join(self, f):
383 return os.path.join(self.path, f)
383 return os.path.join(self.path, f)
384
384
385 def sjoin(self, f):
385 def sjoin(self, f):
386 return os.path.join(self.path, f)
386 return os.path.join(self.path, f)
387
387
388 def wjoin(self, f):
388 def wjoin(self, f):
389 return os.path.join(self.root, f)
389 return os.path.join(self.root, f)
390
390
391 def file(self, f):
391 def file(self, f):
392 if f[0] == '/':
392 if f[0] == '/':
393 f = f[1:]
393 f = f[1:]
394 return filelog.filelog(self.sopener, f, self.revlogversion)
394 return filelog.filelog(self.sopener, f, self.revlogversion)
395
395
396 def changectx(self, changeid=None):
396 def changectx(self, changeid=None):
397 return context.changectx(self, changeid)
397 return context.changectx(self, changeid)
398
398
399 def workingctx(self):
399 def workingctx(self):
400 return context.workingctx(self)
400 return context.workingctx(self)
401
401
402 def parents(self, changeid=None):
402 def parents(self, changeid=None):
403 '''
403 '''
404 get list of changectxs for parents of changeid or working directory
404 get list of changectxs for parents of changeid or working directory
405 '''
405 '''
406 if changeid is None:
406 if changeid is None:
407 pl = self.dirstate.parents()
407 pl = self.dirstate.parents()
408 else:
408 else:
409 n = self.changelog.lookup(changeid)
409 n = self.changelog.lookup(changeid)
410 pl = self.changelog.parents(n)
410 pl = self.changelog.parents(n)
411 if pl[1] == nullid:
411 if pl[1] == nullid:
412 return [self.changectx(pl[0])]
412 return [self.changectx(pl[0])]
413 return [self.changectx(pl[0]), self.changectx(pl[1])]
413 return [self.changectx(pl[0]), self.changectx(pl[1])]
414
414
415 def filectx(self, path, changeid=None, fileid=None):
415 def filectx(self, path, changeid=None, fileid=None):
416 """changeid can be a changeset revision, node, or tag.
416 """changeid can be a changeset revision, node, or tag.
417 fileid can be a file revision or node."""
417 fileid can be a file revision or node."""
418 return context.filectx(self, path, changeid, fileid)
418 return context.filectx(self, path, changeid, fileid)
419
419
420 def getcwd(self):
420 def getcwd(self):
421 return self.dirstate.getcwd()
421 return self.dirstate.getcwd()
422
422
423 def wfile(self, f, mode='r'):
423 def wfile(self, f, mode='r'):
424 return self.wopener(f, mode)
424 return self.wopener(f, mode)
425
425
426 def wread(self, filename):
426 def wread(self, filename):
427 if self.encodepats == None:
427 if self.encodepats == None:
428 l = []
428 l = []
429 for pat, cmd in self.ui.configitems("encode"):
429 for pat, cmd in self.ui.configitems("encode"):
430 mf = util.matcher(self.root, "", [pat], [], [])[1]
430 mf = util.matcher(self.root, "", [pat], [], [])[1]
431 l.append((mf, cmd))
431 l.append((mf, cmd))
432 self.encodepats = l
432 self.encodepats = l
433
433
434 data = self.wopener(filename, 'r').read()
434 data = self.wopener(filename, 'r').read()
435
435
436 for mf, cmd in self.encodepats:
436 for mf, cmd in self.encodepats:
437 if mf(filename):
437 if mf(filename):
438 self.ui.debug(_("filtering %s through %s\n") % (filename, cmd))
438 self.ui.debug(_("filtering %s through %s\n") % (filename, cmd))
439 data = util.filter(data, cmd)
439 data = util.filter(data, cmd)
440 break
440 break
441
441
442 return data
442 return data
443
443
444 def wwrite(self, filename, data, fd=None):
444 def wwrite(self, filename, data, fd=None):
445 if self.decodepats == None:
445 if self.decodepats == None:
446 l = []
446 l = []
447 for pat, cmd in self.ui.configitems("decode"):
447 for pat, cmd in self.ui.configitems("decode"):
448 mf = util.matcher(self.root, "", [pat], [], [])[1]
448 mf = util.matcher(self.root, "", [pat], [], [])[1]
449 l.append((mf, cmd))
449 l.append((mf, cmd))
450 self.decodepats = l
450 self.decodepats = l
451
451
452 for mf, cmd in self.decodepats:
452 for mf, cmd in self.decodepats:
453 if mf(filename):
453 if mf(filename):
454 self.ui.debug(_("filtering %s through %s\n") % (filename, cmd))
454 self.ui.debug(_("filtering %s through %s\n") % (filename, cmd))
455 data = util.filter(data, cmd)
455 data = util.filter(data, cmd)
456 break
456 break
457
457
458 if fd:
458 if fd:
459 return fd.write(data)
459 return fd.write(data)
460 return self.wopener(filename, 'w').write(data)
460 return self.wopener(filename, 'w').write(data)
461
461
462 def transaction(self):
462 def transaction(self):
463 tr = self.transhandle
463 tr = self.transhandle
464 if tr != None and tr.running():
464 if tr != None and tr.running():
465 return tr.nest()
465 return tr.nest()
466
466
467 # save dirstate for rollback
467 # save dirstate for rollback
468 try:
468 try:
469 ds = self.opener("dirstate").read()
469 ds = self.opener("dirstate").read()
470 except IOError:
470 except IOError:
471 ds = ""
471 ds = ""
472 self.opener("journal.dirstate", "w").write(ds)
472 self.opener("journal.dirstate", "w").write(ds)
473
473
474 tr = transaction.transaction(self.ui.warn, self.sopener,
474 tr = transaction.transaction(self.ui.warn, self.sopener,
475 self.sjoin("journal"),
475 self.sjoin("journal"),
476 aftertrans(self.path))
476 aftertrans(self.path))
477 self.transhandle = tr
477 self.transhandle = tr
478 return tr
478 return tr
479
479
480 def recover(self):
480 def recover(self):
481 l = self.lock()
481 l = self.lock()
482 if os.path.exists(self.sjoin("journal")):
482 if os.path.exists(self.sjoin("journal")):
483 self.ui.status(_("rolling back interrupted transaction\n"))
483 self.ui.status(_("rolling back interrupted transaction\n"))
484 transaction.rollback(self.sopener, self.sjoin("journal"))
484 transaction.rollback(self.sopener, self.sjoin("journal"))
485 self.reload()
485 self.reload()
486 return True
486 return True
487 else:
487 else:
488 self.ui.warn(_("no interrupted transaction available\n"))
488 self.ui.warn(_("no interrupted transaction available\n"))
489 return False
489 return False
490
490
491 def rollback(self, wlock=None):
491 def rollback(self, wlock=None):
492 if not wlock:
492 if not wlock:
493 wlock = self.wlock()
493 wlock = self.wlock()
494 l = self.lock()
494 l = self.lock()
495 if os.path.exists(self.sjoin("undo")):
495 if os.path.exists(self.sjoin("undo")):
496 self.ui.status(_("rolling back last transaction\n"))
496 self.ui.status(_("rolling back last transaction\n"))
497 transaction.rollback(self.sopener, self.sjoin("undo"))
497 transaction.rollback(self.sopener, self.sjoin("undo"))
498 util.rename(self.join("undo.dirstate"), self.join("dirstate"))
498 util.rename(self.join("undo.dirstate"), self.join("dirstate"))
499 self.reload()
499 self.reload()
500 self.wreload()
500 self.wreload()
501 else:
501 else:
502 self.ui.warn(_("no rollback information available\n"))
502 self.ui.warn(_("no rollback information available\n"))
503
503
504 def wreload(self):
504 def wreload(self):
505 self.dirstate.read()
505 self.dirstate.read()
506
506
507 def reload(self):
507 def reload(self):
508 self.changelog.load()
508 self.changelog.load()
509 self.manifest.load()
509 self.manifest.load()
510 self.tagscache = None
510 self.tagscache = None
511 self.nodetagscache = None
511 self.nodetagscache = None
512
512
513 def do_lock(self, lockname, wait, releasefn=None, acquirefn=None,
513 def do_lock(self, lockname, wait, releasefn=None, acquirefn=None,
514 desc=None):
514 desc=None):
515 try:
515 try:
516 l = lock.lock(lockname, 0, releasefn, desc=desc)
516 l = lock.lock(lockname, 0, releasefn, desc=desc)
517 except lock.LockHeld, inst:
517 except lock.LockHeld, inst:
518 if not wait:
518 if not wait:
519 raise
519 raise
520 self.ui.warn(_("waiting for lock on %s held by %s\n") %
520 self.ui.warn(_("waiting for lock on %s held by %s\n") %
521 (desc, inst.args[0]))
521 (desc, inst.args[0]))
522 # default to 600 seconds timeout
522 # default to 600 seconds timeout
523 l = lock.lock(lockname, int(self.ui.config("ui", "timeout", "600")),
523 l = lock.lock(lockname, int(self.ui.config("ui", "timeout", "600")),
524 releasefn, desc=desc)
524 releasefn, desc=desc)
525 if acquirefn:
525 if acquirefn:
526 acquirefn()
526 acquirefn()
527 return l
527 return l
528
528
529 def lock(self, wait=1):
529 def lock(self, wait=1):
530 return self.do_lock(self.sjoin("lock"), wait, acquirefn=self.reload,
530 return self.do_lock(self.sjoin("lock"), wait, acquirefn=self.reload,
531 desc=_('repository %s') % self.origroot)
531 desc=_('repository %s') % self.origroot)
532
532
533 def wlock(self, wait=1):
533 def wlock(self, wait=1):
534 return self.do_lock(self.join("wlock"), wait, self.dirstate.write,
534 return self.do_lock(self.join("wlock"), wait, self.dirstate.write,
535 self.wreload,
535 self.wreload,
536 desc=_('working directory of %s') % self.origroot)
536 desc=_('working directory of %s') % self.origroot)
537
537
538 def filecommit(self, fn, manifest1, manifest2, linkrev, transaction, changelist):
538 def filecommit(self, fn, manifest1, manifest2, linkrev, transaction, changelist):
539 """
539 """
540 commit an individual file as part of a larger transaction
540 commit an individual file as part of a larger transaction
541 """
541 """
542
542
543 t = self.wread(fn)
543 t = self.wread(fn)
544 fl = self.file(fn)
544 fl = self.file(fn)
545 fp1 = manifest1.get(fn, nullid)
545 fp1 = manifest1.get(fn, nullid)
546 fp2 = manifest2.get(fn, nullid)
546 fp2 = manifest2.get(fn, nullid)
547
547
548 meta = {}
548 meta = {}
549 cp = self.dirstate.copied(fn)
549 cp = self.dirstate.copied(fn)
550 if cp:
550 if cp:
551 meta["copy"] = cp
551 meta["copy"] = cp
552 if not manifest2: # not a branch merge
552 if not manifest2: # not a branch merge
553 meta["copyrev"] = hex(manifest1.get(cp, nullid))
553 meta["copyrev"] = hex(manifest1.get(cp, nullid))
554 fp2 = nullid
554 fp2 = nullid
555 elif fp2 != nullid: # copied on remote side
555 elif fp2 != nullid: # copied on remote side
556 meta["copyrev"] = hex(manifest1.get(cp, nullid))
556 meta["copyrev"] = hex(manifest1.get(cp, nullid))
557 else: # copied on local side, reversed
557 else: # copied on local side, reversed
558 meta["copyrev"] = hex(manifest2.get(cp))
558 meta["copyrev"] = hex(manifest2.get(cp))
559 fp2 = nullid
559 fp2 = nullid
560 self.ui.debug(_(" %s: copy %s:%s\n") %
560 self.ui.debug(_(" %s: copy %s:%s\n") %
561 (fn, cp, meta["copyrev"]))
561 (fn, cp, meta["copyrev"]))
562 fp1 = nullid
562 fp1 = nullid
563 elif fp2 != nullid:
563 elif fp2 != nullid:
564 # is one parent an ancestor of the other?
564 # is one parent an ancestor of the other?
565 fpa = fl.ancestor(fp1, fp2)
565 fpa = fl.ancestor(fp1, fp2)
566 if fpa == fp1:
566 if fpa == fp1:
567 fp1, fp2 = fp2, nullid
567 fp1, fp2 = fp2, nullid
568 elif fpa == fp2:
568 elif fpa == fp2:
569 fp2 = nullid
569 fp2 = nullid
570
570
571 # is the file unmodified from the parent? report existing entry
571 # is the file unmodified from the parent? report existing entry
572 if fp2 == nullid and not fl.cmp(fp1, t):
572 if fp2 == nullid and not fl.cmp(fp1, t):
573 return fp1
573 return fp1
574
574
575 changelist.append(fn)
575 changelist.append(fn)
576 return fl.add(t, meta, transaction, linkrev, fp1, fp2)
576 return fl.add(t, meta, transaction, linkrev, fp1, fp2)
577
577
578 def rawcommit(self, files, text, user, date, p1=None, p2=None, wlock=None):
578 def rawcommit(self, files, text, user, date, p1=None, p2=None, wlock=None):
579 if p1 is None:
579 if p1 is None:
580 p1, p2 = self.dirstate.parents()
580 p1, p2 = self.dirstate.parents()
581 return self.commit(files=files, text=text, user=user, date=date,
581 return self.commit(files=files, text=text, user=user, date=date,
582 p1=p1, p2=p2, wlock=wlock)
582 p1=p1, p2=p2, wlock=wlock)
583
583
584 def commit(self, files=None, text="", user=None, date=None,
584 def commit(self, files=None, text="", user=None, date=None,
585 match=util.always, force=False, lock=None, wlock=None,
585 match=util.always, force=False, lock=None, wlock=None,
586 force_editor=False, p1=None, p2=None, extra={}):
586 force_editor=False, p1=None, p2=None, extra={}):
587
587
588 commit = []
588 commit = []
589 remove = []
589 remove = []
590 changed = []
590 changed = []
591 use_dirstate = (p1 is None) # not rawcommit
591 use_dirstate = (p1 is None) # not rawcommit
592 extra = extra.copy()
592 extra = extra.copy()
593
593
594 if use_dirstate:
594 if use_dirstate:
595 if files:
595 if files:
596 for f in files:
596 for f in files:
597 s = self.dirstate.state(f)
597 s = self.dirstate.state(f)
598 if s in 'nmai':
598 if s in 'nmai':
599 commit.append(f)
599 commit.append(f)
600 elif s == 'r':
600 elif s == 'r':
601 remove.append(f)
601 remove.append(f)
602 else:
602 else:
603 self.ui.warn(_("%s not tracked!\n") % f)
603 self.ui.warn(_("%s not tracked!\n") % f)
604 else:
604 else:
605 changes = self.status(match=match)[:5]
605 changes = self.status(match=match)[:5]
606 modified, added, removed, deleted, unknown = changes
606 modified, added, removed, deleted, unknown = changes
607 commit = modified + added
607 commit = modified + added
608 remove = removed
608 remove = removed
609 else:
609 else:
610 commit = files
610 commit = files
611
611
612 if use_dirstate:
612 if use_dirstate:
613 p1, p2 = self.dirstate.parents()
613 p1, p2 = self.dirstate.parents()
614 update_dirstate = True
614 update_dirstate = True
615 else:
615 else:
616 p1, p2 = p1, p2 or nullid
616 p1, p2 = p1, p2 or nullid
617 update_dirstate = (self.dirstate.parents()[0] == p1)
617 update_dirstate = (self.dirstate.parents()[0] == p1)
618
618
619 c1 = self.changelog.read(p1)
619 c1 = self.changelog.read(p1)
620 c2 = self.changelog.read(p2)
620 c2 = self.changelog.read(p2)
621 m1 = self.manifest.read(c1[0]).copy()
621 m1 = self.manifest.read(c1[0]).copy()
622 m2 = self.manifest.read(c2[0])
622 m2 = self.manifest.read(c2[0])
623
623
624 if use_dirstate:
624 if use_dirstate:
625 branchname = self.workingctx().branch()
625 branchname = self.workingctx().branch()
626 else:
626 else:
627 branchname = ""
627 branchname = ""
628
628
629 if use_dirstate:
629 if use_dirstate:
630 oldname = c1[5].get("branch", "")
630 oldname = c1[5].get("branch", "")
631 if not commit and not remove and not force and p2 == nullid and \
631 if not commit and not remove and not force and p2 == nullid and \
632 branchname == oldname:
632 branchname == oldname:
633 self.ui.status(_("nothing changed\n"))
633 self.ui.status(_("nothing changed\n"))
634 return None
634 return None
635
635
636 xp1 = hex(p1)
636 xp1 = hex(p1)
637 if p2 == nullid: xp2 = ''
637 if p2 == nullid: xp2 = ''
638 else: xp2 = hex(p2)
638 else: xp2 = hex(p2)
639
639
640 self.hook("precommit", throw=True, parent1=xp1, parent2=xp2)
640 self.hook("precommit", throw=True, parent1=xp1, parent2=xp2)
641
641
642 if not wlock:
642 if not wlock:
643 wlock = self.wlock()
643 wlock = self.wlock()
644 if not lock:
644 if not lock:
645 lock = self.lock()
645 lock = self.lock()
646 tr = self.transaction()
646 tr = self.transaction()
647
647
648 # check in files
648 # check in files
649 new = []
649 new = {}
650 linkrev = self.changelog.count()
650 linkrev = self.changelog.count()
651 commit.sort()
651 commit.sort()
652 for f in commit:
652 for f in commit:
653 self.ui.note(f + "\n")
653 self.ui.note(f + "\n")
654 try:
654 try:
655 m1[f] = self.filecommit(f, m1, m2, linkrev, tr, changed)
655 new[f] = self.filecommit(f, m1, m2, linkrev, tr, changed)
656 m1.set(f, util.is_exec(self.wjoin(f), m1.execf(f)))
656 m1.set(f, util.is_exec(self.wjoin(f), m1.execf(f)))
657 new.append(f)
658 except IOError:
657 except IOError:
659 if use_dirstate:
658 if use_dirstate:
660 self.ui.warn(_("trouble committing %s!\n") % f)
659 self.ui.warn(_("trouble committing %s!\n") % f)
661 raise
660 raise
662 else:
661 else:
663 remove.append(f)
662 remove.append(f)
664
663
665 # update manifest
664 # update manifest
665 m1.update(new)
666 remove.sort()
666 remove.sort()
667
667
668 for f in remove:
668 for f in remove:
669 if f in m1:
669 if f in m1:
670 del m1[f]
670 del m1[f]
671 mn = self.manifest.add(m1, tr, linkrev, c1[0], c2[0], (new, remove))
671 mn = self.manifest.add(m1, tr, linkrev, c1[0], c2[0], (new, remove))
672
672
673 # add changeset
673 # add changeset
674 new = new.keys()
675 new.sort()
676
674 user = user or self.ui.username()
677 user = user or self.ui.username()
675 if not text or force_editor:
678 if not text or force_editor:
676 edittext = []
679 edittext = []
677 if text:
680 if text:
678 edittext.append(text)
681 edittext.append(text)
679 edittext.append("")
682 edittext.append("")
680 if p2 != nullid:
683 if p2 != nullid:
681 edittext.append("HG: branch merge")
684 edittext.append("HG: branch merge")
682 edittext.extend(["HG: changed %s" % f for f in changed])
685 edittext.extend(["HG: changed %s" % f for f in changed])
683 edittext.extend(["HG: removed %s" % f for f in remove])
686 edittext.extend(["HG: removed %s" % f for f in remove])
684 if not changed and not remove:
687 if not changed and not remove:
685 edittext.append("HG: no files changed")
688 edittext.append("HG: no files changed")
686 edittext.append("")
689 edittext.append("")
687 # run editor in the repository root
690 # run editor in the repository root
688 olddir = os.getcwd()
691 olddir = os.getcwd()
689 os.chdir(self.root)
692 os.chdir(self.root)
690 text = self.ui.edit("\n".join(edittext), user)
693 text = self.ui.edit("\n".join(edittext), user)
691 os.chdir(olddir)
694 os.chdir(olddir)
692
695
693 lines = [line.rstrip() for line in text.rstrip().splitlines()]
696 lines = [line.rstrip() for line in text.rstrip().splitlines()]
694 while lines and not lines[0]:
697 while lines and not lines[0]:
695 del lines[0]
698 del lines[0]
696 if not lines:
699 if not lines:
697 return None
700 return None
698 text = '\n'.join(lines)
701 text = '\n'.join(lines)
699 if branchname:
702 if branchname:
700 extra["branch"] = branchname
703 extra["branch"] = branchname
701 n = self.changelog.add(mn, changed + remove, text, tr, p1, p2,
704 n = self.changelog.add(mn, changed + remove, text, tr, p1, p2,
702 user, date, extra)
705 user, date, extra)
703 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
706 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
704 parent2=xp2)
707 parent2=xp2)
705 tr.close()
708 tr.close()
706
709
707 if use_dirstate or update_dirstate:
710 if use_dirstate or update_dirstate:
708 self.dirstate.setparents(n)
711 self.dirstate.setparents(n)
709 if use_dirstate:
712 if use_dirstate:
710 self.dirstate.update(new, "n")
713 self.dirstate.update(new, "n")
711 self.dirstate.forget(remove)
714 self.dirstate.forget(remove)
712
715
713 self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2)
716 self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2)
714 return n
717 return n
715
718
716 def walk(self, node=None, files=[], match=util.always, badmatch=None):
719 def walk(self, node=None, files=[], match=util.always, badmatch=None):
717 '''
720 '''
718 walk recursively through the directory tree or a given
721 walk recursively through the directory tree or a given
719 changeset, finding all files matched by the match
722 changeset, finding all files matched by the match
720 function
723 function
721
724
722 results are yielded in a tuple (src, filename), where src
725 results are yielded in a tuple (src, filename), where src
723 is one of:
726 is one of:
724 'f' the file was found in the directory tree
727 'f' the file was found in the directory tree
725 'm' the file was only in the dirstate and not in the tree
728 'm' the file was only in the dirstate and not in the tree
726 'b' file was not found and matched badmatch
729 'b' file was not found and matched badmatch
727 '''
730 '''
728
731
729 if node:
732 if node:
730 fdict = dict.fromkeys(files)
733 fdict = dict.fromkeys(files)
731 for fn in self.manifest.read(self.changelog.read(node)[0]):
734 for fn in self.manifest.read(self.changelog.read(node)[0]):
732 for ffn in fdict:
735 for ffn in fdict:
733 # match if the file is the exact name or a directory
736 # match if the file is the exact name or a directory
734 if ffn == fn or fn.startswith("%s/" % ffn):
737 if ffn == fn or fn.startswith("%s/" % ffn):
735 del fdict[ffn]
738 del fdict[ffn]
736 break
739 break
737 if match(fn):
740 if match(fn):
738 yield 'm', fn
741 yield 'm', fn
739 for fn in fdict:
742 for fn in fdict:
740 if badmatch and badmatch(fn):
743 if badmatch and badmatch(fn):
741 if match(fn):
744 if match(fn):
742 yield 'b', fn
745 yield 'b', fn
743 else:
746 else:
744 self.ui.warn(_('%s: No such file in rev %s\n') % (
747 self.ui.warn(_('%s: No such file in rev %s\n') % (
745 util.pathto(self.getcwd(), fn), short(node)))
748 util.pathto(self.getcwd(), fn), short(node)))
746 else:
749 else:
747 for src, fn in self.dirstate.walk(files, match, badmatch=badmatch):
750 for src, fn in self.dirstate.walk(files, match, badmatch=badmatch):
748 yield src, fn
751 yield src, fn
749
752
750 def status(self, node1=None, node2=None, files=[], match=util.always,
753 def status(self, node1=None, node2=None, files=[], match=util.always,
751 wlock=None, list_ignored=False, list_clean=False):
754 wlock=None, list_ignored=False, list_clean=False):
752 """return status of files between two nodes or node and working directory
755 """return status of files between two nodes or node and working directory
753
756
754 If node1 is None, use the first dirstate parent instead.
757 If node1 is None, use the first dirstate parent instead.
755 If node2 is None, compare node1 with working directory.
758 If node2 is None, compare node1 with working directory.
756 """
759 """
757
760
758 def fcmp(fn, mf):
761 def fcmp(fn, mf):
759 t1 = self.wread(fn)
762 t1 = self.wread(fn)
760 return self.file(fn).cmp(mf.get(fn, nullid), t1)
763 return self.file(fn).cmp(mf.get(fn, nullid), t1)
761
764
762 def mfmatches(node):
765 def mfmatches(node):
763 change = self.changelog.read(node)
766 change = self.changelog.read(node)
764 mf = self.manifest.read(change[0]).copy()
767 mf = self.manifest.read(change[0]).copy()
765 for fn in mf.keys():
768 for fn in mf.keys():
766 if not match(fn):
769 if not match(fn):
767 del mf[fn]
770 del mf[fn]
768 return mf
771 return mf
769
772
770 modified, added, removed, deleted, unknown = [], [], [], [], []
773 modified, added, removed, deleted, unknown = [], [], [], [], []
771 ignored, clean = [], []
774 ignored, clean = [], []
772
775
773 compareworking = False
776 compareworking = False
774 if not node1 or (not node2 and node1 == self.dirstate.parents()[0]):
777 if not node1 or (not node2 and node1 == self.dirstate.parents()[0]):
775 compareworking = True
778 compareworking = True
776
779
777 if not compareworking:
780 if not compareworking:
778 # read the manifest from node1 before the manifest from node2,
781 # read the manifest from node1 before the manifest from node2,
779 # so that we'll hit the manifest cache if we're going through
782 # so that we'll hit the manifest cache if we're going through
780 # all the revisions in parent->child order.
783 # all the revisions in parent->child order.
781 mf1 = mfmatches(node1)
784 mf1 = mfmatches(node1)
782
785
783 # are we comparing the working directory?
786 # are we comparing the working directory?
784 if not node2:
787 if not node2:
785 if not wlock:
788 if not wlock:
786 try:
789 try:
787 wlock = self.wlock(wait=0)
790 wlock = self.wlock(wait=0)
788 except lock.LockException:
791 except lock.LockException:
789 wlock = None
792 wlock = None
790 (lookup, modified, added, removed, deleted, unknown,
793 (lookup, modified, added, removed, deleted, unknown,
791 ignored, clean) = self.dirstate.status(files, match,
794 ignored, clean) = self.dirstate.status(files, match,
792 list_ignored, list_clean)
795 list_ignored, list_clean)
793
796
794 # are we comparing working dir against its parent?
797 # are we comparing working dir against its parent?
795 if compareworking:
798 if compareworking:
796 if lookup:
799 if lookup:
797 # do a full compare of any files that might have changed
800 # do a full compare of any files that might have changed
798 mf2 = mfmatches(self.dirstate.parents()[0])
801 mf2 = mfmatches(self.dirstate.parents()[0])
799 for f in lookup:
802 for f in lookup:
800 if fcmp(f, mf2):
803 if fcmp(f, mf2):
801 modified.append(f)
804 modified.append(f)
802 else:
805 else:
803 clean.append(f)
806 clean.append(f)
804 if wlock is not None:
807 if wlock is not None:
805 self.dirstate.update([f], "n")
808 self.dirstate.update([f], "n")
806 else:
809 else:
807 # we are comparing working dir against non-parent
810 # we are comparing working dir against non-parent
808 # generate a pseudo-manifest for the working dir
811 # generate a pseudo-manifest for the working dir
809 # XXX: create it in dirstate.py ?
812 # XXX: create it in dirstate.py ?
810 mf2 = mfmatches(self.dirstate.parents()[0])
813 mf2 = mfmatches(self.dirstate.parents()[0])
811 for f in lookup + modified + added:
814 for f in lookup + modified + added:
812 mf2[f] = ""
815 mf2[f] = ""
813 mf2.set(f, execf=util.is_exec(self.wjoin(f), mf2.execf(f)))
816 mf2.set(f, execf=util.is_exec(self.wjoin(f), mf2.execf(f)))
814 for f in removed:
817 for f in removed:
815 if f in mf2:
818 if f in mf2:
816 del mf2[f]
819 del mf2[f]
817 else:
820 else:
818 # we are comparing two revisions
821 # we are comparing two revisions
819 mf2 = mfmatches(node2)
822 mf2 = mfmatches(node2)
820
823
821 if not compareworking:
824 if not compareworking:
822 # flush lists from dirstate before comparing manifests
825 # flush lists from dirstate before comparing manifests
823 modified, added, clean = [], [], []
826 modified, added, clean = [], [], []
824
827
825 # make sure to sort the files so we talk to the disk in a
828 # make sure to sort the files so we talk to the disk in a
826 # reasonable order
829 # reasonable order
827 mf2keys = mf2.keys()
830 mf2keys = mf2.keys()
828 mf2keys.sort()
831 mf2keys.sort()
829 for fn in mf2keys:
832 for fn in mf2keys:
830 if mf1.has_key(fn):
833 if mf1.has_key(fn):
831 if mf1.flags(fn) != mf2.flags(fn) or \
834 if mf1.flags(fn) != mf2.flags(fn) or \
832 (mf1[fn] != mf2[fn] and (mf2[fn] != "" or fcmp(fn, mf1))):
835 (mf1[fn] != mf2[fn] and (mf2[fn] != "" or fcmp(fn, mf1))):
833 modified.append(fn)
836 modified.append(fn)
834 elif list_clean:
837 elif list_clean:
835 clean.append(fn)
838 clean.append(fn)
836 del mf1[fn]
839 del mf1[fn]
837 else:
840 else:
838 added.append(fn)
841 added.append(fn)
839
842
840 removed = mf1.keys()
843 removed = mf1.keys()
841
844
842 # sort and return results:
845 # sort and return results:
843 for l in modified, added, removed, deleted, unknown, ignored, clean:
846 for l in modified, added, removed, deleted, unknown, ignored, clean:
844 l.sort()
847 l.sort()
845 return (modified, added, removed, deleted, unknown, ignored, clean)
848 return (modified, added, removed, deleted, unknown, ignored, clean)
846
849
847 def add(self, list, wlock=None):
850 def add(self, list, wlock=None):
848 if not wlock:
851 if not wlock:
849 wlock = self.wlock()
852 wlock = self.wlock()
850 for f in list:
853 for f in list:
851 p = self.wjoin(f)
854 p = self.wjoin(f)
852 if not os.path.exists(p):
855 if not os.path.exists(p):
853 self.ui.warn(_("%s does not exist!\n") % f)
856 self.ui.warn(_("%s does not exist!\n") % f)
854 elif not os.path.isfile(p):
857 elif not os.path.isfile(p):
855 self.ui.warn(_("%s not added: only files supported currently\n")
858 self.ui.warn(_("%s not added: only files supported currently\n")
856 % f)
859 % f)
857 elif self.dirstate.state(f) in 'an':
860 elif self.dirstate.state(f) in 'an':
858 self.ui.warn(_("%s already tracked!\n") % f)
861 self.ui.warn(_("%s already tracked!\n") % f)
859 else:
862 else:
860 self.dirstate.update([f], "a")
863 self.dirstate.update([f], "a")
861
864
862 def forget(self, list, wlock=None):
865 def forget(self, list, wlock=None):
863 if not wlock:
866 if not wlock:
864 wlock = self.wlock()
867 wlock = self.wlock()
865 for f in list:
868 for f in list:
866 if self.dirstate.state(f) not in 'ai':
869 if self.dirstate.state(f) not in 'ai':
867 self.ui.warn(_("%s not added!\n") % f)
870 self.ui.warn(_("%s not added!\n") % f)
868 else:
871 else:
869 self.dirstate.forget([f])
872 self.dirstate.forget([f])
870
873
871 def remove(self, list, unlink=False, wlock=None):
874 def remove(self, list, unlink=False, wlock=None):
872 if unlink:
875 if unlink:
873 for f in list:
876 for f in list:
874 try:
877 try:
875 util.unlink(self.wjoin(f))
878 util.unlink(self.wjoin(f))
876 except OSError, inst:
879 except OSError, inst:
877 if inst.errno != errno.ENOENT:
880 if inst.errno != errno.ENOENT:
878 raise
881 raise
879 if not wlock:
882 if not wlock:
880 wlock = self.wlock()
883 wlock = self.wlock()
881 for f in list:
884 for f in list:
882 p = self.wjoin(f)
885 p = self.wjoin(f)
883 if os.path.exists(p):
886 if os.path.exists(p):
884 self.ui.warn(_("%s still exists!\n") % f)
887 self.ui.warn(_("%s still exists!\n") % f)
885 elif self.dirstate.state(f) == 'a':
888 elif self.dirstate.state(f) == 'a':
886 self.dirstate.forget([f])
889 self.dirstate.forget([f])
887 elif f not in self.dirstate:
890 elif f not in self.dirstate:
888 self.ui.warn(_("%s not tracked!\n") % f)
891 self.ui.warn(_("%s not tracked!\n") % f)
889 else:
892 else:
890 self.dirstate.update([f], "r")
893 self.dirstate.update([f], "r")
891
894
892 def undelete(self, list, wlock=None):
895 def undelete(self, list, wlock=None):
893 p = self.dirstate.parents()[0]
896 p = self.dirstate.parents()[0]
894 mn = self.changelog.read(p)[0]
897 mn = self.changelog.read(p)[0]
895 m = self.manifest.read(mn)
898 m = self.manifest.read(mn)
896 if not wlock:
899 if not wlock:
897 wlock = self.wlock()
900 wlock = self.wlock()
898 for f in list:
901 for f in list:
899 if self.dirstate.state(f) not in "r":
902 if self.dirstate.state(f) not in "r":
900 self.ui.warn("%s not removed!\n" % f)
903 self.ui.warn("%s not removed!\n" % f)
901 else:
904 else:
902 t = self.file(f).read(m[f])
905 t = self.file(f).read(m[f])
903 self.wwrite(f, t)
906 self.wwrite(f, t)
904 util.set_exec(self.wjoin(f), m.execf(f))
907 util.set_exec(self.wjoin(f), m.execf(f))
905 self.dirstate.update([f], "n")
908 self.dirstate.update([f], "n")
906
909
907 def copy(self, source, dest, wlock=None):
910 def copy(self, source, dest, wlock=None):
908 p = self.wjoin(dest)
911 p = self.wjoin(dest)
909 if not os.path.exists(p):
912 if not os.path.exists(p):
910 self.ui.warn(_("%s does not exist!\n") % dest)
913 self.ui.warn(_("%s does not exist!\n") % dest)
911 elif not os.path.isfile(p):
914 elif not os.path.isfile(p):
912 self.ui.warn(_("copy failed: %s is not a file\n") % dest)
915 self.ui.warn(_("copy failed: %s is not a file\n") % dest)
913 else:
916 else:
914 if not wlock:
917 if not wlock:
915 wlock = self.wlock()
918 wlock = self.wlock()
916 if self.dirstate.state(dest) == '?':
919 if self.dirstate.state(dest) == '?':
917 self.dirstate.update([dest], "a")
920 self.dirstate.update([dest], "a")
918 self.dirstate.copy(source, dest)
921 self.dirstate.copy(source, dest)
919
922
920 def heads(self, start=None):
923 def heads(self, start=None):
921 heads = self.changelog.heads(start)
924 heads = self.changelog.heads(start)
922 # sort the output in rev descending order
925 # sort the output in rev descending order
923 heads = [(-self.changelog.rev(h), h) for h in heads]
926 heads = [(-self.changelog.rev(h), h) for h in heads]
924 heads.sort()
927 heads.sort()
925 return [n for (r, n) in heads]
928 return [n for (r, n) in heads]
926
929
927 # branchlookup returns a dict giving a list of branches for
930 # branchlookup returns a dict giving a list of branches for
928 # each head. A branch is defined as the tag of a node or
931 # each head. A branch is defined as the tag of a node or
929 # the branch of the node's parents. If a node has multiple
932 # the branch of the node's parents. If a node has multiple
930 # branch tags, tags are eliminated if they are visible from other
933 # branch tags, tags are eliminated if they are visible from other
931 # branch tags.
934 # branch tags.
932 #
935 #
933 # So, for this graph: a->b->c->d->e
936 # So, for this graph: a->b->c->d->e
934 # \ /
937 # \ /
935 # aa -----/
938 # aa -----/
936 # a has tag 2.6.12
939 # a has tag 2.6.12
937 # d has tag 2.6.13
940 # d has tag 2.6.13
938 # e would have branch tags for 2.6.12 and 2.6.13. Because the node
941 # e would have branch tags for 2.6.12 and 2.6.13. Because the node
939 # for 2.6.12 can be reached from the node 2.6.13, that is eliminated
942 # for 2.6.12 can be reached from the node 2.6.13, that is eliminated
940 # from the list.
943 # from the list.
941 #
944 #
942 # It is possible that more than one head will have the same branch tag.
945 # It is possible that more than one head will have the same branch tag.
943 # callers need to check the result for multiple heads under the same
946 # callers need to check the result for multiple heads under the same
944 # branch tag if that is a problem for them (ie checkout of a specific
947 # branch tag if that is a problem for them (ie checkout of a specific
945 # branch).
948 # branch).
946 #
949 #
947 # passing in a specific branch will limit the depth of the search
950 # passing in a specific branch will limit the depth of the search
948 # through the parents. It won't limit the branches returned in the
951 # through the parents. It won't limit the branches returned in the
949 # result though.
952 # result though.
950 def branchlookup(self, heads=None, branch=None):
953 def branchlookup(self, heads=None, branch=None):
951 if not heads:
954 if not heads:
952 heads = self.heads()
955 heads = self.heads()
953 headt = [ h for h in heads ]
956 headt = [ h for h in heads ]
954 chlog = self.changelog
957 chlog = self.changelog
955 branches = {}
958 branches = {}
956 merges = []
959 merges = []
957 seenmerge = {}
960 seenmerge = {}
958
961
959 # traverse the tree once for each head, recording in the branches
962 # traverse the tree once for each head, recording in the branches
960 # dict which tags are visible from this head. The branches
963 # dict which tags are visible from this head. The branches
961 # dict also records which tags are visible from each tag
964 # dict also records which tags are visible from each tag
962 # while we traverse.
965 # while we traverse.
963 while headt or merges:
966 while headt or merges:
964 if merges:
967 if merges:
965 n, found = merges.pop()
968 n, found = merges.pop()
966 visit = [n]
969 visit = [n]
967 else:
970 else:
968 h = headt.pop()
971 h = headt.pop()
969 visit = [h]
972 visit = [h]
970 found = [h]
973 found = [h]
971 seen = {}
974 seen = {}
972 while visit:
975 while visit:
973 n = visit.pop()
976 n = visit.pop()
974 if n in seen:
977 if n in seen:
975 continue
978 continue
976 pp = chlog.parents(n)
979 pp = chlog.parents(n)
977 tags = self.nodetags(n)
980 tags = self.nodetags(n)
978 if tags:
981 if tags:
979 for x in tags:
982 for x in tags:
980 if x == 'tip':
983 if x == 'tip':
981 continue
984 continue
982 for f in found:
985 for f in found:
983 branches.setdefault(f, {})[n] = 1
986 branches.setdefault(f, {})[n] = 1
984 branches.setdefault(n, {})[n] = 1
987 branches.setdefault(n, {})[n] = 1
985 break
988 break
986 if n not in found:
989 if n not in found:
987 found.append(n)
990 found.append(n)
988 if branch in tags:
991 if branch in tags:
989 continue
992 continue
990 seen[n] = 1
993 seen[n] = 1
991 if pp[1] != nullid and n not in seenmerge:
994 if pp[1] != nullid and n not in seenmerge:
992 merges.append((pp[1], [x for x in found]))
995 merges.append((pp[1], [x for x in found]))
993 seenmerge[n] = 1
996 seenmerge[n] = 1
994 if pp[0] != nullid:
997 if pp[0] != nullid:
995 visit.append(pp[0])
998 visit.append(pp[0])
996 # traverse the branches dict, eliminating branch tags from each
999 # traverse the branches dict, eliminating branch tags from each
997 # head that are visible from another branch tag for that head.
1000 # head that are visible from another branch tag for that head.
998 out = {}
1001 out = {}
999 viscache = {}
1002 viscache = {}
1000 for h in heads:
1003 for h in heads:
1001 def visible(node):
1004 def visible(node):
1002 if node in viscache:
1005 if node in viscache:
1003 return viscache[node]
1006 return viscache[node]
1004 ret = {}
1007 ret = {}
1005 visit = [node]
1008 visit = [node]
1006 while visit:
1009 while visit:
1007 x = visit.pop()
1010 x = visit.pop()
1008 if x in viscache:
1011 if x in viscache:
1009 ret.update(viscache[x])
1012 ret.update(viscache[x])
1010 elif x not in ret:
1013 elif x not in ret:
1011 ret[x] = 1
1014 ret[x] = 1
1012 if x in branches:
1015 if x in branches:
1013 visit[len(visit):] = branches[x].keys()
1016 visit[len(visit):] = branches[x].keys()
1014 viscache[node] = ret
1017 viscache[node] = ret
1015 return ret
1018 return ret
1016 if h not in branches:
1019 if h not in branches:
1017 continue
1020 continue
1018 # O(n^2), but somewhat limited. This only searches the
1021 # O(n^2), but somewhat limited. This only searches the
1019 # tags visible from a specific head, not all the tags in the
1022 # tags visible from a specific head, not all the tags in the
1020 # whole repo.
1023 # whole repo.
1021 for b in branches[h]:
1024 for b in branches[h]:
1022 vis = False
1025 vis = False
1023 for bb in branches[h].keys():
1026 for bb in branches[h].keys():
1024 if b != bb:
1027 if b != bb:
1025 if b in visible(bb):
1028 if b in visible(bb):
1026 vis = True
1029 vis = True
1027 break
1030 break
1028 if not vis:
1031 if not vis:
1029 l = out.setdefault(h, [])
1032 l = out.setdefault(h, [])
1030 l[len(l):] = self.nodetags(b)
1033 l[len(l):] = self.nodetags(b)
1031 return out
1034 return out
1032
1035
1033 def branches(self, nodes):
1036 def branches(self, nodes):
1034 if not nodes:
1037 if not nodes:
1035 nodes = [self.changelog.tip()]
1038 nodes = [self.changelog.tip()]
1036 b = []
1039 b = []
1037 for n in nodes:
1040 for n in nodes:
1038 t = n
1041 t = n
1039 while 1:
1042 while 1:
1040 p = self.changelog.parents(n)
1043 p = self.changelog.parents(n)
1041 if p[1] != nullid or p[0] == nullid:
1044 if p[1] != nullid or p[0] == nullid:
1042 b.append((t, n, p[0], p[1]))
1045 b.append((t, n, p[0], p[1]))
1043 break
1046 break
1044 n = p[0]
1047 n = p[0]
1045 return b
1048 return b
1046
1049
1047 def between(self, pairs):
1050 def between(self, pairs):
1048 r = []
1051 r = []
1049
1052
1050 for top, bottom in pairs:
1053 for top, bottom in pairs:
1051 n, l, i = top, [], 0
1054 n, l, i = top, [], 0
1052 f = 1
1055 f = 1
1053
1056
1054 while n != bottom:
1057 while n != bottom:
1055 p = self.changelog.parents(n)[0]
1058 p = self.changelog.parents(n)[0]
1056 if i == f:
1059 if i == f:
1057 l.append(n)
1060 l.append(n)
1058 f = f * 2
1061 f = f * 2
1059 n = p
1062 n = p
1060 i += 1
1063 i += 1
1061
1064
1062 r.append(l)
1065 r.append(l)
1063
1066
1064 return r
1067 return r
1065
1068
1066 def findincoming(self, remote, base=None, heads=None, force=False):
1069 def findincoming(self, remote, base=None, heads=None, force=False):
1067 """Return list of roots of the subsets of missing nodes from remote
1070 """Return list of roots of the subsets of missing nodes from remote
1068
1071
1069 If base dict is specified, assume that these nodes and their parents
1072 If base dict is specified, assume that these nodes and their parents
1070 exist on the remote side and that no child of a node of base exists
1073 exist on the remote side and that no child of a node of base exists
1071 in both remote and self.
1074 in both remote and self.
1072 Furthermore base will be updated to include the nodes that exists
1075 Furthermore base will be updated to include the nodes that exists
1073 in self and remote but no children exists in self and remote.
1076 in self and remote but no children exists in self and remote.
1074 If a list of heads is specified, return only nodes which are heads
1077 If a list of heads is specified, return only nodes which are heads
1075 or ancestors of these heads.
1078 or ancestors of these heads.
1076
1079
1077 All the ancestors of base are in self and in remote.
1080 All the ancestors of base are in self and in remote.
1078 All the descendants of the list returned are missing in self.
1081 All the descendants of the list returned are missing in self.
1079 (and so we know that the rest of the nodes are missing in remote, see
1082 (and so we know that the rest of the nodes are missing in remote, see
1080 outgoing)
1083 outgoing)
1081 """
1084 """
1082 m = self.changelog.nodemap
1085 m = self.changelog.nodemap
1083 search = []
1086 search = []
1084 fetch = {}
1087 fetch = {}
1085 seen = {}
1088 seen = {}
1086 seenbranch = {}
1089 seenbranch = {}
1087 if base == None:
1090 if base == None:
1088 base = {}
1091 base = {}
1089
1092
1090 if not heads:
1093 if not heads:
1091 heads = remote.heads()
1094 heads = remote.heads()
1092
1095
1093 if self.changelog.tip() == nullid:
1096 if self.changelog.tip() == nullid:
1094 base[nullid] = 1
1097 base[nullid] = 1
1095 if heads != [nullid]:
1098 if heads != [nullid]:
1096 return [nullid]
1099 return [nullid]
1097 return []
1100 return []
1098
1101
1099 # assume we're closer to the tip than the root
1102 # assume we're closer to the tip than the root
1100 # and start by examining the heads
1103 # and start by examining the heads
1101 self.ui.status(_("searching for changes\n"))
1104 self.ui.status(_("searching for changes\n"))
1102
1105
1103 unknown = []
1106 unknown = []
1104 for h in heads:
1107 for h in heads:
1105 if h not in m:
1108 if h not in m:
1106 unknown.append(h)
1109 unknown.append(h)
1107 else:
1110 else:
1108 base[h] = 1
1111 base[h] = 1
1109
1112
1110 if not unknown:
1113 if not unknown:
1111 return []
1114 return []
1112
1115
1113 req = dict.fromkeys(unknown)
1116 req = dict.fromkeys(unknown)
1114 reqcnt = 0
1117 reqcnt = 0
1115
1118
1116 # search through remote branches
1119 # search through remote branches
1117 # a 'branch' here is a linear segment of history, with four parts:
1120 # a 'branch' here is a linear segment of history, with four parts:
1118 # head, root, first parent, second parent
1121 # head, root, first parent, second parent
1119 # (a branch always has two parents (or none) by definition)
1122 # (a branch always has two parents (or none) by definition)
1120 unknown = remote.branches(unknown)
1123 unknown = remote.branches(unknown)
1121 while unknown:
1124 while unknown:
1122 r = []
1125 r = []
1123 while unknown:
1126 while unknown:
1124 n = unknown.pop(0)
1127 n = unknown.pop(0)
1125 if n[0] in seen:
1128 if n[0] in seen:
1126 continue
1129 continue
1127
1130
1128 self.ui.debug(_("examining %s:%s\n")
1131 self.ui.debug(_("examining %s:%s\n")
1129 % (short(n[0]), short(n[1])))
1132 % (short(n[0]), short(n[1])))
1130 if n[0] == nullid: # found the end of the branch
1133 if n[0] == nullid: # found the end of the branch
1131 pass
1134 pass
1132 elif n in seenbranch:
1135 elif n in seenbranch:
1133 self.ui.debug(_("branch already found\n"))
1136 self.ui.debug(_("branch already found\n"))
1134 continue
1137 continue
1135 elif n[1] and n[1] in m: # do we know the base?
1138 elif n[1] and n[1] in m: # do we know the base?
1136 self.ui.debug(_("found incomplete branch %s:%s\n")
1139 self.ui.debug(_("found incomplete branch %s:%s\n")
1137 % (short(n[0]), short(n[1])))
1140 % (short(n[0]), short(n[1])))
1138 search.append(n) # schedule branch range for scanning
1141 search.append(n) # schedule branch range for scanning
1139 seenbranch[n] = 1
1142 seenbranch[n] = 1
1140 else:
1143 else:
1141 if n[1] not in seen and n[1] not in fetch:
1144 if n[1] not in seen and n[1] not in fetch:
1142 if n[2] in m and n[3] in m:
1145 if n[2] in m and n[3] in m:
1143 self.ui.debug(_("found new changeset %s\n") %
1146 self.ui.debug(_("found new changeset %s\n") %
1144 short(n[1]))
1147 short(n[1]))
1145 fetch[n[1]] = 1 # earliest unknown
1148 fetch[n[1]] = 1 # earliest unknown
1146 for p in n[2:4]:
1149 for p in n[2:4]:
1147 if p in m:
1150 if p in m:
1148 base[p] = 1 # latest known
1151 base[p] = 1 # latest known
1149
1152
1150 for p in n[2:4]:
1153 for p in n[2:4]:
1151 if p not in req and p not in m:
1154 if p not in req and p not in m:
1152 r.append(p)
1155 r.append(p)
1153 req[p] = 1
1156 req[p] = 1
1154 seen[n[0]] = 1
1157 seen[n[0]] = 1
1155
1158
1156 if r:
1159 if r:
1157 reqcnt += 1
1160 reqcnt += 1
1158 self.ui.debug(_("request %d: %s\n") %
1161 self.ui.debug(_("request %d: %s\n") %
1159 (reqcnt, " ".join(map(short, r))))
1162 (reqcnt, " ".join(map(short, r))))
1160 for p in xrange(0, len(r), 10):
1163 for p in xrange(0, len(r), 10):
1161 for b in remote.branches(r[p:p+10]):
1164 for b in remote.branches(r[p:p+10]):
1162 self.ui.debug(_("received %s:%s\n") %
1165 self.ui.debug(_("received %s:%s\n") %
1163 (short(b[0]), short(b[1])))
1166 (short(b[0]), short(b[1])))
1164 unknown.append(b)
1167 unknown.append(b)
1165
1168
1166 # do binary search on the branches we found
1169 # do binary search on the branches we found
1167 while search:
1170 while search:
1168 n = search.pop(0)
1171 n = search.pop(0)
1169 reqcnt += 1
1172 reqcnt += 1
1170 l = remote.between([(n[0], n[1])])[0]
1173 l = remote.between([(n[0], n[1])])[0]
1171 l.append(n[1])
1174 l.append(n[1])
1172 p = n[0]
1175 p = n[0]
1173 f = 1
1176 f = 1
1174 for i in l:
1177 for i in l:
1175 self.ui.debug(_("narrowing %d:%d %s\n") % (f, len(l), short(i)))
1178 self.ui.debug(_("narrowing %d:%d %s\n") % (f, len(l), short(i)))
1176 if i in m:
1179 if i in m:
1177 if f <= 2:
1180 if f <= 2:
1178 self.ui.debug(_("found new branch changeset %s\n") %
1181 self.ui.debug(_("found new branch changeset %s\n") %
1179 short(p))
1182 short(p))
1180 fetch[p] = 1
1183 fetch[p] = 1
1181 base[i] = 1
1184 base[i] = 1
1182 else:
1185 else:
1183 self.ui.debug(_("narrowed branch search to %s:%s\n")
1186 self.ui.debug(_("narrowed branch search to %s:%s\n")
1184 % (short(p), short(i)))
1187 % (short(p), short(i)))
1185 search.append((p, i))
1188 search.append((p, i))
1186 break
1189 break
1187 p, f = i, f * 2
1190 p, f = i, f * 2
1188
1191
1189 # sanity check our fetch list
1192 # sanity check our fetch list
1190 for f in fetch.keys():
1193 for f in fetch.keys():
1191 if f in m:
1194 if f in m:
1192 raise repo.RepoError(_("already have changeset ") + short(f[:4]))
1195 raise repo.RepoError(_("already have changeset ") + short(f[:4]))
1193
1196
1194 if base.keys() == [nullid]:
1197 if base.keys() == [nullid]:
1195 if force:
1198 if force:
1196 self.ui.warn(_("warning: repository is unrelated\n"))
1199 self.ui.warn(_("warning: repository is unrelated\n"))
1197 else:
1200 else:
1198 raise util.Abort(_("repository is unrelated"))
1201 raise util.Abort(_("repository is unrelated"))
1199
1202
1200 self.ui.debug(_("found new changesets starting at ") +
1203 self.ui.debug(_("found new changesets starting at ") +
1201 " ".join([short(f) for f in fetch]) + "\n")
1204 " ".join([short(f) for f in fetch]) + "\n")
1202
1205
1203 self.ui.debug(_("%d total queries\n") % reqcnt)
1206 self.ui.debug(_("%d total queries\n") % reqcnt)
1204
1207
1205 return fetch.keys()
1208 return fetch.keys()
1206
1209
1207 def findoutgoing(self, remote, base=None, heads=None, force=False):
1210 def findoutgoing(self, remote, base=None, heads=None, force=False):
1208 """Return list of nodes that are roots of subsets not in remote
1211 """Return list of nodes that are roots of subsets not in remote
1209
1212
1210 If base dict is specified, assume that these nodes and their parents
1213 If base dict is specified, assume that these nodes and their parents
1211 exist on the remote side.
1214 exist on the remote side.
1212 If a list of heads is specified, return only nodes which are heads
1215 If a list of heads is specified, return only nodes which are heads
1213 or ancestors of these heads, and return a second element which
1216 or ancestors of these heads, and return a second element which
1214 contains all remote heads which get new children.
1217 contains all remote heads which get new children.
1215 """
1218 """
1216 if base == None:
1219 if base == None:
1217 base = {}
1220 base = {}
1218 self.findincoming(remote, base, heads, force=force)
1221 self.findincoming(remote, base, heads, force=force)
1219
1222
1220 self.ui.debug(_("common changesets up to ")
1223 self.ui.debug(_("common changesets up to ")
1221 + " ".join(map(short, base.keys())) + "\n")
1224 + " ".join(map(short, base.keys())) + "\n")
1222
1225
1223 remain = dict.fromkeys(self.changelog.nodemap)
1226 remain = dict.fromkeys(self.changelog.nodemap)
1224
1227
1225 # prune everything remote has from the tree
1228 # prune everything remote has from the tree
1226 del remain[nullid]
1229 del remain[nullid]
1227 remove = base.keys()
1230 remove = base.keys()
1228 while remove:
1231 while remove:
1229 n = remove.pop(0)
1232 n = remove.pop(0)
1230 if n in remain:
1233 if n in remain:
1231 del remain[n]
1234 del remain[n]
1232 for p in self.changelog.parents(n):
1235 for p in self.changelog.parents(n):
1233 remove.append(p)
1236 remove.append(p)
1234
1237
1235 # find every node whose parents have been pruned
1238 # find every node whose parents have been pruned
1236 subset = []
1239 subset = []
1237 # find every remote head that will get new children
1240 # find every remote head that will get new children
1238 updated_heads = {}
1241 updated_heads = {}
1239 for n in remain:
1242 for n in remain:
1240 p1, p2 = self.changelog.parents(n)
1243 p1, p2 = self.changelog.parents(n)
1241 if p1 not in remain and p2 not in remain:
1244 if p1 not in remain and p2 not in remain:
1242 subset.append(n)
1245 subset.append(n)
1243 if heads:
1246 if heads:
1244 if p1 in heads:
1247 if p1 in heads:
1245 updated_heads[p1] = True
1248 updated_heads[p1] = True
1246 if p2 in heads:
1249 if p2 in heads:
1247 updated_heads[p2] = True
1250 updated_heads[p2] = True
1248
1251
1249 # this is the set of all roots we have to push
1252 # this is the set of all roots we have to push
1250 if heads:
1253 if heads:
1251 return subset, updated_heads.keys()
1254 return subset, updated_heads.keys()
1252 else:
1255 else:
1253 return subset
1256 return subset
1254
1257
1255 def pull(self, remote, heads=None, force=False, lock=None):
1258 def pull(self, remote, heads=None, force=False, lock=None):
1256 mylock = False
1259 mylock = False
1257 if not lock:
1260 if not lock:
1258 lock = self.lock()
1261 lock = self.lock()
1259 mylock = True
1262 mylock = True
1260
1263
1261 try:
1264 try:
1262 fetch = self.findincoming(remote, force=force)
1265 fetch = self.findincoming(remote, force=force)
1263 if fetch == [nullid]:
1266 if fetch == [nullid]:
1264 self.ui.status(_("requesting all changes\n"))
1267 self.ui.status(_("requesting all changes\n"))
1265
1268
1266 if not fetch:
1269 if not fetch:
1267 self.ui.status(_("no changes found\n"))
1270 self.ui.status(_("no changes found\n"))
1268 return 0
1271 return 0
1269
1272
1270 if heads is None:
1273 if heads is None:
1271 cg = remote.changegroup(fetch, 'pull')
1274 cg = remote.changegroup(fetch, 'pull')
1272 else:
1275 else:
1273 if 'changegroupsubset' not in remote.capabilities:
1276 if 'changegroupsubset' not in remote.capabilities:
1274 raise util.Abort(_("Partial pull cannot be done because other repository doesn't support changegroupsubset."))
1277 raise util.Abort(_("Partial pull cannot be done because other repository doesn't support changegroupsubset."))
1275 cg = remote.changegroupsubset(fetch, heads, 'pull')
1278 cg = remote.changegroupsubset(fetch, heads, 'pull')
1276 return self.addchangegroup(cg, 'pull', remote.url())
1279 return self.addchangegroup(cg, 'pull', remote.url())
1277 finally:
1280 finally:
1278 if mylock:
1281 if mylock:
1279 lock.release()
1282 lock.release()
1280
1283
1281 def push(self, remote, force=False, revs=None):
1284 def push(self, remote, force=False, revs=None):
1282 # there are two ways to push to remote repo:
1285 # there are two ways to push to remote repo:
1283 #
1286 #
1284 # addchangegroup assumes local user can lock remote
1287 # addchangegroup assumes local user can lock remote
1285 # repo (local filesystem, old ssh servers).
1288 # repo (local filesystem, old ssh servers).
1286 #
1289 #
1287 # unbundle assumes local user cannot lock remote repo (new ssh
1290 # unbundle assumes local user cannot lock remote repo (new ssh
1288 # servers, http servers).
1291 # servers, http servers).
1289
1292
1290 if remote.capable('unbundle'):
1293 if remote.capable('unbundle'):
1291 return self.push_unbundle(remote, force, revs)
1294 return self.push_unbundle(remote, force, revs)
1292 return self.push_addchangegroup(remote, force, revs)
1295 return self.push_addchangegroup(remote, force, revs)
1293
1296
1294 def prepush(self, remote, force, revs):
1297 def prepush(self, remote, force, revs):
1295 base = {}
1298 base = {}
1296 remote_heads = remote.heads()
1299 remote_heads = remote.heads()
1297 inc = self.findincoming(remote, base, remote_heads, force=force)
1300 inc = self.findincoming(remote, base, remote_heads, force=force)
1298 if not force and inc:
1301 if not force and inc:
1299 self.ui.warn(_("abort: unsynced remote changes!\n"))
1302 self.ui.warn(_("abort: unsynced remote changes!\n"))
1300 self.ui.status(_("(did you forget to sync?"
1303 self.ui.status(_("(did you forget to sync?"
1301 " use push -f to force)\n"))
1304 " use push -f to force)\n"))
1302 return None, 1
1305 return None, 1
1303
1306
1304 update, updated_heads = self.findoutgoing(remote, base, remote_heads)
1307 update, updated_heads = self.findoutgoing(remote, base, remote_heads)
1305 if revs is not None:
1308 if revs is not None:
1306 msng_cl, bases, heads = self.changelog.nodesbetween(update, revs)
1309 msng_cl, bases, heads = self.changelog.nodesbetween(update, revs)
1307 else:
1310 else:
1308 bases, heads = update, self.changelog.heads()
1311 bases, heads = update, self.changelog.heads()
1309
1312
1310 if not bases:
1313 if not bases:
1311 self.ui.status(_("no changes found\n"))
1314 self.ui.status(_("no changes found\n"))
1312 return None, 1
1315 return None, 1
1313 elif not force:
1316 elif not force:
1314 # FIXME we don't properly detect creation of new heads
1317 # FIXME we don't properly detect creation of new heads
1315 # in the push -r case, assume the user knows what he's doing
1318 # in the push -r case, assume the user knows what he's doing
1316 if not revs and len(remote_heads) < len(heads) \
1319 if not revs and len(remote_heads) < len(heads) \
1317 and remote_heads != [nullid]:
1320 and remote_heads != [nullid]:
1318 self.ui.warn(_("abort: push creates new remote branches!\n"))
1321 self.ui.warn(_("abort: push creates new remote branches!\n"))
1319 self.ui.status(_("(did you forget to merge?"
1322 self.ui.status(_("(did you forget to merge?"
1320 " use push -f to force)\n"))
1323 " use push -f to force)\n"))
1321 return None, 1
1324 return None, 1
1322
1325
1323 if revs is None:
1326 if revs is None:
1324 cg = self.changegroup(update, 'push')
1327 cg = self.changegroup(update, 'push')
1325 else:
1328 else:
1326 cg = self.changegroupsubset(update, revs, 'push')
1329 cg = self.changegroupsubset(update, revs, 'push')
1327 return cg, remote_heads
1330 return cg, remote_heads
1328
1331
1329 def push_addchangegroup(self, remote, force, revs):
1332 def push_addchangegroup(self, remote, force, revs):
1330 lock = remote.lock()
1333 lock = remote.lock()
1331
1334
1332 ret = self.prepush(remote, force, revs)
1335 ret = self.prepush(remote, force, revs)
1333 if ret[0] is not None:
1336 if ret[0] is not None:
1334 cg, remote_heads = ret
1337 cg, remote_heads = ret
1335 return remote.addchangegroup(cg, 'push', self.url())
1338 return remote.addchangegroup(cg, 'push', self.url())
1336 return ret[1]
1339 return ret[1]
1337
1340
1338 def push_unbundle(self, remote, force, revs):
1341 def push_unbundle(self, remote, force, revs):
1339 # local repo finds heads on server, finds out what revs it
1342 # local repo finds heads on server, finds out what revs it
1340 # must push. once revs transferred, if server finds it has
1343 # must push. once revs transferred, if server finds it has
1341 # different heads (someone else won commit/push race), server
1344 # different heads (someone else won commit/push race), server
1342 # aborts.
1345 # aborts.
1343
1346
1344 ret = self.prepush(remote, force, revs)
1347 ret = self.prepush(remote, force, revs)
1345 if ret[0] is not None:
1348 if ret[0] is not None:
1346 cg, remote_heads = ret
1349 cg, remote_heads = ret
1347 if force: remote_heads = ['force']
1350 if force: remote_heads = ['force']
1348 return remote.unbundle(cg, remote_heads, 'push')
1351 return remote.unbundle(cg, remote_heads, 'push')
1349 return ret[1]
1352 return ret[1]
1350
1353
1351 def changegroupinfo(self, nodes):
1354 def changegroupinfo(self, nodes):
1352 self.ui.note(_("%d changesets found\n") % len(nodes))
1355 self.ui.note(_("%d changesets found\n") % len(nodes))
1353 if self.ui.debugflag:
1356 if self.ui.debugflag:
1354 self.ui.debug(_("List of changesets:\n"))
1357 self.ui.debug(_("List of changesets:\n"))
1355 for node in nodes:
1358 for node in nodes:
1356 self.ui.debug("%s\n" % hex(node))
1359 self.ui.debug("%s\n" % hex(node))
1357
1360
1358 def changegroupsubset(self, bases, heads, source):
1361 def changegroupsubset(self, bases, heads, source):
1359 """This function generates a changegroup consisting of all the nodes
1362 """This function generates a changegroup consisting of all the nodes
1360 that are descendents of any of the bases, and ancestors of any of
1363 that are descendents of any of the bases, and ancestors of any of
1361 the heads.
1364 the heads.
1362
1365
1363 It is fairly complex as determining which filenodes and which
1366 It is fairly complex as determining which filenodes and which
1364 manifest nodes need to be included for the changeset to be complete
1367 manifest nodes need to be included for the changeset to be complete
1365 is non-trivial.
1368 is non-trivial.
1366
1369
1367 Another wrinkle is doing the reverse, figuring out which changeset in
1370 Another wrinkle is doing the reverse, figuring out which changeset in
1368 the changegroup a particular filenode or manifestnode belongs to."""
1371 the changegroup a particular filenode or manifestnode belongs to."""
1369
1372
1370 self.hook('preoutgoing', throw=True, source=source)
1373 self.hook('preoutgoing', throw=True, source=source)
1371
1374
1372 # Set up some initial variables
1375 # Set up some initial variables
1373 # Make it easy to refer to self.changelog
1376 # Make it easy to refer to self.changelog
1374 cl = self.changelog
1377 cl = self.changelog
1375 # msng is short for missing - compute the list of changesets in this
1378 # msng is short for missing - compute the list of changesets in this
1376 # changegroup.
1379 # changegroup.
1377 msng_cl_lst, bases, heads = cl.nodesbetween(bases, heads)
1380 msng_cl_lst, bases, heads = cl.nodesbetween(bases, heads)
1378 self.changegroupinfo(msng_cl_lst)
1381 self.changegroupinfo(msng_cl_lst)
1379 # Some bases may turn out to be superfluous, and some heads may be
1382 # Some bases may turn out to be superfluous, and some heads may be
1380 # too. nodesbetween will return the minimal set of bases and heads
1383 # too. nodesbetween will return the minimal set of bases and heads
1381 # necessary to re-create the changegroup.
1384 # necessary to re-create the changegroup.
1382
1385
1383 # Known heads are the list of heads that it is assumed the recipient
1386 # Known heads are the list of heads that it is assumed the recipient
1384 # of this changegroup will know about.
1387 # of this changegroup will know about.
1385 knownheads = {}
1388 knownheads = {}
1386 # We assume that all parents of bases are known heads.
1389 # We assume that all parents of bases are known heads.
1387 for n in bases:
1390 for n in bases:
1388 for p in cl.parents(n):
1391 for p in cl.parents(n):
1389 if p != nullid:
1392 if p != nullid:
1390 knownheads[p] = 1
1393 knownheads[p] = 1
1391 knownheads = knownheads.keys()
1394 knownheads = knownheads.keys()
1392 if knownheads:
1395 if knownheads:
1393 # Now that we know what heads are known, we can compute which
1396 # Now that we know what heads are known, we can compute which
1394 # changesets are known. The recipient must know about all
1397 # changesets are known. The recipient must know about all
1395 # changesets required to reach the known heads from the null
1398 # changesets required to reach the known heads from the null
1396 # changeset.
1399 # changeset.
1397 has_cl_set, junk, junk = cl.nodesbetween(None, knownheads)
1400 has_cl_set, junk, junk = cl.nodesbetween(None, knownheads)
1398 junk = None
1401 junk = None
1399 # Transform the list into an ersatz set.
1402 # Transform the list into an ersatz set.
1400 has_cl_set = dict.fromkeys(has_cl_set)
1403 has_cl_set = dict.fromkeys(has_cl_set)
1401 else:
1404 else:
1402 # If there were no known heads, the recipient cannot be assumed to
1405 # If there were no known heads, the recipient cannot be assumed to
1403 # know about any changesets.
1406 # know about any changesets.
1404 has_cl_set = {}
1407 has_cl_set = {}
1405
1408
1406 # Make it easy to refer to self.manifest
1409 # Make it easy to refer to self.manifest
1407 mnfst = self.manifest
1410 mnfst = self.manifest
1408 # We don't know which manifests are missing yet
1411 # We don't know which manifests are missing yet
1409 msng_mnfst_set = {}
1412 msng_mnfst_set = {}
1410 # Nor do we know which filenodes are missing.
1413 # Nor do we know which filenodes are missing.
1411 msng_filenode_set = {}
1414 msng_filenode_set = {}
1412
1415
1413 junk = mnfst.index[mnfst.count() - 1] # Get around a bug in lazyindex
1416 junk = mnfst.index[mnfst.count() - 1] # Get around a bug in lazyindex
1414 junk = None
1417 junk = None
1415
1418
1416 # A changeset always belongs to itself, so the changenode lookup
1419 # A changeset always belongs to itself, so the changenode lookup
1417 # function for a changenode is identity.
1420 # function for a changenode is identity.
1418 def identity(x):
1421 def identity(x):
1419 return x
1422 return x
1420
1423
1421 # A function generating function. Sets up an environment for the
1424 # A function generating function. Sets up an environment for the
1422 # inner function.
1425 # inner function.
1423 def cmp_by_rev_func(revlog):
1426 def cmp_by_rev_func(revlog):
1424 # Compare two nodes by their revision number in the environment's
1427 # Compare two nodes by their revision number in the environment's
1425 # revision history. Since the revision number both represents the
1428 # revision history. Since the revision number both represents the
1426 # most efficient order to read the nodes in, and represents a
1429 # most efficient order to read the nodes in, and represents a
1427 # topological sorting of the nodes, this function is often useful.
1430 # topological sorting of the nodes, this function is often useful.
1428 def cmp_by_rev(a, b):
1431 def cmp_by_rev(a, b):
1429 return cmp(revlog.rev(a), revlog.rev(b))
1432 return cmp(revlog.rev(a), revlog.rev(b))
1430 return cmp_by_rev
1433 return cmp_by_rev
1431
1434
1432 # If we determine that a particular file or manifest node must be a
1435 # If we determine that a particular file or manifest node must be a
1433 # node that the recipient of the changegroup will already have, we can
1436 # node that the recipient of the changegroup will already have, we can
1434 # also assume the recipient will have all the parents. This function
1437 # also assume the recipient will have all the parents. This function
1435 # prunes them from the set of missing nodes.
1438 # prunes them from the set of missing nodes.
1436 def prune_parents(revlog, hasset, msngset):
1439 def prune_parents(revlog, hasset, msngset):
1437 haslst = hasset.keys()
1440 haslst = hasset.keys()
1438 haslst.sort(cmp_by_rev_func(revlog))
1441 haslst.sort(cmp_by_rev_func(revlog))
1439 for node in haslst:
1442 for node in haslst:
1440 parentlst = [p for p in revlog.parents(node) if p != nullid]
1443 parentlst = [p for p in revlog.parents(node) if p != nullid]
1441 while parentlst:
1444 while parentlst:
1442 n = parentlst.pop()
1445 n = parentlst.pop()
1443 if n not in hasset:
1446 if n not in hasset:
1444 hasset[n] = 1
1447 hasset[n] = 1
1445 p = [p for p in revlog.parents(n) if p != nullid]
1448 p = [p for p in revlog.parents(n) if p != nullid]
1446 parentlst.extend(p)
1449 parentlst.extend(p)
1447 for n in hasset:
1450 for n in hasset:
1448 msngset.pop(n, None)
1451 msngset.pop(n, None)
1449
1452
1450 # This is a function generating function used to set up an environment
1453 # This is a function generating function used to set up an environment
1451 # for the inner function to execute in.
1454 # for the inner function to execute in.
1452 def manifest_and_file_collector(changedfileset):
1455 def manifest_and_file_collector(changedfileset):
1453 # This is an information gathering function that gathers
1456 # This is an information gathering function that gathers
1454 # information from each changeset node that goes out as part of
1457 # information from each changeset node that goes out as part of
1455 # the changegroup. The information gathered is a list of which
1458 # the changegroup. The information gathered is a list of which
1456 # manifest nodes are potentially required (the recipient may
1459 # manifest nodes are potentially required (the recipient may
1457 # already have them) and total list of all files which were
1460 # already have them) and total list of all files which were
1458 # changed in any changeset in the changegroup.
1461 # changed in any changeset in the changegroup.
1459 #
1462 #
1460 # We also remember the first changenode we saw any manifest
1463 # We also remember the first changenode we saw any manifest
1461 # referenced by so we can later determine which changenode 'owns'
1464 # referenced by so we can later determine which changenode 'owns'
1462 # the manifest.
1465 # the manifest.
1463 def collect_manifests_and_files(clnode):
1466 def collect_manifests_and_files(clnode):
1464 c = cl.read(clnode)
1467 c = cl.read(clnode)
1465 for f in c[3]:
1468 for f in c[3]:
1466 # This is to make sure we only have one instance of each
1469 # This is to make sure we only have one instance of each
1467 # filename string for each filename.
1470 # filename string for each filename.
1468 changedfileset.setdefault(f, f)
1471 changedfileset.setdefault(f, f)
1469 msng_mnfst_set.setdefault(c[0], clnode)
1472 msng_mnfst_set.setdefault(c[0], clnode)
1470 return collect_manifests_and_files
1473 return collect_manifests_and_files
1471
1474
1472 # Figure out which manifest nodes (of the ones we think might be part
1475 # Figure out which manifest nodes (of the ones we think might be part
1473 # of the changegroup) the recipient must know about and remove them
1476 # of the changegroup) the recipient must know about and remove them
1474 # from the changegroup.
1477 # from the changegroup.
1475 def prune_manifests():
1478 def prune_manifests():
1476 has_mnfst_set = {}
1479 has_mnfst_set = {}
1477 for n in msng_mnfst_set:
1480 for n in msng_mnfst_set:
1478 # If a 'missing' manifest thinks it belongs to a changenode
1481 # If a 'missing' manifest thinks it belongs to a changenode
1479 # the recipient is assumed to have, obviously the recipient
1482 # the recipient is assumed to have, obviously the recipient
1480 # must have that manifest.
1483 # must have that manifest.
1481 linknode = cl.node(mnfst.linkrev(n))
1484 linknode = cl.node(mnfst.linkrev(n))
1482 if linknode in has_cl_set:
1485 if linknode in has_cl_set:
1483 has_mnfst_set[n] = 1
1486 has_mnfst_set[n] = 1
1484 prune_parents(mnfst, has_mnfst_set, msng_mnfst_set)
1487 prune_parents(mnfst, has_mnfst_set, msng_mnfst_set)
1485
1488
1486 # Use the information collected in collect_manifests_and_files to say
1489 # Use the information collected in collect_manifests_and_files to say
1487 # which changenode any manifestnode belongs to.
1490 # which changenode any manifestnode belongs to.
1488 def lookup_manifest_link(mnfstnode):
1491 def lookup_manifest_link(mnfstnode):
1489 return msng_mnfst_set[mnfstnode]
1492 return msng_mnfst_set[mnfstnode]
1490
1493
1491 # A function generating function that sets up the initial environment
1494 # A function generating function that sets up the initial environment
1492 # the inner function.
1495 # the inner function.
1493 def filenode_collector(changedfiles):
1496 def filenode_collector(changedfiles):
1494 next_rev = [0]
1497 next_rev = [0]
1495 # This gathers information from each manifestnode included in the
1498 # This gathers information from each manifestnode included in the
1496 # changegroup about which filenodes the manifest node references
1499 # changegroup about which filenodes the manifest node references
1497 # so we can include those in the changegroup too.
1500 # so we can include those in the changegroup too.
1498 #
1501 #
1499 # It also remembers which changenode each filenode belongs to. It
1502 # It also remembers which changenode each filenode belongs to. It
1500 # does this by assuming the a filenode belongs to the changenode
1503 # does this by assuming the a filenode belongs to the changenode
1501 # the first manifest that references it belongs to.
1504 # the first manifest that references it belongs to.
1502 def collect_msng_filenodes(mnfstnode):
1505 def collect_msng_filenodes(mnfstnode):
1503 r = mnfst.rev(mnfstnode)
1506 r = mnfst.rev(mnfstnode)
1504 if r == next_rev[0]:
1507 if r == next_rev[0]:
1505 # If the last rev we looked at was the one just previous,
1508 # If the last rev we looked at was the one just previous,
1506 # we only need to see a diff.
1509 # we only need to see a diff.
1507 delta = mdiff.patchtext(mnfst.delta(mnfstnode))
1510 delta = mdiff.patchtext(mnfst.delta(mnfstnode))
1508 # For each line in the delta
1511 # For each line in the delta
1509 for dline in delta.splitlines():
1512 for dline in delta.splitlines():
1510 # get the filename and filenode for that line
1513 # get the filename and filenode for that line
1511 f, fnode = dline.split('\0')
1514 f, fnode = dline.split('\0')
1512 fnode = bin(fnode[:40])
1515 fnode = bin(fnode[:40])
1513 f = changedfiles.get(f, None)
1516 f = changedfiles.get(f, None)
1514 # And if the file is in the list of files we care
1517 # And if the file is in the list of files we care
1515 # about.
1518 # about.
1516 if f is not None:
1519 if f is not None:
1517 # Get the changenode this manifest belongs to
1520 # Get the changenode this manifest belongs to
1518 clnode = msng_mnfst_set[mnfstnode]
1521 clnode = msng_mnfst_set[mnfstnode]
1519 # Create the set of filenodes for the file if
1522 # Create the set of filenodes for the file if
1520 # there isn't one already.
1523 # there isn't one already.
1521 ndset = msng_filenode_set.setdefault(f, {})
1524 ndset = msng_filenode_set.setdefault(f, {})
1522 # And set the filenode's changelog node to the
1525 # And set the filenode's changelog node to the
1523 # manifest's if it hasn't been set already.
1526 # manifest's if it hasn't been set already.
1524 ndset.setdefault(fnode, clnode)
1527 ndset.setdefault(fnode, clnode)
1525 else:
1528 else:
1526 # Otherwise we need a full manifest.
1529 # Otherwise we need a full manifest.
1527 m = mnfst.read(mnfstnode)
1530 m = mnfst.read(mnfstnode)
1528 # For every file in we care about.
1531 # For every file in we care about.
1529 for f in changedfiles:
1532 for f in changedfiles:
1530 fnode = m.get(f, None)
1533 fnode = m.get(f, None)
1531 # If it's in the manifest
1534 # If it's in the manifest
1532 if fnode is not None:
1535 if fnode is not None:
1533 # See comments above.
1536 # See comments above.
1534 clnode = msng_mnfst_set[mnfstnode]
1537 clnode = msng_mnfst_set[mnfstnode]
1535 ndset = msng_filenode_set.setdefault(f, {})
1538 ndset = msng_filenode_set.setdefault(f, {})
1536 ndset.setdefault(fnode, clnode)
1539 ndset.setdefault(fnode, clnode)
1537 # Remember the revision we hope to see next.
1540 # Remember the revision we hope to see next.
1538 next_rev[0] = r + 1
1541 next_rev[0] = r + 1
1539 return collect_msng_filenodes
1542 return collect_msng_filenodes
1540
1543
1541 # We have a list of filenodes we think we need for a file, lets remove
1544 # We have a list of filenodes we think we need for a file, lets remove
1542 # all those we now the recipient must have.
1545 # all those we now the recipient must have.
1543 def prune_filenodes(f, filerevlog):
1546 def prune_filenodes(f, filerevlog):
1544 msngset = msng_filenode_set[f]
1547 msngset = msng_filenode_set[f]
1545 hasset = {}
1548 hasset = {}
1546 # If a 'missing' filenode thinks it belongs to a changenode we
1549 # If a 'missing' filenode thinks it belongs to a changenode we
1547 # assume the recipient must have, then the recipient must have
1550 # assume the recipient must have, then the recipient must have
1548 # that filenode.
1551 # that filenode.
1549 for n in msngset:
1552 for n in msngset:
1550 clnode = cl.node(filerevlog.linkrev(n))
1553 clnode = cl.node(filerevlog.linkrev(n))
1551 if clnode in has_cl_set:
1554 if clnode in has_cl_set:
1552 hasset[n] = 1
1555 hasset[n] = 1
1553 prune_parents(filerevlog, hasset, msngset)
1556 prune_parents(filerevlog, hasset, msngset)
1554
1557
1555 # A function generator function that sets up the a context for the
1558 # A function generator function that sets up the a context for the
1556 # inner function.
1559 # inner function.
1557 def lookup_filenode_link_func(fname):
1560 def lookup_filenode_link_func(fname):
1558 msngset = msng_filenode_set[fname]
1561 msngset = msng_filenode_set[fname]
1559 # Lookup the changenode the filenode belongs to.
1562 # Lookup the changenode the filenode belongs to.
1560 def lookup_filenode_link(fnode):
1563 def lookup_filenode_link(fnode):
1561 return msngset[fnode]
1564 return msngset[fnode]
1562 return lookup_filenode_link
1565 return lookup_filenode_link
1563
1566
1564 # Now that we have all theses utility functions to help out and
1567 # Now that we have all theses utility functions to help out and
1565 # logically divide up the task, generate the group.
1568 # logically divide up the task, generate the group.
1566 def gengroup():
1569 def gengroup():
1567 # The set of changed files starts empty.
1570 # The set of changed files starts empty.
1568 changedfiles = {}
1571 changedfiles = {}
1569 # Create a changenode group generator that will call our functions
1572 # Create a changenode group generator that will call our functions
1570 # back to lookup the owning changenode and collect information.
1573 # back to lookup the owning changenode and collect information.
1571 group = cl.group(msng_cl_lst, identity,
1574 group = cl.group(msng_cl_lst, identity,
1572 manifest_and_file_collector(changedfiles))
1575 manifest_and_file_collector(changedfiles))
1573 for chnk in group:
1576 for chnk in group:
1574 yield chnk
1577 yield chnk
1575
1578
1576 # The list of manifests has been collected by the generator
1579 # The list of manifests has been collected by the generator
1577 # calling our functions back.
1580 # calling our functions back.
1578 prune_manifests()
1581 prune_manifests()
1579 msng_mnfst_lst = msng_mnfst_set.keys()
1582 msng_mnfst_lst = msng_mnfst_set.keys()
1580 # Sort the manifestnodes by revision number.
1583 # Sort the manifestnodes by revision number.
1581 msng_mnfst_lst.sort(cmp_by_rev_func(mnfst))
1584 msng_mnfst_lst.sort(cmp_by_rev_func(mnfst))
1582 # Create a generator for the manifestnodes that calls our lookup
1585 # Create a generator for the manifestnodes that calls our lookup
1583 # and data collection functions back.
1586 # and data collection functions back.
1584 group = mnfst.group(msng_mnfst_lst, lookup_manifest_link,
1587 group = mnfst.group(msng_mnfst_lst, lookup_manifest_link,
1585 filenode_collector(changedfiles))
1588 filenode_collector(changedfiles))
1586 for chnk in group:
1589 for chnk in group:
1587 yield chnk
1590 yield chnk
1588
1591
1589 # These are no longer needed, dereference and toss the memory for
1592 # These are no longer needed, dereference and toss the memory for
1590 # them.
1593 # them.
1591 msng_mnfst_lst = None
1594 msng_mnfst_lst = None
1592 msng_mnfst_set.clear()
1595 msng_mnfst_set.clear()
1593
1596
1594 changedfiles = changedfiles.keys()
1597 changedfiles = changedfiles.keys()
1595 changedfiles.sort()
1598 changedfiles.sort()
1596 # Go through all our files in order sorted by name.
1599 # Go through all our files in order sorted by name.
1597 for fname in changedfiles:
1600 for fname in changedfiles:
1598 filerevlog = self.file(fname)
1601 filerevlog = self.file(fname)
1599 # Toss out the filenodes that the recipient isn't really
1602 # Toss out the filenodes that the recipient isn't really
1600 # missing.
1603 # missing.
1601 if msng_filenode_set.has_key(fname):
1604 if msng_filenode_set.has_key(fname):
1602 prune_filenodes(fname, filerevlog)
1605 prune_filenodes(fname, filerevlog)
1603 msng_filenode_lst = msng_filenode_set[fname].keys()
1606 msng_filenode_lst = msng_filenode_set[fname].keys()
1604 else:
1607 else:
1605 msng_filenode_lst = []
1608 msng_filenode_lst = []
1606 # If any filenodes are left, generate the group for them,
1609 # If any filenodes are left, generate the group for them,
1607 # otherwise don't bother.
1610 # otherwise don't bother.
1608 if len(msng_filenode_lst) > 0:
1611 if len(msng_filenode_lst) > 0:
1609 yield changegroup.genchunk(fname)
1612 yield changegroup.genchunk(fname)
1610 # Sort the filenodes by their revision #
1613 # Sort the filenodes by their revision #
1611 msng_filenode_lst.sort(cmp_by_rev_func(filerevlog))
1614 msng_filenode_lst.sort(cmp_by_rev_func(filerevlog))
1612 # Create a group generator and only pass in a changenode
1615 # Create a group generator and only pass in a changenode
1613 # lookup function as we need to collect no information
1616 # lookup function as we need to collect no information
1614 # from filenodes.
1617 # from filenodes.
1615 group = filerevlog.group(msng_filenode_lst,
1618 group = filerevlog.group(msng_filenode_lst,
1616 lookup_filenode_link_func(fname))
1619 lookup_filenode_link_func(fname))
1617 for chnk in group:
1620 for chnk in group:
1618 yield chnk
1621 yield chnk
1619 if msng_filenode_set.has_key(fname):
1622 if msng_filenode_set.has_key(fname):
1620 # Don't need this anymore, toss it to free memory.
1623 # Don't need this anymore, toss it to free memory.
1621 del msng_filenode_set[fname]
1624 del msng_filenode_set[fname]
1622 # Signal that no more groups are left.
1625 # Signal that no more groups are left.
1623 yield changegroup.closechunk()
1626 yield changegroup.closechunk()
1624
1627
1625 if msng_cl_lst:
1628 if msng_cl_lst:
1626 self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source)
1629 self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source)
1627
1630
1628 return util.chunkbuffer(gengroup())
1631 return util.chunkbuffer(gengroup())
1629
1632
1630 def changegroup(self, basenodes, source):
1633 def changegroup(self, basenodes, source):
1631 """Generate a changegroup of all nodes that we have that a recipient
1634 """Generate a changegroup of all nodes that we have that a recipient
1632 doesn't.
1635 doesn't.
1633
1636
1634 This is much easier than the previous function as we can assume that
1637 This is much easier than the previous function as we can assume that
1635 the recipient has any changenode we aren't sending them."""
1638 the recipient has any changenode we aren't sending them."""
1636
1639
1637 self.hook('preoutgoing', throw=True, source=source)
1640 self.hook('preoutgoing', throw=True, source=source)
1638
1641
1639 cl = self.changelog
1642 cl = self.changelog
1640 nodes = cl.nodesbetween(basenodes, None)[0]
1643 nodes = cl.nodesbetween(basenodes, None)[0]
1641 revset = dict.fromkeys([cl.rev(n) for n in nodes])
1644 revset = dict.fromkeys([cl.rev(n) for n in nodes])
1642 self.changegroupinfo(nodes)
1645 self.changegroupinfo(nodes)
1643
1646
1644 def identity(x):
1647 def identity(x):
1645 return x
1648 return x
1646
1649
1647 def gennodelst(revlog):
1650 def gennodelst(revlog):
1648 for r in xrange(0, revlog.count()):
1651 for r in xrange(0, revlog.count()):
1649 n = revlog.node(r)
1652 n = revlog.node(r)
1650 if revlog.linkrev(n) in revset:
1653 if revlog.linkrev(n) in revset:
1651 yield n
1654 yield n
1652
1655
1653 def changed_file_collector(changedfileset):
1656 def changed_file_collector(changedfileset):
1654 def collect_changed_files(clnode):
1657 def collect_changed_files(clnode):
1655 c = cl.read(clnode)
1658 c = cl.read(clnode)
1656 for fname in c[3]:
1659 for fname in c[3]:
1657 changedfileset[fname] = 1
1660 changedfileset[fname] = 1
1658 return collect_changed_files
1661 return collect_changed_files
1659
1662
1660 def lookuprevlink_func(revlog):
1663 def lookuprevlink_func(revlog):
1661 def lookuprevlink(n):
1664 def lookuprevlink(n):
1662 return cl.node(revlog.linkrev(n))
1665 return cl.node(revlog.linkrev(n))
1663 return lookuprevlink
1666 return lookuprevlink
1664
1667
1665 def gengroup():
1668 def gengroup():
1666 # construct a list of all changed files
1669 # construct a list of all changed files
1667 changedfiles = {}
1670 changedfiles = {}
1668
1671
1669 for chnk in cl.group(nodes, identity,
1672 for chnk in cl.group(nodes, identity,
1670 changed_file_collector(changedfiles)):
1673 changed_file_collector(changedfiles)):
1671 yield chnk
1674 yield chnk
1672 changedfiles = changedfiles.keys()
1675 changedfiles = changedfiles.keys()
1673 changedfiles.sort()
1676 changedfiles.sort()
1674
1677
1675 mnfst = self.manifest
1678 mnfst = self.manifest
1676 nodeiter = gennodelst(mnfst)
1679 nodeiter = gennodelst(mnfst)
1677 for chnk in mnfst.group(nodeiter, lookuprevlink_func(mnfst)):
1680 for chnk in mnfst.group(nodeiter, lookuprevlink_func(mnfst)):
1678 yield chnk
1681 yield chnk
1679
1682
1680 for fname in changedfiles:
1683 for fname in changedfiles:
1681 filerevlog = self.file(fname)
1684 filerevlog = self.file(fname)
1682 nodeiter = gennodelst(filerevlog)
1685 nodeiter = gennodelst(filerevlog)
1683 nodeiter = list(nodeiter)
1686 nodeiter = list(nodeiter)
1684 if nodeiter:
1687 if nodeiter:
1685 yield changegroup.genchunk(fname)
1688 yield changegroup.genchunk(fname)
1686 lookup = lookuprevlink_func(filerevlog)
1689 lookup = lookuprevlink_func(filerevlog)
1687 for chnk in filerevlog.group(nodeiter, lookup):
1690 for chnk in filerevlog.group(nodeiter, lookup):
1688 yield chnk
1691 yield chnk
1689
1692
1690 yield changegroup.closechunk()
1693 yield changegroup.closechunk()
1691
1694
1692 if nodes:
1695 if nodes:
1693 self.hook('outgoing', node=hex(nodes[0]), source=source)
1696 self.hook('outgoing', node=hex(nodes[0]), source=source)
1694
1697
1695 return util.chunkbuffer(gengroup())
1698 return util.chunkbuffer(gengroup())
1696
1699
1697 def addchangegroup(self, source, srctype, url):
1700 def addchangegroup(self, source, srctype, url):
1698 """add changegroup to repo.
1701 """add changegroup to repo.
1699 returns number of heads modified or added + 1."""
1702 returns number of heads modified or added + 1."""
1700
1703
1701 def csmap(x):
1704 def csmap(x):
1702 self.ui.debug(_("add changeset %s\n") % short(x))
1705 self.ui.debug(_("add changeset %s\n") % short(x))
1703 return cl.count()
1706 return cl.count()
1704
1707
1705 def revmap(x):
1708 def revmap(x):
1706 return cl.rev(x)
1709 return cl.rev(x)
1707
1710
1708 if not source:
1711 if not source:
1709 return 0
1712 return 0
1710
1713
1711 self.hook('prechangegroup', throw=True, source=srctype, url=url)
1714 self.hook('prechangegroup', throw=True, source=srctype, url=url)
1712
1715
1713 changesets = files = revisions = 0
1716 changesets = files = revisions = 0
1714
1717
1715 tr = self.transaction()
1718 tr = self.transaction()
1716
1719
1717 # write changelog data to temp files so concurrent readers will not see
1720 # write changelog data to temp files so concurrent readers will not see
1718 # inconsistent view
1721 # inconsistent view
1719 cl = None
1722 cl = None
1720 try:
1723 try:
1721 cl = appendfile.appendchangelog(self.sopener,
1724 cl = appendfile.appendchangelog(self.sopener,
1722 self.changelog.version)
1725 self.changelog.version)
1723
1726
1724 oldheads = len(cl.heads())
1727 oldheads = len(cl.heads())
1725
1728
1726 # pull off the changeset group
1729 # pull off the changeset group
1727 self.ui.status(_("adding changesets\n"))
1730 self.ui.status(_("adding changesets\n"))
1728 cor = cl.count() - 1
1731 cor = cl.count() - 1
1729 chunkiter = changegroup.chunkiter(source)
1732 chunkiter = changegroup.chunkiter(source)
1730 if cl.addgroup(chunkiter, csmap, tr, 1) is None:
1733 if cl.addgroup(chunkiter, csmap, tr, 1) is None:
1731 raise util.Abort(_("received changelog group is empty"))
1734 raise util.Abort(_("received changelog group is empty"))
1732 cnr = cl.count() - 1
1735 cnr = cl.count() - 1
1733 changesets = cnr - cor
1736 changesets = cnr - cor
1734
1737
1735 # pull off the manifest group
1738 # pull off the manifest group
1736 self.ui.status(_("adding manifests\n"))
1739 self.ui.status(_("adding manifests\n"))
1737 chunkiter = changegroup.chunkiter(source)
1740 chunkiter = changegroup.chunkiter(source)
1738 # no need to check for empty manifest group here:
1741 # no need to check for empty manifest group here:
1739 # if the result of the merge of 1 and 2 is the same in 3 and 4,
1742 # if the result of the merge of 1 and 2 is the same in 3 and 4,
1740 # no new manifest will be created and the manifest group will
1743 # no new manifest will be created and the manifest group will
1741 # be empty during the pull
1744 # be empty during the pull
1742 self.manifest.addgroup(chunkiter, revmap, tr)
1745 self.manifest.addgroup(chunkiter, revmap, tr)
1743
1746
1744 # process the files
1747 # process the files
1745 self.ui.status(_("adding file changes\n"))
1748 self.ui.status(_("adding file changes\n"))
1746 while 1:
1749 while 1:
1747 f = changegroup.getchunk(source)
1750 f = changegroup.getchunk(source)
1748 if not f:
1751 if not f:
1749 break
1752 break
1750 self.ui.debug(_("adding %s revisions\n") % f)
1753 self.ui.debug(_("adding %s revisions\n") % f)
1751 fl = self.file(f)
1754 fl = self.file(f)
1752 o = fl.count()
1755 o = fl.count()
1753 chunkiter = changegroup.chunkiter(source)
1756 chunkiter = changegroup.chunkiter(source)
1754 if fl.addgroup(chunkiter, revmap, tr) is None:
1757 if fl.addgroup(chunkiter, revmap, tr) is None:
1755 raise util.Abort(_("received file revlog group is empty"))
1758 raise util.Abort(_("received file revlog group is empty"))
1756 revisions += fl.count() - o
1759 revisions += fl.count() - o
1757 files += 1
1760 files += 1
1758
1761
1759 cl.writedata()
1762 cl.writedata()
1760 finally:
1763 finally:
1761 if cl:
1764 if cl:
1762 cl.cleanup()
1765 cl.cleanup()
1763
1766
1764 # make changelog see real files again
1767 # make changelog see real files again
1765 self.changelog = changelog.changelog(self.sopener,
1768 self.changelog = changelog.changelog(self.sopener,
1766 self.changelog.version)
1769 self.changelog.version)
1767 self.changelog.checkinlinesize(tr)
1770 self.changelog.checkinlinesize(tr)
1768
1771
1769 newheads = len(self.changelog.heads())
1772 newheads = len(self.changelog.heads())
1770 heads = ""
1773 heads = ""
1771 if oldheads and newheads != oldheads:
1774 if oldheads and newheads != oldheads:
1772 heads = _(" (%+d heads)") % (newheads - oldheads)
1775 heads = _(" (%+d heads)") % (newheads - oldheads)
1773
1776
1774 self.ui.status(_("added %d changesets"
1777 self.ui.status(_("added %d changesets"
1775 " with %d changes to %d files%s\n")
1778 " with %d changes to %d files%s\n")
1776 % (changesets, revisions, files, heads))
1779 % (changesets, revisions, files, heads))
1777
1780
1778 if changesets > 0:
1781 if changesets > 0:
1779 self.hook('pretxnchangegroup', throw=True,
1782 self.hook('pretxnchangegroup', throw=True,
1780 node=hex(self.changelog.node(cor+1)), source=srctype,
1783 node=hex(self.changelog.node(cor+1)), source=srctype,
1781 url=url)
1784 url=url)
1782
1785
1783 tr.close()
1786 tr.close()
1784
1787
1785 if changesets > 0:
1788 if changesets > 0:
1786 self.hook("changegroup", node=hex(self.changelog.node(cor+1)),
1789 self.hook("changegroup", node=hex(self.changelog.node(cor+1)),
1787 source=srctype, url=url)
1790 source=srctype, url=url)
1788
1791
1789 for i in xrange(cor + 1, cnr + 1):
1792 for i in xrange(cor + 1, cnr + 1):
1790 self.hook("incoming", node=hex(self.changelog.node(i)),
1793 self.hook("incoming", node=hex(self.changelog.node(i)),
1791 source=srctype, url=url)
1794 source=srctype, url=url)
1792
1795
1793 return newheads - oldheads + 1
1796 return newheads - oldheads + 1
1794
1797
1795
1798
1796 def stream_in(self, remote):
1799 def stream_in(self, remote):
1797 fp = remote.stream_out()
1800 fp = remote.stream_out()
1798 l = fp.readline()
1801 l = fp.readline()
1799 try:
1802 try:
1800 resp = int(l)
1803 resp = int(l)
1801 except ValueError:
1804 except ValueError:
1802 raise util.UnexpectedOutput(
1805 raise util.UnexpectedOutput(
1803 _('Unexpected response from remote server:'), l)
1806 _('Unexpected response from remote server:'), l)
1804 if resp != 0:
1807 if resp != 0:
1805 raise util.Abort(_('operation forbidden by server'))
1808 raise util.Abort(_('operation forbidden by server'))
1806 self.ui.status(_('streaming all changes\n'))
1809 self.ui.status(_('streaming all changes\n'))
1807 l = fp.readline()
1810 l = fp.readline()
1808 try:
1811 try:
1809 total_files, total_bytes = map(int, l.split(' ', 1))
1812 total_files, total_bytes = map(int, l.split(' ', 1))
1810 except ValueError, TypeError:
1813 except ValueError, TypeError:
1811 raise util.UnexpectedOutput(
1814 raise util.UnexpectedOutput(
1812 _('Unexpected response from remote server:'), l)
1815 _('Unexpected response from remote server:'), l)
1813 self.ui.status(_('%d files to transfer, %s of data\n') %
1816 self.ui.status(_('%d files to transfer, %s of data\n') %
1814 (total_files, util.bytecount(total_bytes)))
1817 (total_files, util.bytecount(total_bytes)))
1815 start = time.time()
1818 start = time.time()
1816 for i in xrange(total_files):
1819 for i in xrange(total_files):
1817 l = fp.readline()
1820 l = fp.readline()
1818 try:
1821 try:
1819 name, size = l.split('\0', 1)
1822 name, size = l.split('\0', 1)
1820 size = int(size)
1823 size = int(size)
1821 except ValueError, TypeError:
1824 except ValueError, TypeError:
1822 raise util.UnexpectedOutput(
1825 raise util.UnexpectedOutput(
1823 _('Unexpected response from remote server:'), l)
1826 _('Unexpected response from remote server:'), l)
1824 self.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size)))
1827 self.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size)))
1825 ofp = self.sopener(name, 'w')
1828 ofp = self.sopener(name, 'w')
1826 for chunk in util.filechunkiter(fp, limit=size):
1829 for chunk in util.filechunkiter(fp, limit=size):
1827 ofp.write(chunk)
1830 ofp.write(chunk)
1828 ofp.close()
1831 ofp.close()
1829 elapsed = time.time() - start
1832 elapsed = time.time() - start
1830 self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') %
1833 self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') %
1831 (util.bytecount(total_bytes), elapsed,
1834 (util.bytecount(total_bytes), elapsed,
1832 util.bytecount(total_bytes / elapsed)))
1835 util.bytecount(total_bytes / elapsed)))
1833 self.reload()
1836 self.reload()
1834 return len(self.heads()) + 1
1837 return len(self.heads()) + 1
1835
1838
1836 def clone(self, remote, heads=[], stream=False):
1839 def clone(self, remote, heads=[], stream=False):
1837 '''clone remote repository.
1840 '''clone remote repository.
1838
1841
1839 keyword arguments:
1842 keyword arguments:
1840 heads: list of revs to clone (forces use of pull)
1843 heads: list of revs to clone (forces use of pull)
1841 stream: use streaming clone if possible'''
1844 stream: use streaming clone if possible'''
1842
1845
1843 # now, all clients that can request uncompressed clones can
1846 # now, all clients that can request uncompressed clones can
1844 # read repo formats supported by all servers that can serve
1847 # read repo formats supported by all servers that can serve
1845 # them.
1848 # them.
1846
1849
1847 # if revlog format changes, client will have to check version
1850 # if revlog format changes, client will have to check version
1848 # and format flags on "stream" capability, and use
1851 # and format flags on "stream" capability, and use
1849 # uncompressed only if compatible.
1852 # uncompressed only if compatible.
1850
1853
1851 if stream and not heads and remote.capable('stream'):
1854 if stream and not heads and remote.capable('stream'):
1852 return self.stream_in(remote)
1855 return self.stream_in(remote)
1853 return self.pull(remote, heads)
1856 return self.pull(remote, heads)
1854
1857
1855 # used to avoid circular references so destructors work
1858 # used to avoid circular references so destructors work
1856 def aftertrans(base):
1859 def aftertrans(base):
1857 p = base
1860 p = base
1858 def a():
1861 def a():
1859 util.rename(os.path.join(p, "journal"), os.path.join(p, "undo"))
1862 util.rename(os.path.join(p, "journal"), os.path.join(p, "undo"))
1860 util.rename(os.path.join(p, "journal.dirstate"),
1863 util.rename(os.path.join(p, "journal.dirstate"),
1861 os.path.join(p, "undo.dirstate"))
1864 os.path.join(p, "undo.dirstate"))
1862 return a
1865 return a
1863
1866
1864 def instance(ui, path, create):
1867 def instance(ui, path, create):
1865 return localrepository(ui, util.drop_scheme('file', path), create)
1868 return localrepository(ui, util.drop_scheme('file', path), create)
1866
1869
1867 def islocal(path):
1870 def islocal(path):
1868 return True
1871 return True
General Comments 0
You need to be logged in to leave comments. Login now