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