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