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