##// END OF EJS Templates
merge with stable
Matt Mackall -
r25270:61b3529e merge default
parent child Browse files
Show More
@@ -1,439 +1,443 b''
1 1 # branchmap.py - logic to computes, maintain and stores branchmap for local repo
2 2 #
3 3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from node import bin, hex, nullid, nullrev
9 9 import encoding
10 10 import scmutil
11 11 import util
12 12 import time
13 13 from array import array
14 14 from struct import calcsize, pack, unpack
15 15
16 16 def _filename(repo):
17 17 """name of a branchcache file for a given repo or repoview"""
18 18 filename = "cache/branch2"
19 19 if repo.filtername:
20 20 filename = '%s-%s' % (filename, repo.filtername)
21 21 return filename
22 22
23 23 def read(repo):
24 24 try:
25 25 f = repo.vfs(_filename(repo))
26 26 lines = f.read().split('\n')
27 27 f.close()
28 28 except (IOError, OSError):
29 29 return None
30 30
31 31 try:
32 32 cachekey = lines.pop(0).split(" ", 2)
33 33 last, lrev = cachekey[:2]
34 34 last, lrev = bin(last), int(lrev)
35 35 filteredhash = None
36 36 if len(cachekey) > 2:
37 37 filteredhash = bin(cachekey[2])
38 38 partial = branchcache(tipnode=last, tiprev=lrev,
39 39 filteredhash=filteredhash)
40 40 if not partial.validfor(repo):
41 41 # invalidate the cache
42 42 raise ValueError('tip differs')
43 43 for l in lines:
44 44 if not l:
45 45 continue
46 46 node, state, label = l.split(" ", 2)
47 47 if state not in 'oc':
48 48 raise ValueError('invalid branch state')
49 49 label = encoding.tolocal(label.strip())
50 50 if not node in repo:
51 51 raise ValueError('node %s does not exist' % node)
52 52 node = bin(node)
53 53 partial.setdefault(label, []).append(node)
54 54 if state == 'c':
55 55 partial._closednodes.add(node)
56 56 except KeyboardInterrupt:
57 57 raise
58 58 except Exception, inst:
59 59 if repo.ui.debugflag:
60 60 msg = 'invalid branchheads cache'
61 61 if repo.filtername is not None:
62 62 msg += ' (%s)' % repo.filtername
63 63 msg += ': %s\n'
64 64 repo.ui.debug(msg % inst)
65 65 partial = None
66 66 return partial
67 67
68 68 ### Nearest subset relation
69 69 # Nearest subset of filter X is a filter Y so that:
70 70 # * Y is included in X,
71 71 # * X - Y is as small as possible.
72 72 # This create and ordering used for branchmap purpose.
73 73 # the ordering may be partial
74 74 subsettable = {None: 'visible',
75 75 'visible': 'served',
76 76 'served': 'immutable',
77 77 'immutable': 'base'}
78 78
79 79 def updatecache(repo):
80 80 cl = repo.changelog
81 81 filtername = repo.filtername
82 82 partial = repo._branchcaches.get(filtername)
83 83
84 84 revs = []
85 85 if partial is None or not partial.validfor(repo):
86 86 partial = read(repo)
87 87 if partial is None:
88 88 subsetname = subsettable.get(filtername)
89 89 if subsetname is None:
90 90 partial = branchcache()
91 91 else:
92 92 subset = repo.filtered(subsetname)
93 93 partial = subset.branchmap().copy()
94 94 extrarevs = subset.changelog.filteredrevs - cl.filteredrevs
95 95 revs.extend(r for r in extrarevs if r <= partial.tiprev)
96 96 revs.extend(cl.revs(start=partial.tiprev + 1))
97 97 if revs:
98 98 partial.update(repo, revs)
99 99 partial.write(repo)
100 100
101 101 assert partial.validfor(repo), filtername
102 102 repo._branchcaches[repo.filtername] = partial
103 103
104 104 class branchcache(dict):
105 105 """A dict like object that hold branches heads cache.
106 106
107 107 This cache is used to avoid costly computations to determine all the
108 108 branch heads of a repo.
109 109
110 110 The cache is serialized on disk in the following format:
111 111
112 112 <tip hex node> <tip rev number> [optional filtered repo hex hash]
113 113 <branch head hex node> <open/closed state> <branch name>
114 114 <branch head hex node> <open/closed state> <branch name>
115 115 ...
116 116
117 117 The first line is used to check if the cache is still valid. If the
118 118 branch cache is for a filtered repo view, an optional third hash is
119 119 included that hashes the hashes of all filtered revisions.
120 120
121 121 The open/closed state is represented by a single letter 'o' or 'c'.
122 122 This field can be used to avoid changelog reads when determining if a
123 123 branch head closes a branch or not.
124 124 """
125 125
126 126 def __init__(self, entries=(), tipnode=nullid, tiprev=nullrev,
127 127 filteredhash=None, closednodes=None):
128 128 super(branchcache, self).__init__(entries)
129 129 self.tipnode = tipnode
130 130 self.tiprev = tiprev
131 131 self.filteredhash = filteredhash
132 132 # closednodes is a set of nodes that close their branch. If the branch
133 133 # cache has been updated, it may contain nodes that are no longer
134 134 # heads.
135 135 if closednodes is None:
136 136 self._closednodes = set()
137 137 else:
138 138 self._closednodes = closednodes
139 139
140 140 def validfor(self, repo):
141 141 """Is the cache content valid regarding a repo
142 142
143 143 - False when cached tipnode is unknown or if we detect a strip.
144 144 - True when cache is up to date or a subset of current repo."""
145 145 try:
146 146 return ((self.tipnode == repo.changelog.node(self.tiprev))
147 147 and (self.filteredhash == \
148 148 scmutil.filteredhash(repo, self.tiprev)))
149 149 except IndexError:
150 150 return False
151 151
152 152 def _branchtip(self, heads):
153 153 '''Return tuple with last open head in heads and false,
154 154 otherwise return last closed head and true.'''
155 155 tip = heads[-1]
156 156 closed = True
157 157 for h in reversed(heads):
158 158 if h not in self._closednodes:
159 159 tip = h
160 160 closed = False
161 161 break
162 162 return tip, closed
163 163
164 164 def branchtip(self, branch):
165 165 '''Return the tipmost open head on branch head, otherwise return the
166 166 tipmost closed head on branch.
167 167 Raise KeyError for unknown branch.'''
168 168 return self._branchtip(self[branch])[0]
169 169
170 170 def branchheads(self, branch, closed=False):
171 171 heads = self[branch]
172 172 if not closed:
173 173 heads = [h for h in heads if h not in self._closednodes]
174 174 return heads
175 175
176 176 def iterbranches(self):
177 177 for bn, heads in self.iteritems():
178 178 yield (bn, heads) + self._branchtip(heads)
179 179
180 180 def copy(self):
181 181 """return an deep copy of the branchcache object"""
182 182 return branchcache(self, self.tipnode, self.tiprev, self.filteredhash,
183 183 self._closednodes)
184 184
185 185 def write(self, repo):
186 186 try:
187 187 f = repo.vfs(_filename(repo), "w", atomictemp=True)
188 188 cachekey = [hex(self.tipnode), str(self.tiprev)]
189 189 if self.filteredhash is not None:
190 190 cachekey.append(hex(self.filteredhash))
191 191 f.write(" ".join(cachekey) + '\n')
192 192 nodecount = 0
193 193 for label, nodes in sorted(self.iteritems()):
194 194 for node in nodes:
195 195 nodecount += 1
196 196 if node in self._closednodes:
197 197 state = 'c'
198 198 else:
199 199 state = 'o'
200 200 f.write("%s %s %s\n" % (hex(node), state,
201 201 encoding.fromlocal(label)))
202 202 f.close()
203 203 repo.ui.log('branchcache',
204 204 'wrote %s branch cache with %d labels and %d nodes\n',
205 205 repo.filtername, len(self), nodecount)
206 206 except (IOError, OSError, util.Abort), inst:
207 207 repo.ui.debug("couldn't write branch cache: %s\n" % inst)
208 208 # Abort may be raise by read only opener
209 209 pass
210 210
211 211 def update(self, repo, revgen):
212 212 """Given a branchhead cache, self, that may have extra nodes or be
213 213 missing heads, and a generator of nodes that are strictly a superset of
214 214 heads missing, this function updates self to be correct.
215 215 """
216 216 starttime = time.time()
217 217 cl = repo.changelog
218 218 # collect new branch entries
219 219 newbranches = {}
220 220 getbranchinfo = repo.revbranchcache().branchinfo
221 221 for r in revgen:
222 222 branch, closesbranch = getbranchinfo(r)
223 223 newbranches.setdefault(branch, []).append(r)
224 224 if closesbranch:
225 225 self._closednodes.add(cl.node(r))
226 226
227 227 # fetch current topological heads to speed up filtering
228 228 topoheads = set(cl.headrevs())
229 229
230 230 # if older branchheads are reachable from new ones, they aren't
231 231 # really branchheads. Note checking parents is insufficient:
232 232 # 1 (branch a) -> 2 (branch b) -> 3 (branch a)
233 233 for branch, newheadrevs in newbranches.iteritems():
234 234 bheads = self.setdefault(branch, [])
235 235 bheadset = set(cl.rev(node) for node in bheads)
236 236
237 237 # This have been tested True on all internal usage of this function.
238 238 # run it again in case of doubt
239 239 # assert not (set(bheadrevs) & set(newheadrevs))
240 240 newheadrevs.sort()
241 241 bheadset.update(newheadrevs)
242 242
243 243 # This prunes out two kinds of heads - heads that are superseded by
244 244 # a head in newheadrevs, and newheadrevs that are not heads because
245 245 # an existing head is their descendant.
246 246 uncertain = bheadset - topoheads
247 247 if uncertain:
248 248 floorrev = min(uncertain)
249 249 ancestors = set(cl.ancestors(newheadrevs, floorrev))
250 250 bheadset -= ancestors
251 251 bheadrevs = sorted(bheadset)
252 252 self[branch] = [cl.node(rev) for rev in bheadrevs]
253 253 tiprev = bheadrevs[-1]
254 254 if tiprev > self.tiprev:
255 255 self.tipnode = cl.node(tiprev)
256 256 self.tiprev = tiprev
257 257
258 258 if not self.validfor(repo):
259 259 # cache key are not valid anymore
260 260 self.tipnode = nullid
261 261 self.tiprev = nullrev
262 262 for heads in self.values():
263 263 tiprev = max(cl.rev(node) for node in heads)
264 264 if tiprev > self.tiprev:
265 265 self.tipnode = cl.node(tiprev)
266 266 self.tiprev = tiprev
267 267 self.filteredhash = scmutil.filteredhash(repo, self.tiprev)
268 268
269 269 duration = time.time() - starttime
270 270 repo.ui.log('branchcache', 'updated %s branch cache in %.4f seconds\n',
271 271 repo.filtername, duration)
272 272
273 273 # Revision branch info cache
274 274
275 275 _rbcversion = '-v1'
276 276 _rbcnames = 'cache/rbc-names' + _rbcversion
277 277 _rbcrevs = 'cache/rbc-revs' + _rbcversion
278 278 # [4 byte hash prefix][4 byte branch name number with sign bit indicating open]
279 279 _rbcrecfmt = '>4sI'
280 280 _rbcrecsize = calcsize(_rbcrecfmt)
281 281 _rbcnodelen = 4
282 282 _rbcbranchidxmask = 0x7fffffff
283 283 _rbccloseflag = 0x80000000
284 284
285 285 class revbranchcache(object):
286 286 """Persistent cache, mapping from revision number to branch name and close.
287 287 This is a low level cache, independent of filtering.
288 288
289 289 Branch names are stored in rbc-names in internal encoding separated by 0.
290 290 rbc-names is append-only, and each branch name is only stored once and will
291 291 thus have a unique index.
292 292
293 293 The branch info for each revision is stored in rbc-revs as constant size
294 294 records. The whole file is read into memory, but it is only 'parsed' on
295 295 demand. The file is usually append-only but will be truncated if repo
296 296 modification is detected.
297 297 The record for each revision contains the first 4 bytes of the
298 298 corresponding node hash, and the record is only used if it still matches.
299 299 Even a completely trashed rbc-revs fill thus still give the right result
300 300 while converging towards full recovery ... assuming no incorrectly matching
301 301 node hashes.
302 302 The record also contains 4 bytes where 31 bits contains the index of the
303 303 branch and the last bit indicate that it is a branch close commit.
304 304 The usage pattern for rbc-revs is thus somewhat similar to 00changelog.i
305 305 and will grow with it but be 1/8th of its size.
306 306 """
307 307
308 308 def __init__(self, repo, readonly=True):
309 309 assert repo.filtername is None
310 310 self._repo = repo
311 311 self._names = [] # branch names in local encoding with static index
312 312 self._rbcrevs = array('c') # structs of type _rbcrecfmt
313 313 self._rbcsnameslen = 0
314 314 try:
315 315 bndata = repo.vfs.read(_rbcnames)
316 316 self._rbcsnameslen = len(bndata) # for verification before writing
317 317 self._names = [encoding.tolocal(bn) for bn in bndata.split('\0')]
318 318 except (IOError, OSError), inst:
319 319 if readonly:
320 320 # don't try to use cache - fall back to the slow path
321 321 self.branchinfo = self._branchinfo
322 322
323 323 if self._names:
324 324 try:
325 325 data = repo.vfs.read(_rbcrevs)
326 326 self._rbcrevs.fromstring(data)
327 327 except (IOError, OSError), inst:
328 328 repo.ui.debug("couldn't read revision branch cache: %s\n" %
329 329 inst)
330 330 # remember number of good records on disk
331 331 self._rbcrevslen = min(len(self._rbcrevs) // _rbcrecsize,
332 332 len(repo.changelog))
333 333 if self._rbcrevslen == 0:
334 334 self._names = []
335 335 self._rbcnamescount = len(self._names) # number of good names on disk
336 336 self._namesreverse = dict((b, r) for r, b in enumerate(self._names))
337 337
338 338 def branchinfo(self, rev):
339 339 """Return branch name and close flag for rev, using and updating
340 340 persistent cache."""
341 341 changelog = self._repo.changelog
342 342 rbcrevidx = rev * _rbcrecsize
343 343
344 # avoid negative index, changelog.read(nullrev) is fast without cache
345 if rev == nullrev:
346 return changelog.branchinfo(rev)
347
344 348 # if requested rev is missing, add and populate all missing revs
345 349 if len(self._rbcrevs) < rbcrevidx + _rbcrecsize:
346 350 self._rbcrevs.extend('\0' * (len(changelog) * _rbcrecsize -
347 351 len(self._rbcrevs)))
348 352
349 353 # fast path: extract data from cache, use it if node is matching
350 354 reponode = changelog.node(rev)[:_rbcnodelen]
351 355 cachenode, branchidx = unpack(
352 356 _rbcrecfmt, buffer(self._rbcrevs, rbcrevidx, _rbcrecsize))
353 357 close = bool(branchidx & _rbccloseflag)
354 358 if close:
355 359 branchidx &= _rbcbranchidxmask
356 360 if cachenode == '\0\0\0\0':
357 361 pass
358 362 elif cachenode == reponode:
359 363 return self._names[branchidx], close
360 364 else:
361 365 # rev/node map has changed, invalidate the cache from here up
362 366 truncate = rbcrevidx + _rbcrecsize
363 367 del self._rbcrevs[truncate:]
364 368 self._rbcrevslen = min(self._rbcrevslen, truncate)
365 369
366 370 # fall back to slow path and make sure it will be written to disk
367 371 return self._branchinfo(rev)
368 372
369 373 def _branchinfo(self, rev):
370 374 """Retrieve branch info from changelog and update _rbcrevs"""
371 375 changelog = self._repo.changelog
372 376 b, close = changelog.branchinfo(rev)
373 377 if b in self._namesreverse:
374 378 branchidx = self._namesreverse[b]
375 379 else:
376 380 branchidx = len(self._names)
377 381 self._names.append(b)
378 382 self._namesreverse[b] = branchidx
379 383 reponode = changelog.node(rev)
380 384 if close:
381 385 branchidx |= _rbccloseflag
382 386 self._setcachedata(rev, reponode, branchidx)
383 387 return b, close
384 388
385 389 def _setcachedata(self, rev, node, branchidx):
386 390 """Writes the node's branch data to the in-memory cache data."""
387 391 rbcrevidx = rev * _rbcrecsize
388 392 rec = array('c')
389 393 rec.fromstring(pack(_rbcrecfmt, node, branchidx))
390 394 self._rbcrevs[rbcrevidx:rbcrevidx + _rbcrecsize] = rec
391 395 self._rbcrevslen = min(self._rbcrevslen, rev)
392 396
393 397 tr = self._repo.currenttransaction()
394 398 if tr:
395 399 tr.addfinalize('write-revbranchcache', self.write)
396 400
397 401 def write(self, tr=None):
398 402 """Save branch cache if it is dirty."""
399 403 repo = self._repo
400 404 if self._rbcnamescount < len(self._names):
401 405 try:
402 406 if self._rbcnamescount != 0:
403 407 f = repo.vfs.open(_rbcnames, 'ab')
404 408 if f.tell() == self._rbcsnameslen:
405 409 f.write('\0')
406 410 else:
407 411 f.close()
408 412 repo.ui.debug("%s changed - rewriting it\n" % _rbcnames)
409 413 self._rbcnamescount = 0
410 414 self._rbcrevslen = 0
411 415 if self._rbcnamescount == 0:
412 416 f = repo.vfs.open(_rbcnames, 'wb')
413 417 f.write('\0'.join(encoding.fromlocal(b)
414 418 for b in self._names[self._rbcnamescount:]))
415 419 self._rbcsnameslen = f.tell()
416 420 f.close()
417 421 except (IOError, OSError, util.Abort), inst:
418 422 repo.ui.debug("couldn't write revision branch cache names: "
419 423 "%s\n" % inst)
420 424 return
421 425 self._rbcnamescount = len(self._names)
422 426
423 427 start = self._rbcrevslen * _rbcrecsize
424 428 if start != len(self._rbcrevs):
425 429 revs = min(len(repo.changelog), len(self._rbcrevs) // _rbcrecsize)
426 430 try:
427 431 f = repo.vfs.open(_rbcrevs, 'ab')
428 432 if f.tell() != start:
429 433 repo.ui.debug("truncating %s to %s\n" % (_rbcrevs, start))
430 434 f.seek(start)
431 435 f.truncate()
432 436 end = revs * _rbcrecsize
433 437 f.write(self._rbcrevs[start:end])
434 438 f.close()
435 439 except (IOError, OSError, util.Abort), inst:
436 440 repo.ui.debug("couldn't write revision branch cache: %s\n" %
437 441 inst)
438 442 return
439 443 self._rbcrevslen = revs
@@ -1,1937 +1,1938 b''
1 1 # localrepo.py - read/write repository class for mercurial
2 2 #
3 3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7 from node import hex, nullid, short
8 8 from i18n import _
9 9 import urllib
10 10 import peer, changegroup, subrepo, pushkey, obsolete, repoview
11 11 import changelog, dirstate, filelog, manifest, context, bookmarks, phases
12 12 import lock as lockmod
13 13 import transaction, store, encoding, exchange, bundle2
14 14 import scmutil, util, extensions, hook, error, revset
15 15 import match as matchmod
16 16 import merge as mergemod
17 17 import tags as tagsmod
18 18 from lock import release
19 import weakref, errno, os, time, inspect
19 import weakref, errno, os, time, inspect, random
20 20 import branchmap, pathutil
21 21 import namespaces
22 22 propertycache = util.propertycache
23 23 filecache = scmutil.filecache
24 24
25 25 class repofilecache(filecache):
26 26 """All filecache usage on repo are done for logic that should be unfiltered
27 27 """
28 28
29 29 def __get__(self, repo, type=None):
30 30 return super(repofilecache, self).__get__(repo.unfiltered(), type)
31 31 def __set__(self, repo, value):
32 32 return super(repofilecache, self).__set__(repo.unfiltered(), value)
33 33 def __delete__(self, repo):
34 34 return super(repofilecache, self).__delete__(repo.unfiltered())
35 35
36 36 class storecache(repofilecache):
37 37 """filecache for files in the store"""
38 38 def join(self, obj, fname):
39 39 return obj.sjoin(fname)
40 40
41 41 class unfilteredpropertycache(propertycache):
42 42 """propertycache that apply to unfiltered repo only"""
43 43
44 44 def __get__(self, repo, type=None):
45 45 unfi = repo.unfiltered()
46 46 if unfi is repo:
47 47 return super(unfilteredpropertycache, self).__get__(unfi)
48 48 return getattr(unfi, self.name)
49 49
50 50 class filteredpropertycache(propertycache):
51 51 """propertycache that must take filtering in account"""
52 52
53 53 def cachevalue(self, obj, value):
54 54 object.__setattr__(obj, self.name, value)
55 55
56 56
57 57 def hasunfilteredcache(repo, name):
58 58 """check if a repo has an unfilteredpropertycache value for <name>"""
59 59 return name in vars(repo.unfiltered())
60 60
61 61 def unfilteredmethod(orig):
62 62 """decorate method that always need to be run on unfiltered version"""
63 63 def wrapper(repo, *args, **kwargs):
64 64 return orig(repo.unfiltered(), *args, **kwargs)
65 65 return wrapper
66 66
67 67 moderncaps = set(('lookup', 'branchmap', 'pushkey', 'known', 'getbundle',
68 68 'unbundle'))
69 69 legacycaps = moderncaps.union(set(['changegroupsubset']))
70 70
71 71 class localpeer(peer.peerrepository):
72 72 '''peer for a local repo; reflects only the most recent API'''
73 73
74 74 def __init__(self, repo, caps=moderncaps):
75 75 peer.peerrepository.__init__(self)
76 76 self._repo = repo.filtered('served')
77 77 self.ui = repo.ui
78 78 self._caps = repo._restrictcapabilities(caps)
79 79 self.requirements = repo.requirements
80 80 self.supportedformats = repo.supportedformats
81 81
82 82 def close(self):
83 83 self._repo.close()
84 84
85 85 def _capabilities(self):
86 86 return self._caps
87 87
88 88 def local(self):
89 89 return self._repo
90 90
91 91 def canpush(self):
92 92 return True
93 93
94 94 def url(self):
95 95 return self._repo.url()
96 96
97 97 def lookup(self, key):
98 98 return self._repo.lookup(key)
99 99
100 100 def branchmap(self):
101 101 return self._repo.branchmap()
102 102
103 103 def heads(self):
104 104 return self._repo.heads()
105 105
106 106 def known(self, nodes):
107 107 return self._repo.known(nodes)
108 108
109 109 def getbundle(self, source, heads=None, common=None, bundlecaps=None,
110 110 **kwargs):
111 111 cg = exchange.getbundle(self._repo, source, heads=heads,
112 112 common=common, bundlecaps=bundlecaps, **kwargs)
113 113 if bundlecaps is not None and 'HG20' in bundlecaps:
114 114 # When requesting a bundle2, getbundle returns a stream to make the
115 115 # wire level function happier. We need to build a proper object
116 116 # from it in local peer.
117 117 cg = bundle2.getunbundler(self.ui, cg)
118 118 return cg
119 119
120 120 # TODO We might want to move the next two calls into legacypeer and add
121 121 # unbundle instead.
122 122
123 123 def unbundle(self, cg, heads, url):
124 124 """apply a bundle on a repo
125 125
126 126 This function handles the repo locking itself."""
127 127 try:
128 128 try:
129 129 cg = exchange.readbundle(self.ui, cg, None)
130 130 ret = exchange.unbundle(self._repo, cg, heads, 'push', url)
131 131 if util.safehasattr(ret, 'getchunks'):
132 132 # This is a bundle20 object, turn it into an unbundler.
133 133 # This little dance should be dropped eventually when the
134 134 # API is finally improved.
135 135 stream = util.chunkbuffer(ret.getchunks())
136 136 ret = bundle2.getunbundler(self.ui, stream)
137 137 return ret
138 138 except Exception, exc:
139 139 # If the exception contains output salvaged from a bundle2
140 140 # reply, we need to make sure it is printed before continuing
141 141 # to fail. So we build a bundle2 with such output and consume
142 142 # it directly.
143 143 #
144 144 # This is not very elegant but allows a "simple" solution for
145 145 # issue4594
146 146 output = getattr(exc, '_bundle2salvagedoutput', ())
147 147 if output:
148 148 bundler = bundle2.bundle20(self._repo.ui)
149 149 for out in output:
150 150 bundler.addpart(out)
151 151 stream = util.chunkbuffer(bundler.getchunks())
152 152 b = bundle2.getunbundler(self.ui, stream)
153 153 bundle2.processbundle(self._repo, b)
154 154 raise
155 155 except error.PushRaced, exc:
156 156 raise error.ResponseError(_('push failed:'), str(exc))
157 157
158 158 def lock(self):
159 159 return self._repo.lock()
160 160
161 161 def addchangegroup(self, cg, source, url):
162 162 return changegroup.addchangegroup(self._repo, cg, source, url)
163 163
164 164 def pushkey(self, namespace, key, old, new):
165 165 return self._repo.pushkey(namespace, key, old, new)
166 166
167 167 def listkeys(self, namespace):
168 168 return self._repo.listkeys(namespace)
169 169
170 170 def debugwireargs(self, one, two, three=None, four=None, five=None):
171 171 '''used to test argument passing over the wire'''
172 172 return "%s %s %s %s %s" % (one, two, three, four, five)
173 173
174 174 class locallegacypeer(localpeer):
175 175 '''peer extension which implements legacy methods too; used for tests with
176 176 restricted capabilities'''
177 177
178 178 def __init__(self, repo):
179 179 localpeer.__init__(self, repo, caps=legacycaps)
180 180
181 181 def branches(self, nodes):
182 182 return self._repo.branches(nodes)
183 183
184 184 def between(self, pairs):
185 185 return self._repo.between(pairs)
186 186
187 187 def changegroup(self, basenodes, source):
188 188 return changegroup.changegroup(self._repo, basenodes, source)
189 189
190 190 def changegroupsubset(self, bases, heads, source):
191 191 return changegroup.changegroupsubset(self._repo, bases, heads, source)
192 192
193 193 class localrepository(object):
194 194
195 195 supportedformats = set(('revlogv1', 'generaldelta', 'treemanifest',
196 196 'manifestv2'))
197 197 _basesupported = supportedformats | set(('store', 'fncache', 'shared',
198 198 'dotencode'))
199 199 openerreqs = set(('revlogv1', 'generaldelta', 'treemanifest', 'manifestv2'))
200 200 filtername = None
201 201
202 202 # a list of (ui, featureset) functions.
203 203 # only functions defined in module of enabled extensions are invoked
204 204 featuresetupfuncs = set()
205 205
206 206 def _baserequirements(self, create):
207 207 return ['revlogv1']
208 208
209 209 def __init__(self, baseui, path=None, create=False):
210 210 self.requirements = set()
211 211 self.wvfs = scmutil.vfs(path, expandpath=True, realpath=True)
212 212 self.wopener = self.wvfs
213 213 self.root = self.wvfs.base
214 214 self.path = self.wvfs.join(".hg")
215 215 self.origroot = path
216 216 self.auditor = pathutil.pathauditor(self.root, self._checknested)
217 217 self.vfs = scmutil.vfs(self.path)
218 218 self.opener = self.vfs
219 219 self.baseui = baseui
220 220 self.ui = baseui.copy()
221 221 self.ui.copy = baseui.copy # prevent copying repo configuration
222 222 # A list of callback to shape the phase if no data were found.
223 223 # Callback are in the form: func(repo, roots) --> processed root.
224 224 # This list it to be filled by extension during repo setup
225 225 self._phasedefaults = []
226 226 try:
227 227 self.ui.readconfig(self.join("hgrc"), self.root)
228 228 extensions.loadall(self.ui)
229 229 except IOError:
230 230 pass
231 231
232 232 if self.featuresetupfuncs:
233 233 self.supported = set(self._basesupported) # use private copy
234 234 extmods = set(m.__name__ for n, m
235 235 in extensions.extensions(self.ui))
236 236 for setupfunc in self.featuresetupfuncs:
237 237 if setupfunc.__module__ in extmods:
238 238 setupfunc(self.ui, self.supported)
239 239 else:
240 240 self.supported = self._basesupported
241 241
242 242 if not self.vfs.isdir():
243 243 if create:
244 244 if not self.wvfs.exists():
245 245 self.wvfs.makedirs()
246 246 self.vfs.makedir(notindexed=True)
247 247 self.requirements.update(self._baserequirements(create))
248 248 if self.ui.configbool('format', 'usestore', True):
249 249 self.vfs.mkdir("store")
250 250 self.requirements.add("store")
251 251 if self.ui.configbool('format', 'usefncache', True):
252 252 self.requirements.add("fncache")
253 253 if self.ui.configbool('format', 'dotencode', True):
254 254 self.requirements.add('dotencode')
255 255 # create an invalid changelog
256 256 self.vfs.append(
257 257 "00changelog.i",
258 258 '\0\0\0\2' # represents revlogv2
259 259 ' dummy changelog to prevent using the old repo layout'
260 260 )
261 261 if self.ui.configbool('format', 'generaldelta', False):
262 262 self.requirements.add("generaldelta")
263 263 if self.ui.configbool('experimental', 'treemanifest', False):
264 264 self.requirements.add("treemanifest")
265 265 if self.ui.configbool('experimental', 'manifestv2', False):
266 266 self.requirements.add("manifestv2")
267 267 else:
268 268 raise error.RepoError(_("repository %s not found") % path)
269 269 elif create:
270 270 raise error.RepoError(_("repository %s already exists") % path)
271 271 else:
272 272 try:
273 273 self.requirements = scmutil.readrequires(
274 274 self.vfs, self.supported)
275 275 except IOError, inst:
276 276 if inst.errno != errno.ENOENT:
277 277 raise
278 278
279 279 self.sharedpath = self.path
280 280 try:
281 281 vfs = scmutil.vfs(self.vfs.read("sharedpath").rstrip('\n'),
282 282 realpath=True)
283 283 s = vfs.base
284 284 if not vfs.exists():
285 285 raise error.RepoError(
286 286 _('.hg/sharedpath points to nonexistent directory %s') % s)
287 287 self.sharedpath = s
288 288 except IOError, inst:
289 289 if inst.errno != errno.ENOENT:
290 290 raise
291 291
292 292 self.store = store.store(
293 293 self.requirements, self.sharedpath, scmutil.vfs)
294 294 self.spath = self.store.path
295 295 self.svfs = self.store.vfs
296 296 self.sopener = self.svfs
297 297 self.sjoin = self.store.join
298 298 self.vfs.createmode = self.store.createmode
299 299 self._applyopenerreqs()
300 300 if create:
301 301 self._writerequirements()
302 302
303 303
304 304 self._branchcaches = {}
305 305 self._revbranchcache = None
306 306 self.filterpats = {}
307 307 self._datafilters = {}
308 308 self._transref = self._lockref = self._wlockref = None
309 309
310 310 # A cache for various files under .hg/ that tracks file changes,
311 311 # (used by the filecache decorator)
312 312 #
313 313 # Maps a property name to its util.filecacheentry
314 314 self._filecache = {}
315 315
316 316 # hold sets of revision to be filtered
317 317 # should be cleared when something might have changed the filter value:
318 318 # - new changesets,
319 319 # - phase change,
320 320 # - new obsolescence marker,
321 321 # - working directory parent change,
322 322 # - bookmark changes
323 323 self.filteredrevcache = {}
324 324
325 325 # generic mapping between names and nodes
326 326 self.names = namespaces.namespaces()
327 327
328 328 def close(self):
329 329 self._writecaches()
330 330
331 331 def _writecaches(self):
332 332 if self._revbranchcache:
333 333 self._revbranchcache.write()
334 334
335 335 def _restrictcapabilities(self, caps):
336 336 if self.ui.configbool('experimental', 'bundle2-advertise', True):
337 337 caps = set(caps)
338 338 capsblob = bundle2.encodecaps(bundle2.getrepocaps(self))
339 339 caps.add('bundle2=' + urllib.quote(capsblob))
340 340 return caps
341 341
342 342 def _applyopenerreqs(self):
343 343 self.svfs.options = dict((r, 1) for r in self.requirements
344 344 if r in self.openerreqs)
345 345 chunkcachesize = self.ui.configint('format', 'chunkcachesize')
346 346 if chunkcachesize is not None:
347 347 self.svfs.options['chunkcachesize'] = chunkcachesize
348 348 maxchainlen = self.ui.configint('format', 'maxchainlen')
349 349 if maxchainlen is not None:
350 350 self.svfs.options['maxchainlen'] = maxchainlen
351 351 manifestcachesize = self.ui.configint('format', 'manifestcachesize')
352 352 if manifestcachesize is not None:
353 353 self.svfs.options['manifestcachesize'] = manifestcachesize
354 354
355 355 def _writerequirements(self):
356 356 scmutil.writerequires(self.vfs, self.requirements)
357 357
358 358 def _checknested(self, path):
359 359 """Determine if path is a legal nested repository."""
360 360 if not path.startswith(self.root):
361 361 return False
362 362 subpath = path[len(self.root) + 1:]
363 363 normsubpath = util.pconvert(subpath)
364 364
365 365 # XXX: Checking against the current working copy is wrong in
366 366 # the sense that it can reject things like
367 367 #
368 368 # $ hg cat -r 10 sub/x.txt
369 369 #
370 370 # if sub/ is no longer a subrepository in the working copy
371 371 # parent revision.
372 372 #
373 373 # However, it can of course also allow things that would have
374 374 # been rejected before, such as the above cat command if sub/
375 375 # is a subrepository now, but was a normal directory before.
376 376 # The old path auditor would have rejected by mistake since it
377 377 # panics when it sees sub/.hg/.
378 378 #
379 379 # All in all, checking against the working copy seems sensible
380 380 # since we want to prevent access to nested repositories on
381 381 # the filesystem *now*.
382 382 ctx = self[None]
383 383 parts = util.splitpath(subpath)
384 384 while parts:
385 385 prefix = '/'.join(parts)
386 386 if prefix in ctx.substate:
387 387 if prefix == normsubpath:
388 388 return True
389 389 else:
390 390 sub = ctx.sub(prefix)
391 391 return sub.checknested(subpath[len(prefix) + 1:])
392 392 else:
393 393 parts.pop()
394 394 return False
395 395
396 396 def peer(self):
397 397 return localpeer(self) # not cached to avoid reference cycle
398 398
399 399 def unfiltered(self):
400 400 """Return unfiltered version of the repository
401 401
402 402 Intended to be overwritten by filtered repo."""
403 403 return self
404 404
405 405 def filtered(self, name):
406 406 """Return a filtered version of a repository"""
407 407 # build a new class with the mixin and the current class
408 408 # (possibly subclass of the repo)
409 409 class proxycls(repoview.repoview, self.unfiltered().__class__):
410 410 pass
411 411 return proxycls(self, name)
412 412
413 413 @repofilecache('bookmarks')
414 414 def _bookmarks(self):
415 415 return bookmarks.bmstore(self)
416 416
417 417 @repofilecache('bookmarks.current')
418 418 def _activebookmark(self):
419 419 return bookmarks.readactive(self)
420 420
421 421 def bookmarkheads(self, bookmark):
422 422 name = bookmark.split('@', 1)[0]
423 423 heads = []
424 424 for mark, n in self._bookmarks.iteritems():
425 425 if mark.split('@', 1)[0] == name:
426 426 heads.append(n)
427 427 return heads
428 428
429 429 @storecache('phaseroots')
430 430 def _phasecache(self):
431 431 return phases.phasecache(self, self._phasedefaults)
432 432
433 433 @storecache('obsstore')
434 434 def obsstore(self):
435 435 # read default format for new obsstore.
436 436 defaultformat = self.ui.configint('format', 'obsstore-version', None)
437 437 # rely on obsstore class default when possible.
438 438 kwargs = {}
439 439 if defaultformat is not None:
440 440 kwargs['defaultformat'] = defaultformat
441 441 readonly = not obsolete.isenabled(self, obsolete.createmarkersopt)
442 442 store = obsolete.obsstore(self.svfs, readonly=readonly,
443 443 **kwargs)
444 444 if store and readonly:
445 445 self.ui.warn(
446 446 _('obsolete feature not enabled but %i markers found!\n')
447 447 % len(list(store)))
448 448 return store
449 449
450 450 @storecache('00changelog.i')
451 451 def changelog(self):
452 452 c = changelog.changelog(self.svfs)
453 453 if 'HG_PENDING' in os.environ:
454 454 p = os.environ['HG_PENDING']
455 455 if p.startswith(self.root):
456 456 c.readpending('00changelog.i.a')
457 457 return c
458 458
459 459 @storecache('00manifest.i')
460 460 def manifest(self):
461 461 return manifest.manifest(self.svfs)
462 462
463 463 def dirlog(self, dir):
464 464 return self.manifest.dirlog(dir)
465 465
466 466 @repofilecache('dirstate')
467 467 def dirstate(self):
468 468 warned = [0]
469 469 def validate(node):
470 470 try:
471 471 self.changelog.rev(node)
472 472 return node
473 473 except error.LookupError:
474 474 if not warned[0]:
475 475 warned[0] = True
476 476 self.ui.warn(_("warning: ignoring unknown"
477 477 " working parent %s!\n") % short(node))
478 478 return nullid
479 479
480 480 return dirstate.dirstate(self.vfs, self.ui, self.root, validate)
481 481
482 482 def __getitem__(self, changeid):
483 483 if changeid is None:
484 484 return context.workingctx(self)
485 485 if isinstance(changeid, slice):
486 486 return [context.changectx(self, i)
487 487 for i in xrange(*changeid.indices(len(self)))
488 488 if i not in self.changelog.filteredrevs]
489 489 return context.changectx(self, changeid)
490 490
491 491 def __contains__(self, changeid):
492 492 try:
493 493 self[changeid]
494 494 return True
495 495 except error.RepoLookupError:
496 496 return False
497 497
498 498 def __nonzero__(self):
499 499 return True
500 500
501 501 def __len__(self):
502 502 return len(self.changelog)
503 503
504 504 def __iter__(self):
505 505 return iter(self.changelog)
506 506
507 507 def revs(self, expr, *args):
508 508 '''Return a list of revisions matching the given revset'''
509 509 expr = revset.formatspec(expr, *args)
510 510 m = revset.match(None, expr)
511 511 return m(self)
512 512
513 513 def set(self, expr, *args):
514 514 '''
515 515 Yield a context for each matching revision, after doing arg
516 516 replacement via revset.formatspec
517 517 '''
518 518 for r in self.revs(expr, *args):
519 519 yield self[r]
520 520
521 521 def url(self):
522 522 return 'file:' + self.root
523 523
524 524 def hook(self, name, throw=False, **args):
525 525 """Call a hook, passing this repo instance.
526 526
527 527 This a convenience method to aid invoking hooks. Extensions likely
528 528 won't call this unless they have registered a custom hook or are
529 529 replacing code that is expected to call a hook.
530 530 """
531 531 return hook.hook(self.ui, self, name, throw, **args)
532 532
533 533 @unfilteredmethod
534 534 def _tag(self, names, node, message, local, user, date, extra={},
535 535 editor=False):
536 536 if isinstance(names, str):
537 537 names = (names,)
538 538
539 539 branches = self.branchmap()
540 540 for name in names:
541 541 self.hook('pretag', throw=True, node=hex(node), tag=name,
542 542 local=local)
543 543 if name in branches:
544 544 self.ui.warn(_("warning: tag %s conflicts with existing"
545 545 " branch name\n") % name)
546 546
547 547 def writetags(fp, names, munge, prevtags):
548 548 fp.seek(0, 2)
549 549 if prevtags and prevtags[-1] != '\n':
550 550 fp.write('\n')
551 551 for name in names:
552 552 if munge:
553 553 m = munge(name)
554 554 else:
555 555 m = name
556 556
557 557 if (self._tagscache.tagtypes and
558 558 name in self._tagscache.tagtypes):
559 559 old = self.tags().get(name, nullid)
560 560 fp.write('%s %s\n' % (hex(old), m))
561 561 fp.write('%s %s\n' % (hex(node), m))
562 562 fp.close()
563 563
564 564 prevtags = ''
565 565 if local:
566 566 try:
567 567 fp = self.vfs('localtags', 'r+')
568 568 except IOError:
569 569 fp = self.vfs('localtags', 'a')
570 570 else:
571 571 prevtags = fp.read()
572 572
573 573 # local tags are stored in the current charset
574 574 writetags(fp, names, None, prevtags)
575 575 for name in names:
576 576 self.hook('tag', node=hex(node), tag=name, local=local)
577 577 return
578 578
579 579 try:
580 580 fp = self.wfile('.hgtags', 'rb+')
581 581 except IOError, e:
582 582 if e.errno != errno.ENOENT:
583 583 raise
584 584 fp = self.wfile('.hgtags', 'ab')
585 585 else:
586 586 prevtags = fp.read()
587 587
588 588 # committed tags are stored in UTF-8
589 589 writetags(fp, names, encoding.fromlocal, prevtags)
590 590
591 591 fp.close()
592 592
593 593 self.invalidatecaches()
594 594
595 595 if '.hgtags' not in self.dirstate:
596 596 self[None].add(['.hgtags'])
597 597
598 598 m = matchmod.exact(self.root, '', ['.hgtags'])
599 599 tagnode = self.commit(message, user, date, extra=extra, match=m,
600 600 editor=editor)
601 601
602 602 for name in names:
603 603 self.hook('tag', node=hex(node), tag=name, local=local)
604 604
605 605 return tagnode
606 606
607 607 def tag(self, names, node, message, local, user, date, editor=False):
608 608 '''tag a revision with one or more symbolic names.
609 609
610 610 names is a list of strings or, when adding a single tag, names may be a
611 611 string.
612 612
613 613 if local is True, the tags are stored in a per-repository file.
614 614 otherwise, they are stored in the .hgtags file, and a new
615 615 changeset is committed with the change.
616 616
617 617 keyword arguments:
618 618
619 619 local: whether to store tags in non-version-controlled file
620 620 (default False)
621 621
622 622 message: commit message to use if committing
623 623
624 624 user: name of user to use if committing
625 625
626 626 date: date tuple to use if committing'''
627 627
628 628 if not local:
629 629 m = matchmod.exact(self.root, '', ['.hgtags'])
630 630 if any(self.status(match=m, unknown=True, ignored=True)):
631 631 raise util.Abort(_('working copy of .hgtags is changed'),
632 632 hint=_('please commit .hgtags manually'))
633 633
634 634 self.tags() # instantiate the cache
635 635 self._tag(names, node, message, local, user, date, editor=editor)
636 636
637 637 @filteredpropertycache
638 638 def _tagscache(self):
639 639 '''Returns a tagscache object that contains various tags related
640 640 caches.'''
641 641
642 642 # This simplifies its cache management by having one decorated
643 643 # function (this one) and the rest simply fetch things from it.
644 644 class tagscache(object):
645 645 def __init__(self):
646 646 # These two define the set of tags for this repository. tags
647 647 # maps tag name to node; tagtypes maps tag name to 'global' or
648 648 # 'local'. (Global tags are defined by .hgtags across all
649 649 # heads, and local tags are defined in .hg/localtags.)
650 650 # They constitute the in-memory cache of tags.
651 651 self.tags = self.tagtypes = None
652 652
653 653 self.nodetagscache = self.tagslist = None
654 654
655 655 cache = tagscache()
656 656 cache.tags, cache.tagtypes = self._findtags()
657 657
658 658 return cache
659 659
660 660 def tags(self):
661 661 '''return a mapping of tag to node'''
662 662 t = {}
663 663 if self.changelog.filteredrevs:
664 664 tags, tt = self._findtags()
665 665 else:
666 666 tags = self._tagscache.tags
667 667 for k, v in tags.iteritems():
668 668 try:
669 669 # ignore tags to unknown nodes
670 670 self.changelog.rev(v)
671 671 t[k] = v
672 672 except (error.LookupError, ValueError):
673 673 pass
674 674 return t
675 675
676 676 def _findtags(self):
677 677 '''Do the hard work of finding tags. Return a pair of dicts
678 678 (tags, tagtypes) where tags maps tag name to node, and tagtypes
679 679 maps tag name to a string like \'global\' or \'local\'.
680 680 Subclasses or extensions are free to add their own tags, but
681 681 should be aware that the returned dicts will be retained for the
682 682 duration of the localrepo object.'''
683 683
684 684 # XXX what tagtype should subclasses/extensions use? Currently
685 685 # mq and bookmarks add tags, but do not set the tagtype at all.
686 686 # Should each extension invent its own tag type? Should there
687 687 # be one tagtype for all such "virtual" tags? Or is the status
688 688 # quo fine?
689 689
690 690 alltags = {} # map tag name to (node, hist)
691 691 tagtypes = {}
692 692
693 693 tagsmod.findglobaltags(self.ui, self, alltags, tagtypes)
694 694 tagsmod.readlocaltags(self.ui, self, alltags, tagtypes)
695 695
696 696 # Build the return dicts. Have to re-encode tag names because
697 697 # the tags module always uses UTF-8 (in order not to lose info
698 698 # writing to the cache), but the rest of Mercurial wants them in
699 699 # local encoding.
700 700 tags = {}
701 701 for (name, (node, hist)) in alltags.iteritems():
702 702 if node != nullid:
703 703 tags[encoding.tolocal(name)] = node
704 704 tags['tip'] = self.changelog.tip()
705 705 tagtypes = dict([(encoding.tolocal(name), value)
706 706 for (name, value) in tagtypes.iteritems()])
707 707 return (tags, tagtypes)
708 708
709 709 def tagtype(self, tagname):
710 710 '''
711 711 return the type of the given tag. result can be:
712 712
713 713 'local' : a local tag
714 714 'global' : a global tag
715 715 None : tag does not exist
716 716 '''
717 717
718 718 return self._tagscache.tagtypes.get(tagname)
719 719
720 720 def tagslist(self):
721 721 '''return a list of tags ordered by revision'''
722 722 if not self._tagscache.tagslist:
723 723 l = []
724 724 for t, n in self.tags().iteritems():
725 725 l.append((self.changelog.rev(n), t, n))
726 726 self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)]
727 727
728 728 return self._tagscache.tagslist
729 729
730 730 def nodetags(self, node):
731 731 '''return the tags associated with a node'''
732 732 if not self._tagscache.nodetagscache:
733 733 nodetagscache = {}
734 734 for t, n in self._tagscache.tags.iteritems():
735 735 nodetagscache.setdefault(n, []).append(t)
736 736 for tags in nodetagscache.itervalues():
737 737 tags.sort()
738 738 self._tagscache.nodetagscache = nodetagscache
739 739 return self._tagscache.nodetagscache.get(node, [])
740 740
741 741 def nodebookmarks(self, node):
742 742 marks = []
743 743 for bookmark, n in self._bookmarks.iteritems():
744 744 if n == node:
745 745 marks.append(bookmark)
746 746 return sorted(marks)
747 747
748 748 def branchmap(self):
749 749 '''returns a dictionary {branch: [branchheads]} with branchheads
750 750 ordered by increasing revision number'''
751 751 branchmap.updatecache(self)
752 752 return self._branchcaches[self.filtername]
753 753
754 754 @unfilteredmethod
755 755 def revbranchcache(self):
756 756 if not self._revbranchcache:
757 757 self._revbranchcache = branchmap.revbranchcache(self.unfiltered())
758 758 return self._revbranchcache
759 759
760 760 def branchtip(self, branch, ignoremissing=False):
761 761 '''return the tip node for a given branch
762 762
763 763 If ignoremissing is True, then this method will not raise an error.
764 764 This is helpful for callers that only expect None for a missing branch
765 765 (e.g. namespace).
766 766
767 767 '''
768 768 try:
769 769 return self.branchmap().branchtip(branch)
770 770 except KeyError:
771 771 if not ignoremissing:
772 772 raise error.RepoLookupError(_("unknown branch '%s'") % branch)
773 773 else:
774 774 pass
775 775
776 776 def lookup(self, key):
777 777 return self[key].node()
778 778
779 779 def lookupbranch(self, key, remote=None):
780 780 repo = remote or self
781 781 if key in repo.branchmap():
782 782 return key
783 783
784 784 repo = (remote and remote.local()) and remote or self
785 785 return repo[key].branch()
786 786
787 787 def known(self, nodes):
788 788 nm = self.changelog.nodemap
789 789 pc = self._phasecache
790 790 result = []
791 791 for n in nodes:
792 792 r = nm.get(n)
793 793 resp = not (r is None or pc.phase(self, r) >= phases.secret)
794 794 result.append(resp)
795 795 return result
796 796
797 797 def local(self):
798 798 return self
799 799
800 800 def cancopy(self):
801 801 # so statichttprepo's override of local() works
802 802 if not self.local():
803 803 return False
804 804 if not self.ui.configbool('phases', 'publish', True):
805 805 return True
806 806 # if publishing we can't copy if there is filtered content
807 807 return not self.filtered('visible').changelog.filteredrevs
808 808
809 809 def shared(self):
810 810 '''the type of shared repository (None if not shared)'''
811 811 if self.sharedpath != self.path:
812 812 return 'store'
813 813 return None
814 814
815 815 def join(self, f, *insidef):
816 816 return self.vfs.join(os.path.join(f, *insidef))
817 817
818 818 def wjoin(self, f, *insidef):
819 819 return self.vfs.reljoin(self.root, f, *insidef)
820 820
821 821 def file(self, f):
822 822 if f[0] == '/':
823 823 f = f[1:]
824 824 return filelog.filelog(self.svfs, f)
825 825
826 826 def changectx(self, changeid):
827 827 return self[changeid]
828 828
829 829 def parents(self, changeid=None):
830 830 '''get list of changectxs for parents of changeid'''
831 831 return self[changeid].parents()
832 832
833 833 def setparents(self, p1, p2=nullid):
834 834 self.dirstate.beginparentchange()
835 835 copies = self.dirstate.setparents(p1, p2)
836 836 pctx = self[p1]
837 837 if copies:
838 838 # Adjust copy records, the dirstate cannot do it, it
839 839 # requires access to parents manifests. Preserve them
840 840 # only for entries added to first parent.
841 841 for f in copies:
842 842 if f not in pctx and copies[f] in pctx:
843 843 self.dirstate.copy(copies[f], f)
844 844 if p2 == nullid:
845 845 for f, s in sorted(self.dirstate.copies().items()):
846 846 if f not in pctx and s not in pctx:
847 847 self.dirstate.copy(None, f)
848 848 self.dirstate.endparentchange()
849 849
850 850 def filectx(self, path, changeid=None, fileid=None):
851 851 """changeid can be a changeset revision, node, or tag.
852 852 fileid can be a file revision or node."""
853 853 return context.filectx(self, path, changeid, fileid)
854 854
855 855 def getcwd(self):
856 856 return self.dirstate.getcwd()
857 857
858 858 def pathto(self, f, cwd=None):
859 859 return self.dirstate.pathto(f, cwd)
860 860
861 861 def wfile(self, f, mode='r'):
862 862 return self.wvfs(f, mode)
863 863
864 864 def _link(self, f):
865 865 return self.wvfs.islink(f)
866 866
867 867 def _loadfilter(self, filter):
868 868 if filter not in self.filterpats:
869 869 l = []
870 870 for pat, cmd in self.ui.configitems(filter):
871 871 if cmd == '!':
872 872 continue
873 873 mf = matchmod.match(self.root, '', [pat])
874 874 fn = None
875 875 params = cmd
876 876 for name, filterfn in self._datafilters.iteritems():
877 877 if cmd.startswith(name):
878 878 fn = filterfn
879 879 params = cmd[len(name):].lstrip()
880 880 break
881 881 if not fn:
882 882 fn = lambda s, c, **kwargs: util.filter(s, c)
883 883 # Wrap old filters not supporting keyword arguments
884 884 if not inspect.getargspec(fn)[2]:
885 885 oldfn = fn
886 886 fn = lambda s, c, **kwargs: oldfn(s, c)
887 887 l.append((mf, fn, params))
888 888 self.filterpats[filter] = l
889 889 return self.filterpats[filter]
890 890
891 891 def _filter(self, filterpats, filename, data):
892 892 for mf, fn, cmd in filterpats:
893 893 if mf(filename):
894 894 self.ui.debug("filtering %s through %s\n" % (filename, cmd))
895 895 data = fn(data, cmd, ui=self.ui, repo=self, filename=filename)
896 896 break
897 897
898 898 return data
899 899
900 900 @unfilteredpropertycache
901 901 def _encodefilterpats(self):
902 902 return self._loadfilter('encode')
903 903
904 904 @unfilteredpropertycache
905 905 def _decodefilterpats(self):
906 906 return self._loadfilter('decode')
907 907
908 908 def adddatafilter(self, name, filter):
909 909 self._datafilters[name] = filter
910 910
911 911 def wread(self, filename):
912 912 if self._link(filename):
913 913 data = self.wvfs.readlink(filename)
914 914 else:
915 915 data = self.wvfs.read(filename)
916 916 return self._filter(self._encodefilterpats, filename, data)
917 917
918 918 def wwrite(self, filename, data, flags):
919 919 """write ``data`` into ``filename`` in the working directory
920 920
921 921 This returns length of written (maybe decoded) data.
922 922 """
923 923 data = self._filter(self._decodefilterpats, filename, data)
924 924 if 'l' in flags:
925 925 self.wvfs.symlink(data, filename)
926 926 else:
927 927 self.wvfs.write(filename, data)
928 928 if 'x' in flags:
929 929 self.wvfs.setflags(filename, False, True)
930 930 return len(data)
931 931
932 932 def wwritedata(self, filename, data):
933 933 return self._filter(self._decodefilterpats, filename, data)
934 934
935 935 def currenttransaction(self):
936 936 """return the current transaction or None if non exists"""
937 937 if self._transref:
938 938 tr = self._transref()
939 939 else:
940 940 tr = None
941 941
942 942 if tr and tr.running():
943 943 return tr
944 944 return None
945 945
946 946 def transaction(self, desc, report=None):
947 947 if (self.ui.configbool('devel', 'all')
948 948 or self.ui.configbool('devel', 'check-locks')):
949 949 l = self._lockref and self._lockref()
950 950 if l is None or not l.held:
951 951 scmutil.develwarn(self.ui, 'transaction with no lock')
952 952 tr = self.currenttransaction()
953 953 if tr is not None:
954 954 return tr.nest()
955 955
956 956 # abort here if the journal already exists
957 957 if self.svfs.exists("journal"):
958 958 raise error.RepoError(
959 959 _("abandoned transaction found"),
960 960 hint=_("run 'hg recover' to clean up transaction"))
961 961
962 self.hook('pretxnopen', throw=True, txnname=desc)
962 idbase = "%.40f#%f" % (random.random(), time.time())
963 txnid = 'TXN:' + util.sha1(idbase).hexdigest()
964 self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid)
963 965
964 966 self._writejournal(desc)
965 967 renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()]
966 968 if report:
967 969 rp = report
968 970 else:
969 971 rp = self.ui.warn
970 972 vfsmap = {'plain': self.vfs} # root of .hg/
971 973 # we must avoid cyclic reference between repo and transaction.
972 974 reporef = weakref.ref(self)
973 975 def validate(tr):
974 976 """will run pre-closing hooks"""
975 977 pending = lambda: tr.writepending() and self.root or ""
976 978 reporef().hook('pretxnclose', throw=True, pending=pending,
977 979 txnname=desc, **tr.hookargs)
978 980
979 981 tr = transaction.transaction(rp, self.sopener, vfsmap,
980 982 "journal",
981 983 "undo",
982 984 aftertrans(renames),
983 985 self.store.createmode,
984 986 validator=validate)
985 987
986 trid = 'TXN:' + util.sha1("%s#%f" % (id(tr), time.time())).hexdigest()
987 tr.hookargs['txnid'] = trid
988 tr.hookargs['txnid'] = txnid
988 989 # note: writing the fncache only during finalize mean that the file is
989 990 # outdated when running hooks. As fncache is used for streaming clone,
990 991 # this is not expected to break anything that happen during the hooks.
991 992 tr.addfinalize('flush-fncache', self.store.write)
992 993 def txnclosehook(tr2):
993 994 """To be run if transaction is successful, will schedule a hook run
994 995 """
995 996 def hook():
996 997 reporef().hook('txnclose', throw=False, txnname=desc,
997 998 **tr2.hookargs)
998 999 reporef()._afterlock(hook)
999 1000 tr.addfinalize('txnclose-hook', txnclosehook)
1000 1001 def txnaborthook(tr2):
1001 1002 """To be run if transaction is aborted
1002 1003 """
1003 1004 reporef().hook('txnabort', throw=False, txnname=desc,
1004 1005 **tr2.hookargs)
1005 1006 tr.addabort('txnabort-hook', txnaborthook)
1006 1007 self._transref = weakref.ref(tr)
1007 1008 return tr
1008 1009
1009 1010 def _journalfiles(self):
1010 1011 return ((self.svfs, 'journal'),
1011 1012 (self.vfs, 'journal.dirstate'),
1012 1013 (self.vfs, 'journal.branch'),
1013 1014 (self.vfs, 'journal.desc'),
1014 1015 (self.vfs, 'journal.bookmarks'),
1015 1016 (self.svfs, 'journal.phaseroots'))
1016 1017
1017 1018 def undofiles(self):
1018 1019 return [(vfs, undoname(x)) for vfs, x in self._journalfiles()]
1019 1020
1020 1021 def _writejournal(self, desc):
1021 1022 self.vfs.write("journal.dirstate",
1022 1023 self.vfs.tryread("dirstate"))
1023 1024 self.vfs.write("journal.branch",
1024 1025 encoding.fromlocal(self.dirstate.branch()))
1025 1026 self.vfs.write("journal.desc",
1026 1027 "%d\n%s\n" % (len(self), desc))
1027 1028 self.vfs.write("journal.bookmarks",
1028 1029 self.vfs.tryread("bookmarks"))
1029 1030 self.svfs.write("journal.phaseroots",
1030 1031 self.svfs.tryread("phaseroots"))
1031 1032
1032 1033 def recover(self):
1033 1034 lock = self.lock()
1034 1035 try:
1035 1036 if self.svfs.exists("journal"):
1036 1037 self.ui.status(_("rolling back interrupted transaction\n"))
1037 1038 vfsmap = {'': self.svfs,
1038 1039 'plain': self.vfs,}
1039 1040 transaction.rollback(self.svfs, vfsmap, "journal",
1040 1041 self.ui.warn)
1041 1042 self.invalidate()
1042 1043 return True
1043 1044 else:
1044 1045 self.ui.warn(_("no interrupted transaction available\n"))
1045 1046 return False
1046 1047 finally:
1047 1048 lock.release()
1048 1049
1049 1050 def rollback(self, dryrun=False, force=False):
1050 1051 wlock = lock = None
1051 1052 try:
1052 1053 wlock = self.wlock()
1053 1054 lock = self.lock()
1054 1055 if self.svfs.exists("undo"):
1055 1056 return self._rollback(dryrun, force)
1056 1057 else:
1057 1058 self.ui.warn(_("no rollback information available\n"))
1058 1059 return 1
1059 1060 finally:
1060 1061 release(lock, wlock)
1061 1062
1062 1063 @unfilteredmethod # Until we get smarter cache management
1063 1064 def _rollback(self, dryrun, force):
1064 1065 ui = self.ui
1065 1066 try:
1066 1067 args = self.vfs.read('undo.desc').splitlines()
1067 1068 (oldlen, desc, detail) = (int(args[0]), args[1], None)
1068 1069 if len(args) >= 3:
1069 1070 detail = args[2]
1070 1071 oldtip = oldlen - 1
1071 1072
1072 1073 if detail and ui.verbose:
1073 1074 msg = (_('repository tip rolled back to revision %s'
1074 1075 ' (undo %s: %s)\n')
1075 1076 % (oldtip, desc, detail))
1076 1077 else:
1077 1078 msg = (_('repository tip rolled back to revision %s'
1078 1079 ' (undo %s)\n')
1079 1080 % (oldtip, desc))
1080 1081 except IOError:
1081 1082 msg = _('rolling back unknown transaction\n')
1082 1083 desc = None
1083 1084
1084 1085 if not force and self['.'] != self['tip'] and desc == 'commit':
1085 1086 raise util.Abort(
1086 1087 _('rollback of last commit while not checked out '
1087 1088 'may lose data'), hint=_('use -f to force'))
1088 1089
1089 1090 ui.status(msg)
1090 1091 if dryrun:
1091 1092 return 0
1092 1093
1093 1094 parents = self.dirstate.parents()
1094 1095 self.destroying()
1095 1096 vfsmap = {'plain': self.vfs, '': self.svfs}
1096 1097 transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn)
1097 1098 if self.vfs.exists('undo.bookmarks'):
1098 1099 self.vfs.rename('undo.bookmarks', 'bookmarks')
1099 1100 if self.svfs.exists('undo.phaseroots'):
1100 1101 self.svfs.rename('undo.phaseroots', 'phaseroots')
1101 1102 self.invalidate()
1102 1103
1103 1104 parentgone = (parents[0] not in self.changelog.nodemap or
1104 1105 parents[1] not in self.changelog.nodemap)
1105 1106 if parentgone:
1106 1107 self.vfs.rename('undo.dirstate', 'dirstate')
1107 1108 try:
1108 1109 branch = self.vfs.read('undo.branch')
1109 1110 self.dirstate.setbranch(encoding.tolocal(branch))
1110 1111 except IOError:
1111 1112 ui.warn(_('named branch could not be reset: '
1112 1113 'current branch is still \'%s\'\n')
1113 1114 % self.dirstate.branch())
1114 1115
1115 1116 self.dirstate.invalidate()
1116 1117 parents = tuple([p.rev() for p in self.parents()])
1117 1118 if len(parents) > 1:
1118 1119 ui.status(_('working directory now based on '
1119 1120 'revisions %d and %d\n') % parents)
1120 1121 else:
1121 1122 ui.status(_('working directory now based on '
1122 1123 'revision %d\n') % parents)
1123 1124 ms = mergemod.mergestate(self)
1124 1125 ms.reset(self['.'].node())
1125 1126
1126 1127 # TODO: if we know which new heads may result from this rollback, pass
1127 1128 # them to destroy(), which will prevent the branchhead cache from being
1128 1129 # invalidated.
1129 1130 self.destroyed()
1130 1131 return 0
1131 1132
1132 1133 def invalidatecaches(self):
1133 1134
1134 1135 if '_tagscache' in vars(self):
1135 1136 # can't use delattr on proxy
1136 1137 del self.__dict__['_tagscache']
1137 1138
1138 1139 self.unfiltered()._branchcaches.clear()
1139 1140 self.invalidatevolatilesets()
1140 1141
1141 1142 def invalidatevolatilesets(self):
1142 1143 self.filteredrevcache.clear()
1143 1144 obsolete.clearobscaches(self)
1144 1145
1145 1146 def invalidatedirstate(self):
1146 1147 '''Invalidates the dirstate, causing the next call to dirstate
1147 1148 to check if it was modified since the last time it was read,
1148 1149 rereading it if it has.
1149 1150
1150 1151 This is different to dirstate.invalidate() that it doesn't always
1151 1152 rereads the dirstate. Use dirstate.invalidate() if you want to
1152 1153 explicitly read the dirstate again (i.e. restoring it to a previous
1153 1154 known good state).'''
1154 1155 if hasunfilteredcache(self, 'dirstate'):
1155 1156 for k in self.dirstate._filecache:
1156 1157 try:
1157 1158 delattr(self.dirstate, k)
1158 1159 except AttributeError:
1159 1160 pass
1160 1161 delattr(self.unfiltered(), 'dirstate')
1161 1162
1162 1163 def invalidate(self):
1163 1164 unfiltered = self.unfiltered() # all file caches are stored unfiltered
1164 1165 for k in self._filecache:
1165 1166 # dirstate is invalidated separately in invalidatedirstate()
1166 1167 if k == 'dirstate':
1167 1168 continue
1168 1169
1169 1170 try:
1170 1171 delattr(unfiltered, k)
1171 1172 except AttributeError:
1172 1173 pass
1173 1174 self.invalidatecaches()
1174 1175 self.store.invalidatecaches()
1175 1176
1176 1177 def invalidateall(self):
1177 1178 '''Fully invalidates both store and non-store parts, causing the
1178 1179 subsequent operation to reread any outside changes.'''
1179 1180 # extension should hook this to invalidate its caches
1180 1181 self.invalidate()
1181 1182 self.invalidatedirstate()
1182 1183
1183 1184 def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc):
1184 1185 try:
1185 1186 l = lockmod.lock(vfs, lockname, 0, releasefn, desc=desc)
1186 1187 except error.LockHeld, inst:
1187 1188 if not wait:
1188 1189 raise
1189 1190 self.ui.warn(_("waiting for lock on %s held by %r\n") %
1190 1191 (desc, inst.locker))
1191 1192 # default to 600 seconds timeout
1192 1193 l = lockmod.lock(vfs, lockname,
1193 1194 int(self.ui.config("ui", "timeout", "600")),
1194 1195 releasefn, desc=desc)
1195 1196 self.ui.warn(_("got lock after %s seconds\n") % l.delay)
1196 1197 if acquirefn:
1197 1198 acquirefn()
1198 1199 return l
1199 1200
1200 1201 def _afterlock(self, callback):
1201 1202 """add a callback to be run when the repository is fully unlocked
1202 1203
1203 1204 The callback will be executed when the outermost lock is released
1204 1205 (with wlock being higher level than 'lock')."""
1205 1206 for ref in (self._wlockref, self._lockref):
1206 1207 l = ref and ref()
1207 1208 if l and l.held:
1208 1209 l.postrelease.append(callback)
1209 1210 break
1210 1211 else: # no lock have been found.
1211 1212 callback()
1212 1213
1213 1214 def lock(self, wait=True):
1214 1215 '''Lock the repository store (.hg/store) and return a weak reference
1215 1216 to the lock. Use this before modifying the store (e.g. committing or
1216 1217 stripping). If you are opening a transaction, get a lock as well.)
1217 1218
1218 1219 If both 'lock' and 'wlock' must be acquired, ensure you always acquires
1219 1220 'wlock' first to avoid a dead-lock hazard.'''
1220 1221 l = self._lockref and self._lockref()
1221 1222 if l is not None and l.held:
1222 1223 l.lock()
1223 1224 return l
1224 1225
1225 1226 def unlock():
1226 1227 for k, ce in self._filecache.items():
1227 1228 if k == 'dirstate' or k not in self.__dict__:
1228 1229 continue
1229 1230 ce.refresh()
1230 1231
1231 1232 l = self._lock(self.svfs, "lock", wait, unlock,
1232 1233 self.invalidate, _('repository %s') % self.origroot)
1233 1234 self._lockref = weakref.ref(l)
1234 1235 return l
1235 1236
1236 1237 def wlock(self, wait=True):
1237 1238 '''Lock the non-store parts of the repository (everything under
1238 1239 .hg except .hg/store) and return a weak reference to the lock.
1239 1240
1240 1241 Use this before modifying files in .hg.
1241 1242
1242 1243 If both 'lock' and 'wlock' must be acquired, ensure you always acquires
1243 1244 'wlock' first to avoid a dead-lock hazard.'''
1244 1245 l = self._wlockref and self._wlockref()
1245 1246 if l is not None and l.held:
1246 1247 l.lock()
1247 1248 return l
1248 1249
1249 1250 # We do not need to check for non-waiting lock aquisition. Such
1250 1251 # acquisition would not cause dead-lock as they would just fail.
1251 1252 if wait and (self.ui.configbool('devel', 'all')
1252 1253 or self.ui.configbool('devel', 'check-locks')):
1253 1254 l = self._lockref and self._lockref()
1254 1255 if l is not None and l.held:
1255 1256 scmutil.develwarn(self.ui, '"wlock" acquired after "lock"')
1256 1257
1257 1258 def unlock():
1258 1259 if self.dirstate.pendingparentchange():
1259 1260 self.dirstate.invalidate()
1260 1261 else:
1261 1262 self.dirstate.write()
1262 1263
1263 1264 self._filecache['dirstate'].refresh()
1264 1265
1265 1266 l = self._lock(self.vfs, "wlock", wait, unlock,
1266 1267 self.invalidatedirstate, _('working directory of %s') %
1267 1268 self.origroot)
1268 1269 self._wlockref = weakref.ref(l)
1269 1270 return l
1270 1271
1271 1272 def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist):
1272 1273 """
1273 1274 commit an individual file as part of a larger transaction
1274 1275 """
1275 1276
1276 1277 fname = fctx.path()
1277 1278 fparent1 = manifest1.get(fname, nullid)
1278 1279 fparent2 = manifest2.get(fname, nullid)
1279 1280 if isinstance(fctx, context.filectx):
1280 1281 node = fctx.filenode()
1281 1282 if node in [fparent1, fparent2]:
1282 1283 self.ui.debug('reusing %s filelog entry\n' % fname)
1283 1284 return node
1284 1285
1285 1286 flog = self.file(fname)
1286 1287 meta = {}
1287 1288 copy = fctx.renamed()
1288 1289 if copy and copy[0] != fname:
1289 1290 # Mark the new revision of this file as a copy of another
1290 1291 # file. This copy data will effectively act as a parent
1291 1292 # of this new revision. If this is a merge, the first
1292 1293 # parent will be the nullid (meaning "look up the copy data")
1293 1294 # and the second one will be the other parent. For example:
1294 1295 #
1295 1296 # 0 --- 1 --- 3 rev1 changes file foo
1296 1297 # \ / rev2 renames foo to bar and changes it
1297 1298 # \- 2 -/ rev3 should have bar with all changes and
1298 1299 # should record that bar descends from
1299 1300 # bar in rev2 and foo in rev1
1300 1301 #
1301 1302 # this allows this merge to succeed:
1302 1303 #
1303 1304 # 0 --- 1 --- 3 rev4 reverts the content change from rev2
1304 1305 # \ / merging rev3 and rev4 should use bar@rev2
1305 1306 # \- 2 --- 4 as the merge base
1306 1307 #
1307 1308
1308 1309 cfname = copy[0]
1309 1310 crev = manifest1.get(cfname)
1310 1311 newfparent = fparent2
1311 1312
1312 1313 if manifest2: # branch merge
1313 1314 if fparent2 == nullid or crev is None: # copied on remote side
1314 1315 if cfname in manifest2:
1315 1316 crev = manifest2[cfname]
1316 1317 newfparent = fparent1
1317 1318
1318 1319 # Here, we used to search backwards through history to try to find
1319 1320 # where the file copy came from if the source of a copy was not in
1320 1321 # the parent directory. However, this doesn't actually make sense to
1321 1322 # do (what does a copy from something not in your working copy even
1322 1323 # mean?) and it causes bugs (eg, issue4476). Instead, we will warn
1323 1324 # the user that copy information was dropped, so if they didn't
1324 1325 # expect this outcome it can be fixed, but this is the correct
1325 1326 # behavior in this circumstance.
1326 1327
1327 1328 if crev:
1328 1329 self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev)))
1329 1330 meta["copy"] = cfname
1330 1331 meta["copyrev"] = hex(crev)
1331 1332 fparent1, fparent2 = nullid, newfparent
1332 1333 else:
1333 1334 self.ui.warn(_("warning: can't find ancestor for '%s' "
1334 1335 "copied from '%s'!\n") % (fname, cfname))
1335 1336
1336 1337 elif fparent1 == nullid:
1337 1338 fparent1, fparent2 = fparent2, nullid
1338 1339 elif fparent2 != nullid:
1339 1340 # is one parent an ancestor of the other?
1340 1341 fparentancestors = flog.commonancestorsheads(fparent1, fparent2)
1341 1342 if fparent1 in fparentancestors:
1342 1343 fparent1, fparent2 = fparent2, nullid
1343 1344 elif fparent2 in fparentancestors:
1344 1345 fparent2 = nullid
1345 1346
1346 1347 # is the file changed?
1347 1348 text = fctx.data()
1348 1349 if fparent2 != nullid or flog.cmp(fparent1, text) or meta:
1349 1350 changelist.append(fname)
1350 1351 return flog.add(text, meta, tr, linkrev, fparent1, fparent2)
1351 1352 # are just the flags changed during merge?
1352 1353 elif fname in manifest1 and manifest1.flags(fname) != fctx.flags():
1353 1354 changelist.append(fname)
1354 1355
1355 1356 return fparent1
1356 1357
1357 1358 @unfilteredmethod
1358 1359 def commit(self, text="", user=None, date=None, match=None, force=False,
1359 1360 editor=False, extra={}):
1360 1361 """Add a new revision to current repository.
1361 1362
1362 1363 Revision information is gathered from the working directory,
1363 1364 match can be used to filter the committed files. If editor is
1364 1365 supplied, it is called to get a commit message.
1365 1366 """
1366 1367
1367 1368 def fail(f, msg):
1368 1369 raise util.Abort('%s: %s' % (f, msg))
1369 1370
1370 1371 if not match:
1371 1372 match = matchmod.always(self.root, '')
1372 1373
1373 1374 if not force:
1374 1375 vdirs = []
1375 1376 match.explicitdir = vdirs.append
1376 1377 match.bad = fail
1377 1378
1378 1379 wlock = self.wlock()
1379 1380 try:
1380 1381 wctx = self[None]
1381 1382 merge = len(wctx.parents()) > 1
1382 1383
1383 1384 if not force and merge and match.ispartial():
1384 1385 raise util.Abort(_('cannot partially commit a merge '
1385 1386 '(do not specify files or patterns)'))
1386 1387
1387 1388 status = self.status(match=match, clean=force)
1388 1389 if force:
1389 1390 status.modified.extend(status.clean) # mq may commit clean files
1390 1391
1391 1392 # check subrepos
1392 1393 subs = []
1393 1394 commitsubs = set()
1394 1395 newstate = wctx.substate.copy()
1395 1396 # only manage subrepos and .hgsubstate if .hgsub is present
1396 1397 if '.hgsub' in wctx:
1397 1398 # we'll decide whether to track this ourselves, thanks
1398 1399 for c in status.modified, status.added, status.removed:
1399 1400 if '.hgsubstate' in c:
1400 1401 c.remove('.hgsubstate')
1401 1402
1402 1403 # compare current state to last committed state
1403 1404 # build new substate based on last committed state
1404 1405 oldstate = wctx.p1().substate
1405 1406 for s in sorted(newstate.keys()):
1406 1407 if not match(s):
1407 1408 # ignore working copy, use old state if present
1408 1409 if s in oldstate:
1409 1410 newstate[s] = oldstate[s]
1410 1411 continue
1411 1412 if not force:
1412 1413 raise util.Abort(
1413 1414 _("commit with new subrepo %s excluded") % s)
1414 1415 dirtyreason = wctx.sub(s).dirtyreason(True)
1415 1416 if dirtyreason:
1416 1417 if not self.ui.configbool('ui', 'commitsubrepos'):
1417 1418 raise util.Abort(dirtyreason,
1418 1419 hint=_("use --subrepos for recursive commit"))
1419 1420 subs.append(s)
1420 1421 commitsubs.add(s)
1421 1422 else:
1422 1423 bs = wctx.sub(s).basestate()
1423 1424 newstate[s] = (newstate[s][0], bs, newstate[s][2])
1424 1425 if oldstate.get(s, (None, None, None))[1] != bs:
1425 1426 subs.append(s)
1426 1427
1427 1428 # check for removed subrepos
1428 1429 for p in wctx.parents():
1429 1430 r = [s for s in p.substate if s not in newstate]
1430 1431 subs += [s for s in r if match(s)]
1431 1432 if subs:
1432 1433 if (not match('.hgsub') and
1433 1434 '.hgsub' in (wctx.modified() + wctx.added())):
1434 1435 raise util.Abort(
1435 1436 _("can't commit subrepos without .hgsub"))
1436 1437 status.modified.insert(0, '.hgsubstate')
1437 1438
1438 1439 elif '.hgsub' in status.removed:
1439 1440 # clean up .hgsubstate when .hgsub is removed
1440 1441 if ('.hgsubstate' in wctx and
1441 1442 '.hgsubstate' not in (status.modified + status.added +
1442 1443 status.removed)):
1443 1444 status.removed.insert(0, '.hgsubstate')
1444 1445
1445 1446 # make sure all explicit patterns are matched
1446 1447 if not force and match.files():
1447 1448 matched = set(status.modified + status.added + status.removed)
1448 1449
1449 1450 for f in match.files():
1450 1451 f = self.dirstate.normalize(f)
1451 1452 if f == '.' or f in matched or f in wctx.substate:
1452 1453 continue
1453 1454 if f in status.deleted:
1454 1455 fail(f, _('file not found!'))
1455 1456 if f in vdirs: # visited directory
1456 1457 d = f + '/'
1457 1458 for mf in matched:
1458 1459 if mf.startswith(d):
1459 1460 break
1460 1461 else:
1461 1462 fail(f, _("no match under directory!"))
1462 1463 elif f not in self.dirstate:
1463 1464 fail(f, _("file not tracked!"))
1464 1465
1465 1466 cctx = context.workingcommitctx(self, status,
1466 1467 text, user, date, extra)
1467 1468
1468 1469 allowemptycommit = (wctx.branch() != wctx.p1().branch()
1469 1470 or extra.get('close') or merge or cctx.files()
1470 1471 or self.ui.configbool('ui', 'allowemptycommit'))
1471 1472 if not allowemptycommit:
1472 1473 return None
1473 1474
1474 1475 if merge and cctx.deleted():
1475 1476 raise util.Abort(_("cannot commit merge with missing files"))
1476 1477
1477 1478 ms = mergemod.mergestate(self)
1478 1479 for f in status.modified:
1479 1480 if f in ms and ms[f] == 'u':
1480 1481 raise util.Abort(_('unresolved merge conflicts '
1481 1482 '(see "hg help resolve")'))
1482 1483
1483 1484 if editor:
1484 1485 cctx._text = editor(self, cctx, subs)
1485 1486 edited = (text != cctx._text)
1486 1487
1487 1488 # Save commit message in case this transaction gets rolled back
1488 1489 # (e.g. by a pretxncommit hook). Leave the content alone on
1489 1490 # the assumption that the user will use the same editor again.
1490 1491 msgfn = self.savecommitmessage(cctx._text)
1491 1492
1492 1493 # commit subs and write new state
1493 1494 if subs:
1494 1495 for s in sorted(commitsubs):
1495 1496 sub = wctx.sub(s)
1496 1497 self.ui.status(_('committing subrepository %s\n') %
1497 1498 subrepo.subrelpath(sub))
1498 1499 sr = sub.commit(cctx._text, user, date)
1499 1500 newstate[s] = (newstate[s][0], sr)
1500 1501 subrepo.writestate(self, newstate)
1501 1502
1502 1503 p1, p2 = self.dirstate.parents()
1503 1504 hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '')
1504 1505 try:
1505 1506 self.hook("precommit", throw=True, parent1=hookp1,
1506 1507 parent2=hookp2)
1507 1508 ret = self.commitctx(cctx, True)
1508 1509 except: # re-raises
1509 1510 if edited:
1510 1511 self.ui.write(
1511 1512 _('note: commit message saved in %s\n') % msgfn)
1512 1513 raise
1513 1514
1514 1515 # update bookmarks, dirstate and mergestate
1515 1516 bookmarks.update(self, [p1, p2], ret)
1516 1517 cctx.markcommitted(ret)
1517 1518 ms.reset()
1518 1519 finally:
1519 1520 wlock.release()
1520 1521
1521 1522 def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2):
1522 1523 # hack for command that use a temporary commit (eg: histedit)
1523 1524 # temporary commit got stripped before hook release
1524 1525 if self.changelog.hasnode(ret):
1525 1526 self.hook("commit", node=node, parent1=parent1,
1526 1527 parent2=parent2)
1527 1528 self._afterlock(commithook)
1528 1529 return ret
1529 1530
1530 1531 @unfilteredmethod
1531 1532 def commitctx(self, ctx, error=False):
1532 1533 """Add a new revision to current repository.
1533 1534 Revision information is passed via the context argument.
1534 1535 """
1535 1536
1536 1537 tr = None
1537 1538 p1, p2 = ctx.p1(), ctx.p2()
1538 1539 user = ctx.user()
1539 1540
1540 1541 lock = self.lock()
1541 1542 try:
1542 1543 tr = self.transaction("commit")
1543 1544 trp = weakref.proxy(tr)
1544 1545
1545 1546 if ctx.files():
1546 1547 m1 = p1.manifest()
1547 1548 m2 = p2.manifest()
1548 1549 m = m1.copy()
1549 1550
1550 1551 # check in files
1551 1552 added = []
1552 1553 changed = []
1553 1554 removed = list(ctx.removed())
1554 1555 linkrev = len(self)
1555 1556 self.ui.note(_("committing files:\n"))
1556 1557 for f in sorted(ctx.modified() + ctx.added()):
1557 1558 self.ui.note(f + "\n")
1558 1559 try:
1559 1560 fctx = ctx[f]
1560 1561 if fctx is None:
1561 1562 removed.append(f)
1562 1563 else:
1563 1564 added.append(f)
1564 1565 m[f] = self._filecommit(fctx, m1, m2, linkrev,
1565 1566 trp, changed)
1566 1567 m.setflag(f, fctx.flags())
1567 1568 except OSError, inst:
1568 1569 self.ui.warn(_("trouble committing %s!\n") % f)
1569 1570 raise
1570 1571 except IOError, inst:
1571 1572 errcode = getattr(inst, 'errno', errno.ENOENT)
1572 1573 if error or errcode and errcode != errno.ENOENT:
1573 1574 self.ui.warn(_("trouble committing %s!\n") % f)
1574 1575 raise
1575 1576
1576 1577 # update manifest
1577 1578 self.ui.note(_("committing manifest\n"))
1578 1579 removed = [f for f in sorted(removed) if f in m1 or f in m2]
1579 1580 drop = [f for f in removed if f in m]
1580 1581 for f in drop:
1581 1582 del m[f]
1582 1583 mn = self.manifest.add(m, trp, linkrev,
1583 1584 p1.manifestnode(), p2.manifestnode(),
1584 1585 added, drop)
1585 1586 files = changed + removed
1586 1587 else:
1587 1588 mn = p1.manifestnode()
1588 1589 files = []
1589 1590
1590 1591 # update changelog
1591 1592 self.ui.note(_("committing changelog\n"))
1592 1593 self.changelog.delayupdate(tr)
1593 1594 n = self.changelog.add(mn, files, ctx.description(),
1594 1595 trp, p1.node(), p2.node(),
1595 1596 user, ctx.date(), ctx.extra().copy())
1596 1597 p = lambda: tr.writepending() and self.root or ""
1597 1598 xp1, xp2 = p1.hex(), p2 and p2.hex() or ''
1598 1599 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
1599 1600 parent2=xp2, pending=p)
1600 1601 # set the new commit is proper phase
1601 1602 targetphase = subrepo.newcommitphase(self.ui, ctx)
1602 1603 if targetphase:
1603 1604 # retract boundary do not alter parent changeset.
1604 1605 # if a parent have higher the resulting phase will
1605 1606 # be compliant anyway
1606 1607 #
1607 1608 # if minimal phase was 0 we don't need to retract anything
1608 1609 phases.retractboundary(self, tr, targetphase, [n])
1609 1610 tr.close()
1610 1611 branchmap.updatecache(self.filtered('served'))
1611 1612 return n
1612 1613 finally:
1613 1614 if tr:
1614 1615 tr.release()
1615 1616 lock.release()
1616 1617
1617 1618 @unfilteredmethod
1618 1619 def destroying(self):
1619 1620 '''Inform the repository that nodes are about to be destroyed.
1620 1621 Intended for use by strip and rollback, so there's a common
1621 1622 place for anything that has to be done before destroying history.
1622 1623
1623 1624 This is mostly useful for saving state that is in memory and waiting
1624 1625 to be flushed when the current lock is released. Because a call to
1625 1626 destroyed is imminent, the repo will be invalidated causing those
1626 1627 changes to stay in memory (waiting for the next unlock), or vanish
1627 1628 completely.
1628 1629 '''
1629 1630 # When using the same lock to commit and strip, the phasecache is left
1630 1631 # dirty after committing. Then when we strip, the repo is invalidated,
1631 1632 # causing those changes to disappear.
1632 1633 if '_phasecache' in vars(self):
1633 1634 self._phasecache.write()
1634 1635
1635 1636 @unfilteredmethod
1636 1637 def destroyed(self):
1637 1638 '''Inform the repository that nodes have been destroyed.
1638 1639 Intended for use by strip and rollback, so there's a common
1639 1640 place for anything that has to be done after destroying history.
1640 1641 '''
1641 1642 # When one tries to:
1642 1643 # 1) destroy nodes thus calling this method (e.g. strip)
1643 1644 # 2) use phasecache somewhere (e.g. commit)
1644 1645 #
1645 1646 # then 2) will fail because the phasecache contains nodes that were
1646 1647 # removed. We can either remove phasecache from the filecache,
1647 1648 # causing it to reload next time it is accessed, or simply filter
1648 1649 # the removed nodes now and write the updated cache.
1649 1650 self._phasecache.filterunknown(self)
1650 1651 self._phasecache.write()
1651 1652
1652 1653 # update the 'served' branch cache to help read only server process
1653 1654 # Thanks to branchcache collaboration this is done from the nearest
1654 1655 # filtered subset and it is expected to be fast.
1655 1656 branchmap.updatecache(self.filtered('served'))
1656 1657
1657 1658 # Ensure the persistent tag cache is updated. Doing it now
1658 1659 # means that the tag cache only has to worry about destroyed
1659 1660 # heads immediately after a strip/rollback. That in turn
1660 1661 # guarantees that "cachetip == currenttip" (comparing both rev
1661 1662 # and node) always means no nodes have been added or destroyed.
1662 1663
1663 1664 # XXX this is suboptimal when qrefresh'ing: we strip the current
1664 1665 # head, refresh the tag cache, then immediately add a new head.
1665 1666 # But I think doing it this way is necessary for the "instant
1666 1667 # tag cache retrieval" case to work.
1667 1668 self.invalidate()
1668 1669
1669 1670 def walk(self, match, node=None):
1670 1671 '''
1671 1672 walk recursively through the directory tree or a given
1672 1673 changeset, finding all files matched by the match
1673 1674 function
1674 1675 '''
1675 1676 return self[node].walk(match)
1676 1677
1677 1678 def status(self, node1='.', node2=None, match=None,
1678 1679 ignored=False, clean=False, unknown=False,
1679 1680 listsubrepos=False):
1680 1681 '''a convenience method that calls node1.status(node2)'''
1681 1682 return self[node1].status(node2, match, ignored, clean, unknown,
1682 1683 listsubrepos)
1683 1684
1684 1685 def heads(self, start=None):
1685 1686 heads = self.changelog.heads(start)
1686 1687 # sort the output in rev descending order
1687 1688 return sorted(heads, key=self.changelog.rev, reverse=True)
1688 1689
1689 1690 def branchheads(self, branch=None, start=None, closed=False):
1690 1691 '''return a (possibly filtered) list of heads for the given branch
1691 1692
1692 1693 Heads are returned in topological order, from newest to oldest.
1693 1694 If branch is None, use the dirstate branch.
1694 1695 If start is not None, return only heads reachable from start.
1695 1696 If closed is True, return heads that are marked as closed as well.
1696 1697 '''
1697 1698 if branch is None:
1698 1699 branch = self[None].branch()
1699 1700 branches = self.branchmap()
1700 1701 if branch not in branches:
1701 1702 return []
1702 1703 # the cache returns heads ordered lowest to highest
1703 1704 bheads = list(reversed(branches.branchheads(branch, closed=closed)))
1704 1705 if start is not None:
1705 1706 # filter out the heads that cannot be reached from startrev
1706 1707 fbheads = set(self.changelog.nodesbetween([start], bheads)[2])
1707 1708 bheads = [h for h in bheads if h in fbheads]
1708 1709 return bheads
1709 1710
1710 1711 def branches(self, nodes):
1711 1712 if not nodes:
1712 1713 nodes = [self.changelog.tip()]
1713 1714 b = []
1714 1715 for n in nodes:
1715 1716 t = n
1716 1717 while True:
1717 1718 p = self.changelog.parents(n)
1718 1719 if p[1] != nullid or p[0] == nullid:
1719 1720 b.append((t, n, p[0], p[1]))
1720 1721 break
1721 1722 n = p[0]
1722 1723 return b
1723 1724
1724 1725 def between(self, pairs):
1725 1726 r = []
1726 1727
1727 1728 for top, bottom in pairs:
1728 1729 n, l, i = top, [], 0
1729 1730 f = 1
1730 1731
1731 1732 while n != bottom and n != nullid:
1732 1733 p = self.changelog.parents(n)[0]
1733 1734 if i == f:
1734 1735 l.append(n)
1735 1736 f = f * 2
1736 1737 n = p
1737 1738 i += 1
1738 1739
1739 1740 r.append(l)
1740 1741
1741 1742 return r
1742 1743
1743 1744 def checkpush(self, pushop):
1744 1745 """Extensions can override this function if additional checks have
1745 1746 to be performed before pushing, or call it if they override push
1746 1747 command.
1747 1748 """
1748 1749 pass
1749 1750
1750 1751 @unfilteredpropertycache
1751 1752 def prepushoutgoinghooks(self):
1752 1753 """Return util.hooks consists of "(repo, remote, outgoing)"
1753 1754 functions, which are called before pushing changesets.
1754 1755 """
1755 1756 return util.hooks()
1756 1757
1757 1758 def stream_in(self, remote, remotereqs):
1758 1759 # Save remote branchmap. We will use it later
1759 1760 # to speed up branchcache creation
1760 1761 rbranchmap = None
1761 1762 if remote.capable("branchmap"):
1762 1763 rbranchmap = remote.branchmap()
1763 1764
1764 1765 fp = remote.stream_out()
1765 1766 l = fp.readline()
1766 1767 try:
1767 1768 resp = int(l)
1768 1769 except ValueError:
1769 1770 raise error.ResponseError(
1770 1771 _('unexpected response from remote server:'), l)
1771 1772 if resp == 1:
1772 1773 raise util.Abort(_('operation forbidden by server'))
1773 1774 elif resp == 2:
1774 1775 raise util.Abort(_('locking the remote repository failed'))
1775 1776 elif resp != 0:
1776 1777 raise util.Abort(_('the server sent an unknown error code'))
1777 1778
1778 1779 self.applystreamclone(remotereqs, rbranchmap, fp)
1779 1780 return len(self.heads()) + 1
1780 1781
1781 1782 def applystreamclone(self, remotereqs, remotebranchmap, fp):
1782 1783 """Apply stream clone data to this repository.
1783 1784
1784 1785 "remotereqs" is a set of requirements to handle the incoming data.
1785 1786 "remotebranchmap" is the result of a branchmap lookup on the remote. It
1786 1787 can be None.
1787 1788 "fp" is a file object containing the raw stream data, suitable for
1788 1789 feeding into exchange.consumestreamclone.
1789 1790 """
1790 1791 lock = self.lock()
1791 1792 try:
1792 1793 exchange.consumestreamclone(self, fp)
1793 1794
1794 1795 # new requirements = old non-format requirements +
1795 1796 # new format-related remote requirements
1796 1797 # requirements from the streamed-in repository
1797 1798 self.requirements = remotereqs | (
1798 1799 self.requirements - self.supportedformats)
1799 1800 self._applyopenerreqs()
1800 1801 self._writerequirements()
1801 1802
1802 1803 if remotebranchmap:
1803 1804 rbheads = []
1804 1805 closed = []
1805 1806 for bheads in remotebranchmap.itervalues():
1806 1807 rbheads.extend(bheads)
1807 1808 for h in bheads:
1808 1809 r = self.changelog.rev(h)
1809 1810 b, c = self.changelog.branchinfo(r)
1810 1811 if c:
1811 1812 closed.append(h)
1812 1813
1813 1814 if rbheads:
1814 1815 rtiprev = max((int(self.changelog.rev(node))
1815 1816 for node in rbheads))
1816 1817 cache = branchmap.branchcache(remotebranchmap,
1817 1818 self[rtiprev].node(),
1818 1819 rtiprev,
1819 1820 closednodes=closed)
1820 1821 # Try to stick it as low as possible
1821 1822 # filter above served are unlikely to be fetch from a clone
1822 1823 for candidate in ('base', 'immutable', 'served'):
1823 1824 rview = self.filtered(candidate)
1824 1825 if cache.validfor(rview):
1825 1826 self._branchcaches[candidate] = cache
1826 1827 cache.write(rview)
1827 1828 break
1828 1829 self.invalidate()
1829 1830 finally:
1830 1831 lock.release()
1831 1832
1832 1833 def clone(self, remote, heads=[], stream=None):
1833 1834 '''clone remote repository.
1834 1835
1835 1836 keyword arguments:
1836 1837 heads: list of revs to clone (forces use of pull)
1837 1838 stream: use streaming clone if possible'''
1838 1839
1839 1840 # now, all clients that can request uncompressed clones can
1840 1841 # read repo formats supported by all servers that can serve
1841 1842 # them.
1842 1843
1843 1844 # if revlog format changes, client will have to check version
1844 1845 # and format flags on "stream" capability, and use
1845 1846 # uncompressed only if compatible.
1846 1847
1847 1848 if stream is None:
1848 1849 # if the server explicitly prefers to stream (for fast LANs)
1849 1850 stream = remote.capable('stream-preferred')
1850 1851
1851 1852 if stream and not heads:
1852 1853 # 'stream' means remote revlog format is revlogv1 only
1853 1854 if remote.capable('stream'):
1854 1855 self.stream_in(remote, set(('revlogv1',)))
1855 1856 else:
1856 1857 # otherwise, 'streamreqs' contains the remote revlog format
1857 1858 streamreqs = remote.capable('streamreqs')
1858 1859 if streamreqs:
1859 1860 streamreqs = set(streamreqs.split(','))
1860 1861 # if we support it, stream in and adjust our requirements
1861 1862 if not streamreqs - self.supportedformats:
1862 1863 self.stream_in(remote, streamreqs)
1863 1864
1864 1865 quiet = self.ui.backupconfig('ui', 'quietbookmarkmove')
1865 1866 try:
1866 1867 self.ui.setconfig('ui', 'quietbookmarkmove', True, 'clone')
1867 1868 ret = exchange.pull(self, remote, heads).cgresult
1868 1869 finally:
1869 1870 self.ui.restoreconfig(quiet)
1870 1871 return ret
1871 1872
1872 1873 def pushkey(self, namespace, key, old, new):
1873 1874 try:
1874 1875 tr = self.currenttransaction()
1875 1876 hookargs = {}
1876 1877 if tr is not None:
1877 1878 hookargs.update(tr.hookargs)
1878 1879 pending = lambda: tr.writepending() and self.root or ""
1879 1880 hookargs['pending'] = pending
1880 1881 hookargs['namespace'] = namespace
1881 1882 hookargs['key'] = key
1882 1883 hookargs['old'] = old
1883 1884 hookargs['new'] = new
1884 1885 self.hook('prepushkey', throw=True, **hookargs)
1885 1886 except error.HookAbort, exc:
1886 1887 self.ui.write_err(_("pushkey-abort: %s\n") % exc)
1887 1888 if exc.hint:
1888 1889 self.ui.write_err(_("(%s)\n") % exc.hint)
1889 1890 return False
1890 1891 self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key))
1891 1892 ret = pushkey.push(self, namespace, key, old, new)
1892 1893 def runhook():
1893 1894 self.hook('pushkey', namespace=namespace, key=key, old=old, new=new,
1894 1895 ret=ret)
1895 1896 self._afterlock(runhook)
1896 1897 return ret
1897 1898
1898 1899 def listkeys(self, namespace):
1899 1900 self.hook('prelistkeys', throw=True, namespace=namespace)
1900 1901 self.ui.debug('listing keys for "%s"\n' % namespace)
1901 1902 values = pushkey.list(self, namespace)
1902 1903 self.hook('listkeys', namespace=namespace, values=values)
1903 1904 return values
1904 1905
1905 1906 def debugwireargs(self, one, two, three=None, four=None, five=None):
1906 1907 '''used to test argument passing over the wire'''
1907 1908 return "%s %s %s %s %s" % (one, two, three, four, five)
1908 1909
1909 1910 def savecommitmessage(self, text):
1910 1911 fp = self.vfs('last-message.txt', 'wb')
1911 1912 try:
1912 1913 fp.write(text)
1913 1914 finally:
1914 1915 fp.close()
1915 1916 return self.pathto(fp.name[len(self.root) + 1:])
1916 1917
1917 1918 # used to avoid circular references so destructors work
1918 1919 def aftertrans(files):
1919 1920 renamefiles = [tuple(t) for t in files]
1920 1921 def a():
1921 1922 for vfs, src, dest in renamefiles:
1922 1923 try:
1923 1924 vfs.rename(src, dest)
1924 1925 except OSError: # journal file does not yet exist
1925 1926 pass
1926 1927 return a
1927 1928
1928 1929 def undoname(fn):
1929 1930 base, name = os.path.split(fn)
1930 1931 assert name.startswith('journal')
1931 1932 return os.path.join(base, name.replace('journal', 'undo', 1))
1932 1933
1933 1934 def instance(ui, path, create):
1934 1935 return localrepository(ui, util.urllocalpath(path), create)
1935 1936
1936 1937 def islocal(path):
1937 1938 return True
@@ -1,3511 +1,3507 b''
1 1 # revset.py - revision set queries for mercurial
2 2 #
3 3 # Copyright 2010 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 import re
9 9 import parser, util, error, hbisect, phases
10 10 import node
11 11 import heapq
12 12 import match as matchmod
13 13 from i18n import _
14 14 import encoding
15 15 import obsolete as obsmod
16 16 import pathutil
17 17 import repoview
18 18
19 19 def _revancestors(repo, revs, followfirst):
20 20 """Like revlog.ancestors(), but supports followfirst."""
21 21 if followfirst:
22 22 cut = 1
23 23 else:
24 24 cut = None
25 25 cl = repo.changelog
26 26
27 27 def iterate():
28 28 revs.sort(reverse=True)
29 29 irevs = iter(revs)
30 30 h = []
31 31
32 32 inputrev = next(irevs, None)
33 33 if inputrev is not None:
34 34 heapq.heappush(h, -inputrev)
35 35
36 36 seen = set()
37 37 while h:
38 38 current = -heapq.heappop(h)
39 39 if current == inputrev:
40 40 inputrev = next(irevs, None)
41 41 if inputrev is not None:
42 42 heapq.heappush(h, -inputrev)
43 43 if current not in seen:
44 44 seen.add(current)
45 45 yield current
46 46 for parent in cl.parentrevs(current)[:cut]:
47 47 if parent != node.nullrev:
48 48 heapq.heappush(h, -parent)
49 49
50 50 return generatorset(iterate(), iterasc=False)
51 51
52 52 def _revdescendants(repo, revs, followfirst):
53 53 """Like revlog.descendants() but supports followfirst."""
54 54 if followfirst:
55 55 cut = 1
56 56 else:
57 57 cut = None
58 58
59 59 def iterate():
60 60 cl = repo.changelog
61 61 first = min(revs)
62 62 nullrev = node.nullrev
63 63 if first == nullrev:
64 64 # Are there nodes with a null first parent and a non-null
65 65 # second one? Maybe. Do we care? Probably not.
66 66 for i in cl:
67 67 yield i
68 68 else:
69 69 seen = set(revs)
70 70 for i in cl.revs(first + 1):
71 71 for x in cl.parentrevs(i)[:cut]:
72 72 if x != nullrev and x in seen:
73 73 seen.add(i)
74 74 yield i
75 75 break
76 76
77 77 return generatorset(iterate(), iterasc=True)
78 78
79 79 def _revsbetween(repo, roots, heads):
80 80 """Return all paths between roots and heads, inclusive of both endpoint
81 81 sets."""
82 82 if not roots:
83 83 return baseset()
84 84 parentrevs = repo.changelog.parentrevs
85 85 visit = list(heads)
86 86 reachable = set()
87 87 seen = {}
88 88 minroot = min(roots)
89 89 roots = set(roots)
90 90 # open-code the post-order traversal due to the tiny size of
91 91 # sys.getrecursionlimit()
92 92 while visit:
93 93 rev = visit.pop()
94 94 if rev in roots:
95 95 reachable.add(rev)
96 96 parents = parentrevs(rev)
97 97 seen[rev] = parents
98 98 for parent in parents:
99 99 if parent >= minroot and parent not in seen:
100 100 visit.append(parent)
101 101 if not reachable:
102 102 return baseset()
103 103 for rev in sorted(seen):
104 104 for parent in seen[rev]:
105 105 if parent in reachable:
106 106 reachable.add(rev)
107 107 return baseset(sorted(reachable))
108 108
109 109 elements = {
110 110 "(": (21, ("group", 1, ")"), ("func", 1, ")")),
111 111 "##": (20, None, ("_concat", 20)),
112 112 "~": (18, None, ("ancestor", 18)),
113 113 "^": (18, None, ("parent", 18), ("parentpost", 18)),
114 114 "-": (5, ("negate", 19), ("minus", 5)),
115 115 "::": (17, ("dagrangepre", 17), ("dagrange", 17),
116 116 ("dagrangepost", 17)),
117 117 "..": (17, ("dagrangepre", 17), ("dagrange", 17),
118 118 ("dagrangepost", 17)),
119 119 ":": (15, ("rangepre", 15), ("range", 15), ("rangepost", 15)),
120 120 "not": (10, ("not", 10)),
121 121 "!": (10, ("not", 10)),
122 122 "and": (5, None, ("and", 5)),
123 123 "&": (5, None, ("and", 5)),
124 124 "%": (5, None, ("only", 5), ("onlypost", 5)),
125 125 "or": (4, None, ("or", 4)),
126 126 "|": (4, None, ("or", 4)),
127 127 "+": (4, None, ("or", 4)),
128 128 ",": (2, None, ("list", 2)),
129 129 ")": (0, None, None),
130 130 "symbol": (0, ("symbol",), None),
131 131 "string": (0, ("string",), None),
132 132 "end": (0, None, None),
133 133 }
134 134
135 135 keywords = set(['and', 'or', 'not'])
136 136
137 137 # default set of valid characters for the initial letter of symbols
138 138 _syminitletters = set(c for c in [chr(i) for i in xrange(256)]
139 139 if c.isalnum() or c in '._@' or ord(c) > 127)
140 140
141 141 # default set of valid characters for non-initial letters of symbols
142 142 _symletters = set(c for c in [chr(i) for i in xrange(256)]
143 143 if c.isalnum() or c in '-._/@' or ord(c) > 127)
144 144
145 145 def tokenize(program, lookup=None, syminitletters=None, symletters=None):
146 146 '''
147 147 Parse a revset statement into a stream of tokens
148 148
149 149 ``syminitletters`` is the set of valid characters for the initial
150 150 letter of symbols.
151 151
152 152 By default, character ``c`` is recognized as valid for initial
153 153 letter of symbols, if ``c.isalnum() or c in '._@' or ord(c) > 127``.
154 154
155 155 ``symletters`` is the set of valid characters for non-initial
156 156 letters of symbols.
157 157
158 158 By default, character ``c`` is recognized as valid for non-initial
159 159 letters of symbols, if ``c.isalnum() or c in '-._/@' or ord(c) > 127``.
160 160
161 161 Check that @ is a valid unquoted token character (issue3686):
162 162 >>> list(tokenize("@::"))
163 163 [('symbol', '@', 0), ('::', None, 1), ('end', None, 3)]
164 164
165 165 '''
166 166 if syminitletters is None:
167 167 syminitletters = _syminitletters
168 168 if symletters is None:
169 169 symletters = _symletters
170 170
171 171 pos, l = 0, len(program)
172 172 while pos < l:
173 173 c = program[pos]
174 174 if c.isspace(): # skip inter-token whitespace
175 175 pass
176 176 elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully
177 177 yield ('::', None, pos)
178 178 pos += 1 # skip ahead
179 179 elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully
180 180 yield ('..', None, pos)
181 181 pos += 1 # skip ahead
182 182 elif c == '#' and program[pos:pos + 2] == '##': # look ahead carefully
183 183 yield ('##', None, pos)
184 184 pos += 1 # skip ahead
185 185 elif c in "():,-|&+!~^%": # handle simple operators
186 186 yield (c, None, pos)
187 187 elif (c in '"\'' or c == 'r' and
188 188 program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings
189 189 if c == 'r':
190 190 pos += 1
191 191 c = program[pos]
192 192 decode = lambda x: x
193 193 else:
194 194 decode = lambda x: x.decode('string-escape')
195 195 pos += 1
196 196 s = pos
197 197 while pos < l: # find closing quote
198 198 d = program[pos]
199 199 if d == '\\': # skip over escaped characters
200 200 pos += 2
201 201 continue
202 202 if d == c:
203 203 yield ('string', decode(program[s:pos]), s)
204 204 break
205 205 pos += 1
206 206 else:
207 207 raise error.ParseError(_("unterminated string"), s)
208 208 # gather up a symbol/keyword
209 209 elif c in syminitletters:
210 210 s = pos
211 211 pos += 1
212 212 while pos < l: # find end of symbol
213 213 d = program[pos]
214 214 if d not in symletters:
215 215 break
216 216 if d == '.' and program[pos - 1] == '.': # special case for ..
217 217 pos -= 1
218 218 break
219 219 pos += 1
220 220 sym = program[s:pos]
221 221 if sym in keywords: # operator keywords
222 222 yield (sym, None, s)
223 223 elif '-' in sym:
224 224 # some jerk gave us foo-bar-baz, try to check if it's a symbol
225 225 if lookup and lookup(sym):
226 226 # looks like a real symbol
227 227 yield ('symbol', sym, s)
228 228 else:
229 229 # looks like an expression
230 230 parts = sym.split('-')
231 231 for p in parts[:-1]:
232 232 if p: # possible consecutive -
233 233 yield ('symbol', p, s)
234 234 s += len(p)
235 235 yield ('-', None, pos)
236 236 s += 1
237 237 if parts[-1]: # possible trailing -
238 238 yield ('symbol', parts[-1], s)
239 239 else:
240 240 yield ('symbol', sym, s)
241 241 pos -= 1
242 242 else:
243 243 raise error.ParseError(_("syntax error in revset '%s'") %
244 244 program, pos)
245 245 pos += 1
246 246 yield ('end', None, pos)
247 247
248 248 def parseerrordetail(inst):
249 249 """Compose error message from specified ParseError object
250 250 """
251 251 if len(inst.args) > 1:
252 252 return _('at %s: %s') % (inst.args[1], inst.args[0])
253 253 else:
254 254 return inst.args[0]
255 255
256 256 # helpers
257 257
258 258 def getstring(x, err):
259 259 if x and (x[0] == 'string' or x[0] == 'symbol'):
260 260 return x[1]
261 261 raise error.ParseError(err)
262 262
263 263 def getlist(x):
264 264 if not x:
265 265 return []
266 266 if x[0] == 'list':
267 267 return getlist(x[1]) + [x[2]]
268 268 return [x]
269 269
270 270 def getargs(x, min, max, err):
271 271 l = getlist(x)
272 272 if len(l) < min or (max >= 0 and len(l) > max):
273 273 raise error.ParseError(err)
274 274 return l
275 275
276 276 def isvalidsymbol(tree):
277 277 """Examine whether specified ``tree`` is valid ``symbol`` or not
278 278 """
279 279 return tree[0] == 'symbol' and len(tree) > 1
280 280
281 281 def getsymbol(tree):
282 282 """Get symbol name from valid ``symbol`` in ``tree``
283 283
284 284 This assumes that ``tree`` is already examined by ``isvalidsymbol``.
285 285 """
286 286 return tree[1]
287 287
288 288 def isvalidfunc(tree):
289 289 """Examine whether specified ``tree`` is valid ``func`` or not
290 290 """
291 291 return tree[0] == 'func' and len(tree) > 1 and isvalidsymbol(tree[1])
292 292
293 293 def getfuncname(tree):
294 294 """Get function name from valid ``func`` in ``tree``
295 295
296 296 This assumes that ``tree`` is already examined by ``isvalidfunc``.
297 297 """
298 298 return getsymbol(tree[1])
299 299
300 300 def getfuncargs(tree):
301 301 """Get list of function arguments from valid ``func`` in ``tree``
302 302
303 303 This assumes that ``tree`` is already examined by ``isvalidfunc``.
304 304 """
305 305 if len(tree) > 2:
306 306 return getlist(tree[2])
307 307 else:
308 308 return []
309 309
310 310 def getset(repo, subset, x):
311 311 if not x:
312 312 raise error.ParseError(_("missing argument"))
313 313 s = methods[x[0]](repo, subset, *x[1:])
314 314 if util.safehasattr(s, 'isascending'):
315 315 return s
316 316 return baseset(s)
317 317
318 318 def _getrevsource(repo, r):
319 319 extra = repo[r].extra()
320 320 for label in ('source', 'transplant_source', 'rebase_source'):
321 321 if label in extra:
322 322 try:
323 323 return repo[extra[label]].rev()
324 324 except error.RepoLookupError:
325 325 pass
326 326 return None
327 327
328 328 # operator methods
329 329
330 330 def stringset(repo, subset, x):
331 331 x = repo[x].rev()
332 if x in subset:
332 if (x in subset
333 or x == node.nullrev and isinstance(subset, fullreposet)):
333 334 return baseset([x])
334 335 return baseset()
335 336
336 337 def rangeset(repo, subset, x, y):
337 338 m = getset(repo, fullreposet(repo), x)
338 339 n = getset(repo, fullreposet(repo), y)
339 340
340 341 if not m or not n:
341 342 return baseset()
342 343 m, n = m.first(), n.last()
343 344
344 345 if m < n:
345 346 r = spanset(repo, m, n + 1)
346 347 else:
347 348 r = spanset(repo, m, n - 1)
348 349 return r & subset
349 350
350 351 def dagrange(repo, subset, x, y):
351 352 r = fullreposet(repo)
352 353 xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y))
353 354 return xs & subset
354 355
355 356 def andset(repo, subset, x, y):
356 357 return getset(repo, getset(repo, subset, x), y)
357 358
358 359 def orset(repo, subset, x, y):
359 360 xl = getset(repo, subset, x)
360 361 yl = getset(repo, subset, y)
361 362 return xl + yl
362 363
363 364 def notset(repo, subset, x):
364 365 return subset - getset(repo, subset, x)
365 366
366 367 def listset(repo, subset, a, b):
367 368 raise error.ParseError(_("can't use a list in this context"))
368 369
369 370 def func(repo, subset, a, b):
370 371 if a[0] == 'symbol' and a[1] in symbols:
371 372 return symbols[a[1]](repo, subset, b)
372 373 raise error.UnknownIdentifier(a[1], symbols.keys())
373 374
374 375 # functions
375 376
376 377 def adds(repo, subset, x):
377 378 """``adds(pattern)``
378 379 Changesets that add a file matching pattern.
379 380
380 381 The pattern without explicit kind like ``glob:`` is expected to be
381 382 relative to the current directory and match against a file or a
382 383 directory.
383 384 """
384 385 # i18n: "adds" is a keyword
385 386 pat = getstring(x, _("adds requires a pattern"))
386 387 return checkstatus(repo, subset, pat, 1)
387 388
388 389 def ancestor(repo, subset, x):
389 390 """``ancestor(*changeset)``
390 391 A greatest common ancestor of the changesets.
391 392
392 393 Accepts 0 or more changesets.
393 394 Will return empty list when passed no args.
394 395 Greatest common ancestor of a single changeset is that changeset.
395 396 """
396 397 # i18n: "ancestor" is a keyword
397 398 l = getlist(x)
398 399 rl = fullreposet(repo)
399 400 anc = None
400 401
401 402 # (getset(repo, rl, i) for i in l) generates a list of lists
402 403 for revs in (getset(repo, rl, i) for i in l):
403 404 for r in revs:
404 405 if anc is None:
405 406 anc = repo[r]
406 407 else:
407 408 anc = anc.ancestor(repo[r])
408 409
409 410 if anc is not None and anc.rev() in subset:
410 411 return baseset([anc.rev()])
411 412 return baseset()
412 413
413 414 def _ancestors(repo, subset, x, followfirst=False):
414 415 heads = getset(repo, fullreposet(repo), x)
415 416 if not heads:
416 417 return baseset()
417 418 s = _revancestors(repo, heads, followfirst)
418 419 return subset & s
419 420
420 421 def ancestors(repo, subset, x):
421 422 """``ancestors(set)``
422 423 Changesets that are ancestors of a changeset in set.
423 424 """
424 425 return _ancestors(repo, subset, x)
425 426
426 427 def _firstancestors(repo, subset, x):
427 428 # ``_firstancestors(set)``
428 429 # Like ``ancestors(set)`` but follows only the first parents.
429 430 return _ancestors(repo, subset, x, followfirst=True)
430 431
431 432 def ancestorspec(repo, subset, x, n):
432 433 """``set~n``
433 434 Changesets that are the Nth ancestor (first parents only) of a changeset
434 435 in set.
435 436 """
436 437 try:
437 438 n = int(n[1])
438 439 except (TypeError, ValueError):
439 440 raise error.ParseError(_("~ expects a number"))
440 441 ps = set()
441 442 cl = repo.changelog
442 443 for r in getset(repo, fullreposet(repo), x):
443 444 for i in range(n):
444 445 r = cl.parentrevs(r)[0]
445 446 ps.add(r)
446 447 return subset & ps
447 448
448 449 def author(repo, subset, x):
449 450 """``author(string)``
450 451 Alias for ``user(string)``.
451 452 """
452 453 # i18n: "author" is a keyword
453 454 n = encoding.lower(getstring(x, _("author requires a string")))
454 455 kind, pattern, matcher = _substringmatcher(n)
455 456 return subset.filter(lambda x: matcher(encoding.lower(repo[x].user())))
456 457
457 458 def bisect(repo, subset, x):
458 459 """``bisect(string)``
459 460 Changesets marked in the specified bisect status:
460 461
461 462 - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip
462 463 - ``goods``, ``bads`` : csets topologically good/bad
463 464 - ``range`` : csets taking part in the bisection
464 465 - ``pruned`` : csets that are goods, bads or skipped
465 466 - ``untested`` : csets whose fate is yet unknown
466 467 - ``ignored`` : csets ignored due to DAG topology
467 468 - ``current`` : the cset currently being bisected
468 469 """
469 470 # i18n: "bisect" is a keyword
470 471 status = getstring(x, _("bisect requires a string")).lower()
471 472 state = set(hbisect.get(repo, status))
472 473 return subset & state
473 474
474 475 # Backward-compatibility
475 476 # - no help entry so that we do not advertise it any more
476 477 def bisected(repo, subset, x):
477 478 return bisect(repo, subset, x)
478 479
479 480 def bookmark(repo, subset, x):
480 481 """``bookmark([name])``
481 482 The named bookmark or all bookmarks.
482 483
483 484 If `name` starts with `re:`, the remainder of the name is treated as
484 485 a regular expression. To match a bookmark that actually starts with `re:`,
485 486 use the prefix `literal:`.
486 487 """
487 488 # i18n: "bookmark" is a keyword
488 489 args = getargs(x, 0, 1, _('bookmark takes one or no arguments'))
489 490 if args:
490 491 bm = getstring(args[0],
491 492 # i18n: "bookmark" is a keyword
492 493 _('the argument to bookmark must be a string'))
493 494 kind, pattern, matcher = _stringmatcher(bm)
494 495 bms = set()
495 496 if kind == 'literal':
496 497 bmrev = repo._bookmarks.get(pattern, None)
497 498 if not bmrev:
498 499 raise error.RepoLookupError(_("bookmark '%s' does not exist")
499 500 % bm)
500 501 bms.add(repo[bmrev].rev())
501 502 else:
502 503 matchrevs = set()
503 504 for name, bmrev in repo._bookmarks.iteritems():
504 505 if matcher(name):
505 506 matchrevs.add(bmrev)
506 507 if not matchrevs:
507 508 raise error.RepoLookupError(_("no bookmarks exist"
508 509 " that match '%s'") % pattern)
509 510 for bmrev in matchrevs:
510 511 bms.add(repo[bmrev].rev())
511 512 else:
512 513 bms = set([repo[r].rev()
513 514 for r in repo._bookmarks.values()])
514 515 bms -= set([node.nullrev])
515 516 return subset & bms
516 517
517 518 def branch(repo, subset, x):
518 519 """``branch(string or set)``
519 520 All changesets belonging to the given branch or the branches of the given
520 521 changesets.
521 522
522 523 If `string` starts with `re:`, the remainder of the name is treated as
523 524 a regular expression. To match a branch that actually starts with `re:`,
524 525 use the prefix `literal:`.
525 526 """
526 527 getbi = repo.revbranchcache().branchinfo
527 528
528 529 try:
529 530 b = getstring(x, '')
530 531 except error.ParseError:
531 532 # not a string, but another revspec, e.g. tip()
532 533 pass
533 534 else:
534 535 kind, pattern, matcher = _stringmatcher(b)
535 536 if kind == 'literal':
536 537 # note: falls through to the revspec case if no branch with
537 538 # this name exists
538 539 if pattern in repo.branchmap():
539 540 return subset.filter(lambda r: matcher(getbi(r)[0]))
540 541 else:
541 542 return subset.filter(lambda r: matcher(getbi(r)[0]))
542 543
543 544 s = getset(repo, fullreposet(repo), x)
544 545 b = set()
545 546 for r in s:
546 547 b.add(getbi(r)[0])
547 548 c = s.__contains__
548 549 return subset.filter(lambda r: c(r) or getbi(r)[0] in b)
549 550
550 551 def bumped(repo, subset, x):
551 552 """``bumped()``
552 553 Mutable changesets marked as successors of public changesets.
553 554
554 555 Only non-public and non-obsolete changesets can be `bumped`.
555 556 """
556 557 # i18n: "bumped" is a keyword
557 558 getargs(x, 0, 0, _("bumped takes no arguments"))
558 559 bumped = obsmod.getrevs(repo, 'bumped')
559 560 return subset & bumped
560 561
561 562 def bundle(repo, subset, x):
562 563 """``bundle()``
563 564 Changesets in the bundle.
564 565
565 566 Bundle must be specified by the -R option."""
566 567
567 568 try:
568 569 bundlerevs = repo.changelog.bundlerevs
569 570 except AttributeError:
570 571 raise util.Abort(_("no bundle provided - specify with -R"))
571 572 return subset & bundlerevs
572 573
573 574 def checkstatus(repo, subset, pat, field):
574 575 hasset = matchmod.patkind(pat) == 'set'
575 576
576 577 mcache = [None]
577 578 def matches(x):
578 579 c = repo[x]
579 580 if not mcache[0] or hasset:
580 581 mcache[0] = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
581 582 m = mcache[0]
582 583 fname = None
583 584 if not m.anypats() and len(m.files()) == 1:
584 585 fname = m.files()[0]
585 586 if fname is not None:
586 587 if fname not in c.files():
587 588 return False
588 589 else:
589 590 for f in c.files():
590 591 if m(f):
591 592 break
592 593 else:
593 594 return False
594 595 files = repo.status(c.p1().node(), c.node())[field]
595 596 if fname is not None:
596 597 if fname in files:
597 598 return True
598 599 else:
599 600 for f in files:
600 601 if m(f):
601 602 return True
602 603
603 604 return subset.filter(matches)
604 605
605 606 def _children(repo, narrow, parentset):
606 607 cs = set()
607 608 if not parentset:
608 609 return baseset(cs)
609 610 pr = repo.changelog.parentrevs
610 611 minrev = min(parentset)
611 612 for r in narrow:
612 613 if r <= minrev:
613 614 continue
614 615 for p in pr(r):
615 616 if p in parentset:
616 617 cs.add(r)
617 618 return baseset(cs)
618 619
619 620 def children(repo, subset, x):
620 621 """``children(set)``
621 622 Child changesets of changesets in set.
622 623 """
623 624 s = getset(repo, fullreposet(repo), x)
624 625 cs = _children(repo, subset, s)
625 626 return subset & cs
626 627
627 628 def closed(repo, subset, x):
628 629 """``closed()``
629 630 Changeset is closed.
630 631 """
631 632 # i18n: "closed" is a keyword
632 633 getargs(x, 0, 0, _("closed takes no arguments"))
633 634 return subset.filter(lambda r: repo[r].closesbranch())
634 635
635 636 def contains(repo, subset, x):
636 637 """``contains(pattern)``
637 638 The revision's manifest contains a file matching pattern (but might not
638 639 modify it). See :hg:`help patterns` for information about file patterns.
639 640
640 641 The pattern without explicit kind like ``glob:`` is expected to be
641 642 relative to the current directory and match against a file exactly
642 643 for efficiency.
643 644 """
644 645 # i18n: "contains" is a keyword
645 646 pat = getstring(x, _("contains requires a pattern"))
646 647
647 648 def matches(x):
648 649 if not matchmod.patkind(pat):
649 650 pats = pathutil.canonpath(repo.root, repo.getcwd(), pat)
650 651 if pats in repo[x]:
651 652 return True
652 653 else:
653 654 c = repo[x]
654 655 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
655 656 for f in c.manifest():
656 657 if m(f):
657 658 return True
658 659 return False
659 660
660 661 return subset.filter(matches)
661 662
662 663 def converted(repo, subset, x):
663 664 """``converted([id])``
664 665 Changesets converted from the given identifier in the old repository if
665 666 present, or all converted changesets if no identifier is specified.
666 667 """
667 668
668 669 # There is exactly no chance of resolving the revision, so do a simple
669 670 # string compare and hope for the best
670 671
671 672 rev = None
672 673 # i18n: "converted" is a keyword
673 674 l = getargs(x, 0, 1, _('converted takes one or no arguments'))
674 675 if l:
675 676 # i18n: "converted" is a keyword
676 677 rev = getstring(l[0], _('converted requires a revision'))
677 678
678 679 def _matchvalue(r):
679 680 source = repo[r].extra().get('convert_revision', None)
680 681 return source is not None and (rev is None or source.startswith(rev))
681 682
682 683 return subset.filter(lambda r: _matchvalue(r))
683 684
684 685 def date(repo, subset, x):
685 686 """``date(interval)``
686 687 Changesets within the interval, see :hg:`help dates`.
687 688 """
688 689 # i18n: "date" is a keyword
689 690 ds = getstring(x, _("date requires a string"))
690 691 dm = util.matchdate(ds)
691 692 return subset.filter(lambda x: dm(repo[x].date()[0]))
692 693
693 694 def desc(repo, subset, x):
694 695 """``desc(string)``
695 696 Search commit message for string. The match is case-insensitive.
696 697 """
697 698 # i18n: "desc" is a keyword
698 699 ds = encoding.lower(getstring(x, _("desc requires a string")))
699 700
700 701 def matches(x):
701 702 c = repo[x]
702 703 return ds in encoding.lower(c.description())
703 704
704 705 return subset.filter(matches)
705 706
706 707 def _descendants(repo, subset, x, followfirst=False):
707 708 roots = getset(repo, fullreposet(repo), x)
708 709 if not roots:
709 710 return baseset()
710 711 s = _revdescendants(repo, roots, followfirst)
711 712
712 713 # Both sets need to be ascending in order to lazily return the union
713 714 # in the correct order.
714 715 base = subset & roots
715 716 desc = subset & s
716 717 result = base + desc
717 718 if subset.isascending():
718 719 result.sort()
719 720 elif subset.isdescending():
720 721 result.sort(reverse=True)
721 722 else:
722 723 result = subset & result
723 724 return result
724 725
725 726 def descendants(repo, subset, x):
726 727 """``descendants(set)``
727 728 Changesets which are descendants of changesets in set.
728 729 """
729 730 return _descendants(repo, subset, x)
730 731
731 732 def _firstdescendants(repo, subset, x):
732 733 # ``_firstdescendants(set)``
733 734 # Like ``descendants(set)`` but follows only the first parents.
734 735 return _descendants(repo, subset, x, followfirst=True)
735 736
736 737 def destination(repo, subset, x):
737 738 """``destination([set])``
738 739 Changesets that were created by a graft, transplant or rebase operation,
739 740 with the given revisions specified as the source. Omitting the optional set
740 741 is the same as passing all().
741 742 """
742 743 if x is not None:
743 744 sources = getset(repo, fullreposet(repo), x)
744 745 else:
745 746 sources = fullreposet(repo)
746 747
747 748 dests = set()
748 749
749 750 # subset contains all of the possible destinations that can be returned, so
750 751 # iterate over them and see if their source(s) were provided in the arg set.
751 752 # Even if the immediate src of r is not in the arg set, src's source (or
752 753 # further back) may be. Scanning back further than the immediate src allows
753 754 # transitive transplants and rebases to yield the same results as transitive
754 755 # grafts.
755 756 for r in subset:
756 757 src = _getrevsource(repo, r)
757 758 lineage = None
758 759
759 760 while src is not None:
760 761 if lineage is None:
761 762 lineage = list()
762 763
763 764 lineage.append(r)
764 765
765 766 # The visited lineage is a match if the current source is in the arg
766 767 # set. Since every candidate dest is visited by way of iterating
767 768 # subset, any dests further back in the lineage will be tested by a
768 769 # different iteration over subset. Likewise, if the src was already
769 770 # selected, the current lineage can be selected without going back
770 771 # further.
771 772 if src in sources or src in dests:
772 773 dests.update(lineage)
773 774 break
774 775
775 776 r = src
776 777 src = _getrevsource(repo, r)
777 778
778 779 return subset.filter(dests.__contains__)
779 780
780 781 def divergent(repo, subset, x):
781 782 """``divergent()``
782 783 Final successors of changesets with an alternative set of final successors.
783 784 """
784 785 # i18n: "divergent" is a keyword
785 786 getargs(x, 0, 0, _("divergent takes no arguments"))
786 787 divergent = obsmod.getrevs(repo, 'divergent')
787 788 return subset & divergent
788 789
789 790 def draft(repo, subset, x):
790 791 """``draft()``
791 792 Changeset in draft phase."""
792 793 # i18n: "draft" is a keyword
793 794 getargs(x, 0, 0, _("draft takes no arguments"))
794 795 phase = repo._phasecache.phase
795 796 target = phases.draft
796 797 condition = lambda r: phase(repo, r) == target
797 798 return subset.filter(condition, cache=False)
798 799
799 800 def extinct(repo, subset, x):
800 801 """``extinct()``
801 802 Obsolete changesets with obsolete descendants only.
802 803 """
803 804 # i18n: "extinct" is a keyword
804 805 getargs(x, 0, 0, _("extinct takes no arguments"))
805 806 extincts = obsmod.getrevs(repo, 'extinct')
806 807 return subset & extincts
807 808
808 809 def extra(repo, subset, x):
809 810 """``extra(label, [value])``
810 811 Changesets with the given label in the extra metadata, with the given
811 812 optional value.
812 813
813 814 If `value` starts with `re:`, the remainder of the value is treated as
814 815 a regular expression. To match a value that actually starts with `re:`,
815 816 use the prefix `literal:`.
816 817 """
817 818
818 819 # i18n: "extra" is a keyword
819 820 l = getargs(x, 1, 2, _('extra takes at least 1 and at most 2 arguments'))
820 821 # i18n: "extra" is a keyword
821 822 label = getstring(l[0], _('first argument to extra must be a string'))
822 823 value = None
823 824
824 825 if len(l) > 1:
825 826 # i18n: "extra" is a keyword
826 827 value = getstring(l[1], _('second argument to extra must be a string'))
827 828 kind, value, matcher = _stringmatcher(value)
828 829
829 830 def _matchvalue(r):
830 831 extra = repo[r].extra()
831 832 return label in extra and (value is None or matcher(extra[label]))
832 833
833 834 return subset.filter(lambda r: _matchvalue(r))
834 835
835 836 def filelog(repo, subset, x):
836 837 """``filelog(pattern)``
837 838 Changesets connected to the specified filelog.
838 839
839 840 For performance reasons, visits only revisions mentioned in the file-level
840 841 filelog, rather than filtering through all changesets (much faster, but
841 842 doesn't include deletes or duplicate changes). For a slower, more accurate
842 843 result, use ``file()``.
843 844
844 845 The pattern without explicit kind like ``glob:`` is expected to be
845 846 relative to the current directory and match against a file exactly
846 847 for efficiency.
847 848
848 849 If some linkrev points to revisions filtered by the current repoview, we'll
849 850 work around it to return a non-filtered value.
850 851 """
851 852
852 853 # i18n: "filelog" is a keyword
853 854 pat = getstring(x, _("filelog requires a pattern"))
854 855 s = set()
855 856 cl = repo.changelog
856 857
857 858 if not matchmod.patkind(pat):
858 859 f = pathutil.canonpath(repo.root, repo.getcwd(), pat)
859 860 files = [f]
860 861 else:
861 862 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None])
862 863 files = (f for f in repo[None] if m(f))
863 864
864 865 for f in files:
865 866 backrevref = {} # final value for: filerev -> changerev
866 867 lowestchild = {} # lowest known filerev child of a filerev
867 868 delayed = [] # filerev with filtered linkrev, for post-processing
868 869 lowesthead = None # cache for manifest content of all head revisions
869 870 fl = repo.file(f)
870 871 for fr in list(fl):
871 872 rev = fl.linkrev(fr)
872 873 if rev not in cl:
873 874 # changerev pointed in linkrev is filtered
874 875 # record it for post processing.
875 876 delayed.append((fr, rev))
876 877 continue
877 878 for p in fl.parentrevs(fr):
878 879 if 0 <= p and p not in lowestchild:
879 880 lowestchild[p] = fr
880 881 backrevref[fr] = rev
881 882 s.add(rev)
882 883
883 884 # Post-processing of all filerevs we skipped because they were
884 885 # filtered. If such filerevs have known and unfiltered children, this
885 886 # means they have an unfiltered appearance out there. We'll use linkrev
886 887 # adjustment to find one of these appearances. The lowest known child
887 888 # will be used as a starting point because it is the best upper-bound we
888 889 # have.
889 890 #
890 891 # This approach will fail when an unfiltered but linkrev-shadowed
891 892 # appearance exists in a head changeset without unfiltered filerev
892 893 # children anywhere.
893 894 while delayed:
894 895 # must be a descending iteration. To slowly fill lowest child
895 896 # information that is of potential use by the next item.
896 897 fr, rev = delayed.pop()
897 898 lkr = rev
898 899
899 900 child = lowestchild.get(fr)
900 901
901 902 if child is None:
902 903 # search for existence of this file revision in a head revision.
903 904 # There are three possibilities:
904 905 # - the revision exists in a head and we can find an
905 906 # introduction from there,
906 907 # - the revision does not exist in a head because it has been
907 908 # changed since its introduction: we would have found a child
908 909 # and be in the other 'else' clause,
909 910 # - all versions of the revision are hidden.
910 911 if lowesthead is None:
911 912 lowesthead = {}
912 913 for h in repo.heads():
913 914 fnode = repo[h].manifest().get(f)
914 915 if fnode is not None:
915 916 lowesthead[fl.rev(fnode)] = h
916 917 headrev = lowesthead.get(fr)
917 918 if headrev is None:
918 919 # content is nowhere unfiltered
919 920 continue
920 921 rev = repo[headrev][f].introrev()
921 922 else:
922 923 # the lowest known child is a good upper bound
923 924 childcrev = backrevref[child]
924 925 # XXX this does not guarantee returning the lowest
925 926 # introduction of this revision, but this gives a
926 927 # result which is a good start and will fit in most
927 928 # cases. We probably need to fix the multiple
928 929 # introductions case properly (report each
929 930 # introduction, even for identical file revisions)
930 931 # once and for all at some point anyway.
931 932 for p in repo[childcrev][f].parents():
932 933 if p.filerev() == fr:
933 934 rev = p.rev()
934 935 break
935 936 if rev == lkr: # no shadowed entry found
936 937 # XXX This should never happen unless some manifest points
937 938 # to biggish file revisions (like a revision that uses a
938 939 # parent that never appears in the manifest ancestors)
939 940 continue
940 941
941 942 # Fill the data for the next iteration.
942 943 for p in fl.parentrevs(fr):
943 944 if 0 <= p and p not in lowestchild:
944 945 lowestchild[p] = fr
945 946 backrevref[fr] = rev
946 947 s.add(rev)
947 948
948 949 return subset & s
949 950
950 951 def first(repo, subset, x):
951 952 """``first(set, [n])``
952 953 An alias for limit().
953 954 """
954 955 return limit(repo, subset, x)
955 956
956 957 def _follow(repo, subset, x, name, followfirst=False):
957 958 l = getargs(x, 0, 1, _("%s takes no arguments or a filename") % name)
958 959 c = repo['.']
959 960 if l:
960 961 x = getstring(l[0], _("%s expected a filename") % name)
961 962 if x in c:
962 963 cx = c[x]
963 964 s = set(ctx.rev() for ctx in cx.ancestors(followfirst=followfirst))
964 965 # include the revision responsible for the most recent version
965 966 s.add(cx.introrev())
966 967 else:
967 968 return baseset()
968 969 else:
969 970 s = _revancestors(repo, baseset([c.rev()]), followfirst)
970 971
971 972 return subset & s
972 973
973 974 def follow(repo, subset, x):
974 975 """``follow([file])``
975 976 An alias for ``::.`` (ancestors of the working directory's first parent).
976 977 If a filename is specified, the history of the given file is followed,
977 978 including copies.
978 979 """
979 980 return _follow(repo, subset, x, 'follow')
980 981
981 982 def _followfirst(repo, subset, x):
982 983 # ``followfirst([file])``
983 984 # Like ``follow([file])`` but follows only the first parent of
984 985 # every revision or file revision.
985 986 return _follow(repo, subset, x, '_followfirst', followfirst=True)
986 987
987 988 def getall(repo, subset, x):
988 989 """``all()``
989 990 All changesets, the same as ``0:tip``.
990 991 """
991 992 # i18n: "all" is a keyword
992 993 getargs(x, 0, 0, _("all takes no arguments"))
993 994 return subset & spanset(repo) # drop "null" if any
994 995
995 996 def grep(repo, subset, x):
996 997 """``grep(regex)``
997 998 Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')``
998 999 to ensure special escape characters are handled correctly. Unlike
999 1000 ``keyword(string)``, the match is case-sensitive.
1000 1001 """
1001 1002 try:
1002 1003 # i18n: "grep" is a keyword
1003 1004 gr = re.compile(getstring(x, _("grep requires a string")))
1004 1005 except re.error, e:
1005 1006 raise error.ParseError(_('invalid match pattern: %s') % e)
1006 1007
1007 1008 def matches(x):
1008 1009 c = repo[x]
1009 1010 for e in c.files() + [c.user(), c.description()]:
1010 1011 if gr.search(e):
1011 1012 return True
1012 1013 return False
1013 1014
1014 1015 return subset.filter(matches)
1015 1016
1016 1017 def _matchfiles(repo, subset, x):
1017 1018 # _matchfiles takes a revset list of prefixed arguments:
1018 1019 #
1019 1020 # [p:foo, i:bar, x:baz]
1020 1021 #
1021 1022 # builds a match object from them and filters subset. Allowed
1022 1023 # prefixes are 'p:' for regular patterns, 'i:' for include
1023 1024 # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass
1024 1025 # a revision identifier, or the empty string to reference the
1025 1026 # working directory, from which the match object is
1026 1027 # initialized. Use 'd:' to set the default matching mode, default
1027 1028 # to 'glob'. At most one 'r:' and 'd:' argument can be passed.
1028 1029
1029 1030 # i18n: "_matchfiles" is a keyword
1030 1031 l = getargs(x, 1, -1, _("_matchfiles requires at least one argument"))
1031 1032 pats, inc, exc = [], [], []
1032 1033 rev, default = None, None
1033 1034 for arg in l:
1034 1035 # i18n: "_matchfiles" is a keyword
1035 1036 s = getstring(arg, _("_matchfiles requires string arguments"))
1036 1037 prefix, value = s[:2], s[2:]
1037 1038 if prefix == 'p:':
1038 1039 pats.append(value)
1039 1040 elif prefix == 'i:':
1040 1041 inc.append(value)
1041 1042 elif prefix == 'x:':
1042 1043 exc.append(value)
1043 1044 elif prefix == 'r:':
1044 1045 if rev is not None:
1045 1046 # i18n: "_matchfiles" is a keyword
1046 1047 raise error.ParseError(_('_matchfiles expected at most one '
1047 1048 'revision'))
1048 1049 if value != '': # empty means working directory; leave rev as None
1049 1050 rev = value
1050 1051 elif prefix == 'd:':
1051 1052 if default is not None:
1052 1053 # i18n: "_matchfiles" is a keyword
1053 1054 raise error.ParseError(_('_matchfiles expected at most one '
1054 1055 'default mode'))
1055 1056 default = value
1056 1057 else:
1057 1058 # i18n: "_matchfiles" is a keyword
1058 1059 raise error.ParseError(_('invalid _matchfiles prefix: %s') % prefix)
1059 1060 if not default:
1060 1061 default = 'glob'
1061 1062
1062 1063 m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc,
1063 1064 exclude=exc, ctx=repo[rev], default=default)
1064 1065
1065 1066 def matches(x):
1066 1067 for f in repo[x].files():
1067 1068 if m(f):
1068 1069 return True
1069 1070 return False
1070 1071
1071 1072 return subset.filter(matches)
1072 1073
1073 1074 def hasfile(repo, subset, x):
1074 1075 """``file(pattern)``
1075 1076 Changesets affecting files matched by pattern.
1076 1077
1077 1078 For a faster but less accurate result, consider using ``filelog()``
1078 1079 instead.
1079 1080
1080 1081 This predicate uses ``glob:`` as the default kind of pattern.
1081 1082 """
1082 1083 # i18n: "file" is a keyword
1083 1084 pat = getstring(x, _("file requires a pattern"))
1084 1085 return _matchfiles(repo, subset, ('string', 'p:' + pat))
1085 1086
1086 1087 def head(repo, subset, x):
1087 1088 """``head()``
1088 1089 Changeset is a named branch head.
1089 1090 """
1090 1091 # i18n: "head" is a keyword
1091 1092 getargs(x, 0, 0, _("head takes no arguments"))
1092 1093 hs = set()
1093 1094 for b, ls in repo.branchmap().iteritems():
1094 1095 hs.update(repo[h].rev() for h in ls)
1095 1096 return baseset(hs).filter(subset.__contains__)
1096 1097
1097 1098 def heads(repo, subset, x):
1098 1099 """``heads(set)``
1099 1100 Members of set with no children in set.
1100 1101 """
1101 1102 s = getset(repo, subset, x)
1102 1103 ps = parents(repo, subset, x)
1103 1104 return s - ps
1104 1105
1105 1106 def hidden(repo, subset, x):
1106 1107 """``hidden()``
1107 1108 Hidden changesets.
1108 1109 """
1109 1110 # i18n: "hidden" is a keyword
1110 1111 getargs(x, 0, 0, _("hidden takes no arguments"))
1111 1112 hiddenrevs = repoview.filterrevs(repo, 'visible')
1112 1113 return subset & hiddenrevs
1113 1114
1114 1115 def keyword(repo, subset, x):
1115 1116 """``keyword(string)``
1116 1117 Search commit message, user name, and names of changed files for
1117 1118 string. The match is case-insensitive.
1118 1119 """
1119 1120 # i18n: "keyword" is a keyword
1120 1121 kw = encoding.lower(getstring(x, _("keyword requires a string")))
1121 1122
1122 1123 def matches(r):
1123 1124 c = repo[r]
1124 1125 return any(kw in encoding.lower(t) for t in c.files() + [c.user(),
1125 1126 c.description()])
1126 1127
1127 1128 return subset.filter(matches)
1128 1129
1129 1130 def limit(repo, subset, x):
1130 1131 """``limit(set, [n])``
1131 1132 First n members of set, defaulting to 1.
1132 1133 """
1133 1134 # i18n: "limit" is a keyword
1134 1135 l = getargs(x, 1, 2, _("limit requires one or two arguments"))
1135 1136 try:
1136 1137 lim = 1
1137 1138 if len(l) == 2:
1138 1139 # i18n: "limit" is a keyword
1139 1140 lim = int(getstring(l[1], _("limit requires a number")))
1140 1141 except (TypeError, ValueError):
1141 1142 # i18n: "limit" is a keyword
1142 1143 raise error.ParseError(_("limit expects a number"))
1143 1144 ss = subset
1144 1145 os = getset(repo, fullreposet(repo), l[0])
1145 1146 result = []
1146 1147 it = iter(os)
1147 1148 for x in xrange(lim):
1148 1149 y = next(it, None)
1149 1150 if y is None:
1150 1151 break
1151 1152 elif y in ss:
1152 1153 result.append(y)
1153 1154 return baseset(result)
1154 1155
1155 1156 def last(repo, subset, x):
1156 1157 """``last(set, [n])``
1157 1158 Last n members of set, defaulting to 1.
1158 1159 """
1159 1160 # i18n: "last" is a keyword
1160 1161 l = getargs(x, 1, 2, _("last requires one or two arguments"))
1161 1162 try:
1162 1163 lim = 1
1163 1164 if len(l) == 2:
1164 1165 # i18n: "last" is a keyword
1165 1166 lim = int(getstring(l[1], _("last requires a number")))
1166 1167 except (TypeError, ValueError):
1167 1168 # i18n: "last" is a keyword
1168 1169 raise error.ParseError(_("last expects a number"))
1169 1170 ss = subset
1170 1171 os = getset(repo, fullreposet(repo), l[0])
1171 1172 os.reverse()
1172 1173 result = []
1173 1174 it = iter(os)
1174 1175 for x in xrange(lim):
1175 1176 y = next(it, None)
1176 1177 if y is None:
1177 1178 break
1178 1179 elif y in ss:
1179 1180 result.append(y)
1180 1181 return baseset(result)
1181 1182
1182 1183 def maxrev(repo, subset, x):
1183 1184 """``max(set)``
1184 1185 Changeset with highest revision number in set.
1185 1186 """
1186 1187 os = getset(repo, fullreposet(repo), x)
1187 1188 if os:
1188 1189 m = os.max()
1189 1190 if m in subset:
1190 1191 return baseset([m])
1191 1192 return baseset()
1192 1193
1193 1194 def merge(repo, subset, x):
1194 1195 """``merge()``
1195 1196 Changeset is a merge changeset.
1196 1197 """
1197 1198 # i18n: "merge" is a keyword
1198 1199 getargs(x, 0, 0, _("merge takes no arguments"))
1199 1200 cl = repo.changelog
1200 1201 return subset.filter(lambda r: cl.parentrevs(r)[1] != -1)
1201 1202
1202 1203 def branchpoint(repo, subset, x):
1203 1204 """``branchpoint()``
1204 1205 Changesets with more than one child.
1205 1206 """
1206 1207 # i18n: "branchpoint" is a keyword
1207 1208 getargs(x, 0, 0, _("branchpoint takes no arguments"))
1208 1209 cl = repo.changelog
1209 1210 if not subset:
1210 1211 return baseset()
1211 1212 baserev = min(subset)
1212 1213 parentscount = [0]*(len(repo) - baserev)
1213 1214 for r in cl.revs(start=baserev + 1):
1214 1215 for p in cl.parentrevs(r):
1215 1216 if p >= baserev:
1216 1217 parentscount[p - baserev] += 1
1217 1218 return subset.filter(lambda r: parentscount[r - baserev] > 1)
1218 1219
1219 1220 def minrev(repo, subset, x):
1220 1221 """``min(set)``
1221 1222 Changeset with lowest revision number in set.
1222 1223 """
1223 1224 os = getset(repo, fullreposet(repo), x)
1224 1225 if os:
1225 1226 m = os.min()
1226 1227 if m in subset:
1227 1228 return baseset([m])
1228 1229 return baseset()
1229 1230
1230 1231 def modifies(repo, subset, x):
1231 1232 """``modifies(pattern)``
1232 1233 Changesets modifying files matched by pattern.
1233 1234
1234 1235 The pattern without explicit kind like ``glob:`` is expected to be
1235 1236 relative to the current directory and match against a file or a
1236 1237 directory.
1237 1238 """
1238 1239 # i18n: "modifies" is a keyword
1239 1240 pat = getstring(x, _("modifies requires a pattern"))
1240 1241 return checkstatus(repo, subset, pat, 0)
1241 1242
1242 1243 def named(repo, subset, x):
1243 1244 """``named(namespace)``
1244 1245 The changesets in a given namespace.
1245 1246
1246 1247 If `namespace` starts with `re:`, the remainder of the string is treated as
1247 1248 a regular expression. To match a namespace that actually starts with `re:`,
1248 1249 use the prefix `literal:`.
1249 1250 """
1250 1251 # i18n: "named" is a keyword
1251 1252 args = getargs(x, 1, 1, _('named requires a namespace argument'))
1252 1253
1253 1254 ns = getstring(args[0],
1254 1255 # i18n: "named" is a keyword
1255 1256 _('the argument to named must be a string'))
1256 1257 kind, pattern, matcher = _stringmatcher(ns)
1257 1258 namespaces = set()
1258 1259 if kind == 'literal':
1259 1260 if pattern not in repo.names:
1260 1261 raise error.RepoLookupError(_("namespace '%s' does not exist")
1261 1262 % ns)
1262 1263 namespaces.add(repo.names[pattern])
1263 1264 else:
1264 1265 for name, ns in repo.names.iteritems():
1265 1266 if matcher(name):
1266 1267 namespaces.add(ns)
1267 1268 if not namespaces:
1268 1269 raise error.RepoLookupError(_("no namespace exists"
1269 1270 " that match '%s'") % pattern)
1270 1271
1271 1272 names = set()
1272 1273 for ns in namespaces:
1273 1274 for name in ns.listnames(repo):
1274 1275 if name not in ns.deprecated:
1275 1276 names.update(repo[n].rev() for n in ns.nodes(repo, name))
1276 1277
1277 1278 names -= set([node.nullrev])
1278 1279 return subset & names
1279 1280
1280 1281 def node_(repo, subset, x):
1281 1282 """``id(string)``
1282 1283 Revision non-ambiguously specified by the given hex string prefix.
1283 1284 """
1284 1285 # i18n: "id" is a keyword
1285 1286 l = getargs(x, 1, 1, _("id requires one argument"))
1286 1287 # i18n: "id" is a keyword
1287 1288 n = getstring(l[0], _("id requires a string"))
1288 1289 if len(n) == 40:
1289 1290 try:
1290 1291 rn = repo.changelog.rev(node.bin(n))
1291 1292 except (LookupError, TypeError):
1292 1293 rn = None
1293 1294 else:
1294 1295 rn = None
1295 1296 pm = repo.changelog._partialmatch(n)
1296 1297 if pm is not None:
1297 1298 rn = repo.changelog.rev(pm)
1298 1299
1299 1300 if rn is None:
1300 1301 return baseset()
1301 1302 result = baseset([rn])
1302 1303 return result & subset
1303 1304
1304 1305 def obsolete(repo, subset, x):
1305 1306 """``obsolete()``
1306 1307 Mutable changeset with a newer version."""
1307 1308 # i18n: "obsolete" is a keyword
1308 1309 getargs(x, 0, 0, _("obsolete takes no arguments"))
1309 1310 obsoletes = obsmod.getrevs(repo, 'obsolete')
1310 1311 return subset & obsoletes
1311 1312
1312 1313 def only(repo, subset, x):
1313 1314 """``only(set, [set])``
1314 1315 Changesets that are ancestors of the first set that are not ancestors
1315 1316 of any other head in the repo. If a second set is specified, the result
1316 1317 is ancestors of the first set that are not ancestors of the second set
1317 1318 (i.e. ::<set1> - ::<set2>).
1318 1319 """
1319 1320 cl = repo.changelog
1320 1321 # i18n: "only" is a keyword
1321 1322 args = getargs(x, 1, 2, _('only takes one or two arguments'))
1322 1323 include = getset(repo, fullreposet(repo), args[0])
1323 1324 if len(args) == 1:
1324 1325 if not include:
1325 1326 return baseset()
1326 1327
1327 1328 descendants = set(_revdescendants(repo, include, False))
1328 1329 exclude = [rev for rev in cl.headrevs()
1329 1330 if not rev in descendants and not rev in include]
1330 1331 else:
1331 1332 exclude = getset(repo, fullreposet(repo), args[1])
1332 1333
1333 1334 results = set(cl.findmissingrevs(common=exclude, heads=include))
1334 1335 return subset & results
1335 1336
1336 1337 def origin(repo, subset, x):
1337 1338 """``origin([set])``
1338 1339 Changesets that were specified as a source for the grafts, transplants or
1339 1340 rebases that created the given revisions. Omitting the optional set is the
1340 1341 same as passing all(). If a changeset created by these operations is itself
1341 1342 specified as a source for one of these operations, only the source changeset
1342 1343 for the first operation is selected.
1343 1344 """
1344 1345 if x is not None:
1345 1346 dests = getset(repo, fullreposet(repo), x)
1346 1347 else:
1347 1348 dests = fullreposet(repo)
1348 1349
1349 1350 def _firstsrc(rev):
1350 1351 src = _getrevsource(repo, rev)
1351 1352 if src is None:
1352 1353 return None
1353 1354
1354 1355 while True:
1355 1356 prev = _getrevsource(repo, src)
1356 1357
1357 1358 if prev is None:
1358 1359 return src
1359 1360 src = prev
1360 1361
1361 1362 o = set([_firstsrc(r) for r in dests])
1362 1363 o -= set([None])
1363 1364 return subset & o
1364 1365
1365 1366 def outgoing(repo, subset, x):
1366 1367 """``outgoing([path])``
1367 1368 Changesets not found in the specified destination repository, or the
1368 1369 default push location.
1369 1370 """
1370 1371 # Avoid cycles.
1371 1372 import discovery
1372 1373 import hg
1373 1374 # i18n: "outgoing" is a keyword
1374 1375 l = getargs(x, 0, 1, _("outgoing takes one or no arguments"))
1375 1376 # i18n: "outgoing" is a keyword
1376 1377 dest = l and getstring(l[0], _("outgoing requires a repository path")) or ''
1377 1378 dest = repo.ui.expandpath(dest or 'default-push', dest or 'default')
1378 1379 dest, branches = hg.parseurl(dest)
1379 1380 revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
1380 1381 if revs:
1381 1382 revs = [repo.lookup(rev) for rev in revs]
1382 1383 other = hg.peer(repo, {}, dest)
1383 1384 repo.ui.pushbuffer()
1384 1385 outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs)
1385 1386 repo.ui.popbuffer()
1386 1387 cl = repo.changelog
1387 1388 o = set([cl.rev(r) for r in outgoing.missing])
1388 1389 return subset & o
1389 1390
1390 1391 def p1(repo, subset, x):
1391 1392 """``p1([set])``
1392 1393 First parent of changesets in set, or the working directory.
1393 1394 """
1394 1395 if x is None:
1395 1396 p = repo[x].p1().rev()
1396 1397 if p >= 0:
1397 1398 return subset & baseset([p])
1398 1399 return baseset()
1399 1400
1400 1401 ps = set()
1401 1402 cl = repo.changelog
1402 1403 for r in getset(repo, fullreposet(repo), x):
1403 1404 ps.add(cl.parentrevs(r)[0])
1404 1405 ps -= set([node.nullrev])
1405 1406 return subset & ps
1406 1407
1407 1408 def p2(repo, subset, x):
1408 1409 """``p2([set])``
1409 1410 Second parent of changesets in set, or the working directory.
1410 1411 """
1411 1412 if x is None:
1412 1413 ps = repo[x].parents()
1413 1414 try:
1414 1415 p = ps[1].rev()
1415 1416 if p >= 0:
1416 1417 return subset & baseset([p])
1417 1418 return baseset()
1418 1419 except IndexError:
1419 1420 return baseset()
1420 1421
1421 1422 ps = set()
1422 1423 cl = repo.changelog
1423 1424 for r in getset(repo, fullreposet(repo), x):
1424 1425 ps.add(cl.parentrevs(r)[1])
1425 1426 ps -= set([node.nullrev])
1426 1427 return subset & ps
1427 1428
1428 1429 def parents(repo, subset, x):
1429 1430 """``parents([set])``
1430 1431 The set of all parents for all changesets in set, or the working directory.
1431 1432 """
1432 1433 if x is None:
1433 1434 ps = set(p.rev() for p in repo[x].parents())
1434 1435 else:
1435 1436 ps = set()
1436 1437 cl = repo.changelog
1437 1438 for r in getset(repo, fullreposet(repo), x):
1438 1439 ps.update(cl.parentrevs(r))
1439 1440 ps -= set([node.nullrev])
1440 1441 return subset & ps
1441 1442
1442 1443 def parentspec(repo, subset, x, n):
1443 1444 """``set^0``
1444 1445 The set.
1445 1446 ``set^1`` (or ``set^``), ``set^2``
1446 1447 First or second parent, respectively, of all changesets in set.
1447 1448 """
1448 1449 try:
1449 1450 n = int(n[1])
1450 1451 if n not in (0, 1, 2):
1451 1452 raise ValueError
1452 1453 except (TypeError, ValueError):
1453 1454 raise error.ParseError(_("^ expects a number 0, 1, or 2"))
1454 1455 ps = set()
1455 1456 cl = repo.changelog
1456 1457 for r in getset(repo, fullreposet(repo), x):
1457 1458 if n == 0:
1458 1459 ps.add(r)
1459 1460 elif n == 1:
1460 1461 ps.add(cl.parentrevs(r)[0])
1461 1462 elif n == 2:
1462 1463 parents = cl.parentrevs(r)
1463 1464 if len(parents) > 1:
1464 1465 ps.add(parents[1])
1465 1466 return subset & ps
1466 1467
1467 1468 def present(repo, subset, x):
1468 1469 """``present(set)``
1469 1470 An empty set, if any revision in set isn't found; otherwise,
1470 1471 all revisions in set.
1471 1472
1472 1473 If any of specified revisions is not present in the local repository,
1473 1474 the query is normally aborted. But this predicate allows the query
1474 1475 to continue even in such cases.
1475 1476 """
1476 1477 try:
1477 1478 return getset(repo, subset, x)
1478 1479 except error.RepoLookupError:
1479 1480 return baseset()
1480 1481
1481 1482 # for internal use
1482 1483 def _notpublic(repo, subset, x):
1483 1484 getargs(x, 0, 0, "_notpublic takes no arguments")
1484 1485 if repo._phasecache._phasesets:
1485 1486 s = set()
1486 1487 for u in repo._phasecache._phasesets[1:]:
1487 1488 s.update(u)
1488 1489 return subset & s
1489 1490 else:
1490 1491 phase = repo._phasecache.phase
1491 1492 target = phases.public
1492 1493 condition = lambda r: phase(repo, r) != target
1493 1494 return subset.filter(condition, cache=False)
1494 1495
1495 1496 def public(repo, subset, x):
1496 1497 """``public()``
1497 1498 Changeset in public phase."""
1498 1499 # i18n: "public" is a keyword
1499 1500 getargs(x, 0, 0, _("public takes no arguments"))
1500 1501 phase = repo._phasecache.phase
1501 1502 target = phases.public
1502 1503 condition = lambda r: phase(repo, r) == target
1503 1504 return subset.filter(condition, cache=False)
1504 1505
1505 1506 def remote(repo, subset, x):
1506 1507 """``remote([id [,path]])``
1507 1508 Local revision that corresponds to the given identifier in a
1508 1509 remote repository, if present. Here, the '.' identifier is a
1509 1510 synonym for the current local branch.
1510 1511 """
1511 1512
1512 1513 import hg # avoid start-up nasties
1513 1514 # i18n: "remote" is a keyword
1514 1515 l = getargs(x, 0, 2, _("remote takes one, two or no arguments"))
1515 1516
1516 1517 q = '.'
1517 1518 if len(l) > 0:
1518 1519 # i18n: "remote" is a keyword
1519 1520 q = getstring(l[0], _("remote requires a string id"))
1520 1521 if q == '.':
1521 1522 q = repo['.'].branch()
1522 1523
1523 1524 dest = ''
1524 1525 if len(l) > 1:
1525 1526 # i18n: "remote" is a keyword
1526 1527 dest = getstring(l[1], _("remote requires a repository path"))
1527 1528 dest = repo.ui.expandpath(dest or 'default')
1528 1529 dest, branches = hg.parseurl(dest)
1529 1530 revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
1530 1531 if revs:
1531 1532 revs = [repo.lookup(rev) for rev in revs]
1532 1533 other = hg.peer(repo, {}, dest)
1533 1534 n = other.lookup(q)
1534 1535 if n in repo:
1535 1536 r = repo[n].rev()
1536 1537 if r in subset:
1537 1538 return baseset([r])
1538 1539 return baseset()
1539 1540
1540 1541 def removes(repo, subset, x):
1541 1542 """``removes(pattern)``
1542 1543 Changesets which remove files matching pattern.
1543 1544
1544 1545 The pattern without explicit kind like ``glob:`` is expected to be
1545 1546 relative to the current directory and match against a file or a
1546 1547 directory.
1547 1548 """
1548 1549 # i18n: "removes" is a keyword
1549 1550 pat = getstring(x, _("removes requires a pattern"))
1550 1551 return checkstatus(repo, subset, pat, 2)
1551 1552
1552 1553 def rev(repo, subset, x):
1553 1554 """``rev(number)``
1554 1555 Revision with the given numeric identifier.
1555 1556 """
1556 1557 # i18n: "rev" is a keyword
1557 1558 l = getargs(x, 1, 1, _("rev requires one argument"))
1558 1559 try:
1559 1560 # i18n: "rev" is a keyword
1560 1561 l = int(getstring(l[0], _("rev requires a number")))
1561 1562 except (TypeError, ValueError):
1562 1563 # i18n: "rev" is a keyword
1563 1564 raise error.ParseError(_("rev expects a number"))
1564 1565 if l not in repo.changelog and l != node.nullrev:
1565 1566 return baseset()
1566 1567 return subset & baseset([l])
1567 1568
1568 1569 def matching(repo, subset, x):
1569 1570 """``matching(revision [, field])``
1570 1571 Changesets in which a given set of fields match the set of fields in the
1571 1572 selected revision or set.
1572 1573
1573 1574 To match more than one field pass the list of fields to match separated
1574 1575 by spaces (e.g. ``author description``).
1575 1576
1576 1577 Valid fields are most regular revision fields and some special fields.
1577 1578
1578 1579 Regular revision fields are ``description``, ``author``, ``branch``,
1579 1580 ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user``
1580 1581 and ``diff``.
1581 1582 Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the
1582 1583 contents of the revision. Two revisions matching their ``diff`` will
1583 1584 also match their ``files``.
1584 1585
1585 1586 Special fields are ``summary`` and ``metadata``:
1586 1587 ``summary`` matches the first line of the description.
1587 1588 ``metadata`` is equivalent to matching ``description user date``
1588 1589 (i.e. it matches the main metadata fields).
1589 1590
1590 1591 ``metadata`` is the default field which is used when no fields are
1591 1592 specified. You can match more than one field at a time.
1592 1593 """
1593 1594 # i18n: "matching" is a keyword
1594 1595 l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments"))
1595 1596
1596 1597 revs = getset(repo, fullreposet(repo), l[0])
1597 1598
1598 1599 fieldlist = ['metadata']
1599 1600 if len(l) > 1:
1600 1601 fieldlist = getstring(l[1],
1601 1602 # i18n: "matching" is a keyword
1602 1603 _("matching requires a string "
1603 1604 "as its second argument")).split()
1604 1605
1605 1606 # Make sure that there are no repeated fields,
1606 1607 # expand the 'special' 'metadata' field type
1607 1608 # and check the 'files' whenever we check the 'diff'
1608 1609 fields = []
1609 1610 for field in fieldlist:
1610 1611 if field == 'metadata':
1611 1612 fields += ['user', 'description', 'date']
1612 1613 elif field == 'diff':
1613 1614 # a revision matching the diff must also match the files
1614 1615 # since matching the diff is very costly, make sure to
1615 1616 # also match the files first
1616 1617 fields += ['files', 'diff']
1617 1618 else:
1618 1619 if field == 'author':
1619 1620 field = 'user'
1620 1621 fields.append(field)
1621 1622 fields = set(fields)
1622 1623 if 'summary' in fields and 'description' in fields:
1623 1624 # If a revision matches its description it also matches its summary
1624 1625 fields.discard('summary')
1625 1626
1626 1627 # We may want to match more than one field
1627 1628 # Not all fields take the same amount of time to be matched
1628 1629 # Sort the selected fields in order of increasing matching cost
1629 1630 fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary',
1630 1631 'files', 'description', 'substate', 'diff']
1631 1632 def fieldkeyfunc(f):
1632 1633 try:
1633 1634 return fieldorder.index(f)
1634 1635 except ValueError:
1635 1636 # assume an unknown field is very costly
1636 1637 return len(fieldorder)
1637 1638 fields = list(fields)
1638 1639 fields.sort(key=fieldkeyfunc)
1639 1640
1640 1641 # Each field will be matched with its own "getfield" function
1641 1642 # which will be added to the getfieldfuncs array of functions
1642 1643 getfieldfuncs = []
1643 1644 _funcs = {
1644 1645 'user': lambda r: repo[r].user(),
1645 1646 'branch': lambda r: repo[r].branch(),
1646 1647 'date': lambda r: repo[r].date(),
1647 1648 'description': lambda r: repo[r].description(),
1648 1649 'files': lambda r: repo[r].files(),
1649 1650 'parents': lambda r: repo[r].parents(),
1650 1651 'phase': lambda r: repo[r].phase(),
1651 1652 'substate': lambda r: repo[r].substate,
1652 1653 'summary': lambda r: repo[r].description().splitlines()[0],
1653 1654 'diff': lambda r: list(repo[r].diff(git=True),)
1654 1655 }
1655 1656 for info in fields:
1656 1657 getfield = _funcs.get(info, None)
1657 1658 if getfield is None:
1658 1659 raise error.ParseError(
1659 1660 # i18n: "matching" is a keyword
1660 1661 _("unexpected field name passed to matching: %s") % info)
1661 1662 getfieldfuncs.append(getfield)
1662 1663 # convert the getfield array of functions into a "getinfo" function
1663 1664 # which returns an array of field values (or a single value if there
1664 1665 # is only one field to match)
1665 1666 getinfo = lambda r: [f(r) for f in getfieldfuncs]
1666 1667
1667 1668 def matches(x):
1668 1669 for rev in revs:
1669 1670 target = getinfo(rev)
1670 1671 match = True
1671 1672 for n, f in enumerate(getfieldfuncs):
1672 1673 if target[n] != f(x):
1673 1674 match = False
1674 1675 if match:
1675 1676 return True
1676 1677 return False
1677 1678
1678 1679 return subset.filter(matches)
1679 1680
1680 1681 def reverse(repo, subset, x):
1681 1682 """``reverse(set)``
1682 1683 Reverse order of set.
1683 1684 """
1684 1685 l = getset(repo, subset, x)
1685 1686 l.reverse()
1686 1687 return l
1687 1688
1688 1689 def roots(repo, subset, x):
1689 1690 """``roots(set)``
1690 1691 Changesets in set with no parent changeset in set.
1691 1692 """
1692 1693 s = getset(repo, fullreposet(repo), x)
1693 1694 subset = subset & s# baseset([r for r in s if r in subset])
1694 1695 cs = _children(repo, subset, s)
1695 1696 return subset - cs
1696 1697
1697 1698 def secret(repo, subset, x):
1698 1699 """``secret()``
1699 1700 Changeset in secret phase."""
1700 1701 # i18n: "secret" is a keyword
1701 1702 getargs(x, 0, 0, _("secret takes no arguments"))
1702 1703 phase = repo._phasecache.phase
1703 1704 target = phases.secret
1704 1705 condition = lambda r: phase(repo, r) == target
1705 1706 return subset.filter(condition, cache=False)
1706 1707
1707 1708 def sort(repo, subset, x):
1708 1709 """``sort(set[, [-]key...])``
1709 1710 Sort set by keys. The default sort order is ascending, specify a key
1710 1711 as ``-key`` to sort in descending order.
1711 1712
1712 1713 The keys can be:
1713 1714
1714 1715 - ``rev`` for the revision number,
1715 1716 - ``branch`` for the branch name,
1716 1717 - ``desc`` for the commit message (description),
1717 1718 - ``user`` for user name (``author`` can be used as an alias),
1718 1719 - ``date`` for the commit date
1719 1720 """
1720 1721 # i18n: "sort" is a keyword
1721 1722 l = getargs(x, 1, 2, _("sort requires one or two arguments"))
1722 1723 keys = "rev"
1723 1724 if len(l) == 2:
1724 1725 # i18n: "sort" is a keyword
1725 1726 keys = getstring(l[1], _("sort spec must be a string"))
1726 1727
1727 1728 s = l[0]
1728 1729 keys = keys.split()
1729 1730 l = []
1730 1731 def invert(s):
1731 1732 return "".join(chr(255 - ord(c)) for c in s)
1732 1733 revs = getset(repo, subset, s)
1733 1734 if keys == ["rev"]:
1734 1735 revs.sort()
1735 1736 return revs
1736 1737 elif keys == ["-rev"]:
1737 1738 revs.sort(reverse=True)
1738 1739 return revs
1739 1740 for r in revs:
1740 1741 c = repo[r]
1741 1742 e = []
1742 1743 for k in keys:
1743 1744 if k == 'rev':
1744 1745 e.append(r)
1745 1746 elif k == '-rev':
1746 1747 e.append(-r)
1747 1748 elif k == 'branch':
1748 1749 e.append(c.branch())
1749 1750 elif k == '-branch':
1750 1751 e.append(invert(c.branch()))
1751 1752 elif k == 'desc':
1752 1753 e.append(c.description())
1753 1754 elif k == '-desc':
1754 1755 e.append(invert(c.description()))
1755 1756 elif k in 'user author':
1756 1757 e.append(c.user())
1757 1758 elif k in '-user -author':
1758 1759 e.append(invert(c.user()))
1759 1760 elif k == 'date':
1760 1761 e.append(c.date()[0])
1761 1762 elif k == '-date':
1762 1763 e.append(-c.date()[0])
1763 1764 else:
1764 1765 raise error.ParseError(_("unknown sort key %r") % k)
1765 1766 e.append(r)
1766 1767 l.append(e)
1767 1768 l.sort()
1768 1769 return baseset([e[-1] for e in l])
1769 1770
1770 1771 def subrepo(repo, subset, x):
1771 1772 """``subrepo([pattern])``
1772 1773 Changesets that add, modify or remove the given subrepo. If no subrepo
1773 1774 pattern is named, any subrepo changes are returned.
1774 1775 """
1775 1776 # i18n: "subrepo" is a keyword
1776 1777 args = getargs(x, 0, 1, _('subrepo takes at most one argument'))
1777 1778 if len(args) != 0:
1778 1779 pat = getstring(args[0], _("subrepo requires a pattern"))
1779 1780
1780 1781 m = matchmod.exact(repo.root, repo.root, ['.hgsubstate'])
1781 1782
1782 1783 def submatches(names):
1783 1784 k, p, m = _stringmatcher(pat)
1784 1785 for name in names:
1785 1786 if m(name):
1786 1787 yield name
1787 1788
1788 1789 def matches(x):
1789 1790 c = repo[x]
1790 1791 s = repo.status(c.p1().node(), c.node(), match=m)
1791 1792
1792 1793 if len(args) == 0:
1793 1794 return s.added or s.modified or s.removed
1794 1795
1795 1796 if s.added:
1796 1797 return any(submatches(c.substate.keys()))
1797 1798
1798 1799 if s.modified:
1799 1800 subs = set(c.p1().substate.keys())
1800 1801 subs.update(c.substate.keys())
1801 1802
1802 1803 for path in submatches(subs):
1803 1804 if c.p1().substate.get(path) != c.substate.get(path):
1804 1805 return True
1805 1806
1806 1807 if s.removed:
1807 1808 return any(submatches(c.p1().substate.keys()))
1808 1809
1809 1810 return False
1810 1811
1811 1812 return subset.filter(matches)
1812 1813
1813 1814 def _stringmatcher(pattern):
1814 1815 """
1815 1816 accepts a string, possibly starting with 're:' or 'literal:' prefix.
1816 1817 returns the matcher name, pattern, and matcher function.
1817 1818 missing or unknown prefixes are treated as literal matches.
1818 1819
1819 1820 helper for tests:
1820 1821 >>> def test(pattern, *tests):
1821 1822 ... kind, pattern, matcher = _stringmatcher(pattern)
1822 1823 ... return (kind, pattern, [bool(matcher(t)) for t in tests])
1823 1824
1824 1825 exact matching (no prefix):
1825 1826 >>> test('abcdefg', 'abc', 'def', 'abcdefg')
1826 1827 ('literal', 'abcdefg', [False, False, True])
1827 1828
1828 1829 regex matching ('re:' prefix)
1829 1830 >>> test('re:a.+b', 'nomatch', 'fooadef', 'fooadefbar')
1830 1831 ('re', 'a.+b', [False, False, True])
1831 1832
1832 1833 force exact matches ('literal:' prefix)
1833 1834 >>> test('literal:re:foobar', 'foobar', 're:foobar')
1834 1835 ('literal', 're:foobar', [False, True])
1835 1836
1836 1837 unknown prefixes are ignored and treated as literals
1837 1838 >>> test('foo:bar', 'foo', 'bar', 'foo:bar')
1838 1839 ('literal', 'foo:bar', [False, False, True])
1839 1840 """
1840 1841 if pattern.startswith('re:'):
1841 1842 pattern = pattern[3:]
1842 1843 try:
1843 1844 regex = re.compile(pattern)
1844 1845 except re.error, e:
1845 1846 raise error.ParseError(_('invalid regular expression: %s')
1846 1847 % e)
1847 1848 return 're', pattern, regex.search
1848 1849 elif pattern.startswith('literal:'):
1849 1850 pattern = pattern[8:]
1850 1851 return 'literal', pattern, pattern.__eq__
1851 1852
1852 1853 def _substringmatcher(pattern):
1853 1854 kind, pattern, matcher = _stringmatcher(pattern)
1854 1855 if kind == 'literal':
1855 1856 matcher = lambda s: pattern in s
1856 1857 return kind, pattern, matcher
1857 1858
1858 1859 def tag(repo, subset, x):
1859 1860 """``tag([name])``
1860 1861 The specified tag by name, or all tagged revisions if no name is given.
1861 1862
1862 1863 If `name` starts with `re:`, the remainder of the name is treated as
1863 1864 a regular expression. To match a tag that actually starts with `re:`,
1864 1865 use the prefix `literal:`.
1865 1866 """
1866 1867 # i18n: "tag" is a keyword
1867 1868 args = getargs(x, 0, 1, _("tag takes one or no arguments"))
1868 1869 cl = repo.changelog
1869 1870 if args:
1870 1871 pattern = getstring(args[0],
1871 1872 # i18n: "tag" is a keyword
1872 1873 _('the argument to tag must be a string'))
1873 1874 kind, pattern, matcher = _stringmatcher(pattern)
1874 1875 if kind == 'literal':
1875 1876 # avoid resolving all tags
1876 1877 tn = repo._tagscache.tags.get(pattern, None)
1877 1878 if tn is None:
1878 1879 raise error.RepoLookupError(_("tag '%s' does not exist")
1879 1880 % pattern)
1880 1881 s = set([repo[tn].rev()])
1881 1882 else:
1882 1883 s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)])
1883 1884 else:
1884 1885 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip'])
1885 1886 return subset & s
1886 1887
1887 1888 def tagged(repo, subset, x):
1888 1889 return tag(repo, subset, x)
1889 1890
1890 1891 def unstable(repo, subset, x):
1891 1892 """``unstable()``
1892 1893 Non-obsolete changesets with obsolete ancestors.
1893 1894 """
1894 1895 # i18n: "unstable" is a keyword
1895 1896 getargs(x, 0, 0, _("unstable takes no arguments"))
1896 1897 unstables = obsmod.getrevs(repo, 'unstable')
1897 1898 return subset & unstables
1898 1899
1899 1900
1900 1901 def user(repo, subset, x):
1901 1902 """``user(string)``
1902 1903 User name contains string. The match is case-insensitive.
1903 1904
1904 1905 If `string` starts with `re:`, the remainder of the string is treated as
1905 1906 a regular expression. To match a user that actually contains `re:`, use
1906 1907 the prefix `literal:`.
1907 1908 """
1908 1909 return author(repo, subset, x)
1909 1910
1910 1911 # experimental
1911 1912 def wdir(repo, subset, x):
1912 1913 # i18n: "wdir" is a keyword
1913 1914 getargs(x, 0, 0, _("wdir takes no arguments"))
1914 if None in subset:
1915 if None in subset or isinstance(subset, fullreposet):
1915 1916 return baseset([None])
1916 1917 return baseset()
1917 1918
1918 1919 # for internal use
1919 1920 def _list(repo, subset, x):
1920 1921 s = getstring(x, "internal error")
1921 1922 if not s:
1922 1923 return baseset()
1923 1924 ls = [repo[r].rev() for r in s.split('\0')]
1924 1925 s = subset
1925 1926 return baseset([r for r in ls if r in s])
1926 1927
1927 1928 # for internal use
1928 1929 def _intlist(repo, subset, x):
1929 1930 s = getstring(x, "internal error")
1930 1931 if not s:
1931 1932 return baseset()
1932 1933 ls = [int(r) for r in s.split('\0')]
1933 1934 s = subset
1934 1935 return baseset([r for r in ls if r in s])
1935 1936
1936 1937 # for internal use
1937 1938 def _hexlist(repo, subset, x):
1938 1939 s = getstring(x, "internal error")
1939 1940 if not s:
1940 1941 return baseset()
1941 1942 cl = repo.changelog
1942 1943 ls = [cl.rev(node.bin(r)) for r in s.split('\0')]
1943 1944 s = subset
1944 1945 return baseset([r for r in ls if r in s])
1945 1946
1946 1947 symbols = {
1947 1948 "adds": adds,
1948 1949 "all": getall,
1949 1950 "ancestor": ancestor,
1950 1951 "ancestors": ancestors,
1951 1952 "_firstancestors": _firstancestors,
1952 1953 "author": author,
1953 1954 "bisect": bisect,
1954 1955 "bisected": bisected,
1955 1956 "bookmark": bookmark,
1956 1957 "branch": branch,
1957 1958 "branchpoint": branchpoint,
1958 1959 "bumped": bumped,
1959 1960 "bundle": bundle,
1960 1961 "children": children,
1961 1962 "closed": closed,
1962 1963 "contains": contains,
1963 1964 "converted": converted,
1964 1965 "date": date,
1965 1966 "desc": desc,
1966 1967 "descendants": descendants,
1967 1968 "_firstdescendants": _firstdescendants,
1968 1969 "destination": destination,
1969 1970 "divergent": divergent,
1970 1971 "draft": draft,
1971 1972 "extinct": extinct,
1972 1973 "extra": extra,
1973 1974 "file": hasfile,
1974 1975 "filelog": filelog,
1975 1976 "first": first,
1976 1977 "follow": follow,
1977 1978 "_followfirst": _followfirst,
1978 1979 "grep": grep,
1979 1980 "head": head,
1980 1981 "heads": heads,
1981 1982 "hidden": hidden,
1982 1983 "id": node_,
1983 1984 "keyword": keyword,
1984 1985 "last": last,
1985 1986 "limit": limit,
1986 1987 "_matchfiles": _matchfiles,
1987 1988 "max": maxrev,
1988 1989 "merge": merge,
1989 1990 "min": minrev,
1990 1991 "modifies": modifies,
1991 1992 "named": named,
1992 1993 "obsolete": obsolete,
1993 1994 "only": only,
1994 1995 "origin": origin,
1995 1996 "outgoing": outgoing,
1996 1997 "p1": p1,
1997 1998 "p2": p2,
1998 1999 "parents": parents,
1999 2000 "present": present,
2000 2001 "public": public,
2001 2002 "_notpublic": _notpublic,
2002 2003 "remote": remote,
2003 2004 "removes": removes,
2004 2005 "rev": rev,
2005 2006 "reverse": reverse,
2006 2007 "roots": roots,
2007 2008 "sort": sort,
2008 2009 "secret": secret,
2009 2010 "subrepo": subrepo,
2010 2011 "matching": matching,
2011 2012 "tag": tag,
2012 2013 "tagged": tagged,
2013 2014 "user": user,
2014 2015 "unstable": unstable,
2015 2016 "wdir": wdir,
2016 2017 "_list": _list,
2017 2018 "_intlist": _intlist,
2018 2019 "_hexlist": _hexlist,
2019 2020 }
2020 2021
2021 2022 # symbols which can't be used for a DoS attack for any given input
2022 2023 # (e.g. those which accept regexes as plain strings shouldn't be included)
2023 2024 # functions that just return a lot of changesets (like all) don't count here
2024 2025 safesymbols = set([
2025 2026 "adds",
2026 2027 "all",
2027 2028 "ancestor",
2028 2029 "ancestors",
2029 2030 "_firstancestors",
2030 2031 "author",
2031 2032 "bisect",
2032 2033 "bisected",
2033 2034 "bookmark",
2034 2035 "branch",
2035 2036 "branchpoint",
2036 2037 "bumped",
2037 2038 "bundle",
2038 2039 "children",
2039 2040 "closed",
2040 2041 "converted",
2041 2042 "date",
2042 2043 "desc",
2043 2044 "descendants",
2044 2045 "_firstdescendants",
2045 2046 "destination",
2046 2047 "divergent",
2047 2048 "draft",
2048 2049 "extinct",
2049 2050 "extra",
2050 2051 "file",
2051 2052 "filelog",
2052 2053 "first",
2053 2054 "follow",
2054 2055 "_followfirst",
2055 2056 "head",
2056 2057 "heads",
2057 2058 "hidden",
2058 2059 "id",
2059 2060 "keyword",
2060 2061 "last",
2061 2062 "limit",
2062 2063 "_matchfiles",
2063 2064 "max",
2064 2065 "merge",
2065 2066 "min",
2066 2067 "modifies",
2067 2068 "obsolete",
2068 2069 "only",
2069 2070 "origin",
2070 2071 "outgoing",
2071 2072 "p1",
2072 2073 "p2",
2073 2074 "parents",
2074 2075 "present",
2075 2076 "public",
2076 2077 "_notpublic",
2077 2078 "remote",
2078 2079 "removes",
2079 2080 "rev",
2080 2081 "reverse",
2081 2082 "roots",
2082 2083 "sort",
2083 2084 "secret",
2084 2085 "matching",
2085 2086 "tag",
2086 2087 "tagged",
2087 2088 "user",
2088 2089 "unstable",
2089 2090 "wdir",
2090 2091 "_list",
2091 2092 "_intlist",
2092 2093 "_hexlist",
2093 2094 ])
2094 2095
2095 2096 methods = {
2096 2097 "range": rangeset,
2097 2098 "dagrange": dagrange,
2098 2099 "string": stringset,
2099 2100 "symbol": stringset,
2100 2101 "and": andset,
2101 2102 "or": orset,
2102 2103 "not": notset,
2103 2104 "list": listset,
2104 2105 "func": func,
2105 2106 "ancestor": ancestorspec,
2106 2107 "parent": parentspec,
2107 2108 "parentpost": p1,
2108 2109 }
2109 2110
2110 2111 def optimize(x, small):
2111 2112 if x is None:
2112 2113 return 0, x
2113 2114
2114 2115 smallbonus = 1
2115 2116 if small:
2116 2117 smallbonus = .5
2117 2118
2118 2119 op = x[0]
2119 2120 if op == 'minus':
2120 2121 return optimize(('and', x[1], ('not', x[2])), small)
2121 2122 elif op == 'only':
2122 2123 return optimize(('func', ('symbol', 'only'),
2123 2124 ('list', x[1], x[2])), small)
2124 2125 elif op == 'onlypost':
2125 2126 return optimize(('func', ('symbol', 'only'), x[1]), small)
2126 2127 elif op == 'dagrangepre':
2127 2128 return optimize(('func', ('symbol', 'ancestors'), x[1]), small)
2128 2129 elif op == 'dagrangepost':
2129 2130 return optimize(('func', ('symbol', 'descendants'), x[1]), small)
2130 2131 elif op == 'rangepre':
2131 2132 return optimize(('range', ('string', '0'), x[1]), small)
2132 2133 elif op == 'rangepost':
2133 2134 return optimize(('range', x[1], ('string', 'tip')), small)
2134 2135 elif op == 'negate':
2135 2136 return optimize(('string',
2136 2137 '-' + getstring(x[1], _("can't negate that"))), small)
2137 2138 elif op in 'string symbol negate':
2138 2139 return smallbonus, x # single revisions are small
2139 2140 elif op == 'and':
2140 2141 wa, ta = optimize(x[1], True)
2141 2142 wb, tb = optimize(x[2], True)
2142 2143
2143 2144 # (::x and not ::y)/(not ::y and ::x) have a fast path
2144 2145 def isonly(revs, bases):
2145 2146 return (
2146 2147 revs[0] == 'func'
2147 2148 and getstring(revs[1], _('not a symbol')) == 'ancestors'
2148 2149 and bases[0] == 'not'
2149 2150 and bases[1][0] == 'func'
2150 2151 and getstring(bases[1][1], _('not a symbol')) == 'ancestors')
2151 2152
2152 2153 w = min(wa, wb)
2153 2154 if isonly(ta, tb):
2154 2155 return w, ('func', ('symbol', 'only'), ('list', ta[2], tb[1][2]))
2155 2156 if isonly(tb, ta):
2156 2157 return w, ('func', ('symbol', 'only'), ('list', tb[2], ta[1][2]))
2157 2158
2158 2159 if wa > wb:
2159 2160 return w, (op, tb, ta)
2160 2161 return w, (op, ta, tb)
2161 2162 elif op == 'or':
2162 2163 wa, ta = optimize(x[1], False)
2163 2164 wb, tb = optimize(x[2], False)
2164 2165 if wb < wa:
2165 2166 wb, wa = wa, wb
2166 2167 return max(wa, wb), (op, ta, tb)
2167 2168 elif op == 'not':
2168 2169 # Optimize not public() to _notpublic() because we have a fast version
2169 2170 if x[1] == ('func', ('symbol', 'public'), None):
2170 2171 newsym = ('func', ('symbol', '_notpublic'), None)
2171 2172 o = optimize(newsym, not small)
2172 2173 return o[0], o[1]
2173 2174 else:
2174 2175 o = optimize(x[1], not small)
2175 2176 return o[0], (op, o[1])
2176 2177 elif op == 'parentpost':
2177 2178 o = optimize(x[1], small)
2178 2179 return o[0], (op, o[1])
2179 2180 elif op == 'group':
2180 2181 return optimize(x[1], small)
2181 2182 elif op in 'dagrange range list parent ancestorspec':
2182 2183 if op == 'parent':
2183 2184 # x^:y means (x^) : y, not x ^ (:y)
2184 2185 post = ('parentpost', x[1])
2185 2186 if x[2][0] == 'dagrangepre':
2186 2187 return optimize(('dagrange', post, x[2][1]), small)
2187 2188 elif x[2][0] == 'rangepre':
2188 2189 return optimize(('range', post, x[2][1]), small)
2189 2190
2190 2191 wa, ta = optimize(x[1], small)
2191 2192 wb, tb = optimize(x[2], small)
2192 2193 return wa + wb, (op, ta, tb)
2193 2194 elif op == 'func':
2194 2195 f = getstring(x[1], _("not a symbol"))
2195 2196 wa, ta = optimize(x[2], small)
2196 2197 if f in ("author branch closed date desc file grep keyword "
2197 2198 "outgoing user"):
2198 2199 w = 10 # slow
2199 2200 elif f in "modifies adds removes":
2200 2201 w = 30 # slower
2201 2202 elif f == "contains":
2202 2203 w = 100 # very slow
2203 2204 elif f == "ancestor":
2204 2205 w = 1 * smallbonus
2205 2206 elif f in "reverse limit first _intlist":
2206 2207 w = 0
2207 2208 elif f in "sort":
2208 2209 w = 10 # assume most sorts look at changelog
2209 2210 else:
2210 2211 w = 1
2211 2212 return w + wa, (op, x[1], ta)
2212 2213 return 1, x
2213 2214
2214 2215 _aliasarg = ('func', ('symbol', '_aliasarg'))
2215 2216 def _getaliasarg(tree):
2216 2217 """If tree matches ('func', ('symbol', '_aliasarg'), ('string', X))
2217 2218 return X, None otherwise.
2218 2219 """
2219 2220 if (len(tree) == 3 and tree[:2] == _aliasarg
2220 2221 and tree[2][0] == 'string'):
2221 2222 return tree[2][1]
2222 2223 return None
2223 2224
2224 2225 def _checkaliasarg(tree, known=None):
2225 2226 """Check tree contains no _aliasarg construct or only ones which
2226 2227 value is in known. Used to avoid alias placeholders injection.
2227 2228 """
2228 2229 if isinstance(tree, tuple):
2229 2230 arg = _getaliasarg(tree)
2230 2231 if arg is not None and (not known or arg not in known):
2231 2232 raise error.UnknownIdentifier('_aliasarg', [])
2232 2233 for t in tree:
2233 2234 _checkaliasarg(t, known)
2234 2235
2235 2236 # the set of valid characters for the initial letter of symbols in
2236 2237 # alias declarations and definitions
2237 2238 _aliassyminitletters = set(c for c in [chr(i) for i in xrange(256)]
2238 2239 if c.isalnum() or c in '._@$' or ord(c) > 127)
2239 2240
2240 2241 def _tokenizealias(program, lookup=None):
2241 2242 """Parse alias declaration/definition into a stream of tokens
2242 2243
2243 2244 This allows symbol names to use also ``$`` as an initial letter
2244 2245 (for backward compatibility), and callers of this function should
2245 2246 examine whether ``$`` is used also for unexpected symbols or not.
2246 2247 """
2247 2248 return tokenize(program, lookup=lookup,
2248 2249 syminitletters=_aliassyminitletters)
2249 2250
2250 2251 def _parsealiasdecl(decl):
2251 2252 """Parse alias declaration ``decl``
2252 2253
2253 2254 This returns ``(name, tree, args, errorstr)`` tuple:
2254 2255
2255 2256 - ``name``: of declared alias (may be ``decl`` itself at error)
2256 2257 - ``tree``: parse result (or ``None`` at error)
2257 2258 - ``args``: list of alias argument names (or None for symbol declaration)
2258 2259 - ``errorstr``: detail about detected error (or None)
2259 2260
2260 2261 >>> _parsealiasdecl('foo')
2261 2262 ('foo', ('symbol', 'foo'), None, None)
2262 2263 >>> _parsealiasdecl('$foo')
2263 2264 ('$foo', None, None, "'$' not for alias arguments")
2264 2265 >>> _parsealiasdecl('foo::bar')
2265 2266 ('foo::bar', None, None, 'invalid format')
2266 2267 >>> _parsealiasdecl('foo bar')
2267 2268 ('foo bar', None, None, 'at 4: invalid token')
2268 2269 >>> _parsealiasdecl('foo()')
2269 2270 ('foo', ('func', ('symbol', 'foo')), [], None)
2270 2271 >>> _parsealiasdecl('$foo()')
2271 2272 ('$foo()', None, None, "'$' not for alias arguments")
2272 2273 >>> _parsealiasdecl('foo($1, $2)')
2273 2274 ('foo', ('func', ('symbol', 'foo')), ['$1', '$2'], None)
2274 2275 >>> _parsealiasdecl('foo(bar_bar, baz.baz)')
2275 2276 ('foo', ('func', ('symbol', 'foo')), ['bar_bar', 'baz.baz'], None)
2276 2277 >>> _parsealiasdecl('foo($1, $2, nested($1, $2))')
2277 2278 ('foo($1, $2, nested($1, $2))', None, None, 'invalid argument list')
2278 2279 >>> _parsealiasdecl('foo(bar($1, $2))')
2279 2280 ('foo(bar($1, $2))', None, None, 'invalid argument list')
2280 2281 >>> _parsealiasdecl('foo("string")')
2281 2282 ('foo("string")', None, None, 'invalid argument list')
2282 2283 >>> _parsealiasdecl('foo($1, $2')
2283 2284 ('foo($1, $2', None, None, 'at 10: unexpected token: end')
2284 2285 >>> _parsealiasdecl('foo("string')
2285 2286 ('foo("string', None, None, 'at 5: unterminated string')
2286 2287 >>> _parsealiasdecl('foo($1, $2, $1)')
2287 2288 ('foo', None, None, 'argument names collide with each other')
2288 2289 """
2289 2290 p = parser.parser(_tokenizealias, elements)
2290 2291 try:
2291 2292 tree, pos = p.parse(decl)
2292 2293 if (pos != len(decl)):
2293 2294 raise error.ParseError(_('invalid token'), pos)
2294 2295
2295 2296 if isvalidsymbol(tree):
2296 2297 # "name = ...." style
2297 2298 name = getsymbol(tree)
2298 2299 if name.startswith('$'):
2299 2300 return (decl, None, None, _("'$' not for alias arguments"))
2300 2301 return (name, ('symbol', name), None, None)
2301 2302
2302 2303 if isvalidfunc(tree):
2303 2304 # "name(arg, ....) = ...." style
2304 2305 name = getfuncname(tree)
2305 2306 if name.startswith('$'):
2306 2307 return (decl, None, None, _("'$' not for alias arguments"))
2307 2308 args = []
2308 2309 for arg in getfuncargs(tree):
2309 2310 if not isvalidsymbol(arg):
2310 2311 return (decl, None, None, _("invalid argument list"))
2311 2312 args.append(getsymbol(arg))
2312 2313 if len(args) != len(set(args)):
2313 2314 return (name, None, None,
2314 2315 _("argument names collide with each other"))
2315 2316 return (name, ('func', ('symbol', name)), args, None)
2316 2317
2317 2318 return (decl, None, None, _("invalid format"))
2318 2319 except error.ParseError, inst:
2319 2320 return (decl, None, None, parseerrordetail(inst))
2320 2321
2321 2322 def _parsealiasdefn(defn, args):
2322 2323 """Parse alias definition ``defn``
2323 2324
2324 2325 This function also replaces alias argument references in the
2325 2326 specified definition by ``_aliasarg(ARGNAME)``.
2326 2327
2327 2328 ``args`` is a list of alias argument names, or None if the alias
2328 2329 is declared as a symbol.
2329 2330
2330 2331 This returns "tree" as parsing result.
2331 2332
2332 2333 >>> args = ['$1', '$2', 'foo']
2333 2334 >>> print prettyformat(_parsealiasdefn('$1 or foo', args))
2334 2335 (or
2335 2336 (func
2336 2337 ('symbol', '_aliasarg')
2337 2338 ('string', '$1'))
2338 2339 (func
2339 2340 ('symbol', '_aliasarg')
2340 2341 ('string', 'foo')))
2341 2342 >>> try:
2342 2343 ... _parsealiasdefn('$1 or $bar', args)
2343 2344 ... except error.ParseError, inst:
2344 2345 ... print parseerrordetail(inst)
2345 2346 at 6: '$' not for alias arguments
2346 2347 >>> args = ['$1', '$10', 'foo']
2347 2348 >>> print prettyformat(_parsealiasdefn('$10 or foobar', args))
2348 2349 (or
2349 2350 (func
2350 2351 ('symbol', '_aliasarg')
2351 2352 ('string', '$10'))
2352 2353 ('symbol', 'foobar'))
2353 2354 >>> print prettyformat(_parsealiasdefn('"$1" or "foo"', args))
2354 2355 (or
2355 2356 ('string', '$1')
2356 2357 ('string', 'foo'))
2357 2358 """
2358 2359 def tokenizedefn(program, lookup=None):
2359 2360 if args:
2360 2361 argset = set(args)
2361 2362 else:
2362 2363 argset = set()
2363 2364
2364 2365 for t, value, pos in _tokenizealias(program, lookup=lookup):
2365 2366 if t == 'symbol':
2366 2367 if value in argset:
2367 2368 # emulate tokenization of "_aliasarg('ARGNAME')":
2368 2369 # "_aliasarg()" is an unknown symbol only used separate
2369 2370 # alias argument placeholders from regular strings.
2370 2371 yield ('symbol', '_aliasarg', pos)
2371 2372 yield ('(', None, pos)
2372 2373 yield ('string', value, pos)
2373 2374 yield (')', None, pos)
2374 2375 continue
2375 2376 elif value.startswith('$'):
2376 2377 raise error.ParseError(_("'$' not for alias arguments"),
2377 2378 pos)
2378 2379 yield (t, value, pos)
2379 2380
2380 2381 p = parser.parser(tokenizedefn, elements)
2381 2382 tree, pos = p.parse(defn)
2382 2383 if pos != len(defn):
2383 2384 raise error.ParseError(_('invalid token'), pos)
2384 2385 return tree
2385 2386
2386 2387 class revsetalias(object):
2387 2388 # whether own `error` information is already shown or not.
2388 2389 # this avoids showing same warning multiple times at each `findaliases`.
2389 2390 warned = False
2390 2391
2391 2392 def __init__(self, name, value):
2392 2393 '''Aliases like:
2393 2394
2394 2395 h = heads(default)
2395 2396 b($1) = ancestors($1) - ancestors(default)
2396 2397 '''
2397 2398 self.name, self.tree, self.args, self.error = _parsealiasdecl(name)
2398 2399 if self.error:
2399 2400 self.error = _('failed to parse the declaration of revset alias'
2400 2401 ' "%s": %s') % (self.name, self.error)
2401 2402 return
2402 2403
2403 2404 try:
2404 2405 self.replacement = _parsealiasdefn(value, self.args)
2405 2406 # Check for placeholder injection
2406 2407 _checkaliasarg(self.replacement, self.args)
2407 2408 except error.ParseError, inst:
2408 2409 self.error = _('failed to parse the definition of revset alias'
2409 2410 ' "%s": %s') % (self.name, parseerrordetail(inst))
2410 2411
2411 2412 def _getalias(aliases, tree):
2412 2413 """If tree looks like an unexpanded alias, return it. Return None
2413 2414 otherwise.
2414 2415 """
2415 2416 if isinstance(tree, tuple) and tree:
2416 2417 if tree[0] == 'symbol' and len(tree) == 2:
2417 2418 name = tree[1]
2418 2419 alias = aliases.get(name)
2419 2420 if alias and alias.args is None and alias.tree == tree:
2420 2421 return alias
2421 2422 if tree[0] == 'func' and len(tree) > 1:
2422 2423 if tree[1][0] == 'symbol' and len(tree[1]) == 2:
2423 2424 name = tree[1][1]
2424 2425 alias = aliases.get(name)
2425 2426 if alias and alias.args is not None and alias.tree == tree[:2]:
2426 2427 return alias
2427 2428 return None
2428 2429
2429 2430 def _expandargs(tree, args):
2430 2431 """Replace _aliasarg instances with the substitution value of the
2431 2432 same name in args, recursively.
2432 2433 """
2433 2434 if not tree or not isinstance(tree, tuple):
2434 2435 return tree
2435 2436 arg = _getaliasarg(tree)
2436 2437 if arg is not None:
2437 2438 return args[arg]
2438 2439 return tuple(_expandargs(t, args) for t in tree)
2439 2440
2440 2441 def _expandaliases(aliases, tree, expanding, cache):
2441 2442 """Expand aliases in tree, recursively.
2442 2443
2443 2444 'aliases' is a dictionary mapping user defined aliases to
2444 2445 revsetalias objects.
2445 2446 """
2446 2447 if not isinstance(tree, tuple):
2447 2448 # Do not expand raw strings
2448 2449 return tree
2449 2450 alias = _getalias(aliases, tree)
2450 2451 if alias is not None:
2451 2452 if alias.error:
2452 2453 raise util.Abort(alias.error)
2453 2454 if alias in expanding:
2454 2455 raise error.ParseError(_('infinite expansion of revset alias "%s" '
2455 2456 'detected') % alias.name)
2456 2457 expanding.append(alias)
2457 2458 if alias.name not in cache:
2458 2459 cache[alias.name] = _expandaliases(aliases, alias.replacement,
2459 2460 expanding, cache)
2460 2461 result = cache[alias.name]
2461 2462 expanding.pop()
2462 2463 if alias.args is not None:
2463 2464 l = getlist(tree[2])
2464 2465 if len(l) != len(alias.args):
2465 2466 raise error.ParseError(
2466 2467 _('invalid number of arguments: %s') % len(l))
2467 2468 l = [_expandaliases(aliases, a, [], cache) for a in l]
2468 2469 result = _expandargs(result, dict(zip(alias.args, l)))
2469 2470 else:
2470 2471 result = tuple(_expandaliases(aliases, t, expanding, cache)
2471 2472 for t in tree)
2472 2473 return result
2473 2474
2474 2475 def findaliases(ui, tree, showwarning=None):
2475 2476 _checkaliasarg(tree)
2476 2477 aliases = {}
2477 2478 for k, v in ui.configitems('revsetalias'):
2478 2479 alias = revsetalias(k, v)
2479 2480 aliases[alias.name] = alias
2480 2481 tree = _expandaliases(aliases, tree, [], {})
2481 2482 if showwarning:
2482 2483 # warn about problematic (but not referred) aliases
2483 2484 for name, alias in sorted(aliases.iteritems()):
2484 2485 if alias.error and not alias.warned:
2485 2486 showwarning(_('warning: %s\n') % (alias.error))
2486 2487 alias.warned = True
2487 2488 return tree
2488 2489
2489 2490 def foldconcat(tree):
2490 2491 """Fold elements to be concatenated by `##`
2491 2492 """
2492 2493 if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
2493 2494 return tree
2494 2495 if tree[0] == '_concat':
2495 2496 pending = [tree]
2496 2497 l = []
2497 2498 while pending:
2498 2499 e = pending.pop()
2499 2500 if e[0] == '_concat':
2500 2501 pending.extend(reversed(e[1:]))
2501 2502 elif e[0] in ('string', 'symbol'):
2502 2503 l.append(e[1])
2503 2504 else:
2504 2505 msg = _("\"##\" can't concatenate \"%s\" element") % (e[0])
2505 2506 raise error.ParseError(msg)
2506 2507 return ('string', ''.join(l))
2507 2508 else:
2508 2509 return tuple(foldconcat(t) for t in tree)
2509 2510
2510 2511 def parse(spec, lookup=None):
2511 2512 p = parser.parser(tokenize, elements)
2512 2513 tree, pos = p.parse(spec, lookup=lookup)
2513 2514 if pos != len(spec):
2514 2515 raise error.ParseError(_("invalid token"), pos)
2515 2516 return tree
2516 2517
2517 2518 def posttreebuilthook(tree, repo):
2518 2519 # hook for extensions to execute code on the optimized tree
2519 2520 pass
2520 2521
2521 2522 def match(ui, spec, repo=None):
2522 2523 if not spec:
2523 2524 raise error.ParseError(_("empty query"))
2524 2525 lookup = None
2525 2526 if repo:
2526 2527 lookup = repo.__contains__
2527 2528 tree = parse(spec, lookup)
2528 2529 if ui:
2529 2530 tree = findaliases(ui, tree, showwarning=ui.warn)
2530 2531 tree = foldconcat(tree)
2531 2532 weight, tree = optimize(tree, True)
2532 2533 posttreebuilthook(tree, repo)
2533 2534 def mfunc(repo, subset=None):
2534 2535 if subset is None:
2535 2536 subset = fullreposet(repo)
2536 2537 if util.safehasattr(subset, 'isascending'):
2537 2538 result = getset(repo, subset, tree)
2538 2539 else:
2539 2540 result = getset(repo, baseset(subset), tree)
2540 2541 return result
2541 2542 return mfunc
2542 2543
2543 2544 def formatspec(expr, *args):
2544 2545 '''
2545 2546 This is a convenience function for using revsets internally, and
2546 2547 escapes arguments appropriately. Aliases are intentionally ignored
2547 2548 so that intended expression behavior isn't accidentally subverted.
2548 2549
2549 2550 Supported arguments:
2550 2551
2551 2552 %r = revset expression, parenthesized
2552 2553 %d = int(arg), no quoting
2553 2554 %s = string(arg), escaped and single-quoted
2554 2555 %b = arg.branch(), escaped and single-quoted
2555 2556 %n = hex(arg), single-quoted
2556 2557 %% = a literal '%'
2557 2558
2558 2559 Prefixing the type with 'l' specifies a parenthesized list of that type.
2559 2560
2560 2561 >>> formatspec('%r:: and %lr', '10 or 11', ("this()", "that()"))
2561 2562 '(10 or 11):: and ((this()) or (that()))'
2562 2563 >>> formatspec('%d:: and not %d::', 10, 20)
2563 2564 '10:: and not 20::'
2564 2565 >>> formatspec('%ld or %ld', [], [1])
2565 2566 "_list('') or 1"
2566 2567 >>> formatspec('keyword(%s)', 'foo\\xe9')
2567 2568 "keyword('foo\\\\xe9')"
2568 2569 >>> b = lambda: 'default'
2569 2570 >>> b.branch = b
2570 2571 >>> formatspec('branch(%b)', b)
2571 2572 "branch('default')"
2572 2573 >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd'])
2573 2574 "root(_list('a\\x00b\\x00c\\x00d'))"
2574 2575 '''
2575 2576
2576 2577 def quote(s):
2577 2578 return repr(str(s))
2578 2579
2579 2580 def argtype(c, arg):
2580 2581 if c == 'd':
2581 2582 return str(int(arg))
2582 2583 elif c == 's':
2583 2584 return quote(arg)
2584 2585 elif c == 'r':
2585 2586 parse(arg) # make sure syntax errors are confined
2586 2587 return '(%s)' % arg
2587 2588 elif c == 'n':
2588 2589 return quote(node.hex(arg))
2589 2590 elif c == 'b':
2590 2591 return quote(arg.branch())
2591 2592
2592 2593 def listexp(s, t):
2593 2594 l = len(s)
2594 2595 if l == 0:
2595 2596 return "_list('')"
2596 2597 elif l == 1:
2597 2598 return argtype(t, s[0])
2598 2599 elif t == 'd':
2599 2600 return "_intlist('%s')" % "\0".join(str(int(a)) for a in s)
2600 2601 elif t == 's':
2601 2602 return "_list('%s')" % "\0".join(s)
2602 2603 elif t == 'n':
2603 2604 return "_hexlist('%s')" % "\0".join(node.hex(a) for a in s)
2604 2605 elif t == 'b':
2605 2606 return "_list('%s')" % "\0".join(a.branch() for a in s)
2606 2607
2607 2608 m = l // 2
2608 2609 return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t))
2609 2610
2610 2611 ret = ''
2611 2612 pos = 0
2612 2613 arg = 0
2613 2614 while pos < len(expr):
2614 2615 c = expr[pos]
2615 2616 if c == '%':
2616 2617 pos += 1
2617 2618 d = expr[pos]
2618 2619 if d == '%':
2619 2620 ret += d
2620 2621 elif d in 'dsnbr':
2621 2622 ret += argtype(d, args[arg])
2622 2623 arg += 1
2623 2624 elif d == 'l':
2624 2625 # a list of some type
2625 2626 pos += 1
2626 2627 d = expr[pos]
2627 2628 ret += listexp(list(args[arg]), d)
2628 2629 arg += 1
2629 2630 else:
2630 2631 raise util.Abort('unexpected revspec format character %s' % d)
2631 2632 else:
2632 2633 ret += c
2633 2634 pos += 1
2634 2635
2635 2636 return ret
2636 2637
2637 2638 def prettyformat(tree):
2638 2639 return parser.prettyformat(tree, ('string', 'symbol'))
2639 2640
2640 2641 def depth(tree):
2641 2642 if isinstance(tree, tuple):
2642 2643 return max(map(depth, tree)) + 1
2643 2644 else:
2644 2645 return 0
2645 2646
2646 2647 def funcsused(tree):
2647 2648 if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
2648 2649 return set()
2649 2650 else:
2650 2651 funcs = set()
2651 2652 for s in tree[1:]:
2652 2653 funcs |= funcsused(s)
2653 2654 if tree[0] == 'func':
2654 2655 funcs.add(tree[1][1])
2655 2656 return funcs
2656 2657
2657 2658 class abstractsmartset(object):
2658 2659
2659 2660 def __nonzero__(self):
2660 2661 """True if the smartset is not empty"""
2661 2662 raise NotImplementedError()
2662 2663
2663 2664 def __contains__(self, rev):
2664 2665 """provide fast membership testing"""
2665 2666 raise NotImplementedError()
2666 2667
2667 2668 def __iter__(self):
2668 2669 """iterate the set in the order it is supposed to be iterated"""
2669 2670 raise NotImplementedError()
2670 2671
2671 2672 # Attributes containing a function to perform a fast iteration in a given
2672 2673 # direction. A smartset can have none, one, or both defined.
2673 2674 #
2674 2675 # Default value is None instead of a function returning None to avoid
2675 2676 # initializing an iterator just for testing if a fast method exists.
2676 2677 fastasc = None
2677 2678 fastdesc = None
2678 2679
2679 2680 def isascending(self):
2680 2681 """True if the set will iterate in ascending order"""
2681 2682 raise NotImplementedError()
2682 2683
2683 2684 def isdescending(self):
2684 2685 """True if the set will iterate in descending order"""
2685 2686 raise NotImplementedError()
2686 2687
2687 2688 def min(self):
2688 2689 """return the minimum element in the set"""
2689 2690 if self.fastasc is not None:
2690 2691 for r in self.fastasc():
2691 2692 return r
2692 2693 raise ValueError('arg is an empty sequence')
2693 2694 return min(self)
2694 2695
2695 2696 def max(self):
2696 2697 """return the maximum element in the set"""
2697 2698 if self.fastdesc is not None:
2698 2699 for r in self.fastdesc():
2699 2700 return r
2700 2701 raise ValueError('arg is an empty sequence')
2701 2702 return max(self)
2702 2703
2703 2704 def first(self):
2704 2705 """return the first element in the set (user iteration perspective)
2705 2706
2706 2707 Return None if the set is empty"""
2707 2708 raise NotImplementedError()
2708 2709
2709 2710 def last(self):
2710 2711 """return the last element in the set (user iteration perspective)
2711 2712
2712 2713 Return None if the set is empty"""
2713 2714 raise NotImplementedError()
2714 2715
2715 2716 def __len__(self):
2716 2717 """return the length of the smartsets
2717 2718
2718 2719 This can be expensive on smartset that could be lazy otherwise."""
2719 2720 raise NotImplementedError()
2720 2721
2721 2722 def reverse(self):
2722 2723 """reverse the expected iteration order"""
2723 2724 raise NotImplementedError()
2724 2725
2725 2726 def sort(self, reverse=True):
2726 2727 """get the set to iterate in an ascending or descending order"""
2727 2728 raise NotImplementedError()
2728 2729
2729 2730 def __and__(self, other):
2730 2731 """Returns a new object with the intersection of the two collections.
2731 2732
2732 2733 This is part of the mandatory API for smartset."""
2733 2734 if isinstance(other, fullreposet):
2734 2735 return self
2735 2736 return self.filter(other.__contains__, cache=False)
2736 2737
2737 2738 def __add__(self, other):
2738 2739 """Returns a new object with the union of the two collections.
2739 2740
2740 2741 This is part of the mandatory API for smartset."""
2741 2742 return addset(self, other)
2742 2743
2743 2744 def __sub__(self, other):
2744 2745 """Returns a new object with the substraction of the two collections.
2745 2746
2746 2747 This is part of the mandatory API for smartset."""
2747 2748 c = other.__contains__
2748 2749 return self.filter(lambda r: not c(r), cache=False)
2749 2750
2750 2751 def filter(self, condition, cache=True):
2751 2752 """Returns this smartset filtered by condition as a new smartset.
2752 2753
2753 2754 `condition` is a callable which takes a revision number and returns a
2754 2755 boolean.
2755 2756
2756 2757 This is part of the mandatory API for smartset."""
2757 2758 # builtin cannot be cached. but do not needs to
2758 2759 if cache and util.safehasattr(condition, 'func_code'):
2759 2760 condition = util.cachefunc(condition)
2760 2761 return filteredset(self, condition)
2761 2762
2762 2763 class baseset(abstractsmartset):
2763 2764 """Basic data structure that represents a revset and contains the basic
2764 2765 operation that it should be able to perform.
2765 2766
2766 2767 Every method in this class should be implemented by any smartset class.
2767 2768 """
2768 2769 def __init__(self, data=()):
2769 2770 if not isinstance(data, list):
2770 2771 data = list(data)
2771 2772 self._list = data
2772 2773 self._ascending = None
2773 2774
2774 2775 @util.propertycache
2775 2776 def _set(self):
2776 2777 return set(self._list)
2777 2778
2778 2779 @util.propertycache
2779 2780 def _asclist(self):
2780 2781 asclist = self._list[:]
2781 2782 asclist.sort()
2782 2783 return asclist
2783 2784
2784 2785 def __iter__(self):
2785 2786 if self._ascending is None:
2786 2787 return iter(self._list)
2787 2788 elif self._ascending:
2788 2789 return iter(self._asclist)
2789 2790 else:
2790 2791 return reversed(self._asclist)
2791 2792
2792 2793 def fastasc(self):
2793 2794 return iter(self._asclist)
2794 2795
2795 2796 def fastdesc(self):
2796 2797 return reversed(self._asclist)
2797 2798
2798 2799 @util.propertycache
2799 2800 def __contains__(self):
2800 2801 return self._set.__contains__
2801 2802
2802 2803 def __nonzero__(self):
2803 2804 return bool(self._list)
2804 2805
2805 2806 def sort(self, reverse=False):
2806 2807 self._ascending = not bool(reverse)
2807 2808
2808 2809 def reverse(self):
2809 2810 if self._ascending is None:
2810 2811 self._list.reverse()
2811 2812 else:
2812 2813 self._ascending = not self._ascending
2813 2814
2814 2815 def __len__(self):
2815 2816 return len(self._list)
2816 2817
2817 2818 def isascending(self):
2818 2819 """Returns True if the collection is ascending order, False if not.
2819 2820
2820 2821 This is part of the mandatory API for smartset."""
2821 2822 if len(self) <= 1:
2822 2823 return True
2823 2824 return self._ascending is not None and self._ascending
2824 2825
2825 2826 def isdescending(self):
2826 2827 """Returns True if the collection is descending order, False if not.
2827 2828
2828 2829 This is part of the mandatory API for smartset."""
2829 2830 if len(self) <= 1:
2830 2831 return True
2831 2832 return self._ascending is not None and not self._ascending
2832 2833
2833 2834 def first(self):
2834 2835 if self:
2835 2836 if self._ascending is None:
2836 2837 return self._list[0]
2837 2838 elif self._ascending:
2838 2839 return self._asclist[0]
2839 2840 else:
2840 2841 return self._asclist[-1]
2841 2842 return None
2842 2843
2843 2844 def last(self):
2844 2845 if self:
2845 2846 if self._ascending is None:
2846 2847 return self._list[-1]
2847 2848 elif self._ascending:
2848 2849 return self._asclist[-1]
2849 2850 else:
2850 2851 return self._asclist[0]
2851 2852 return None
2852 2853
2853 2854 def __repr__(self):
2854 2855 d = {None: '', False: '-', True: '+'}[self._ascending]
2855 2856 return '<%s%s %r>' % (type(self).__name__, d, self._list)
2856 2857
2857 2858 class filteredset(abstractsmartset):
2858 2859 """Duck type for baseset class which iterates lazily over the revisions in
2859 2860 the subset and contains a function which tests for membership in the
2860 2861 revset
2861 2862 """
2862 2863 def __init__(self, subset, condition=lambda x: True):
2863 2864 """
2864 2865 condition: a function that decide whether a revision in the subset
2865 2866 belongs to the revset or not.
2866 2867 """
2867 2868 self._subset = subset
2868 2869 self._condition = condition
2869 2870 self._cache = {}
2870 2871
2871 2872 def __contains__(self, x):
2872 2873 c = self._cache
2873 2874 if x not in c:
2874 2875 v = c[x] = x in self._subset and self._condition(x)
2875 2876 return v
2876 2877 return c[x]
2877 2878
2878 2879 def __iter__(self):
2879 2880 return self._iterfilter(self._subset)
2880 2881
2881 2882 def _iterfilter(self, it):
2882 2883 cond = self._condition
2883 2884 for x in it:
2884 2885 if cond(x):
2885 2886 yield x
2886 2887
2887 2888 @property
2888 2889 def fastasc(self):
2889 2890 it = self._subset.fastasc
2890 2891 if it is None:
2891 2892 return None
2892 2893 return lambda: self._iterfilter(it())
2893 2894
2894 2895 @property
2895 2896 def fastdesc(self):
2896 2897 it = self._subset.fastdesc
2897 2898 if it is None:
2898 2899 return None
2899 2900 return lambda: self._iterfilter(it())
2900 2901
2901 2902 def __nonzero__(self):
2902 2903 for r in self:
2903 2904 return True
2904 2905 return False
2905 2906
2906 2907 def __len__(self):
2907 2908 # Basic implementation to be changed in future patches.
2908 2909 l = baseset([r for r in self])
2909 2910 return len(l)
2910 2911
2911 2912 def sort(self, reverse=False):
2912 2913 self._subset.sort(reverse=reverse)
2913 2914
2914 2915 def reverse(self):
2915 2916 self._subset.reverse()
2916 2917
2917 2918 def isascending(self):
2918 2919 return self._subset.isascending()
2919 2920
2920 2921 def isdescending(self):
2921 2922 return self._subset.isdescending()
2922 2923
2923 2924 def first(self):
2924 2925 for x in self:
2925 2926 return x
2926 2927 return None
2927 2928
2928 2929 def last(self):
2929 2930 it = None
2930 2931 if self._subset.isascending:
2931 2932 it = self.fastdesc
2932 2933 elif self._subset.isdescending:
2933 2934 it = self.fastdesc
2934 2935 if it is None:
2935 2936 # slowly consume everything. This needs improvement
2936 2937 it = lambda: reversed(list(self))
2937 2938 for x in it():
2938 2939 return x
2939 2940 return None
2940 2941
2941 2942 def __repr__(self):
2942 2943 return '<%s %r>' % (type(self).__name__, self._subset)
2943 2944
2944 2945 def _iterordered(ascending, iter1, iter2):
2945 2946 """produce an ordered iteration from two iterators with the same order
2946 2947
2947 2948 The ascending is used to indicated the iteration direction.
2948 2949 """
2949 2950 choice = max
2950 2951 if ascending:
2951 2952 choice = min
2952 2953
2953 2954 val1 = None
2954 2955 val2 = None
2955 2956 try:
2956 2957 # Consume both iterators in an ordered way until one is empty
2957 2958 while True:
2958 2959 if val1 is None:
2959 2960 val1 = iter1.next()
2960 2961 if val2 is None:
2961 2962 val2 = iter2.next()
2962 2963 next = choice(val1, val2)
2963 2964 yield next
2964 2965 if val1 == next:
2965 2966 val1 = None
2966 2967 if val2 == next:
2967 2968 val2 = None
2968 2969 except StopIteration:
2969 2970 # Flush any remaining values and consume the other one
2970 2971 it = iter2
2971 2972 if val1 is not None:
2972 2973 yield val1
2973 2974 it = iter1
2974 2975 elif val2 is not None:
2975 2976 # might have been equality and both are empty
2976 2977 yield val2
2977 2978 for val in it:
2978 2979 yield val
2979 2980
2980 2981 class addset(abstractsmartset):
2981 2982 """Represent the addition of two sets
2982 2983
2983 2984 Wrapper structure for lazily adding two structures without losing much
2984 2985 performance on the __contains__ method
2985 2986
2986 2987 If the ascending attribute is set, that means the two structures are
2987 2988 ordered in either an ascending or descending way. Therefore, we can add
2988 2989 them maintaining the order by iterating over both at the same time
2989 2990
2990 2991 >>> xs = baseset([0, 3, 2])
2991 2992 >>> ys = baseset([5, 2, 4])
2992 2993
2993 2994 >>> rs = addset(xs, ys)
2994 2995 >>> bool(rs), 0 in rs, 1 in rs, 5 in rs, rs.first(), rs.last()
2995 2996 (True, True, False, True, 0, 4)
2996 2997 >>> rs = addset(xs, baseset([]))
2997 2998 >>> bool(rs), 0 in rs, 1 in rs, rs.first(), rs.last()
2998 2999 (True, True, False, 0, 2)
2999 3000 >>> rs = addset(baseset([]), baseset([]))
3000 3001 >>> bool(rs), 0 in rs, rs.first(), rs.last()
3001 3002 (False, False, None, None)
3002 3003
3003 3004 iterate unsorted:
3004 3005 >>> rs = addset(xs, ys)
3005 3006 >>> [x for x in rs] # without _genlist
3006 3007 [0, 3, 2, 5, 4]
3007 3008 >>> assert not rs._genlist
3008 3009 >>> len(rs)
3009 3010 5
3010 3011 >>> [x for x in rs] # with _genlist
3011 3012 [0, 3, 2, 5, 4]
3012 3013 >>> assert rs._genlist
3013 3014
3014 3015 iterate ascending:
3015 3016 >>> rs = addset(xs, ys, ascending=True)
3016 3017 >>> [x for x in rs], [x for x in rs.fastasc()] # without _asclist
3017 3018 ([0, 2, 3, 4, 5], [0, 2, 3, 4, 5])
3018 3019 >>> assert not rs._asclist
3019 3020 >>> len(rs)
3020 3021 5
3021 3022 >>> [x for x in rs], [x for x in rs.fastasc()]
3022 3023 ([0, 2, 3, 4, 5], [0, 2, 3, 4, 5])
3023 3024 >>> assert rs._asclist
3024 3025
3025 3026 iterate descending:
3026 3027 >>> rs = addset(xs, ys, ascending=False)
3027 3028 >>> [x for x in rs], [x for x in rs.fastdesc()] # without _asclist
3028 3029 ([5, 4, 3, 2, 0], [5, 4, 3, 2, 0])
3029 3030 >>> assert not rs._asclist
3030 3031 >>> len(rs)
3031 3032 5
3032 3033 >>> [x for x in rs], [x for x in rs.fastdesc()]
3033 3034 ([5, 4, 3, 2, 0], [5, 4, 3, 2, 0])
3034 3035 >>> assert rs._asclist
3035 3036
3036 3037 iterate ascending without fastasc:
3037 3038 >>> rs = addset(xs, generatorset(ys), ascending=True)
3038 3039 >>> assert rs.fastasc is None
3039 3040 >>> [x for x in rs]
3040 3041 [0, 2, 3, 4, 5]
3041 3042
3042 3043 iterate descending without fastdesc:
3043 3044 >>> rs = addset(generatorset(xs), ys, ascending=False)
3044 3045 >>> assert rs.fastdesc is None
3045 3046 >>> [x for x in rs]
3046 3047 [5, 4, 3, 2, 0]
3047 3048 """
3048 3049 def __init__(self, revs1, revs2, ascending=None):
3049 3050 self._r1 = revs1
3050 3051 self._r2 = revs2
3051 3052 self._iter = None
3052 3053 self._ascending = ascending
3053 3054 self._genlist = None
3054 3055 self._asclist = None
3055 3056
3056 3057 def __len__(self):
3057 3058 return len(self._list)
3058 3059
3059 3060 def __nonzero__(self):
3060 3061 return bool(self._r1) or bool(self._r2)
3061 3062
3062 3063 @util.propertycache
3063 3064 def _list(self):
3064 3065 if not self._genlist:
3065 3066 self._genlist = baseset(iter(self))
3066 3067 return self._genlist
3067 3068
3068 3069 def __iter__(self):
3069 3070 """Iterate over both collections without repeating elements
3070 3071
3071 3072 If the ascending attribute is not set, iterate over the first one and
3072 3073 then over the second one checking for membership on the first one so we
3073 3074 dont yield any duplicates.
3074 3075
3075 3076 If the ascending attribute is set, iterate over both collections at the
3076 3077 same time, yielding only one value at a time in the given order.
3077 3078 """
3078 3079 if self._ascending is None:
3079 3080 if self._genlist:
3080 3081 return iter(self._genlist)
3081 3082 def arbitraryordergen():
3082 3083 for r in self._r1:
3083 3084 yield r
3084 3085 inr1 = self._r1.__contains__
3085 3086 for r in self._r2:
3086 3087 if not inr1(r):
3087 3088 yield r
3088 3089 return arbitraryordergen()
3089 3090 # try to use our own fast iterator if it exists
3090 3091 self._trysetasclist()
3091 3092 if self._ascending:
3092 3093 attr = 'fastasc'
3093 3094 else:
3094 3095 attr = 'fastdesc'
3095 3096 it = getattr(self, attr)
3096 3097 if it is not None:
3097 3098 return it()
3098 3099 # maybe half of the component supports fast
3099 3100 # get iterator for _r1
3100 3101 iter1 = getattr(self._r1, attr)
3101 3102 if iter1 is None:
3102 3103 # let's avoid side effect (not sure it matters)
3103 3104 iter1 = iter(sorted(self._r1, reverse=not self._ascending))
3104 3105 else:
3105 3106 iter1 = iter1()
3106 3107 # get iterator for _r2
3107 3108 iter2 = getattr(self._r2, attr)
3108 3109 if iter2 is None:
3109 3110 # let's avoid side effect (not sure it matters)
3110 3111 iter2 = iter(sorted(self._r2, reverse=not self._ascending))
3111 3112 else:
3112 3113 iter2 = iter2()
3113 3114 return _iterordered(self._ascending, iter1, iter2)
3114 3115
3115 3116 def _trysetasclist(self):
3116 3117 """populate the _asclist attribute if possible and necessary"""
3117 3118 if self._genlist is not None and self._asclist is None:
3118 3119 self._asclist = sorted(self._genlist)
3119 3120
3120 3121 @property
3121 3122 def fastasc(self):
3122 3123 self._trysetasclist()
3123 3124 if self._asclist is not None:
3124 3125 return self._asclist.__iter__
3125 3126 iter1 = self._r1.fastasc
3126 3127 iter2 = self._r2.fastasc
3127 3128 if None in (iter1, iter2):
3128 3129 return None
3129 3130 return lambda: _iterordered(True, iter1(), iter2())
3130 3131
3131 3132 @property
3132 3133 def fastdesc(self):
3133 3134 self._trysetasclist()
3134 3135 if self._asclist is not None:
3135 3136 return self._asclist.__reversed__
3136 3137 iter1 = self._r1.fastdesc
3137 3138 iter2 = self._r2.fastdesc
3138 3139 if None in (iter1, iter2):
3139 3140 return None
3140 3141 return lambda: _iterordered(False, iter1(), iter2())
3141 3142
3142 3143 def __contains__(self, x):
3143 3144 return x in self._r1 or x in self._r2
3144 3145
3145 3146 def sort(self, reverse=False):
3146 3147 """Sort the added set
3147 3148
3148 3149 For this we use the cached list with all the generated values and if we
3149 3150 know they are ascending or descending we can sort them in a smart way.
3150 3151 """
3151 3152 self._ascending = not reverse
3152 3153
3153 3154 def isascending(self):
3154 3155 return self._ascending is not None and self._ascending
3155 3156
3156 3157 def isdescending(self):
3157 3158 return self._ascending is not None and not self._ascending
3158 3159
3159 3160 def reverse(self):
3160 3161 if self._ascending is None:
3161 3162 self._list.reverse()
3162 3163 else:
3163 3164 self._ascending = not self._ascending
3164 3165
3165 3166 def first(self):
3166 3167 for x in self:
3167 3168 return x
3168 3169 return None
3169 3170
3170 3171 def last(self):
3171 3172 self.reverse()
3172 3173 val = self.first()
3173 3174 self.reverse()
3174 3175 return val
3175 3176
3176 3177 def __repr__(self):
3177 3178 d = {None: '', False: '-', True: '+'}[self._ascending]
3178 3179 return '<%s%s %r, %r>' % (type(self).__name__, d, self._r1, self._r2)
3179 3180
3180 3181 class generatorset(abstractsmartset):
3181 3182 """Wrap a generator for lazy iteration
3182 3183
3183 3184 Wrapper structure for generators that provides lazy membership and can
3184 3185 be iterated more than once.
3185 3186 When asked for membership it generates values until either it finds the
3186 3187 requested one or has gone through all the elements in the generator
3187 3188 """
3188 3189 def __init__(self, gen, iterasc=None):
3189 3190 """
3190 3191 gen: a generator producing the values for the generatorset.
3191 3192 """
3192 3193 self._gen = gen
3193 3194 self._asclist = None
3194 3195 self._cache = {}
3195 3196 self._genlist = []
3196 3197 self._finished = False
3197 3198 self._ascending = True
3198 3199 if iterasc is not None:
3199 3200 if iterasc:
3200 3201 self.fastasc = self._iterator
3201 3202 self.__contains__ = self._asccontains
3202 3203 else:
3203 3204 self.fastdesc = self._iterator
3204 3205 self.__contains__ = self._desccontains
3205 3206
3206 3207 def __nonzero__(self):
3207 3208 # Do not use 'for r in self' because it will enforce the iteration
3208 3209 # order (default ascending), possibly unrolling a whole descending
3209 3210 # iterator.
3210 3211 if self._genlist:
3211 3212 return True
3212 3213 for r in self._consumegen():
3213 3214 return True
3214 3215 return False
3215 3216
3216 3217 def __contains__(self, x):
3217 3218 if x in self._cache:
3218 3219 return self._cache[x]
3219 3220
3220 3221 # Use new values only, as existing values would be cached.
3221 3222 for l in self._consumegen():
3222 3223 if l == x:
3223 3224 return True
3224 3225
3225 3226 self._cache[x] = False
3226 3227 return False
3227 3228
3228 3229 def _asccontains(self, x):
3229 3230 """version of contains optimised for ascending generator"""
3230 3231 if x in self._cache:
3231 3232 return self._cache[x]
3232 3233
3233 3234 # Use new values only, as existing values would be cached.
3234 3235 for l in self._consumegen():
3235 3236 if l == x:
3236 3237 return True
3237 3238 if l > x:
3238 3239 break
3239 3240
3240 3241 self._cache[x] = False
3241 3242 return False
3242 3243
3243 3244 def _desccontains(self, x):
3244 3245 """version of contains optimised for descending generator"""
3245 3246 if x in self._cache:
3246 3247 return self._cache[x]
3247 3248
3248 3249 # Use new values only, as existing values would be cached.
3249 3250 for l in self._consumegen():
3250 3251 if l == x:
3251 3252 return True
3252 3253 if l < x:
3253 3254 break
3254 3255
3255 3256 self._cache[x] = False
3256 3257 return False
3257 3258
3258 3259 def __iter__(self):
3259 3260 if self._ascending:
3260 3261 it = self.fastasc
3261 3262 else:
3262 3263 it = self.fastdesc
3263 3264 if it is not None:
3264 3265 return it()
3265 3266 # we need to consume the iterator
3266 3267 for x in self._consumegen():
3267 3268 pass
3268 3269 # recall the same code
3269 3270 return iter(self)
3270 3271
3271 3272 def _iterator(self):
3272 3273 if self._finished:
3273 3274 return iter(self._genlist)
3274 3275
3275 3276 # We have to use this complex iteration strategy to allow multiple
3276 3277 # iterations at the same time. We need to be able to catch revision
3277 3278 # removed from _consumegen and added to genlist in another instance.
3278 3279 #
3279 3280 # Getting rid of it would provide an about 15% speed up on this
3280 3281 # iteration.
3281 3282 genlist = self._genlist
3282 3283 nextrev = self._consumegen().next
3283 3284 _len = len # cache global lookup
3284 3285 def gen():
3285 3286 i = 0
3286 3287 while True:
3287 3288 if i < _len(genlist):
3288 3289 yield genlist[i]
3289 3290 else:
3290 3291 yield nextrev()
3291 3292 i += 1
3292 3293 return gen()
3293 3294
3294 3295 def _consumegen(self):
3295 3296 cache = self._cache
3296 3297 genlist = self._genlist.append
3297 3298 for item in self._gen:
3298 3299 cache[item] = True
3299 3300 genlist(item)
3300 3301 yield item
3301 3302 if not self._finished:
3302 3303 self._finished = True
3303 3304 asc = self._genlist[:]
3304 3305 asc.sort()
3305 3306 self._asclist = asc
3306 3307 self.fastasc = asc.__iter__
3307 3308 self.fastdesc = asc.__reversed__
3308 3309
3309 3310 def __len__(self):
3310 3311 for x in self._consumegen():
3311 3312 pass
3312 3313 return len(self._genlist)
3313 3314
3314 3315 def sort(self, reverse=False):
3315 3316 self._ascending = not reverse
3316 3317
3317 3318 def reverse(self):
3318 3319 self._ascending = not self._ascending
3319 3320
3320 3321 def isascending(self):
3321 3322 return self._ascending
3322 3323
3323 3324 def isdescending(self):
3324 3325 return not self._ascending
3325 3326
3326 3327 def first(self):
3327 3328 if self._ascending:
3328 3329 it = self.fastasc
3329 3330 else:
3330 3331 it = self.fastdesc
3331 3332 if it is None:
3332 3333 # we need to consume all and try again
3333 3334 for x in self._consumegen():
3334 3335 pass
3335 3336 return self.first()
3336 3337 return next(it(), None)
3337 3338
3338 3339 def last(self):
3339 3340 if self._ascending:
3340 3341 it = self.fastdesc
3341 3342 else:
3342 3343 it = self.fastasc
3343 3344 if it is None:
3344 3345 # we need to consume all and try again
3345 3346 for x in self._consumegen():
3346 3347 pass
3347 3348 return self.first()
3348 3349 return next(it(), None)
3349 3350
3350 3351 def __repr__(self):
3351 3352 d = {False: '-', True: '+'}[self._ascending]
3352 3353 return '<%s%s>' % (type(self).__name__, d)
3353 3354
3354 3355 class spanset(abstractsmartset):
3355 3356 """Duck type for baseset class which represents a range of revisions and
3356 3357 can work lazily and without having all the range in memory
3357 3358
3358 3359 Note that spanset(x, y) behave almost like xrange(x, y) except for two
3359 3360 notable points:
3360 3361 - when x < y it will be automatically descending,
3361 3362 - revision filtered with this repoview will be skipped.
3362 3363
3363 3364 """
3364 3365 def __init__(self, repo, start=0, end=None):
3365 3366 """
3366 3367 start: first revision included the set
3367 3368 (default to 0)
3368 3369 end: first revision excluded (last+1)
3369 3370 (default to len(repo)
3370 3371
3371 3372 Spanset will be descending if `end` < `start`.
3372 3373 """
3373 3374 if end is None:
3374 3375 end = len(repo)
3375 3376 self._ascending = start <= end
3376 3377 if not self._ascending:
3377 3378 start, end = end + 1, start +1
3378 3379 self._start = start
3379 3380 self._end = end
3380 3381 self._hiddenrevs = repo.changelog.filteredrevs
3381 3382
3382 3383 def sort(self, reverse=False):
3383 3384 self._ascending = not reverse
3384 3385
3385 3386 def reverse(self):
3386 3387 self._ascending = not self._ascending
3387 3388
3388 3389 def _iterfilter(self, iterrange):
3389 3390 s = self._hiddenrevs
3390 3391 for r in iterrange:
3391 3392 if r not in s:
3392 3393 yield r
3393 3394
3394 3395 def __iter__(self):
3395 3396 if self._ascending:
3396 3397 return self.fastasc()
3397 3398 else:
3398 3399 return self.fastdesc()
3399 3400
3400 3401 def fastasc(self):
3401 3402 iterrange = xrange(self._start, self._end)
3402 3403 if self._hiddenrevs:
3403 3404 return self._iterfilter(iterrange)
3404 3405 return iter(iterrange)
3405 3406
3406 3407 def fastdesc(self):
3407 3408 iterrange = xrange(self._end - 1, self._start - 1, -1)
3408 3409 if self._hiddenrevs:
3409 3410 return self._iterfilter(iterrange)
3410 3411 return iter(iterrange)
3411 3412
3412 3413 def __contains__(self, rev):
3413 3414 hidden = self._hiddenrevs
3414 3415 return ((self._start <= rev < self._end)
3415 3416 and not (hidden and rev in hidden))
3416 3417
3417 3418 def __nonzero__(self):
3418 3419 for r in self:
3419 3420 return True
3420 3421 return False
3421 3422
3422 3423 def __len__(self):
3423 3424 if not self._hiddenrevs:
3424 3425 return abs(self._end - self._start)
3425 3426 else:
3426 3427 count = 0
3427 3428 start = self._start
3428 3429 end = self._end
3429 3430 for rev in self._hiddenrevs:
3430 3431 if (end < rev <= start) or (start <= rev < end):
3431 3432 count += 1
3432 3433 return abs(self._end - self._start) - count
3433 3434
3434 3435 def isascending(self):
3435 3436 return self._ascending
3436 3437
3437 3438 def isdescending(self):
3438 3439 return not self._ascending
3439 3440
3440 3441 def first(self):
3441 3442 if self._ascending:
3442 3443 it = self.fastasc
3443 3444 else:
3444 3445 it = self.fastdesc
3445 3446 for x in it():
3446 3447 return x
3447 3448 return None
3448 3449
3449 3450 def last(self):
3450 3451 if self._ascending:
3451 3452 it = self.fastdesc
3452 3453 else:
3453 3454 it = self.fastasc
3454 3455 for x in it():
3455 3456 return x
3456 3457 return None
3457 3458
3458 3459 def __repr__(self):
3459 3460 d = {False: '-', True: '+'}[self._ascending]
3460 3461 return '<%s%s %d:%d>' % (type(self).__name__, d,
3461 3462 self._start, self._end - 1)
3462 3463
3463 3464 class fullreposet(spanset):
3464 3465 """a set containing all revisions in the repo
3465 3466
3466 3467 This class exists to host special optimization and magic to handle virtual
3467 3468 revisions such as "null".
3468 3469 """
3469 3470
3470 3471 def __init__(self, repo):
3471 3472 super(fullreposet, self).__init__(repo)
3472 3473
3473 def __contains__(self, rev):
3474 # assumes the given rev is valid
3475 hidden = self._hiddenrevs
3476 return not (hidden and rev in hidden)
3477
3478 3474 def __and__(self, other):
3479 3475 """As self contains the whole repo, all of the other set should also be
3480 3476 in self. Therefore `self & other = other`.
3481 3477
3482 3478 This boldly assumes the other contains valid revs only.
3483 3479 """
3484 3480 # other not a smartset, make is so
3485 3481 if not util.safehasattr(other, 'isascending'):
3486 3482 # filter out hidden revision
3487 3483 # (this boldly assumes all smartset are pure)
3488 3484 #
3489 3485 # `other` was used with "&", let's assume this is a set like
3490 3486 # object.
3491 3487 other = baseset(other - self._hiddenrevs)
3492 3488
3493 3489 other.sort(reverse=self.isdescending())
3494 3490 return other
3495 3491
3496 3492 def prettyformatset(revs):
3497 3493 lines = []
3498 3494 rs = repr(revs)
3499 3495 p = 0
3500 3496 while p < len(rs):
3501 3497 q = rs.find('<', p + 1)
3502 3498 if q < 0:
3503 3499 q = len(rs)
3504 3500 l = rs.count('<', 0, p) - rs.count('>', 0, p)
3505 3501 assert l >= 0
3506 3502 lines.append((l, rs[p:q].rstrip()))
3507 3503 p = q
3508 3504 return '\n'.join(' ' * l + s for l, s in lines)
3509 3505
3510 3506 # tell hggettext to extract docstrings from these functions:
3511 3507 i18nfunctions = symbols.values()
@@ -1,2378 +1,2386 b''
1 1 @ (34) head
2 2 |
3 3 | o (33) head
4 4 | |
5 5 o | (32) expand
6 6 |\ \
7 7 | o \ (31) expand
8 8 | |\ \
9 9 | | o \ (30) expand
10 10 | | |\ \
11 11 | | | o | (29) regular commit
12 12 | | | | |
13 13 | | o | | (28) merge zero known
14 14 | | |\ \ \
15 15 o | | | | | (27) collapse
16 16 |/ / / / /
17 17 | | o---+ (26) merge one known; far right
18 18 | | | | |
19 19 +---o | | (25) merge one known; far left
20 20 | | | | |
21 21 | | o | | (24) merge one known; immediate right
22 22 | | |\| |
23 23 | | o | | (23) merge one known; immediate left
24 24 | |/| | |
25 25 +---o---+ (22) merge two known; one far left, one far right
26 26 | | / /
27 27 o | | | (21) expand
28 28 |\ \ \ \
29 29 | o---+-+ (20) merge two known; two far right
30 30 | / / /
31 31 o | | | (19) expand
32 32 |\ \ \ \
33 33 +---+---o (18) merge two known; two far left
34 34 | | | |
35 35 | o | | (17) expand
36 36 | |\ \ \
37 37 | | o---+ (16) merge two known; one immediate right, one near right
38 38 | | |/ /
39 39 o | | | (15) expand
40 40 |\ \ \ \
41 41 | o-----+ (14) merge two known; one immediate right, one far right
42 42 | |/ / /
43 43 o | | | (13) expand
44 44 |\ \ \ \
45 45 +---o | | (12) merge two known; one immediate right, one far left
46 46 | | |/ /
47 47 | o | | (11) expand
48 48 | |\ \ \
49 49 | | o---+ (10) merge two known; one immediate left, one near right
50 50 | |/ / /
51 51 o | | | (9) expand
52 52 |\ \ \ \
53 53 | o-----+ (8) merge two known; one immediate left, one far right
54 54 |/ / / /
55 55 o | | | (7) expand
56 56 |\ \ \ \
57 57 +---o | | (6) merge two known; one immediate left, one far left
58 58 | |/ / /
59 59 | o | | (5) expand
60 60 | |\ \ \
61 61 | | o | | (4) merge two known; one immediate left, one immediate right
62 62 | |/|/ /
63 63 | o / / (3) collapse
64 64 |/ / /
65 65 o / / (2) collapse
66 66 |/ /
67 67 o / (1) collapse
68 68 |/
69 69 o (0) root
70 70
71 71
72 72 $ commit()
73 73 > {
74 74 > rev=$1
75 75 > msg=$2
76 76 > shift 2
77 77 > if [ "$#" -gt 0 ]; then
78 78 > hg debugsetparents "$@"
79 79 > fi
80 80 > echo $rev > a
81 81 > hg commit -Aqd "$rev 0" -m "($rev) $msg"
82 82 > }
83 83
84 84 $ cat > printrevset.py <<EOF
85 85 > from mercurial import extensions, revset, commands, cmdutil
86 86 >
87 87 > def uisetup(ui):
88 88 > def printrevset(orig, ui, repo, *pats, **opts):
89 89 > if opts.get('print_revset'):
90 90 > expr = cmdutil.getgraphlogrevs(repo, pats, opts)[1]
91 91 > if expr:
92 92 > tree = revset.parse(expr)
93 93 > else:
94 94 > tree = []
95 95 > ui.write('%r\n' % (opts.get('rev', []),))
96 96 > ui.write(revset.prettyformat(tree) + '\n')
97 97 > return 0
98 98 > return orig(ui, repo, *pats, **opts)
99 99 > entry = extensions.wrapcommand(commands.table, 'log', printrevset)
100 100 > entry[1].append(('', 'print-revset', False,
101 101 > 'print generated revset and exit (DEPRECATED)'))
102 102 > EOF
103 103
104 104 $ echo "[extensions]" >> $HGRCPATH
105 105 $ echo "printrevset=`pwd`/printrevset.py" >> $HGRCPATH
106 106
107 107 $ hg init repo
108 108 $ cd repo
109 109
110 110 Empty repo:
111 111
112 112 $ hg log -G
113 113
114 114
115 115 Building DAG:
116 116
117 117 $ commit 0 "root"
118 118 $ commit 1 "collapse" 0
119 119 $ commit 2 "collapse" 1
120 120 $ commit 3 "collapse" 2
121 121 $ commit 4 "merge two known; one immediate left, one immediate right" 1 3
122 122 $ commit 5 "expand" 3 4
123 123 $ commit 6 "merge two known; one immediate left, one far left" 2 5
124 124 $ commit 7 "expand" 2 5
125 125 $ commit 8 "merge two known; one immediate left, one far right" 0 7
126 126 $ commit 9 "expand" 7 8
127 127 $ commit 10 "merge two known; one immediate left, one near right" 0 6
128 128 $ commit 11 "expand" 6 10
129 129 $ commit 12 "merge two known; one immediate right, one far left" 1 9
130 130 $ commit 13 "expand" 9 11
131 131 $ commit 14 "merge two known; one immediate right, one far right" 0 12
132 132 $ commit 15 "expand" 13 14
133 133 $ commit 16 "merge two known; one immediate right, one near right" 0 1
134 134 $ commit 17 "expand" 12 16
135 135 $ commit 18 "merge two known; two far left" 1 15
136 136 $ commit 19 "expand" 15 17
137 137 $ commit 20 "merge two known; two far right" 0 18
138 138 $ commit 21 "expand" 19 20
139 139 $ commit 22 "merge two known; one far left, one far right" 18 21
140 140 $ commit 23 "merge one known; immediate left" 1 22
141 141 $ commit 24 "merge one known; immediate right" 0 23
142 142 $ commit 25 "merge one known; far left" 21 24
143 143 $ commit 26 "merge one known; far right" 18 25
144 144 $ commit 27 "collapse" 21
145 145 $ commit 28 "merge zero known" 1 26
146 146 $ commit 29 "regular commit" 0
147 147 $ commit 30 "expand" 28 29
148 148 $ commit 31 "expand" 21 30
149 149 $ commit 32 "expand" 27 31
150 150 $ commit 33 "head" 18
151 151 $ commit 34 "head" 32
152 152
153 153
154 154 $ hg log -G -q
155 155 @ 34:fea3ac5810e0
156 156 |
157 157 | o 33:68608f5145f9
158 158 | |
159 159 o | 32:d06dffa21a31
160 160 |\ \
161 161 | o \ 31:621d83e11f67
162 162 | |\ \
163 163 | | o \ 30:6e11cd4b648f
164 164 | | |\ \
165 165 | | | o | 29:cd9bb2be7593
166 166 | | | | |
167 167 | | o | | 28:44ecd0b9ae99
168 168 | | |\ \ \
169 169 o | | | | | 27:886ed638191b
170 170 |/ / / / /
171 171 | | o---+ 26:7f25b6c2f0b9
172 172 | | | | |
173 173 +---o | | 25:91da8ed57247
174 174 | | | | |
175 175 | | o | | 24:a9c19a3d96b7
176 176 | | |\| |
177 177 | | o | | 23:a01cddf0766d
178 178 | |/| | |
179 179 +---o---+ 22:e0d9cccacb5d
180 180 | | / /
181 181 o | | | 21:d42a756af44d
182 182 |\ \ \ \
183 183 | o---+-+ 20:d30ed6450e32
184 184 | / / /
185 185 o | | | 19:31ddc2c1573b
186 186 |\ \ \ \
187 187 +---+---o 18:1aa84d96232a
188 188 | | | |
189 189 | o | | 17:44765d7c06e0
190 190 | |\ \ \
191 191 | | o---+ 16:3677d192927d
192 192 | | |/ /
193 193 o | | | 15:1dda3f72782d
194 194 |\ \ \ \
195 195 | o-----+ 14:8eac370358ef
196 196 | |/ / /
197 197 o | | | 13:22d8966a97e3
198 198 |\ \ \ \
199 199 +---o | | 12:86b91144a6e9
200 200 | | |/ /
201 201 | o | | 11:832d76e6bdf2
202 202 | |\ \ \
203 203 | | o---+ 10:74c64d036d72
204 204 | |/ / /
205 205 o | | | 9:7010c0af0a35
206 206 |\ \ \ \
207 207 | o-----+ 8:7a0b11f71937
208 208 |/ / / /
209 209 o | | | 7:b632bb1b1224
210 210 |\ \ \ \
211 211 +---o | | 6:b105a072e251
212 212 | |/ / /
213 213 | o | | 5:4409d547b708
214 214 | |\ \ \
215 215 | | o | | 4:26a8bac39d9f
216 216 | |/|/ /
217 217 | o / / 3:27eef8ed80b4
218 218 |/ / /
219 219 o / / 2:3d9a33b8d1e1
220 220 |/ /
221 221 o / 1:6db2ef61d156
222 222 |/
223 223 o 0:e6eb3150255d
224 224
225 225
226 226 $ hg log -G
227 227 @ changeset: 34:fea3ac5810e0
228 228 | tag: tip
229 229 | parent: 32:d06dffa21a31
230 230 | user: test
231 231 | date: Thu Jan 01 00:00:34 1970 +0000
232 232 | summary: (34) head
233 233 |
234 234 | o changeset: 33:68608f5145f9
235 235 | | parent: 18:1aa84d96232a
236 236 | | user: test
237 237 | | date: Thu Jan 01 00:00:33 1970 +0000
238 238 | | summary: (33) head
239 239 | |
240 240 o | changeset: 32:d06dffa21a31
241 241 |\ \ parent: 27:886ed638191b
242 242 | | | parent: 31:621d83e11f67
243 243 | | | user: test
244 244 | | | date: Thu Jan 01 00:00:32 1970 +0000
245 245 | | | summary: (32) expand
246 246 | | |
247 247 | o | changeset: 31:621d83e11f67
248 248 | |\ \ parent: 21:d42a756af44d
249 249 | | | | parent: 30:6e11cd4b648f
250 250 | | | | user: test
251 251 | | | | date: Thu Jan 01 00:00:31 1970 +0000
252 252 | | | | summary: (31) expand
253 253 | | | |
254 254 | | o | changeset: 30:6e11cd4b648f
255 255 | | |\ \ parent: 28:44ecd0b9ae99
256 256 | | | | | parent: 29:cd9bb2be7593
257 257 | | | | | user: test
258 258 | | | | | date: Thu Jan 01 00:00:30 1970 +0000
259 259 | | | | | summary: (30) expand
260 260 | | | | |
261 261 | | | o | changeset: 29:cd9bb2be7593
262 262 | | | | | parent: 0:e6eb3150255d
263 263 | | | | | user: test
264 264 | | | | | date: Thu Jan 01 00:00:29 1970 +0000
265 265 | | | | | summary: (29) regular commit
266 266 | | | | |
267 267 | | o | | changeset: 28:44ecd0b9ae99
268 268 | | |\ \ \ parent: 1:6db2ef61d156
269 269 | | | | | | parent: 26:7f25b6c2f0b9
270 270 | | | | | | user: test
271 271 | | | | | | date: Thu Jan 01 00:00:28 1970 +0000
272 272 | | | | | | summary: (28) merge zero known
273 273 | | | | | |
274 274 o | | | | | changeset: 27:886ed638191b
275 275 |/ / / / / parent: 21:d42a756af44d
276 276 | | | | | user: test
277 277 | | | | | date: Thu Jan 01 00:00:27 1970 +0000
278 278 | | | | | summary: (27) collapse
279 279 | | | | |
280 280 | | o---+ changeset: 26:7f25b6c2f0b9
281 281 | | | | | parent: 18:1aa84d96232a
282 282 | | | | | parent: 25:91da8ed57247
283 283 | | | | | user: test
284 284 | | | | | date: Thu Jan 01 00:00:26 1970 +0000
285 285 | | | | | summary: (26) merge one known; far right
286 286 | | | | |
287 287 +---o | | changeset: 25:91da8ed57247
288 288 | | | | | parent: 21:d42a756af44d
289 289 | | | | | parent: 24:a9c19a3d96b7
290 290 | | | | | user: test
291 291 | | | | | date: Thu Jan 01 00:00:25 1970 +0000
292 292 | | | | | summary: (25) merge one known; far left
293 293 | | | | |
294 294 | | o | | changeset: 24:a9c19a3d96b7
295 295 | | |\| | parent: 0:e6eb3150255d
296 296 | | | | | parent: 23:a01cddf0766d
297 297 | | | | | user: test
298 298 | | | | | date: Thu Jan 01 00:00:24 1970 +0000
299 299 | | | | | summary: (24) merge one known; immediate right
300 300 | | | | |
301 301 | | o | | changeset: 23:a01cddf0766d
302 302 | |/| | | parent: 1:6db2ef61d156
303 303 | | | | | parent: 22:e0d9cccacb5d
304 304 | | | | | user: test
305 305 | | | | | date: Thu Jan 01 00:00:23 1970 +0000
306 306 | | | | | summary: (23) merge one known; immediate left
307 307 | | | | |
308 308 +---o---+ changeset: 22:e0d9cccacb5d
309 309 | | | | parent: 18:1aa84d96232a
310 310 | | / / parent: 21:d42a756af44d
311 311 | | | | user: test
312 312 | | | | date: Thu Jan 01 00:00:22 1970 +0000
313 313 | | | | summary: (22) merge two known; one far left, one far right
314 314 | | | |
315 315 o | | | changeset: 21:d42a756af44d
316 316 |\ \ \ \ parent: 19:31ddc2c1573b
317 317 | | | | | parent: 20:d30ed6450e32
318 318 | | | | | user: test
319 319 | | | | | date: Thu Jan 01 00:00:21 1970 +0000
320 320 | | | | | summary: (21) expand
321 321 | | | | |
322 322 | o---+-+ changeset: 20:d30ed6450e32
323 323 | | | | parent: 0:e6eb3150255d
324 324 | / / / parent: 18:1aa84d96232a
325 325 | | | | user: test
326 326 | | | | date: Thu Jan 01 00:00:20 1970 +0000
327 327 | | | | summary: (20) merge two known; two far right
328 328 | | | |
329 329 o | | | changeset: 19:31ddc2c1573b
330 330 |\ \ \ \ parent: 15:1dda3f72782d
331 331 | | | | | parent: 17:44765d7c06e0
332 332 | | | | | user: test
333 333 | | | | | date: Thu Jan 01 00:00:19 1970 +0000
334 334 | | | | | summary: (19) expand
335 335 | | | | |
336 336 +---+---o changeset: 18:1aa84d96232a
337 337 | | | | parent: 1:6db2ef61d156
338 338 | | | | parent: 15:1dda3f72782d
339 339 | | | | user: test
340 340 | | | | date: Thu Jan 01 00:00:18 1970 +0000
341 341 | | | | summary: (18) merge two known; two far left
342 342 | | | |
343 343 | o | | changeset: 17:44765d7c06e0
344 344 | |\ \ \ parent: 12:86b91144a6e9
345 345 | | | | | parent: 16:3677d192927d
346 346 | | | | | user: test
347 347 | | | | | date: Thu Jan 01 00:00:17 1970 +0000
348 348 | | | | | summary: (17) expand
349 349 | | | | |
350 350 | | o---+ changeset: 16:3677d192927d
351 351 | | | | | parent: 0:e6eb3150255d
352 352 | | |/ / parent: 1:6db2ef61d156
353 353 | | | | user: test
354 354 | | | | date: Thu Jan 01 00:00:16 1970 +0000
355 355 | | | | summary: (16) merge two known; one immediate right, one near right
356 356 | | | |
357 357 o | | | changeset: 15:1dda3f72782d
358 358 |\ \ \ \ parent: 13:22d8966a97e3
359 359 | | | | | parent: 14:8eac370358ef
360 360 | | | | | user: test
361 361 | | | | | date: Thu Jan 01 00:00:15 1970 +0000
362 362 | | | | | summary: (15) expand
363 363 | | | | |
364 364 | o-----+ changeset: 14:8eac370358ef
365 365 | | | | | parent: 0:e6eb3150255d
366 366 | |/ / / parent: 12:86b91144a6e9
367 367 | | | | user: test
368 368 | | | | date: Thu Jan 01 00:00:14 1970 +0000
369 369 | | | | summary: (14) merge two known; one immediate right, one far right
370 370 | | | |
371 371 o | | | changeset: 13:22d8966a97e3
372 372 |\ \ \ \ parent: 9:7010c0af0a35
373 373 | | | | | parent: 11:832d76e6bdf2
374 374 | | | | | user: test
375 375 | | | | | date: Thu Jan 01 00:00:13 1970 +0000
376 376 | | | | | summary: (13) expand
377 377 | | | | |
378 378 +---o | | changeset: 12:86b91144a6e9
379 379 | | |/ / parent: 1:6db2ef61d156
380 380 | | | | parent: 9:7010c0af0a35
381 381 | | | | user: test
382 382 | | | | date: Thu Jan 01 00:00:12 1970 +0000
383 383 | | | | summary: (12) merge two known; one immediate right, one far left
384 384 | | | |
385 385 | o | | changeset: 11:832d76e6bdf2
386 386 | |\ \ \ parent: 6:b105a072e251
387 387 | | | | | parent: 10:74c64d036d72
388 388 | | | | | user: test
389 389 | | | | | date: Thu Jan 01 00:00:11 1970 +0000
390 390 | | | | | summary: (11) expand
391 391 | | | | |
392 392 | | o---+ changeset: 10:74c64d036d72
393 393 | | | | | parent: 0:e6eb3150255d
394 394 | |/ / / parent: 6:b105a072e251
395 395 | | | | user: test
396 396 | | | | date: Thu Jan 01 00:00:10 1970 +0000
397 397 | | | | summary: (10) merge two known; one immediate left, one near right
398 398 | | | |
399 399 o | | | changeset: 9:7010c0af0a35
400 400 |\ \ \ \ parent: 7:b632bb1b1224
401 401 | | | | | parent: 8:7a0b11f71937
402 402 | | | | | user: test
403 403 | | | | | date: Thu Jan 01 00:00:09 1970 +0000
404 404 | | | | | summary: (9) expand
405 405 | | | | |
406 406 | o-----+ changeset: 8:7a0b11f71937
407 407 | | | | | parent: 0:e6eb3150255d
408 408 |/ / / / parent: 7:b632bb1b1224
409 409 | | | | user: test
410 410 | | | | date: Thu Jan 01 00:00:08 1970 +0000
411 411 | | | | summary: (8) merge two known; one immediate left, one far right
412 412 | | | |
413 413 o | | | changeset: 7:b632bb1b1224
414 414 |\ \ \ \ parent: 2:3d9a33b8d1e1
415 415 | | | | | parent: 5:4409d547b708
416 416 | | | | | user: test
417 417 | | | | | date: Thu Jan 01 00:00:07 1970 +0000
418 418 | | | | | summary: (7) expand
419 419 | | | | |
420 420 +---o | | changeset: 6:b105a072e251
421 421 | |/ / / parent: 2:3d9a33b8d1e1
422 422 | | | | parent: 5:4409d547b708
423 423 | | | | user: test
424 424 | | | | date: Thu Jan 01 00:00:06 1970 +0000
425 425 | | | | summary: (6) merge two known; one immediate left, one far left
426 426 | | | |
427 427 | o | | changeset: 5:4409d547b708
428 428 | |\ \ \ parent: 3:27eef8ed80b4
429 429 | | | | | parent: 4:26a8bac39d9f
430 430 | | | | | user: test
431 431 | | | | | date: Thu Jan 01 00:00:05 1970 +0000
432 432 | | | | | summary: (5) expand
433 433 | | | | |
434 434 | | o | | changeset: 4:26a8bac39d9f
435 435 | |/|/ / parent: 1:6db2ef61d156
436 436 | | | | parent: 3:27eef8ed80b4
437 437 | | | | user: test
438 438 | | | | date: Thu Jan 01 00:00:04 1970 +0000
439 439 | | | | summary: (4) merge two known; one immediate left, one immediate right
440 440 | | | |
441 441 | o | | changeset: 3:27eef8ed80b4
442 442 |/ / / user: test
443 443 | | | date: Thu Jan 01 00:00:03 1970 +0000
444 444 | | | summary: (3) collapse
445 445 | | |
446 446 o | | changeset: 2:3d9a33b8d1e1
447 447 |/ / user: test
448 448 | | date: Thu Jan 01 00:00:02 1970 +0000
449 449 | | summary: (2) collapse
450 450 | |
451 451 o | changeset: 1:6db2ef61d156
452 452 |/ user: test
453 453 | date: Thu Jan 01 00:00:01 1970 +0000
454 454 | summary: (1) collapse
455 455 |
456 456 o changeset: 0:e6eb3150255d
457 457 user: test
458 458 date: Thu Jan 01 00:00:00 1970 +0000
459 459 summary: (0) root
460 460
461 461
462 462 File glog:
463 463 $ hg log -G a
464 464 @ changeset: 34:fea3ac5810e0
465 465 | tag: tip
466 466 | parent: 32:d06dffa21a31
467 467 | user: test
468 468 | date: Thu Jan 01 00:00:34 1970 +0000
469 469 | summary: (34) head
470 470 |
471 471 | o changeset: 33:68608f5145f9
472 472 | | parent: 18:1aa84d96232a
473 473 | | user: test
474 474 | | date: Thu Jan 01 00:00:33 1970 +0000
475 475 | | summary: (33) head
476 476 | |
477 477 o | changeset: 32:d06dffa21a31
478 478 |\ \ parent: 27:886ed638191b
479 479 | | | parent: 31:621d83e11f67
480 480 | | | user: test
481 481 | | | date: Thu Jan 01 00:00:32 1970 +0000
482 482 | | | summary: (32) expand
483 483 | | |
484 484 | o | changeset: 31:621d83e11f67
485 485 | |\ \ parent: 21:d42a756af44d
486 486 | | | | parent: 30:6e11cd4b648f
487 487 | | | | user: test
488 488 | | | | date: Thu Jan 01 00:00:31 1970 +0000
489 489 | | | | summary: (31) expand
490 490 | | | |
491 491 | | o | changeset: 30:6e11cd4b648f
492 492 | | |\ \ parent: 28:44ecd0b9ae99
493 493 | | | | | parent: 29:cd9bb2be7593
494 494 | | | | | user: test
495 495 | | | | | date: Thu Jan 01 00:00:30 1970 +0000
496 496 | | | | | summary: (30) expand
497 497 | | | | |
498 498 | | | o | changeset: 29:cd9bb2be7593
499 499 | | | | | parent: 0:e6eb3150255d
500 500 | | | | | user: test
501 501 | | | | | date: Thu Jan 01 00:00:29 1970 +0000
502 502 | | | | | summary: (29) regular commit
503 503 | | | | |
504 504 | | o | | changeset: 28:44ecd0b9ae99
505 505 | | |\ \ \ parent: 1:6db2ef61d156
506 506 | | | | | | parent: 26:7f25b6c2f0b9
507 507 | | | | | | user: test
508 508 | | | | | | date: Thu Jan 01 00:00:28 1970 +0000
509 509 | | | | | | summary: (28) merge zero known
510 510 | | | | | |
511 511 o | | | | | changeset: 27:886ed638191b
512 512 |/ / / / / parent: 21:d42a756af44d
513 513 | | | | | user: test
514 514 | | | | | date: Thu Jan 01 00:00:27 1970 +0000
515 515 | | | | | summary: (27) collapse
516 516 | | | | |
517 517 | | o---+ changeset: 26:7f25b6c2f0b9
518 518 | | | | | parent: 18:1aa84d96232a
519 519 | | | | | parent: 25:91da8ed57247
520 520 | | | | | user: test
521 521 | | | | | date: Thu Jan 01 00:00:26 1970 +0000
522 522 | | | | | summary: (26) merge one known; far right
523 523 | | | | |
524 524 +---o | | changeset: 25:91da8ed57247
525 525 | | | | | parent: 21:d42a756af44d
526 526 | | | | | parent: 24:a9c19a3d96b7
527 527 | | | | | user: test
528 528 | | | | | date: Thu Jan 01 00:00:25 1970 +0000
529 529 | | | | | summary: (25) merge one known; far left
530 530 | | | | |
531 531 | | o | | changeset: 24:a9c19a3d96b7
532 532 | | |\| | parent: 0:e6eb3150255d
533 533 | | | | | parent: 23:a01cddf0766d
534 534 | | | | | user: test
535 535 | | | | | date: Thu Jan 01 00:00:24 1970 +0000
536 536 | | | | | summary: (24) merge one known; immediate right
537 537 | | | | |
538 538 | | o | | changeset: 23:a01cddf0766d
539 539 | |/| | | parent: 1:6db2ef61d156
540 540 | | | | | parent: 22:e0d9cccacb5d
541 541 | | | | | user: test
542 542 | | | | | date: Thu Jan 01 00:00:23 1970 +0000
543 543 | | | | | summary: (23) merge one known; immediate left
544 544 | | | | |
545 545 +---o---+ changeset: 22:e0d9cccacb5d
546 546 | | | | parent: 18:1aa84d96232a
547 547 | | / / parent: 21:d42a756af44d
548 548 | | | | user: test
549 549 | | | | date: Thu Jan 01 00:00:22 1970 +0000
550 550 | | | | summary: (22) merge two known; one far left, one far right
551 551 | | | |
552 552 o | | | changeset: 21:d42a756af44d
553 553 |\ \ \ \ parent: 19:31ddc2c1573b
554 554 | | | | | parent: 20:d30ed6450e32
555 555 | | | | | user: test
556 556 | | | | | date: Thu Jan 01 00:00:21 1970 +0000
557 557 | | | | | summary: (21) expand
558 558 | | | | |
559 559 | o---+-+ changeset: 20:d30ed6450e32
560 560 | | | | parent: 0:e6eb3150255d
561 561 | / / / parent: 18:1aa84d96232a
562 562 | | | | user: test
563 563 | | | | date: Thu Jan 01 00:00:20 1970 +0000
564 564 | | | | summary: (20) merge two known; two far right
565 565 | | | |
566 566 o | | | changeset: 19:31ddc2c1573b
567 567 |\ \ \ \ parent: 15:1dda3f72782d
568 568 | | | | | parent: 17:44765d7c06e0
569 569 | | | | | user: test
570 570 | | | | | date: Thu Jan 01 00:00:19 1970 +0000
571 571 | | | | | summary: (19) expand
572 572 | | | | |
573 573 +---+---o changeset: 18:1aa84d96232a
574 574 | | | | parent: 1:6db2ef61d156
575 575 | | | | parent: 15:1dda3f72782d
576 576 | | | | user: test
577 577 | | | | date: Thu Jan 01 00:00:18 1970 +0000
578 578 | | | | summary: (18) merge two known; two far left
579 579 | | | |
580 580 | o | | changeset: 17:44765d7c06e0
581 581 | |\ \ \ parent: 12:86b91144a6e9
582 582 | | | | | parent: 16:3677d192927d
583 583 | | | | | user: test
584 584 | | | | | date: Thu Jan 01 00:00:17 1970 +0000
585 585 | | | | | summary: (17) expand
586 586 | | | | |
587 587 | | o---+ changeset: 16:3677d192927d
588 588 | | | | | parent: 0:e6eb3150255d
589 589 | | |/ / parent: 1:6db2ef61d156
590 590 | | | | user: test
591 591 | | | | date: Thu Jan 01 00:00:16 1970 +0000
592 592 | | | | summary: (16) merge two known; one immediate right, one near right
593 593 | | | |
594 594 o | | | changeset: 15:1dda3f72782d
595 595 |\ \ \ \ parent: 13:22d8966a97e3
596 596 | | | | | parent: 14:8eac370358ef
597 597 | | | | | user: test
598 598 | | | | | date: Thu Jan 01 00:00:15 1970 +0000
599 599 | | | | | summary: (15) expand
600 600 | | | | |
601 601 | o-----+ changeset: 14:8eac370358ef
602 602 | | | | | parent: 0:e6eb3150255d
603 603 | |/ / / parent: 12:86b91144a6e9
604 604 | | | | user: test
605 605 | | | | date: Thu Jan 01 00:00:14 1970 +0000
606 606 | | | | summary: (14) merge two known; one immediate right, one far right
607 607 | | | |
608 608 o | | | changeset: 13:22d8966a97e3
609 609 |\ \ \ \ parent: 9:7010c0af0a35
610 610 | | | | | parent: 11:832d76e6bdf2
611 611 | | | | | user: test
612 612 | | | | | date: Thu Jan 01 00:00:13 1970 +0000
613 613 | | | | | summary: (13) expand
614 614 | | | | |
615 615 +---o | | changeset: 12:86b91144a6e9
616 616 | | |/ / parent: 1:6db2ef61d156
617 617 | | | | parent: 9:7010c0af0a35
618 618 | | | | user: test
619 619 | | | | date: Thu Jan 01 00:00:12 1970 +0000
620 620 | | | | summary: (12) merge two known; one immediate right, one far left
621 621 | | | |
622 622 | o | | changeset: 11:832d76e6bdf2
623 623 | |\ \ \ parent: 6:b105a072e251
624 624 | | | | | parent: 10:74c64d036d72
625 625 | | | | | user: test
626 626 | | | | | date: Thu Jan 01 00:00:11 1970 +0000
627 627 | | | | | summary: (11) expand
628 628 | | | | |
629 629 | | o---+ changeset: 10:74c64d036d72
630 630 | | | | | parent: 0:e6eb3150255d
631 631 | |/ / / parent: 6:b105a072e251
632 632 | | | | user: test
633 633 | | | | date: Thu Jan 01 00:00:10 1970 +0000
634 634 | | | | summary: (10) merge two known; one immediate left, one near right
635 635 | | | |
636 636 o | | | changeset: 9:7010c0af0a35
637 637 |\ \ \ \ parent: 7:b632bb1b1224
638 638 | | | | | parent: 8:7a0b11f71937
639 639 | | | | | user: test
640 640 | | | | | date: Thu Jan 01 00:00:09 1970 +0000
641 641 | | | | | summary: (9) expand
642 642 | | | | |
643 643 | o-----+ changeset: 8:7a0b11f71937
644 644 | | | | | parent: 0:e6eb3150255d
645 645 |/ / / / parent: 7:b632bb1b1224
646 646 | | | | user: test
647 647 | | | | date: Thu Jan 01 00:00:08 1970 +0000
648 648 | | | | summary: (8) merge two known; one immediate left, one far right
649 649 | | | |
650 650 o | | | changeset: 7:b632bb1b1224
651 651 |\ \ \ \ parent: 2:3d9a33b8d1e1
652 652 | | | | | parent: 5:4409d547b708
653 653 | | | | | user: test
654 654 | | | | | date: Thu Jan 01 00:00:07 1970 +0000
655 655 | | | | | summary: (7) expand
656 656 | | | | |
657 657 +---o | | changeset: 6:b105a072e251
658 658 | |/ / / parent: 2:3d9a33b8d1e1
659 659 | | | | parent: 5:4409d547b708
660 660 | | | | user: test
661 661 | | | | date: Thu Jan 01 00:00:06 1970 +0000
662 662 | | | | summary: (6) merge two known; one immediate left, one far left
663 663 | | | |
664 664 | o | | changeset: 5:4409d547b708
665 665 | |\ \ \ parent: 3:27eef8ed80b4
666 666 | | | | | parent: 4:26a8bac39d9f
667 667 | | | | | user: test
668 668 | | | | | date: Thu Jan 01 00:00:05 1970 +0000
669 669 | | | | | summary: (5) expand
670 670 | | | | |
671 671 | | o | | changeset: 4:26a8bac39d9f
672 672 | |/|/ / parent: 1:6db2ef61d156
673 673 | | | | parent: 3:27eef8ed80b4
674 674 | | | | user: test
675 675 | | | | date: Thu Jan 01 00:00:04 1970 +0000
676 676 | | | | summary: (4) merge two known; one immediate left, one immediate right
677 677 | | | |
678 678 | o | | changeset: 3:27eef8ed80b4
679 679 |/ / / user: test
680 680 | | | date: Thu Jan 01 00:00:03 1970 +0000
681 681 | | | summary: (3) collapse
682 682 | | |
683 683 o | | changeset: 2:3d9a33b8d1e1
684 684 |/ / user: test
685 685 | | date: Thu Jan 01 00:00:02 1970 +0000
686 686 | | summary: (2) collapse
687 687 | |
688 688 o | changeset: 1:6db2ef61d156
689 689 |/ user: test
690 690 | date: Thu Jan 01 00:00:01 1970 +0000
691 691 | summary: (1) collapse
692 692 |
693 693 o changeset: 0:e6eb3150255d
694 694 user: test
695 695 date: Thu Jan 01 00:00:00 1970 +0000
696 696 summary: (0) root
697 697
698 698
699 699 File glog per revset:
700 700
701 701 $ hg log -G -r 'file("a")'
702 702 @ changeset: 34:fea3ac5810e0
703 703 | tag: tip
704 704 | parent: 32:d06dffa21a31
705 705 | user: test
706 706 | date: Thu Jan 01 00:00:34 1970 +0000
707 707 | summary: (34) head
708 708 |
709 709 | o changeset: 33:68608f5145f9
710 710 | | parent: 18:1aa84d96232a
711 711 | | user: test
712 712 | | date: Thu Jan 01 00:00:33 1970 +0000
713 713 | | summary: (33) head
714 714 | |
715 715 o | changeset: 32:d06dffa21a31
716 716 |\ \ parent: 27:886ed638191b
717 717 | | | parent: 31:621d83e11f67
718 718 | | | user: test
719 719 | | | date: Thu Jan 01 00:00:32 1970 +0000
720 720 | | | summary: (32) expand
721 721 | | |
722 722 | o | changeset: 31:621d83e11f67
723 723 | |\ \ parent: 21:d42a756af44d
724 724 | | | | parent: 30:6e11cd4b648f
725 725 | | | | user: test
726 726 | | | | date: Thu Jan 01 00:00:31 1970 +0000
727 727 | | | | summary: (31) expand
728 728 | | | |
729 729 | | o | changeset: 30:6e11cd4b648f
730 730 | | |\ \ parent: 28:44ecd0b9ae99
731 731 | | | | | parent: 29:cd9bb2be7593
732 732 | | | | | user: test
733 733 | | | | | date: Thu Jan 01 00:00:30 1970 +0000
734 734 | | | | | summary: (30) expand
735 735 | | | | |
736 736 | | | o | changeset: 29:cd9bb2be7593
737 737 | | | | | parent: 0:e6eb3150255d
738 738 | | | | | user: test
739 739 | | | | | date: Thu Jan 01 00:00:29 1970 +0000
740 740 | | | | | summary: (29) regular commit
741 741 | | | | |
742 742 | | o | | changeset: 28:44ecd0b9ae99
743 743 | | |\ \ \ parent: 1:6db2ef61d156
744 744 | | | | | | parent: 26:7f25b6c2f0b9
745 745 | | | | | | user: test
746 746 | | | | | | date: Thu Jan 01 00:00:28 1970 +0000
747 747 | | | | | | summary: (28) merge zero known
748 748 | | | | | |
749 749 o | | | | | changeset: 27:886ed638191b
750 750 |/ / / / / parent: 21:d42a756af44d
751 751 | | | | | user: test
752 752 | | | | | date: Thu Jan 01 00:00:27 1970 +0000
753 753 | | | | | summary: (27) collapse
754 754 | | | | |
755 755 | | o---+ changeset: 26:7f25b6c2f0b9
756 756 | | | | | parent: 18:1aa84d96232a
757 757 | | | | | parent: 25:91da8ed57247
758 758 | | | | | user: test
759 759 | | | | | date: Thu Jan 01 00:00:26 1970 +0000
760 760 | | | | | summary: (26) merge one known; far right
761 761 | | | | |
762 762 +---o | | changeset: 25:91da8ed57247
763 763 | | | | | parent: 21:d42a756af44d
764 764 | | | | | parent: 24:a9c19a3d96b7
765 765 | | | | | user: test
766 766 | | | | | date: Thu Jan 01 00:00:25 1970 +0000
767 767 | | | | | summary: (25) merge one known; far left
768 768 | | | | |
769 769 | | o | | changeset: 24:a9c19a3d96b7
770 770 | | |\| | parent: 0:e6eb3150255d
771 771 | | | | | parent: 23:a01cddf0766d
772 772 | | | | | user: test
773 773 | | | | | date: Thu Jan 01 00:00:24 1970 +0000
774 774 | | | | | summary: (24) merge one known; immediate right
775 775 | | | | |
776 776 | | o | | changeset: 23:a01cddf0766d
777 777 | |/| | | parent: 1:6db2ef61d156
778 778 | | | | | parent: 22:e0d9cccacb5d
779 779 | | | | | user: test
780 780 | | | | | date: Thu Jan 01 00:00:23 1970 +0000
781 781 | | | | | summary: (23) merge one known; immediate left
782 782 | | | | |
783 783 +---o---+ changeset: 22:e0d9cccacb5d
784 784 | | | | parent: 18:1aa84d96232a
785 785 | | / / parent: 21:d42a756af44d
786 786 | | | | user: test
787 787 | | | | date: Thu Jan 01 00:00:22 1970 +0000
788 788 | | | | summary: (22) merge two known; one far left, one far right
789 789 | | | |
790 790 o | | | changeset: 21:d42a756af44d
791 791 |\ \ \ \ parent: 19:31ddc2c1573b
792 792 | | | | | parent: 20:d30ed6450e32
793 793 | | | | | user: test
794 794 | | | | | date: Thu Jan 01 00:00:21 1970 +0000
795 795 | | | | | summary: (21) expand
796 796 | | | | |
797 797 | o---+-+ changeset: 20:d30ed6450e32
798 798 | | | | parent: 0:e6eb3150255d
799 799 | / / / parent: 18:1aa84d96232a
800 800 | | | | user: test
801 801 | | | | date: Thu Jan 01 00:00:20 1970 +0000
802 802 | | | | summary: (20) merge two known; two far right
803 803 | | | |
804 804 o | | | changeset: 19:31ddc2c1573b
805 805 |\ \ \ \ parent: 15:1dda3f72782d
806 806 | | | | | parent: 17:44765d7c06e0
807 807 | | | | | user: test
808 808 | | | | | date: Thu Jan 01 00:00:19 1970 +0000
809 809 | | | | | summary: (19) expand
810 810 | | | | |
811 811 +---+---o changeset: 18:1aa84d96232a
812 812 | | | | parent: 1:6db2ef61d156
813 813 | | | | parent: 15:1dda3f72782d
814 814 | | | | user: test
815 815 | | | | date: Thu Jan 01 00:00:18 1970 +0000
816 816 | | | | summary: (18) merge two known; two far left
817 817 | | | |
818 818 | o | | changeset: 17:44765d7c06e0
819 819 | |\ \ \ parent: 12:86b91144a6e9
820 820 | | | | | parent: 16:3677d192927d
821 821 | | | | | user: test
822 822 | | | | | date: Thu Jan 01 00:00:17 1970 +0000
823 823 | | | | | summary: (17) expand
824 824 | | | | |
825 825 | | o---+ changeset: 16:3677d192927d
826 826 | | | | | parent: 0:e6eb3150255d
827 827 | | |/ / parent: 1:6db2ef61d156
828 828 | | | | user: test
829 829 | | | | date: Thu Jan 01 00:00:16 1970 +0000
830 830 | | | | summary: (16) merge two known; one immediate right, one near right
831 831 | | | |
832 832 o | | | changeset: 15:1dda3f72782d
833 833 |\ \ \ \ parent: 13:22d8966a97e3
834 834 | | | | | parent: 14:8eac370358ef
835 835 | | | | | user: test
836 836 | | | | | date: Thu Jan 01 00:00:15 1970 +0000
837 837 | | | | | summary: (15) expand
838 838 | | | | |
839 839 | o-----+ changeset: 14:8eac370358ef
840 840 | | | | | parent: 0:e6eb3150255d
841 841 | |/ / / parent: 12:86b91144a6e9
842 842 | | | | user: test
843 843 | | | | date: Thu Jan 01 00:00:14 1970 +0000
844 844 | | | | summary: (14) merge two known; one immediate right, one far right
845 845 | | | |
846 846 o | | | changeset: 13:22d8966a97e3
847 847 |\ \ \ \ parent: 9:7010c0af0a35
848 848 | | | | | parent: 11:832d76e6bdf2
849 849 | | | | | user: test
850 850 | | | | | date: Thu Jan 01 00:00:13 1970 +0000
851 851 | | | | | summary: (13) expand
852 852 | | | | |
853 853 +---o | | changeset: 12:86b91144a6e9
854 854 | | |/ / parent: 1:6db2ef61d156
855 855 | | | | parent: 9:7010c0af0a35
856 856 | | | | user: test
857 857 | | | | date: Thu Jan 01 00:00:12 1970 +0000
858 858 | | | | summary: (12) merge two known; one immediate right, one far left
859 859 | | | |
860 860 | o | | changeset: 11:832d76e6bdf2
861 861 | |\ \ \ parent: 6:b105a072e251
862 862 | | | | | parent: 10:74c64d036d72
863 863 | | | | | user: test
864 864 | | | | | date: Thu Jan 01 00:00:11 1970 +0000
865 865 | | | | | summary: (11) expand
866 866 | | | | |
867 867 | | o---+ changeset: 10:74c64d036d72
868 868 | | | | | parent: 0:e6eb3150255d
869 869 | |/ / / parent: 6:b105a072e251
870 870 | | | | user: test
871 871 | | | | date: Thu Jan 01 00:00:10 1970 +0000
872 872 | | | | summary: (10) merge two known; one immediate left, one near right
873 873 | | | |
874 874 o | | | changeset: 9:7010c0af0a35
875 875 |\ \ \ \ parent: 7:b632bb1b1224
876 876 | | | | | parent: 8:7a0b11f71937
877 877 | | | | | user: test
878 878 | | | | | date: Thu Jan 01 00:00:09 1970 +0000
879 879 | | | | | summary: (9) expand
880 880 | | | | |
881 881 | o-----+ changeset: 8:7a0b11f71937
882 882 | | | | | parent: 0:e6eb3150255d
883 883 |/ / / / parent: 7:b632bb1b1224
884 884 | | | | user: test
885 885 | | | | date: Thu Jan 01 00:00:08 1970 +0000
886 886 | | | | summary: (8) merge two known; one immediate left, one far right
887 887 | | | |
888 888 o | | | changeset: 7:b632bb1b1224
889 889 |\ \ \ \ parent: 2:3d9a33b8d1e1
890 890 | | | | | parent: 5:4409d547b708
891 891 | | | | | user: test
892 892 | | | | | date: Thu Jan 01 00:00:07 1970 +0000
893 893 | | | | | summary: (7) expand
894 894 | | | | |
895 895 +---o | | changeset: 6:b105a072e251
896 896 | |/ / / parent: 2:3d9a33b8d1e1
897 897 | | | | parent: 5:4409d547b708
898 898 | | | | user: test
899 899 | | | | date: Thu Jan 01 00:00:06 1970 +0000
900 900 | | | | summary: (6) merge two known; one immediate left, one far left
901 901 | | | |
902 902 | o | | changeset: 5:4409d547b708
903 903 | |\ \ \ parent: 3:27eef8ed80b4
904 904 | | | | | parent: 4:26a8bac39d9f
905 905 | | | | | user: test
906 906 | | | | | date: Thu Jan 01 00:00:05 1970 +0000
907 907 | | | | | summary: (5) expand
908 908 | | | | |
909 909 | | o | | changeset: 4:26a8bac39d9f
910 910 | |/|/ / parent: 1:6db2ef61d156
911 911 | | | | parent: 3:27eef8ed80b4
912 912 | | | | user: test
913 913 | | | | date: Thu Jan 01 00:00:04 1970 +0000
914 914 | | | | summary: (4) merge two known; one immediate left, one immediate right
915 915 | | | |
916 916 | o | | changeset: 3:27eef8ed80b4
917 917 |/ / / user: test
918 918 | | | date: Thu Jan 01 00:00:03 1970 +0000
919 919 | | | summary: (3) collapse
920 920 | | |
921 921 o | | changeset: 2:3d9a33b8d1e1
922 922 |/ / user: test
923 923 | | date: Thu Jan 01 00:00:02 1970 +0000
924 924 | | summary: (2) collapse
925 925 | |
926 926 o | changeset: 1:6db2ef61d156
927 927 |/ user: test
928 928 | date: Thu Jan 01 00:00:01 1970 +0000
929 929 | summary: (1) collapse
930 930 |
931 931 o changeset: 0:e6eb3150255d
932 932 user: test
933 933 date: Thu Jan 01 00:00:00 1970 +0000
934 934 summary: (0) root
935 935
936 936
937 937
938 938 File glog per revset (only merges):
939 939
940 940 $ hg log -G -r 'file("a")' -m
941 941 o changeset: 32:d06dffa21a31
942 942 |\ parent: 27:886ed638191b
943 943 | | parent: 31:621d83e11f67
944 944 | | user: test
945 945 | | date: Thu Jan 01 00:00:32 1970 +0000
946 946 | | summary: (32) expand
947 947 | |
948 948 o | changeset: 31:621d83e11f67
949 949 |\| parent: 21:d42a756af44d
950 950 | | parent: 30:6e11cd4b648f
951 951 | | user: test
952 952 | | date: Thu Jan 01 00:00:31 1970 +0000
953 953 | | summary: (31) expand
954 954 | |
955 955 o | changeset: 30:6e11cd4b648f
956 956 |\ \ parent: 28:44ecd0b9ae99
957 957 | | | parent: 29:cd9bb2be7593
958 958 | | | user: test
959 959 | | | date: Thu Jan 01 00:00:30 1970 +0000
960 960 | | | summary: (30) expand
961 961 | | |
962 962 o | | changeset: 28:44ecd0b9ae99
963 963 |\ \ \ parent: 1:6db2ef61d156
964 964 | | | | parent: 26:7f25b6c2f0b9
965 965 | | | | user: test
966 966 | | | | date: Thu Jan 01 00:00:28 1970 +0000
967 967 | | | | summary: (28) merge zero known
968 968 | | | |
969 969 o | | | changeset: 26:7f25b6c2f0b9
970 970 |\ \ \ \ parent: 18:1aa84d96232a
971 971 | | | | | parent: 25:91da8ed57247
972 972 | | | | | user: test
973 973 | | | | | date: Thu Jan 01 00:00:26 1970 +0000
974 974 | | | | | summary: (26) merge one known; far right
975 975 | | | | |
976 976 | o-----+ changeset: 25:91da8ed57247
977 977 | | | | | parent: 21:d42a756af44d
978 978 | | | | | parent: 24:a9c19a3d96b7
979 979 | | | | | user: test
980 980 | | | | | date: Thu Jan 01 00:00:25 1970 +0000
981 981 | | | | | summary: (25) merge one known; far left
982 982 | | | | |
983 983 | o | | | changeset: 24:a9c19a3d96b7
984 984 | |\ \ \ \ parent: 0:e6eb3150255d
985 985 | | | | | | parent: 23:a01cddf0766d
986 986 | | | | | | user: test
987 987 | | | | | | date: Thu Jan 01 00:00:24 1970 +0000
988 988 | | | | | | summary: (24) merge one known; immediate right
989 989 | | | | | |
990 990 | o---+ | | changeset: 23:a01cddf0766d
991 991 | | | | | | parent: 1:6db2ef61d156
992 992 | | | | | | parent: 22:e0d9cccacb5d
993 993 | | | | | | user: test
994 994 | | | | | | date: Thu Jan 01 00:00:23 1970 +0000
995 995 | | | | | | summary: (23) merge one known; immediate left
996 996 | | | | | |
997 997 | o-------+ changeset: 22:e0d9cccacb5d
998 998 | | | | | | parent: 18:1aa84d96232a
999 999 |/ / / / / parent: 21:d42a756af44d
1000 1000 | | | | | user: test
1001 1001 | | | | | date: Thu Jan 01 00:00:22 1970 +0000
1002 1002 | | | | | summary: (22) merge two known; one far left, one far right
1003 1003 | | | | |
1004 1004 | | | | o changeset: 21:d42a756af44d
1005 1005 | | | | |\ parent: 19:31ddc2c1573b
1006 1006 | | | | | | parent: 20:d30ed6450e32
1007 1007 | | | | | | user: test
1008 1008 | | | | | | date: Thu Jan 01 00:00:21 1970 +0000
1009 1009 | | | | | | summary: (21) expand
1010 1010 | | | | | |
1011 1011 +-+-------o changeset: 20:d30ed6450e32
1012 1012 | | | | | parent: 0:e6eb3150255d
1013 1013 | | | | | parent: 18:1aa84d96232a
1014 1014 | | | | | user: test
1015 1015 | | | | | date: Thu Jan 01 00:00:20 1970 +0000
1016 1016 | | | | | summary: (20) merge two known; two far right
1017 1017 | | | | |
1018 1018 | | | | o changeset: 19:31ddc2c1573b
1019 1019 | | | | |\ parent: 15:1dda3f72782d
1020 1020 | | | | | | parent: 17:44765d7c06e0
1021 1021 | | | | | | user: test
1022 1022 | | | | | | date: Thu Jan 01 00:00:19 1970 +0000
1023 1023 | | | | | | summary: (19) expand
1024 1024 | | | | | |
1025 1025 o---+---+ | changeset: 18:1aa84d96232a
1026 1026 | | | | | parent: 1:6db2ef61d156
1027 1027 / / / / / parent: 15:1dda3f72782d
1028 1028 | | | | | user: test
1029 1029 | | | | | date: Thu Jan 01 00:00:18 1970 +0000
1030 1030 | | | | | summary: (18) merge two known; two far left
1031 1031 | | | | |
1032 1032 | | | | o changeset: 17:44765d7c06e0
1033 1033 | | | | |\ parent: 12:86b91144a6e9
1034 1034 | | | | | | parent: 16:3677d192927d
1035 1035 | | | | | | user: test
1036 1036 | | | | | | date: Thu Jan 01 00:00:17 1970 +0000
1037 1037 | | | | | | summary: (17) expand
1038 1038 | | | | | |
1039 1039 +-+-------o changeset: 16:3677d192927d
1040 1040 | | | | | parent: 0:e6eb3150255d
1041 1041 | | | | | parent: 1:6db2ef61d156
1042 1042 | | | | | user: test
1043 1043 | | | | | date: Thu Jan 01 00:00:16 1970 +0000
1044 1044 | | | | | summary: (16) merge two known; one immediate right, one near right
1045 1045 | | | | |
1046 1046 | | | o | changeset: 15:1dda3f72782d
1047 1047 | | | |\ \ parent: 13:22d8966a97e3
1048 1048 | | | | | | parent: 14:8eac370358ef
1049 1049 | | | | | | user: test
1050 1050 | | | | | | date: Thu Jan 01 00:00:15 1970 +0000
1051 1051 | | | | | | summary: (15) expand
1052 1052 | | | | | |
1053 1053 +-------o | changeset: 14:8eac370358ef
1054 1054 | | | | |/ parent: 0:e6eb3150255d
1055 1055 | | | | | parent: 12:86b91144a6e9
1056 1056 | | | | | user: test
1057 1057 | | | | | date: Thu Jan 01 00:00:14 1970 +0000
1058 1058 | | | | | summary: (14) merge two known; one immediate right, one far right
1059 1059 | | | | |
1060 1060 | | | o | changeset: 13:22d8966a97e3
1061 1061 | | | |\ \ parent: 9:7010c0af0a35
1062 1062 | | | | | | parent: 11:832d76e6bdf2
1063 1063 | | | | | | user: test
1064 1064 | | | | | | date: Thu Jan 01 00:00:13 1970 +0000
1065 1065 | | | | | | summary: (13) expand
1066 1066 | | | | | |
1067 1067 | +---+---o changeset: 12:86b91144a6e9
1068 1068 | | | | | parent: 1:6db2ef61d156
1069 1069 | | | | | parent: 9:7010c0af0a35
1070 1070 | | | | | user: test
1071 1071 | | | | | date: Thu Jan 01 00:00:12 1970 +0000
1072 1072 | | | | | summary: (12) merge two known; one immediate right, one far left
1073 1073 | | | | |
1074 1074 | | | | o changeset: 11:832d76e6bdf2
1075 1075 | | | | |\ parent: 6:b105a072e251
1076 1076 | | | | | | parent: 10:74c64d036d72
1077 1077 | | | | | | user: test
1078 1078 | | | | | | date: Thu Jan 01 00:00:11 1970 +0000
1079 1079 | | | | | | summary: (11) expand
1080 1080 | | | | | |
1081 1081 +---------o changeset: 10:74c64d036d72
1082 1082 | | | | |/ parent: 0:e6eb3150255d
1083 1083 | | | | | parent: 6:b105a072e251
1084 1084 | | | | | user: test
1085 1085 | | | | | date: Thu Jan 01 00:00:10 1970 +0000
1086 1086 | | | | | summary: (10) merge two known; one immediate left, one near right
1087 1087 | | | | |
1088 1088 | | | o | changeset: 9:7010c0af0a35
1089 1089 | | | |\ \ parent: 7:b632bb1b1224
1090 1090 | | | | | | parent: 8:7a0b11f71937
1091 1091 | | | | | | user: test
1092 1092 | | | | | | date: Thu Jan 01 00:00:09 1970 +0000
1093 1093 | | | | | | summary: (9) expand
1094 1094 | | | | | |
1095 1095 +-------o | changeset: 8:7a0b11f71937
1096 1096 | | | |/ / parent: 0:e6eb3150255d
1097 1097 | | | | | parent: 7:b632bb1b1224
1098 1098 | | | | | user: test
1099 1099 | | | | | date: Thu Jan 01 00:00:08 1970 +0000
1100 1100 | | | | | summary: (8) merge two known; one immediate left, one far right
1101 1101 | | | | |
1102 1102 | | | o | changeset: 7:b632bb1b1224
1103 1103 | | | |\ \ parent: 2:3d9a33b8d1e1
1104 1104 | | | | | | parent: 5:4409d547b708
1105 1105 | | | | | | user: test
1106 1106 | | | | | | date: Thu Jan 01 00:00:07 1970 +0000
1107 1107 | | | | | | summary: (7) expand
1108 1108 | | | | | |
1109 1109 | | | +---o changeset: 6:b105a072e251
1110 1110 | | | | |/ parent: 2:3d9a33b8d1e1
1111 1111 | | | | | parent: 5:4409d547b708
1112 1112 | | | | | user: test
1113 1113 | | | | | date: Thu Jan 01 00:00:06 1970 +0000
1114 1114 | | | | | summary: (6) merge two known; one immediate left, one far left
1115 1115 | | | | |
1116 1116 | | | o | changeset: 5:4409d547b708
1117 1117 | | | |\ \ parent: 3:27eef8ed80b4
1118 1118 | | | | | | parent: 4:26a8bac39d9f
1119 1119 | | | | | | user: test
1120 1120 | | | | | | date: Thu Jan 01 00:00:05 1970 +0000
1121 1121 | | | | | | summary: (5) expand
1122 1122 | | | | | |
1123 1123 | +---o | | changeset: 4:26a8bac39d9f
1124 1124 | | | |/ / parent: 1:6db2ef61d156
1125 1125 | | | | | parent: 3:27eef8ed80b4
1126 1126 | | | | | user: test
1127 1127 | | | | | date: Thu Jan 01 00:00:04 1970 +0000
1128 1128 | | | | | summary: (4) merge two known; one immediate left, one immediate right
1129 1129 | | | | |
1130 1130
1131 1131
1132 1132 Empty revision range - display nothing:
1133 1133 $ hg log -G -r 1..0
1134 1134
1135 1135 $ cd ..
1136 1136
1137 1137 #if no-outer-repo
1138 1138
1139 1139 From outer space:
1140 1140 $ hg log -G -l1 repo
1141 1141 @ changeset: 34:fea3ac5810e0
1142 1142 | tag: tip
1143 1143 | parent: 32:d06dffa21a31
1144 1144 | user: test
1145 1145 | date: Thu Jan 01 00:00:34 1970 +0000
1146 1146 | summary: (34) head
1147 1147 |
1148 1148 $ hg log -G -l1 repo/a
1149 1149 @ changeset: 34:fea3ac5810e0
1150 1150 | tag: tip
1151 1151 | parent: 32:d06dffa21a31
1152 1152 | user: test
1153 1153 | date: Thu Jan 01 00:00:34 1970 +0000
1154 1154 | summary: (34) head
1155 1155 |
1156 1156 $ hg log -G -l1 repo/missing
1157 1157
1158 1158 #endif
1159 1159
1160 1160 File log with revs != cset revs:
1161 1161 $ hg init flog
1162 1162 $ cd flog
1163 1163 $ echo one >one
1164 1164 $ hg add one
1165 1165 $ hg commit -mone
1166 1166 $ echo two >two
1167 1167 $ hg add two
1168 1168 $ hg commit -mtwo
1169 1169 $ echo more >two
1170 1170 $ hg commit -mmore
1171 1171 $ hg log -G two
1172 1172 @ changeset: 2:12c28321755b
1173 1173 | tag: tip
1174 1174 | user: test
1175 1175 | date: Thu Jan 01 00:00:00 1970 +0000
1176 1176 | summary: more
1177 1177 |
1178 1178 o changeset: 1:5ac72c0599bf
1179 1179 | user: test
1180 1180 | date: Thu Jan 01 00:00:00 1970 +0000
1181 1181 | summary: two
1182 1182 |
1183 1183
1184 1184 Issue1896: File log with explicit style
1185 1185 $ hg log -G --style=default one
1186 1186 o changeset: 0:3d578b4a1f53
1187 1187 user: test
1188 1188 date: Thu Jan 01 00:00:00 1970 +0000
1189 1189 summary: one
1190 1190
1191 1191 Issue2395: glog --style header and footer
1192 1192 $ hg log -G --style=xml one
1193 1193 <?xml version="1.0"?>
1194 1194 <log>
1195 1195 o <logentry revision="0" node="3d578b4a1f537d5fcf7301bfa9c0b97adfaa6fb1">
1196 1196 <author email="test">test</author>
1197 1197 <date>1970-01-01T00:00:00+00:00</date>
1198 1198 <msg xml:space="preserve">one</msg>
1199 1199 </logentry>
1200 1200 </log>
1201 1201
1202 1202 $ cd ..
1203 1203
1204 1204 Incoming and outgoing:
1205 1205
1206 1206 $ hg clone -U -r31 repo repo2
1207 1207 adding changesets
1208 1208 adding manifests
1209 1209 adding file changes
1210 1210 added 31 changesets with 31 changes to 1 files
1211 1211 $ cd repo2
1212 1212
1213 1213 $ hg incoming --graph ../repo
1214 1214 comparing with ../repo
1215 1215 searching for changes
1216 1216 o changeset: 34:fea3ac5810e0
1217 1217 | tag: tip
1218 1218 | parent: 32:d06dffa21a31
1219 1219 | user: test
1220 1220 | date: Thu Jan 01 00:00:34 1970 +0000
1221 1221 | summary: (34) head
1222 1222 |
1223 1223 | o changeset: 33:68608f5145f9
1224 1224 | parent: 18:1aa84d96232a
1225 1225 | user: test
1226 1226 | date: Thu Jan 01 00:00:33 1970 +0000
1227 1227 | summary: (33) head
1228 1228 |
1229 1229 o changeset: 32:d06dffa21a31
1230 1230 | parent: 27:886ed638191b
1231 1231 | parent: 31:621d83e11f67
1232 1232 | user: test
1233 1233 | date: Thu Jan 01 00:00:32 1970 +0000
1234 1234 | summary: (32) expand
1235 1235 |
1236 1236 o changeset: 27:886ed638191b
1237 1237 parent: 21:d42a756af44d
1238 1238 user: test
1239 1239 date: Thu Jan 01 00:00:27 1970 +0000
1240 1240 summary: (27) collapse
1241 1241
1242 1242 $ cd ..
1243 1243
1244 1244 $ hg -R repo outgoing --graph repo2
1245 1245 comparing with repo2
1246 1246 searching for changes
1247 1247 @ changeset: 34:fea3ac5810e0
1248 1248 | tag: tip
1249 1249 | parent: 32:d06dffa21a31
1250 1250 | user: test
1251 1251 | date: Thu Jan 01 00:00:34 1970 +0000
1252 1252 | summary: (34) head
1253 1253 |
1254 1254 | o changeset: 33:68608f5145f9
1255 1255 | parent: 18:1aa84d96232a
1256 1256 | user: test
1257 1257 | date: Thu Jan 01 00:00:33 1970 +0000
1258 1258 | summary: (33) head
1259 1259 |
1260 1260 o changeset: 32:d06dffa21a31
1261 1261 | parent: 27:886ed638191b
1262 1262 | parent: 31:621d83e11f67
1263 1263 | user: test
1264 1264 | date: Thu Jan 01 00:00:32 1970 +0000
1265 1265 | summary: (32) expand
1266 1266 |
1267 1267 o changeset: 27:886ed638191b
1268 1268 parent: 21:d42a756af44d
1269 1269 user: test
1270 1270 date: Thu Jan 01 00:00:27 1970 +0000
1271 1271 summary: (27) collapse
1272 1272
1273 1273
1274 1274 File + limit with revs != cset revs:
1275 1275 $ cd repo
1276 1276 $ touch b
1277 1277 $ hg ci -Aqm0
1278 1278 $ hg log -G -l2 a
1279 1279 o changeset: 34:fea3ac5810e0
1280 1280 | parent: 32:d06dffa21a31
1281 1281 | user: test
1282 1282 | date: Thu Jan 01 00:00:34 1970 +0000
1283 1283 | summary: (34) head
1284 1284 |
1285 1285 | o changeset: 33:68608f5145f9
1286 1286 | | parent: 18:1aa84d96232a
1287 1287 | | user: test
1288 1288 | | date: Thu Jan 01 00:00:33 1970 +0000
1289 1289 | | summary: (33) head
1290 1290 | |
1291 1291
1292 1292 File + limit + -ra:b, (b - a) < limit:
1293 1293 $ hg log -G -l3000 -r32:tip a
1294 1294 o changeset: 34:fea3ac5810e0
1295 1295 | parent: 32:d06dffa21a31
1296 1296 | user: test
1297 1297 | date: Thu Jan 01 00:00:34 1970 +0000
1298 1298 | summary: (34) head
1299 1299 |
1300 1300 | o changeset: 33:68608f5145f9
1301 1301 | | parent: 18:1aa84d96232a
1302 1302 | | user: test
1303 1303 | | date: Thu Jan 01 00:00:33 1970 +0000
1304 1304 | | summary: (33) head
1305 1305 | |
1306 1306 o | changeset: 32:d06dffa21a31
1307 1307 |\ \ parent: 27:886ed638191b
1308 1308 | | | parent: 31:621d83e11f67
1309 1309 | | | user: test
1310 1310 | | | date: Thu Jan 01 00:00:32 1970 +0000
1311 1311 | | | summary: (32) expand
1312 1312 | | |
1313 1313
1314 1314 Point out a common and an uncommon unshown parent
1315 1315
1316 1316 $ hg log -G -r 'rev(8) or rev(9)'
1317 1317 o changeset: 9:7010c0af0a35
1318 1318 |\ parent: 7:b632bb1b1224
1319 1319 | | parent: 8:7a0b11f71937
1320 1320 | | user: test
1321 1321 | | date: Thu Jan 01 00:00:09 1970 +0000
1322 1322 | | summary: (9) expand
1323 1323 | |
1324 1324 o | changeset: 8:7a0b11f71937
1325 1325 |\| parent: 0:e6eb3150255d
1326 1326 | | parent: 7:b632bb1b1224
1327 1327 | | user: test
1328 1328 | | date: Thu Jan 01 00:00:08 1970 +0000
1329 1329 | | summary: (8) merge two known; one immediate left, one far right
1330 1330 | |
1331 1331
1332 1332 File + limit + -ra:b, b < tip:
1333 1333
1334 1334 $ hg log -G -l1 -r32:34 a
1335 1335 o changeset: 34:fea3ac5810e0
1336 1336 | parent: 32:d06dffa21a31
1337 1337 | user: test
1338 1338 | date: Thu Jan 01 00:00:34 1970 +0000
1339 1339 | summary: (34) head
1340 1340 |
1341 1341
1342 1342 file(File) + limit + -ra:b, b < tip:
1343 1343
1344 1344 $ hg log -G -l1 -r32:34 -r 'file("a")'
1345 1345 o changeset: 34:fea3ac5810e0
1346 1346 | parent: 32:d06dffa21a31
1347 1347 | user: test
1348 1348 | date: Thu Jan 01 00:00:34 1970 +0000
1349 1349 | summary: (34) head
1350 1350 |
1351 1351
1352 1352 limit(file(File) and a::b), b < tip:
1353 1353
1354 1354 $ hg log -G -r 'limit(file("a") and 32::34, 1)'
1355 1355 o changeset: 32:d06dffa21a31
1356 1356 |\ parent: 27:886ed638191b
1357 1357 | | parent: 31:621d83e11f67
1358 1358 | | user: test
1359 1359 | | date: Thu Jan 01 00:00:32 1970 +0000
1360 1360 | | summary: (32) expand
1361 1361 | |
1362 1362
1363 1363 File + limit + -ra:b, b < tip:
1364 1364
1365 1365 $ hg log -G -r 'limit(file("a") and 34::32, 1)'
1366 1366
1367 1367 File + limit + -ra:b, b < tip, (b - a) < limit:
1368 1368
1369 1369 $ hg log -G -l10 -r33:34 a
1370 1370 o changeset: 34:fea3ac5810e0
1371 1371 | parent: 32:d06dffa21a31
1372 1372 | user: test
1373 1373 | date: Thu Jan 01 00:00:34 1970 +0000
1374 1374 | summary: (34) head
1375 1375 |
1376 1376 | o changeset: 33:68608f5145f9
1377 1377 | | parent: 18:1aa84d96232a
1378 1378 | | user: test
1379 1379 | | date: Thu Jan 01 00:00:33 1970 +0000
1380 1380 | | summary: (33) head
1381 1381 | |
1382 1382
1383 1383 Do not crash or produce strange graphs if history is buggy
1384 1384
1385 1385 $ hg branch branch
1386 1386 marked working directory as branch branch
1387 1387 (branches are permanent and global, did you want a bookmark?)
1388 1388 $ commit 36 "buggy merge: identical parents" 35 35
1389 1389 $ hg log -G -l5
1390 1390 @ changeset: 36:08a19a744424
1391 1391 | branch: branch
1392 1392 | tag: tip
1393 1393 | parent: 35:9159c3644c5e
1394 1394 | parent: 35:9159c3644c5e
1395 1395 | user: test
1396 1396 | date: Thu Jan 01 00:00:36 1970 +0000
1397 1397 | summary: (36) buggy merge: identical parents
1398 1398 |
1399 1399 o changeset: 35:9159c3644c5e
1400 1400 | user: test
1401 1401 | date: Thu Jan 01 00:00:00 1970 +0000
1402 1402 | summary: 0
1403 1403 |
1404 1404 o changeset: 34:fea3ac5810e0
1405 1405 | parent: 32:d06dffa21a31
1406 1406 | user: test
1407 1407 | date: Thu Jan 01 00:00:34 1970 +0000
1408 1408 | summary: (34) head
1409 1409 |
1410 1410 | o changeset: 33:68608f5145f9
1411 1411 | | parent: 18:1aa84d96232a
1412 1412 | | user: test
1413 1413 | | date: Thu Jan 01 00:00:33 1970 +0000
1414 1414 | | summary: (33) head
1415 1415 | |
1416 1416 o | changeset: 32:d06dffa21a31
1417 1417 |\ \ parent: 27:886ed638191b
1418 1418 | | | parent: 31:621d83e11f67
1419 1419 | | | user: test
1420 1420 | | | date: Thu Jan 01 00:00:32 1970 +0000
1421 1421 | | | summary: (32) expand
1422 1422 | | |
1423 1423
1424 1424 Test log -G options
1425 1425
1426 1426 $ testlog() {
1427 1427 > hg log -G --print-revset "$@"
1428 1428 > hg log --template 'nodetag {rev}\n' "$@" | grep nodetag \
1429 1429 > | sed 's/.*nodetag/nodetag/' > log.nodes
1430 1430 > hg log -G --template 'nodetag {rev}\n' "$@" | grep nodetag \
1431 1431 > | sed 's/.*nodetag/nodetag/' > glog.nodes
1432 1432 > diff -u log.nodes glog.nodes | grep '^[-+@ ]' || :
1433 1433 > }
1434 1434
1435 1435 glog always reorders nodes which explains the difference with log
1436 1436
1437 1437 $ testlog -r 27 -r 25 -r 21 -r 34 -r 32 -r 31
1438 1438 ['27', '25', '21', '34', '32', '31']
1439 1439 []
1440 1440 --- log.nodes * (glob)
1441 1441 +++ glog.nodes * (glob)
1442 1442 @@ -1,6 +1,6 @@
1443 1443 -nodetag 27
1444 1444 -nodetag 25
1445 1445 -nodetag 21
1446 1446 nodetag 34
1447 1447 nodetag 32
1448 1448 nodetag 31
1449 1449 +nodetag 27
1450 1450 +nodetag 25
1451 1451 +nodetag 21
1452 1452 $ testlog -u test -u not-a-user
1453 1453 []
1454 1454 (group
1455 1455 (group
1456 1456 (or
1457 1457 (func
1458 1458 ('symbol', 'user')
1459 1459 ('string', 'test'))
1460 1460 (func
1461 1461 ('symbol', 'user')
1462 1462 ('string', 'not-a-user')))))
1463 1463 $ testlog -b not-a-branch
1464 1464 abort: unknown revision 'not-a-branch'!
1465 1465 abort: unknown revision 'not-a-branch'!
1466 1466 abort: unknown revision 'not-a-branch'!
1467 1467 $ testlog -b 35 -b 36 --only-branch branch
1468 1468 []
1469 1469 (group
1470 1470 (group
1471 1471 (or
1472 1472 (or
1473 1473 (func
1474 1474 ('symbol', 'branch')
1475 1475 ('string', 'default'))
1476 1476 (func
1477 1477 ('symbol', 'branch')
1478 1478 ('string', 'branch')))
1479 1479 (func
1480 1480 ('symbol', 'branch')
1481 1481 ('string', 'branch')))))
1482 1482 $ testlog -k expand -k merge
1483 1483 []
1484 1484 (group
1485 1485 (group
1486 1486 (or
1487 1487 (func
1488 1488 ('symbol', 'keyword')
1489 1489 ('string', 'expand'))
1490 1490 (func
1491 1491 ('symbol', 'keyword')
1492 1492 ('string', 'merge')))))
1493 1493 $ testlog --only-merges
1494 1494 []
1495 1495 (group
1496 1496 (func
1497 1497 ('symbol', 'merge')
1498 1498 None))
1499 1499 $ testlog --no-merges
1500 1500 []
1501 1501 (group
1502 1502 (not
1503 1503 (func
1504 1504 ('symbol', 'merge')
1505 1505 None)))
1506 1506 $ testlog --date '2 0 to 4 0'
1507 1507 []
1508 1508 (group
1509 1509 (func
1510 1510 ('symbol', 'date')
1511 1511 ('string', '2 0 to 4 0')))
1512 1512 $ hg log -G -d 'brace ) in a date'
1513 1513 abort: invalid date: 'brace ) in a date'
1514 1514 [255]
1515 1515 $ testlog --prune 31 --prune 32
1516 1516 []
1517 1517 (group
1518 1518 (group
1519 1519 (and
1520 1520 (not
1521 1521 (group
1522 1522 (or
1523 1523 ('string', '31')
1524 1524 (func
1525 1525 ('symbol', 'ancestors')
1526 1526 ('string', '31')))))
1527 1527 (not
1528 1528 (group
1529 1529 (or
1530 1530 ('string', '32')
1531 1531 (func
1532 1532 ('symbol', 'ancestors')
1533 1533 ('string', '32'))))))))
1534 1534
1535 1535 Dedicated repo for --follow and paths filtering. The g is crafted to
1536 1536 have 2 filelog topological heads in a linear changeset graph.
1537 1537
1538 1538 $ cd ..
1539 1539 $ hg init follow
1540 1540 $ cd follow
1541 1541 $ testlog --follow
1542 1542 []
1543 1543 []
1544 1544 $ testlog -rnull
1545 1545 ['null']
1546 1546 []
1547 1547 $ echo a > a
1548 1548 $ echo aa > aa
1549 1549 $ echo f > f
1550 1550 $ hg ci -Am "add a" a aa f
1551 1551 $ hg cp a b
1552 1552 $ hg cp f g
1553 1553 $ hg ci -m "copy a b"
1554 1554 $ mkdir dir
1555 1555 $ hg mv b dir
1556 1556 $ echo g >> g
1557 1557 $ echo f >> f
1558 1558 $ hg ci -m "mv b dir/b"
1559 1559 $ hg mv a b
1560 1560 $ hg cp -f f g
1561 1561 $ echo a > d
1562 1562 $ hg add d
1563 1563 $ hg ci -m "mv a b; add d"
1564 1564 $ hg mv dir/b e
1565 1565 $ hg ci -m "mv dir/b e"
1566 1566 $ hg log -G --template '({rev}) {desc|firstline}\n'
1567 1567 @ (4) mv dir/b e
1568 1568 |
1569 1569 o (3) mv a b; add d
1570 1570 |
1571 1571 o (2) mv b dir/b
1572 1572 |
1573 1573 o (1) copy a b
1574 1574 |
1575 1575 o (0) add a
1576 1576
1577 1577
1578 1578 $ testlog a
1579 1579 []
1580 1580 (group
1581 1581 (group
1582 1582 (func
1583 1583 ('symbol', 'filelog')
1584 1584 ('string', 'a'))))
1585 1585 $ testlog a b
1586 1586 []
1587 1587 (group
1588 1588 (group
1589 1589 (or
1590 1590 (func
1591 1591 ('symbol', 'filelog')
1592 1592 ('string', 'a'))
1593 1593 (func
1594 1594 ('symbol', 'filelog')
1595 1595 ('string', 'b')))))
1596 1596
1597 1597 Test falling back to slow path for non-existing files
1598 1598
1599 1599 $ testlog a c
1600 1600 []
1601 1601 (group
1602 1602 (func
1603 1603 ('symbol', '_matchfiles')
1604 1604 (list
1605 1605 (list
1606 1606 (list
1607 1607 ('string', 'r:')
1608 1608 ('string', 'd:relpath'))
1609 1609 ('string', 'p:a'))
1610 1610 ('string', 'p:c'))))
1611 1611
1612 1612 Test multiple --include/--exclude/paths
1613 1613
1614 1614 $ testlog --include a --include e --exclude b --exclude e a e
1615 1615 []
1616 1616 (group
1617 1617 (func
1618 1618 ('symbol', '_matchfiles')
1619 1619 (list
1620 1620 (list
1621 1621 (list
1622 1622 (list
1623 1623 (list
1624 1624 (list
1625 1625 (list
1626 1626 ('string', 'r:')
1627 1627 ('string', 'd:relpath'))
1628 1628 ('string', 'p:a'))
1629 1629 ('string', 'p:e'))
1630 1630 ('string', 'i:a'))
1631 1631 ('string', 'i:e'))
1632 1632 ('string', 'x:b'))
1633 1633 ('string', 'x:e'))))
1634 1634
1635 1635 Test glob expansion of pats
1636 1636
1637 1637 $ expandglobs=`$PYTHON -c "import mercurial.util; \
1638 1638 > print mercurial.util.expandglobs and 'true' or 'false'"`
1639 1639 $ if [ $expandglobs = "true" ]; then
1640 1640 > testlog 'a*';
1641 1641 > else
1642 1642 > testlog a*;
1643 1643 > fi;
1644 1644 []
1645 1645 (group
1646 1646 (group
1647 1647 (func
1648 1648 ('symbol', 'filelog')
1649 1649 ('string', 'aa'))))
1650 1650
1651 1651 Test --follow on a non-existent directory
1652 1652
1653 1653 $ testlog -f dir
1654 1654 abort: cannot follow file not in parent revision: "dir"
1655 1655 abort: cannot follow file not in parent revision: "dir"
1656 1656 abort: cannot follow file not in parent revision: "dir"
1657 1657
1658 1658 Test --follow on a directory
1659 1659
1660 1660 $ hg up -q '.^'
1661 1661 $ testlog -f dir
1662 1662 []
1663 1663 (group
1664 1664 (and
1665 1665 (func
1666 1666 ('symbol', 'ancestors')
1667 1667 ('symbol', '.'))
1668 1668 (func
1669 1669 ('symbol', '_matchfiles')
1670 1670 (list
1671 1671 (list
1672 1672 ('string', 'r:')
1673 1673 ('string', 'd:relpath'))
1674 1674 ('string', 'p:dir')))))
1675 1675 $ hg up -q tip
1676 1676
1677 1677 Test --follow on file not in parent revision
1678 1678
1679 1679 $ testlog -f a
1680 1680 abort: cannot follow file not in parent revision: "a"
1681 1681 abort: cannot follow file not in parent revision: "a"
1682 1682 abort: cannot follow file not in parent revision: "a"
1683 1683
1684 1684 Test --follow and patterns
1685 1685
1686 1686 $ testlog -f 'glob:*'
1687 1687 []
1688 1688 (group
1689 1689 (and
1690 1690 (func
1691 1691 ('symbol', 'ancestors')
1692 1692 ('symbol', '.'))
1693 1693 (func
1694 1694 ('symbol', '_matchfiles')
1695 1695 (list
1696 1696 (list
1697 1697 ('string', 'r:')
1698 1698 ('string', 'd:relpath'))
1699 1699 ('string', 'p:glob:*')))))
1700 1700
1701 1701 Test --follow on a single rename
1702 1702
1703 1703 $ hg up -q 2
1704 1704 $ testlog -f a
1705 1705 []
1706 1706 (group
1707 1707 (group
1708 1708 (func
1709 1709 ('symbol', 'follow')
1710 1710 ('string', 'a'))))
1711 1711
1712 1712 Test --follow and multiple renames
1713 1713
1714 1714 $ hg up -q tip
1715 1715 $ testlog -f e
1716 1716 []
1717 1717 (group
1718 1718 (group
1719 1719 (func
1720 1720 ('symbol', 'follow')
1721 1721 ('string', 'e'))))
1722 1722
1723 1723 Test --follow and multiple filelog heads
1724 1724
1725 1725 $ hg up -q 2
1726 1726 $ testlog -f g
1727 1727 []
1728 1728 (group
1729 1729 (group
1730 1730 (func
1731 1731 ('symbol', 'follow')
1732 1732 ('string', 'g'))))
1733 1733 $ cat log.nodes
1734 1734 nodetag 2
1735 1735 nodetag 1
1736 1736 nodetag 0
1737 1737 $ hg up -q tip
1738 1738 $ testlog -f g
1739 1739 []
1740 1740 (group
1741 1741 (group
1742 1742 (func
1743 1743 ('symbol', 'follow')
1744 1744 ('string', 'g'))))
1745 1745 $ cat log.nodes
1746 1746 nodetag 3
1747 1747 nodetag 2
1748 1748 nodetag 0
1749 1749
1750 1750 Test --follow and multiple files
1751 1751
1752 1752 $ testlog -f g e
1753 1753 []
1754 1754 (group
1755 1755 (group
1756 1756 (or
1757 1757 (func
1758 1758 ('symbol', 'follow')
1759 1759 ('string', 'g'))
1760 1760 (func
1761 1761 ('symbol', 'follow')
1762 1762 ('string', 'e')))))
1763 1763 $ cat log.nodes
1764 1764 nodetag 4
1765 1765 nodetag 3
1766 1766 nodetag 2
1767 1767 nodetag 1
1768 1768 nodetag 0
1769 1769
1770 1770 Test --follow null parent
1771 1771
1772 1772 $ hg up -q null
1773 1773 $ testlog -f
1774 1774 []
1775 1775 []
1776 1776
1777 1777 Test --follow-first
1778 1778
1779 1779 $ hg up -q 3
1780 1780 $ echo ee > e
1781 1781 $ hg ci -Am "add another e" e
1782 1782 created new head
1783 1783 $ hg merge --tool internal:other 4
1784 1784 0 files updated, 1 files merged, 1 files removed, 0 files unresolved
1785 1785 (branch merge, don't forget to commit)
1786 1786 $ echo merge > e
1787 1787 $ hg ci -m "merge 5 and 4"
1788 1788 $ testlog --follow-first
1789 1789 []
1790 1790 (group
1791 1791 (func
1792 1792 ('symbol', '_firstancestors')
1793 1793 (func
1794 1794 ('symbol', 'rev')
1795 1795 ('symbol', '6'))))
1796 1796
1797 1797 Cannot compare with log --follow-first FILE as it never worked
1798 1798
1799 1799 $ hg log -G --print-revset --follow-first e
1800 1800 []
1801 1801 (group
1802 1802 (group
1803 1803 (func
1804 1804 ('symbol', '_followfirst')
1805 1805 ('string', 'e'))))
1806 1806 $ hg log -G --follow-first e --template '{rev} {desc|firstline}\n'
1807 1807 @ 6 merge 5 and 4
1808 1808 |\
1809 1809 o | 5 add another e
1810 1810 | |
1811 1811
1812 1812 Test --copies
1813 1813
1814 1814 $ hg log -G --copies --template "{rev} {desc|firstline} \
1815 1815 > copies: {file_copies_switch}\n"
1816 1816 @ 6 merge 5 and 4 copies:
1817 1817 |\
1818 1818 | o 5 add another e copies:
1819 1819 | |
1820 1820 o | 4 mv dir/b e copies: e (dir/b)
1821 1821 |/
1822 1822 o 3 mv a b; add d copies: b (a)g (f)
1823 1823 |
1824 1824 o 2 mv b dir/b copies: dir/b (b)
1825 1825 |
1826 1826 o 1 copy a b copies: b (a)g (f)
1827 1827 |
1828 1828 o 0 add a copies:
1829 1829
1830 1830 Test "set:..." and parent revision
1831 1831
1832 1832 $ hg up -q 4
1833 1833 $ testlog "set:copied()"
1834 1834 []
1835 1835 (group
1836 1836 (func
1837 1837 ('symbol', '_matchfiles')
1838 1838 (list
1839 1839 (list
1840 1840 ('string', 'r:')
1841 1841 ('string', 'd:relpath'))
1842 1842 ('string', 'p:set:copied()'))))
1843 1843 $ testlog --include "set:copied()"
1844 1844 []
1845 1845 (group
1846 1846 (func
1847 1847 ('symbol', '_matchfiles')
1848 1848 (list
1849 1849 (list
1850 1850 ('string', 'r:')
1851 1851 ('string', 'd:relpath'))
1852 1852 ('string', 'i:set:copied()'))))
1853 1853 $ testlog -r "sort(file('set:copied()'), -rev)"
1854 1854 ["sort(file('set:copied()'), -rev)"]
1855 1855 []
1856 1856
1857 1857 Test --removed
1858 1858
1859 1859 $ testlog --removed
1860 1860 []
1861 1861 []
1862 1862 $ testlog --removed a
1863 1863 []
1864 1864 (group
1865 1865 (func
1866 1866 ('symbol', '_matchfiles')
1867 1867 (list
1868 1868 (list
1869 1869 ('string', 'r:')
1870 1870 ('string', 'd:relpath'))
1871 1871 ('string', 'p:a'))))
1872 1872 $ testlog --removed --follow a
1873 1873 []
1874 1874 (group
1875 1875 (and
1876 1876 (func
1877 1877 ('symbol', 'ancestors')
1878 1878 ('symbol', '.'))
1879 1879 (func
1880 1880 ('symbol', '_matchfiles')
1881 1881 (list
1882 1882 (list
1883 1883 ('string', 'r:')
1884 1884 ('string', 'd:relpath'))
1885 1885 ('string', 'p:a')))))
1886 1886
1887 1887 Test --patch and --stat with --follow and --follow-first
1888 1888
1889 1889 $ hg up -q 3
1890 1890 $ hg log -G --git --patch b
1891 1891 o changeset: 1:216d4c92cf98
1892 1892 | user: test
1893 1893 | date: Thu Jan 01 00:00:00 1970 +0000
1894 1894 | summary: copy a b
1895 1895 |
1896 1896 | diff --git a/a b/b
1897 1897 | copy from a
1898 1898 | copy to b
1899 1899 |
1900 1900
1901 1901 $ hg log -G --git --stat b
1902 1902 o changeset: 1:216d4c92cf98
1903 1903 | user: test
1904 1904 | date: Thu Jan 01 00:00:00 1970 +0000
1905 1905 | summary: copy a b
1906 1906 |
1907 1907 | b | 0
1908 1908 | 1 files changed, 0 insertions(+), 0 deletions(-)
1909 1909 |
1910 1910
1911 1911 $ hg log -G --git --patch --follow b
1912 1912 o changeset: 1:216d4c92cf98
1913 1913 | user: test
1914 1914 | date: Thu Jan 01 00:00:00 1970 +0000
1915 1915 | summary: copy a b
1916 1916 |
1917 1917 | diff --git a/a b/b
1918 1918 | copy from a
1919 1919 | copy to b
1920 1920 |
1921 1921 o changeset: 0:f8035bb17114
1922 1922 user: test
1923 1923 date: Thu Jan 01 00:00:00 1970 +0000
1924 1924 summary: add a
1925 1925
1926 1926 diff --git a/a b/a
1927 1927 new file mode 100644
1928 1928 --- /dev/null
1929 1929 +++ b/a
1930 1930 @@ -0,0 +1,1 @@
1931 1931 +a
1932 1932
1933 1933
1934 1934 $ hg log -G --git --stat --follow b
1935 1935 o changeset: 1:216d4c92cf98
1936 1936 | user: test
1937 1937 | date: Thu Jan 01 00:00:00 1970 +0000
1938 1938 | summary: copy a b
1939 1939 |
1940 1940 | b | 0
1941 1941 | 1 files changed, 0 insertions(+), 0 deletions(-)
1942 1942 |
1943 1943 o changeset: 0:f8035bb17114
1944 1944 user: test
1945 1945 date: Thu Jan 01 00:00:00 1970 +0000
1946 1946 summary: add a
1947 1947
1948 1948 a | 1 +
1949 1949 1 files changed, 1 insertions(+), 0 deletions(-)
1950 1950
1951 1951
1952 1952 $ hg up -q 6
1953 1953 $ hg log -G --git --patch --follow-first e
1954 1954 @ changeset: 6:fc281d8ff18d
1955 1955 |\ tag: tip
1956 1956 | | parent: 5:99b31f1c2782
1957 1957 | | parent: 4:17d952250a9d
1958 1958 | | user: test
1959 1959 | | date: Thu Jan 01 00:00:00 1970 +0000
1960 1960 | | summary: merge 5 and 4
1961 1961 | |
1962 1962 | | diff --git a/e b/e
1963 1963 | | --- a/e
1964 1964 | | +++ b/e
1965 1965 | | @@ -1,1 +1,1 @@
1966 1966 | | -ee
1967 1967 | | +merge
1968 1968 | |
1969 1969 o | changeset: 5:99b31f1c2782
1970 1970 | | parent: 3:5918b8d165d1
1971 1971 | | user: test
1972 1972 | | date: Thu Jan 01 00:00:00 1970 +0000
1973 1973 | | summary: add another e
1974 1974 | |
1975 1975 | | diff --git a/e b/e
1976 1976 | | new file mode 100644
1977 1977 | | --- /dev/null
1978 1978 | | +++ b/e
1979 1979 | | @@ -0,0 +1,1 @@
1980 1980 | | +ee
1981 1981 | |
1982 1982
1983 1983 Test old-style --rev
1984 1984
1985 1985 $ hg tag 'foo-bar'
1986 1986 $ testlog -r 'foo-bar'
1987 1987 ['foo-bar']
1988 1988 []
1989 1989
1990 1990 Test --follow and forward --rev
1991 1991
1992 1992 $ hg up -q 6
1993 1993 $ echo g > g
1994 1994 $ hg ci -Am 'add g' g
1995 1995 created new head
1996 1996 $ hg up -q 2
1997 1997 $ hg log -G --template "{rev} {desc|firstline}\n"
1998 1998 o 8 add g
1999 1999 |
2000 2000 | o 7 Added tag foo-bar for changeset fc281d8ff18d
2001 2001 |/
2002 2002 o 6 merge 5 and 4
2003 2003 |\
2004 2004 | o 5 add another e
2005 2005 | |
2006 2006 o | 4 mv dir/b e
2007 2007 |/
2008 2008 o 3 mv a b; add d
2009 2009 |
2010 2010 @ 2 mv b dir/b
2011 2011 |
2012 2012 o 1 copy a b
2013 2013 |
2014 2014 o 0 add a
2015 2015
2016 2016 $ hg export 'all()'
2017 2017 # HG changeset patch
2018 2018 # User test
2019 2019 # Date 0 0
2020 2020 # Thu Jan 01 00:00:00 1970 +0000
2021 2021 # Node ID f8035bb17114da16215af3436ec5222428ace8ee
2022 2022 # Parent 0000000000000000000000000000000000000000
2023 2023 add a
2024 2024
2025 2025 diff -r 000000000000 -r f8035bb17114 a
2026 2026 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2027 2027 +++ b/a Thu Jan 01 00:00:00 1970 +0000
2028 2028 @@ -0,0 +1,1 @@
2029 2029 +a
2030 2030 diff -r 000000000000 -r f8035bb17114 aa
2031 2031 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2032 2032 +++ b/aa Thu Jan 01 00:00:00 1970 +0000
2033 2033 @@ -0,0 +1,1 @@
2034 2034 +aa
2035 2035 diff -r 000000000000 -r f8035bb17114 f
2036 2036 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2037 2037 +++ b/f Thu Jan 01 00:00:00 1970 +0000
2038 2038 @@ -0,0 +1,1 @@
2039 2039 +f
2040 2040 # HG changeset patch
2041 2041 # User test
2042 2042 # Date 0 0
2043 2043 # Thu Jan 01 00:00:00 1970 +0000
2044 2044 # Node ID 216d4c92cf98ff2b4641d508b76b529f3d424c92
2045 2045 # Parent f8035bb17114da16215af3436ec5222428ace8ee
2046 2046 copy a b
2047 2047
2048 2048 diff -r f8035bb17114 -r 216d4c92cf98 b
2049 2049 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2050 2050 +++ b/b Thu Jan 01 00:00:00 1970 +0000
2051 2051 @@ -0,0 +1,1 @@
2052 2052 +a
2053 2053 diff -r f8035bb17114 -r 216d4c92cf98 g
2054 2054 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2055 2055 +++ b/g Thu Jan 01 00:00:00 1970 +0000
2056 2056 @@ -0,0 +1,1 @@
2057 2057 +f
2058 2058 # HG changeset patch
2059 2059 # User test
2060 2060 # Date 0 0
2061 2061 # Thu Jan 01 00:00:00 1970 +0000
2062 2062 # Node ID bb573313a9e8349099b6ea2b2fb1fc7f424446f3
2063 2063 # Parent 216d4c92cf98ff2b4641d508b76b529f3d424c92
2064 2064 mv b dir/b
2065 2065
2066 2066 diff -r 216d4c92cf98 -r bb573313a9e8 b
2067 2067 --- a/b Thu Jan 01 00:00:00 1970 +0000
2068 2068 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2069 2069 @@ -1,1 +0,0 @@
2070 2070 -a
2071 2071 diff -r 216d4c92cf98 -r bb573313a9e8 dir/b
2072 2072 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2073 2073 +++ b/dir/b Thu Jan 01 00:00:00 1970 +0000
2074 2074 @@ -0,0 +1,1 @@
2075 2075 +a
2076 2076 diff -r 216d4c92cf98 -r bb573313a9e8 f
2077 2077 --- a/f Thu Jan 01 00:00:00 1970 +0000
2078 2078 +++ b/f Thu Jan 01 00:00:00 1970 +0000
2079 2079 @@ -1,1 +1,2 @@
2080 2080 f
2081 2081 +f
2082 2082 diff -r 216d4c92cf98 -r bb573313a9e8 g
2083 2083 --- a/g Thu Jan 01 00:00:00 1970 +0000
2084 2084 +++ b/g Thu Jan 01 00:00:00 1970 +0000
2085 2085 @@ -1,1 +1,2 @@
2086 2086 f
2087 2087 +g
2088 2088 # HG changeset patch
2089 2089 # User test
2090 2090 # Date 0 0
2091 2091 # Thu Jan 01 00:00:00 1970 +0000
2092 2092 # Node ID 5918b8d165d1364e78a66d02e66caa0133c5d1ed
2093 2093 # Parent bb573313a9e8349099b6ea2b2fb1fc7f424446f3
2094 2094 mv a b; add d
2095 2095
2096 2096 diff -r bb573313a9e8 -r 5918b8d165d1 a
2097 2097 --- a/a Thu Jan 01 00:00:00 1970 +0000
2098 2098 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2099 2099 @@ -1,1 +0,0 @@
2100 2100 -a
2101 2101 diff -r bb573313a9e8 -r 5918b8d165d1 b
2102 2102 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2103 2103 +++ b/b Thu Jan 01 00:00:00 1970 +0000
2104 2104 @@ -0,0 +1,1 @@
2105 2105 +a
2106 2106 diff -r bb573313a9e8 -r 5918b8d165d1 d
2107 2107 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2108 2108 +++ b/d Thu Jan 01 00:00:00 1970 +0000
2109 2109 @@ -0,0 +1,1 @@
2110 2110 +a
2111 2111 diff -r bb573313a9e8 -r 5918b8d165d1 g
2112 2112 --- a/g Thu Jan 01 00:00:00 1970 +0000
2113 2113 +++ b/g Thu Jan 01 00:00:00 1970 +0000
2114 2114 @@ -1,2 +1,2 @@
2115 2115 f
2116 2116 -g
2117 2117 +f
2118 2118 # HG changeset patch
2119 2119 # User test
2120 2120 # Date 0 0
2121 2121 # Thu Jan 01 00:00:00 1970 +0000
2122 2122 # Node ID 17d952250a9d03cc3dc77b199ab60e959b9b0260
2123 2123 # Parent 5918b8d165d1364e78a66d02e66caa0133c5d1ed
2124 2124 mv dir/b e
2125 2125
2126 2126 diff -r 5918b8d165d1 -r 17d952250a9d dir/b
2127 2127 --- a/dir/b Thu Jan 01 00:00:00 1970 +0000
2128 2128 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2129 2129 @@ -1,1 +0,0 @@
2130 2130 -a
2131 2131 diff -r 5918b8d165d1 -r 17d952250a9d e
2132 2132 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2133 2133 +++ b/e Thu Jan 01 00:00:00 1970 +0000
2134 2134 @@ -0,0 +1,1 @@
2135 2135 +a
2136 2136 # HG changeset patch
2137 2137 # User test
2138 2138 # Date 0 0
2139 2139 # Thu Jan 01 00:00:00 1970 +0000
2140 2140 # Node ID 99b31f1c2782e2deb1723cef08930f70fc84b37b
2141 2141 # Parent 5918b8d165d1364e78a66d02e66caa0133c5d1ed
2142 2142 add another e
2143 2143
2144 2144 diff -r 5918b8d165d1 -r 99b31f1c2782 e
2145 2145 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2146 2146 +++ b/e Thu Jan 01 00:00:00 1970 +0000
2147 2147 @@ -0,0 +1,1 @@
2148 2148 +ee
2149 2149 # HG changeset patch
2150 2150 # User test
2151 2151 # Date 0 0
2152 2152 # Thu Jan 01 00:00:00 1970 +0000
2153 2153 # Node ID fc281d8ff18d999ad6497b3d27390bcd695dcc73
2154 2154 # Parent 99b31f1c2782e2deb1723cef08930f70fc84b37b
2155 2155 # Parent 17d952250a9d03cc3dc77b199ab60e959b9b0260
2156 2156 merge 5 and 4
2157 2157
2158 2158 diff -r 99b31f1c2782 -r fc281d8ff18d dir/b
2159 2159 --- a/dir/b Thu Jan 01 00:00:00 1970 +0000
2160 2160 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2161 2161 @@ -1,1 +0,0 @@
2162 2162 -a
2163 2163 diff -r 99b31f1c2782 -r fc281d8ff18d e
2164 2164 --- a/e Thu Jan 01 00:00:00 1970 +0000
2165 2165 +++ b/e Thu Jan 01 00:00:00 1970 +0000
2166 2166 @@ -1,1 +1,1 @@
2167 2167 -ee
2168 2168 +merge
2169 2169 # HG changeset patch
2170 2170 # User test
2171 2171 # Date 0 0
2172 2172 # Thu Jan 01 00:00:00 1970 +0000
2173 2173 # Node ID 02dbb8e276b8ab7abfd07cab50c901647e75c2dd
2174 2174 # Parent fc281d8ff18d999ad6497b3d27390bcd695dcc73
2175 2175 Added tag foo-bar for changeset fc281d8ff18d
2176 2176
2177 2177 diff -r fc281d8ff18d -r 02dbb8e276b8 .hgtags
2178 2178 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2179 2179 +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000
2180 2180 @@ -0,0 +1,1 @@
2181 2181 +fc281d8ff18d999ad6497b3d27390bcd695dcc73 foo-bar
2182 2182 # HG changeset patch
2183 2183 # User test
2184 2184 # Date 0 0
2185 2185 # Thu Jan 01 00:00:00 1970 +0000
2186 2186 # Node ID 24c2e826ddebf80f9dcd60b856bdb8e6715c5449
2187 2187 # Parent fc281d8ff18d999ad6497b3d27390bcd695dcc73
2188 2188 add g
2189 2189
2190 2190 diff -r fc281d8ff18d -r 24c2e826ddeb g
2191 2191 --- a/g Thu Jan 01 00:00:00 1970 +0000
2192 2192 +++ b/g Thu Jan 01 00:00:00 1970 +0000
2193 2193 @@ -1,2 +1,1 @@
2194 2194 -f
2195 2195 -f
2196 2196 +g
2197 2197 $ testlog --follow -r6 -r8 -r5 -r7 -r4
2198 2198 ['6', '8', '5', '7', '4']
2199 2199 (group
2200 2200 (func
2201 2201 ('symbol', 'descendants')
2202 2202 (func
2203 2203 ('symbol', 'rev')
2204 2204 ('symbol', '6'))))
2205 2205
2206 2206 Test --follow-first and forward --rev
2207 2207
2208 2208 $ testlog --follow-first -r6 -r8 -r5 -r7 -r4
2209 2209 ['6', '8', '5', '7', '4']
2210 2210 (group
2211 2211 (func
2212 2212 ('symbol', '_firstdescendants')
2213 2213 (func
2214 2214 ('symbol', 'rev')
2215 2215 ('symbol', '6'))))
2216 2216 --- log.nodes * (glob)
2217 2217 +++ glog.nodes * (glob)
2218 2218 @@ -1,3 +1,3 @@
2219 2219 -nodetag 6
2220 2220 nodetag 8
2221 2221 nodetag 7
2222 2222 +nodetag 6
2223 2223
2224 2224 Test --follow and backward --rev
2225 2225
2226 2226 $ testlog --follow -r6 -r5 -r7 -r8 -r4
2227 2227 ['6', '5', '7', '8', '4']
2228 2228 (group
2229 2229 (func
2230 2230 ('symbol', 'ancestors')
2231 2231 (func
2232 2232 ('symbol', 'rev')
2233 2233 ('symbol', '6'))))
2234 2234
2235 2235 Test --follow-first and backward --rev
2236 2236
2237 2237 $ testlog --follow-first -r6 -r5 -r7 -r8 -r4
2238 2238 ['6', '5', '7', '8', '4']
2239 2239 (group
2240 2240 (func
2241 2241 ('symbol', '_firstancestors')
2242 2242 (func
2243 2243 ('symbol', 'rev')
2244 2244 ('symbol', '6'))))
2245 2245
2246 2246 Test --follow with --rev of graphlog extension
2247 2247
2248 2248 $ hg --config extensions.graphlog= glog -qfr1
2249 2249 o 1:216d4c92cf98
2250 2250 |
2251 2251 o 0:f8035bb17114
2252 2252
2253 2253
2254 2254 Test subdir
2255 2255
2256 2256 $ hg up -q 3
2257 2257 $ cd dir
2258 2258 $ testlog .
2259 2259 []
2260 2260 (group
2261 2261 (func
2262 2262 ('symbol', '_matchfiles')
2263 2263 (list
2264 2264 (list
2265 2265 ('string', 'r:')
2266 2266 ('string', 'd:relpath'))
2267 2267 ('string', 'p:.'))))
2268 2268 $ testlog ../b
2269 2269 []
2270 2270 (group
2271 2271 (group
2272 2272 (func
2273 2273 ('symbol', 'filelog')
2274 2274 ('string', '../b'))))
2275 2275 $ testlog -f ../b
2276 2276 []
2277 2277 (group
2278 2278 (group
2279 2279 (func
2280 2280 ('symbol', 'follow')
2281 2281 ('string', 'b'))))
2282 2282 $ cd ..
2283 2283
2284 2284 Test --hidden
2285 2285 (enable obsolete)
2286 2286
2287 2287 $ cat >> $HGRCPATH << EOF
2288 2288 > [experimental]
2289 2289 > evolution=createmarkers
2290 2290 > EOF
2291 2291
2292 2292 $ hg debugobsolete `hg id --debug -i -r 8`
2293 2293 $ testlog
2294 2294 []
2295 2295 []
2296 2296 $ testlog --hidden
2297 2297 []
2298 2298 []
2299 2299 $ hg log -G --template '{rev} {desc}\n'
2300 2300 o 7 Added tag foo-bar for changeset fc281d8ff18d
2301 2301 |
2302 2302 o 6 merge 5 and 4
2303 2303 |\
2304 2304 | o 5 add another e
2305 2305 | |
2306 2306 o | 4 mv dir/b e
2307 2307 |/
2308 2308 @ 3 mv a b; add d
2309 2309 |
2310 2310 o 2 mv b dir/b
2311 2311 |
2312 2312 o 1 copy a b
2313 2313 |
2314 2314 o 0 add a
2315 2315
2316 2316
2317 2317 A template without trailing newline should do something sane
2318 2318
2319 2319 $ hg log -G -r ::2 --template '{rev} {desc}'
2320 2320 o 2 mv b dir/b
2321 2321 |
2322 2322 o 1 copy a b
2323 2323 |
2324 2324 o 0 add a
2325 2325
2326 2326
2327 2327 Extra newlines must be preserved
2328 2328
2329 2329 $ hg log -G -r ::2 --template '\n{rev} {desc}\n\n'
2330 2330 o
2331 2331 | 2 mv b dir/b
2332 2332 |
2333 2333 o
2334 2334 | 1 copy a b
2335 2335 |
2336 2336 o
2337 2337 0 add a
2338 2338
2339 2339
2340 2340 The almost-empty template should do something sane too ...
2341 2341
2342 2342 $ hg log -G -r ::2 --template '\n'
2343 2343 o
2344 2344 |
2345 2345 o
2346 2346 |
2347 2347 o
2348 2348
2349 2349
2350 2350 issue3772
2351 2351
2352 2352 $ hg log -G -r :null
2353 2353 o changeset: 0:f8035bb17114
2354 2354 | user: test
2355 2355 | date: Thu Jan 01 00:00:00 1970 +0000
2356 2356 | summary: add a
2357 2357 |
2358 2358 o changeset: -1:000000000000
2359 2359 user:
2360 2360 date: Thu Jan 01 00:00:00 1970 +0000
2361 2361
2362 2362 $ hg log -G -r null:null
2363 2363 o changeset: -1:000000000000
2364 2364 user:
2365 2365 date: Thu Jan 01 00:00:00 1970 +0000
2366 2366
2367 2367
2368 2368 should not draw line down to null due to the magic of fullreposet
2369 2369
2370 2370 $ hg log -G -r 'all()' | tail -6
2371 2371 |
2372 2372 o changeset: 0:f8035bb17114
2373 2373 user: test
2374 2374 date: Thu Jan 01 00:00:00 1970 +0000
2375 2375 summary: add a
2376 2376
2377 2377
2378 $ hg log -G -r 'branch(default)' | tail -6
2379 |
2380 o changeset: 0:f8035bb17114
2381 user: test
2382 date: Thu Jan 01 00:00:00 1970 +0000
2383 summary: add a
2384
2385
2378 2386 $ cd ..
@@ -1,697 +1,697 b''
1 1 commit hooks can see env vars
2 2 (and post-transaction one are run unlocked)
3 3
4 4 $ cat > $TESTTMP/txnabort.checkargs.py <<EOF
5 5 > def showargs(ui, repo, hooktype, **kwargs):
6 6 > ui.write('%s python hook: %s\n' % (hooktype, ','.join(sorted(kwargs))))
7 7 > EOF
8 8
9 9 $ hg init a
10 10 $ cd a
11 11 $ cat > .hg/hgrc <<EOF
12 12 > [hooks]
13 13 > commit = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" commit"
14 14 > commit.b = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" commit.b"
15 15 > precommit = sh -c "HG_LOCAL= HG_NODE= HG_TAG= python \"$TESTDIR/printenv.py\" precommit"
16 16 > pretxncommit = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" pretxncommit"
17 17 > pretxncommit.tip = hg -q tip
18 18 > pre-identify = python "$TESTDIR/printenv.py" pre-identify 1
19 19 > pre-cat = python "$TESTDIR/printenv.py" pre-cat
20 20 > post-cat = python "$TESTDIR/printenv.py" post-cat
21 21 > pretxnopen = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" pretxnopen"
22 22 > pretxnclose = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" pretxnclose"
23 23 > txnclose = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" txnclose"
24 24 > txnabort.0 = python:$TESTTMP/txnabort.checkargs.py:showargs
25 25 > txnabort.1 = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" txnabort"
26 26 > txnclose.checklock = sh -c "hg debuglock > /dev/null"
27 27 > EOF
28 28 $ echo a > a
29 29 $ hg add a
30 30 $ hg commit -m a
31 31 precommit hook: HG_PARENT1=0000000000000000000000000000000000000000
32 pretxnopen hook: HG_TXNNAME=commit
32 pretxnopen hook: HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
33 33 pretxncommit hook: HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000 HG_PENDING=$TESTTMP/a
34 34 0:cb9a9f314b8b
35 35 pretxnclose hook: HG_PENDING=$TESTTMP/a HG_PHASES_MOVED=1 HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
36 36 txnclose hook: HG_PHASES_MOVED=1 HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
37 37 commit hook: HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000
38 38 commit.b hook: HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000
39 39
40 40 $ hg clone . ../b
41 41 updating to branch default
42 42 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
43 43 $ cd ../b
44 44
45 45 changegroup hooks can see env vars
46 46
47 47 $ cat > .hg/hgrc <<EOF
48 48 > [hooks]
49 49 > prechangegroup = python "$TESTDIR/printenv.py" prechangegroup
50 50 > changegroup = python "$TESTDIR/printenv.py" changegroup
51 51 > incoming = python "$TESTDIR/printenv.py" incoming
52 52 > EOF
53 53
54 54 pretxncommit and commit hooks can see both parents of merge
55 55
56 56 $ cd ../a
57 57 $ echo b >> a
58 58 $ hg commit -m a1 -d "1 0"
59 59 precommit hook: HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
60 pretxnopen hook: HG_TXNNAME=commit
60 pretxnopen hook: HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
61 61 pretxncommit hook: HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PENDING=$TESTTMP/a
62 62 1:ab228980c14d
63 63 pretxnclose hook: HG_PENDING=$TESTTMP/a HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
64 64 txnclose hook: HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
65 65 commit hook: HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
66 66 commit.b hook: HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
67 67 $ hg update -C 0
68 68 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
69 69 $ echo b > b
70 70 $ hg add b
71 71 $ hg commit -m b -d '1 0'
72 72 precommit hook: HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
73 pretxnopen hook: HG_TXNNAME=commit
73 pretxnopen hook: HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
74 74 pretxncommit hook: HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PENDING=$TESTTMP/a
75 75 2:ee9deb46ab31
76 76 pretxnclose hook: HG_PENDING=$TESTTMP/a HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
77 77 txnclose hook: HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
78 78 commit hook: HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
79 79 commit.b hook: HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
80 80 created new head
81 81 $ hg merge 1
82 82 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
83 83 (branch merge, don't forget to commit)
84 84 $ hg commit -m merge -d '2 0'
85 85 precommit hook: HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
86 pretxnopen hook: HG_TXNNAME=commit
86 pretxnopen hook: HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
87 87 pretxncommit hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd HG_PENDING=$TESTTMP/a
88 88 3:07f3376c1e65
89 89 pretxnclose hook: HG_PENDING=$TESTTMP/a HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
90 90 txnclose hook: HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
91 91 commit hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
92 92 commit.b hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
93 93
94 94 test generic hooks
95 95
96 96 $ hg id
97 97 pre-identify hook: HG_ARGS=id HG_OPTS={'bookmarks': None, 'branch': None, 'id': None, 'insecure': None, 'num': None, 'remotecmd': '', 'rev': '', 'ssh': '', 'tags': None} HG_PATS=[]
98 98 abort: pre-identify hook exited with status 1
99 99 [255]
100 100 $ hg cat b
101 101 pre-cat hook: HG_ARGS=cat b HG_OPTS={'decode': None, 'exclude': [], 'include': [], 'output': '', 'rev': ''} HG_PATS=['b']
102 102 b
103 103 post-cat hook: HG_ARGS=cat b HG_OPTS={'decode': None, 'exclude': [], 'include': [], 'output': '', 'rev': ''} HG_PATS=['b'] HG_RESULT=0
104 104
105 105 $ cd ../b
106 106 $ hg pull ../a
107 107 pulling from ../a
108 108 searching for changes
109 109 prechangegroup hook: HG_SOURCE=pull HG_TXNID=TXN:* HG_URL=file:$TESTTMP/a (glob)
110 110 adding changesets
111 111 adding manifests
112 112 adding file changes
113 113 added 3 changesets with 2 changes to 2 files
114 114 changegroup hook: HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_SOURCE=pull HG_TXNID=TXN:* HG_URL=file:$TESTTMP/a (glob)
115 115 incoming hook: HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_SOURCE=pull HG_TXNID=TXN:* HG_URL=file:$TESTTMP/a (glob)
116 116 incoming hook: HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_SOURCE=pull HG_TXNID=TXN:* HG_URL=file:$TESTTMP/a (glob)
117 117 incoming hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_SOURCE=pull HG_TXNID=TXN:* HG_URL=file:$TESTTMP/a (glob)
118 118 (run 'hg update' to get a working copy)
119 119
120 120 tag hooks can see env vars
121 121
122 122 $ cd ../a
123 123 $ cat >> .hg/hgrc <<EOF
124 124 > pretag = python "$TESTDIR/printenv.py" pretag
125 125 > tag = sh -c "HG_PARENT1= HG_PARENT2= python \"$TESTDIR/printenv.py\" tag"
126 126 > EOF
127 127 $ hg tag -d '3 0' a
128 128 pretag hook: HG_LOCAL=0 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_TAG=a
129 129 precommit hook: HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
130 pretxnopen hook: HG_TXNNAME=commit
130 pretxnopen hook: HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
131 131 pretxncommit hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PENDING=$TESTTMP/a
132 132 4:539e4b31b6dc
133 133 pretxnclose hook: HG_PENDING=$TESTTMP/a HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
134 134 tag hook: HG_LOCAL=0 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_TAG=a
135 135 txnclose hook: HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
136 136 commit hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
137 137 commit.b hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
138 138 $ hg tag -l la
139 139 pretag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la
140 140 tag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la
141 141
142 142 pretag hook can forbid tagging
143 143
144 144 $ echo "pretag.forbid = python \"$TESTDIR/printenv.py\" pretag.forbid 1" >> .hg/hgrc
145 145 $ hg tag -d '4 0' fa
146 146 pretag hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa
147 147 pretag.forbid hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa
148 148 abort: pretag.forbid hook exited with status 1
149 149 [255]
150 150 $ hg tag -l fla
151 151 pretag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fla
152 152 pretag.forbid hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fla
153 153 abort: pretag.forbid hook exited with status 1
154 154 [255]
155 155
156 156 pretxncommit hook can see changeset, can roll back txn, changeset no
157 157 more there after
158 158
159 159 $ echo "pretxncommit.forbid0 = hg tip -q" >> .hg/hgrc
160 160 $ echo "pretxncommit.forbid1 = python \"$TESTDIR/printenv.py\" pretxncommit.forbid 1" >> .hg/hgrc
161 161 $ echo z > z
162 162 $ hg add z
163 163 $ hg -q tip
164 164 4:539e4b31b6dc
165 165 $ hg commit -m 'fail' -d '4 0'
166 166 precommit hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
167 pretxnopen hook: HG_TXNNAME=commit
167 pretxnopen hook: HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
168 168 pretxncommit hook: HG_NODE=6f611f8018c10e827fee6bd2bc807f937e761567 HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PENDING=$TESTTMP/a
169 169 5:6f611f8018c1
170 170 5:6f611f8018c1
171 171 pretxncommit.forbid hook: HG_NODE=6f611f8018c10e827fee6bd2bc807f937e761567 HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PENDING=$TESTTMP/a
172 172 transaction abort!
173 173 txnabort python hook: txnid,txnname
174 174 txnabort hook: HG_TXNID=TXN:* HG_TXNNAME=commit (glob)
175 175 rollback completed
176 176 abort: pretxncommit.forbid1 hook exited with status 1
177 177 [255]
178 178 $ hg -q tip
179 179 4:539e4b31b6dc
180 180
181 181 (Check that no 'changelog.i.a' file were left behind)
182 182
183 183 $ ls -1 .hg/store/
184 184 00changelog.i
185 185 00manifest.i
186 186 data
187 187 fncache
188 188 journal.phaseroots
189 189 phaseroots
190 190 undo
191 191 undo.backup.fncache
192 192 undo.backupfiles
193 193 undo.phaseroots
194 194
195 195
196 196 precommit hook can prevent commit
197 197
198 198 $ echo "precommit.forbid = python \"$TESTDIR/printenv.py\" precommit.forbid 1" >> .hg/hgrc
199 199 $ hg commit -m 'fail' -d '4 0'
200 200 precommit hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
201 201 precommit.forbid hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
202 202 abort: precommit.forbid hook exited with status 1
203 203 [255]
204 204 $ hg -q tip
205 205 4:539e4b31b6dc
206 206
207 207 preupdate hook can prevent update
208 208
209 209 $ echo "preupdate = python \"$TESTDIR/printenv.py\" preupdate" >> .hg/hgrc
210 210 $ hg update 1
211 211 preupdate hook: HG_PARENT1=ab228980c14d
212 212 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
213 213
214 214 update hook
215 215
216 216 $ echo "update = python \"$TESTDIR/printenv.py\" update" >> .hg/hgrc
217 217 $ hg update
218 218 preupdate hook: HG_PARENT1=539e4b31b6dc
219 219 update hook: HG_ERROR=0 HG_PARENT1=539e4b31b6dc
220 220 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
221 221
222 222 pushkey hook
223 223
224 224 $ echo "pushkey = python \"$TESTDIR/printenv.py\" pushkey" >> .hg/hgrc
225 225 $ cd ../b
226 226 $ hg bookmark -r null foo
227 227 $ hg push -B foo ../a
228 228 pushing to ../a
229 229 searching for changes
230 230 no changes found
231 pretxnopen hook: HG_TXNNAME=bookmarks
231 pretxnopen hook: HG_TXNID=TXN:* HG_TXNNAME=bookmarks (glob)
232 232 pretxnclose hook: HG_BOOKMARK_MOVED=1 HG_PENDING=$TESTTMP/a HG_TXNID=TXN:* HG_TXNNAME=bookmarks (glob)
233 233 txnclose hook: HG_BOOKMARK_MOVED=1 HG_TXNID=TXN:* HG_TXNNAME=bookmarks (glob)
234 234 pushkey hook: HG_KEY=foo HG_NAMESPACE=bookmarks HG_NEW=0000000000000000000000000000000000000000 HG_RET=1
235 235 exporting bookmark foo
236 236 [1]
237 237 $ cd ../a
238 238
239 239 listkeys hook
240 240
241 241 $ echo "listkeys = python \"$TESTDIR/printenv.py\" listkeys" >> .hg/hgrc
242 242 $ hg bookmark -r null bar
243 243 $ cd ../b
244 244 $ hg pull -B bar ../a
245 245 pulling from ../a
246 246 listkeys hook: HG_NAMESPACE=bookmarks HG_VALUES={'bar': '0000000000000000000000000000000000000000', 'foo': '0000000000000000000000000000000000000000'}
247 247 listkeys hook: HG_NAMESPACE=bookmarks HG_VALUES={'bar': '0000000000000000000000000000000000000000', 'foo': '0000000000000000000000000000000000000000'}
248 248 no changes found
249 249 listkeys hook: HG_NAMESPACE=phases HG_VALUES={'cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b': '1', 'publishing': 'True'}
250 250 adding remote bookmark bar
251 251 $ cd ../a
252 252
253 253 test that prepushkey can prevent incoming keys
254 254
255 255 $ echo "prepushkey = python \"$TESTDIR/printenv.py\" prepushkey.forbid 1" >> .hg/hgrc
256 256 $ cd ../b
257 257 $ hg bookmark -r null baz
258 258 $ hg push -B baz ../a
259 259 pushing to ../a
260 260 searching for changes
261 261 listkeys hook: HG_NAMESPACE=phases HG_VALUES={'cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b': '1', 'publishing': 'True'}
262 262 listkeys hook: HG_NAMESPACE=bookmarks HG_VALUES={'bar': '0000000000000000000000000000000000000000', 'foo': '0000000000000000000000000000000000000000'}
263 263 no changes found
264 264 listkeys hook: HG_NAMESPACE=phases HG_VALUES={'cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b': '1', 'publishing': 'True'}
265 265 prepushkey.forbid hook: HG_KEY=baz HG_NAMESPACE=bookmarks HG_NEW=0000000000000000000000000000000000000000
266 266 pushkey-abort: prepushkey hook exited with status 1
267 267 exporting bookmark baz failed!
268 268 [1]
269 269 $ cd ../a
270 270
271 271 test that prelistkeys can prevent listing keys
272 272
273 273 $ echo "prelistkeys = python \"$TESTDIR/printenv.py\" prelistkeys.forbid 1" >> .hg/hgrc
274 274 $ hg bookmark -r null quux
275 275 $ cd ../b
276 276 $ hg pull -B quux ../a
277 277 pulling from ../a
278 278 prelistkeys.forbid hook: HG_NAMESPACE=bookmarks
279 279 abort: prelistkeys hook exited with status 1
280 280 [255]
281 281 $ cd ../a
282 282 $ rm .hg/hgrc
283 283
284 284 prechangegroup hook can prevent incoming changes
285 285
286 286 $ cd ../b
287 287 $ hg -q tip
288 288 3:07f3376c1e65
289 289 $ cat > .hg/hgrc <<EOF
290 290 > [hooks]
291 291 > prechangegroup.forbid = python "$TESTDIR/printenv.py" prechangegroup.forbid 1
292 292 > EOF
293 293 $ hg pull ../a
294 294 pulling from ../a
295 295 searching for changes
296 296 prechangegroup.forbid hook: HG_SOURCE=pull HG_TXNID=TXN:* HG_URL=file:$TESTTMP/a (glob)
297 297 abort: prechangegroup.forbid hook exited with status 1
298 298 [255]
299 299
300 300 pretxnchangegroup hook can see incoming changes, can roll back txn,
301 301 incoming changes no longer there after
302 302
303 303 $ cat > .hg/hgrc <<EOF
304 304 > [hooks]
305 305 > pretxnchangegroup.forbid0 = hg tip -q
306 306 > pretxnchangegroup.forbid1 = python "$TESTDIR/printenv.py" pretxnchangegroup.forbid 1
307 307 > EOF
308 308 $ hg pull ../a
309 309 pulling from ../a
310 310 searching for changes
311 311 adding changesets
312 312 adding manifests
313 313 adding file changes
314 314 added 1 changesets with 1 changes to 1 files
315 315 4:539e4b31b6dc
316 316 pretxnchangegroup.forbid hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PENDING=$TESTTMP/b HG_SOURCE=pull HG_TXNID=TXN:* HG_URL=file:$TESTTMP/a (glob)
317 317 transaction abort!
318 318 rollback completed
319 319 abort: pretxnchangegroup.forbid1 hook exited with status 1
320 320 [255]
321 321 $ hg -q tip
322 322 3:07f3376c1e65
323 323
324 324 outgoing hooks can see env vars
325 325
326 326 $ rm .hg/hgrc
327 327 $ cat > ../a/.hg/hgrc <<EOF
328 328 > [hooks]
329 329 > preoutgoing = python "$TESTDIR/printenv.py" preoutgoing
330 330 > outgoing = python "$TESTDIR/printenv.py" outgoing
331 331 > EOF
332 332 $ hg pull ../a
333 333 pulling from ../a
334 334 searching for changes
335 335 preoutgoing hook: HG_SOURCE=pull
336 336 adding changesets
337 337 outgoing hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_SOURCE=pull
338 338 adding manifests
339 339 adding file changes
340 340 added 1 changesets with 1 changes to 1 files
341 341 adding remote bookmark quux
342 342 (run 'hg update' to get a working copy)
343 343 $ hg rollback
344 344 repository tip rolled back to revision 3 (undo pull)
345 345
346 346 preoutgoing hook can prevent outgoing changes
347 347
348 348 $ echo "preoutgoing.forbid = python \"$TESTDIR/printenv.py\" preoutgoing.forbid 1" >> ../a/.hg/hgrc
349 349 $ hg pull ../a
350 350 pulling from ../a
351 351 searching for changes
352 352 preoutgoing hook: HG_SOURCE=pull
353 353 preoutgoing.forbid hook: HG_SOURCE=pull
354 354 abort: preoutgoing.forbid hook exited with status 1
355 355 [255]
356 356
357 357 outgoing hooks work for local clones
358 358
359 359 $ cd ..
360 360 $ cat > a/.hg/hgrc <<EOF
361 361 > [hooks]
362 362 > preoutgoing = python "$TESTDIR/printenv.py" preoutgoing
363 363 > outgoing = python "$TESTDIR/printenv.py" outgoing
364 364 > EOF
365 365 $ hg clone a c
366 366 preoutgoing hook: HG_SOURCE=clone
367 367 outgoing hook: HG_NODE=0000000000000000000000000000000000000000 HG_SOURCE=clone
368 368 updating to branch default
369 369 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
370 370 $ rm -rf c
371 371
372 372 preoutgoing hook can prevent outgoing changes for local clones
373 373
374 374 $ echo "preoutgoing.forbid = python \"$TESTDIR/printenv.py\" preoutgoing.forbid 1" >> a/.hg/hgrc
375 375 $ hg clone a zzz
376 376 preoutgoing hook: HG_SOURCE=clone
377 377 preoutgoing.forbid hook: HG_SOURCE=clone
378 378 abort: preoutgoing.forbid hook exited with status 1
379 379 [255]
380 380
381 381 $ cd "$TESTTMP/b"
382 382
383 383 $ cat > hooktests.py <<EOF
384 384 > from mercurial import util
385 385 >
386 386 > uncallable = 0
387 387 >
388 388 > def printargs(args):
389 389 > args.pop('ui', None)
390 390 > args.pop('repo', None)
391 391 > a = list(args.items())
392 392 > a.sort()
393 393 > print 'hook args:'
394 394 > for k, v in a:
395 395 > print ' ', k, v
396 396 >
397 397 > def passhook(**args):
398 398 > printargs(args)
399 399 >
400 400 > def failhook(**args):
401 401 > printargs(args)
402 402 > return True
403 403 >
404 404 > class LocalException(Exception):
405 405 > pass
406 406 >
407 407 > def raisehook(**args):
408 408 > raise LocalException('exception from hook')
409 409 >
410 410 > def aborthook(**args):
411 411 > raise util.Abort('raise abort from hook')
412 412 >
413 413 > def brokenhook(**args):
414 414 > return 1 + {}
415 415 >
416 416 > def verbosehook(ui, **args):
417 417 > ui.note('verbose output from hook\n')
418 418 >
419 419 > def printtags(ui, repo, **args):
420 420 > print sorted(repo.tags())
421 421 >
422 422 > class container:
423 423 > unreachable = 1
424 424 > EOF
425 425
426 426 test python hooks
427 427
428 428 #if windows
429 429 $ PYTHONPATH="$TESTTMP/b;$PYTHONPATH"
430 430 #else
431 431 $ PYTHONPATH="$TESTTMP/b:$PYTHONPATH"
432 432 #endif
433 433 $ export PYTHONPATH
434 434
435 435 $ echo '[hooks]' > ../a/.hg/hgrc
436 436 $ echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc
437 437 $ hg pull ../a 2>&1 | grep 'raised an exception'
438 438 error: preoutgoing.broken hook raised an exception: unsupported operand type(s) for +: 'int' and 'dict'
439 439
440 440 $ echo '[hooks]' > ../a/.hg/hgrc
441 441 $ echo 'preoutgoing.raise = python:hooktests.raisehook' >> ../a/.hg/hgrc
442 442 $ hg pull ../a 2>&1 | grep 'raised an exception'
443 443 error: preoutgoing.raise hook raised an exception: exception from hook
444 444
445 445 $ echo '[hooks]' > ../a/.hg/hgrc
446 446 $ echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../a/.hg/hgrc
447 447 $ hg pull ../a
448 448 pulling from ../a
449 449 searching for changes
450 450 error: preoutgoing.abort hook failed: raise abort from hook
451 451 abort: raise abort from hook
452 452 [255]
453 453
454 454 $ echo '[hooks]' > ../a/.hg/hgrc
455 455 $ echo 'preoutgoing.fail = python:hooktests.failhook' >> ../a/.hg/hgrc
456 456 $ hg pull ../a
457 457 pulling from ../a
458 458 searching for changes
459 459 hook args:
460 460 hooktype preoutgoing
461 461 source pull
462 462 abort: preoutgoing.fail hook failed
463 463 [255]
464 464
465 465 $ echo '[hooks]' > ../a/.hg/hgrc
466 466 $ echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc
467 467 $ hg pull ../a
468 468 pulling from ../a
469 469 searching for changes
470 470 abort: preoutgoing.uncallable hook is invalid ("hooktests.uncallable" is not callable)
471 471 [255]
472 472
473 473 $ echo '[hooks]' > ../a/.hg/hgrc
474 474 $ echo 'preoutgoing.nohook = python:hooktests.nohook' >> ../a/.hg/hgrc
475 475 $ hg pull ../a
476 476 pulling from ../a
477 477 searching for changes
478 478 abort: preoutgoing.nohook hook is invalid ("hooktests.nohook" is not defined)
479 479 [255]
480 480
481 481 $ echo '[hooks]' > ../a/.hg/hgrc
482 482 $ echo 'preoutgoing.nomodule = python:nomodule' >> ../a/.hg/hgrc
483 483 $ hg pull ../a
484 484 pulling from ../a
485 485 searching for changes
486 486 abort: preoutgoing.nomodule hook is invalid ("nomodule" not in a module)
487 487 [255]
488 488
489 489 $ echo '[hooks]' > ../a/.hg/hgrc
490 490 $ echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc
491 491 $ hg pull ../a
492 492 pulling from ../a
493 493 searching for changes
494 494 abort: preoutgoing.badmodule hook is invalid (import of "nomodule" failed)
495 495 [255]
496 496
497 497 $ echo '[hooks]' > ../a/.hg/hgrc
498 498 $ echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc
499 499 $ hg pull ../a
500 500 pulling from ../a
501 501 searching for changes
502 502 abort: preoutgoing.unreachable hook is invalid (import of "hooktests.container" failed)
503 503 [255]
504 504
505 505 $ echo '[hooks]' > ../a/.hg/hgrc
506 506 $ echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc
507 507 $ hg pull ../a
508 508 pulling from ../a
509 509 searching for changes
510 510 hook args:
511 511 hooktype preoutgoing
512 512 source pull
513 513 adding changesets
514 514 adding manifests
515 515 adding file changes
516 516 added 1 changesets with 1 changes to 1 files
517 517 adding remote bookmark quux
518 518 (run 'hg update' to get a working copy)
519 519
520 520 make sure --traceback works
521 521
522 522 $ echo '[hooks]' > .hg/hgrc
523 523 $ echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc
524 524
525 525 $ echo aa > a
526 526 $ hg --traceback commit -d '0 0' -ma 2>&1 | grep '^Traceback'
527 527 Traceback (most recent call last):
528 528
529 529 $ cd ..
530 530 $ hg init c
531 531 $ cd c
532 532
533 533 $ cat > hookext.py <<EOF
534 534 > def autohook(**args):
535 535 > print "Automatically installed hook"
536 536 >
537 537 > def reposetup(ui, repo):
538 538 > repo.ui.setconfig("hooks", "commit.auto", autohook)
539 539 > EOF
540 540 $ echo '[extensions]' >> .hg/hgrc
541 541 $ echo 'hookext = hookext.py' >> .hg/hgrc
542 542
543 543 $ touch foo
544 544 $ hg add foo
545 545 $ hg ci -d '0 0' -m 'add foo'
546 546 Automatically installed hook
547 547 $ echo >> foo
548 548 $ hg ci --debug -d '0 0' -m 'change foo'
549 549 committing files:
550 550 foo
551 551 committing manifest
552 552 committing changelog
553 553 calling hook commit.auto: hgext_hookext.autohook
554 554 Automatically installed hook
555 555 committed changeset 1:52998019f6252a2b893452765fcb0a47351a5708
556 556
557 557 $ hg showconfig hooks
558 558 hooks.commit.auto=<function autohook at *> (glob)
559 559
560 560 test python hook configured with python:[file]:[hook] syntax
561 561
562 562 $ cd ..
563 563 $ mkdir d
564 564 $ cd d
565 565 $ hg init repo
566 566 $ mkdir hooks
567 567
568 568 $ cd hooks
569 569 $ cat > testhooks.py <<EOF
570 570 > def testhook(**args):
571 571 > print 'hook works'
572 572 > EOF
573 573 $ echo '[hooks]' > ../repo/.hg/hgrc
574 574 $ echo "pre-commit.test = python:`pwd`/testhooks.py:testhook" >> ../repo/.hg/hgrc
575 575
576 576 $ cd ../repo
577 577 $ hg commit -d '0 0'
578 578 hook works
579 579 nothing changed
580 580 [1]
581 581
582 582 $ echo '[hooks]' > .hg/hgrc
583 583 $ echo "update.ne = python:`pwd`/nonexistent.py:testhook" >> .hg/hgrc
584 584 $ echo "pre-identify.npmd = python:`pwd`/:no_python_module_dir" >> .hg/hgrc
585 585
586 586 $ hg up null
587 587 loading update.ne hook failed:
588 588 abort: No such file or directory: $TESTTMP/d/repo/nonexistent.py
589 589 [255]
590 590
591 591 $ hg id
592 592 loading pre-identify.npmd hook failed:
593 593 abort: No module named repo!
594 594 [255]
595 595
596 596 $ cd ../../b
597 597
598 598 make sure --traceback works on hook import failure
599 599
600 600 $ cat > importfail.py <<EOF
601 601 > import somebogusmodule
602 602 > # dereference something in the module to force demandimport to load it
603 603 > somebogusmodule.whatever
604 604 > EOF
605 605
606 606 $ echo '[hooks]' > .hg/hgrc
607 607 $ echo 'precommit.importfail = python:importfail.whatever' >> .hg/hgrc
608 608
609 609 $ echo a >> a
610 610 $ hg --traceback commit -ma 2>&1 | egrep -v '^( +File| [a-zA-Z(])'
611 611 exception from first failed import attempt:
612 612 Traceback (most recent call last):
613 613 ImportError: No module named somebogusmodule
614 614 exception from second failed import attempt:
615 615 Traceback (most recent call last):
616 616 ImportError: No module named hgext_importfail
617 617 Traceback (most recent call last):
618 618 Abort: precommit.importfail hook is invalid (import of "importfail" failed)
619 619 abort: precommit.importfail hook is invalid (import of "importfail" failed)
620 620
621 621 Issue1827: Hooks Update & Commit not completely post operation
622 622
623 623 commit and update hooks should run after command completion. The largefiles
624 624 use demonstrates a recursive wlock, showing the hook doesn't run until the
625 625 final release (and dirstate flush).
626 626
627 627 $ echo '[hooks]' > .hg/hgrc
628 628 $ echo 'commit = hg id' >> .hg/hgrc
629 629 $ echo 'update = hg id' >> .hg/hgrc
630 630 $ echo bb > a
631 631 $ hg ci -ma
632 632 223eafe2750c tip
633 633 $ hg up 0 --config extensions.largefiles=
634 634 cb9a9f314b8b
635 635 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
636 636
637 637 make sure --verbose (and --quiet/--debug etc.) are propagated to the local ui
638 638 that is passed to pre/post hooks
639 639
640 640 $ echo '[hooks]' > .hg/hgrc
641 641 $ echo 'pre-identify = python:hooktests.verbosehook' >> .hg/hgrc
642 642 $ hg id
643 643 cb9a9f314b8b
644 644 $ hg id --verbose
645 645 calling hook pre-identify: hooktests.verbosehook
646 646 verbose output from hook
647 647 cb9a9f314b8b
648 648
649 649 Ensure hooks can be prioritized
650 650
651 651 $ echo '[hooks]' > .hg/hgrc
652 652 $ echo 'pre-identify.a = python:hooktests.verbosehook' >> .hg/hgrc
653 653 $ echo 'pre-identify.b = python:hooktests.verbosehook' >> .hg/hgrc
654 654 $ echo 'priority.pre-identify.b = 1' >> .hg/hgrc
655 655 $ echo 'pre-identify.c = python:hooktests.verbosehook' >> .hg/hgrc
656 656 $ hg id --verbose
657 657 calling hook pre-identify.b: hooktests.verbosehook
658 658 verbose output from hook
659 659 calling hook pre-identify.a: hooktests.verbosehook
660 660 verbose output from hook
661 661 calling hook pre-identify.c: hooktests.verbosehook
662 662 verbose output from hook
663 663 cb9a9f314b8b
664 664
665 665 new tags must be visible in pretxncommit (issue3210)
666 666
667 667 $ echo 'pretxncommit.printtags = python:hooktests.printtags' >> .hg/hgrc
668 668 $ hg tag -f foo
669 669 ['a', 'foo', 'tip']
670 670
671 671 new commits must be visible in pretxnchangegroup (issue3428)
672 672
673 673 $ cd ..
674 674 $ hg init to
675 675 $ echo '[hooks]' >> to/.hg/hgrc
676 676 $ echo 'pretxnchangegroup = hg --traceback tip' >> to/.hg/hgrc
677 677 $ echo a >> to/a
678 678 $ hg --cwd to ci -Ama
679 679 adding a
680 680 $ hg clone to from
681 681 updating to branch default
682 682 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
683 683 $ echo aa >> from/a
684 684 $ hg --cwd from ci -mb
685 685 $ hg --cwd from push
686 686 pushing to $TESTTMP/to (glob)
687 687 searching for changes
688 688 adding changesets
689 689 adding manifests
690 690 adding file changes
691 691 added 1 changesets with 1 changes to 1 files
692 692 changeset: 1:9836a07b9b9d
693 693 tag: tip
694 694 user: test
695 695 date: Thu Jan 01 00:00:00 1970 +0000
696 696 summary: b
697 697
@@ -1,1764 +1,1804 b''
1 1 $ HGENCODING=utf-8
2 2 $ export HGENCODING
3 3 $ cat > testrevset.py << EOF
4 4 > import mercurial.revset
5 5 >
6 6 > baseset = mercurial.revset.baseset
7 7 >
8 8 > def r3232(repo, subset, x):
9 9 > """"simple revset that return [3,2,3,2]
10 10 >
11 11 > revisions duplicated on purpose.
12 12 > """
13 13 > if 3 not in subset:
14 14 > if 2 in subset:
15 15 > return baseset([2,2])
16 16 > return baseset()
17 17 > return baseset([3,3,2,2])
18 18 >
19 19 > mercurial.revset.symbols['r3232'] = r3232
20 20 > EOF
21 21 $ cat >> $HGRCPATH << EOF
22 22 > [extensions]
23 23 > testrevset=$TESTTMP/testrevset.py
24 24 > EOF
25 25
26 26 $ try() {
27 27 > hg debugrevspec --debug "$@"
28 28 > }
29 29
30 30 $ log() {
31 31 > hg log --template '{rev}\n' -r "$1"
32 32 > }
33 33
34 34 $ hg init repo
35 35 $ cd repo
36 36
37 37 $ echo a > a
38 38 $ hg branch a
39 39 marked working directory as branch a
40 40 (branches are permanent and global, did you want a bookmark?)
41 41 $ hg ci -Aqm0
42 42
43 43 $ echo b > b
44 44 $ hg branch b
45 45 marked working directory as branch b
46 46 (branches are permanent and global, did you want a bookmark?)
47 47 $ hg ci -Aqm1
48 48
49 49 $ rm a
50 50 $ hg branch a-b-c-
51 51 marked working directory as branch a-b-c-
52 52 (branches are permanent and global, did you want a bookmark?)
53 53 $ hg ci -Aqm2 -u Bob
54 54
55 55 $ hg log -r "extra('branch', 'a-b-c-')" --template '{rev}\n'
56 56 2
57 57 $ hg log -r "extra('branch')" --template '{rev}\n'
58 58 0
59 59 1
60 60 2
61 61 $ hg log -r "extra('branch', 're:a')" --template '{rev} {branch}\n'
62 62 0 a
63 63 2 a-b-c-
64 64
65 65 $ hg co 1
66 66 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
67 67 $ hg branch +a+b+c+
68 68 marked working directory as branch +a+b+c+
69 69 (branches are permanent and global, did you want a bookmark?)
70 70 $ hg ci -Aqm3
71 71
72 72 $ hg co 2 # interleave
73 73 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
74 74 $ echo bb > b
75 75 $ hg branch -- -a-b-c-
76 76 marked working directory as branch -a-b-c-
77 77 (branches are permanent and global, did you want a bookmark?)
78 78 $ hg ci -Aqm4 -d "May 12 2005"
79 79
80 80 $ hg co 3
81 81 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
82 82 $ hg branch !a/b/c/
83 83 marked working directory as branch !a/b/c/
84 84 (branches are permanent and global, did you want a bookmark?)
85 85 $ hg ci -Aqm"5 bug"
86 86
87 87 $ hg merge 4
88 88 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
89 89 (branch merge, don't forget to commit)
90 90 $ hg branch _a_b_c_
91 91 marked working directory as branch _a_b_c_
92 92 (branches are permanent and global, did you want a bookmark?)
93 93 $ hg ci -Aqm"6 issue619"
94 94
95 95 $ hg branch .a.b.c.
96 96 marked working directory as branch .a.b.c.
97 97 (branches are permanent and global, did you want a bookmark?)
98 98 $ hg ci -Aqm7
99 99
100 100 $ hg branch all
101 101 marked working directory as branch all
102 102 (branches are permanent and global, did you want a bookmark?)
103 103
104 104 $ hg co 4
105 105 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
106 106 $ hg branch Γ©
107 107 marked working directory as branch \xc3\xa9 (esc)
108 108 (branches are permanent and global, did you want a bookmark?)
109 109 $ hg ci -Aqm9
110 110
111 111 $ hg tag -r6 1.0
112 112 $ hg bookmark -r6 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
113 113
114 114 $ hg clone --quiet -U -r 7 . ../remote1
115 115 $ hg clone --quiet -U -r 8 . ../remote2
116 116 $ echo "[paths]" >> .hg/hgrc
117 117 $ echo "default = ../remote1" >> .hg/hgrc
118 118
119 119 trivial
120 120
121 121 $ try 0:1
122 122 (range
123 123 ('symbol', '0')
124 124 ('symbol', '1'))
125 125 * set:
126 126 <spanset+ 0:1>
127 127 0
128 128 1
129 129 $ try 3::6
130 130 (dagrange
131 131 ('symbol', '3')
132 132 ('symbol', '6'))
133 133 * set:
134 134 <baseset [3, 5, 6]>
135 135 3
136 136 5
137 137 6
138 138 $ try '0|1|2'
139 139 (or
140 140 (or
141 141 ('symbol', '0')
142 142 ('symbol', '1'))
143 143 ('symbol', '2'))
144 144 * set:
145 145 <addset
146 146 <addset
147 147 <baseset [0]>,
148 148 <baseset [1]>>,
149 149 <baseset [2]>>
150 150 0
151 151 1
152 152 2
153 153
154 154 names that should work without quoting
155 155
156 156 $ try a
157 157 ('symbol', 'a')
158 158 * set:
159 159 <baseset [0]>
160 160 0
161 161 $ try b-a
162 162 (minus
163 163 ('symbol', 'b')
164 164 ('symbol', 'a'))
165 165 * set:
166 166 <filteredset
167 167 <baseset [1]>>
168 168 1
169 169 $ try _a_b_c_
170 170 ('symbol', '_a_b_c_')
171 171 * set:
172 172 <baseset [6]>
173 173 6
174 174 $ try _a_b_c_-a
175 175 (minus
176 176 ('symbol', '_a_b_c_')
177 177 ('symbol', 'a'))
178 178 * set:
179 179 <filteredset
180 180 <baseset [6]>>
181 181 6
182 182 $ try .a.b.c.
183 183 ('symbol', '.a.b.c.')
184 184 * set:
185 185 <baseset [7]>
186 186 7
187 187 $ try .a.b.c.-a
188 188 (minus
189 189 ('symbol', '.a.b.c.')
190 190 ('symbol', 'a'))
191 191 * set:
192 192 <filteredset
193 193 <baseset [7]>>
194 194 7
195 195 $ try -- '-a-b-c-' # complains
196 196 hg: parse error at 7: not a prefix: end
197 197 [255]
198 198 $ log -a-b-c- # succeeds with fallback
199 199 4
200 200
201 201 $ try -- -a-b-c--a # complains
202 202 (minus
203 203 (minus
204 204 (minus
205 205 (negate
206 206 ('symbol', 'a'))
207 207 ('symbol', 'b'))
208 208 ('symbol', 'c'))
209 209 (negate
210 210 ('symbol', 'a')))
211 211 abort: unknown revision '-a'!
212 212 [255]
213 213 $ try Γ©
214 214 ('symbol', '\xc3\xa9')
215 215 * set:
216 216 <baseset [9]>
217 217 9
218 218
219 219 no quoting needed
220 220
221 221 $ log ::a-b-c-
222 222 0
223 223 1
224 224 2
225 225
226 226 quoting needed
227 227
228 228 $ try '"-a-b-c-"-a'
229 229 (minus
230 230 ('string', '-a-b-c-')
231 231 ('symbol', 'a'))
232 232 * set:
233 233 <filteredset
234 234 <baseset [4]>>
235 235 4
236 236
237 237 $ log '1 or 2'
238 238 1
239 239 2
240 240 $ log '1|2'
241 241 1
242 242 2
243 243 $ log '1 and 2'
244 244 $ log '1&2'
245 245 $ try '1&2|3' # precedence - and is higher
246 246 (or
247 247 (and
248 248 ('symbol', '1')
249 249 ('symbol', '2'))
250 250 ('symbol', '3'))
251 251 * set:
252 252 <addset
253 253 <baseset []>,
254 254 <baseset [3]>>
255 255 3
256 256 $ try '1|2&3'
257 257 (or
258 258 ('symbol', '1')
259 259 (and
260 260 ('symbol', '2')
261 261 ('symbol', '3')))
262 262 * set:
263 263 <addset
264 264 <baseset [1]>,
265 265 <baseset []>>
266 266 1
267 267 $ try '1&2&3' # associativity
268 268 (and
269 269 (and
270 270 ('symbol', '1')
271 271 ('symbol', '2'))
272 272 ('symbol', '3'))
273 273 * set:
274 274 <baseset []>
275 275 $ try '1|(2|3)'
276 276 (or
277 277 ('symbol', '1')
278 278 (group
279 279 (or
280 280 ('symbol', '2')
281 281 ('symbol', '3'))))
282 282 * set:
283 283 <addset
284 284 <baseset [1]>,
285 285 <addset
286 286 <baseset [2]>,
287 287 <baseset [3]>>>
288 288 1
289 289 2
290 290 3
291 291 $ log '1.0' # tag
292 292 6
293 293 $ log 'a' # branch
294 294 0
295 295 $ log '2785f51ee'
296 296 0
297 297 $ log 'date(2005)'
298 298 4
299 299 $ log 'date(this is a test)'
300 300 hg: parse error at 10: unexpected token: symbol
301 301 [255]
302 302 $ log 'date()'
303 303 hg: parse error: date requires a string
304 304 [255]
305 305 $ log 'date'
306 306 abort: unknown revision 'date'!
307 307 [255]
308 308 $ log 'date('
309 309 hg: parse error at 5: not a prefix: end
310 310 [255]
311 311 $ log 'date(tip)'
312 312 abort: invalid date: 'tip'
313 313 [255]
314 314 $ log '0:date'
315 315 abort: unknown revision 'date'!
316 316 [255]
317 317 $ log '::"date"'
318 318 abort: unknown revision 'date'!
319 319 [255]
320 320 $ hg book date -r 4
321 321 $ log '0:date'
322 322 0
323 323 1
324 324 2
325 325 3
326 326 4
327 327 $ log '::date'
328 328 0
329 329 1
330 330 2
331 331 4
332 332 $ log '::"date"'
333 333 0
334 334 1
335 335 2
336 336 4
337 337 $ log 'date(2005) and 1::'
338 338 4
339 339 $ hg book -d date
340 340
341 341 Test that symbols only get parsed as functions if there's an opening
342 342 parenthesis.
343 343
344 344 $ hg book only -r 9
345 345 $ log 'only(only)' # Outer "only" is a function, inner "only" is the bookmark
346 346 8
347 347 9
348 348
349 349 ancestor can accept 0 or more arguments
350 350
351 351 $ log 'ancestor()'
352 352 $ log 'ancestor(1)'
353 353 1
354 354 $ log 'ancestor(4,5)'
355 355 1
356 356 $ log 'ancestor(4,5) and 4'
357 357 $ log 'ancestor(0,0,1,3)'
358 358 0
359 359 $ log 'ancestor(3,1,5,3,5,1)'
360 360 1
361 361 $ log 'ancestor(0,1,3,5)'
362 362 0
363 363 $ log 'ancestor(1,2,3,4,5)'
364 364 1
365 365
366 366 test ancestors
367 367
368 368 $ log 'ancestors(5)'
369 369 0
370 370 1
371 371 3
372 372 5
373 373 $ log 'ancestor(ancestors(5))'
374 374 0
375 375 $ log '::r3232()'
376 376 0
377 377 1
378 378 2
379 379 3
380 380
381 381 $ log 'author(bob)'
382 382 2
383 383 $ log 'author("re:bob|test")'
384 384 0
385 385 1
386 386 2
387 387 3
388 388 4
389 389 5
390 390 6
391 391 7
392 392 8
393 393 9
394 394 $ log 'branch(Γ©)'
395 395 8
396 396 9
397 397 $ log 'branch(a)'
398 398 0
399 399 $ hg log -r 'branch("re:a")' --template '{rev} {branch}\n'
400 400 0 a
401 401 2 a-b-c-
402 402 3 +a+b+c+
403 403 4 -a-b-c-
404 404 5 !a/b/c/
405 405 6 _a_b_c_
406 406 7 .a.b.c.
407 407 $ log 'children(ancestor(4,5))'
408 408 2
409 409 3
410 410 $ log 'closed()'
411 411 $ log 'contains(a)'
412 412 0
413 413 1
414 414 3
415 415 5
416 416 $ log 'contains("../repo/a")'
417 417 0
418 418 1
419 419 3
420 420 5
421 421 $ log 'desc(B)'
422 422 5
423 423 $ log 'descendants(2 or 3)'
424 424 2
425 425 3
426 426 4
427 427 5
428 428 6
429 429 7
430 430 8
431 431 9
432 432 $ log 'file("b*")'
433 433 1
434 434 4
435 435 $ log 'filelog("b")'
436 436 1
437 437 4
438 438 $ log 'filelog("../repo/b")'
439 439 1
440 440 4
441 441 $ log 'follow()'
442 442 0
443 443 1
444 444 2
445 445 4
446 446 8
447 447 9
448 448 $ log 'grep("issue\d+")'
449 449 6
450 450 $ try 'grep("(")' # invalid regular expression
451 451 (func
452 452 ('symbol', 'grep')
453 453 ('string', '('))
454 454 hg: parse error: invalid match pattern: unbalanced parenthesis
455 455 [255]
456 456 $ try 'grep("\bissue\d+")'
457 457 (func
458 458 ('symbol', 'grep')
459 459 ('string', '\x08issue\\d+'))
460 460 * set:
461 461 <filteredset
462 462 <fullreposet+ 0:9>>
463 463 $ try 'grep(r"\bissue\d+")'
464 464 (func
465 465 ('symbol', 'grep')
466 466 ('string', '\\bissue\\d+'))
467 467 * set:
468 468 <filteredset
469 469 <fullreposet+ 0:9>>
470 470 6
471 471 $ try 'grep(r"\")'
472 472 hg: parse error at 7: unterminated string
473 473 [255]
474 474 $ log 'head()'
475 475 0
476 476 1
477 477 2
478 478 3
479 479 4
480 480 5
481 481 6
482 482 7
483 483 9
484 484 $ log 'heads(6::)'
485 485 7
486 486 $ log 'keyword(issue)'
487 487 6
488 488 $ log 'keyword("test a")'
489 489 $ log 'limit(head(), 1)'
490 490 0
491 491 $ log 'matching(6)'
492 492 6
493 493 $ log 'matching(6:7, "phase parents user date branch summary files description substate")'
494 494 6
495 495 7
496 496
497 497 Testing min and max
498 498
499 499 max: simple
500 500
501 501 $ log 'max(contains(a))'
502 502 5
503 503
504 504 max: simple on unordered set)
505 505
506 506 $ log 'max((4+0+2+5+7) and contains(a))'
507 507 5
508 508
509 509 max: no result
510 510
511 511 $ log 'max(contains(stringthatdoesnotappearanywhere))'
512 512
513 513 max: no result on unordered set
514 514
515 515 $ log 'max((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))'
516 516
517 517 min: simple
518 518
519 519 $ log 'min(contains(a))'
520 520 0
521 521
522 522 min: simple on unordered set
523 523
524 524 $ log 'min((4+0+2+5+7) and contains(a))'
525 525 0
526 526
527 527 min: empty
528 528
529 529 $ log 'min(contains(stringthatdoesnotappearanywhere))'
530 530
531 531 min: empty on unordered set
532 532
533 533 $ log 'min((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))'
534 534
535 535
536 536 $ log 'merge()'
537 537 6
538 538 $ log 'branchpoint()'
539 539 1
540 540 4
541 541 $ log 'modifies(b)'
542 542 4
543 543 $ log 'modifies("path:b")'
544 544 4
545 545 $ log 'modifies("*")'
546 546 4
547 547 6
548 548 $ log 'modifies("set:modified()")'
549 549 4
550 550 $ log 'id(5)'
551 551 2
552 552 $ log 'only(9)'
553 553 8
554 554 9
555 555 $ log 'only(8)'
556 556 8
557 557 $ log 'only(9, 5)'
558 558 2
559 559 4
560 560 8
561 561 9
562 562 $ log 'only(7 + 9, 5 + 2)'
563 563 4
564 564 6
565 565 7
566 566 8
567 567 9
568 568
569 569 Test empty set input
570 570 $ log 'only(p2())'
571 571 $ log 'only(p1(), p2())'
572 572 0
573 573 1
574 574 2
575 575 4
576 576 8
577 577 9
578 578
579 579 Test '%' operator
580 580
581 581 $ log '9%'
582 582 8
583 583 9
584 584 $ log '9%5'
585 585 2
586 586 4
587 587 8
588 588 9
589 589 $ log '(7 + 9)%(5 + 2)'
590 590 4
591 591 6
592 592 7
593 593 8
594 594 9
595 595
596 596 Test opreand of '%' is optimized recursively (issue4670)
597 597
598 598 $ try --optimize '8:9-8%'
599 599 (onlypost
600 600 (minus
601 601 (range
602 602 ('symbol', '8')
603 603 ('symbol', '9'))
604 604 ('symbol', '8')))
605 605 * optimized:
606 606 (func
607 607 ('symbol', 'only')
608 608 (and
609 609 (range
610 610 ('symbol', '8')
611 611 ('symbol', '9'))
612 612 (not
613 613 ('symbol', '8'))))
614 614 * set:
615 615 <baseset+ [8, 9]>
616 616 8
617 617 9
618 618 $ try --optimize '(9)%(5)'
619 619 (only
620 620 (group
621 621 ('symbol', '9'))
622 622 (group
623 623 ('symbol', '5')))
624 624 * optimized:
625 625 (func
626 626 ('symbol', 'only')
627 627 (list
628 628 ('symbol', '9')
629 629 ('symbol', '5')))
630 630 * set:
631 631 <baseset+ [8, 9, 2, 4]>
632 632 2
633 633 4
634 634 8
635 635 9
636 636
637 637 Test the order of operations
638 638
639 639 $ log '7 + 9%5 + 2'
640 640 7
641 641 2
642 642 4
643 643 8
644 644 9
645 645
646 646 Test explicit numeric revision
647 647 $ log 'rev(-2)'
648 648 $ log 'rev(-1)'
649 649 -1
650 650 $ log 'rev(0)'
651 651 0
652 652 $ log 'rev(9)'
653 653 9
654 654 $ log 'rev(10)'
655 655 $ log 'rev(tip)'
656 656 hg: parse error: rev expects a number
657 657 [255]
658 658
659 659 Test hexadecimal revision
660 660 $ log 'id(2)'
661 661 abort: 00changelog.i@2: ambiguous identifier!
662 662 [255]
663 663 $ log 'id(23268)'
664 664 4
665 665 $ log 'id(2785f51eece)'
666 666 0
667 667 $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532c)'
668 668 8
669 669 $ log 'id(d5d0dcbdc4a)'
670 670 $ log 'id(d5d0dcbdc4w)'
671 671 $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532d)'
672 672 $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532q)'
673 673 $ log 'id(1.0)'
674 674 $ log 'id(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)'
675 675
676 676 Test null revision
677 677 $ log '(null)'
678 678 -1
679 679 $ log '(null:0)'
680 680 -1
681 681 0
682 682 $ log '(0:null)'
683 683 0
684 684 -1
685 685 $ log 'null::0'
686 686 -1
687 687 0
688 688 $ log 'null:tip - 0:'
689 689 -1
690 690 $ log 'null: and null::' | head -1
691 691 -1
692 692 $ log 'null: or 0:' | head -2
693 693 -1
694 694 0
695 695 $ log 'ancestors(null)'
696 696 -1
697 697 $ log 'reverse(null:)' | tail -2
698 698 0
699 699 -1
700 BROKEN: should be '-1'
700 701 $ log 'first(null:)'
701 -1
702 BROKEN: should be '-1'
702 703 $ log 'min(null:)'
703 -1
704 704 $ log 'tip:null and all()' | tail -2
705 705 1
706 706 0
707 707
708 708 Test working-directory revision
709 709 $ hg debugrevspec 'wdir()'
710 710 None
711 BROKEN: should include 'None'
711 712 $ hg debugrevspec 'tip or wdir()'
712 713 9
713 None
714 714 $ hg debugrevspec '0:tip and wdir()'
715 715
716 716 $ log 'outgoing()'
717 717 8
718 718 9
719 719 $ log 'outgoing("../remote1")'
720 720 8
721 721 9
722 722 $ log 'outgoing("../remote2")'
723 723 3
724 724 5
725 725 6
726 726 7
727 727 9
728 728 $ log 'p1(merge())'
729 729 5
730 730 $ log 'p2(merge())'
731 731 4
732 732 $ log 'parents(merge())'
733 733 4
734 734 5
735 735 $ log 'p1(branchpoint())'
736 736 0
737 737 2
738 738 $ log 'p2(branchpoint())'
739 739 $ log 'parents(branchpoint())'
740 740 0
741 741 2
742 742 $ log 'removes(a)'
743 743 2
744 744 6
745 745 $ log 'roots(all())'
746 746 0
747 747 $ log 'reverse(2 or 3 or 4 or 5)'
748 748 5
749 749 4
750 750 3
751 751 2
752 752 $ log 'reverse(all())'
753 753 9
754 754 8
755 755 7
756 756 6
757 757 5
758 758 4
759 759 3
760 760 2
761 761 1
762 762 0
763 763 $ log 'reverse(all()) & filelog(b)'
764 764 4
765 765 1
766 766 $ log 'rev(5)'
767 767 5
768 768 $ log 'sort(limit(reverse(all()), 3))'
769 769 7
770 770 8
771 771 9
772 772 $ log 'sort(2 or 3 or 4 or 5, date)'
773 773 2
774 774 3
775 775 5
776 776 4
777 777 $ log 'tagged()'
778 778 6
779 779 $ log 'tag()'
780 780 6
781 781 $ log 'tag(1.0)'
782 782 6
783 783 $ log 'tag(tip)'
784 784 9
785 785
786 786 test sort revset
787 787 --------------------------------------------
788 788
789 789 test when adding two unordered revsets
790 790
791 791 $ log 'sort(keyword(issue) or modifies(b))'
792 792 4
793 793 6
794 794
795 795 test when sorting a reversed collection in the same way it is
796 796
797 797 $ log 'sort(reverse(all()), -rev)'
798 798 9
799 799 8
800 800 7
801 801 6
802 802 5
803 803 4
804 804 3
805 805 2
806 806 1
807 807 0
808 808
809 809 test when sorting a reversed collection
810 810
811 811 $ log 'sort(reverse(all()), rev)'
812 812 0
813 813 1
814 814 2
815 815 3
816 816 4
817 817 5
818 818 6
819 819 7
820 820 8
821 821 9
822 822
823 823
824 824 test sorting two sorted collections in different orders
825 825
826 826 $ log 'sort(outgoing() or reverse(removes(a)), rev)'
827 827 2
828 828 6
829 829 8
830 830 9
831 831
832 832 test sorting two sorted collections in different orders backwards
833 833
834 834 $ log 'sort(outgoing() or reverse(removes(a)), -rev)'
835 835 9
836 836 8
837 837 6
838 838 2
839 839
840 840 test subtracting something from an addset
841 841
842 842 $ log '(outgoing() or removes(a)) - removes(a)'
843 843 8
844 844 9
845 845
846 846 test intersecting something with an addset
847 847
848 848 $ log 'parents(outgoing() or removes(a))'
849 849 1
850 850 4
851 851 5
852 852 8
853 853
854 854 test that `or` operation combines elements in the right order:
855 855
856 856 $ log '3:4 or 2:5'
857 857 3
858 858 4
859 859 2
860 860 5
861 861 $ log '3:4 or 5:2'
862 862 3
863 863 4
864 864 5
865 865 2
866 866 $ log 'sort(3:4 or 2:5)'
867 867 2
868 868 3
869 869 4
870 870 5
871 871 $ log 'sort(3:4 or 5:2)'
872 872 2
873 873 3
874 874 4
875 875 5
876 876
877 877 test that `or` operation skips duplicated revisions from right-hand side
878 878
879 879 $ try 'reverse(1::5) or ancestors(4)'
880 880 (or
881 881 (func
882 882 ('symbol', 'reverse')
883 883 (dagrange
884 884 ('symbol', '1')
885 885 ('symbol', '5')))
886 886 (func
887 887 ('symbol', 'ancestors')
888 888 ('symbol', '4')))
889 889 * set:
890 890 <addset
891 891 <baseset [5, 3, 1]>,
892 892 <generatorset+>>
893 893 5
894 894 3
895 895 1
896 896 0
897 897 2
898 898 4
899 899 $ try 'sort(ancestors(4) or reverse(1::5))'
900 900 (func
901 901 ('symbol', 'sort')
902 902 (or
903 903 (func
904 904 ('symbol', 'ancestors')
905 905 ('symbol', '4'))
906 906 (func
907 907 ('symbol', 'reverse')
908 908 (dagrange
909 909 ('symbol', '1')
910 910 ('symbol', '5')))))
911 911 * set:
912 912 <addset+
913 913 <generatorset+>,
914 914 <baseset [5, 3, 1]>>
915 915 0
916 916 1
917 917 2
918 918 3
919 919 4
920 920 5
921 921
922 922 check that conversion to only works
923 923 $ try --optimize '::3 - ::1'
924 924 (minus
925 925 (dagrangepre
926 926 ('symbol', '3'))
927 927 (dagrangepre
928 928 ('symbol', '1')))
929 929 * optimized:
930 930 (func
931 931 ('symbol', 'only')
932 932 (list
933 933 ('symbol', '3')
934 934 ('symbol', '1')))
935 935 * set:
936 936 <baseset+ [3]>
937 937 3
938 938 $ try --optimize 'ancestors(1) - ancestors(3)'
939 939 (minus
940 940 (func
941 941 ('symbol', 'ancestors')
942 942 ('symbol', '1'))
943 943 (func
944 944 ('symbol', 'ancestors')
945 945 ('symbol', '3')))
946 946 * optimized:
947 947 (func
948 948 ('symbol', 'only')
949 949 (list
950 950 ('symbol', '1')
951 951 ('symbol', '3')))
952 952 * set:
953 953 <baseset+ []>
954 954 $ try --optimize 'not ::2 and ::6'
955 955 (and
956 956 (not
957 957 (dagrangepre
958 958 ('symbol', '2')))
959 959 (dagrangepre
960 960 ('symbol', '6')))
961 961 * optimized:
962 962 (func
963 963 ('symbol', 'only')
964 964 (list
965 965 ('symbol', '6')
966 966 ('symbol', '2')))
967 967 * set:
968 968 <baseset+ [3, 4, 5, 6]>
969 969 3
970 970 4
971 971 5
972 972 6
973 973 $ try --optimize 'ancestors(6) and not ancestors(4)'
974 974 (and
975 975 (func
976 976 ('symbol', 'ancestors')
977 977 ('symbol', '6'))
978 978 (not
979 979 (func
980 980 ('symbol', 'ancestors')
981 981 ('symbol', '4'))))
982 982 * optimized:
983 983 (func
984 984 ('symbol', 'only')
985 985 (list
986 986 ('symbol', '6')
987 987 ('symbol', '4')))
988 988 * set:
989 989 <baseset+ [3, 5, 6]>
990 990 3
991 991 5
992 992 6
993 993
994 994 we can use patterns when searching for tags
995 995
996 996 $ log 'tag("1..*")'
997 997 abort: tag '1..*' does not exist!
998 998 [255]
999 999 $ log 'tag("re:1..*")'
1000 1000 6
1001 1001 $ log 'tag("re:[0-9].[0-9]")'
1002 1002 6
1003 1003 $ log 'tag("literal:1.0")'
1004 1004 6
1005 1005 $ log 'tag("re:0..*")'
1006 1006
1007 1007 $ log 'tag(unknown)'
1008 1008 abort: tag 'unknown' does not exist!
1009 1009 [255]
1010 1010 $ log 'tag("re:unknown")'
1011 1011 $ log 'present(tag("unknown"))'
1012 1012 $ log 'present(tag("re:unknown"))'
1013 1013 $ log 'branch(unknown)'
1014 1014 abort: unknown revision 'unknown'!
1015 1015 [255]
1016 1016 $ log 'branch("re:unknown")'
1017 1017 $ log 'present(branch("unknown"))'
1018 1018 $ log 'present(branch("re:unknown"))'
1019 1019 $ log 'user(bob)'
1020 1020 2
1021 1021
1022 1022 $ log '4::8'
1023 1023 4
1024 1024 8
1025 1025 $ log '4:8'
1026 1026 4
1027 1027 5
1028 1028 6
1029 1029 7
1030 1030 8
1031 1031
1032 1032 $ log 'sort(!merge() & (modifies(b) | user(bob) | keyword(bug) | keyword(issue) & 1::9), "-date")'
1033 1033 4
1034 1034 2
1035 1035 5
1036 1036
1037 1037 $ log 'not 0 and 0:2'
1038 1038 1
1039 1039 2
1040 1040 $ log 'not 1 and 0:2'
1041 1041 0
1042 1042 2
1043 1043 $ log 'not 2 and 0:2'
1044 1044 0
1045 1045 1
1046 1046 $ log '(1 and 2)::'
1047 1047 $ log '(1 and 2):'
1048 1048 $ log '(1 and 2):3'
1049 1049 $ log 'sort(head(), -rev)'
1050 1050 9
1051 1051 7
1052 1052 6
1053 1053 5
1054 1054 4
1055 1055 3
1056 1056 2
1057 1057 1
1058 1058 0
1059 1059 $ log '4::8 - 8'
1060 1060 4
1061 1061 $ log 'matching(1 or 2 or 3) and (2 or 3 or 1)'
1062 1062 2
1063 1063 3
1064 1064 1
1065 1065
1066 1066 $ log 'named("unknown")'
1067 1067 abort: namespace 'unknown' does not exist!
1068 1068 [255]
1069 1069 $ log 'named("re:unknown")'
1070 1070 abort: no namespace exists that match 'unknown'!
1071 1071 [255]
1072 1072 $ log 'present(named("unknown"))'
1073 1073 $ log 'present(named("re:unknown"))'
1074 1074
1075 1075 $ log 'tag()'
1076 1076 6
1077 1077 $ log 'named("tags")'
1078 1078 6
1079 1079
1080 1080 issue2437
1081 1081
1082 1082 $ log '3 and p1(5)'
1083 1083 3
1084 1084 $ log '4 and p2(6)'
1085 1085 4
1086 1086 $ log '1 and parents(:2)'
1087 1087 1
1088 1088 $ log '2 and children(1:)'
1089 1089 2
1090 1090 $ log 'roots(all()) or roots(all())'
1091 1091 0
1092 1092 $ hg debugrevspec 'roots(all()) or roots(all())'
1093 1093 0
1094 1094 $ log 'heads(branch(Γ©)) or heads(branch(Γ©))'
1095 1095 9
1096 1096 $ log 'ancestors(8) and (heads(branch("-a-b-c-")) or heads(branch(Γ©)))'
1097 1097 4
1098 1098
1099 1099 issue2654: report a parse error if the revset was not completely parsed
1100 1100
1101 1101 $ log '1 OR 2'
1102 1102 hg: parse error at 2: invalid token
1103 1103 [255]
1104 1104
1105 1105 or operator should preserve ordering:
1106 1106 $ log 'reverse(2::4) or tip'
1107 1107 4
1108 1108 2
1109 1109 9
1110 1110
1111 1111 parentrevspec
1112 1112
1113 1113 $ log 'merge()^0'
1114 1114 6
1115 1115 $ log 'merge()^'
1116 1116 5
1117 1117 $ log 'merge()^1'
1118 1118 5
1119 1119 $ log 'merge()^2'
1120 1120 4
1121 1121 $ log 'merge()^^'
1122 1122 3
1123 1123 $ log 'merge()^1^'
1124 1124 3
1125 1125 $ log 'merge()^^^'
1126 1126 1
1127 1127
1128 1128 $ log 'merge()~0'
1129 1129 6
1130 1130 $ log 'merge()~1'
1131 1131 5
1132 1132 $ log 'merge()~2'
1133 1133 3
1134 1134 $ log 'merge()~2^1'
1135 1135 1
1136 1136 $ log 'merge()~3'
1137 1137 1
1138 1138
1139 1139 $ log '(-3:tip)^'
1140 1140 4
1141 1141 6
1142 1142 8
1143 1143
1144 1144 $ log 'tip^foo'
1145 1145 hg: parse error: ^ expects a number 0, 1, or 2
1146 1146 [255]
1147 1147
1148 1148 Bogus function gets suggestions
1149 1149 $ log 'add()'
1150 1150 hg: parse error: unknown identifier: add
1151 1151 (did you mean 'adds'?)
1152 1152 [255]
1153 1153 $ log 'added()'
1154 1154 hg: parse error: unknown identifier: added
1155 1155 (did you mean 'adds'?)
1156 1156 [255]
1157 1157 $ log 'remo()'
1158 1158 hg: parse error: unknown identifier: remo
1159 1159 (did you mean one of remote, removes?)
1160 1160 [255]
1161 1161 $ log 'babar()'
1162 1162 hg: parse error: unknown identifier: babar
1163 1163 [255]
1164 1164
1165 1165 multiple revspecs
1166 1166
1167 1167 $ hg log -r 'tip~1:tip' -r 'tip~2:tip~1' --template '{rev}\n'
1168 1168 8
1169 1169 9
1170 1170 4
1171 1171 5
1172 1172 6
1173 1173 7
1174 1174
1175 1175 test usage in revpair (with "+")
1176 1176
1177 1177 (real pair)
1178 1178
1179 1179 $ hg diff -r 'tip^^' -r 'tip'
1180 1180 diff -r 2326846efdab -r 24286f4ae135 .hgtags
1181 1181 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1182 1182 +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000
1183 1183 @@ -0,0 +1,1 @@
1184 1184 +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0
1185 1185 $ hg diff -r 'tip^^::tip'
1186 1186 diff -r 2326846efdab -r 24286f4ae135 .hgtags
1187 1187 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1188 1188 +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000
1189 1189 @@ -0,0 +1,1 @@
1190 1190 +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0
1191 1191
1192 1192 (single rev)
1193 1193
1194 1194 $ hg diff -r 'tip^' -r 'tip^'
1195 1195 $ hg diff -r 'tip^::tip^ or tip^'
1196 1196
1197 1197 (single rev that does not looks like a range)
1198 1198
1199 1199 $ hg diff -r 'tip^ or tip^'
1200 1200 diff -r d5d0dcbdc4d9 .hgtags
1201 1201 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1202 1202 +++ b/.hgtags * (glob)
1203 1203 @@ -0,0 +1,1 @@
1204 1204 +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0
1205 1205
1206 1206 (no rev)
1207 1207
1208 1208 $ hg diff -r 'author("babar") or author("celeste")'
1209 1209 abort: empty revision range
1210 1210 [255]
1211 1211
1212 1212 aliases:
1213 1213
1214 1214 $ echo '[revsetalias]' >> .hg/hgrc
1215 1215 $ echo 'm = merge()' >> .hg/hgrc
1216 1216 (revset aliases can override builtin revsets)
1217 1217 $ echo 'p2($1) = p1($1)' >> .hg/hgrc
1218 1218 $ echo 'sincem = descendants(m)' >> .hg/hgrc
1219 1219 $ echo 'd($1) = reverse(sort($1, date))' >> .hg/hgrc
1220 1220 $ echo 'rs(ARG1, ARG2) = reverse(sort(ARG1, ARG2))' >> .hg/hgrc
1221 1221 $ echo 'rs4(ARG1, ARGA, ARGB, ARG2) = reverse(sort(ARG1, ARG2))' >> .hg/hgrc
1222 1222
1223 1223 $ try m
1224 1224 ('symbol', 'm')
1225 1225 (func
1226 1226 ('symbol', 'merge')
1227 1227 None)
1228 1228 * set:
1229 1229 <filteredset
1230 1230 <fullreposet+ 0:9>>
1231 1231 6
1232 1232
1233 1233 $ HGPLAIN=1
1234 1234 $ export HGPLAIN
1235 1235 $ try m
1236 1236 ('symbol', 'm')
1237 1237 abort: unknown revision 'm'!
1238 1238 [255]
1239 1239
1240 1240 $ HGPLAINEXCEPT=revsetalias
1241 1241 $ export HGPLAINEXCEPT
1242 1242 $ try m
1243 1243 ('symbol', 'm')
1244 1244 (func
1245 1245 ('symbol', 'merge')
1246 1246 None)
1247 1247 * set:
1248 1248 <filteredset
1249 1249 <fullreposet+ 0:9>>
1250 1250 6
1251 1251
1252 1252 $ unset HGPLAIN
1253 1253 $ unset HGPLAINEXCEPT
1254 1254
1255 1255 $ try 'p2(.)'
1256 1256 (func
1257 1257 ('symbol', 'p2')
1258 1258 ('symbol', '.'))
1259 1259 (func
1260 1260 ('symbol', 'p1')
1261 1261 ('symbol', '.'))
1262 1262 * set:
1263 1263 <baseset+ [8]>
1264 1264 8
1265 1265
1266 1266 $ HGPLAIN=1
1267 1267 $ export HGPLAIN
1268 1268 $ try 'p2(.)'
1269 1269 (func
1270 1270 ('symbol', 'p2')
1271 1271 ('symbol', '.'))
1272 1272 * set:
1273 1273 <baseset+ []>
1274 1274
1275 1275 $ HGPLAINEXCEPT=revsetalias
1276 1276 $ export HGPLAINEXCEPT
1277 1277 $ try 'p2(.)'
1278 1278 (func
1279 1279 ('symbol', 'p2')
1280 1280 ('symbol', '.'))
1281 1281 (func
1282 1282 ('symbol', 'p1')
1283 1283 ('symbol', '.'))
1284 1284 * set:
1285 1285 <baseset+ [8]>
1286 1286 8
1287 1287
1288 1288 $ unset HGPLAIN
1289 1289 $ unset HGPLAINEXCEPT
1290 1290
1291 1291 test alias recursion
1292 1292
1293 1293 $ try sincem
1294 1294 ('symbol', 'sincem')
1295 1295 (func
1296 1296 ('symbol', 'descendants')
1297 1297 (func
1298 1298 ('symbol', 'merge')
1299 1299 None))
1300 1300 * set:
1301 1301 <addset+
1302 1302 <filteredset
1303 1303 <fullreposet+ 0:9>>,
1304 1304 <generatorset+>>
1305 1305 6
1306 1306 7
1307 1307
1308 1308 test infinite recursion
1309 1309
1310 1310 $ echo 'recurse1 = recurse2' >> .hg/hgrc
1311 1311 $ echo 'recurse2 = recurse1' >> .hg/hgrc
1312 1312 $ try recurse1
1313 1313 ('symbol', 'recurse1')
1314 1314 hg: parse error: infinite expansion of revset alias "recurse1" detected
1315 1315 [255]
1316 1316
1317 1317 $ echo 'level1($1, $2) = $1 or $2' >> .hg/hgrc
1318 1318 $ echo 'level2($1, $2) = level1($2, $1)' >> .hg/hgrc
1319 1319 $ try "level2(level1(1, 2), 3)"
1320 1320 (func
1321 1321 ('symbol', 'level2')
1322 1322 (list
1323 1323 (func
1324 1324 ('symbol', 'level1')
1325 1325 (list
1326 1326 ('symbol', '1')
1327 1327 ('symbol', '2')))
1328 1328 ('symbol', '3')))
1329 1329 (or
1330 1330 ('symbol', '3')
1331 1331 (or
1332 1332 ('symbol', '1')
1333 1333 ('symbol', '2')))
1334 1334 * set:
1335 1335 <addset
1336 1336 <baseset [3]>,
1337 1337 <addset
1338 1338 <baseset [1]>,
1339 1339 <baseset [2]>>>
1340 1340 3
1341 1341 1
1342 1342 2
1343 1343
1344 1344 test nesting and variable passing
1345 1345
1346 1346 $ echo 'nested($1) = nested2($1)' >> .hg/hgrc
1347 1347 $ echo 'nested2($1) = nested3($1)' >> .hg/hgrc
1348 1348 $ echo 'nested3($1) = max($1)' >> .hg/hgrc
1349 1349 $ try 'nested(2:5)'
1350 1350 (func
1351 1351 ('symbol', 'nested')
1352 1352 (range
1353 1353 ('symbol', '2')
1354 1354 ('symbol', '5')))
1355 1355 (func
1356 1356 ('symbol', 'max')
1357 1357 (range
1358 1358 ('symbol', '2')
1359 1359 ('symbol', '5')))
1360 1360 * set:
1361 1361 <baseset [5]>
1362 1362 5
1363 1363
1364 1364 test variable isolation, variable placeholders are rewritten as string
1365 1365 then parsed and matched again as string. Check they do not leak too
1366 1366 far away.
1367 1367
1368 1368 $ echo 'injectparamasstring = max("$1")' >> .hg/hgrc
1369 1369 $ echo 'callinjection($1) = descendants(injectparamasstring)' >> .hg/hgrc
1370 1370 $ try 'callinjection(2:5)'
1371 1371 (func
1372 1372 ('symbol', 'callinjection')
1373 1373 (range
1374 1374 ('symbol', '2')
1375 1375 ('symbol', '5')))
1376 1376 (func
1377 1377 ('symbol', 'descendants')
1378 1378 (func
1379 1379 ('symbol', 'max')
1380 1380 ('string', '$1')))
1381 1381 abort: unknown revision '$1'!
1382 1382 [255]
1383 1383
1384 1384 $ echo 'injectparamasstring2 = max(_aliasarg("$1"))' >> .hg/hgrc
1385 1385 $ echo 'callinjection2($1) = descendants(injectparamasstring2)' >> .hg/hgrc
1386 1386 $ try 'callinjection2(2:5)'
1387 1387 (func
1388 1388 ('symbol', 'callinjection2')
1389 1389 (range
1390 1390 ('symbol', '2')
1391 1391 ('symbol', '5')))
1392 1392 abort: failed to parse the definition of revset alias "injectparamasstring2": unknown identifier: _aliasarg
1393 1393 [255]
1394 1394 $ hg debugrevspec --debug --config revsetalias.anotherbadone='branch(' "tip"
1395 1395 ('symbol', 'tip')
1396 1396 warning: failed to parse the definition of revset alias "anotherbadone": at 7: not a prefix: end
1397 1397 warning: failed to parse the definition of revset alias "injectparamasstring2": unknown identifier: _aliasarg
1398 1398 * set:
1399 1399 <baseset [9]>
1400 1400 9
1401 1401 >>> data = file('.hg/hgrc', 'rb').read()
1402 1402 >>> file('.hg/hgrc', 'wb').write(data.replace('_aliasarg', ''))
1403 1403
1404 1404 $ try 'tip'
1405 1405 ('symbol', 'tip')
1406 1406 * set:
1407 1407 <baseset [9]>
1408 1408 9
1409 1409
1410 1410 $ hg debugrevspec --debug --config revsetalias.'bad name'='tip' "tip"
1411 1411 ('symbol', 'tip')
1412 1412 warning: failed to parse the declaration of revset alias "bad name": at 4: invalid token
1413 1413 * set:
1414 1414 <baseset [9]>
1415 1415 9
1416 1416 $ echo 'strictreplacing($1, $10) = $10 or desc("$1")' >> .hg/hgrc
1417 1417 $ try 'strictreplacing("foo", tip)'
1418 1418 (func
1419 1419 ('symbol', 'strictreplacing')
1420 1420 (list
1421 1421 ('string', 'foo')
1422 1422 ('symbol', 'tip')))
1423 1423 (or
1424 1424 ('symbol', 'tip')
1425 1425 (func
1426 1426 ('symbol', 'desc')
1427 1427 ('string', '$1')))
1428 1428 * set:
1429 1429 <addset
1430 1430 <baseset [9]>,
1431 1431 <filteredset
1432 1432 <fullreposet+ 0:9>>>
1433 1433 9
1434 1434
1435 1435 $ try 'd(2:5)'
1436 1436 (func
1437 1437 ('symbol', 'd')
1438 1438 (range
1439 1439 ('symbol', '2')
1440 1440 ('symbol', '5')))
1441 1441 (func
1442 1442 ('symbol', 'reverse')
1443 1443 (func
1444 1444 ('symbol', 'sort')
1445 1445 (list
1446 1446 (range
1447 1447 ('symbol', '2')
1448 1448 ('symbol', '5'))
1449 1449 ('symbol', 'date'))))
1450 1450 * set:
1451 1451 <baseset [4, 5, 3, 2]>
1452 1452 4
1453 1453 5
1454 1454 3
1455 1455 2
1456 1456 $ try 'rs(2 or 3, date)'
1457 1457 (func
1458 1458 ('symbol', 'rs')
1459 1459 (list
1460 1460 (or
1461 1461 ('symbol', '2')
1462 1462 ('symbol', '3'))
1463 1463 ('symbol', 'date')))
1464 1464 (func
1465 1465 ('symbol', 'reverse')
1466 1466 (func
1467 1467 ('symbol', 'sort')
1468 1468 (list
1469 1469 (or
1470 1470 ('symbol', '2')
1471 1471 ('symbol', '3'))
1472 1472 ('symbol', 'date'))))
1473 1473 * set:
1474 1474 <baseset [3, 2]>
1475 1475 3
1476 1476 2
1477 1477 $ try 'rs()'
1478 1478 (func
1479 1479 ('symbol', 'rs')
1480 1480 None)
1481 1481 hg: parse error: invalid number of arguments: 0
1482 1482 [255]
1483 1483 $ try 'rs(2)'
1484 1484 (func
1485 1485 ('symbol', 'rs')
1486 1486 ('symbol', '2'))
1487 1487 hg: parse error: invalid number of arguments: 1
1488 1488 [255]
1489 1489 $ try 'rs(2, data, 7)'
1490 1490 (func
1491 1491 ('symbol', 'rs')
1492 1492 (list
1493 1493 (list
1494 1494 ('symbol', '2')
1495 1495 ('symbol', 'data'))
1496 1496 ('symbol', '7')))
1497 1497 hg: parse error: invalid number of arguments: 3
1498 1498 [255]
1499 1499 $ try 'rs4(2 or 3, x, x, date)'
1500 1500 (func
1501 1501 ('symbol', 'rs4')
1502 1502 (list
1503 1503 (list
1504 1504 (list
1505 1505 (or
1506 1506 ('symbol', '2')
1507 1507 ('symbol', '3'))
1508 1508 ('symbol', 'x'))
1509 1509 ('symbol', 'x'))
1510 1510 ('symbol', 'date')))
1511 1511 (func
1512 1512 ('symbol', 'reverse')
1513 1513 (func
1514 1514 ('symbol', 'sort')
1515 1515 (list
1516 1516 (or
1517 1517 ('symbol', '2')
1518 1518 ('symbol', '3'))
1519 1519 ('symbol', 'date'))))
1520 1520 * set:
1521 1521 <baseset [3, 2]>
1522 1522 3
1523 1523 2
1524 1524
1525 1525 issue4553: check that revset aliases override existing hash prefix
1526 1526
1527 1527 $ hg log -qr e
1528 1528 6:e0cc66ef77e8
1529 1529
1530 1530 $ hg log -qr e --config revsetalias.e="all()"
1531 1531 0:2785f51eece5
1532 1532 1:d75937da8da0
1533 1533 2:5ed5505e9f1c
1534 1534 3:8528aa5637f2
1535 1535 4:2326846efdab
1536 1536 5:904fa392b941
1537 1537 6:e0cc66ef77e8
1538 1538 7:013af1973af4
1539 1539 8:d5d0dcbdc4d9
1540 1540 9:24286f4ae135
1541 1541
1542 1542 $ hg log -qr e: --config revsetalias.e="0"
1543 1543 0:2785f51eece5
1544 1544 1:d75937da8da0
1545 1545 2:5ed5505e9f1c
1546 1546 3:8528aa5637f2
1547 1547 4:2326846efdab
1548 1548 5:904fa392b941
1549 1549 6:e0cc66ef77e8
1550 1550 7:013af1973af4
1551 1551 8:d5d0dcbdc4d9
1552 1552 9:24286f4ae135
1553 1553
1554 1554 $ hg log -qr :e --config revsetalias.e="9"
1555 1555 0:2785f51eece5
1556 1556 1:d75937da8da0
1557 1557 2:5ed5505e9f1c
1558 1558 3:8528aa5637f2
1559 1559 4:2326846efdab
1560 1560 5:904fa392b941
1561 1561 6:e0cc66ef77e8
1562 1562 7:013af1973af4
1563 1563 8:d5d0dcbdc4d9
1564 1564 9:24286f4ae135
1565 1565
1566 1566 $ hg log -qr e:
1567 1567 6:e0cc66ef77e8
1568 1568 7:013af1973af4
1569 1569 8:d5d0dcbdc4d9
1570 1570 9:24286f4ae135
1571 1571
1572 1572 $ hg log -qr :e
1573 1573 0:2785f51eece5
1574 1574 1:d75937da8da0
1575 1575 2:5ed5505e9f1c
1576 1576 3:8528aa5637f2
1577 1577 4:2326846efdab
1578 1578 5:904fa392b941
1579 1579 6:e0cc66ef77e8
1580 1580
1581 1581 issue2549 - correct optimizations
1582 1582
1583 1583 $ log 'limit(1 or 2 or 3, 2) and not 2'
1584 1584 1
1585 1585 $ log 'max(1 or 2) and not 2'
1586 1586 $ log 'min(1 or 2) and not 1'
1587 1587 $ log 'last(1 or 2, 1) and not 2'
1588 1588
1589 1589 issue4289 - ordering of built-ins
1590 1590 $ hg log -M -q -r 3:2
1591 1591 3:8528aa5637f2
1592 1592 2:5ed5505e9f1c
1593 1593
1594 1594 test revsets started with 40-chars hash (issue3669)
1595 1595
1596 1596 $ ISSUE3669_TIP=`hg tip --template '{node}'`
1597 1597 $ hg log -r "${ISSUE3669_TIP}" --template '{rev}\n'
1598 1598 9
1599 1599 $ hg log -r "${ISSUE3669_TIP}^" --template '{rev}\n'
1600 1600 8
1601 1601
1602 1602 test or-ed indirect predicates (issue3775)
1603 1603
1604 1604 $ log '6 or 6^1' | sort
1605 1605 5
1606 1606 6
1607 1607 $ log '6^1 or 6' | sort
1608 1608 5
1609 1609 6
1610 1610 $ log '4 or 4~1' | sort
1611 1611 2
1612 1612 4
1613 1613 $ log '4~1 or 4' | sort
1614 1614 2
1615 1615 4
1616 1616 $ log '(0 or 2):(4 or 6) or 0 or 6' | sort
1617 1617 0
1618 1618 1
1619 1619 2
1620 1620 3
1621 1621 4
1622 1622 5
1623 1623 6
1624 1624 $ log '0 or 6 or (0 or 2):(4 or 6)' | sort
1625 1625 0
1626 1626 1
1627 1627 2
1628 1628 3
1629 1629 4
1630 1630 5
1631 1631 6
1632 1632
1633 1633 tests for 'remote()' predicate:
1634 1634 #. (csets in remote) (id) (remote)
1635 1635 1. less than local current branch "default"
1636 1636 2. same with local specified "default"
1637 1637 3. more than local specified specified
1638 1638
1639 1639 $ hg clone --quiet -U . ../remote3
1640 1640 $ cd ../remote3
1641 1641 $ hg update -q 7
1642 1642 $ echo r > r
1643 1643 $ hg ci -Aqm 10
1644 1644 $ log 'remote()'
1645 1645 7
1646 1646 $ log 'remote("a-b-c-")'
1647 1647 2
1648 1648 $ cd ../repo
1649 1649 $ log 'remote(".a.b.c.", "../remote3")'
1650 1650
1651 1651 tests for concatenation of strings/symbols by "##"
1652 1652
1653 1653 $ try "278 ## '5f5' ## 1ee ## 'ce5'"
1654 1654 (_concat
1655 1655 (_concat
1656 1656 (_concat
1657 1657 ('symbol', '278')
1658 1658 ('string', '5f5'))
1659 1659 ('symbol', '1ee'))
1660 1660 ('string', 'ce5'))
1661 1661 ('string', '2785f51eece5')
1662 1662 * set:
1663 1663 <baseset [0]>
1664 1664 0
1665 1665
1666 1666 $ echo 'cat4($1, $2, $3, $4) = $1 ## $2 ## $3 ## $4' >> .hg/hgrc
1667 1667 $ try "cat4(278, '5f5', 1ee, 'ce5')"
1668 1668 (func
1669 1669 ('symbol', 'cat4')
1670 1670 (list
1671 1671 (list
1672 1672 (list
1673 1673 ('symbol', '278')
1674 1674 ('string', '5f5'))
1675 1675 ('symbol', '1ee'))
1676 1676 ('string', 'ce5')))
1677 1677 (_concat
1678 1678 (_concat
1679 1679 (_concat
1680 1680 ('symbol', '278')
1681 1681 ('string', '5f5'))
1682 1682 ('symbol', '1ee'))
1683 1683 ('string', 'ce5'))
1684 1684 ('string', '2785f51eece5')
1685 1685 * set:
1686 1686 <baseset [0]>
1687 1687 0
1688 1688
1689 1689 (check concatenation in alias nesting)
1690 1690
1691 1691 $ echo 'cat2($1, $2) = $1 ## $2' >> .hg/hgrc
1692 1692 $ echo 'cat2x2($1, $2, $3, $4) = cat2($1 ## $2, $3 ## $4)' >> .hg/hgrc
1693 1693 $ log "cat2x2(278, '5f5', 1ee, 'ce5')"
1694 1694 0
1695 1695
1696 1696 (check operator priority)
1697 1697
1698 1698 $ echo 'cat2n2($1, $2, $3, $4) = $1 ## $2 or $3 ## $4~2' >> .hg/hgrc
1699 1699 $ log "cat2n2(2785f5, 1eece5, 24286f, 4ae135)"
1700 1700 0
1701 1701 4
1702 1702
1703 1703 $ cd ..
1704 1704
1705 prepare repository that has "default" branches of multiple roots
1706
1707 $ hg init namedbranch
1708 $ cd namedbranch
1709
1710 $ echo default0 >> a
1711 $ hg ci -Aqm0
1712 $ echo default1 >> a
1713 $ hg ci -m1
1714
1715 $ hg branch -q stable
1716 $ echo stable2 >> a
1717 $ hg ci -m2
1718 $ echo stable3 >> a
1719 $ hg ci -m3
1720
1721 $ hg update -q null
1722 $ echo default4 >> a
1723 $ hg ci -Aqm4
1724 $ echo default5 >> a
1725 $ hg ci -m5
1726
1727 "null" revision belongs to "default" branch (issue4683)
1728
1729 $ log 'branch(null)'
1730 0
1731 1
1732 4
1733 5
1734
1735 "null" revision belongs to "default" branch, but it shouldn't appear in set
1736 unless explicitly specified (issue4682)
1737
1738 $ log 'children(branch(default))'
1739 1
1740 2
1741 5
1742
1743 $ cd ..
1744
1705 1745 test author/desc/keyword in problematic encoding
1706 1746 # unicode: cp932:
1707 1747 # u30A2 0x83 0x41(= 'A')
1708 1748 # u30C2 0x83 0x61(= 'a')
1709 1749
1710 1750 $ hg init problematicencoding
1711 1751 $ cd problematicencoding
1712 1752
1713 1753 $ python > setup.sh <<EOF
1714 1754 > print u'''
1715 1755 > echo a > text
1716 1756 > hg add text
1717 1757 > hg --encoding utf-8 commit -u '\u30A2' -m none
1718 1758 > echo b > text
1719 1759 > hg --encoding utf-8 commit -u '\u30C2' -m none
1720 1760 > echo c > text
1721 1761 > hg --encoding utf-8 commit -u none -m '\u30A2'
1722 1762 > echo d > text
1723 1763 > hg --encoding utf-8 commit -u none -m '\u30C2'
1724 1764 > '''.encode('utf-8')
1725 1765 > EOF
1726 1766 $ sh < setup.sh
1727 1767
1728 1768 test in problematic encoding
1729 1769 $ python > test.sh <<EOF
1730 1770 > print u'''
1731 1771 > hg --encoding cp932 log --template '{rev}\\n' -r 'author(\u30A2)'
1732 1772 > echo ====
1733 1773 > hg --encoding cp932 log --template '{rev}\\n' -r 'author(\u30C2)'
1734 1774 > echo ====
1735 1775 > hg --encoding cp932 log --template '{rev}\\n' -r 'desc(\u30A2)'
1736 1776 > echo ====
1737 1777 > hg --encoding cp932 log --template '{rev}\\n' -r 'desc(\u30C2)'
1738 1778 > echo ====
1739 1779 > hg --encoding cp932 log --template '{rev}\\n' -r 'keyword(\u30A2)'
1740 1780 > echo ====
1741 1781 > hg --encoding cp932 log --template '{rev}\\n' -r 'keyword(\u30C2)'
1742 1782 > '''.encode('cp932')
1743 1783 > EOF
1744 1784 $ sh < test.sh
1745 1785 0
1746 1786 ====
1747 1787 1
1748 1788 ====
1749 1789 2
1750 1790 ====
1751 1791 3
1752 1792 ====
1753 1793 0
1754 1794 2
1755 1795 ====
1756 1796 1
1757 1797 3
1758 1798
1759 1799 test error message of bad revset
1760 1800 $ hg log -r 'foo\\'
1761 1801 hg: parse error at 3: syntax error in revset 'foo\\'
1762 1802 [255]
1763 1803
1764 1804 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now