##// END OF EJS Templates
commit: fix a typo ("form p1" -> "from p1")...
Martin von Zweigbergk -
r42472:8988e640 default
parent child Browse files
Show More
@@ -1,3143 +1,3143
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
8 8 from __future__ import absolute_import
9 9
10 10 import errno
11 11 import hashlib
12 12 import os
13 13 import random
14 14 import sys
15 15 import time
16 16 import weakref
17 17
18 18 from .i18n import _
19 19 from .node import (
20 20 bin,
21 21 hex,
22 22 nullid,
23 23 nullrev,
24 24 short,
25 25 )
26 26 from . import (
27 27 bookmarks,
28 28 branchmap,
29 29 bundle2,
30 30 changegroup,
31 31 changelog,
32 32 color,
33 33 context,
34 34 dirstate,
35 35 dirstateguard,
36 36 discovery,
37 37 encoding,
38 38 error,
39 39 exchange,
40 40 extensions,
41 41 filelog,
42 42 hook,
43 43 lock as lockmod,
44 44 manifest,
45 45 match as matchmod,
46 46 merge as mergemod,
47 47 mergeutil,
48 48 namespaces,
49 49 narrowspec,
50 50 obsolete,
51 51 pathutil,
52 52 phases,
53 53 pushkey,
54 54 pycompat,
55 55 repository,
56 56 repoview,
57 57 revset,
58 58 revsetlang,
59 59 scmutil,
60 60 sparse,
61 61 store as storemod,
62 62 subrepoutil,
63 63 tags as tagsmod,
64 64 transaction,
65 65 txnutil,
66 66 util,
67 67 vfs as vfsmod,
68 68 )
69 69 from .utils import (
70 70 interfaceutil,
71 71 procutil,
72 72 stringutil,
73 73 )
74 74
75 75 from .revlogutils import (
76 76 constants as revlogconst,
77 77 )
78 78
79 79 release = lockmod.release
80 80 urlerr = util.urlerr
81 81 urlreq = util.urlreq
82 82
83 83 # set of (path, vfs-location) tuples. vfs-location is:
84 84 # - 'plain for vfs relative paths
85 85 # - '' for svfs relative paths
86 86 _cachedfiles = set()
87 87
88 88 class _basefilecache(scmutil.filecache):
89 89 """All filecache usage on repo are done for logic that should be unfiltered
90 90 """
91 91 def __get__(self, repo, type=None):
92 92 if repo is None:
93 93 return self
94 94 # proxy to unfiltered __dict__ since filtered repo has no entry
95 95 unfi = repo.unfiltered()
96 96 try:
97 97 return unfi.__dict__[self.sname]
98 98 except KeyError:
99 99 pass
100 100 return super(_basefilecache, self).__get__(unfi, type)
101 101
102 102 def set(self, repo, value):
103 103 return super(_basefilecache, self).set(repo.unfiltered(), value)
104 104
105 105 class repofilecache(_basefilecache):
106 106 """filecache for files in .hg but outside of .hg/store"""
107 107 def __init__(self, *paths):
108 108 super(repofilecache, self).__init__(*paths)
109 109 for path in paths:
110 110 _cachedfiles.add((path, 'plain'))
111 111
112 112 def join(self, obj, fname):
113 113 return obj.vfs.join(fname)
114 114
115 115 class storecache(_basefilecache):
116 116 """filecache for files in the store"""
117 117 def __init__(self, *paths):
118 118 super(storecache, self).__init__(*paths)
119 119 for path in paths:
120 120 _cachedfiles.add((path, ''))
121 121
122 122 def join(self, obj, fname):
123 123 return obj.sjoin(fname)
124 124
125 125 def isfilecached(repo, name):
126 126 """check if a repo has already cached "name" filecache-ed property
127 127
128 128 This returns (cachedobj-or-None, iscached) tuple.
129 129 """
130 130 cacheentry = repo.unfiltered()._filecache.get(name, None)
131 131 if not cacheentry:
132 132 return None, False
133 133 return cacheentry.obj, True
134 134
135 135 class unfilteredpropertycache(util.propertycache):
136 136 """propertycache that apply to unfiltered repo only"""
137 137
138 138 def __get__(self, repo, type=None):
139 139 unfi = repo.unfiltered()
140 140 if unfi is repo:
141 141 return super(unfilteredpropertycache, self).__get__(unfi)
142 142 return getattr(unfi, self.name)
143 143
144 144 class filteredpropertycache(util.propertycache):
145 145 """propertycache that must take filtering in account"""
146 146
147 147 def cachevalue(self, obj, value):
148 148 object.__setattr__(obj, self.name, value)
149 149
150 150
151 151 def hasunfilteredcache(repo, name):
152 152 """check if a repo has an unfilteredpropertycache value for <name>"""
153 153 return name in vars(repo.unfiltered())
154 154
155 155 def unfilteredmethod(orig):
156 156 """decorate method that always need to be run on unfiltered version"""
157 157 def wrapper(repo, *args, **kwargs):
158 158 return orig(repo.unfiltered(), *args, **kwargs)
159 159 return wrapper
160 160
161 161 moderncaps = {'lookup', 'branchmap', 'pushkey', 'known', 'getbundle',
162 162 'unbundle'}
163 163 legacycaps = moderncaps.union({'changegroupsubset'})
164 164
165 165 @interfaceutil.implementer(repository.ipeercommandexecutor)
166 166 class localcommandexecutor(object):
167 167 def __init__(self, peer):
168 168 self._peer = peer
169 169 self._sent = False
170 170 self._closed = False
171 171
172 172 def __enter__(self):
173 173 return self
174 174
175 175 def __exit__(self, exctype, excvalue, exctb):
176 176 self.close()
177 177
178 178 def callcommand(self, command, args):
179 179 if self._sent:
180 180 raise error.ProgrammingError('callcommand() cannot be used after '
181 181 'sendcommands()')
182 182
183 183 if self._closed:
184 184 raise error.ProgrammingError('callcommand() cannot be used after '
185 185 'close()')
186 186
187 187 # We don't need to support anything fancy. Just call the named
188 188 # method on the peer and return a resolved future.
189 189 fn = getattr(self._peer, pycompat.sysstr(command))
190 190
191 191 f = pycompat.futures.Future()
192 192
193 193 try:
194 194 result = fn(**pycompat.strkwargs(args))
195 195 except Exception:
196 196 pycompat.future_set_exception_info(f, sys.exc_info()[1:])
197 197 else:
198 198 f.set_result(result)
199 199
200 200 return f
201 201
202 202 def sendcommands(self):
203 203 self._sent = True
204 204
205 205 def close(self):
206 206 self._closed = True
207 207
208 208 @interfaceutil.implementer(repository.ipeercommands)
209 209 class localpeer(repository.peer):
210 210 '''peer for a local repo; reflects only the most recent API'''
211 211
212 212 def __init__(self, repo, caps=None):
213 213 super(localpeer, self).__init__()
214 214
215 215 if caps is None:
216 216 caps = moderncaps.copy()
217 217 self._repo = repo.filtered('served')
218 218 self.ui = repo.ui
219 219 self._caps = repo._restrictcapabilities(caps)
220 220
221 221 # Begin of _basepeer interface.
222 222
223 223 def url(self):
224 224 return self._repo.url()
225 225
226 226 def local(self):
227 227 return self._repo
228 228
229 229 def peer(self):
230 230 return self
231 231
232 232 def canpush(self):
233 233 return True
234 234
235 235 def close(self):
236 236 self._repo.close()
237 237
238 238 # End of _basepeer interface.
239 239
240 240 # Begin of _basewirecommands interface.
241 241
242 242 def branchmap(self):
243 243 return self._repo.branchmap()
244 244
245 245 def capabilities(self):
246 246 return self._caps
247 247
248 248 def clonebundles(self):
249 249 return self._repo.tryread('clonebundles.manifest')
250 250
251 251 def debugwireargs(self, one, two, three=None, four=None, five=None):
252 252 """Used to test argument passing over the wire"""
253 253 return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three),
254 254 pycompat.bytestr(four),
255 255 pycompat.bytestr(five))
256 256
257 257 def getbundle(self, source, heads=None, common=None, bundlecaps=None,
258 258 **kwargs):
259 259 chunks = exchange.getbundlechunks(self._repo, source, heads=heads,
260 260 common=common, bundlecaps=bundlecaps,
261 261 **kwargs)[1]
262 262 cb = util.chunkbuffer(chunks)
263 263
264 264 if exchange.bundle2requested(bundlecaps):
265 265 # When requesting a bundle2, getbundle returns a stream to make the
266 266 # wire level function happier. We need to build a proper object
267 267 # from it in local peer.
268 268 return bundle2.getunbundler(self.ui, cb)
269 269 else:
270 270 return changegroup.getunbundler('01', cb, None)
271 271
272 272 def heads(self):
273 273 return self._repo.heads()
274 274
275 275 def known(self, nodes):
276 276 return self._repo.known(nodes)
277 277
278 278 def listkeys(self, namespace):
279 279 return self._repo.listkeys(namespace)
280 280
281 281 def lookup(self, key):
282 282 return self._repo.lookup(key)
283 283
284 284 def pushkey(self, namespace, key, old, new):
285 285 return self._repo.pushkey(namespace, key, old, new)
286 286
287 287 def stream_out(self):
288 288 raise error.Abort(_('cannot perform stream clone against local '
289 289 'peer'))
290 290
291 291 def unbundle(self, bundle, heads, url):
292 292 """apply a bundle on a repo
293 293
294 294 This function handles the repo locking itself."""
295 295 try:
296 296 try:
297 297 bundle = exchange.readbundle(self.ui, bundle, None)
298 298 ret = exchange.unbundle(self._repo, bundle, heads, 'push', url)
299 299 if util.safehasattr(ret, 'getchunks'):
300 300 # This is a bundle20 object, turn it into an unbundler.
301 301 # This little dance should be dropped eventually when the
302 302 # API is finally improved.
303 303 stream = util.chunkbuffer(ret.getchunks())
304 304 ret = bundle2.getunbundler(self.ui, stream)
305 305 return ret
306 306 except Exception as exc:
307 307 # If the exception contains output salvaged from a bundle2
308 308 # reply, we need to make sure it is printed before continuing
309 309 # to fail. So we build a bundle2 with such output and consume
310 310 # it directly.
311 311 #
312 312 # This is not very elegant but allows a "simple" solution for
313 313 # issue4594
314 314 output = getattr(exc, '_bundle2salvagedoutput', ())
315 315 if output:
316 316 bundler = bundle2.bundle20(self._repo.ui)
317 317 for out in output:
318 318 bundler.addpart(out)
319 319 stream = util.chunkbuffer(bundler.getchunks())
320 320 b = bundle2.getunbundler(self.ui, stream)
321 321 bundle2.processbundle(self._repo, b)
322 322 raise
323 323 except error.PushRaced as exc:
324 324 raise error.ResponseError(_('push failed:'),
325 325 stringutil.forcebytestr(exc))
326 326
327 327 # End of _basewirecommands interface.
328 328
329 329 # Begin of peer interface.
330 330
331 331 def commandexecutor(self):
332 332 return localcommandexecutor(self)
333 333
334 334 # End of peer interface.
335 335
336 336 @interfaceutil.implementer(repository.ipeerlegacycommands)
337 337 class locallegacypeer(localpeer):
338 338 '''peer extension which implements legacy methods too; used for tests with
339 339 restricted capabilities'''
340 340
341 341 def __init__(self, repo):
342 342 super(locallegacypeer, self).__init__(repo, caps=legacycaps)
343 343
344 344 # Begin of baselegacywirecommands interface.
345 345
346 346 def between(self, pairs):
347 347 return self._repo.between(pairs)
348 348
349 349 def branches(self, nodes):
350 350 return self._repo.branches(nodes)
351 351
352 352 def changegroup(self, nodes, source):
353 353 outgoing = discovery.outgoing(self._repo, missingroots=nodes,
354 354 missingheads=self._repo.heads())
355 355 return changegroup.makechangegroup(self._repo, outgoing, '01', source)
356 356
357 357 def changegroupsubset(self, bases, heads, source):
358 358 outgoing = discovery.outgoing(self._repo, missingroots=bases,
359 359 missingheads=heads)
360 360 return changegroup.makechangegroup(self._repo, outgoing, '01', source)
361 361
362 362 # End of baselegacywirecommands interface.
363 363
364 364 # Increment the sub-version when the revlog v2 format changes to lock out old
365 365 # clients.
366 366 REVLOGV2_REQUIREMENT = 'exp-revlogv2.1'
367 367
368 368 # A repository with the sparserevlog feature will have delta chains that
369 369 # can spread over a larger span. Sparse reading cuts these large spans into
370 370 # pieces, so that each piece isn't too big.
371 371 # Without the sparserevlog capability, reading from the repository could use
372 372 # huge amounts of memory, because the whole span would be read at once,
373 373 # including all the intermediate revisions that aren't pertinent for the chain.
374 374 # This is why once a repository has enabled sparse-read, it becomes required.
375 375 SPARSEREVLOG_REQUIREMENT = 'sparserevlog'
376 376
377 377 # Functions receiving (ui, features) that extensions can register to impact
378 378 # the ability to load repositories with custom requirements. Only
379 379 # functions defined in loaded extensions are called.
380 380 #
381 381 # The function receives a set of requirement strings that the repository
382 382 # is capable of opening. Functions will typically add elements to the
383 383 # set to reflect that the extension knows how to handle that requirements.
384 384 featuresetupfuncs = set()
385 385
386 386 def makelocalrepository(baseui, path, intents=None):
387 387 """Create a local repository object.
388 388
389 389 Given arguments needed to construct a local repository, this function
390 390 performs various early repository loading functionality (such as
391 391 reading the ``.hg/requires`` and ``.hg/hgrc`` files), validates that
392 392 the repository can be opened, derives a type suitable for representing
393 393 that repository, and returns an instance of it.
394 394
395 395 The returned object conforms to the ``repository.completelocalrepository``
396 396 interface.
397 397
398 398 The repository type is derived by calling a series of factory functions
399 399 for each aspect/interface of the final repository. These are defined by
400 400 ``REPO_INTERFACES``.
401 401
402 402 Each factory function is called to produce a type implementing a specific
403 403 interface. The cumulative list of returned types will be combined into a
404 404 new type and that type will be instantiated to represent the local
405 405 repository.
406 406
407 407 The factory functions each receive various state that may be consulted
408 408 as part of deriving a type.
409 409
410 410 Extensions should wrap these factory functions to customize repository type
411 411 creation. Note that an extension's wrapped function may be called even if
412 412 that extension is not loaded for the repo being constructed. Extensions
413 413 should check if their ``__name__`` appears in the
414 414 ``extensionmodulenames`` set passed to the factory function and no-op if
415 415 not.
416 416 """
417 417 ui = baseui.copy()
418 418 # Prevent copying repo configuration.
419 419 ui.copy = baseui.copy
420 420
421 421 # Working directory VFS rooted at repository root.
422 422 wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True)
423 423
424 424 # Main VFS for .hg/ directory.
425 425 hgpath = wdirvfs.join(b'.hg')
426 426 hgvfs = vfsmod.vfs(hgpath, cacheaudited=True)
427 427
428 428 # The .hg/ path should exist and should be a directory. All other
429 429 # cases are errors.
430 430 if not hgvfs.isdir():
431 431 try:
432 432 hgvfs.stat()
433 433 except OSError as e:
434 434 if e.errno != errno.ENOENT:
435 435 raise
436 436
437 437 raise error.RepoError(_(b'repository %s not found') % path)
438 438
439 439 # .hg/requires file contains a newline-delimited list of
440 440 # features/capabilities the opener (us) must have in order to use
441 441 # the repository. This file was introduced in Mercurial 0.9.2,
442 442 # which means very old repositories may not have one. We assume
443 443 # a missing file translates to no requirements.
444 444 try:
445 445 requirements = set(hgvfs.read(b'requires').splitlines())
446 446 except IOError as e:
447 447 if e.errno != errno.ENOENT:
448 448 raise
449 449 requirements = set()
450 450
451 451 # The .hg/hgrc file may load extensions or contain config options
452 452 # that influence repository construction. Attempt to load it and
453 453 # process any new extensions that it may have pulled in.
454 454 if loadhgrc(ui, wdirvfs, hgvfs, requirements):
455 455 afterhgrcload(ui, wdirvfs, hgvfs, requirements)
456 456 extensions.loadall(ui)
457 457 extensions.populateui(ui)
458 458
459 459 # Set of module names of extensions loaded for this repository.
460 460 extensionmodulenames = {m.__name__ for n, m in extensions.extensions(ui)}
461 461
462 462 supportedrequirements = gathersupportedrequirements(ui)
463 463
464 464 # We first validate the requirements are known.
465 465 ensurerequirementsrecognized(requirements, supportedrequirements)
466 466
467 467 # Then we validate that the known set is reasonable to use together.
468 468 ensurerequirementscompatible(ui, requirements)
469 469
470 470 # TODO there are unhandled edge cases related to opening repositories with
471 471 # shared storage. If storage is shared, we should also test for requirements
472 472 # compatibility in the pointed-to repo. This entails loading the .hg/hgrc in
473 473 # that repo, as that repo may load extensions needed to open it. This is a
474 474 # bit complicated because we don't want the other hgrc to overwrite settings
475 475 # in this hgrc.
476 476 #
477 477 # This bug is somewhat mitigated by the fact that we copy the .hg/requires
478 478 # file when sharing repos. But if a requirement is added after the share is
479 479 # performed, thereby introducing a new requirement for the opener, we may
480 480 # will not see that and could encounter a run-time error interacting with
481 481 # that shared store since it has an unknown-to-us requirement.
482 482
483 483 # At this point, we know we should be capable of opening the repository.
484 484 # Now get on with doing that.
485 485
486 486 features = set()
487 487
488 488 # The "store" part of the repository holds versioned data. How it is
489 489 # accessed is determined by various requirements. The ``shared`` or
490 490 # ``relshared`` requirements indicate the store lives in the path contained
491 491 # in the ``.hg/sharedpath`` file. This is an absolute path for
492 492 # ``shared`` and relative to ``.hg/`` for ``relshared``.
493 493 if b'shared' in requirements or b'relshared' in requirements:
494 494 sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n')
495 495 if b'relshared' in requirements:
496 496 sharedpath = hgvfs.join(sharedpath)
497 497
498 498 sharedvfs = vfsmod.vfs(sharedpath, realpath=True)
499 499
500 500 if not sharedvfs.exists():
501 501 raise error.RepoError(_(b'.hg/sharedpath points to nonexistent '
502 502 b'directory %s') % sharedvfs.base)
503 503
504 504 features.add(repository.REPO_FEATURE_SHARED_STORAGE)
505 505
506 506 storebasepath = sharedvfs.base
507 507 cachepath = sharedvfs.join(b'cache')
508 508 else:
509 509 storebasepath = hgvfs.base
510 510 cachepath = hgvfs.join(b'cache')
511 511 wcachepath = hgvfs.join(b'wcache')
512 512
513 513
514 514 # The store has changed over time and the exact layout is dictated by
515 515 # requirements. The store interface abstracts differences across all
516 516 # of them.
517 517 store = makestore(requirements, storebasepath,
518 518 lambda base: vfsmod.vfs(base, cacheaudited=True))
519 519 hgvfs.createmode = store.createmode
520 520
521 521 storevfs = store.vfs
522 522 storevfs.options = resolvestorevfsoptions(ui, requirements, features)
523 523
524 524 # The cache vfs is used to manage cache files.
525 525 cachevfs = vfsmod.vfs(cachepath, cacheaudited=True)
526 526 cachevfs.createmode = store.createmode
527 527 # The cache vfs is used to manage cache files related to the working copy
528 528 wcachevfs = vfsmod.vfs(wcachepath, cacheaudited=True)
529 529 wcachevfs.createmode = store.createmode
530 530
531 531 # Now resolve the type for the repository object. We do this by repeatedly
532 532 # calling a factory function to produces types for specific aspects of the
533 533 # repo's operation. The aggregate returned types are used as base classes
534 534 # for a dynamically-derived type, which will represent our new repository.
535 535
536 536 bases = []
537 537 extrastate = {}
538 538
539 539 for iface, fn in REPO_INTERFACES:
540 540 # We pass all potentially useful state to give extensions tons of
541 541 # flexibility.
542 542 typ = fn()(ui=ui,
543 543 intents=intents,
544 544 requirements=requirements,
545 545 features=features,
546 546 wdirvfs=wdirvfs,
547 547 hgvfs=hgvfs,
548 548 store=store,
549 549 storevfs=storevfs,
550 550 storeoptions=storevfs.options,
551 551 cachevfs=cachevfs,
552 552 wcachevfs=wcachevfs,
553 553 extensionmodulenames=extensionmodulenames,
554 554 extrastate=extrastate,
555 555 baseclasses=bases)
556 556
557 557 if not isinstance(typ, type):
558 558 raise error.ProgrammingError('unable to construct type for %s' %
559 559 iface)
560 560
561 561 bases.append(typ)
562 562
563 563 # type() allows you to use characters in type names that wouldn't be
564 564 # recognized as Python symbols in source code. We abuse that to add
565 565 # rich information about our constructed repo.
566 566 name = pycompat.sysstr(b'derivedrepo:%s<%s>' % (
567 567 wdirvfs.base,
568 568 b','.join(sorted(requirements))))
569 569
570 570 cls = type(name, tuple(bases), {})
571 571
572 572 return cls(
573 573 baseui=baseui,
574 574 ui=ui,
575 575 origroot=path,
576 576 wdirvfs=wdirvfs,
577 577 hgvfs=hgvfs,
578 578 requirements=requirements,
579 579 supportedrequirements=supportedrequirements,
580 580 sharedpath=storebasepath,
581 581 store=store,
582 582 cachevfs=cachevfs,
583 583 wcachevfs=wcachevfs,
584 584 features=features,
585 585 intents=intents)
586 586
587 587 def loadhgrc(ui, wdirvfs, hgvfs, requirements):
588 588 """Load hgrc files/content into a ui instance.
589 589
590 590 This is called during repository opening to load any additional
591 591 config files or settings relevant to the current repository.
592 592
593 593 Returns a bool indicating whether any additional configs were loaded.
594 594
595 595 Extensions should monkeypatch this function to modify how per-repo
596 596 configs are loaded. For example, an extension may wish to pull in
597 597 configs from alternate files or sources.
598 598 """
599 599 try:
600 600 ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base)
601 601 return True
602 602 except IOError:
603 603 return False
604 604
605 605 def afterhgrcload(ui, wdirvfs, hgvfs, requirements):
606 606 """Perform additional actions after .hg/hgrc is loaded.
607 607
608 608 This function is called during repository loading immediately after
609 609 the .hg/hgrc file is loaded and before per-repo extensions are loaded.
610 610
611 611 The function can be used to validate configs, automatically add
612 612 options (including extensions) based on requirements, etc.
613 613 """
614 614
615 615 # Map of requirements to list of extensions to load automatically when
616 616 # requirement is present.
617 617 autoextensions = {
618 618 b'largefiles': [b'largefiles'],
619 619 b'lfs': [b'lfs'],
620 620 }
621 621
622 622 for requirement, names in sorted(autoextensions.items()):
623 623 if requirement not in requirements:
624 624 continue
625 625
626 626 for name in names:
627 627 if not ui.hasconfig(b'extensions', name):
628 628 ui.setconfig(b'extensions', name, b'', source='autoload')
629 629
630 630 def gathersupportedrequirements(ui):
631 631 """Determine the complete set of recognized requirements."""
632 632 # Start with all requirements supported by this file.
633 633 supported = set(localrepository._basesupported)
634 634
635 635 # Execute ``featuresetupfuncs`` entries if they belong to an extension
636 636 # relevant to this ui instance.
637 637 modules = {m.__name__ for n, m in extensions.extensions(ui)}
638 638
639 639 for fn in featuresetupfuncs:
640 640 if fn.__module__ in modules:
641 641 fn(ui, supported)
642 642
643 643 # Add derived requirements from registered compression engines.
644 644 for name in util.compengines:
645 645 engine = util.compengines[name]
646 646 if engine.available() and engine.revlogheader():
647 647 supported.add(b'exp-compression-%s' % name)
648 648 if engine.name() == 'zstd':
649 649 supported.add(b'revlog-compression-zstd')
650 650
651 651 return supported
652 652
653 653 def ensurerequirementsrecognized(requirements, supported):
654 654 """Validate that a set of local requirements is recognized.
655 655
656 656 Receives a set of requirements. Raises an ``error.RepoError`` if there
657 657 exists any requirement in that set that currently loaded code doesn't
658 658 recognize.
659 659
660 660 Returns a set of supported requirements.
661 661 """
662 662 missing = set()
663 663
664 664 for requirement in requirements:
665 665 if requirement in supported:
666 666 continue
667 667
668 668 if not requirement or not requirement[0:1].isalnum():
669 669 raise error.RequirementError(_(b'.hg/requires file is corrupt'))
670 670
671 671 missing.add(requirement)
672 672
673 673 if missing:
674 674 raise error.RequirementError(
675 675 _(b'repository requires features unknown to this Mercurial: %s') %
676 676 b' '.join(sorted(missing)),
677 677 hint=_(b'see https://mercurial-scm.org/wiki/MissingRequirement '
678 678 b'for more information'))
679 679
680 680 def ensurerequirementscompatible(ui, requirements):
681 681 """Validates that a set of recognized requirements is mutually compatible.
682 682
683 683 Some requirements may not be compatible with others or require
684 684 config options that aren't enabled. This function is called during
685 685 repository opening to ensure that the set of requirements needed
686 686 to open a repository is sane and compatible with config options.
687 687
688 688 Extensions can monkeypatch this function to perform additional
689 689 checking.
690 690
691 691 ``error.RepoError`` should be raised on failure.
692 692 """
693 693 if b'exp-sparse' in requirements and not sparse.enabled:
694 694 raise error.RepoError(_(b'repository is using sparse feature but '
695 695 b'sparse is not enabled; enable the '
696 696 b'"sparse" extensions to access'))
697 697
698 698 def makestore(requirements, path, vfstype):
699 699 """Construct a storage object for a repository."""
700 700 if b'store' in requirements:
701 701 if b'fncache' in requirements:
702 702 return storemod.fncachestore(path, vfstype,
703 703 b'dotencode' in requirements)
704 704
705 705 return storemod.encodedstore(path, vfstype)
706 706
707 707 return storemod.basicstore(path, vfstype)
708 708
709 709 def resolvestorevfsoptions(ui, requirements, features):
710 710 """Resolve the options to pass to the store vfs opener.
711 711
712 712 The returned dict is used to influence behavior of the storage layer.
713 713 """
714 714 options = {}
715 715
716 716 if b'treemanifest' in requirements:
717 717 options[b'treemanifest'] = True
718 718
719 719 # experimental config: format.manifestcachesize
720 720 manifestcachesize = ui.configint(b'format', b'manifestcachesize')
721 721 if manifestcachesize is not None:
722 722 options[b'manifestcachesize'] = manifestcachesize
723 723
724 724 # In the absence of another requirement superseding a revlog-related
725 725 # requirement, we have to assume the repo is using revlog version 0.
726 726 # This revlog format is super old and we don't bother trying to parse
727 727 # opener options for it because those options wouldn't do anything
728 728 # meaningful on such old repos.
729 729 if b'revlogv1' in requirements or REVLOGV2_REQUIREMENT in requirements:
730 730 options.update(resolverevlogstorevfsoptions(ui, requirements, features))
731 731
732 732 return options
733 733
734 734 def resolverevlogstorevfsoptions(ui, requirements, features):
735 735 """Resolve opener options specific to revlogs."""
736 736
737 737 options = {}
738 738 options[b'flagprocessors'] = {}
739 739
740 740 if b'revlogv1' in requirements:
741 741 options[b'revlogv1'] = True
742 742 if REVLOGV2_REQUIREMENT in requirements:
743 743 options[b'revlogv2'] = True
744 744
745 745 if b'generaldelta' in requirements:
746 746 options[b'generaldelta'] = True
747 747
748 748 # experimental config: format.chunkcachesize
749 749 chunkcachesize = ui.configint(b'format', b'chunkcachesize')
750 750 if chunkcachesize is not None:
751 751 options[b'chunkcachesize'] = chunkcachesize
752 752
753 753 deltabothparents = ui.configbool(b'storage',
754 754 b'revlog.optimize-delta-parent-choice')
755 755 options[b'deltabothparents'] = deltabothparents
756 756
757 757 lazydelta = ui.configbool(b'storage', b'revlog.reuse-external-delta')
758 758 lazydeltabase = False
759 759 if lazydelta:
760 760 lazydeltabase = ui.configbool(b'storage',
761 761 b'revlog.reuse-external-delta-parent')
762 762 if lazydeltabase is None:
763 763 lazydeltabase = not scmutil.gddeltaconfig(ui)
764 764 options[b'lazydelta'] = lazydelta
765 765 options[b'lazydeltabase'] = lazydeltabase
766 766
767 767 chainspan = ui.configbytes(b'experimental', b'maxdeltachainspan')
768 768 if 0 <= chainspan:
769 769 options[b'maxdeltachainspan'] = chainspan
770 770
771 771 mmapindexthreshold = ui.configbytes(b'experimental',
772 772 b'mmapindexthreshold')
773 773 if mmapindexthreshold is not None:
774 774 options[b'mmapindexthreshold'] = mmapindexthreshold
775 775
776 776 withsparseread = ui.configbool(b'experimental', b'sparse-read')
777 777 srdensitythres = float(ui.config(b'experimental',
778 778 b'sparse-read.density-threshold'))
779 779 srmingapsize = ui.configbytes(b'experimental',
780 780 b'sparse-read.min-gap-size')
781 781 options[b'with-sparse-read'] = withsparseread
782 782 options[b'sparse-read-density-threshold'] = srdensitythres
783 783 options[b'sparse-read-min-gap-size'] = srmingapsize
784 784
785 785 sparserevlog = SPARSEREVLOG_REQUIREMENT in requirements
786 786 options[b'sparse-revlog'] = sparserevlog
787 787 if sparserevlog:
788 788 options[b'generaldelta'] = True
789 789
790 790 maxchainlen = None
791 791 if sparserevlog:
792 792 maxchainlen = revlogconst.SPARSE_REVLOG_MAX_CHAIN_LENGTH
793 793 # experimental config: format.maxchainlen
794 794 maxchainlen = ui.configint(b'format', b'maxchainlen', maxchainlen)
795 795 if maxchainlen is not None:
796 796 options[b'maxchainlen'] = maxchainlen
797 797
798 798 for r in requirements:
799 799 # we allow multiple compression engine requirement to co-exist because
800 800 # strickly speaking, revlog seems to support mixed compression style.
801 801 #
802 802 # The compression used for new entries will be "the last one"
803 803 prefix = r.startswith
804 804 if prefix('revlog-compression-') or prefix('exp-compression-'):
805 805 options[b'compengine'] = r.split('-', 2)[2]
806 806
807 807 options[b'zlib.level'] = ui.configint(b'storage', b'revlog.zlib.level')
808 808 if options[b'zlib.level'] is not None:
809 809 if not (0 <= options[b'zlib.level'] <= 9):
810 810 msg = _('invalid value for `storage.revlog.zlib.level` config: %d')
811 811 raise error.Abort(msg % options[b'zlib.level'])
812 812 options[b'zstd.level'] = ui.configint(b'storage', b'revlog.zstd.level')
813 813 if options[b'zstd.level'] is not None:
814 814 if not (0 <= options[b'zstd.level'] <= 22):
815 815 msg = _('invalid value for `storage.revlog.zstd.level` config: %d')
816 816 raise error.Abort(msg % options[b'zstd.level'])
817 817
818 818 if repository.NARROW_REQUIREMENT in requirements:
819 819 options[b'enableellipsis'] = True
820 820
821 821 return options
822 822
823 823 def makemain(**kwargs):
824 824 """Produce a type conforming to ``ilocalrepositorymain``."""
825 825 return localrepository
826 826
827 827 @interfaceutil.implementer(repository.ilocalrepositoryfilestorage)
828 828 class revlogfilestorage(object):
829 829 """File storage when using revlogs."""
830 830
831 831 def file(self, path):
832 832 if path[0] == b'/':
833 833 path = path[1:]
834 834
835 835 return filelog.filelog(self.svfs, path)
836 836
837 837 @interfaceutil.implementer(repository.ilocalrepositoryfilestorage)
838 838 class revlognarrowfilestorage(object):
839 839 """File storage when using revlogs and narrow files."""
840 840
841 841 def file(self, path):
842 842 if path[0] == b'/':
843 843 path = path[1:]
844 844
845 845 return filelog.narrowfilelog(self.svfs, path, self._storenarrowmatch)
846 846
847 847 def makefilestorage(requirements, features, **kwargs):
848 848 """Produce a type conforming to ``ilocalrepositoryfilestorage``."""
849 849 features.add(repository.REPO_FEATURE_REVLOG_FILE_STORAGE)
850 850 features.add(repository.REPO_FEATURE_STREAM_CLONE)
851 851
852 852 if repository.NARROW_REQUIREMENT in requirements:
853 853 return revlognarrowfilestorage
854 854 else:
855 855 return revlogfilestorage
856 856
857 857 # List of repository interfaces and factory functions for them. Each
858 858 # will be called in order during ``makelocalrepository()`` to iteratively
859 859 # derive the final type for a local repository instance. We capture the
860 860 # function as a lambda so we don't hold a reference and the module-level
861 861 # functions can be wrapped.
862 862 REPO_INTERFACES = [
863 863 (repository.ilocalrepositorymain, lambda: makemain),
864 864 (repository.ilocalrepositoryfilestorage, lambda: makefilestorage),
865 865 ]
866 866
867 867 @interfaceutil.implementer(repository.ilocalrepositorymain)
868 868 class localrepository(object):
869 869 """Main class for representing local repositories.
870 870
871 871 All local repositories are instances of this class.
872 872
873 873 Constructed on its own, instances of this class are not usable as
874 874 repository objects. To obtain a usable repository object, call
875 875 ``hg.repository()``, ``localrepo.instance()``, or
876 876 ``localrepo.makelocalrepository()``. The latter is the lowest-level.
877 877 ``instance()`` adds support for creating new repositories.
878 878 ``hg.repository()`` adds more extension integration, including calling
879 879 ``reposetup()``. Generally speaking, ``hg.repository()`` should be
880 880 used.
881 881 """
882 882
883 883 # obsolete experimental requirements:
884 884 # - manifestv2: An experimental new manifest format that allowed
885 885 # for stem compression of long paths. Experiment ended up not
886 886 # being successful (repository sizes went up due to worse delta
887 887 # chains), and the code was deleted in 4.6.
888 888 supportedformats = {
889 889 'revlogv1',
890 890 'generaldelta',
891 891 'treemanifest',
892 892 REVLOGV2_REQUIREMENT,
893 893 SPARSEREVLOG_REQUIREMENT,
894 894 }
895 895 _basesupported = supportedformats | {
896 896 'store',
897 897 'fncache',
898 898 'shared',
899 899 'relshared',
900 900 'dotencode',
901 901 'exp-sparse',
902 902 'internal-phase'
903 903 }
904 904
905 905 # list of prefix for file which can be written without 'wlock'
906 906 # Extensions should extend this list when needed
907 907 _wlockfreeprefix = {
908 908 # We migh consider requiring 'wlock' for the next
909 909 # two, but pretty much all the existing code assume
910 910 # wlock is not needed so we keep them excluded for
911 911 # now.
912 912 'hgrc',
913 913 'requires',
914 914 # XXX cache is a complicatged business someone
915 915 # should investigate this in depth at some point
916 916 'cache/',
917 917 # XXX shouldn't be dirstate covered by the wlock?
918 918 'dirstate',
919 919 # XXX bisect was still a bit too messy at the time
920 920 # this changeset was introduced. Someone should fix
921 921 # the remainig bit and drop this line
922 922 'bisect.state',
923 923 }
924 924
925 925 def __init__(self, baseui, ui, origroot, wdirvfs, hgvfs, requirements,
926 926 supportedrequirements, sharedpath, store, cachevfs, wcachevfs,
927 927 features, intents=None):
928 928 """Create a new local repository instance.
929 929
930 930 Most callers should use ``hg.repository()``, ``localrepo.instance()``,
931 931 or ``localrepo.makelocalrepository()`` for obtaining a new repository
932 932 object.
933 933
934 934 Arguments:
935 935
936 936 baseui
937 937 ``ui.ui`` instance that ``ui`` argument was based off of.
938 938
939 939 ui
940 940 ``ui.ui`` instance for use by the repository.
941 941
942 942 origroot
943 943 ``bytes`` path to working directory root of this repository.
944 944
945 945 wdirvfs
946 946 ``vfs.vfs`` rooted at the working directory.
947 947
948 948 hgvfs
949 949 ``vfs.vfs`` rooted at .hg/
950 950
951 951 requirements
952 952 ``set`` of bytestrings representing repository opening requirements.
953 953
954 954 supportedrequirements
955 955 ``set`` of bytestrings representing repository requirements that we
956 956 know how to open. May be a supetset of ``requirements``.
957 957
958 958 sharedpath
959 959 ``bytes`` Defining path to storage base directory. Points to a
960 960 ``.hg/`` directory somewhere.
961 961
962 962 store
963 963 ``store.basicstore`` (or derived) instance providing access to
964 964 versioned storage.
965 965
966 966 cachevfs
967 967 ``vfs.vfs`` used for cache files.
968 968
969 969 wcachevfs
970 970 ``vfs.vfs`` used for cache files related to the working copy.
971 971
972 972 features
973 973 ``set`` of bytestrings defining features/capabilities of this
974 974 instance.
975 975
976 976 intents
977 977 ``set`` of system strings indicating what this repo will be used
978 978 for.
979 979 """
980 980 self.baseui = baseui
981 981 self.ui = ui
982 982 self.origroot = origroot
983 983 # vfs rooted at working directory.
984 984 self.wvfs = wdirvfs
985 985 self.root = wdirvfs.base
986 986 # vfs rooted at .hg/. Used to access most non-store paths.
987 987 self.vfs = hgvfs
988 988 self.path = hgvfs.base
989 989 self.requirements = requirements
990 990 self.supported = supportedrequirements
991 991 self.sharedpath = sharedpath
992 992 self.store = store
993 993 self.cachevfs = cachevfs
994 994 self.wcachevfs = wcachevfs
995 995 self.features = features
996 996
997 997 self.filtername = None
998 998
999 999 if (self.ui.configbool('devel', 'all-warnings') or
1000 1000 self.ui.configbool('devel', 'check-locks')):
1001 1001 self.vfs.audit = self._getvfsward(self.vfs.audit)
1002 1002 # A list of callback to shape the phase if no data were found.
1003 1003 # Callback are in the form: func(repo, roots) --> processed root.
1004 1004 # This list it to be filled by extension during repo setup
1005 1005 self._phasedefaults = []
1006 1006
1007 1007 color.setup(self.ui)
1008 1008
1009 1009 self.spath = self.store.path
1010 1010 self.svfs = self.store.vfs
1011 1011 self.sjoin = self.store.join
1012 1012 if (self.ui.configbool('devel', 'all-warnings') or
1013 1013 self.ui.configbool('devel', 'check-locks')):
1014 1014 if util.safehasattr(self.svfs, 'vfs'): # this is filtervfs
1015 1015 self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit)
1016 1016 else: # standard vfs
1017 1017 self.svfs.audit = self._getsvfsward(self.svfs.audit)
1018 1018
1019 1019 self._dirstatevalidatewarned = False
1020 1020
1021 1021 self._branchcaches = branchmap.BranchMapCache()
1022 1022 self._revbranchcache = None
1023 1023 self._filterpats = {}
1024 1024 self._datafilters = {}
1025 1025 self._transref = self._lockref = self._wlockref = None
1026 1026
1027 1027 # A cache for various files under .hg/ that tracks file changes,
1028 1028 # (used by the filecache decorator)
1029 1029 #
1030 1030 # Maps a property name to its util.filecacheentry
1031 1031 self._filecache = {}
1032 1032
1033 1033 # hold sets of revision to be filtered
1034 1034 # should be cleared when something might have changed the filter value:
1035 1035 # - new changesets,
1036 1036 # - phase change,
1037 1037 # - new obsolescence marker,
1038 1038 # - working directory parent change,
1039 1039 # - bookmark changes
1040 1040 self.filteredrevcache = {}
1041 1041
1042 1042 # post-dirstate-status hooks
1043 1043 self._postdsstatus = []
1044 1044
1045 1045 # generic mapping between names and nodes
1046 1046 self.names = namespaces.namespaces()
1047 1047
1048 1048 # Key to signature value.
1049 1049 self._sparsesignaturecache = {}
1050 1050 # Signature to cached matcher instance.
1051 1051 self._sparsematchercache = {}
1052 1052
1053 1053 self._extrafilterid = repoview.extrafilter(ui)
1054 1054
1055 1055 def _getvfsward(self, origfunc):
1056 1056 """build a ward for self.vfs"""
1057 1057 rref = weakref.ref(self)
1058 1058 def checkvfs(path, mode=None):
1059 1059 ret = origfunc(path, mode=mode)
1060 1060 repo = rref()
1061 1061 if (repo is None
1062 1062 or not util.safehasattr(repo, '_wlockref')
1063 1063 or not util.safehasattr(repo, '_lockref')):
1064 1064 return
1065 1065 if mode in (None, 'r', 'rb'):
1066 1066 return
1067 1067 if path.startswith(repo.path):
1068 1068 # truncate name relative to the repository (.hg)
1069 1069 path = path[len(repo.path) + 1:]
1070 1070 if path.startswith('cache/'):
1071 1071 msg = 'accessing cache with vfs instead of cachevfs: "%s"'
1072 1072 repo.ui.develwarn(msg % path, stacklevel=3, config="cache-vfs")
1073 1073 if path.startswith('journal.') or path.startswith('undo.'):
1074 1074 # journal is covered by 'lock'
1075 1075 if repo._currentlock(repo._lockref) is None:
1076 1076 repo.ui.develwarn('write with no lock: "%s"' % path,
1077 1077 stacklevel=3, config='check-locks')
1078 1078 elif repo._currentlock(repo._wlockref) is None:
1079 1079 # rest of vfs files are covered by 'wlock'
1080 1080 #
1081 1081 # exclude special files
1082 1082 for prefix in self._wlockfreeprefix:
1083 1083 if path.startswith(prefix):
1084 1084 return
1085 1085 repo.ui.develwarn('write with no wlock: "%s"' % path,
1086 1086 stacklevel=3, config='check-locks')
1087 1087 return ret
1088 1088 return checkvfs
1089 1089
1090 1090 def _getsvfsward(self, origfunc):
1091 1091 """build a ward for self.svfs"""
1092 1092 rref = weakref.ref(self)
1093 1093 def checksvfs(path, mode=None):
1094 1094 ret = origfunc(path, mode=mode)
1095 1095 repo = rref()
1096 1096 if repo is None or not util.safehasattr(repo, '_lockref'):
1097 1097 return
1098 1098 if mode in (None, 'r', 'rb'):
1099 1099 return
1100 1100 if path.startswith(repo.sharedpath):
1101 1101 # truncate name relative to the repository (.hg)
1102 1102 path = path[len(repo.sharedpath) + 1:]
1103 1103 if repo._currentlock(repo._lockref) is None:
1104 1104 repo.ui.develwarn('write with no lock: "%s"' % path,
1105 1105 stacklevel=4)
1106 1106 return ret
1107 1107 return checksvfs
1108 1108
1109 1109 def close(self):
1110 1110 self._writecaches()
1111 1111
1112 1112 def _writecaches(self):
1113 1113 if self._revbranchcache:
1114 1114 self._revbranchcache.write()
1115 1115
1116 1116 def _restrictcapabilities(self, caps):
1117 1117 if self.ui.configbool('experimental', 'bundle2-advertise'):
1118 1118 caps = set(caps)
1119 1119 capsblob = bundle2.encodecaps(bundle2.getrepocaps(self,
1120 1120 role='client'))
1121 1121 caps.add('bundle2=' + urlreq.quote(capsblob))
1122 1122 return caps
1123 1123
1124 1124 def _writerequirements(self):
1125 1125 scmutil.writerequires(self.vfs, self.requirements)
1126 1126
1127 1127 # Don't cache auditor/nofsauditor, or you'll end up with reference cycle:
1128 1128 # self -> auditor -> self._checknested -> self
1129 1129
1130 1130 @property
1131 1131 def auditor(self):
1132 1132 # This is only used by context.workingctx.match in order to
1133 1133 # detect files in subrepos.
1134 1134 return pathutil.pathauditor(self.root, callback=self._checknested)
1135 1135
1136 1136 @property
1137 1137 def nofsauditor(self):
1138 1138 # This is only used by context.basectx.match in order to detect
1139 1139 # files in subrepos.
1140 1140 return pathutil.pathauditor(self.root, callback=self._checknested,
1141 1141 realfs=False, cached=True)
1142 1142
1143 1143 def _checknested(self, path):
1144 1144 """Determine if path is a legal nested repository."""
1145 1145 if not path.startswith(self.root):
1146 1146 return False
1147 1147 subpath = path[len(self.root) + 1:]
1148 1148 normsubpath = util.pconvert(subpath)
1149 1149
1150 1150 # XXX: Checking against the current working copy is wrong in
1151 1151 # the sense that it can reject things like
1152 1152 #
1153 1153 # $ hg cat -r 10 sub/x.txt
1154 1154 #
1155 1155 # if sub/ is no longer a subrepository in the working copy
1156 1156 # parent revision.
1157 1157 #
1158 1158 # However, it can of course also allow things that would have
1159 1159 # been rejected before, such as the above cat command if sub/
1160 1160 # is a subrepository now, but was a normal directory before.
1161 1161 # The old path auditor would have rejected by mistake since it
1162 1162 # panics when it sees sub/.hg/.
1163 1163 #
1164 1164 # All in all, checking against the working copy seems sensible
1165 1165 # since we want to prevent access to nested repositories on
1166 1166 # the filesystem *now*.
1167 1167 ctx = self[None]
1168 1168 parts = util.splitpath(subpath)
1169 1169 while parts:
1170 1170 prefix = '/'.join(parts)
1171 1171 if prefix in ctx.substate:
1172 1172 if prefix == normsubpath:
1173 1173 return True
1174 1174 else:
1175 1175 sub = ctx.sub(prefix)
1176 1176 return sub.checknested(subpath[len(prefix) + 1:])
1177 1177 else:
1178 1178 parts.pop()
1179 1179 return False
1180 1180
1181 1181 def peer(self):
1182 1182 return localpeer(self) # not cached to avoid reference cycle
1183 1183
1184 1184 def unfiltered(self):
1185 1185 """Return unfiltered version of the repository
1186 1186
1187 1187 Intended to be overwritten by filtered repo."""
1188 1188 return self
1189 1189
1190 1190 def filtered(self, name, visibilityexceptions=None):
1191 1191 """Return a filtered version of a repository
1192 1192
1193 1193 The `name` parameter is the identifier of the requested view. This
1194 1194 will return a repoview object set "exactly" to the specified view.
1195 1195
1196 1196 This function does not apply recursive filtering to a repository. For
1197 1197 example calling `repo.filtered("served")` will return a repoview using
1198 1198 the "served" view, regardless of the initial view used by `repo`.
1199 1199
1200 1200 In other word, there is always only one level of `repoview` "filtering".
1201 1201 """
1202 1202 if self._extrafilterid is not None and '%' not in name:
1203 1203 name = name + '%' + self._extrafilterid
1204 1204
1205 1205 cls = repoview.newtype(self.unfiltered().__class__)
1206 1206 return cls(self, name, visibilityexceptions)
1207 1207
1208 1208 @repofilecache('bookmarks', 'bookmarks.current')
1209 1209 def _bookmarks(self):
1210 1210 return bookmarks.bmstore(self)
1211 1211
1212 1212 @property
1213 1213 def _activebookmark(self):
1214 1214 return self._bookmarks.active
1215 1215
1216 1216 # _phasesets depend on changelog. what we need is to call
1217 1217 # _phasecache.invalidate() if '00changelog.i' was changed, but it
1218 1218 # can't be easily expressed in filecache mechanism.
1219 1219 @storecache('phaseroots', '00changelog.i')
1220 1220 def _phasecache(self):
1221 1221 return phases.phasecache(self, self._phasedefaults)
1222 1222
1223 1223 @storecache('obsstore')
1224 1224 def obsstore(self):
1225 1225 return obsolete.makestore(self.ui, self)
1226 1226
1227 1227 @storecache('00changelog.i')
1228 1228 def changelog(self):
1229 1229 return changelog.changelog(self.svfs,
1230 1230 trypending=txnutil.mayhavepending(self.root))
1231 1231
1232 1232 @storecache('00manifest.i')
1233 1233 def manifestlog(self):
1234 1234 rootstore = manifest.manifestrevlog(self.svfs)
1235 1235 return manifest.manifestlog(self.svfs, self, rootstore,
1236 1236 self._storenarrowmatch)
1237 1237
1238 1238 @repofilecache('dirstate')
1239 1239 def dirstate(self):
1240 1240 return self._makedirstate()
1241 1241
1242 1242 def _makedirstate(self):
1243 1243 """Extension point for wrapping the dirstate per-repo."""
1244 1244 sparsematchfn = lambda: sparse.matcher(self)
1245 1245
1246 1246 return dirstate.dirstate(self.vfs, self.ui, self.root,
1247 1247 self._dirstatevalidate, sparsematchfn)
1248 1248
1249 1249 def _dirstatevalidate(self, node):
1250 1250 try:
1251 1251 self.changelog.rev(node)
1252 1252 return node
1253 1253 except error.LookupError:
1254 1254 if not self._dirstatevalidatewarned:
1255 1255 self._dirstatevalidatewarned = True
1256 1256 self.ui.warn(_("warning: ignoring unknown"
1257 1257 " working parent %s!\n") % short(node))
1258 1258 return nullid
1259 1259
1260 1260 @storecache(narrowspec.FILENAME)
1261 1261 def narrowpats(self):
1262 1262 """matcher patterns for this repository's narrowspec
1263 1263
1264 1264 A tuple of (includes, excludes).
1265 1265 """
1266 1266 return narrowspec.load(self)
1267 1267
1268 1268 @storecache(narrowspec.FILENAME)
1269 1269 def _storenarrowmatch(self):
1270 1270 if repository.NARROW_REQUIREMENT not in self.requirements:
1271 1271 return matchmod.always()
1272 1272 include, exclude = self.narrowpats
1273 1273 return narrowspec.match(self.root, include=include, exclude=exclude)
1274 1274
1275 1275 @storecache(narrowspec.FILENAME)
1276 1276 def _narrowmatch(self):
1277 1277 if repository.NARROW_REQUIREMENT not in self.requirements:
1278 1278 return matchmod.always()
1279 1279 narrowspec.checkworkingcopynarrowspec(self)
1280 1280 include, exclude = self.narrowpats
1281 1281 return narrowspec.match(self.root, include=include, exclude=exclude)
1282 1282
1283 1283 def narrowmatch(self, match=None, includeexact=False):
1284 1284 """matcher corresponding the the repo's narrowspec
1285 1285
1286 1286 If `match` is given, then that will be intersected with the narrow
1287 1287 matcher.
1288 1288
1289 1289 If `includeexact` is True, then any exact matches from `match` will
1290 1290 be included even if they're outside the narrowspec.
1291 1291 """
1292 1292 if match:
1293 1293 if includeexact and not self._narrowmatch.always():
1294 1294 # do not exclude explicitly-specified paths so that they can
1295 1295 # be warned later on
1296 1296 em = matchmod.exact(match.files())
1297 1297 nm = matchmod.unionmatcher([self._narrowmatch, em])
1298 1298 return matchmod.intersectmatchers(match, nm)
1299 1299 return matchmod.intersectmatchers(match, self._narrowmatch)
1300 1300 return self._narrowmatch
1301 1301
1302 1302 def setnarrowpats(self, newincludes, newexcludes):
1303 1303 narrowspec.save(self, newincludes, newexcludes)
1304 1304 self.invalidate(clearfilecache=True)
1305 1305
1306 1306 def __getitem__(self, changeid):
1307 1307 if changeid is None:
1308 1308 return context.workingctx(self)
1309 1309 if isinstance(changeid, context.basectx):
1310 1310 return changeid
1311 1311 if isinstance(changeid, slice):
1312 1312 # wdirrev isn't contiguous so the slice shouldn't include it
1313 1313 return [self[i]
1314 1314 for i in pycompat.xrange(*changeid.indices(len(self)))
1315 1315 if i not in self.changelog.filteredrevs]
1316 1316 try:
1317 1317 if isinstance(changeid, int):
1318 1318 node = self.changelog.node(changeid)
1319 1319 rev = changeid
1320 1320 elif changeid == 'null':
1321 1321 node = nullid
1322 1322 rev = nullrev
1323 1323 elif changeid == 'tip':
1324 1324 node = self.changelog.tip()
1325 1325 rev = self.changelog.rev(node)
1326 1326 elif changeid == '.':
1327 1327 # this is a hack to delay/avoid loading obsmarkers
1328 1328 # when we know that '.' won't be hidden
1329 1329 node = self.dirstate.p1()
1330 1330 rev = self.unfiltered().changelog.rev(node)
1331 1331 elif len(changeid) == 20:
1332 1332 try:
1333 1333 node = changeid
1334 1334 rev = self.changelog.rev(changeid)
1335 1335 except error.FilteredLookupError:
1336 1336 changeid = hex(changeid) # for the error message
1337 1337 raise
1338 1338 except LookupError:
1339 1339 # check if it might have come from damaged dirstate
1340 1340 #
1341 1341 # XXX we could avoid the unfiltered if we had a recognizable
1342 1342 # exception for filtered changeset access
1343 1343 if (self.local()
1344 1344 and changeid in self.unfiltered().dirstate.parents()):
1345 1345 msg = _("working directory has unknown parent '%s'!")
1346 1346 raise error.Abort(msg % short(changeid))
1347 1347 changeid = hex(changeid) # for the error message
1348 1348 raise
1349 1349
1350 1350 elif len(changeid) == 40:
1351 1351 node = bin(changeid)
1352 1352 rev = self.changelog.rev(node)
1353 1353 else:
1354 1354 raise error.ProgrammingError(
1355 1355 "unsupported changeid '%s' of type %s" %
1356 1356 (changeid, type(changeid)))
1357 1357
1358 1358 return context.changectx(self, rev, node)
1359 1359
1360 1360 except (error.FilteredIndexError, error.FilteredLookupError):
1361 1361 raise error.FilteredRepoLookupError(_("filtered revision '%s'")
1362 1362 % pycompat.bytestr(changeid))
1363 1363 except (IndexError, LookupError):
1364 1364 raise error.RepoLookupError(
1365 1365 _("unknown revision '%s'") % pycompat.bytestr(changeid))
1366 1366 except error.WdirUnsupported:
1367 1367 return context.workingctx(self)
1368 1368
1369 1369 def __contains__(self, changeid):
1370 1370 """True if the given changeid exists
1371 1371
1372 1372 error.AmbiguousPrefixLookupError is raised if an ambiguous node
1373 1373 specified.
1374 1374 """
1375 1375 try:
1376 1376 self[changeid]
1377 1377 return True
1378 1378 except error.RepoLookupError:
1379 1379 return False
1380 1380
1381 1381 def __nonzero__(self):
1382 1382 return True
1383 1383
1384 1384 __bool__ = __nonzero__
1385 1385
1386 1386 def __len__(self):
1387 1387 # no need to pay the cost of repoview.changelog
1388 1388 unfi = self.unfiltered()
1389 1389 return len(unfi.changelog)
1390 1390
1391 1391 def __iter__(self):
1392 1392 return iter(self.changelog)
1393 1393
1394 1394 def revs(self, expr, *args):
1395 1395 '''Find revisions matching a revset.
1396 1396
1397 1397 The revset is specified as a string ``expr`` that may contain
1398 1398 %-formatting to escape certain types. See ``revsetlang.formatspec``.
1399 1399
1400 1400 Revset aliases from the configuration are not expanded. To expand
1401 1401 user aliases, consider calling ``scmutil.revrange()`` or
1402 1402 ``repo.anyrevs([expr], user=True)``.
1403 1403
1404 1404 Returns a revset.abstractsmartset, which is a list-like interface
1405 1405 that contains integer revisions.
1406 1406 '''
1407 1407 tree = revsetlang.spectree(expr, *args)
1408 1408 return revset.makematcher(tree)(self)
1409 1409
1410 1410 def set(self, expr, *args):
1411 1411 '''Find revisions matching a revset and emit changectx instances.
1412 1412
1413 1413 This is a convenience wrapper around ``revs()`` that iterates the
1414 1414 result and is a generator of changectx instances.
1415 1415
1416 1416 Revset aliases from the configuration are not expanded. To expand
1417 1417 user aliases, consider calling ``scmutil.revrange()``.
1418 1418 '''
1419 1419 for r in self.revs(expr, *args):
1420 1420 yield self[r]
1421 1421
1422 1422 def anyrevs(self, specs, user=False, localalias=None):
1423 1423 '''Find revisions matching one of the given revsets.
1424 1424
1425 1425 Revset aliases from the configuration are not expanded by default. To
1426 1426 expand user aliases, specify ``user=True``. To provide some local
1427 1427 definitions overriding user aliases, set ``localalias`` to
1428 1428 ``{name: definitionstring}``.
1429 1429 '''
1430 1430 if user:
1431 1431 m = revset.matchany(self.ui, specs,
1432 1432 lookup=revset.lookupfn(self),
1433 1433 localalias=localalias)
1434 1434 else:
1435 1435 m = revset.matchany(None, specs, localalias=localalias)
1436 1436 return m(self)
1437 1437
1438 1438 def url(self):
1439 1439 return 'file:' + self.root
1440 1440
1441 1441 def hook(self, name, throw=False, **args):
1442 1442 """Call a hook, passing this repo instance.
1443 1443
1444 1444 This a convenience method to aid invoking hooks. Extensions likely
1445 1445 won't call this unless they have registered a custom hook or are
1446 1446 replacing code that is expected to call a hook.
1447 1447 """
1448 1448 return hook.hook(self.ui, self, name, throw, **args)
1449 1449
1450 1450 @filteredpropertycache
1451 1451 def _tagscache(self):
1452 1452 '''Returns a tagscache object that contains various tags related
1453 1453 caches.'''
1454 1454
1455 1455 # This simplifies its cache management by having one decorated
1456 1456 # function (this one) and the rest simply fetch things from it.
1457 1457 class tagscache(object):
1458 1458 def __init__(self):
1459 1459 # These two define the set of tags for this repository. tags
1460 1460 # maps tag name to node; tagtypes maps tag name to 'global' or
1461 1461 # 'local'. (Global tags are defined by .hgtags across all
1462 1462 # heads, and local tags are defined in .hg/localtags.)
1463 1463 # They constitute the in-memory cache of tags.
1464 1464 self.tags = self.tagtypes = None
1465 1465
1466 1466 self.nodetagscache = self.tagslist = None
1467 1467
1468 1468 cache = tagscache()
1469 1469 cache.tags, cache.tagtypes = self._findtags()
1470 1470
1471 1471 return cache
1472 1472
1473 1473 def tags(self):
1474 1474 '''return a mapping of tag to node'''
1475 1475 t = {}
1476 1476 if self.changelog.filteredrevs:
1477 1477 tags, tt = self._findtags()
1478 1478 else:
1479 1479 tags = self._tagscache.tags
1480 1480 rev = self.changelog.rev
1481 1481 for k, v in tags.iteritems():
1482 1482 try:
1483 1483 # ignore tags to unknown nodes
1484 1484 rev(v)
1485 1485 t[k] = v
1486 1486 except (error.LookupError, ValueError):
1487 1487 pass
1488 1488 return t
1489 1489
1490 1490 def _findtags(self):
1491 1491 '''Do the hard work of finding tags. Return a pair of dicts
1492 1492 (tags, tagtypes) where tags maps tag name to node, and tagtypes
1493 1493 maps tag name to a string like \'global\' or \'local\'.
1494 1494 Subclasses or extensions are free to add their own tags, but
1495 1495 should be aware that the returned dicts will be retained for the
1496 1496 duration of the localrepo object.'''
1497 1497
1498 1498 # XXX what tagtype should subclasses/extensions use? Currently
1499 1499 # mq and bookmarks add tags, but do not set the tagtype at all.
1500 1500 # Should each extension invent its own tag type? Should there
1501 1501 # be one tagtype for all such "virtual" tags? Or is the status
1502 1502 # quo fine?
1503 1503
1504 1504
1505 1505 # map tag name to (node, hist)
1506 1506 alltags = tagsmod.findglobaltags(self.ui, self)
1507 1507 # map tag name to tag type
1508 1508 tagtypes = dict((tag, 'global') for tag in alltags)
1509 1509
1510 1510 tagsmod.readlocaltags(self.ui, self, alltags, tagtypes)
1511 1511
1512 1512 # Build the return dicts. Have to re-encode tag names because
1513 1513 # the tags module always uses UTF-8 (in order not to lose info
1514 1514 # writing to the cache), but the rest of Mercurial wants them in
1515 1515 # local encoding.
1516 1516 tags = {}
1517 1517 for (name, (node, hist)) in alltags.iteritems():
1518 1518 if node != nullid:
1519 1519 tags[encoding.tolocal(name)] = node
1520 1520 tags['tip'] = self.changelog.tip()
1521 1521 tagtypes = dict([(encoding.tolocal(name), value)
1522 1522 for (name, value) in tagtypes.iteritems()])
1523 1523 return (tags, tagtypes)
1524 1524
1525 1525 def tagtype(self, tagname):
1526 1526 '''
1527 1527 return the type of the given tag. result can be:
1528 1528
1529 1529 'local' : a local tag
1530 1530 'global' : a global tag
1531 1531 None : tag does not exist
1532 1532 '''
1533 1533
1534 1534 return self._tagscache.tagtypes.get(tagname)
1535 1535
1536 1536 def tagslist(self):
1537 1537 '''return a list of tags ordered by revision'''
1538 1538 if not self._tagscache.tagslist:
1539 1539 l = []
1540 1540 for t, n in self.tags().iteritems():
1541 1541 l.append((self.changelog.rev(n), t, n))
1542 1542 self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)]
1543 1543
1544 1544 return self._tagscache.tagslist
1545 1545
1546 1546 def nodetags(self, node):
1547 1547 '''return the tags associated with a node'''
1548 1548 if not self._tagscache.nodetagscache:
1549 1549 nodetagscache = {}
1550 1550 for t, n in self._tagscache.tags.iteritems():
1551 1551 nodetagscache.setdefault(n, []).append(t)
1552 1552 for tags in nodetagscache.itervalues():
1553 1553 tags.sort()
1554 1554 self._tagscache.nodetagscache = nodetagscache
1555 1555 return self._tagscache.nodetagscache.get(node, [])
1556 1556
1557 1557 def nodebookmarks(self, node):
1558 1558 """return the list of bookmarks pointing to the specified node"""
1559 1559 return self._bookmarks.names(node)
1560 1560
1561 1561 def branchmap(self):
1562 1562 '''returns a dictionary {branch: [branchheads]} with branchheads
1563 1563 ordered by increasing revision number'''
1564 1564 return self._branchcaches[self]
1565 1565
1566 1566 @unfilteredmethod
1567 1567 def revbranchcache(self):
1568 1568 if not self._revbranchcache:
1569 1569 self._revbranchcache = branchmap.revbranchcache(self.unfiltered())
1570 1570 return self._revbranchcache
1571 1571
1572 1572 def branchtip(self, branch, ignoremissing=False):
1573 1573 '''return the tip node for a given branch
1574 1574
1575 1575 If ignoremissing is True, then this method will not raise an error.
1576 1576 This is helpful for callers that only expect None for a missing branch
1577 1577 (e.g. namespace).
1578 1578
1579 1579 '''
1580 1580 try:
1581 1581 return self.branchmap().branchtip(branch)
1582 1582 except KeyError:
1583 1583 if not ignoremissing:
1584 1584 raise error.RepoLookupError(_("unknown branch '%s'") % branch)
1585 1585 else:
1586 1586 pass
1587 1587
1588 1588 def lookup(self, key):
1589 1589 node = scmutil.revsymbol(self, key).node()
1590 1590 if node is None:
1591 1591 raise error.RepoLookupError(_("unknown revision '%s'") % key)
1592 1592 return node
1593 1593
1594 1594 def lookupbranch(self, key):
1595 1595 if self.branchmap().hasbranch(key):
1596 1596 return key
1597 1597
1598 1598 return scmutil.revsymbol(self, key).branch()
1599 1599
1600 1600 def known(self, nodes):
1601 1601 cl = self.changelog
1602 1602 nm = cl.nodemap
1603 1603 filtered = cl.filteredrevs
1604 1604 result = []
1605 1605 for n in nodes:
1606 1606 r = nm.get(n)
1607 1607 resp = not (r is None or r in filtered)
1608 1608 result.append(resp)
1609 1609 return result
1610 1610
1611 1611 def local(self):
1612 1612 return self
1613 1613
1614 1614 def publishing(self):
1615 1615 # it's safe (and desirable) to trust the publish flag unconditionally
1616 1616 # so that we don't finalize changes shared between users via ssh or nfs
1617 1617 return self.ui.configbool('phases', 'publish', untrusted=True)
1618 1618
1619 1619 def cancopy(self):
1620 1620 # so statichttprepo's override of local() works
1621 1621 if not self.local():
1622 1622 return False
1623 1623 if not self.publishing():
1624 1624 return True
1625 1625 # if publishing we can't copy if there is filtered content
1626 1626 return not self.filtered('visible').changelog.filteredrevs
1627 1627
1628 1628 def shared(self):
1629 1629 '''the type of shared repository (None if not shared)'''
1630 1630 if self.sharedpath != self.path:
1631 1631 return 'store'
1632 1632 return None
1633 1633
1634 1634 def wjoin(self, f, *insidef):
1635 1635 return self.vfs.reljoin(self.root, f, *insidef)
1636 1636
1637 1637 def setparents(self, p1, p2=nullid):
1638 1638 with self.dirstate.parentchange():
1639 1639 copies = self.dirstate.setparents(p1, p2)
1640 1640 pctx = self[p1]
1641 1641 if copies:
1642 1642 # Adjust copy records, the dirstate cannot do it, it
1643 1643 # requires access to parents manifests. Preserve them
1644 1644 # only for entries added to first parent.
1645 1645 for f in copies:
1646 1646 if f not in pctx and copies[f] in pctx:
1647 1647 self.dirstate.copy(copies[f], f)
1648 1648 if p2 == nullid:
1649 1649 for f, s in sorted(self.dirstate.copies().items()):
1650 1650 if f not in pctx and s not in pctx:
1651 1651 self.dirstate.copy(None, f)
1652 1652
1653 1653 def filectx(self, path, changeid=None, fileid=None, changectx=None):
1654 1654 """changeid must be a changeset revision, if specified.
1655 1655 fileid can be a file revision or node."""
1656 1656 return context.filectx(self, path, changeid, fileid,
1657 1657 changectx=changectx)
1658 1658
1659 1659 def getcwd(self):
1660 1660 return self.dirstate.getcwd()
1661 1661
1662 1662 def pathto(self, f, cwd=None):
1663 1663 return self.dirstate.pathto(f, cwd)
1664 1664
1665 1665 def _loadfilter(self, filter):
1666 1666 if filter not in self._filterpats:
1667 1667 l = []
1668 1668 for pat, cmd in self.ui.configitems(filter):
1669 1669 if cmd == '!':
1670 1670 continue
1671 1671 mf = matchmod.match(self.root, '', [pat])
1672 1672 fn = None
1673 1673 params = cmd
1674 1674 for name, filterfn in self._datafilters.iteritems():
1675 1675 if cmd.startswith(name):
1676 1676 fn = filterfn
1677 1677 params = cmd[len(name):].lstrip()
1678 1678 break
1679 1679 if not fn:
1680 1680 fn = lambda s, c, **kwargs: procutil.filter(s, c)
1681 1681 # Wrap old filters not supporting keyword arguments
1682 1682 if not pycompat.getargspec(fn)[2]:
1683 1683 oldfn = fn
1684 1684 fn = lambda s, c, **kwargs: oldfn(s, c)
1685 1685 l.append((mf, fn, params))
1686 1686 self._filterpats[filter] = l
1687 1687 return self._filterpats[filter]
1688 1688
1689 1689 def _filter(self, filterpats, filename, data):
1690 1690 for mf, fn, cmd in filterpats:
1691 1691 if mf(filename):
1692 1692 self.ui.debug("filtering %s through %s\n" % (filename, cmd))
1693 1693 data = fn(data, cmd, ui=self.ui, repo=self, filename=filename)
1694 1694 break
1695 1695
1696 1696 return data
1697 1697
1698 1698 @unfilteredpropertycache
1699 1699 def _encodefilterpats(self):
1700 1700 return self._loadfilter('encode')
1701 1701
1702 1702 @unfilteredpropertycache
1703 1703 def _decodefilterpats(self):
1704 1704 return self._loadfilter('decode')
1705 1705
1706 1706 def adddatafilter(self, name, filter):
1707 1707 self._datafilters[name] = filter
1708 1708
1709 1709 def wread(self, filename):
1710 1710 if self.wvfs.islink(filename):
1711 1711 data = self.wvfs.readlink(filename)
1712 1712 else:
1713 1713 data = self.wvfs.read(filename)
1714 1714 return self._filter(self._encodefilterpats, filename, data)
1715 1715
1716 1716 def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs):
1717 1717 """write ``data`` into ``filename`` in the working directory
1718 1718
1719 1719 This returns length of written (maybe decoded) data.
1720 1720 """
1721 1721 data = self._filter(self._decodefilterpats, filename, data)
1722 1722 if 'l' in flags:
1723 1723 self.wvfs.symlink(data, filename)
1724 1724 else:
1725 1725 self.wvfs.write(filename, data, backgroundclose=backgroundclose,
1726 1726 **kwargs)
1727 1727 if 'x' in flags:
1728 1728 self.wvfs.setflags(filename, False, True)
1729 1729 else:
1730 1730 self.wvfs.setflags(filename, False, False)
1731 1731 return len(data)
1732 1732
1733 1733 def wwritedata(self, filename, data):
1734 1734 return self._filter(self._decodefilterpats, filename, data)
1735 1735
1736 1736 def currenttransaction(self):
1737 1737 """return the current transaction or None if non exists"""
1738 1738 if self._transref:
1739 1739 tr = self._transref()
1740 1740 else:
1741 1741 tr = None
1742 1742
1743 1743 if tr and tr.running():
1744 1744 return tr
1745 1745 return None
1746 1746
1747 1747 def transaction(self, desc, report=None):
1748 1748 if (self.ui.configbool('devel', 'all-warnings')
1749 1749 or self.ui.configbool('devel', 'check-locks')):
1750 1750 if self._currentlock(self._lockref) is None:
1751 1751 raise error.ProgrammingError('transaction requires locking')
1752 1752 tr = self.currenttransaction()
1753 1753 if tr is not None:
1754 1754 return tr.nest(name=desc)
1755 1755
1756 1756 # abort here if the journal already exists
1757 1757 if self.svfs.exists("journal"):
1758 1758 raise error.RepoError(
1759 1759 _("abandoned transaction found"),
1760 1760 hint=_("run 'hg recover' to clean up transaction"))
1761 1761
1762 1762 idbase = "%.40f#%f" % (random.random(), time.time())
1763 1763 ha = hex(hashlib.sha1(idbase).digest())
1764 1764 txnid = 'TXN:' + ha
1765 1765 self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid)
1766 1766
1767 1767 self._writejournal(desc)
1768 1768 renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()]
1769 1769 if report:
1770 1770 rp = report
1771 1771 else:
1772 1772 rp = self.ui.warn
1773 1773 vfsmap = {'plain': self.vfs, 'store': self.svfs} # root of .hg/
1774 1774 # we must avoid cyclic reference between repo and transaction.
1775 1775 reporef = weakref.ref(self)
1776 1776 # Code to track tag movement
1777 1777 #
1778 1778 # Since tags are all handled as file content, it is actually quite hard
1779 1779 # to track these movement from a code perspective. So we fallback to a
1780 1780 # tracking at the repository level. One could envision to track changes
1781 1781 # to the '.hgtags' file through changegroup apply but that fails to
1782 1782 # cope with case where transaction expose new heads without changegroup
1783 1783 # being involved (eg: phase movement).
1784 1784 #
1785 1785 # For now, We gate the feature behind a flag since this likely comes
1786 1786 # with performance impacts. The current code run more often than needed
1787 1787 # and do not use caches as much as it could. The current focus is on
1788 1788 # the behavior of the feature so we disable it by default. The flag
1789 1789 # will be removed when we are happy with the performance impact.
1790 1790 #
1791 1791 # Once this feature is no longer experimental move the following
1792 1792 # documentation to the appropriate help section:
1793 1793 #
1794 1794 # The ``HG_TAG_MOVED`` variable will be set if the transaction touched
1795 1795 # tags (new or changed or deleted tags). In addition the details of
1796 1796 # these changes are made available in a file at:
1797 1797 # ``REPOROOT/.hg/changes/tags.changes``.
1798 1798 # Make sure you check for HG_TAG_MOVED before reading that file as it
1799 1799 # might exist from a previous transaction even if no tag were touched
1800 1800 # in this one. Changes are recorded in a line base format::
1801 1801 #
1802 1802 # <action> <hex-node> <tag-name>\n
1803 1803 #
1804 1804 # Actions are defined as follow:
1805 1805 # "-R": tag is removed,
1806 1806 # "+A": tag is added,
1807 1807 # "-M": tag is moved (old value),
1808 1808 # "+M": tag is moved (new value),
1809 1809 tracktags = lambda x: None
1810 1810 # experimental config: experimental.hook-track-tags
1811 1811 shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags')
1812 1812 if desc != 'strip' and shouldtracktags:
1813 1813 oldheads = self.changelog.headrevs()
1814 1814 def tracktags(tr2):
1815 1815 repo = reporef()
1816 1816 oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads)
1817 1817 newheads = repo.changelog.headrevs()
1818 1818 newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads)
1819 1819 # notes: we compare lists here.
1820 1820 # As we do it only once buiding set would not be cheaper
1821 1821 changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes)
1822 1822 if changes:
1823 1823 tr2.hookargs['tag_moved'] = '1'
1824 1824 with repo.vfs('changes/tags.changes', 'w',
1825 1825 atomictemp=True) as changesfile:
1826 1826 # note: we do not register the file to the transaction
1827 1827 # because we needs it to still exist on the transaction
1828 1828 # is close (for txnclose hooks)
1829 1829 tagsmod.writediff(changesfile, changes)
1830 1830 def validate(tr2):
1831 1831 """will run pre-closing hooks"""
1832 1832 # XXX the transaction API is a bit lacking here so we take a hacky
1833 1833 # path for now
1834 1834 #
1835 1835 # We cannot add this as a "pending" hooks since the 'tr.hookargs'
1836 1836 # dict is copied before these run. In addition we needs the data
1837 1837 # available to in memory hooks too.
1838 1838 #
1839 1839 # Moreover, we also need to make sure this runs before txnclose
1840 1840 # hooks and there is no "pending" mechanism that would execute
1841 1841 # logic only if hooks are about to run.
1842 1842 #
1843 1843 # Fixing this limitation of the transaction is also needed to track
1844 1844 # other families of changes (bookmarks, phases, obsolescence).
1845 1845 #
1846 1846 # This will have to be fixed before we remove the experimental
1847 1847 # gating.
1848 1848 tracktags(tr2)
1849 1849 repo = reporef()
1850 1850 if repo.ui.configbool('experimental', 'single-head-per-branch'):
1851 1851 scmutil.enforcesinglehead(repo, tr2, desc)
1852 1852 if hook.hashook(repo.ui, 'pretxnclose-bookmark'):
1853 1853 for name, (old, new) in sorted(tr.changes['bookmarks'].items()):
1854 1854 args = tr.hookargs.copy()
1855 1855 args.update(bookmarks.preparehookargs(name, old, new))
1856 1856 repo.hook('pretxnclose-bookmark', throw=True,
1857 1857 **pycompat.strkwargs(args))
1858 1858 if hook.hashook(repo.ui, 'pretxnclose-phase'):
1859 1859 cl = repo.unfiltered().changelog
1860 1860 for rev, (old, new) in tr.changes['phases'].items():
1861 1861 args = tr.hookargs.copy()
1862 1862 node = hex(cl.node(rev))
1863 1863 args.update(phases.preparehookargs(node, old, new))
1864 1864 repo.hook('pretxnclose-phase', throw=True,
1865 1865 **pycompat.strkwargs(args))
1866 1866
1867 1867 repo.hook('pretxnclose', throw=True,
1868 1868 **pycompat.strkwargs(tr.hookargs))
1869 1869 def releasefn(tr, success):
1870 1870 repo = reporef()
1871 1871 if success:
1872 1872 # this should be explicitly invoked here, because
1873 1873 # in-memory changes aren't written out at closing
1874 1874 # transaction, if tr.addfilegenerator (via
1875 1875 # dirstate.write or so) isn't invoked while
1876 1876 # transaction running
1877 1877 repo.dirstate.write(None)
1878 1878 else:
1879 1879 # discard all changes (including ones already written
1880 1880 # out) in this transaction
1881 1881 narrowspec.restorebackup(self, 'journal.narrowspec')
1882 1882 narrowspec.restorewcbackup(self, 'journal.narrowspec.dirstate')
1883 1883 repo.dirstate.restorebackup(None, 'journal.dirstate')
1884 1884
1885 1885 repo.invalidate(clearfilecache=True)
1886 1886
1887 1887 tr = transaction.transaction(rp, self.svfs, vfsmap,
1888 1888 "journal",
1889 1889 "undo",
1890 1890 aftertrans(renames),
1891 1891 self.store.createmode,
1892 1892 validator=validate,
1893 1893 releasefn=releasefn,
1894 1894 checkambigfiles=_cachedfiles,
1895 1895 name=desc)
1896 1896 tr.changes['origrepolen'] = len(self)
1897 1897 tr.changes['obsmarkers'] = set()
1898 1898 tr.changes['phases'] = {}
1899 1899 tr.changes['bookmarks'] = {}
1900 1900
1901 1901 tr.hookargs['txnid'] = txnid
1902 1902 tr.hookargs['txnname'] = desc
1903 1903 # note: writing the fncache only during finalize mean that the file is
1904 1904 # outdated when running hooks. As fncache is used for streaming clone,
1905 1905 # this is not expected to break anything that happen during the hooks.
1906 1906 tr.addfinalize('flush-fncache', self.store.write)
1907 1907 def txnclosehook(tr2):
1908 1908 """To be run if transaction is successful, will schedule a hook run
1909 1909 """
1910 1910 # Don't reference tr2 in hook() so we don't hold a reference.
1911 1911 # This reduces memory consumption when there are multiple
1912 1912 # transactions per lock. This can likely go away if issue5045
1913 1913 # fixes the function accumulation.
1914 1914 hookargs = tr2.hookargs
1915 1915
1916 1916 def hookfunc():
1917 1917 repo = reporef()
1918 1918 if hook.hashook(repo.ui, 'txnclose-bookmark'):
1919 1919 bmchanges = sorted(tr.changes['bookmarks'].items())
1920 1920 for name, (old, new) in bmchanges:
1921 1921 args = tr.hookargs.copy()
1922 1922 args.update(bookmarks.preparehookargs(name, old, new))
1923 1923 repo.hook('txnclose-bookmark', throw=False,
1924 1924 **pycompat.strkwargs(args))
1925 1925
1926 1926 if hook.hashook(repo.ui, 'txnclose-phase'):
1927 1927 cl = repo.unfiltered().changelog
1928 1928 phasemv = sorted(tr.changes['phases'].items())
1929 1929 for rev, (old, new) in phasemv:
1930 1930 args = tr.hookargs.copy()
1931 1931 node = hex(cl.node(rev))
1932 1932 args.update(phases.preparehookargs(node, old, new))
1933 1933 repo.hook('txnclose-phase', throw=False,
1934 1934 **pycompat.strkwargs(args))
1935 1935
1936 1936 repo.hook('txnclose', throw=False,
1937 1937 **pycompat.strkwargs(hookargs))
1938 1938 reporef()._afterlock(hookfunc)
1939 1939 tr.addfinalize('txnclose-hook', txnclosehook)
1940 1940 # Include a leading "-" to make it happen before the transaction summary
1941 1941 # reports registered via scmutil.registersummarycallback() whose names
1942 1942 # are 00-txnreport etc. That way, the caches will be warm when the
1943 1943 # callbacks run.
1944 1944 tr.addpostclose('-warm-cache', self._buildcacheupdater(tr))
1945 1945 def txnaborthook(tr2):
1946 1946 """To be run if transaction is aborted
1947 1947 """
1948 1948 reporef().hook('txnabort', throw=False,
1949 1949 **pycompat.strkwargs(tr2.hookargs))
1950 1950 tr.addabort('txnabort-hook', txnaborthook)
1951 1951 # avoid eager cache invalidation. in-memory data should be identical
1952 1952 # to stored data if transaction has no error.
1953 1953 tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats)
1954 1954 self._transref = weakref.ref(tr)
1955 1955 scmutil.registersummarycallback(self, tr, desc)
1956 1956 return tr
1957 1957
1958 1958 def _journalfiles(self):
1959 1959 return ((self.svfs, 'journal'),
1960 1960 (self.svfs, 'journal.narrowspec'),
1961 1961 (self.vfs, 'journal.narrowspec.dirstate'),
1962 1962 (self.vfs, 'journal.dirstate'),
1963 1963 (self.vfs, 'journal.branch'),
1964 1964 (self.vfs, 'journal.desc'),
1965 1965 (self.vfs, 'journal.bookmarks'),
1966 1966 (self.svfs, 'journal.phaseroots'))
1967 1967
1968 1968 def undofiles(self):
1969 1969 return [(vfs, undoname(x)) for vfs, x in self._journalfiles()]
1970 1970
1971 1971 @unfilteredmethod
1972 1972 def _writejournal(self, desc):
1973 1973 self.dirstate.savebackup(None, 'journal.dirstate')
1974 1974 narrowspec.savewcbackup(self, 'journal.narrowspec.dirstate')
1975 1975 narrowspec.savebackup(self, 'journal.narrowspec')
1976 1976 self.vfs.write("journal.branch",
1977 1977 encoding.fromlocal(self.dirstate.branch()))
1978 1978 self.vfs.write("journal.desc",
1979 1979 "%d\n%s\n" % (len(self), desc))
1980 1980 self.vfs.write("journal.bookmarks",
1981 1981 self.vfs.tryread("bookmarks"))
1982 1982 self.svfs.write("journal.phaseroots",
1983 1983 self.svfs.tryread("phaseroots"))
1984 1984
1985 1985 def recover(self):
1986 1986 with self.lock():
1987 1987 if self.svfs.exists("journal"):
1988 1988 self.ui.status(_("rolling back interrupted transaction\n"))
1989 1989 vfsmap = {'': self.svfs,
1990 1990 'plain': self.vfs,}
1991 1991 transaction.rollback(self.svfs, vfsmap, "journal",
1992 1992 self.ui.warn,
1993 1993 checkambigfiles=_cachedfiles)
1994 1994 self.invalidate()
1995 1995 return True
1996 1996 else:
1997 1997 self.ui.warn(_("no interrupted transaction available\n"))
1998 1998 return False
1999 1999
2000 2000 def rollback(self, dryrun=False, force=False):
2001 2001 wlock = lock = dsguard = None
2002 2002 try:
2003 2003 wlock = self.wlock()
2004 2004 lock = self.lock()
2005 2005 if self.svfs.exists("undo"):
2006 2006 dsguard = dirstateguard.dirstateguard(self, 'rollback')
2007 2007
2008 2008 return self._rollback(dryrun, force, dsguard)
2009 2009 else:
2010 2010 self.ui.warn(_("no rollback information available\n"))
2011 2011 return 1
2012 2012 finally:
2013 2013 release(dsguard, lock, wlock)
2014 2014
2015 2015 @unfilteredmethod # Until we get smarter cache management
2016 2016 def _rollback(self, dryrun, force, dsguard):
2017 2017 ui = self.ui
2018 2018 try:
2019 2019 args = self.vfs.read('undo.desc').splitlines()
2020 2020 (oldlen, desc, detail) = (int(args[0]), args[1], None)
2021 2021 if len(args) >= 3:
2022 2022 detail = args[2]
2023 2023 oldtip = oldlen - 1
2024 2024
2025 2025 if detail and ui.verbose:
2026 2026 msg = (_('repository tip rolled back to revision %d'
2027 2027 ' (undo %s: %s)\n')
2028 2028 % (oldtip, desc, detail))
2029 2029 else:
2030 2030 msg = (_('repository tip rolled back to revision %d'
2031 2031 ' (undo %s)\n')
2032 2032 % (oldtip, desc))
2033 2033 except IOError:
2034 2034 msg = _('rolling back unknown transaction\n')
2035 2035 desc = None
2036 2036
2037 2037 if not force and self['.'] != self['tip'] and desc == 'commit':
2038 2038 raise error.Abort(
2039 2039 _('rollback of last commit while not checked out '
2040 2040 'may lose data'), hint=_('use -f to force'))
2041 2041
2042 2042 ui.status(msg)
2043 2043 if dryrun:
2044 2044 return 0
2045 2045
2046 2046 parents = self.dirstate.parents()
2047 2047 self.destroying()
2048 2048 vfsmap = {'plain': self.vfs, '': self.svfs}
2049 2049 transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn,
2050 2050 checkambigfiles=_cachedfiles)
2051 2051 if self.vfs.exists('undo.bookmarks'):
2052 2052 self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True)
2053 2053 if self.svfs.exists('undo.phaseroots'):
2054 2054 self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True)
2055 2055 self.invalidate()
2056 2056
2057 2057 parentgone = any(p not in self.changelog.nodemap for p in parents)
2058 2058 if parentgone:
2059 2059 # prevent dirstateguard from overwriting already restored one
2060 2060 dsguard.close()
2061 2061
2062 2062 narrowspec.restorebackup(self, 'undo.narrowspec')
2063 2063 narrowspec.restorewcbackup(self, 'undo.narrowspec.dirstate')
2064 2064 self.dirstate.restorebackup(None, 'undo.dirstate')
2065 2065 try:
2066 2066 branch = self.vfs.read('undo.branch')
2067 2067 self.dirstate.setbranch(encoding.tolocal(branch))
2068 2068 except IOError:
2069 2069 ui.warn(_('named branch could not be reset: '
2070 2070 'current branch is still \'%s\'\n')
2071 2071 % self.dirstate.branch())
2072 2072
2073 2073 parents = tuple([p.rev() for p in self[None].parents()])
2074 2074 if len(parents) > 1:
2075 2075 ui.status(_('working directory now based on '
2076 2076 'revisions %d and %d\n') % parents)
2077 2077 else:
2078 2078 ui.status(_('working directory now based on '
2079 2079 'revision %d\n') % parents)
2080 2080 mergemod.mergestate.clean(self, self['.'].node())
2081 2081
2082 2082 # TODO: if we know which new heads may result from this rollback, pass
2083 2083 # them to destroy(), which will prevent the branchhead cache from being
2084 2084 # invalidated.
2085 2085 self.destroyed()
2086 2086 return 0
2087 2087
2088 2088 def _buildcacheupdater(self, newtransaction):
2089 2089 """called during transaction to build the callback updating cache
2090 2090
2091 2091 Lives on the repository to help extension who might want to augment
2092 2092 this logic. For this purpose, the created transaction is passed to the
2093 2093 method.
2094 2094 """
2095 2095 # we must avoid cyclic reference between repo and transaction.
2096 2096 reporef = weakref.ref(self)
2097 2097 def updater(tr):
2098 2098 repo = reporef()
2099 2099 repo.updatecaches(tr)
2100 2100 return updater
2101 2101
2102 2102 @unfilteredmethod
2103 2103 def updatecaches(self, tr=None, full=False):
2104 2104 """warm appropriate caches
2105 2105
2106 2106 If this function is called after a transaction closed. The transaction
2107 2107 will be available in the 'tr' argument. This can be used to selectively
2108 2108 update caches relevant to the changes in that transaction.
2109 2109
2110 2110 If 'full' is set, make sure all caches the function knows about have
2111 2111 up-to-date data. Even the ones usually loaded more lazily.
2112 2112 """
2113 2113 if tr is not None and tr.hookargs.get('source') == 'strip':
2114 2114 # During strip, many caches are invalid but
2115 2115 # later call to `destroyed` will refresh them.
2116 2116 return
2117 2117
2118 2118 if tr is None or tr.changes['origrepolen'] < len(self):
2119 2119 # accessing the 'ser ved' branchmap should refresh all the others,
2120 2120 self.ui.debug('updating the branch cache\n')
2121 2121 self.filtered('served').branchmap()
2122 2122 self.filtered('served.hidden').branchmap()
2123 2123
2124 2124 if full:
2125 2125 unfi = self.unfiltered()
2126 2126 rbc = unfi.revbranchcache()
2127 2127 for r in unfi.changelog:
2128 2128 rbc.branchinfo(r)
2129 2129 rbc.write()
2130 2130
2131 2131 # ensure the working copy parents are in the manifestfulltextcache
2132 2132 for ctx in self['.'].parents():
2133 2133 ctx.manifest() # accessing the manifest is enough
2134 2134
2135 2135 # accessing fnode cache warms the cache
2136 2136 tagsmod.fnoderevs(self.ui, unfi, unfi.changelog.revs())
2137 2137 # accessing tags warm the cache
2138 2138 self.tags()
2139 2139 self.filtered('served').tags()
2140 2140
2141 2141 def invalidatecaches(self):
2142 2142
2143 2143 if r'_tagscache' in vars(self):
2144 2144 # can't use delattr on proxy
2145 2145 del self.__dict__[r'_tagscache']
2146 2146
2147 2147 self._branchcaches.clear()
2148 2148 self.invalidatevolatilesets()
2149 2149 self._sparsesignaturecache.clear()
2150 2150
2151 2151 def invalidatevolatilesets(self):
2152 2152 self.filteredrevcache.clear()
2153 2153 obsolete.clearobscaches(self)
2154 2154
2155 2155 def invalidatedirstate(self):
2156 2156 '''Invalidates the dirstate, causing the next call to dirstate
2157 2157 to check if it was modified since the last time it was read,
2158 2158 rereading it if it has.
2159 2159
2160 2160 This is different to dirstate.invalidate() that it doesn't always
2161 2161 rereads the dirstate. Use dirstate.invalidate() if you want to
2162 2162 explicitly read the dirstate again (i.e. restoring it to a previous
2163 2163 known good state).'''
2164 2164 if hasunfilteredcache(self, r'dirstate'):
2165 2165 for k in self.dirstate._filecache:
2166 2166 try:
2167 2167 delattr(self.dirstate, k)
2168 2168 except AttributeError:
2169 2169 pass
2170 2170 delattr(self.unfiltered(), r'dirstate')
2171 2171
2172 2172 def invalidate(self, clearfilecache=False):
2173 2173 '''Invalidates both store and non-store parts other than dirstate
2174 2174
2175 2175 If a transaction is running, invalidation of store is omitted,
2176 2176 because discarding in-memory changes might cause inconsistency
2177 2177 (e.g. incomplete fncache causes unintentional failure, but
2178 2178 redundant one doesn't).
2179 2179 '''
2180 2180 unfiltered = self.unfiltered() # all file caches are stored unfiltered
2181 2181 for k in list(self._filecache.keys()):
2182 2182 # dirstate is invalidated separately in invalidatedirstate()
2183 2183 if k == 'dirstate':
2184 2184 continue
2185 2185 if (k == 'changelog' and
2186 2186 self.currenttransaction() and
2187 2187 self.changelog._delayed):
2188 2188 # The changelog object may store unwritten revisions. We don't
2189 2189 # want to lose them.
2190 2190 # TODO: Solve the problem instead of working around it.
2191 2191 continue
2192 2192
2193 2193 if clearfilecache:
2194 2194 del self._filecache[k]
2195 2195 try:
2196 2196 delattr(unfiltered, k)
2197 2197 except AttributeError:
2198 2198 pass
2199 2199 self.invalidatecaches()
2200 2200 if not self.currenttransaction():
2201 2201 # TODO: Changing contents of store outside transaction
2202 2202 # causes inconsistency. We should make in-memory store
2203 2203 # changes detectable, and abort if changed.
2204 2204 self.store.invalidatecaches()
2205 2205
2206 2206 def invalidateall(self):
2207 2207 '''Fully invalidates both store and non-store parts, causing the
2208 2208 subsequent operation to reread any outside changes.'''
2209 2209 # extension should hook this to invalidate its caches
2210 2210 self.invalidate()
2211 2211 self.invalidatedirstate()
2212 2212
2213 2213 @unfilteredmethod
2214 2214 def _refreshfilecachestats(self, tr):
2215 2215 """Reload stats of cached files so that they are flagged as valid"""
2216 2216 for k, ce in self._filecache.items():
2217 2217 k = pycompat.sysstr(k)
2218 2218 if k == r'dirstate' or k not in self.__dict__:
2219 2219 continue
2220 2220 ce.refresh()
2221 2221
2222 2222 def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc,
2223 2223 inheritchecker=None, parentenvvar=None):
2224 2224 parentlock = None
2225 2225 # the contents of parentenvvar are used by the underlying lock to
2226 2226 # determine whether it can be inherited
2227 2227 if parentenvvar is not None:
2228 2228 parentlock = encoding.environ.get(parentenvvar)
2229 2229
2230 2230 timeout = 0
2231 2231 warntimeout = 0
2232 2232 if wait:
2233 2233 timeout = self.ui.configint("ui", "timeout")
2234 2234 warntimeout = self.ui.configint("ui", "timeout.warn")
2235 2235 # internal config: ui.signal-safe-lock
2236 2236 signalsafe = self.ui.configbool('ui', 'signal-safe-lock')
2237 2237
2238 2238 l = lockmod.trylock(self.ui, vfs, lockname, timeout, warntimeout,
2239 2239 releasefn=releasefn,
2240 2240 acquirefn=acquirefn, desc=desc,
2241 2241 inheritchecker=inheritchecker,
2242 2242 parentlock=parentlock,
2243 2243 signalsafe=signalsafe)
2244 2244 return l
2245 2245
2246 2246 def _afterlock(self, callback):
2247 2247 """add a callback to be run when the repository is fully unlocked
2248 2248
2249 2249 The callback will be executed when the outermost lock is released
2250 2250 (with wlock being higher level than 'lock')."""
2251 2251 for ref in (self._wlockref, self._lockref):
2252 2252 l = ref and ref()
2253 2253 if l and l.held:
2254 2254 l.postrelease.append(callback)
2255 2255 break
2256 2256 else: # no lock have been found.
2257 2257 callback()
2258 2258
2259 2259 def lock(self, wait=True):
2260 2260 '''Lock the repository store (.hg/store) and return a weak reference
2261 2261 to the lock. Use this before modifying the store (e.g. committing or
2262 2262 stripping). If you are opening a transaction, get a lock as well.)
2263 2263
2264 2264 If both 'lock' and 'wlock' must be acquired, ensure you always acquires
2265 2265 'wlock' first to avoid a dead-lock hazard.'''
2266 2266 l = self._currentlock(self._lockref)
2267 2267 if l is not None:
2268 2268 l.lock()
2269 2269 return l
2270 2270
2271 2271 l = self._lock(vfs=self.svfs,
2272 2272 lockname="lock",
2273 2273 wait=wait,
2274 2274 releasefn=None,
2275 2275 acquirefn=self.invalidate,
2276 2276 desc=_('repository %s') % self.origroot)
2277 2277 self._lockref = weakref.ref(l)
2278 2278 return l
2279 2279
2280 2280 def _wlockchecktransaction(self):
2281 2281 if self.currenttransaction() is not None:
2282 2282 raise error.LockInheritanceContractViolation(
2283 2283 'wlock cannot be inherited in the middle of a transaction')
2284 2284
2285 2285 def wlock(self, wait=True):
2286 2286 '''Lock the non-store parts of the repository (everything under
2287 2287 .hg except .hg/store) and return a weak reference to the lock.
2288 2288
2289 2289 Use this before modifying files in .hg.
2290 2290
2291 2291 If both 'lock' and 'wlock' must be acquired, ensure you always acquires
2292 2292 'wlock' first to avoid a dead-lock hazard.'''
2293 2293 l = self._wlockref and self._wlockref()
2294 2294 if l is not None and l.held:
2295 2295 l.lock()
2296 2296 return l
2297 2297
2298 2298 # We do not need to check for non-waiting lock acquisition. Such
2299 2299 # acquisition would not cause dead-lock as they would just fail.
2300 2300 if wait and (self.ui.configbool('devel', 'all-warnings')
2301 2301 or self.ui.configbool('devel', 'check-locks')):
2302 2302 if self._currentlock(self._lockref) is not None:
2303 2303 self.ui.develwarn('"wlock" acquired after "lock"')
2304 2304
2305 2305 def unlock():
2306 2306 if self.dirstate.pendingparentchange():
2307 2307 self.dirstate.invalidate()
2308 2308 else:
2309 2309 self.dirstate.write(None)
2310 2310
2311 2311 self._filecache['dirstate'].refresh()
2312 2312
2313 2313 l = self._lock(self.vfs, "wlock", wait, unlock,
2314 2314 self.invalidatedirstate, _('working directory of %s') %
2315 2315 self.origroot,
2316 2316 inheritchecker=self._wlockchecktransaction,
2317 2317 parentenvvar='HG_WLOCK_LOCKER')
2318 2318 self._wlockref = weakref.ref(l)
2319 2319 return l
2320 2320
2321 2321 def _currentlock(self, lockref):
2322 2322 """Returns the lock if it's held, or None if it's not."""
2323 2323 if lockref is None:
2324 2324 return None
2325 2325 l = lockref()
2326 2326 if l is None or not l.held:
2327 2327 return None
2328 2328 return l
2329 2329
2330 2330 def currentwlock(self):
2331 2331 """Returns the wlock if it's held, or None if it's not."""
2332 2332 return self._currentlock(self._wlockref)
2333 2333
2334 2334 def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist,
2335 2335 includecopymeta):
2336 2336 """
2337 2337 commit an individual file as part of a larger transaction
2338 2338 """
2339 2339
2340 2340 fname = fctx.path()
2341 2341 fparent1 = manifest1.get(fname, nullid)
2342 2342 fparent2 = manifest2.get(fname, nullid)
2343 2343 if isinstance(fctx, context.filectx):
2344 2344 node = fctx.filenode()
2345 2345 if node in [fparent1, fparent2]:
2346 2346 self.ui.debug('reusing %s filelog entry\n' % fname)
2347 2347 if manifest1.flags(fname) != fctx.flags():
2348 2348 changelist.append(fname)
2349 2349 return node
2350 2350
2351 2351 flog = self.file(fname)
2352 2352 meta = {}
2353 2353 cfname = fctx.copysource()
2354 2354 if cfname and cfname != fname:
2355 2355 # Mark the new revision of this file as a copy of another
2356 2356 # file. This copy data will effectively act as a parent
2357 2357 # of this new revision. If this is a merge, the first
2358 2358 # parent will be the nullid (meaning "look up the copy data")
2359 2359 # and the second one will be the other parent. For example:
2360 2360 #
2361 2361 # 0 --- 1 --- 3 rev1 changes file foo
2362 2362 # \ / rev2 renames foo to bar and changes it
2363 2363 # \- 2 -/ rev3 should have bar with all changes and
2364 2364 # should record that bar descends from
2365 2365 # bar in rev2 and foo in rev1
2366 2366 #
2367 2367 # this allows this merge to succeed:
2368 2368 #
2369 2369 # 0 --- 1 --- 3 rev4 reverts the content change from rev2
2370 2370 # \ / merging rev3 and rev4 should use bar@rev2
2371 2371 # \- 2 --- 4 as the merge base
2372 2372 #
2373 2373
2374 2374 cnode = manifest1.get(cfname)
2375 2375 newfparent = fparent2
2376 2376
2377 2377 if manifest2: # branch merge
2378 2378 if fparent2 == nullid or cnode is None: # copied on remote side
2379 2379 if cfname in manifest2:
2380 2380 cnode = manifest2[cfname]
2381 2381 newfparent = fparent1
2382 2382
2383 2383 # Here, we used to search backwards through history to try to find
2384 2384 # where the file copy came from if the source of a copy was not in
2385 2385 # the parent directory. However, this doesn't actually make sense to
2386 2386 # do (what does a copy from something not in your working copy even
2387 2387 # mean?) and it causes bugs (eg, issue4476). Instead, we will warn
2388 2388 # the user that copy information was dropped, so if they didn't
2389 2389 # expect this outcome it can be fixed, but this is the correct
2390 2390 # behavior in this circumstance.
2391 2391
2392 2392 if cnode:
2393 2393 self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(cnode)))
2394 2394 if includecopymeta:
2395 2395 meta["copy"] = cfname
2396 2396 meta["copyrev"] = hex(cnode)
2397 2397 fparent1, fparent2 = nullid, newfparent
2398 2398 else:
2399 2399 self.ui.warn(_("warning: can't find ancestor for '%s' "
2400 2400 "copied from '%s'!\n") % (fname, cfname))
2401 2401
2402 2402 elif fparent1 == nullid:
2403 2403 fparent1, fparent2 = fparent2, nullid
2404 2404 elif fparent2 != nullid:
2405 2405 # is one parent an ancestor of the other?
2406 2406 fparentancestors = flog.commonancestorsheads(fparent1, fparent2)
2407 2407 if fparent1 in fparentancestors:
2408 2408 fparent1, fparent2 = fparent2, nullid
2409 2409 elif fparent2 in fparentancestors:
2410 2410 fparent2 = nullid
2411 2411
2412 2412 # is the file changed?
2413 2413 text = fctx.data()
2414 2414 if fparent2 != nullid or flog.cmp(fparent1, text) or meta:
2415 2415 changelist.append(fname)
2416 2416 return flog.add(text, meta, tr, linkrev, fparent1, fparent2)
2417 2417 # are just the flags changed during merge?
2418 2418 elif fname in manifest1 and manifest1.flags(fname) != fctx.flags():
2419 2419 changelist.append(fname)
2420 2420
2421 2421 return fparent1
2422 2422
2423 2423 def checkcommitpatterns(self, wctx, vdirs, match, status, fail):
2424 2424 """check for commit arguments that aren't committable"""
2425 2425 if match.isexact() or match.prefix():
2426 2426 matched = set(status.modified + status.added + status.removed)
2427 2427
2428 2428 for f in match.files():
2429 2429 f = self.dirstate.normalize(f)
2430 2430 if f == '.' or f in matched or f in wctx.substate:
2431 2431 continue
2432 2432 if f in status.deleted:
2433 2433 fail(f, _('file not found!'))
2434 2434 if f in vdirs: # visited directory
2435 2435 d = f + '/'
2436 2436 for mf in matched:
2437 2437 if mf.startswith(d):
2438 2438 break
2439 2439 else:
2440 2440 fail(f, _("no match under directory!"))
2441 2441 elif f not in self.dirstate:
2442 2442 fail(f, _("file not tracked!"))
2443 2443
2444 2444 @unfilteredmethod
2445 2445 def commit(self, text="", user=None, date=None, match=None, force=False,
2446 2446 editor=False, extra=None):
2447 2447 """Add a new revision to current repository.
2448 2448
2449 2449 Revision information is gathered from the working directory,
2450 2450 match can be used to filter the committed files. If editor is
2451 2451 supplied, it is called to get a commit message.
2452 2452 """
2453 2453 if extra is None:
2454 2454 extra = {}
2455 2455
2456 2456 def fail(f, msg):
2457 2457 raise error.Abort('%s: %s' % (f, msg))
2458 2458
2459 2459 if not match:
2460 2460 match = matchmod.always()
2461 2461
2462 2462 if not force:
2463 2463 vdirs = []
2464 2464 match.explicitdir = vdirs.append
2465 2465 match.bad = fail
2466 2466
2467 2467 # lock() for recent changelog (see issue4368)
2468 2468 with self.wlock(), self.lock():
2469 2469 wctx = self[None]
2470 2470 merge = len(wctx.parents()) > 1
2471 2471
2472 2472 if not force and merge and not match.always():
2473 2473 raise error.Abort(_('cannot partially commit a merge '
2474 2474 '(do not specify files or patterns)'))
2475 2475
2476 2476 status = self.status(match=match, clean=force)
2477 2477 if force:
2478 2478 status.modified.extend(status.clean) # mq may commit clean files
2479 2479
2480 2480 # check subrepos
2481 2481 subs, commitsubs, newstate = subrepoutil.precommit(
2482 2482 self.ui, wctx, status, match, force=force)
2483 2483
2484 2484 # make sure all explicit patterns are matched
2485 2485 if not force:
2486 2486 self.checkcommitpatterns(wctx, vdirs, match, status, fail)
2487 2487
2488 2488 cctx = context.workingcommitctx(self, status,
2489 2489 text, user, date, extra)
2490 2490
2491 2491 # internal config: ui.allowemptycommit
2492 2492 allowemptycommit = (wctx.branch() != wctx.p1().branch()
2493 2493 or extra.get('close') or merge or cctx.files()
2494 2494 or self.ui.configbool('ui', 'allowemptycommit'))
2495 2495 if not allowemptycommit:
2496 2496 return None
2497 2497
2498 2498 if merge and cctx.deleted():
2499 2499 raise error.Abort(_("cannot commit merge with missing files"))
2500 2500
2501 2501 ms = mergemod.mergestate.read(self)
2502 2502 mergeutil.checkunresolved(ms)
2503 2503
2504 2504 if editor:
2505 2505 cctx._text = editor(self, cctx, subs)
2506 2506 edited = (text != cctx._text)
2507 2507
2508 2508 # Save commit message in case this transaction gets rolled back
2509 2509 # (e.g. by a pretxncommit hook). Leave the content alone on
2510 2510 # the assumption that the user will use the same editor again.
2511 2511 msgfn = self.savecommitmessage(cctx._text)
2512 2512
2513 2513 # commit subs and write new state
2514 2514 if subs:
2515 2515 uipathfn = scmutil.getuipathfn(self)
2516 2516 for s in sorted(commitsubs):
2517 2517 sub = wctx.sub(s)
2518 2518 self.ui.status(_('committing subrepository %s\n') %
2519 2519 uipathfn(subrepoutil.subrelpath(sub)))
2520 2520 sr = sub.commit(cctx._text, user, date)
2521 2521 newstate[s] = (newstate[s][0], sr)
2522 2522 subrepoutil.writestate(self, newstate)
2523 2523
2524 2524 p1, p2 = self.dirstate.parents()
2525 2525 hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '')
2526 2526 try:
2527 2527 self.hook("precommit", throw=True, parent1=hookp1,
2528 2528 parent2=hookp2)
2529 2529 with self.transaction('commit'):
2530 2530 ret = self.commitctx(cctx, True)
2531 2531 # update bookmarks, dirstate and mergestate
2532 2532 bookmarks.update(self, [p1, p2], ret)
2533 2533 cctx.markcommitted(ret)
2534 2534 ms.reset()
2535 2535 except: # re-raises
2536 2536 if edited:
2537 2537 self.ui.write(
2538 2538 _('note: commit message saved in %s\n') % msgfn)
2539 2539 raise
2540 2540
2541 2541 def commithook():
2542 2542 # hack for command that use a temporary commit (eg: histedit)
2543 2543 # temporary commit got stripped before hook release
2544 2544 if self.changelog.hasnode(ret):
2545 2545 self.hook("commit", node=hex(ret), parent1=hookp1,
2546 2546 parent2=hookp2)
2547 2547 self._afterlock(commithook)
2548 2548 return ret
2549 2549
2550 2550 @unfilteredmethod
2551 2551 def commitctx(self, ctx, error=False):
2552 2552 """Add a new revision to current repository.
2553 2553 Revision information is passed via the context argument.
2554 2554
2555 2555 ctx.files() should list all files involved in this commit, i.e.
2556 2556 modified/added/removed files. On merge, it may be wider than the
2557 2557 ctx.files() to be committed, since any file nodes derived directly
2558 2558 from p1 or p2 are excluded from the committed ctx.files().
2559 2559 """
2560 2560
2561 2561 p1, p2 = ctx.p1(), ctx.p2()
2562 2562 user = ctx.user()
2563 2563
2564 2564 writecopiesto = self.ui.config('experimental', 'copies.write-to')
2565 2565 writefilecopymeta = writecopiesto != 'changeset-only'
2566 2566 p1copies, p2copies = None, None
2567 2567 if writecopiesto in ('changeset-only', 'compatibility'):
2568 2568 p1copies = ctx.p1copies()
2569 2569 p2copies = ctx.p2copies()
2570 2570 with self.lock(), self.transaction("commit") as tr:
2571 2571 trp = weakref.proxy(tr)
2572 2572
2573 2573 if ctx.manifestnode():
2574 2574 # reuse an existing manifest revision
2575 2575 self.ui.debug('reusing known manifest\n')
2576 2576 mn = ctx.manifestnode()
2577 2577 files = ctx.files()
2578 2578 elif ctx.files():
2579 2579 m1ctx = p1.manifestctx()
2580 2580 m2ctx = p2.manifestctx()
2581 2581 mctx = m1ctx.copy()
2582 2582
2583 2583 m = mctx.read()
2584 2584 m1 = m1ctx.read()
2585 2585 m2 = m2ctx.read()
2586 2586
2587 2587 # check in files
2588 2588 added = []
2589 2589 changed = []
2590 2590 removed = list(ctx.removed())
2591 2591 linkrev = len(self)
2592 2592 self.ui.note(_("committing files:\n"))
2593 2593 uipathfn = scmutil.getuipathfn(self)
2594 2594 for f in sorted(ctx.modified() + ctx.added()):
2595 2595 self.ui.note(uipathfn(f) + "\n")
2596 2596 try:
2597 2597 fctx = ctx[f]
2598 2598 if fctx is None:
2599 2599 removed.append(f)
2600 2600 else:
2601 2601 added.append(f)
2602 2602 m[f] = self._filecommit(fctx, m1, m2, linkrev,
2603 2603 trp, changed,
2604 2604 writefilecopymeta)
2605 2605 m.setflag(f, fctx.flags())
2606 2606 except OSError:
2607 2607 self.ui.warn(_("trouble committing %s!\n") %
2608 2608 uipathfn(f))
2609 2609 raise
2610 2610 except IOError as inst:
2611 2611 errcode = getattr(inst, 'errno', errno.ENOENT)
2612 2612 if error or errcode and errcode != errno.ENOENT:
2613 2613 self.ui.warn(_("trouble committing %s!\n") %
2614 2614 uipathfn(f))
2615 2615 raise
2616 2616
2617 2617 # update manifest
2618 2618 removed = [f for f in sorted(removed) if f in m1 or f in m2]
2619 2619 drop = [f for f in removed if f in m]
2620 2620 for f in drop:
2621 2621 del m[f]
2622 2622 files = changed + removed
2623 2623 md = None
2624 2624 if not files:
2625 2625 # if no "files" actually changed in terms of the changelog,
2626 2626 # try hard to detect unmodified manifest entry so that the
2627 2627 # exact same commit can be reproduced later on convert.
2628 2628 md = m1.diff(m, scmutil.matchfiles(self, ctx.files()))
2629 2629 if not files and md:
2630 2630 self.ui.debug('not reusing manifest (no file change in '
2631 2631 'changelog, but manifest differs)\n')
2632 2632 if files or md:
2633 2633 self.ui.note(_("committing manifest\n"))
2634 2634 # we're using narrowmatch here since it's already applied at
2635 2635 # other stages (such as dirstate.walk), so we're already
2636 2636 # ignoring things outside of narrowspec in most cases. The
2637 2637 # one case where we might have files outside the narrowspec
2638 2638 # at this point is merges, and we already error out in the
2639 2639 # case where the merge has files outside of the narrowspec,
2640 2640 # so this is safe.
2641 2641 mn = mctx.write(trp, linkrev,
2642 2642 p1.manifestnode(), p2.manifestnode(),
2643 2643 added, drop, match=self.narrowmatch())
2644 2644 else:
2645 self.ui.debug('reusing manifest form p1 (listed files '
2645 self.ui.debug('reusing manifest from p1 (listed files '
2646 2646 'actually unchanged)\n')
2647 2647 mn = p1.manifestnode()
2648 2648 else:
2649 2649 self.ui.debug('reusing manifest from p1 (no file change)\n')
2650 2650 mn = p1.manifestnode()
2651 2651 files = []
2652 2652
2653 2653 # update changelog
2654 2654 self.ui.note(_("committing changelog\n"))
2655 2655 self.changelog.delayupdate(tr)
2656 2656 n = self.changelog.add(mn, files, ctx.description(),
2657 2657 trp, p1.node(), p2.node(),
2658 2658 user, ctx.date(), ctx.extra().copy(),
2659 2659 p1copies, p2copies)
2660 2660 xp1, xp2 = p1.hex(), p2 and p2.hex() or ''
2661 2661 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
2662 2662 parent2=xp2)
2663 2663 # set the new commit is proper phase
2664 2664 targetphase = subrepoutil.newcommitphase(self.ui, ctx)
2665 2665 if targetphase:
2666 2666 # retract boundary do not alter parent changeset.
2667 2667 # if a parent have higher the resulting phase will
2668 2668 # be compliant anyway
2669 2669 #
2670 2670 # if minimal phase was 0 we don't need to retract anything
2671 2671 phases.registernew(self, tr, targetphase, [n])
2672 2672 return n
2673 2673
2674 2674 @unfilteredmethod
2675 2675 def destroying(self):
2676 2676 '''Inform the repository that nodes are about to be destroyed.
2677 2677 Intended for use by strip and rollback, so there's a common
2678 2678 place for anything that has to be done before destroying history.
2679 2679
2680 2680 This is mostly useful for saving state that is in memory and waiting
2681 2681 to be flushed when the current lock is released. Because a call to
2682 2682 destroyed is imminent, the repo will be invalidated causing those
2683 2683 changes to stay in memory (waiting for the next unlock), or vanish
2684 2684 completely.
2685 2685 '''
2686 2686 # When using the same lock to commit and strip, the phasecache is left
2687 2687 # dirty after committing. Then when we strip, the repo is invalidated,
2688 2688 # causing those changes to disappear.
2689 2689 if '_phasecache' in vars(self):
2690 2690 self._phasecache.write()
2691 2691
2692 2692 @unfilteredmethod
2693 2693 def destroyed(self):
2694 2694 '''Inform the repository that nodes have been destroyed.
2695 2695 Intended for use by strip and rollback, so there's a common
2696 2696 place for anything that has to be done after destroying history.
2697 2697 '''
2698 2698 # When one tries to:
2699 2699 # 1) destroy nodes thus calling this method (e.g. strip)
2700 2700 # 2) use phasecache somewhere (e.g. commit)
2701 2701 #
2702 2702 # then 2) will fail because the phasecache contains nodes that were
2703 2703 # removed. We can either remove phasecache from the filecache,
2704 2704 # causing it to reload next time it is accessed, or simply filter
2705 2705 # the removed nodes now and write the updated cache.
2706 2706 self._phasecache.filterunknown(self)
2707 2707 self._phasecache.write()
2708 2708
2709 2709 # refresh all repository caches
2710 2710 self.updatecaches()
2711 2711
2712 2712 # Ensure the persistent tag cache is updated. Doing it now
2713 2713 # means that the tag cache only has to worry about destroyed
2714 2714 # heads immediately after a strip/rollback. That in turn
2715 2715 # guarantees that "cachetip == currenttip" (comparing both rev
2716 2716 # and node) always means no nodes have been added or destroyed.
2717 2717
2718 2718 # XXX this is suboptimal when qrefresh'ing: we strip the current
2719 2719 # head, refresh the tag cache, then immediately add a new head.
2720 2720 # But I think doing it this way is necessary for the "instant
2721 2721 # tag cache retrieval" case to work.
2722 2722 self.invalidate()
2723 2723
2724 2724 def status(self, node1='.', node2=None, match=None,
2725 2725 ignored=False, clean=False, unknown=False,
2726 2726 listsubrepos=False):
2727 2727 '''a convenience method that calls node1.status(node2)'''
2728 2728 return self[node1].status(node2, match, ignored, clean, unknown,
2729 2729 listsubrepos)
2730 2730
2731 2731 def addpostdsstatus(self, ps):
2732 2732 """Add a callback to run within the wlock, at the point at which status
2733 2733 fixups happen.
2734 2734
2735 2735 On status completion, callback(wctx, status) will be called with the
2736 2736 wlock held, unless the dirstate has changed from underneath or the wlock
2737 2737 couldn't be grabbed.
2738 2738
2739 2739 Callbacks should not capture and use a cached copy of the dirstate --
2740 2740 it might change in the meanwhile. Instead, they should access the
2741 2741 dirstate via wctx.repo().dirstate.
2742 2742
2743 2743 This list is emptied out after each status run -- extensions should
2744 2744 make sure it adds to this list each time dirstate.status is called.
2745 2745 Extensions should also make sure they don't call this for statuses
2746 2746 that don't involve the dirstate.
2747 2747 """
2748 2748
2749 2749 # The list is located here for uniqueness reasons -- it is actually
2750 2750 # managed by the workingctx, but that isn't unique per-repo.
2751 2751 self._postdsstatus.append(ps)
2752 2752
2753 2753 def postdsstatus(self):
2754 2754 """Used by workingctx to get the list of post-dirstate-status hooks."""
2755 2755 return self._postdsstatus
2756 2756
2757 2757 def clearpostdsstatus(self):
2758 2758 """Used by workingctx to clear post-dirstate-status hooks."""
2759 2759 del self._postdsstatus[:]
2760 2760
2761 2761 def heads(self, start=None):
2762 2762 if start is None:
2763 2763 cl = self.changelog
2764 2764 headrevs = reversed(cl.headrevs())
2765 2765 return [cl.node(rev) for rev in headrevs]
2766 2766
2767 2767 heads = self.changelog.heads(start)
2768 2768 # sort the output in rev descending order
2769 2769 return sorted(heads, key=self.changelog.rev, reverse=True)
2770 2770
2771 2771 def branchheads(self, branch=None, start=None, closed=False):
2772 2772 '''return a (possibly filtered) list of heads for the given branch
2773 2773
2774 2774 Heads are returned in topological order, from newest to oldest.
2775 2775 If branch is None, use the dirstate branch.
2776 2776 If start is not None, return only heads reachable from start.
2777 2777 If closed is True, return heads that are marked as closed as well.
2778 2778 '''
2779 2779 if branch is None:
2780 2780 branch = self[None].branch()
2781 2781 branches = self.branchmap()
2782 2782 if not branches.hasbranch(branch):
2783 2783 return []
2784 2784 # the cache returns heads ordered lowest to highest
2785 2785 bheads = list(reversed(branches.branchheads(branch, closed=closed)))
2786 2786 if start is not None:
2787 2787 # filter out the heads that cannot be reached from startrev
2788 2788 fbheads = set(self.changelog.nodesbetween([start], bheads)[2])
2789 2789 bheads = [h for h in bheads if h in fbheads]
2790 2790 return bheads
2791 2791
2792 2792 def branches(self, nodes):
2793 2793 if not nodes:
2794 2794 nodes = [self.changelog.tip()]
2795 2795 b = []
2796 2796 for n in nodes:
2797 2797 t = n
2798 2798 while True:
2799 2799 p = self.changelog.parents(n)
2800 2800 if p[1] != nullid or p[0] == nullid:
2801 2801 b.append((t, n, p[0], p[1]))
2802 2802 break
2803 2803 n = p[0]
2804 2804 return b
2805 2805
2806 2806 def between(self, pairs):
2807 2807 r = []
2808 2808
2809 2809 for top, bottom in pairs:
2810 2810 n, l, i = top, [], 0
2811 2811 f = 1
2812 2812
2813 2813 while n != bottom and n != nullid:
2814 2814 p = self.changelog.parents(n)[0]
2815 2815 if i == f:
2816 2816 l.append(n)
2817 2817 f = f * 2
2818 2818 n = p
2819 2819 i += 1
2820 2820
2821 2821 r.append(l)
2822 2822
2823 2823 return r
2824 2824
2825 2825 def checkpush(self, pushop):
2826 2826 """Extensions can override this function if additional checks have
2827 2827 to be performed before pushing, or call it if they override push
2828 2828 command.
2829 2829 """
2830 2830
2831 2831 @unfilteredpropertycache
2832 2832 def prepushoutgoinghooks(self):
2833 2833 """Return util.hooks consists of a pushop with repo, remote, outgoing
2834 2834 methods, which are called before pushing changesets.
2835 2835 """
2836 2836 return util.hooks()
2837 2837
2838 2838 def pushkey(self, namespace, key, old, new):
2839 2839 try:
2840 2840 tr = self.currenttransaction()
2841 2841 hookargs = {}
2842 2842 if tr is not None:
2843 2843 hookargs.update(tr.hookargs)
2844 2844 hookargs = pycompat.strkwargs(hookargs)
2845 2845 hookargs[r'namespace'] = namespace
2846 2846 hookargs[r'key'] = key
2847 2847 hookargs[r'old'] = old
2848 2848 hookargs[r'new'] = new
2849 2849 self.hook('prepushkey', throw=True, **hookargs)
2850 2850 except error.HookAbort as exc:
2851 2851 self.ui.write_err(_("pushkey-abort: %s\n") % exc)
2852 2852 if exc.hint:
2853 2853 self.ui.write_err(_("(%s)\n") % exc.hint)
2854 2854 return False
2855 2855 self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key))
2856 2856 ret = pushkey.push(self, namespace, key, old, new)
2857 2857 def runhook():
2858 2858 self.hook('pushkey', namespace=namespace, key=key, old=old, new=new,
2859 2859 ret=ret)
2860 2860 self._afterlock(runhook)
2861 2861 return ret
2862 2862
2863 2863 def listkeys(self, namespace):
2864 2864 self.hook('prelistkeys', throw=True, namespace=namespace)
2865 2865 self.ui.debug('listing keys for "%s"\n' % namespace)
2866 2866 values = pushkey.list(self, namespace)
2867 2867 self.hook('listkeys', namespace=namespace, values=values)
2868 2868 return values
2869 2869
2870 2870 def debugwireargs(self, one, two, three=None, four=None, five=None):
2871 2871 '''used to test argument passing over the wire'''
2872 2872 return "%s %s %s %s %s" % (one, two, pycompat.bytestr(three),
2873 2873 pycompat.bytestr(four),
2874 2874 pycompat.bytestr(five))
2875 2875
2876 2876 def savecommitmessage(self, text):
2877 2877 fp = self.vfs('last-message.txt', 'wb')
2878 2878 try:
2879 2879 fp.write(text)
2880 2880 finally:
2881 2881 fp.close()
2882 2882 return self.pathto(fp.name[len(self.root) + 1:])
2883 2883
2884 2884 # used to avoid circular references so destructors work
2885 2885 def aftertrans(files):
2886 2886 renamefiles = [tuple(t) for t in files]
2887 2887 def a():
2888 2888 for vfs, src, dest in renamefiles:
2889 2889 # if src and dest refer to a same file, vfs.rename is a no-op,
2890 2890 # leaving both src and dest on disk. delete dest to make sure
2891 2891 # the rename couldn't be such a no-op.
2892 2892 vfs.tryunlink(dest)
2893 2893 try:
2894 2894 vfs.rename(src, dest)
2895 2895 except OSError: # journal file does not yet exist
2896 2896 pass
2897 2897 return a
2898 2898
2899 2899 def undoname(fn):
2900 2900 base, name = os.path.split(fn)
2901 2901 assert name.startswith('journal')
2902 2902 return os.path.join(base, name.replace('journal', 'undo', 1))
2903 2903
2904 2904 def instance(ui, path, create, intents=None, createopts=None):
2905 2905 localpath = util.urllocalpath(path)
2906 2906 if create:
2907 2907 createrepository(ui, localpath, createopts=createopts)
2908 2908
2909 2909 return makelocalrepository(ui, localpath, intents=intents)
2910 2910
2911 2911 def islocal(path):
2912 2912 return True
2913 2913
2914 2914 def defaultcreateopts(ui, createopts=None):
2915 2915 """Populate the default creation options for a repository.
2916 2916
2917 2917 A dictionary of explicitly requested creation options can be passed
2918 2918 in. Missing keys will be populated.
2919 2919 """
2920 2920 createopts = dict(createopts or {})
2921 2921
2922 2922 if 'backend' not in createopts:
2923 2923 # experimental config: storage.new-repo-backend
2924 2924 createopts['backend'] = ui.config('storage', 'new-repo-backend')
2925 2925
2926 2926 return createopts
2927 2927
2928 2928 def newreporequirements(ui, createopts):
2929 2929 """Determine the set of requirements for a new local repository.
2930 2930
2931 2931 Extensions can wrap this function to specify custom requirements for
2932 2932 new repositories.
2933 2933 """
2934 2934 # If the repo is being created from a shared repository, we copy
2935 2935 # its requirements.
2936 2936 if 'sharedrepo' in createopts:
2937 2937 requirements = set(createopts['sharedrepo'].requirements)
2938 2938 if createopts.get('sharedrelative'):
2939 2939 requirements.add('relshared')
2940 2940 else:
2941 2941 requirements.add('shared')
2942 2942
2943 2943 return requirements
2944 2944
2945 2945 if 'backend' not in createopts:
2946 2946 raise error.ProgrammingError('backend key not present in createopts; '
2947 2947 'was defaultcreateopts() called?')
2948 2948
2949 2949 if createopts['backend'] != 'revlogv1':
2950 2950 raise error.Abort(_('unable to determine repository requirements for '
2951 2951 'storage backend: %s') % createopts['backend'])
2952 2952
2953 2953 requirements = {'revlogv1'}
2954 2954 if ui.configbool('format', 'usestore'):
2955 2955 requirements.add('store')
2956 2956 if ui.configbool('format', 'usefncache'):
2957 2957 requirements.add('fncache')
2958 2958 if ui.configbool('format', 'dotencode'):
2959 2959 requirements.add('dotencode')
2960 2960
2961 2961 compengine = ui.config('format', 'revlog-compression')
2962 2962 if compengine not in util.compengines:
2963 2963 raise error.Abort(_('compression engine %s defined by '
2964 2964 'format.revlog-compression not available') %
2965 2965 compengine,
2966 2966 hint=_('run "hg debuginstall" to list available '
2967 2967 'compression engines'))
2968 2968
2969 2969 # zlib is the historical default and doesn't need an explicit requirement.
2970 2970 elif compengine == 'zstd':
2971 2971 requirements.add('revlog-compression-zstd')
2972 2972 elif compengine != 'zlib':
2973 2973 requirements.add('exp-compression-%s' % compengine)
2974 2974
2975 2975 if scmutil.gdinitconfig(ui):
2976 2976 requirements.add('generaldelta')
2977 2977 if ui.configbool('format', 'sparse-revlog'):
2978 2978 requirements.add(SPARSEREVLOG_REQUIREMENT)
2979 2979 if ui.configbool('experimental', 'treemanifest'):
2980 2980 requirements.add('treemanifest')
2981 2981
2982 2982 revlogv2 = ui.config('experimental', 'revlogv2')
2983 2983 if revlogv2 == 'enable-unstable-format-and-corrupt-my-data':
2984 2984 requirements.remove('revlogv1')
2985 2985 # generaldelta is implied by revlogv2.
2986 2986 requirements.discard('generaldelta')
2987 2987 requirements.add(REVLOGV2_REQUIREMENT)
2988 2988 # experimental config: format.internal-phase
2989 2989 if ui.configbool('format', 'internal-phase'):
2990 2990 requirements.add('internal-phase')
2991 2991
2992 2992 if createopts.get('narrowfiles'):
2993 2993 requirements.add(repository.NARROW_REQUIREMENT)
2994 2994
2995 2995 if createopts.get('lfs'):
2996 2996 requirements.add('lfs')
2997 2997
2998 2998 return requirements
2999 2999
3000 3000 def filterknowncreateopts(ui, createopts):
3001 3001 """Filters a dict of repo creation options against options that are known.
3002 3002
3003 3003 Receives a dict of repo creation options and returns a dict of those
3004 3004 options that we don't know how to handle.
3005 3005
3006 3006 This function is called as part of repository creation. If the
3007 3007 returned dict contains any items, repository creation will not
3008 3008 be allowed, as it means there was a request to create a repository
3009 3009 with options not recognized by loaded code.
3010 3010
3011 3011 Extensions can wrap this function to filter out creation options
3012 3012 they know how to handle.
3013 3013 """
3014 3014 known = {
3015 3015 'backend',
3016 3016 'lfs',
3017 3017 'narrowfiles',
3018 3018 'sharedrepo',
3019 3019 'sharedrelative',
3020 3020 'shareditems',
3021 3021 'shallowfilestore',
3022 3022 }
3023 3023
3024 3024 return {k: v for k, v in createopts.items() if k not in known}
3025 3025
3026 3026 def createrepository(ui, path, createopts=None):
3027 3027 """Create a new repository in a vfs.
3028 3028
3029 3029 ``path`` path to the new repo's working directory.
3030 3030 ``createopts`` options for the new repository.
3031 3031
3032 3032 The following keys for ``createopts`` are recognized:
3033 3033
3034 3034 backend
3035 3035 The storage backend to use.
3036 3036 lfs
3037 3037 Repository will be created with ``lfs`` requirement. The lfs extension
3038 3038 will automatically be loaded when the repository is accessed.
3039 3039 narrowfiles
3040 3040 Set up repository to support narrow file storage.
3041 3041 sharedrepo
3042 3042 Repository object from which storage should be shared.
3043 3043 sharedrelative
3044 3044 Boolean indicating if the path to the shared repo should be
3045 3045 stored as relative. By default, the pointer to the "parent" repo
3046 3046 is stored as an absolute path.
3047 3047 shareditems
3048 3048 Set of items to share to the new repository (in addition to storage).
3049 3049 shallowfilestore
3050 3050 Indicates that storage for files should be shallow (not all ancestor
3051 3051 revisions are known).
3052 3052 """
3053 3053 createopts = defaultcreateopts(ui, createopts=createopts)
3054 3054
3055 3055 unknownopts = filterknowncreateopts(ui, createopts)
3056 3056
3057 3057 if not isinstance(unknownopts, dict):
3058 3058 raise error.ProgrammingError('filterknowncreateopts() did not return '
3059 3059 'a dict')
3060 3060
3061 3061 if unknownopts:
3062 3062 raise error.Abort(_('unable to create repository because of unknown '
3063 3063 'creation option: %s') %
3064 3064 ', '.join(sorted(unknownopts)),
3065 3065 hint=_('is a required extension not loaded?'))
3066 3066
3067 3067 requirements = newreporequirements(ui, createopts=createopts)
3068 3068
3069 3069 wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True)
3070 3070
3071 3071 hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg'))
3072 3072 if hgvfs.exists():
3073 3073 raise error.RepoError(_('repository %s already exists') % path)
3074 3074
3075 3075 if 'sharedrepo' in createopts:
3076 3076 sharedpath = createopts['sharedrepo'].sharedpath
3077 3077
3078 3078 if createopts.get('sharedrelative'):
3079 3079 try:
3080 3080 sharedpath = os.path.relpath(sharedpath, hgvfs.base)
3081 3081 except (IOError, ValueError) as e:
3082 3082 # ValueError is raised on Windows if the drive letters differ
3083 3083 # on each path.
3084 3084 raise error.Abort(_('cannot calculate relative path'),
3085 3085 hint=stringutil.forcebytestr(e))
3086 3086
3087 3087 if not wdirvfs.exists():
3088 3088 wdirvfs.makedirs()
3089 3089
3090 3090 hgvfs.makedir(notindexed=True)
3091 3091 if 'sharedrepo' not in createopts:
3092 3092 hgvfs.mkdir(b'cache')
3093 3093 hgvfs.mkdir(b'wcache')
3094 3094
3095 3095 if b'store' in requirements and 'sharedrepo' not in createopts:
3096 3096 hgvfs.mkdir(b'store')
3097 3097
3098 3098 # We create an invalid changelog outside the store so very old
3099 3099 # Mercurial versions (which didn't know about the requirements
3100 3100 # file) encounter an error on reading the changelog. This
3101 3101 # effectively locks out old clients and prevents them from
3102 3102 # mucking with a repo in an unknown format.
3103 3103 #
3104 3104 # The revlog header has version 2, which won't be recognized by
3105 3105 # such old clients.
3106 3106 hgvfs.append(b'00changelog.i',
3107 3107 b'\0\0\0\2 dummy changelog to prevent using the old repo '
3108 3108 b'layout')
3109 3109
3110 3110 scmutil.writerequires(hgvfs, requirements)
3111 3111
3112 3112 # Write out file telling readers where to find the shared store.
3113 3113 if 'sharedrepo' in createopts:
3114 3114 hgvfs.write(b'sharedpath', sharedpath)
3115 3115
3116 3116 if createopts.get('shareditems'):
3117 3117 shared = b'\n'.join(sorted(createopts['shareditems'])) + b'\n'
3118 3118 hgvfs.write(b'shared', shared)
3119 3119
3120 3120 def poisonrepository(repo):
3121 3121 """Poison a repository instance so it can no longer be used."""
3122 3122 # Perform any cleanup on the instance.
3123 3123 repo.close()
3124 3124
3125 3125 # Our strategy is to replace the type of the object with one that
3126 3126 # has all attribute lookups result in error.
3127 3127 #
3128 3128 # But we have to allow the close() method because some constructors
3129 3129 # of repos call close() on repo references.
3130 3130 class poisonedrepository(object):
3131 3131 def __getattribute__(self, item):
3132 3132 if item == r'close':
3133 3133 return object.__getattribute__(self, item)
3134 3134
3135 3135 raise error.ProgrammingError('repo instances should not be used '
3136 3136 'after unshare')
3137 3137
3138 3138 def close(self):
3139 3139 pass
3140 3140
3141 3141 # We may have a repoview, which intercepts __setattr__. So be sure
3142 3142 # we operate at the lowest level possible.
3143 3143 object.__setattr__(repo, r'__class__', poisonedrepository)
@@ -1,2410 +1,2410
1 1 $ cat >> $HGRCPATH <<EOF
2 2 > [extdiff]
3 3 > # for portability:
4 4 > pdiff = sh "$RUNTESTDIR/pdiff"
5 5 > EOF
6 6
7 7 Create a repo with some stuff in it:
8 8
9 9 $ hg init a
10 10 $ cd a
11 11 $ echo a > a
12 12 $ echo a > d
13 13 $ echo a > e
14 14 $ hg ci -qAm0
15 15 $ echo b > a
16 16 $ hg ci -m1 -u bar
17 17 $ hg mv a b
18 18 $ hg ci -m2
19 19 $ hg cp b c
20 20 $ hg ci -m3 -u baz
21 21 $ echo b > d
22 22 $ echo f > e
23 23 $ hg ci -m4
24 24 $ hg up -q 3
25 25 $ echo b > e
26 26 $ hg branch -q stable
27 27 $ hg ci -m5
28 28 $ hg merge -q default --tool internal:local # for conflicts in e, choose 5 and ignore 4
29 29 $ hg branch -q default
30 30 $ hg ci -m6
31 31 $ hg phase --public 3
32 32 $ hg phase --force --secret 6
33 33
34 34 $ hg log -G --template '{author}@{rev}.{phase}: {desc}\n'
35 35 @ test@6.secret: 6
36 36 |\
37 37 | o test@5.draft: 5
38 38 | |
39 39 o | test@4.draft: 4
40 40 |/
41 41 o baz@3.public: 3
42 42 |
43 43 o test@2.public: 2
44 44 |
45 45 o bar@1.public: 1
46 46 |
47 47 o test@0.public: 0
48 48
49 49 Test --base for grafting the merge of 4 from the perspective of 5, thus only getting the change to d
50 50
51 51 $ hg up -cqr 3
52 52 $ hg graft -r 6 --base 5
53 53 grafting 6:25a2b029d3ae "6" (tip)
54 54 merging e
55 55 $ hg st --change .
56 56 M d
57 57
58 58 $ hg -q strip . --config extensions.strip=
59 59
60 60 Test --base for collapsing changesets 2 and 3, thus getting both b and c
61 61
62 62 $ hg up -cqr 0
63 63 $ hg graft -r 3 --base 1
64 64 grafting 3:4c60f11aa304 "3"
65 65 merging a and b to b
66 66 merging a and c to c
67 67 $ hg st --change .
68 68 A b
69 69 A c
70 70 R a
71 71
72 72 $ hg -q strip . --config extensions.strip=
73 73
74 74 Specifying child as --base revision fails safely (perhaps slightly confusing, but consistent)
75 75
76 76 $ hg graft -r 2 --base 3
77 77 grafting 2:5c095ad7e90f "2"
78 78 note: possible conflict - c was deleted and renamed to:
79 79 a
80 80 note: graft of 2:5c095ad7e90f created no changes to commit
81 81
82 82 Can't continue without starting:
83 83
84 84 $ hg -q up -cr tip
85 85 $ hg rm -q e
86 86 $ hg graft --continue
87 87 abort: no graft in progress
88 88 [255]
89 89 $ hg revert -r . -q e
90 90
91 91 Need to specify a rev:
92 92
93 93 $ hg graft
94 94 abort: no revisions specified
95 95 [255]
96 96
97 97 Can't graft ancestor:
98 98
99 99 $ hg graft 1 2
100 100 skipping ancestor revision 1:5d205f8b35b6
101 101 skipping ancestor revision 2:5c095ad7e90f
102 102 [255]
103 103
104 104 Specify revisions with -r:
105 105
106 106 $ hg graft -r 1 -r 2
107 107 skipping ancestor revision 1:5d205f8b35b6
108 108 skipping ancestor revision 2:5c095ad7e90f
109 109 [255]
110 110
111 111 $ hg graft -r 1 2
112 112 warning: inconsistent use of --rev might give unexpected revision ordering!
113 113 skipping ancestor revision 2:5c095ad7e90f
114 114 skipping ancestor revision 1:5d205f8b35b6
115 115 [255]
116 116
117 117 Conflicting date/user options:
118 118
119 119 $ hg up -q 0
120 120 $ hg graft -U --user foo 2
121 121 abort: --user and --currentuser are mutually exclusive
122 122 [255]
123 123 $ hg graft -D --date '0 0' 2
124 124 abort: --date and --currentdate are mutually exclusive
125 125 [255]
126 126
127 127 Can't graft with dirty wd:
128 128
129 129 $ hg up -q 0
130 130 $ echo foo > a
131 131 $ hg graft 1
132 132 abort: uncommitted changes
133 133 [255]
134 134 $ hg revert a
135 135
136 136 Graft a rename:
137 137 (this also tests that editor is invoked if '--edit' is specified)
138 138
139 139 $ hg status --rev "2^1" --rev 2
140 140 A b
141 141 R a
142 142 $ HGEDITOR=cat hg graft 2 -u foo --edit
143 143 grafting 2:5c095ad7e90f "2"
144 144 merging a and b to b
145 145 2
146 146
147 147
148 148 HG: Enter commit message. Lines beginning with 'HG:' are removed.
149 149 HG: Leave message empty to abort commit.
150 150 HG: --
151 151 HG: user: foo
152 152 HG: branch 'default'
153 153 HG: added b
154 154 HG: removed a
155 155 $ hg export tip --git
156 156 # HG changeset patch
157 157 # User foo
158 158 # Date 0 0
159 159 # Thu Jan 01 00:00:00 1970 +0000
160 160 # Node ID ef0ef43d49e79e81ddafdc7997401ba0041efc82
161 161 # Parent 68795b066622ca79a25816a662041d8f78f3cd9e
162 162 2
163 163
164 164 diff --git a/a b/b
165 165 rename from a
166 166 rename to b
167 167
168 168 Look for extra:source
169 169
170 170 $ hg log --debug -r tip
171 171 changeset: 7:ef0ef43d49e79e81ddafdc7997401ba0041efc82
172 172 tag: tip
173 173 phase: draft
174 174 parent: 0:68795b066622ca79a25816a662041d8f78f3cd9e
175 175 parent: -1:0000000000000000000000000000000000000000
176 176 manifest: 7:e59b6b228f9cbf9903d5e9abf996e083a1f533eb
177 177 user: foo
178 178 date: Thu Jan 01 00:00:00 1970 +0000
179 179 files+: b
180 180 files-: a
181 181 extra: branch=default
182 182 extra: source=5c095ad7e90f871700f02dd1fa5012cb4498a2d4
183 183 description:
184 184 2
185 185
186 186
187 187
188 188 Graft out of order, skipping a merge and a duplicate
189 189 (this also tests that editor is not invoked if '--edit' is not specified)
190 190
191 191 $ hg graft 1 5 4 3 'merge()' 2 -n
192 192 skipping ungraftable merge revision 6
193 193 skipping revision 2:5c095ad7e90f (already grafted to 7:ef0ef43d49e7)
194 194 grafting 1:5d205f8b35b6 "1"
195 195 grafting 5:97f8bfe72746 "5"
196 196 grafting 4:9c233e8e184d "4"
197 197 grafting 3:4c60f11aa304 "3"
198 198
199 199 $ HGEDITOR=cat hg graft 1 5 'merge()' 2 --debug
200 200 skipping ungraftable merge revision 6
201 201 scanning for duplicate grafts
202 202 skipping revision 2:5c095ad7e90f (already grafted to 7:ef0ef43d49e7)
203 203 grafting 1:5d205f8b35b6 "1"
204 204 unmatched files in local:
205 205 b
206 206 all copies found (* = to merge, ! = divergent, % = renamed and deleted):
207 207 src: 'a' -> dst: 'b' *
208 208 checking for directory renames
209 209 resolving manifests
210 210 branchmerge: True, force: True, partial: False
211 211 ancestor: 68795b066622, local: ef0ef43d49e7+, remote: 5d205f8b35b6
212 212 preserving b for resolve of b
213 213 starting 4 threads for background file closing (?)
214 214 b: local copied/moved from a -> m (premerge)
215 215 picked tool ':merge' for b (binary False symlink False changedelete False)
216 216 merging b and a to b
217 217 my b@ef0ef43d49e7+ other a@5d205f8b35b6 ancestor a@68795b066622
218 218 premerge successful
219 219 committing files:
220 220 b
221 221 committing manifest
222 222 committing changelog
223 223 updating the branch cache
224 224 grafting 5:97f8bfe72746 "5"
225 225 all copies found (* = to merge, ! = divergent, % = renamed and deleted):
226 226 src: 'c' -> dst: 'b'
227 227 checking for directory renames
228 228 resolving manifests
229 229 branchmerge: True, force: True, partial: False
230 230 ancestor: 4c60f11aa304, local: 6b9e5368ca4e+, remote: 97f8bfe72746
231 231 e: remote is newer -> g
232 232 getting e
233 233 committing files:
234 234 e
235 235 committing manifest
236 236 committing changelog
237 237 updating the branch cache
238 238 $ HGEDITOR=cat hg graft 4 3 --log --debug
239 239 scanning for duplicate grafts
240 240 grafting 4:9c233e8e184d "4"
241 241 all copies found (* = to merge, ! = divergent, % = renamed and deleted):
242 242 src: 'c' -> dst: 'b'
243 243 checking for directory renames
244 244 resolving manifests
245 245 branchmerge: True, force: True, partial: False
246 246 ancestor: 4c60f11aa304, local: 1905859650ec+, remote: 9c233e8e184d
247 247 preserving e for resolve of e
248 248 d: remote is newer -> g
249 249 getting d
250 250 e: versions differ -> m (premerge)
251 251 picked tool ':merge' for e (binary False symlink False changedelete False)
252 252 merging e
253 253 my e@1905859650ec+ other e@9c233e8e184d ancestor e@4c60f11aa304
254 254 e: versions differ -> m (merge)
255 255 picked tool ':merge' for e (binary False symlink False changedelete False)
256 256 my e@1905859650ec+ other e@9c233e8e184d ancestor e@4c60f11aa304
257 257 warning: conflicts while merging e! (edit, then use 'hg resolve --mark')
258 258 abort: unresolved conflicts, can't continue
259 259 (use 'hg resolve' and 'hg graft --continue')
260 260 [255]
261 261
262 262 Summary should mention graft:
263 263
264 264 $ hg summary |grep graft
265 265 commit: 2 modified, 2 unknown, 1 unresolved (graft in progress)
266 266
267 267 Using status to get more context
268 268
269 269 $ hg status --verbose
270 270 M d
271 271 M e
272 272 ? a.orig
273 273 ? e.orig
274 274 # The repository is in an unfinished *graft* state.
275 275
276 276 # Unresolved merge conflicts:
277 277 #
278 278 # e
279 279 #
280 280 # To mark files as resolved: hg resolve --mark FILE
281 281
282 282 # To continue: hg graft --continue
283 283 # To abort: hg graft --abort
284 284
285 285
286 286 Commit while interrupted should fail:
287 287
288 288 $ hg ci -m 'commit interrupted graft'
289 289 abort: graft in progress
290 290 (use 'hg graft --continue' or 'hg graft --stop' to stop)
291 291 [255]
292 292
293 293 Abort the graft and try committing:
294 294
295 295 $ hg up -C .
296 296 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
297 297 $ echo c >> e
298 298 $ hg ci -mtest
299 299
300 300 $ hg strip . --config extensions.strip=
301 301 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
302 302 saved backup bundle to $TESTTMP/a/.hg/strip-backup/*-backup.hg (glob)
303 303
304 304 Graft again:
305 305
306 306 $ hg graft 1 5 4 3 'merge()' 2
307 307 skipping ungraftable merge revision 6
308 308 skipping revision 2:5c095ad7e90f (already grafted to 7:ef0ef43d49e7)
309 309 skipping revision 1:5d205f8b35b6 (already grafted to 8:6b9e5368ca4e)
310 310 skipping revision 5:97f8bfe72746 (already grafted to 9:1905859650ec)
311 311 grafting 4:9c233e8e184d "4"
312 312 merging e
313 313 warning: conflicts while merging e! (edit, then use 'hg resolve --mark')
314 314 abort: unresolved conflicts, can't continue
315 315 (use 'hg resolve' and 'hg graft --continue')
316 316 [255]
317 317
318 318 Continue without resolve should fail:
319 319
320 320 $ hg graft -c
321 321 grafting 4:9c233e8e184d "4"
322 322 abort: unresolved merge conflicts (see 'hg help resolve')
323 323 [255]
324 324
325 325 Fix up:
326 326
327 327 $ echo b > e
328 328 $ hg resolve -m e
329 329 (no more unresolved files)
330 330 continue: hg graft --continue
331 331
332 332 Continue with a revision should fail:
333 333
334 334 $ hg graft -c 6
335 335 abort: can't specify --continue and revisions
336 336 [255]
337 337
338 338 $ hg graft -c -r 6
339 339 abort: can't specify --continue and revisions
340 340 [255]
341 341
342 342 Continue for real, clobber usernames
343 343
344 344 $ hg graft -c -U
345 345 grafting 4:9c233e8e184d "4"
346 346 grafting 3:4c60f11aa304 "3"
347 347
348 348 Compare with original:
349 349
350 350 $ hg diff -r 6
351 351 $ hg status --rev 0:. -C
352 352 M d
353 353 M e
354 354 A b
355 355 a
356 356 A c
357 357 a
358 358 R a
359 359
360 360 View graph:
361 361
362 362 $ hg log -G --template '{author}@{rev}.{phase}: {desc}\n'
363 363 @ test@11.draft: 3
364 364 |
365 365 o test@10.draft: 4
366 366 |
367 367 o test@9.draft: 5
368 368 |
369 369 o bar@8.draft: 1
370 370 |
371 371 o foo@7.draft: 2
372 372 |
373 373 | o test@6.secret: 6
374 374 | |\
375 375 | | o test@5.draft: 5
376 376 | | |
377 377 | o | test@4.draft: 4
378 378 | |/
379 379 | o baz@3.public: 3
380 380 | |
381 381 | o test@2.public: 2
382 382 | |
383 383 | o bar@1.public: 1
384 384 |/
385 385 o test@0.public: 0
386 386
387 387 Graft again onto another branch should preserve the original source
388 388 $ hg up -q 0
389 389 $ echo 'g'>g
390 390 $ hg add g
391 391 $ hg ci -m 7
392 392 created new head
393 393 $ hg graft 7
394 394 grafting 7:ef0ef43d49e7 "2"
395 395
396 396 $ hg log -r 7 --template '{rev}:{node}\n'
397 397 7:ef0ef43d49e79e81ddafdc7997401ba0041efc82
398 398 $ hg log -r 2 --template '{rev}:{node}\n'
399 399 2:5c095ad7e90f871700f02dd1fa5012cb4498a2d4
400 400
401 401 $ hg log --debug -r tip
402 402 changeset: 13:7a4785234d87ec1aa420ed6b11afe40fa73e12a9
403 403 tag: tip
404 404 phase: draft
405 405 parent: 12:b592ea63bb0c19a6c5c44685ee29a2284f9f1b8f
406 406 parent: -1:0000000000000000000000000000000000000000
407 407 manifest: 13:dc313617b8c32457c0d589e0dbbedfe71f3cd637
408 408 user: foo
409 409 date: Thu Jan 01 00:00:00 1970 +0000
410 410 files+: b
411 411 files-: a
412 412 extra: branch=default
413 413 extra: intermediate-source=ef0ef43d49e79e81ddafdc7997401ba0041efc82
414 414 extra: source=5c095ad7e90f871700f02dd1fa5012cb4498a2d4
415 415 description:
416 416 2
417 417
418 418
419 419 Disallow grafting an already grafted cset onto its original branch
420 420 $ hg up -q 6
421 421 $ hg graft 7
422 422 skipping already grafted revision 7:ef0ef43d49e7 (was grafted from 2:5c095ad7e90f)
423 423 [255]
424 424
425 425 $ hg pdiff --config extensions.extdiff= --patch -r 2 -r 13
426 426 --- */hg-5c095ad7e90f.patch * (glob)
427 427 +++ */hg-7a4785234d87.patch * (glob)
428 428 @@ -1,18 +1,18 @@
429 429 # HG changeset patch
430 430 -# User test
431 431 +# User foo
432 432 # Date 0 0
433 433 # Thu Jan 01 00:00:00 1970 +0000
434 434 -# Node ID 5c095ad7e90f871700f02dd1fa5012cb4498a2d4
435 435 -# Parent 5d205f8b35b66bc36375c9534ffd3237730e8f04
436 436 +# Node ID 7a4785234d87ec1aa420ed6b11afe40fa73e12a9
437 437 +# Parent b592ea63bb0c19a6c5c44685ee29a2284f9f1b8f
438 438 2
439 439
440 440 -diff -r 5d205f8b35b6 -r 5c095ad7e90f a
441 441 +diff -r b592ea63bb0c -r 7a4785234d87 a
442 442 --- a/a Thu Jan 01 00:00:00 1970 +0000
443 443 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
444 444 @@ -1,1 +0,0 @@
445 445 --b
446 446 -diff -r 5d205f8b35b6 -r 5c095ad7e90f b
447 447 +-a
448 448 +diff -r b592ea63bb0c -r 7a4785234d87 b
449 449 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
450 450 +++ b/b Thu Jan 01 00:00:00 1970 +0000
451 451 @@ -0,0 +1,1 @@
452 452 -+b
453 453 ++a
454 454 [1]
455 455
456 456 $ hg pdiff --config extensions.extdiff= --patch -r 2 -r 13 -X .
457 457 --- */hg-5c095ad7e90f.patch * (glob)
458 458 +++ */hg-7a4785234d87.patch * (glob)
459 459 @@ -1,8 +1,8 @@
460 460 # HG changeset patch
461 461 -# User test
462 462 +# User foo
463 463 # Date 0 0
464 464 # Thu Jan 01 00:00:00 1970 +0000
465 465 -# Node ID 5c095ad7e90f871700f02dd1fa5012cb4498a2d4
466 466 -# Parent 5d205f8b35b66bc36375c9534ffd3237730e8f04
467 467 +# Node ID 7a4785234d87ec1aa420ed6b11afe40fa73e12a9
468 468 +# Parent b592ea63bb0c19a6c5c44685ee29a2284f9f1b8f
469 469 2
470 470
471 471 [1]
472 472
473 473 Disallow grafting already grafted csets with the same origin onto each other
474 474 $ hg up -q 13
475 475 $ hg graft 2
476 476 skipping revision 2:5c095ad7e90f (already grafted to 13:7a4785234d87)
477 477 [255]
478 478 $ hg graft 7
479 479 skipping already grafted revision 7:ef0ef43d49e7 (13:7a4785234d87 also has origin 2:5c095ad7e90f)
480 480 [255]
481 481
482 482 $ hg up -q 7
483 483 $ hg graft 2
484 484 skipping revision 2:5c095ad7e90f (already grafted to 7:ef0ef43d49e7)
485 485 [255]
486 486 $ hg graft tip
487 487 skipping already grafted revision 13:7a4785234d87 (7:ef0ef43d49e7 also has origin 2:5c095ad7e90f)
488 488 [255]
489 489
490 490 Graft with --log
491 491
492 492 $ hg up -Cq 1
493 493 $ hg graft 3 --log -u foo
494 494 grafting 3:4c60f11aa304 "3"
495 495 warning: can't find ancestor for 'c' copied from 'b'!
496 496 $ hg log --template '{rev}:{node|short} {parents} {desc}\n' -r tip
497 497 14:0c921c65ef1e 1:5d205f8b35b6 3
498 498 (grafted from 4c60f11aa304a54ae1c199feb94e7fc771e51ed8)
499 499
500 500 Resolve conflicted graft
501 501 $ hg up -q 0
502 502 $ echo b > a
503 503 $ hg ci -m 8
504 504 created new head
505 505 $ echo c > a
506 506 $ hg ci -m 9
507 507 $ hg graft 1 --tool internal:fail
508 508 grafting 1:5d205f8b35b6 "1"
509 509 abort: unresolved conflicts, can't continue
510 510 (use 'hg resolve' and 'hg graft --continue')
511 511 [255]
512 512 $ hg resolve --all
513 513 merging a
514 514 warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
515 515 [1]
516 516 $ cat a
517 517 <<<<<<< local: aaa4406d4f0a - test: 9
518 518 c
519 519 =======
520 520 b
521 521 >>>>>>> graft: 5d205f8b35b6 - bar: 1
522 522 $ echo b > a
523 523 $ hg resolve -m a
524 524 (no more unresolved files)
525 525 continue: hg graft --continue
526 526 $ hg graft -c
527 527 grafting 1:5d205f8b35b6 "1"
528 528 $ hg export tip --git
529 529 # HG changeset patch
530 530 # User bar
531 531 # Date 0 0
532 532 # Thu Jan 01 00:00:00 1970 +0000
533 533 # Node ID f67661df0c4804d301f064f332b57e7d5ddaf2be
534 534 # Parent aaa4406d4f0ae9befd6e58c82ec63706460cbca6
535 535 1
536 536
537 537 diff --git a/a b/a
538 538 --- a/a
539 539 +++ b/a
540 540 @@ -1,1 +1,1 @@
541 541 -c
542 542 +b
543 543
544 544 Resolve conflicted graft with rename
545 545 $ echo c > a
546 546 $ hg ci -m 10
547 547 $ hg graft 2 --tool internal:fail
548 548 grafting 2:5c095ad7e90f "2"
549 549 abort: unresolved conflicts, can't continue
550 550 (use 'hg resolve' and 'hg graft --continue')
551 551 [255]
552 552 $ hg resolve --all
553 553 merging a and b to b
554 554 (no more unresolved files)
555 555 continue: hg graft --continue
556 556 $ hg graft -c
557 557 grafting 2:5c095ad7e90f "2"
558 558 $ hg export tip --git
559 559 # HG changeset patch
560 560 # User test
561 561 # Date 0 0
562 562 # Thu Jan 01 00:00:00 1970 +0000
563 563 # Node ID 9627f653b421c61fc1ea4c4e366745070fa3d2bc
564 564 # Parent ee295f490a40b97f3d18dd4c4f1c8936c233b612
565 565 2
566 566
567 567 diff --git a/a b/b
568 568 rename from a
569 569 rename to b
570 570
571 571 Test simple origin(), with and without args
572 572 $ hg log -r 'origin()'
573 573 changeset: 1:5d205f8b35b6
574 574 user: bar
575 575 date: Thu Jan 01 00:00:00 1970 +0000
576 576 summary: 1
577 577
578 578 changeset: 2:5c095ad7e90f
579 579 user: test
580 580 date: Thu Jan 01 00:00:00 1970 +0000
581 581 summary: 2
582 582
583 583 changeset: 3:4c60f11aa304
584 584 user: baz
585 585 date: Thu Jan 01 00:00:00 1970 +0000
586 586 summary: 3
587 587
588 588 changeset: 4:9c233e8e184d
589 589 user: test
590 590 date: Thu Jan 01 00:00:00 1970 +0000
591 591 summary: 4
592 592
593 593 changeset: 5:97f8bfe72746
594 594 branch: stable
595 595 parent: 3:4c60f11aa304
596 596 user: test
597 597 date: Thu Jan 01 00:00:00 1970 +0000
598 598 summary: 5
599 599
600 600 $ hg log -r 'origin(7)'
601 601 changeset: 2:5c095ad7e90f
602 602 user: test
603 603 date: Thu Jan 01 00:00:00 1970 +0000
604 604 summary: 2
605 605
606 606 Now transplant a graft to test following through copies
607 607 $ hg up -q 0
608 608 $ hg branch -q dev
609 609 $ hg ci -qm "dev branch"
610 610 $ hg --config extensions.transplant= transplant -q 7
611 611 $ hg log -r 'origin(.)'
612 612 changeset: 2:5c095ad7e90f
613 613 user: test
614 614 date: Thu Jan 01 00:00:00 1970 +0000
615 615 summary: 2
616 616
617 617 Test that the graft and transplant markers in extra are converted, allowing
618 618 origin() to still work. Note that these recheck the immediately preceeding two
619 619 tests.
620 620 $ hg --quiet --config extensions.convert= --config convert.hg.saverev=True convert . ../converted
621 621
622 622 The graft case
623 623 $ hg -R ../converted log -r 7 --template "{rev}: {node}\n{join(extras, '\n')}\n"
624 624 7: 7ae846e9111fc8f57745634250c7b9ac0a60689b
625 625 branch=default
626 626 convert_revision=ef0ef43d49e79e81ddafdc7997401ba0041efc82
627 627 source=e0213322b2c1a5d5d236c74e79666441bee67a7d
628 628 $ hg -R ../converted log -r 'origin(7)'
629 629 changeset: 2:e0213322b2c1
630 630 user: test
631 631 date: Thu Jan 01 00:00:00 1970 +0000
632 632 summary: 2
633 633
634 634 Test that template correctly expands more than one 'extra' (issue4362), and that
635 635 'intermediate-source' is converted.
636 636 $ hg -R ../converted log -r 13 --template "{extras % ' Extra: {extra}\n'}"
637 637 Extra: branch=default
638 638 Extra: convert_revision=7a4785234d87ec1aa420ed6b11afe40fa73e12a9
639 639 Extra: intermediate-source=7ae846e9111fc8f57745634250c7b9ac0a60689b
640 640 Extra: source=e0213322b2c1a5d5d236c74e79666441bee67a7d
641 641
642 642 The transplant case
643 643 $ hg -R ../converted log -r tip --template "{rev}: {node}\n{join(extras, '\n')}\n"
644 644 21: fbb6c5cc81002f2b4b49c9d731404688bcae5ade
645 645 branch=dev
646 646 convert_revision=7e61b508e709a11d28194a5359bc3532d910af21
647 647 transplant_source=z\xe8F\xe9\x11\x1f\xc8\xf5wEcBP\xc7\xb9\xac\n`h\x9b
648 648 $ hg -R ../converted log -r 'origin(tip)'
649 649 changeset: 2:e0213322b2c1
650 650 user: test
651 651 date: Thu Jan 01 00:00:00 1970 +0000
652 652 summary: 2
653 653
654 654
655 655 Test simple destination
656 656 $ hg log -r 'destination()'
657 657 changeset: 7:ef0ef43d49e7
658 658 parent: 0:68795b066622
659 659 user: foo
660 660 date: Thu Jan 01 00:00:00 1970 +0000
661 661 summary: 2
662 662
663 663 changeset: 8:6b9e5368ca4e
664 664 user: bar
665 665 date: Thu Jan 01 00:00:00 1970 +0000
666 666 summary: 1
667 667
668 668 changeset: 9:1905859650ec
669 669 user: test
670 670 date: Thu Jan 01 00:00:00 1970 +0000
671 671 summary: 5
672 672
673 673 changeset: 10:52dc0b4c6907
674 674 user: test
675 675 date: Thu Jan 01 00:00:00 1970 +0000
676 676 summary: 4
677 677
678 678 changeset: 11:882b35362a6b
679 679 user: test
680 680 date: Thu Jan 01 00:00:00 1970 +0000
681 681 summary: 3
682 682
683 683 changeset: 13:7a4785234d87
684 684 user: foo
685 685 date: Thu Jan 01 00:00:00 1970 +0000
686 686 summary: 2
687 687
688 688 changeset: 14:0c921c65ef1e
689 689 parent: 1:5d205f8b35b6
690 690 user: foo
691 691 date: Thu Jan 01 00:00:00 1970 +0000
692 692 summary: 3
693 693
694 694 changeset: 17:f67661df0c48
695 695 user: bar
696 696 date: Thu Jan 01 00:00:00 1970 +0000
697 697 summary: 1
698 698
699 699 changeset: 19:9627f653b421
700 700 user: test
701 701 date: Thu Jan 01 00:00:00 1970 +0000
702 702 summary: 2
703 703
704 704 changeset: 21:7e61b508e709
705 705 branch: dev
706 706 tag: tip
707 707 user: foo
708 708 date: Thu Jan 01 00:00:00 1970 +0000
709 709 summary: 2
710 710
711 711 $ hg log -r 'destination(2)'
712 712 changeset: 7:ef0ef43d49e7
713 713 parent: 0:68795b066622
714 714 user: foo
715 715 date: Thu Jan 01 00:00:00 1970 +0000
716 716 summary: 2
717 717
718 718 changeset: 13:7a4785234d87
719 719 user: foo
720 720 date: Thu Jan 01 00:00:00 1970 +0000
721 721 summary: 2
722 722
723 723 changeset: 19:9627f653b421
724 724 user: test
725 725 date: Thu Jan 01 00:00:00 1970 +0000
726 726 summary: 2
727 727
728 728 changeset: 21:7e61b508e709
729 729 branch: dev
730 730 tag: tip
731 731 user: foo
732 732 date: Thu Jan 01 00:00:00 1970 +0000
733 733 summary: 2
734 734
735 735 Transplants of grafts can find a destination...
736 736 $ hg log -r 'destination(7)'
737 737 changeset: 21:7e61b508e709
738 738 branch: dev
739 739 tag: tip
740 740 user: foo
741 741 date: Thu Jan 01 00:00:00 1970 +0000
742 742 summary: 2
743 743
744 744 ... grafts of grafts unfortunately can't
745 745 $ hg graft -q 13 --debug
746 746 scanning for duplicate grafts
747 747 grafting 13:7a4785234d87 "2"
748 748 all copies found (* = to merge, ! = divergent, % = renamed and deleted):
749 749 src: 'a' -> dst: 'b' *
750 750 checking for directory renames
751 751 resolving manifests
752 752 branchmerge: True, force: True, partial: False
753 753 ancestor: b592ea63bb0c, local: 7e61b508e709+, remote: 7a4785234d87
754 754 starting 4 threads for background file closing (?)
755 755 committing files:
756 756 b
757 757 warning: can't find ancestor for 'b' copied from 'a'!
758 reusing manifest form p1 (listed files actually unchanged)
758 reusing manifest from p1 (listed files actually unchanged)
759 759 committing changelog
760 760 updating the branch cache
761 761 $ hg log -r 'destination(13)'
762 762 All copies of a cset
763 763 $ hg log -r 'origin(13) or destination(origin(13))'
764 764 changeset: 2:5c095ad7e90f
765 765 user: test
766 766 date: Thu Jan 01 00:00:00 1970 +0000
767 767 summary: 2
768 768
769 769 changeset: 7:ef0ef43d49e7
770 770 parent: 0:68795b066622
771 771 user: foo
772 772 date: Thu Jan 01 00:00:00 1970 +0000
773 773 summary: 2
774 774
775 775 changeset: 13:7a4785234d87
776 776 user: foo
777 777 date: Thu Jan 01 00:00:00 1970 +0000
778 778 summary: 2
779 779
780 780 changeset: 19:9627f653b421
781 781 user: test
782 782 date: Thu Jan 01 00:00:00 1970 +0000
783 783 summary: 2
784 784
785 785 changeset: 21:7e61b508e709
786 786 branch: dev
787 787 user: foo
788 788 date: Thu Jan 01 00:00:00 1970 +0000
789 789 summary: 2
790 790
791 791 changeset: 22:3a4e92d81b97
792 792 branch: dev
793 793 tag: tip
794 794 user: foo
795 795 date: Thu Jan 01 00:00:00 1970 +0000
796 796 summary: 2
797 797
798 798
799 799 graft works on complex revset
800 800
801 801 $ hg graft 'origin(13) or destination(origin(13))'
802 802 skipping ancestor revision 21:7e61b508e709
803 803 skipping ancestor revision 22:3a4e92d81b97
804 804 skipping revision 2:5c095ad7e90f (already grafted to 22:3a4e92d81b97)
805 805 grafting 7:ef0ef43d49e7 "2"
806 806 warning: can't find ancestor for 'b' copied from 'a'!
807 807 grafting 13:7a4785234d87 "2"
808 808 warning: can't find ancestor for 'b' copied from 'a'!
809 809 grafting 19:9627f653b421 "2"
810 810 merging b
811 811 warning: can't find ancestor for 'b' copied from 'a'!
812 812
813 813 graft with --force (still doesn't graft merges)
814 814
815 815 $ hg graft 19 0 6
816 816 skipping ungraftable merge revision 6
817 817 skipping ancestor revision 0:68795b066622
818 818 skipping already grafted revision 19:9627f653b421 (22:3a4e92d81b97 also has origin 2:5c095ad7e90f)
819 819 [255]
820 820 $ hg graft 19 0 6 --force
821 821 skipping ungraftable merge revision 6
822 822 grafting 19:9627f653b421 "2"
823 823 merging b
824 824 warning: can't find ancestor for 'b' copied from 'a'!
825 825 grafting 0:68795b066622 "0"
826 826
827 827 graft --force after backout
828 828
829 829 $ echo abc > a
830 830 $ hg ci -m 28
831 831 $ hg backout 28
832 832 reverting a
833 833 changeset 29:9d95e865b00c backs out changeset 28:cc20d29aec8d
834 834 $ hg graft 28
835 835 skipping ancestor revision 28:cc20d29aec8d
836 836 [255]
837 837 $ hg graft 28 --force
838 838 grafting 28:cc20d29aec8d "28"
839 839 merging a
840 840 $ cat a
841 841 abc
842 842
843 843 graft --continue after --force
844 844
845 845 $ echo def > a
846 846 $ hg ci -m 31
847 847 $ hg graft 28 --force --tool internal:fail
848 848 grafting 28:cc20d29aec8d "28"
849 849 abort: unresolved conflicts, can't continue
850 850 (use 'hg resolve' and 'hg graft --continue')
851 851 [255]
852 852 $ hg resolve --all
853 853 merging a
854 854 warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
855 855 [1]
856 856 $ echo abc > a
857 857 $ hg resolve -m a
858 858 (no more unresolved files)
859 859 continue: hg graft --continue
860 860 $ hg graft -c
861 861 grafting 28:cc20d29aec8d "28"
862 862 $ cat a
863 863 abc
864 864
865 865 Continue testing same origin policy, using revision numbers from test above
866 866 but do some destructive editing of the repo:
867 867
868 868 $ hg up -qC 7
869 869 $ hg tag -l -r 13 tmp
870 870 $ hg --config extensions.strip= strip 2
871 871 saved backup bundle to $TESTTMP/a/.hg/strip-backup/5c095ad7e90f-d323a1e4-backup.hg
872 872 $ hg graft tmp
873 873 skipping already grafted revision 8:7a4785234d87 (2:ef0ef43d49e7 also has unknown origin 5c095ad7e90f)
874 874 [255]
875 875
876 876 Empty graft
877 877
878 878 $ hg up -qr 26
879 879 $ hg tag -f something
880 880 $ hg graft -qr 27
881 881 $ hg graft -f 27
882 882 grafting 27:17d42b8f5d50 "28"
883 883 note: graft of 27:17d42b8f5d50 created no changes to commit
884 884
885 885 $ cd ..
886 886
887 887 Graft to duplicate a commit
888 888
889 889 $ hg init graftsibling
890 890 $ cd graftsibling
891 891 $ touch a
892 892 $ hg commit -qAm a
893 893 $ touch b
894 894 $ hg commit -qAm b
895 895 $ hg log -G -T '{rev}\n'
896 896 @ 1
897 897 |
898 898 o 0
899 899
900 900 $ hg up -q 0
901 901 $ hg graft -r 1
902 902 grafting 1:0e067c57feba "b" (tip)
903 903 $ hg log -G -T '{rev}\n'
904 904 @ 2
905 905 |
906 906 | o 1
907 907 |/
908 908 o 0
909 909
910 910 Graft to duplicate a commit twice
911 911
912 912 $ hg up -q 0
913 913 $ hg graft -r 2
914 914 grafting 2:044ec77f6389 "b" (tip)
915 915 $ hg log -G -T '{rev}\n'
916 916 @ 3
917 917 |
918 918 | o 2
919 919 |/
920 920 | o 1
921 921 |/
922 922 o 0
923 923
924 924 Graft from behind a move or rename
925 925 ==================================
926 926
927 927 NOTE: This is affected by issue5343, and will need updating when it's fixed
928 928
929 929 Consider this topology for a regular graft:
930 930
931 931 o c1
932 932 |
933 933 | o c2
934 934 | |
935 935 | o ca # stands for "common ancestor"
936 936 |/
937 937 o cta # stands for "common topological ancestor"
938 938
939 939 Note that in issue5343, ca==cta.
940 940
941 941 The following table shows the possible cases. Here, "x->y" and, equivalently,
942 942 "y<-x", where x is an ancestor of y, means that some copy happened from x to y.
943 943
944 944 name | c1<-cta | cta<->ca | ca->c2
945 945 A.0 | | |
946 946 A.1 | X | |
947 947 A.2 | | X |
948 948 A.3 | | | X
949 949 A.4 | X | X |
950 950 A.5 | X | | X
951 951 A.6 | | X | X
952 952 A.7 | X | X | X
953 953
954 954 A.0 is trivial, and doesn't need copy tracking.
955 955 For A.1, a forward rename is recorded in the c1 pass, to be followed later.
956 956 In A.2, the rename is recorded in the c2 pass and followed backwards.
957 957 A.3 is recorded in the c2 pass as a forward rename to be duplicated on target.
958 958 In A.4, both passes of checkcopies record incomplete renames, which are
959 959 then joined in mergecopies to record a rename to be followed.
960 960 In A.5 and A.7, the c1 pass records an incomplete rename, while the c2 pass
961 961 records an incomplete divergence. The incomplete rename is then joined to the
962 962 appropriate side of the incomplete divergence, and the result is recorded as a
963 963 divergence. The code doesn't distinguish at all between these two cases, since
964 964 the end result of them is the same: an incomplete divergence joined with an
965 965 incomplete rename into a divergence.
966 966 Finally, A.6 records a divergence entirely in the c2 pass.
967 967
968 968 A.4 has a degenerate case a<-b<-a->a, where checkcopies isn't needed at all.
969 969 A.5 has a special case a<-b<-b->a, which is treated like a<-b->a in a merge.
970 970 A.5 has issue5343 as a special case.
971 971 A.6 has a special case a<-a<-b->a. Here, checkcopies will find a spurious
972 972 incomplete divergence, which is in fact complete. This is handled later in
973 973 mergecopies.
974 974 A.7 has 4 special cases: a<-b<-a->b (the "ping-pong" case), a<-b<-c->b,
975 975 a<-b<-a->c and a<-b<-c->a. Of these, only the "ping-pong" case is interesting,
976 976 the others are fairly trivial (a<-b<-c->b and a<-b<-a->c proceed like the base
977 977 case, a<-b<-c->a is treated the same as a<-b<-b->a).
978 978
979 979 f5a therefore tests the "ping-pong" rename case, where a file is renamed to the
980 980 same name on both branches, then the rename is backed out on one branch, and
981 981 the backout is grafted to the other branch. This creates a challenging rename
982 982 sequence of a<-b<-a->b in the graft target, topological CA, graft CA and graft
983 983 source, respectively. Since rename detection will run on the c1 side for such a
984 984 sequence (as for technical reasons, we split the c1 and c2 sides not at the
985 985 graft CA, but rather at the topological CA), it will pick up a false rename,
986 986 and cause a spurious merge conflict. This false rename is always exactly the
987 987 reverse of the true rename that would be detected on the c2 side, so we can
988 988 correct for it by detecting this condition and reversing as necessary.
989 989
990 990 First, set up the repository with commits to be grafted
991 991
992 992 $ hg init ../graftmove
993 993 $ cd ../graftmove
994 994 $ echo c1a > f1a
995 995 $ echo c2a > f2a
996 996 $ echo c3a > f3a
997 997 $ echo c4a > f4a
998 998 $ echo c5a > f5a
999 999 $ hg ci -qAm A0
1000 1000 $ hg mv f1a f1b
1001 1001 $ hg mv f3a f3b
1002 1002 $ hg mv f5a f5b
1003 1003 $ hg ci -qAm B0
1004 1004 $ echo c1c > f1b
1005 1005 $ hg mv f2a f2c
1006 1006 $ hg mv f5b f5a
1007 1007 $ echo c5c > f5a
1008 1008 $ hg ci -qAm C0
1009 1009 $ hg mv f3b f3d
1010 1010 $ echo c4d > f4a
1011 1011 $ hg ci -qAm D0
1012 1012 $ hg log -G
1013 1013 @ changeset: 3:b69f5839d2d9
1014 1014 | tag: tip
1015 1015 | user: test
1016 1016 | date: Thu Jan 01 00:00:00 1970 +0000
1017 1017 | summary: D0
1018 1018 |
1019 1019 o changeset: 2:f58c7e2b28fa
1020 1020 | user: test
1021 1021 | date: Thu Jan 01 00:00:00 1970 +0000
1022 1022 | summary: C0
1023 1023 |
1024 1024 o changeset: 1:3d7bba921b5d
1025 1025 | user: test
1026 1026 | date: Thu Jan 01 00:00:00 1970 +0000
1027 1027 | summary: B0
1028 1028 |
1029 1029 o changeset: 0:11f7a1b56675
1030 1030 user: test
1031 1031 date: Thu Jan 01 00:00:00 1970 +0000
1032 1032 summary: A0
1033 1033
1034 1034
1035 1035 Test the cases A.2 (f1x), A.3 (f2x) and a special case of A.6 (f5x) where the
1036 1036 two renames actually converge to the same name (thus no actual divergence).
1037 1037
1038 1038 $ hg up -q 'desc("A0")'
1039 1039 $ HGEDITOR="echo C1 >" hg graft -r 'desc("C0")' --edit
1040 1040 grafting 2:f58c7e2b28fa "C0"
1041 1041 merging f1a and f1b to f1a
1042 1042 merging f5a
1043 1043 warning: can't find ancestor for 'f5a' copied from 'f5b'!
1044 1044 $ hg status --change .
1045 1045 M f1a
1046 1046 M f5a
1047 1047 A f2c
1048 1048 R f2a
1049 1049 $ hg cat f1a
1050 1050 c1c
1051 1051 $ hg cat f1b
1052 1052 f1b: no such file in rev c9763722f9bd
1053 1053 [1]
1054 1054
1055 1055 Test the cases A.0 (f4x) and A.6 (f3x)
1056 1056
1057 1057 $ HGEDITOR="echo D1 >" hg graft -r 'desc("D0")' --edit
1058 1058 grafting 3:b69f5839d2d9 "D0"
1059 1059 note: possible conflict - f3b was renamed multiple times to:
1060 1060 f3a
1061 1061 f3d
1062 1062 warning: can't find ancestor for 'f3d' copied from 'f3b'!
1063 1063
1064 1064 Set up the repository for some further tests
1065 1065
1066 1066 $ hg up -q "min(desc("A0"))"
1067 1067 $ hg mv f1a f1e
1068 1068 $ echo c2e > f2a
1069 1069 $ hg mv f3a f3e
1070 1070 $ hg mv f4a f4e
1071 1071 $ hg mv f5a f5b
1072 1072 $ hg ci -qAm "E0"
1073 1073 $ hg up -q "min(desc("A0"))"
1074 1074 $ hg cp f1a f1f
1075 1075 $ hg ci -qAm "F0"
1076 1076 $ hg up -q "min(desc("A0"))"
1077 1077 $ hg cp f1a f1g
1078 1078 $ echo c1g > f1g
1079 1079 $ hg ci -qAm "G0"
1080 1080 $ hg log -G
1081 1081 @ changeset: 8:ba67f08fb15a
1082 1082 | tag: tip
1083 1083 | parent: 0:11f7a1b56675
1084 1084 | user: test
1085 1085 | date: Thu Jan 01 00:00:00 1970 +0000
1086 1086 | summary: G0
1087 1087 |
1088 1088 | o changeset: 7:d376ab0d7fda
1089 1089 |/ parent: 0:11f7a1b56675
1090 1090 | user: test
1091 1091 | date: Thu Jan 01 00:00:00 1970 +0000
1092 1092 | summary: F0
1093 1093 |
1094 1094 | o changeset: 6:6bd1736cab86
1095 1095 |/ parent: 0:11f7a1b56675
1096 1096 | user: test
1097 1097 | date: Thu Jan 01 00:00:00 1970 +0000
1098 1098 | summary: E0
1099 1099 |
1100 1100 | o changeset: 5:560daee679da
1101 1101 | | user: test
1102 1102 | | date: Thu Jan 01 00:00:00 1970 +0000
1103 1103 | | summary: D1
1104 1104 | |
1105 1105 | o changeset: 4:c9763722f9bd
1106 1106 |/ parent: 0:11f7a1b56675
1107 1107 | user: test
1108 1108 | date: Thu Jan 01 00:00:00 1970 +0000
1109 1109 | summary: C1
1110 1110 |
1111 1111 | o changeset: 3:b69f5839d2d9
1112 1112 | | user: test
1113 1113 | | date: Thu Jan 01 00:00:00 1970 +0000
1114 1114 | | summary: D0
1115 1115 | |
1116 1116 | o changeset: 2:f58c7e2b28fa
1117 1117 | | user: test
1118 1118 | | date: Thu Jan 01 00:00:00 1970 +0000
1119 1119 | | summary: C0
1120 1120 | |
1121 1121 | o changeset: 1:3d7bba921b5d
1122 1122 |/ user: test
1123 1123 | date: Thu Jan 01 00:00:00 1970 +0000
1124 1124 | summary: B0
1125 1125 |
1126 1126 o changeset: 0:11f7a1b56675
1127 1127 user: test
1128 1128 date: Thu Jan 01 00:00:00 1970 +0000
1129 1129 summary: A0
1130 1130
1131 1131
1132 1132 Test the cases A.4 (f1x), the "ping-pong" special case of A.7 (f5x),
1133 1133 and A.3 with a local content change to be preserved (f2x).
1134 1134
1135 1135 $ hg up -q "desc("E0")"
1136 1136 $ HGEDITOR="echo C2 >" hg graft -r 'desc("C0")' --edit
1137 1137 grafting 2:f58c7e2b28fa "C0"
1138 1138 merging f1e and f1b to f1e
1139 1139 merging f2a and f2c to f2c
1140 1140
1141 1141 Test the cases A.1 (f4x) and A.7 (f3x).
1142 1142
1143 1143 $ HGEDITOR="echo D2 >" hg graft -r 'desc("D0")' --edit
1144 1144 grafting 3:b69f5839d2d9 "D0"
1145 1145 note: possible conflict - f3b was renamed multiple times to:
1146 1146 f3d
1147 1147 f3e
1148 1148 merging f4e and f4a to f4e
1149 1149 warning: can't find ancestor for 'f3d' copied from 'f3b'!
1150 1150
1151 1151 $ hg cat f2c
1152 1152 c2e
1153 1153
1154 1154 Test the case A.5 (move case, f1x).
1155 1155
1156 1156 $ hg up -q "desc("C0")"
1157 1157 BROKEN: Shouldn't get the warning about missing ancestor
1158 1158 $ HGEDITOR="echo E1 >" hg graft -r 'desc("E0")' --edit
1159 1159 grafting 6:6bd1736cab86 "E0"
1160 1160 note: possible conflict - f1a was renamed multiple times to:
1161 1161 f1b
1162 1162 f1e
1163 1163 note: possible conflict - f3a was renamed multiple times to:
1164 1164 f3b
1165 1165 f3e
1166 1166 merging f2c and f2a to f2c
1167 1167 merging f5a and f5b to f5b
1168 1168 warning: can't find ancestor for 'f1e' copied from 'f1a'!
1169 1169 warning: can't find ancestor for 'f3e' copied from 'f3a'!
1170 1170 $ cat f1e
1171 1171 c1a
1172 1172
1173 1173 Test the case A.5 (copy case, f1x).
1174 1174
1175 1175 $ hg up -q "desc("C0")"
1176 1176 BROKEN: Shouldn't get the warning about missing ancestor
1177 1177 $ HGEDITOR="echo F1 >" hg graft -r 'desc("F0")' --edit
1178 1178 grafting 7:d376ab0d7fda "F0"
1179 1179 warning: can't find ancestor for 'f1f' copied from 'f1a'!
1180 1180 BROKEN: f1f should be marked a copy from f1b
1181 1181 $ hg st --copies --change .
1182 1182 A f1f
1183 1183 BROKEN: f1f should have the new content from f1b (i.e. "c1c")
1184 1184 $ cat f1f
1185 1185 c1a
1186 1186
1187 1187 Test the case A.5 (copy+modify case, f1x).
1188 1188
1189 1189 $ hg up -q "desc("C0")"
1190 1190 BROKEN: We should get a merge conflict from the 3-way merge between f1b in C0
1191 1191 (content "c1c") and f1g in G0 (content "c1g") with f1a in A0 as base (content
1192 1192 "c1a")
1193 1193 $ HGEDITOR="echo G1 >" hg graft -r 'desc("G0")' --edit
1194 1194 grafting 8:ba67f08fb15a "G0"
1195 1195 warning: can't find ancestor for 'f1g' copied from 'f1a'!
1196 1196
1197 1197 Check the results of the grafts tested
1198 1198
1199 1199 $ hg log -CGv --patch --git
1200 1200 @ changeset: 13:ef3adf6c20a4
1201 1201 | tag: tip
1202 1202 | parent: 2:f58c7e2b28fa
1203 1203 | user: test
1204 1204 | date: Thu Jan 01 00:00:00 1970 +0000
1205 1205 | files: f1g
1206 1206 | description:
1207 1207 | G1
1208 1208 |
1209 1209 |
1210 1210 | diff --git a/f1g b/f1g
1211 1211 | new file mode 100644
1212 1212 | --- /dev/null
1213 1213 | +++ b/f1g
1214 1214 | @@ -0,0 +1,1 @@
1215 1215 | +c1g
1216 1216 |
1217 1217 | o changeset: 12:b5542d755b54
1218 1218 |/ parent: 2:f58c7e2b28fa
1219 1219 | user: test
1220 1220 | date: Thu Jan 01 00:00:00 1970 +0000
1221 1221 | files: f1f
1222 1222 | description:
1223 1223 | F1
1224 1224 |
1225 1225 |
1226 1226 | diff --git a/f1f b/f1f
1227 1227 | new file mode 100644
1228 1228 | --- /dev/null
1229 1229 | +++ b/f1f
1230 1230 | @@ -0,0 +1,1 @@
1231 1231 | +c1a
1232 1232 |
1233 1233 | o changeset: 11:f8a162271246
1234 1234 |/ parent: 2:f58c7e2b28fa
1235 1235 | user: test
1236 1236 | date: Thu Jan 01 00:00:00 1970 +0000
1237 1237 | files: f1e f2c f3e f4a f4e f5a f5b
1238 1238 | copies: f4e (f4a) f5b (f5a)
1239 1239 | description:
1240 1240 | E1
1241 1241 |
1242 1242 |
1243 1243 | diff --git a/f1e b/f1e
1244 1244 | new file mode 100644
1245 1245 | --- /dev/null
1246 1246 | +++ b/f1e
1247 1247 | @@ -0,0 +1,1 @@
1248 1248 | +c1a
1249 1249 | diff --git a/f2c b/f2c
1250 1250 | --- a/f2c
1251 1251 | +++ b/f2c
1252 1252 | @@ -1,1 +1,1 @@
1253 1253 | -c2a
1254 1254 | +c2e
1255 1255 | diff --git a/f3e b/f3e
1256 1256 | new file mode 100644
1257 1257 | --- /dev/null
1258 1258 | +++ b/f3e
1259 1259 | @@ -0,0 +1,1 @@
1260 1260 | +c3a
1261 1261 | diff --git a/f4a b/f4e
1262 1262 | rename from f4a
1263 1263 | rename to f4e
1264 1264 | diff --git a/f5a b/f5b
1265 1265 | rename from f5a
1266 1266 | rename to f5b
1267 1267 |
1268 1268 | o changeset: 10:93ee502e8b0a
1269 1269 | | user: test
1270 1270 | | date: Thu Jan 01 00:00:00 1970 +0000
1271 1271 | | files: f3d f4e
1272 1272 | | description:
1273 1273 | | D2
1274 1274 | |
1275 1275 | |
1276 1276 | | diff --git a/f3d b/f3d
1277 1277 | | new file mode 100644
1278 1278 | | --- /dev/null
1279 1279 | | +++ b/f3d
1280 1280 | | @@ -0,0 +1,1 @@
1281 1281 | | +c3a
1282 1282 | | diff --git a/f4e b/f4e
1283 1283 | | --- a/f4e
1284 1284 | | +++ b/f4e
1285 1285 | | @@ -1,1 +1,1 @@
1286 1286 | | -c4a
1287 1287 | | +c4d
1288 1288 | |
1289 1289 | o changeset: 9:539cf145f496
1290 1290 | | parent: 6:6bd1736cab86
1291 1291 | | user: test
1292 1292 | | date: Thu Jan 01 00:00:00 1970 +0000
1293 1293 | | files: f1e f2a f2c f5a f5b
1294 1294 | | copies: f2c (f2a) f5a (f5b)
1295 1295 | | description:
1296 1296 | | C2
1297 1297 | |
1298 1298 | |
1299 1299 | | diff --git a/f1e b/f1e
1300 1300 | | --- a/f1e
1301 1301 | | +++ b/f1e
1302 1302 | | @@ -1,1 +1,1 @@
1303 1303 | | -c1a
1304 1304 | | +c1c
1305 1305 | | diff --git a/f2a b/f2c
1306 1306 | | rename from f2a
1307 1307 | | rename to f2c
1308 1308 | | diff --git a/f5b b/f5a
1309 1309 | | rename from f5b
1310 1310 | | rename to f5a
1311 1311 | | --- a/f5b
1312 1312 | | +++ b/f5a
1313 1313 | | @@ -1,1 +1,1 @@
1314 1314 | | -c5a
1315 1315 | | +c5c
1316 1316 | |
1317 1317 | | o changeset: 8:ba67f08fb15a
1318 1318 | | | parent: 0:11f7a1b56675
1319 1319 | | | user: test
1320 1320 | | | date: Thu Jan 01 00:00:00 1970 +0000
1321 1321 | | | files: f1g
1322 1322 | | | copies: f1g (f1a)
1323 1323 | | | description:
1324 1324 | | | G0
1325 1325 | | |
1326 1326 | | |
1327 1327 | | | diff --git a/f1a b/f1g
1328 1328 | | | copy from f1a
1329 1329 | | | copy to f1g
1330 1330 | | | --- a/f1a
1331 1331 | | | +++ b/f1g
1332 1332 | | | @@ -1,1 +1,1 @@
1333 1333 | | | -c1a
1334 1334 | | | +c1g
1335 1335 | | |
1336 1336 | | | o changeset: 7:d376ab0d7fda
1337 1337 | | |/ parent: 0:11f7a1b56675
1338 1338 | | | user: test
1339 1339 | | | date: Thu Jan 01 00:00:00 1970 +0000
1340 1340 | | | files: f1f
1341 1341 | | | copies: f1f (f1a)
1342 1342 | | | description:
1343 1343 | | | F0
1344 1344 | | |
1345 1345 | | |
1346 1346 | | | diff --git a/f1a b/f1f
1347 1347 | | | copy from f1a
1348 1348 | | | copy to f1f
1349 1349 | | |
1350 1350 | o | changeset: 6:6bd1736cab86
1351 1351 | |/ parent: 0:11f7a1b56675
1352 1352 | | user: test
1353 1353 | | date: Thu Jan 01 00:00:00 1970 +0000
1354 1354 | | files: f1a f1e f2a f3a f3e f4a f4e f5a f5b
1355 1355 | | copies: f1e (f1a) f3e (f3a) f4e (f4a) f5b (f5a)
1356 1356 | | description:
1357 1357 | | E0
1358 1358 | |
1359 1359 | |
1360 1360 | | diff --git a/f1a b/f1e
1361 1361 | | rename from f1a
1362 1362 | | rename to f1e
1363 1363 | | diff --git a/f2a b/f2a
1364 1364 | | --- a/f2a
1365 1365 | | +++ b/f2a
1366 1366 | | @@ -1,1 +1,1 @@
1367 1367 | | -c2a
1368 1368 | | +c2e
1369 1369 | | diff --git a/f3a b/f3e
1370 1370 | | rename from f3a
1371 1371 | | rename to f3e
1372 1372 | | diff --git a/f4a b/f4e
1373 1373 | | rename from f4a
1374 1374 | | rename to f4e
1375 1375 | | diff --git a/f5a b/f5b
1376 1376 | | rename from f5a
1377 1377 | | rename to f5b
1378 1378 | |
1379 1379 | | o changeset: 5:560daee679da
1380 1380 | | | user: test
1381 1381 | | | date: Thu Jan 01 00:00:00 1970 +0000
1382 1382 | | | files: f3d f4a
1383 1383 | | | description:
1384 1384 | | | D1
1385 1385 | | |
1386 1386 | | |
1387 1387 | | | diff --git a/f3d b/f3d
1388 1388 | | | new file mode 100644
1389 1389 | | | --- /dev/null
1390 1390 | | | +++ b/f3d
1391 1391 | | | @@ -0,0 +1,1 @@
1392 1392 | | | +c3a
1393 1393 | | | diff --git a/f4a b/f4a
1394 1394 | | | --- a/f4a
1395 1395 | | | +++ b/f4a
1396 1396 | | | @@ -1,1 +1,1 @@
1397 1397 | | | -c4a
1398 1398 | | | +c4d
1399 1399 | | |
1400 1400 | | o changeset: 4:c9763722f9bd
1401 1401 | |/ parent: 0:11f7a1b56675
1402 1402 | | user: test
1403 1403 | | date: Thu Jan 01 00:00:00 1970 +0000
1404 1404 | | files: f1a f2a f2c f5a
1405 1405 | | copies: f2c (f2a)
1406 1406 | | description:
1407 1407 | | C1
1408 1408 | |
1409 1409 | |
1410 1410 | | diff --git a/f1a b/f1a
1411 1411 | | --- a/f1a
1412 1412 | | +++ b/f1a
1413 1413 | | @@ -1,1 +1,1 @@
1414 1414 | | -c1a
1415 1415 | | +c1c
1416 1416 | | diff --git a/f2a b/f2c
1417 1417 | | rename from f2a
1418 1418 | | rename to f2c
1419 1419 | | diff --git a/f5a b/f5a
1420 1420 | | --- a/f5a
1421 1421 | | +++ b/f5a
1422 1422 | | @@ -1,1 +1,1 @@
1423 1423 | | -c5a
1424 1424 | | +c5c
1425 1425 | |
1426 1426 +---o changeset: 3:b69f5839d2d9
1427 1427 | | user: test
1428 1428 | | date: Thu Jan 01 00:00:00 1970 +0000
1429 1429 | | files: f3b f3d f4a
1430 1430 | | copies: f3d (f3b)
1431 1431 | | description:
1432 1432 | | D0
1433 1433 | |
1434 1434 | |
1435 1435 | | diff --git a/f3b b/f3d
1436 1436 | | rename from f3b
1437 1437 | | rename to f3d
1438 1438 | | diff --git a/f4a b/f4a
1439 1439 | | --- a/f4a
1440 1440 | | +++ b/f4a
1441 1441 | | @@ -1,1 +1,1 @@
1442 1442 | | -c4a
1443 1443 | | +c4d
1444 1444 | |
1445 1445 o | changeset: 2:f58c7e2b28fa
1446 1446 | | user: test
1447 1447 | | date: Thu Jan 01 00:00:00 1970 +0000
1448 1448 | | files: f1b f2a f2c f5a f5b
1449 1449 | | copies: f2c (f2a) f5a (f5b)
1450 1450 | | description:
1451 1451 | | C0
1452 1452 | |
1453 1453 | |
1454 1454 | | diff --git a/f1b b/f1b
1455 1455 | | --- a/f1b
1456 1456 | | +++ b/f1b
1457 1457 | | @@ -1,1 +1,1 @@
1458 1458 | | -c1a
1459 1459 | | +c1c
1460 1460 | | diff --git a/f2a b/f2c
1461 1461 | | rename from f2a
1462 1462 | | rename to f2c
1463 1463 | | diff --git a/f5b b/f5a
1464 1464 | | rename from f5b
1465 1465 | | rename to f5a
1466 1466 | | --- a/f5b
1467 1467 | | +++ b/f5a
1468 1468 | | @@ -1,1 +1,1 @@
1469 1469 | | -c5a
1470 1470 | | +c5c
1471 1471 | |
1472 1472 o | changeset: 1:3d7bba921b5d
1473 1473 |/ user: test
1474 1474 | date: Thu Jan 01 00:00:00 1970 +0000
1475 1475 | files: f1a f1b f3a f3b f5a f5b
1476 1476 | copies: f1b (f1a) f3b (f3a) f5b (f5a)
1477 1477 | description:
1478 1478 | B0
1479 1479 |
1480 1480 |
1481 1481 | diff --git a/f1a b/f1b
1482 1482 | rename from f1a
1483 1483 | rename to f1b
1484 1484 | diff --git a/f3a b/f3b
1485 1485 | rename from f3a
1486 1486 | rename to f3b
1487 1487 | diff --git a/f5a b/f5b
1488 1488 | rename from f5a
1489 1489 | rename to f5b
1490 1490 |
1491 1491 o changeset: 0:11f7a1b56675
1492 1492 user: test
1493 1493 date: Thu Jan 01 00:00:00 1970 +0000
1494 1494 files: f1a f2a f3a f4a f5a
1495 1495 description:
1496 1496 A0
1497 1497
1498 1498
1499 1499 diff --git a/f1a b/f1a
1500 1500 new file mode 100644
1501 1501 --- /dev/null
1502 1502 +++ b/f1a
1503 1503 @@ -0,0 +1,1 @@
1504 1504 +c1a
1505 1505 diff --git a/f2a b/f2a
1506 1506 new file mode 100644
1507 1507 --- /dev/null
1508 1508 +++ b/f2a
1509 1509 @@ -0,0 +1,1 @@
1510 1510 +c2a
1511 1511 diff --git a/f3a b/f3a
1512 1512 new file mode 100644
1513 1513 --- /dev/null
1514 1514 +++ b/f3a
1515 1515 @@ -0,0 +1,1 @@
1516 1516 +c3a
1517 1517 diff --git a/f4a b/f4a
1518 1518 new file mode 100644
1519 1519 --- /dev/null
1520 1520 +++ b/f4a
1521 1521 @@ -0,0 +1,1 @@
1522 1522 +c4a
1523 1523 diff --git a/f5a b/f5a
1524 1524 new file mode 100644
1525 1525 --- /dev/null
1526 1526 +++ b/f5a
1527 1527 @@ -0,0 +1,1 @@
1528 1528 +c5a
1529 1529
1530 1530 Check superfluous filemerge of files renamed in the past but untouched by graft
1531 1531
1532 1532 $ echo a > a
1533 1533 $ hg ci -qAma
1534 1534 $ hg mv a b
1535 1535 $ echo b > b
1536 1536 $ hg ci -qAmb
1537 1537 $ echo c > c
1538 1538 $ hg ci -qAmc
1539 1539 $ hg up -q .~2
1540 1540 $ hg graft tip -qt:fail
1541 1541
1542 1542 $ cd ..
1543 1543
1544 1544 Graft a change into a new file previously grafted into a renamed directory
1545 1545
1546 1546 $ hg init dirmovenewfile
1547 1547 $ cd dirmovenewfile
1548 1548 $ mkdir a
1549 1549 $ echo a > a/a
1550 1550 $ hg ci -qAma
1551 1551 $ echo x > a/x
1552 1552 $ hg ci -qAmx
1553 1553 $ hg up -q 0
1554 1554 $ hg mv -q a b
1555 1555 $ hg ci -qAmb
1556 1556 $ hg graft -q 1 # a/x grafted as b/x, but no copy information recorded
1557 1557 $ hg up -q 1
1558 1558 $ echo y > a/x
1559 1559 $ hg ci -qAmy
1560 1560 $ hg up -q 3
1561 1561 $ hg graft -q 4
1562 1562 $ hg status --change .
1563 1563 M b/x
1564 1564
1565 1565 Prepare for test of skipped changesets and how merges can influence it:
1566 1566
1567 1567 $ hg merge -q -r 1 --tool :local
1568 1568 $ hg ci -m m
1569 1569 $ echo xx >> b/x
1570 1570 $ hg ci -m xx
1571 1571
1572 1572 $ hg log -G -T '{rev} {desc|firstline}'
1573 1573 @ 7 xx
1574 1574 |
1575 1575 o 6 m
1576 1576 |\
1577 1577 | o 5 y
1578 1578 | |
1579 1579 +---o 4 y
1580 1580 | |
1581 1581 | o 3 x
1582 1582 | |
1583 1583 | o 2 b
1584 1584 | |
1585 1585 o | 1 x
1586 1586 |/
1587 1587 o 0 a
1588 1588
1589 1589 Grafting of plain changes correctly detects that 3 and 5 should be skipped:
1590 1590
1591 1591 $ hg up -qCr 4
1592 1592 $ hg graft --tool :local -r 2::5
1593 1593 skipping already grafted revision 3:ca093ca2f1d9 (was grafted from 1:13ec5badbf2a)
1594 1594 skipping already grafted revision 5:43e9eb70dab0 (was grafted from 4:6c9a1289e5f1)
1595 1595 grafting 2:42127f193bcd "b"
1596 1596
1597 1597 Extending the graft range to include a (skipped) merge of 3 will not prevent us from
1598 1598 also detecting that both 3 and 5 should be skipped:
1599 1599
1600 1600 $ hg up -qCr 4
1601 1601 $ hg graft --tool :local -r 2::7
1602 1602 skipping ungraftable merge revision 6
1603 1603 skipping already grafted revision 3:ca093ca2f1d9 (was grafted from 1:13ec5badbf2a)
1604 1604 skipping already grafted revision 5:43e9eb70dab0 (was grafted from 4:6c9a1289e5f1)
1605 1605 grafting 2:42127f193bcd "b"
1606 1606 grafting 7:d3c3f2b38ecc "xx"
1607 1607 note: graft of 7:d3c3f2b38ecc created no changes to commit
1608 1608
1609 1609 $ cd ..
1610 1610
1611 1611 Grafted revision should be warned and skipped only once. (issue6024)
1612 1612
1613 1613 $ mkdir issue6024
1614 1614 $ cd issue6024
1615 1615
1616 1616 $ hg init base
1617 1617 $ cd base
1618 1618 $ touch x
1619 1619 $ hg commit -qAminit
1620 1620 $ echo a > x
1621 1621 $ hg commit -mchange
1622 1622 $ hg update -q 0
1623 1623 $ hg graft -r 1
1624 1624 grafting 1:a0b923c546aa "change" (tip)
1625 1625 $ cd ..
1626 1626
1627 1627 $ hg clone -qr 2 base clone
1628 1628 $ cd clone
1629 1629 $ hg pull -q
1630 1630 $ hg merge -q 2
1631 1631 $ hg commit -mmerge
1632 1632 $ hg update -q 0
1633 1633 $ hg graft -r 1
1634 1634 grafting 1:04fc6d444368 "change"
1635 1635 $ hg update -q 3
1636 1636 $ hg log -G -T '{rev}:{node|shortest} <- {extras.source|shortest}\n'
1637 1637 o 4:4e16 <- a0b9
1638 1638 |
1639 1639 | @ 3:f0ac <-
1640 1640 | |\
1641 1641 +---o 2:a0b9 <-
1642 1642 | |
1643 1643 | o 1:04fc <- a0b9
1644 1644 |/
1645 1645 o 0:7848 <-
1646 1646
1647 1647
1648 1648 the source of rev 4 is an ancestor of the working parent, and was also
1649 1649 grafted as rev 1. it should be stripped from the target revisions only once.
1650 1650
1651 1651 $ hg graft -r 4
1652 1652 skipping already grafted revision 4:4e16bab40c9c (1:04fc6d444368 also has origin 2:a0b923c546aa)
1653 1653 [255]
1654 1654
1655 1655 $ cd ../..
1656 1656
1657 1657 Testing the reading of old format graftstate file with newer mercurial
1658 1658
1659 1659 $ hg init oldgraft
1660 1660 $ cd oldgraft
1661 1661 $ for ch in a b c; do echo foo > $ch; hg add $ch; hg ci -Aqm "added "$ch; done;
1662 1662 $ hg log -GT "{rev}:{node|short} {desc}\n"
1663 1663 @ 2:8be98ac1a569 added c
1664 1664 |
1665 1665 o 1:80e6d2c47cfe added b
1666 1666 |
1667 1667 o 0:f7ad41964313 added a
1668 1668
1669 1669 $ hg up 0
1670 1670 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
1671 1671 $ echo bar > b
1672 1672 $ hg add b
1673 1673 $ hg ci -m "bar to b"
1674 1674 created new head
1675 1675 $ hg graft -r 1 -r 2
1676 1676 grafting 1:80e6d2c47cfe "added b"
1677 1677 merging b
1678 1678 warning: conflicts while merging b! (edit, then use 'hg resolve --mark')
1679 1679 abort: unresolved conflicts, can't continue
1680 1680 (use 'hg resolve' and 'hg graft --continue')
1681 1681 [255]
1682 1682
1683 1683 Writing the nodes in old format to graftstate
1684 1684
1685 1685 $ hg log -r 1 -r 2 -T '{node}\n' > .hg/graftstate
1686 1686 $ echo foo > b
1687 1687 $ hg resolve -m
1688 1688 (no more unresolved files)
1689 1689 continue: hg graft --continue
1690 1690 $ hg graft --continue
1691 1691 grafting 1:80e6d2c47cfe "added b"
1692 1692 grafting 2:8be98ac1a569 "added c"
1693 1693
1694 1694 Testing that --user is preserved during conflicts and value is reused while
1695 1695 running `hg graft --continue`
1696 1696
1697 1697 $ hg log -G
1698 1698 @ changeset: 5:711e9fa999f1
1699 1699 | tag: tip
1700 1700 | user: test
1701 1701 | date: Thu Jan 01 00:00:00 1970 +0000
1702 1702 | summary: added c
1703 1703 |
1704 1704 o changeset: 4:e5ad7353b408
1705 1705 | user: test
1706 1706 | date: Thu Jan 01 00:00:00 1970 +0000
1707 1707 | summary: added b
1708 1708 |
1709 1709 o changeset: 3:9e887f7a939c
1710 1710 | parent: 0:f7ad41964313
1711 1711 | user: test
1712 1712 | date: Thu Jan 01 00:00:00 1970 +0000
1713 1713 | summary: bar to b
1714 1714 |
1715 1715 | o changeset: 2:8be98ac1a569
1716 1716 | | user: test
1717 1717 | | date: Thu Jan 01 00:00:00 1970 +0000
1718 1718 | | summary: added c
1719 1719 | |
1720 1720 | o changeset: 1:80e6d2c47cfe
1721 1721 |/ user: test
1722 1722 | date: Thu Jan 01 00:00:00 1970 +0000
1723 1723 | summary: added b
1724 1724 |
1725 1725 o changeset: 0:f7ad41964313
1726 1726 user: test
1727 1727 date: Thu Jan 01 00:00:00 1970 +0000
1728 1728 summary: added a
1729 1729
1730 1730
1731 1731 $ hg up '.^^'
1732 1732 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
1733 1733
1734 1734 $ hg graft -r 1 -r 2 --user batman
1735 1735 grafting 1:80e6d2c47cfe "added b"
1736 1736 merging b
1737 1737 warning: conflicts while merging b! (edit, then use 'hg resolve --mark')
1738 1738 abort: unresolved conflicts, can't continue
1739 1739 (use 'hg resolve' and 'hg graft --continue')
1740 1740 [255]
1741 1741
1742 1742 $ echo wat > b
1743 1743 $ hg resolve -m
1744 1744 (no more unresolved files)
1745 1745 continue: hg graft --continue
1746 1746
1747 1747 $ hg graft --continue
1748 1748 grafting 1:80e6d2c47cfe "added b"
1749 1749 grafting 2:8be98ac1a569 "added c"
1750 1750
1751 1751 $ hg log -Gr 3::
1752 1752 @ changeset: 7:11a36ffaacf2
1753 1753 | tag: tip
1754 1754 | user: batman
1755 1755 | date: Thu Jan 01 00:00:00 1970 +0000
1756 1756 | summary: added c
1757 1757 |
1758 1758 o changeset: 6:76803afc6511
1759 1759 | parent: 3:9e887f7a939c
1760 1760 | user: batman
1761 1761 | date: Thu Jan 01 00:00:00 1970 +0000
1762 1762 | summary: added b
1763 1763 |
1764 1764 | o changeset: 5:711e9fa999f1
1765 1765 | | user: test
1766 1766 | | date: Thu Jan 01 00:00:00 1970 +0000
1767 1767 | | summary: added c
1768 1768 | |
1769 1769 | o changeset: 4:e5ad7353b408
1770 1770 |/ user: test
1771 1771 | date: Thu Jan 01 00:00:00 1970 +0000
1772 1772 | summary: added b
1773 1773 |
1774 1774 o changeset: 3:9e887f7a939c
1775 1775 | parent: 0:f7ad41964313
1776 1776 ~ user: test
1777 1777 date: Thu Jan 01 00:00:00 1970 +0000
1778 1778 summary: bar to b
1779 1779
1780 1780 Test that --date is preserved and reused in `hg graft --continue`
1781 1781
1782 1782 $ hg up '.^^'
1783 1783 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
1784 1784 $ hg graft -r 1 -r 2 --date '1234560000 120'
1785 1785 grafting 1:80e6d2c47cfe "added b"
1786 1786 merging b
1787 1787 warning: conflicts while merging b! (edit, then use 'hg resolve --mark')
1788 1788 abort: unresolved conflicts, can't continue
1789 1789 (use 'hg resolve' and 'hg graft --continue')
1790 1790 [255]
1791 1791
1792 1792 $ echo foobar > b
1793 1793 $ hg resolve -m
1794 1794 (no more unresolved files)
1795 1795 continue: hg graft --continue
1796 1796 $ hg graft --continue
1797 1797 grafting 1:80e6d2c47cfe "added b"
1798 1798 grafting 2:8be98ac1a569 "added c"
1799 1799
1800 1800 $ hg log -Gr '.^^::.'
1801 1801 @ changeset: 9:1896b76e007a
1802 1802 | tag: tip
1803 1803 | user: test
1804 1804 | date: Fri Feb 13 21:18:00 2009 -0002
1805 1805 | summary: added c
1806 1806 |
1807 1807 o changeset: 8:ce2b4f1632af
1808 1808 | parent: 3:9e887f7a939c
1809 1809 | user: test
1810 1810 | date: Fri Feb 13 21:18:00 2009 -0002
1811 1811 | summary: added b
1812 1812 |
1813 1813 o changeset: 3:9e887f7a939c
1814 1814 | parent: 0:f7ad41964313
1815 1815 ~ user: test
1816 1816 date: Thu Jan 01 00:00:00 1970 +0000
1817 1817 summary: bar to b
1818 1818
1819 1819 Test that --log is preserved and reused in `hg graft --continue`
1820 1820
1821 1821 $ hg up '.^^'
1822 1822 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
1823 1823 $ hg graft -r 1 -r 2 --log
1824 1824 grafting 1:80e6d2c47cfe "added b"
1825 1825 merging b
1826 1826 warning: conflicts while merging b! (edit, then use 'hg resolve --mark')
1827 1827 abort: unresolved conflicts, can't continue
1828 1828 (use 'hg resolve' and 'hg graft --continue')
1829 1829 [255]
1830 1830
1831 1831 $ echo foobar > b
1832 1832 $ hg resolve -m
1833 1833 (no more unresolved files)
1834 1834 continue: hg graft --continue
1835 1835
1836 1836 $ hg graft --continue
1837 1837 grafting 1:80e6d2c47cfe "added b"
1838 1838 grafting 2:8be98ac1a569 "added c"
1839 1839
1840 1840 $ hg log -GT "{rev}:{node|short} {desc}" -r '.^^::.'
1841 1841 @ 11:30c1050a58b2 added c
1842 1842 | (grafted from 8be98ac1a56990c2d9ca6861041b8390af7bd6f3)
1843 1843 o 10:ec7eda2313e2 added b
1844 1844 | (grafted from 80e6d2c47cfe5b3185519568327a17a061c7efb6)
1845 1845 o 3:9e887f7a939c bar to b
1846 1846 |
1847 1847 ~
1848 1848
1849 1849 $ cd ..
1850 1850
1851 1851 Testing the --stop flag of `hg graft` which stops the interrupted graft
1852 1852
1853 1853 $ hg init stopgraft
1854 1854 $ cd stopgraft
1855 1855 $ for ch in a b c d; do echo $ch > $ch; hg add $ch; hg ci -Aqm "added "$ch; done;
1856 1856
1857 1857 $ hg log -G
1858 1858 @ changeset: 3:9150fe93bec6
1859 1859 | tag: tip
1860 1860 | user: test
1861 1861 | date: Thu Jan 01 00:00:00 1970 +0000
1862 1862 | summary: added d
1863 1863 |
1864 1864 o changeset: 2:155349b645be
1865 1865 | user: test
1866 1866 | date: Thu Jan 01 00:00:00 1970 +0000
1867 1867 | summary: added c
1868 1868 |
1869 1869 o changeset: 1:5f6d8a4bf34a
1870 1870 | user: test
1871 1871 | date: Thu Jan 01 00:00:00 1970 +0000
1872 1872 | summary: added b
1873 1873 |
1874 1874 o changeset: 0:9092f1db7931
1875 1875 user: test
1876 1876 date: Thu Jan 01 00:00:00 1970 +0000
1877 1877 summary: added a
1878 1878
1879 1879 $ hg up '.^^'
1880 1880 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
1881 1881
1882 1882 $ echo foo > d
1883 1883 $ hg ci -Aqm "added foo to d"
1884 1884
1885 1885 $ hg graft --stop
1886 1886 abort: no interrupted graft found
1887 1887 [255]
1888 1888
1889 1889 $ hg graft -r 3
1890 1890 grafting 3:9150fe93bec6 "added d"
1891 1891 merging d
1892 1892 warning: conflicts while merging d! (edit, then use 'hg resolve --mark')
1893 1893 abort: unresolved conflicts, can't continue
1894 1894 (use 'hg resolve' and 'hg graft --continue')
1895 1895 [255]
1896 1896
1897 1897 $ hg graft --stop --continue
1898 1898 abort: cannot use '--continue' and '--stop' together
1899 1899 [255]
1900 1900
1901 1901 $ hg graft --stop -U
1902 1902 abort: cannot specify any other flag with '--stop'
1903 1903 [255]
1904 1904 $ hg graft --stop --rev 4
1905 1905 abort: cannot specify any other flag with '--stop'
1906 1906 [255]
1907 1907 $ hg graft --stop --log
1908 1908 abort: cannot specify any other flag with '--stop'
1909 1909 [255]
1910 1910
1911 1911 $ hg graft --stop
1912 1912 stopped the interrupted graft
1913 1913 working directory is now at a0deacecd59d
1914 1914
1915 1915 $ hg diff
1916 1916
1917 1917 $ hg log -Gr '.'
1918 1918 @ changeset: 4:a0deacecd59d
1919 1919 | tag: tip
1920 1920 ~ parent: 1:5f6d8a4bf34a
1921 1921 user: test
1922 1922 date: Thu Jan 01 00:00:00 1970 +0000
1923 1923 summary: added foo to d
1924 1924
1925 1925 $ hg graft -r 2 -r 3
1926 1926 grafting 2:155349b645be "added c"
1927 1927 grafting 3:9150fe93bec6 "added d"
1928 1928 merging d
1929 1929 warning: conflicts while merging d! (edit, then use 'hg resolve --mark')
1930 1930 abort: unresolved conflicts, can't continue
1931 1931 (use 'hg resolve' and 'hg graft --continue')
1932 1932 [255]
1933 1933
1934 1934 $ hg graft --stop
1935 1935 stopped the interrupted graft
1936 1936 working directory is now at 75b447541a9e
1937 1937
1938 1938 $ hg diff
1939 1939
1940 1940 $ hg log -G -T "{rev}:{node|short} {desc}"
1941 1941 @ 5:75b447541a9e added c
1942 1942 |
1943 1943 o 4:a0deacecd59d added foo to d
1944 1944 |
1945 1945 | o 3:9150fe93bec6 added d
1946 1946 | |
1947 1947 | o 2:155349b645be added c
1948 1948 |/
1949 1949 o 1:5f6d8a4bf34a added b
1950 1950 |
1951 1951 o 0:9092f1db7931 added a
1952 1952
1953 1953 $ cd ..
1954 1954
1955 1955 Testing the --abort flag for `hg graft` which aborts and rollback to state
1956 1956 before the graft
1957 1957
1958 1958 $ hg init abortgraft
1959 1959 $ cd abortgraft
1960 1960 $ for ch in a b c d; do echo $ch > $ch; hg add $ch; hg ci -Aqm "added "$ch; done;
1961 1961
1962 1962 $ hg up '.^^'
1963 1963 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
1964 1964
1965 1965 $ echo x > x
1966 1966 $ hg ci -Aqm "added x"
1967 1967 $ hg up '.^'
1968 1968 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
1969 1969 $ echo foo > c
1970 1970 $ hg ci -Aqm "added foo to c"
1971 1971
1972 1972 $ hg log -GT "{rev}:{node|short} {desc}"
1973 1973 @ 5:36b793615f78 added foo to c
1974 1974 |
1975 1975 | o 4:863a25e1a9ea added x
1976 1976 |/
1977 1977 | o 3:9150fe93bec6 added d
1978 1978 | |
1979 1979 | o 2:155349b645be added c
1980 1980 |/
1981 1981 o 1:5f6d8a4bf34a added b
1982 1982 |
1983 1983 o 0:9092f1db7931 added a
1984 1984
1985 1985 $ hg up 9150fe93bec6
1986 1986 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
1987 1987
1988 1988 $ hg graft --abort
1989 1989 abort: no interrupted graft to abort
1990 1990 [255]
1991 1991
1992 1992 when stripping is required
1993 1993 $ hg graft -r 4 -r 5
1994 1994 grafting 4:863a25e1a9ea "added x"
1995 1995 grafting 5:36b793615f78 "added foo to c" (tip)
1996 1996 merging c
1997 1997 warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
1998 1998 abort: unresolved conflicts, can't continue
1999 1999 (use 'hg resolve' and 'hg graft --continue')
2000 2000 [255]
2001 2001
2002 2002 $ hg graft --continue --abort
2003 2003 abort: cannot use '--continue' and '--abort' together
2004 2004 [255]
2005 2005
2006 2006 $ hg graft --abort --stop
2007 2007 abort: cannot use '--abort' and '--stop' together
2008 2008 [255]
2009 2009
2010 2010 $ hg graft --abort --currentuser
2011 2011 abort: cannot specify any other flag with '--abort'
2012 2012 [255]
2013 2013
2014 2014 $ hg graft --abort --edit
2015 2015 abort: cannot specify any other flag with '--abort'
2016 2016 [255]
2017 2017
2018 2018 $ hg graft --abort
2019 2019 graft aborted
2020 2020 working directory is now at 9150fe93bec6
2021 2021 $ hg log -GT "{rev}:{node|short} {desc}"
2022 2022 o 5:36b793615f78 added foo to c
2023 2023 |
2024 2024 | o 4:863a25e1a9ea added x
2025 2025 |/
2026 2026 | @ 3:9150fe93bec6 added d
2027 2027 | |
2028 2028 | o 2:155349b645be added c
2029 2029 |/
2030 2030 o 1:5f6d8a4bf34a added b
2031 2031 |
2032 2032 o 0:9092f1db7931 added a
2033 2033
2034 2034 when stripping is not required
2035 2035 $ hg graft -r 5
2036 2036 grafting 5:36b793615f78 "added foo to c" (tip)
2037 2037 merging c
2038 2038 warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
2039 2039 abort: unresolved conflicts, can't continue
2040 2040 (use 'hg resolve' and 'hg graft --continue')
2041 2041 [255]
2042 2042
2043 2043 $ hg graft --abort
2044 2044 graft aborted
2045 2045 working directory is now at 9150fe93bec6
2046 2046 $ hg log -GT "{rev}:{node|short} {desc}"
2047 2047 o 5:36b793615f78 added foo to c
2048 2048 |
2049 2049 | o 4:863a25e1a9ea added x
2050 2050 |/
2051 2051 | @ 3:9150fe93bec6 added d
2052 2052 | |
2053 2053 | o 2:155349b645be added c
2054 2054 |/
2055 2055 o 1:5f6d8a4bf34a added b
2056 2056 |
2057 2057 o 0:9092f1db7931 added a
2058 2058
2059 2059 when some of the changesets became public
2060 2060
2061 2061 $ hg graft -r 4 -r 5
2062 2062 grafting 4:863a25e1a9ea "added x"
2063 2063 grafting 5:36b793615f78 "added foo to c" (tip)
2064 2064 merging c
2065 2065 warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
2066 2066 abort: unresolved conflicts, can't continue
2067 2067 (use 'hg resolve' and 'hg graft --continue')
2068 2068 [255]
2069 2069
2070 2070 $ hg log -GT "{rev}:{node|short} {desc}"
2071 2071 @ 6:6ec71c037d94 added x
2072 2072 |
2073 2073 | o 5:36b793615f78 added foo to c
2074 2074 | |
2075 2075 | | o 4:863a25e1a9ea added x
2076 2076 | |/
2077 2077 o | 3:9150fe93bec6 added d
2078 2078 | |
2079 2079 o | 2:155349b645be added c
2080 2080 |/
2081 2081 o 1:5f6d8a4bf34a added b
2082 2082 |
2083 2083 o 0:9092f1db7931 added a
2084 2084
2085 2085 $ hg phase -r 6 --public
2086 2086
2087 2087 $ hg graft --abort
2088 2088 cannot clean up public changesets 6ec71c037d94
2089 2089 graft aborted
2090 2090 working directory is now at 6ec71c037d94
2091 2091
2092 2092 when we created new changesets on top of existing one
2093 2093
2094 2094 $ hg up '.^^'
2095 2095 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
2096 2096 $ echo y > y
2097 2097 $ hg ci -Aqm "added y"
2098 2098 $ echo z > z
2099 2099 $ hg ci -Aqm "added z"
2100 2100
2101 2101 $ hg up 3
2102 2102 1 files updated, 0 files merged, 3 files removed, 0 files unresolved
2103 2103 $ hg log -GT "{rev}:{node|short} {desc}"
2104 2104 o 8:637f9e9bbfd4 added z
2105 2105 |
2106 2106 o 7:123221671fd4 added y
2107 2107 |
2108 2108 | o 6:6ec71c037d94 added x
2109 2109 | |
2110 2110 | | o 5:36b793615f78 added foo to c
2111 2111 | | |
2112 2112 | | | o 4:863a25e1a9ea added x
2113 2113 | | |/
2114 2114 | @ | 3:9150fe93bec6 added d
2115 2115 |/ /
2116 2116 o / 2:155349b645be added c
2117 2117 |/
2118 2118 o 1:5f6d8a4bf34a added b
2119 2119 |
2120 2120 o 0:9092f1db7931 added a
2121 2121
2122 2122 $ hg graft -r 8 -r 7 -r 5
2123 2123 grafting 8:637f9e9bbfd4 "added z" (tip)
2124 2124 grafting 7:123221671fd4 "added y"
2125 2125 grafting 5:36b793615f78 "added foo to c"
2126 2126 merging c
2127 2127 warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
2128 2128 abort: unresolved conflicts, can't continue
2129 2129 (use 'hg resolve' and 'hg graft --continue')
2130 2130 [255]
2131 2131
2132 2132 $ cd ..
2133 2133 $ hg init pullrepo
2134 2134 $ cd pullrepo
2135 2135 $ cat >> .hg/hgrc <<EOF
2136 2136 > [phases]
2137 2137 > publish=False
2138 2138 > EOF
2139 2139 $ hg pull ../abortgraft --config phases.publish=False
2140 2140 pulling from ../abortgraft
2141 2141 requesting all changes
2142 2142 adding changesets
2143 2143 adding manifests
2144 2144 adding file changes
2145 2145 added 11 changesets with 9 changes to 8 files (+4 heads)
2146 2146 new changesets 9092f1db7931:6b98ff0062dd (6 drafts)
2147 2147 (run 'hg heads' to see heads, 'hg merge' to merge)
2148 2148 $ hg up 9
2149 2149 5 files updated, 0 files merged, 0 files removed, 0 files unresolved
2150 2150 $ echo w > w
2151 2151 $ hg ci -Aqm "added w" --config phases.publish=False
2152 2152
2153 2153 $ cd ../abortgraft
2154 2154 $ hg pull ../pullrepo
2155 2155 pulling from ../pullrepo
2156 2156 searching for changes
2157 2157 adding changesets
2158 2158 adding manifests
2159 2159 adding file changes
2160 2160 added 1 changesets with 1 changes to 1 files (+1 heads)
2161 2161 new changesets 311dfc6cf3bf (1 drafts)
2162 2162 (run 'hg heads .' to see heads, 'hg merge' to merge)
2163 2163
2164 2164 $ hg graft --abort
2165 2165 new changesets detected on destination branch, can't strip
2166 2166 graft aborted
2167 2167 working directory is now at 6b98ff0062dd
2168 2168
2169 2169 $ cd ..
2170 2170
2171 2171 ============================
2172 2172 Testing --no-commit option:|
2173 2173 ============================
2174 2174
2175 2175 $ hg init nocommit
2176 2176 $ cd nocommit
2177 2177 $ echo a > a
2178 2178 $ hg ci -qAma
2179 2179 $ echo b > b
2180 2180 $ hg ci -qAmb
2181 2181 $ hg up -q 0
2182 2182 $ echo c > c
2183 2183 $ hg ci -qAmc
2184 2184 $ hg log -GT "{rev}:{node|short} {desc}\n"
2185 2185 @ 2:d36c0562f908 c
2186 2186 |
2187 2187 | o 1:d2ae7f538514 b
2188 2188 |/
2189 2189 o 0:cb9a9f314b8b a
2190 2190
2191 2191
2192 2192 Check reporting when --no-commit used with non-applicable options:
2193 2193
2194 2194 $ hg graft 1 --no-commit -e
2195 2195 abort: cannot specify --no-commit and --edit together
2196 2196 [255]
2197 2197
2198 2198 $ hg graft 1 --no-commit --log
2199 2199 abort: cannot specify --no-commit and --log together
2200 2200 [255]
2201 2201
2202 2202 $ hg graft 1 --no-commit -D
2203 2203 abort: cannot specify --no-commit and --currentdate together
2204 2204 [255]
2205 2205
2206 2206 Test --no-commit is working:
2207 2207 $ hg graft 1 --no-commit
2208 2208 grafting 1:d2ae7f538514 "b"
2209 2209
2210 2210 $ hg log -GT "{rev}:{node|short} {desc}\n"
2211 2211 @ 2:d36c0562f908 c
2212 2212 |
2213 2213 | o 1:d2ae7f538514 b
2214 2214 |/
2215 2215 o 0:cb9a9f314b8b a
2216 2216
2217 2217
2218 2218 $ hg diff
2219 2219 diff -r d36c0562f908 b
2220 2220 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2221 2221 +++ b/b Thu Jan 01 00:00:00 1970 +0000
2222 2222 @@ -0,0 +1,1 @@
2223 2223 +b
2224 2224
2225 2225 Prepare wrdir to check --no-commit is resepected after --continue:
2226 2226
2227 2227 $ hg up -qC
2228 2228 $ echo A>a
2229 2229 $ hg ci -qm "A in file a"
2230 2230 $ hg up -q 1
2231 2231 $ echo B>a
2232 2232 $ hg ci -qm "B in file a"
2233 2233 $ hg log -GT "{rev}:{node|short} {desc}\n"
2234 2234 @ 4:2aa9ad1006ff B in file a
2235 2235 |
2236 2236 | o 3:09e253b87e17 A in file a
2237 2237 | |
2238 2238 | o 2:d36c0562f908 c
2239 2239 | |
2240 2240 o | 1:d2ae7f538514 b
2241 2241 |/
2242 2242 o 0:cb9a9f314b8b a
2243 2243
2244 2244
2245 2245 $ hg graft 3 --no-commit
2246 2246 grafting 3:09e253b87e17 "A in file a"
2247 2247 merging a
2248 2248 warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
2249 2249 abort: unresolved conflicts, can't continue
2250 2250 (use 'hg resolve' and 'hg graft --continue')
2251 2251 [255]
2252 2252
2253 2253 Resolve conflict:
2254 2254 $ echo A>a
2255 2255 $ hg resolve --mark
2256 2256 (no more unresolved files)
2257 2257 continue: hg graft --continue
2258 2258
2259 2259 $ hg graft --continue
2260 2260 grafting 3:09e253b87e17 "A in file a"
2261 2261 $ hg log -GT "{rev}:{node|short} {desc}\n"
2262 2262 @ 4:2aa9ad1006ff B in file a
2263 2263 |
2264 2264 | o 3:09e253b87e17 A in file a
2265 2265 | |
2266 2266 | o 2:d36c0562f908 c
2267 2267 | |
2268 2268 o | 1:d2ae7f538514 b
2269 2269 |/
2270 2270 o 0:cb9a9f314b8b a
2271 2271
2272 2272 $ hg diff
2273 2273 diff -r 2aa9ad1006ff a
2274 2274 --- a/a Thu Jan 01 00:00:00 1970 +0000
2275 2275 +++ b/a Thu Jan 01 00:00:00 1970 +0000
2276 2276 @@ -1,1 +1,1 @@
2277 2277 -B
2278 2278 +A
2279 2279
2280 2280 $ hg up -qC
2281 2281
2282 2282 Check --no-commit is resepected when passed with --continue:
2283 2283
2284 2284 $ hg graft 3
2285 2285 grafting 3:09e253b87e17 "A in file a"
2286 2286 merging a
2287 2287 warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
2288 2288 abort: unresolved conflicts, can't continue
2289 2289 (use 'hg resolve' and 'hg graft --continue')
2290 2290 [255]
2291 2291
2292 2292 Resolve conflict:
2293 2293 $ echo A>a
2294 2294 $ hg resolve --mark
2295 2295 (no more unresolved files)
2296 2296 continue: hg graft --continue
2297 2297
2298 2298 $ hg graft --continue --no-commit
2299 2299 grafting 3:09e253b87e17 "A in file a"
2300 2300 $ hg diff
2301 2301 diff -r 2aa9ad1006ff a
2302 2302 --- a/a Thu Jan 01 00:00:00 1970 +0000
2303 2303 +++ b/a Thu Jan 01 00:00:00 1970 +0000
2304 2304 @@ -1,1 +1,1 @@
2305 2305 -B
2306 2306 +A
2307 2307
2308 2308 $ hg log -GT "{rev}:{node|short} {desc}\n"
2309 2309 @ 4:2aa9ad1006ff B in file a
2310 2310 |
2311 2311 | o 3:09e253b87e17 A in file a
2312 2312 | |
2313 2313 | o 2:d36c0562f908 c
2314 2314 | |
2315 2315 o | 1:d2ae7f538514 b
2316 2316 |/
2317 2317 o 0:cb9a9f314b8b a
2318 2318
2319 2319 $ hg up -qC
2320 2320
2321 2321 Test --no-commit when graft multiple revisions:
2322 2322 When there is conflict:
2323 2323 $ hg graft -r "2::3" --no-commit
2324 2324 grafting 2:d36c0562f908 "c"
2325 2325 grafting 3:09e253b87e17 "A in file a"
2326 2326 merging a
2327 2327 warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
2328 2328 abort: unresolved conflicts, can't continue
2329 2329 (use 'hg resolve' and 'hg graft --continue')
2330 2330 [255]
2331 2331
2332 2332 $ echo A>a
2333 2333 $ hg resolve --mark
2334 2334 (no more unresolved files)
2335 2335 continue: hg graft --continue
2336 2336 $ hg graft --continue
2337 2337 grafting 3:09e253b87e17 "A in file a"
2338 2338 $ hg diff
2339 2339 diff -r 2aa9ad1006ff a
2340 2340 --- a/a Thu Jan 01 00:00:00 1970 +0000
2341 2341 +++ b/a Thu Jan 01 00:00:00 1970 +0000
2342 2342 @@ -1,1 +1,1 @@
2343 2343 -B
2344 2344 +A
2345 2345 diff -r 2aa9ad1006ff c
2346 2346 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2347 2347 +++ b/c Thu Jan 01 00:00:00 1970 +0000
2348 2348 @@ -0,0 +1,1 @@
2349 2349 +c
2350 2350
2351 2351 $ hg log -GT "{rev}:{node|short} {desc}\n"
2352 2352 @ 4:2aa9ad1006ff B in file a
2353 2353 |
2354 2354 | o 3:09e253b87e17 A in file a
2355 2355 | |
2356 2356 | o 2:d36c0562f908 c
2357 2357 | |
2358 2358 o | 1:d2ae7f538514 b
2359 2359 |/
2360 2360 o 0:cb9a9f314b8b a
2361 2361
2362 2362 $ hg up -qC
2363 2363
2364 2364 When there is no conflict:
2365 2365 $ echo d>d
2366 2366 $ hg add d -q
2367 2367 $ hg ci -qmd
2368 2368 $ hg up 3 -q
2369 2369 $ hg log -GT "{rev}:{node|short} {desc}\n"
2370 2370 o 5:baefa8927fc0 d
2371 2371 |
2372 2372 o 4:2aa9ad1006ff B in file a
2373 2373 |
2374 2374 | @ 3:09e253b87e17 A in file a
2375 2375 | |
2376 2376 | o 2:d36c0562f908 c
2377 2377 | |
2378 2378 o | 1:d2ae7f538514 b
2379 2379 |/
2380 2380 o 0:cb9a9f314b8b a
2381 2381
2382 2382
2383 2383 $ hg graft -r 1 -r 5 --no-commit
2384 2384 grafting 1:d2ae7f538514 "b"
2385 2385 grafting 5:baefa8927fc0 "d" (tip)
2386 2386 $ hg diff
2387 2387 diff -r 09e253b87e17 b
2388 2388 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2389 2389 +++ b/b Thu Jan 01 00:00:00 1970 +0000
2390 2390 @@ -0,0 +1,1 @@
2391 2391 +b
2392 2392 diff -r 09e253b87e17 d
2393 2393 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2394 2394 +++ b/d Thu Jan 01 00:00:00 1970 +0000
2395 2395 @@ -0,0 +1,1 @@
2396 2396 +d
2397 2397 $ hg log -GT "{rev}:{node|short} {desc}\n"
2398 2398 o 5:baefa8927fc0 d
2399 2399 |
2400 2400 o 4:2aa9ad1006ff B in file a
2401 2401 |
2402 2402 | @ 3:09e253b87e17 A in file a
2403 2403 | |
2404 2404 | o 2:d36c0562f908 c
2405 2405 | |
2406 2406 o | 1:d2ae7f538514 b
2407 2407 |/
2408 2408 o 0:cb9a9f314b8b a
2409 2409
2410 2410 $ cd ..
@@ -1,379 +1,379
1 1 $ cat <<'EOF' >> "$HGRCPATH"
2 2 > [extensions]
3 3 > convert =
4 4 > [templates]
5 5 > l = '{rev}:{node|short} p={p1rev},{p2rev} m={manifest} f={files|json}'
6 6 > EOF
7 7
8 8 $ check_convert_identity () {
9 9 > hg convert -q "$1" "$1.converted"
10 10 > hg outgoing -q -R "$1.converted" "$1"
11 11 > if [ "$?" != 1 ]; then
12 12 > echo '*** BUG: hash changes on convert ***'
13 13 > hg log -R "$1.converted" -GTl
14 14 > fi
15 15 > }
16 16
17 17 Files added at both parents:
18 18
19 19 $ hg init added-both
20 20 $ cd added-both
21 21 $ touch a b c
22 22 $ hg ci -qAm0 a
23 23 $ hg ci -qAm1 b
24 24 $ hg up -q 0
25 25 $ hg ci -qAm2 c
26 26
27 27 $ hg merge
28 28 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
29 29 (branch merge, don't forget to commit)
30 30 $ hg ci --debug -m merge
31 31 committing files:
32 32 b
33 33 not reusing manifest (no file change in changelog, but manifest differs)
34 34 committing manifest
35 35 committing changelog
36 36 updating the branch cache
37 37 committed changeset 3:7aa8a293f5d97377037afc21e871e036e718d659
38 38 $ hg log -GTl
39 39 @ 3:7aa8a293f5d9 p=2,1 m=3:8667461869a1 f=[]
40 40 |\
41 41 | o 2:e0ea47086fce p=0,-1 m=2:b2e5b07f9374 f=["c"]
42 42 | |
43 43 o | 1:64d01526d4c2 p=0,-1 m=1:686dbf0aeca4 f=["b"]
44 44 |/
45 45 o 0:487a0a245cea p=-1,-1 m=0:8515d4bfda76 f=["a"]
46 46
47 47
48 48 $ cd ..
49 49 $ check_convert_identity added-both
50 50
51 51 Files added at both parents, but the other removed at the merge:
52 52 (In this case, ctx.files() after the commit contains the removed file "b", but
53 53 its manifest does not differ from p1.)
54 54
55 55 $ hg init added-both-removed-at-merge
56 56 $ cd added-both-removed-at-merge
57 57 $ touch a b c
58 58 $ hg ci -qAm0 a
59 59 $ hg ci -qAm1 b
60 60 $ hg up -q 0
61 61 $ hg ci -qAm2 c
62 62
63 63 $ hg merge
64 64 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
65 65 (branch merge, don't forget to commit)
66 66 $ hg rm -f b
67 67 $ hg ci --debug -m merge
68 68 committing files:
69 69 committing manifest
70 70 committing changelog
71 71 updating the branch cache
72 72 committed changeset 3:915745f3ca3d9d699925269474c2d0a9526e8dfa
73 73 $ hg log -GTl
74 74 @ 3:915745f3ca3d p=2,1 m=3:8e9cf3456921 f=["b"]
75 75 |\
76 76 | o 2:e0ea47086fce p=0,-1 m=2:b2e5b07f9374 f=["c"]
77 77 | |
78 78 o | 1:64d01526d4c2 p=0,-1 m=1:686dbf0aeca4 f=["b"]
79 79 |/
80 80 o 0:487a0a245cea p=-1,-1 m=0:8515d4bfda76 f=["a"]
81 81
82 82
83 83 $ cd ..
84 84 $ check_convert_identity added-both
85 85
86 86 An identical file added at both parents:
87 87
88 88 $ hg init added-identical
89 89 $ cd added-identical
90 90 $ touch a b
91 91 $ hg ci -qAm0 a
92 92 $ hg ci -qAm1 b
93 93 $ hg up -q 0
94 94 $ touch b
95 95 $ hg ci -qAm2 b
96 96
97 97 $ hg merge
98 98 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
99 99 (branch merge, don't forget to commit)
100 100 $ hg ci --debug -m merge
101 101 reusing manifest from p1 (no file change)
102 102 committing changelog
103 103 updating the branch cache
104 104 committed changeset 3:de26182cd210f0c3fb175ca7616704ab963d3024
105 105 $ hg log -GTl
106 106 @ 3:de26182cd210 p=2,1 m=1:686dbf0aeca4 f=[]
107 107 |\
108 108 | o 2:f00991f11eca p=0,-1 m=1:686dbf0aeca4 f=["b"]
109 109 | |
110 110 o | 1:64d01526d4c2 p=0,-1 m=1:686dbf0aeca4 f=["b"]
111 111 |/
112 112 o 0:487a0a245cea p=-1,-1 m=0:8515d4bfda76 f=["a"]
113 113
114 114
115 115 $ cd ..
116 116 $ check_convert_identity added-identical
117 117
118 118 #if execbit
119 119
120 120 An identical file added at both parents, but the flag differs. Take local:
121 121
122 122 $ hg init flag-change-take-p1
123 123 $ cd flag-change-take-p1
124 124 $ touch a b
125 125 $ hg ci -qAm0 a
126 126 $ hg ci -qAm1 b
127 127 $ hg up -q 0
128 128 $ touch b
129 129 $ chmod +x b
130 130 $ hg ci -qAm2 b
131 131
132 132 $ hg merge
133 133 warning: cannot merge flags for b without common ancestor - keeping local flags
134 134 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
135 135 (branch merge, don't forget to commit)
136 136 $ chmod +x b
137 137 $ hg ci --debug -m merge
138 138 committing files:
139 139 b
140 reusing manifest form p1 (listed files actually unchanged)
140 reusing manifest from p1 (listed files actually unchanged)
141 141 committing changelog
142 142 updating the branch cache
143 143 committed changeset 3:c8d50407916ef8a5a97cb6e36ca9bc844a6ee13e
144 144 $ hg log -GTl
145 145 @ 3:c8d50407916e p=2,1 m=2:36b69ba4b24b f=[]
146 146 |\
147 147 | o 2:99451f16b3f5 p=0,-1 m=2:36b69ba4b24b f=["b"]
148 148 | |
149 149 o | 1:64d01526d4c2 p=0,-1 m=1:686dbf0aeca4 f=["b"]
150 150 |/
151 151 o 0:487a0a245cea p=-1,-1 m=0:8515d4bfda76 f=["a"]
152 152
153 153 $ hg files -vr3
154 154 0 a
155 155 0 x b
156 156
157 157 $ cd ..
158 158 $ check_convert_identity flag-change-take-p1
159 159
160 160 An identical file added at both parents, but the flag differs. Take other:
161 161
162 162 $ hg init flag-change-take-p2
163 163 $ cd flag-change-take-p2
164 164 $ touch a b
165 165 $ hg ci -qAm0 a
166 166 $ hg ci -qAm1 b
167 167 $ hg up -q 0
168 168 $ touch b
169 169 $ chmod +x b
170 170 $ hg ci -qAm2 b
171 171
172 172 $ hg merge
173 173 warning: cannot merge flags for b without common ancestor - keeping local flags
174 174 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
175 175 (branch merge, don't forget to commit)
176 176 $ chmod -x b
177 177 $ hg ci --debug -m merge
178 178 committing files:
179 179 b
180 180 committing manifest
181 181 committing changelog
182 182 updating the branch cache
183 183 committed changeset 3:06a62a687d87c7d8944743dee1ee9d8c66b3f6e3
184 184 $ hg log -GTl
185 185 @ 3:06a62a687d87 p=2,1 m=3:2a315ba1aa45 f=["b"]
186 186 |\
187 187 | o 2:99451f16b3f5 p=0,-1 m=2:36b69ba4b24b f=["b"]
188 188 | |
189 189 o | 1:64d01526d4c2 p=0,-1 m=1:686dbf0aeca4 f=["b"]
190 190 |/
191 191 o 0:487a0a245cea p=-1,-1 m=0:8515d4bfda76 f=["a"]
192 192
193 193 $ hg files -vr3
194 194 0 a
195 195 0 b
196 196
197 197 $ cd ..
198 198 $ check_convert_identity flag-change-take-p2
199 199
200 200 #endif
201 201
202 202 An identical file added at both parents, one more file added at p2:
203 203
204 204 $ hg init added-some-p2
205 205 $ cd added-some-p2
206 206 $ touch a b c
207 207 $ hg ci -qAm0 a
208 208 $ hg ci -qAm1 b
209 209 $ hg ci -qAm2 c
210 210 $ hg up -q 0
211 211 $ touch b
212 212 $ hg ci -qAm3 b
213 213
214 214 $ hg merge
215 215 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
216 216 (branch merge, don't forget to commit)
217 217 $ hg ci --debug -m merge
218 218 committing files:
219 219 c
220 220 not reusing manifest (no file change in changelog, but manifest differs)
221 221 committing manifest
222 222 committing changelog
223 223 updating the branch cache
224 224 committed changeset 4:f7fbc4e4d9a8fde03ba475adad675578c8bf472d
225 225 $ hg log -GTl
226 226 @ 4:f7fbc4e4d9a8 p=3,2 m=3:92acd5bfd716 f=[]
227 227 |\
228 228 | o 3:e9d9f3cc981f p=0,-1 m=1:686dbf0aeca4 f=["b"]
229 229 | |
230 230 o | 2:93c5529a4ec7 p=1,-1 m=2:ae25a31b30b3 f=["c"]
231 231 | |
232 232 o | 1:64d01526d4c2 p=0,-1 m=1:686dbf0aeca4 f=["b"]
233 233 |/
234 234 o 0:487a0a245cea p=-1,-1 m=0:8515d4bfda76 f=["a"]
235 235
236 236
237 237 $ cd ..
238 238 $ check_convert_identity added-some-p2
239 239
240 240 An identical file added at both parents, one more file added at p1:
241 241 (In this case, p1 manifest is reused at the merge commit, which means the
242 242 manifest DAG does not have the same shape as the changelog.)
243 243
244 244 $ hg init added-some-p1
245 245 $ cd added-some-p1
246 246 $ touch a b
247 247 $ hg ci -qAm0 a
248 248 $ hg ci -qAm1 b
249 249 $ hg up -q 0
250 250 $ touch b c
251 251 $ hg ci -qAm2 b
252 252 $ hg ci -qAm3 c
253 253
254 254 $ hg merge
255 255 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
256 256 (branch merge, don't forget to commit)
257 257 $ hg ci --debug -m merge
258 258 reusing manifest from p1 (no file change)
259 259 committing changelog
260 260 updating the branch cache
261 261 committed changeset 4:a9f0f589a913f5a149dc10dfbd5af726977c36c4
262 262 $ hg log -GTl
263 263 @ 4:a9f0f589a913 p=3,1 m=2:ae25a31b30b3 f=[]
264 264 |\
265 265 | o 3:b8dc385241b5 p=2,-1 m=2:ae25a31b30b3 f=["c"]
266 266 | |
267 267 | o 2:f00991f11eca p=0,-1 m=1:686dbf0aeca4 f=["b"]
268 268 | |
269 269 o | 1:64d01526d4c2 p=0,-1 m=1:686dbf0aeca4 f=["b"]
270 270 |/
271 271 o 0:487a0a245cea p=-1,-1 m=0:8515d4bfda76 f=["a"]
272 272
273 273
274 274 $ cd ..
275 275 $ check_convert_identity added-some-p1
276 276
277 277 A file added at p2, a named branch created at p1:
278 278
279 279 $ hg init named-branch-p1
280 280 $ cd named-branch-p1
281 281 $ touch a b
282 282 $ hg ci -qAm0 a
283 283 $ hg ci -qAm1 b
284 284 $ hg up -q 0
285 285 $ hg branch -q foo
286 286 $ hg ci -m2
287 287
288 288 $ hg merge default
289 289 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
290 290 (branch merge, don't forget to commit)
291 291 $ hg ci --debug -m merge
292 292 committing files:
293 293 b
294 294 not reusing manifest (no file change in changelog, but manifest differs)
295 295 committing manifest
296 296 committing changelog
297 297 updating the branch cache
298 298 committed changeset 3:fb97d83b02fd072295cfc2171f21b7d38509bfd7
299 299 $ hg log -GT'{l} branch={branch}'
300 300 @ 3:fb97d83b02fd p=2,1 m=2:9091c64f4ea1 f=[] branch=foo
301 301 |\
302 302 | o 2:a3a9fa6587e5 p=0,-1 m=0:8515d4bfda76 f=[] branch=foo
303 303 | |
304 304 o | 1:64d01526d4c2 p=0,-1 m=1:686dbf0aeca4 f=["b"] branch=default
305 305 |/
306 306 o 0:487a0a245cea p=-1,-1 m=0:8515d4bfda76 f=["a"] branch=default
307 307
308 308
309 309 $ cd ..
310 310 $ check_convert_identity named-branch-p1
311 311
312 312 A file added at p1, a named branch created at p2:
313 313 (In this case, p1 manifest is reused at the merge commit, which means the
314 314 manifest DAG does not have the same shape as the changelog.)
315 315
316 316 $ hg init named-branch-p2
317 317 $ cd named-branch-p2
318 318 $ touch a b
319 319 $ hg ci -qAm0 a
320 320 $ hg branch -q foo
321 321 $ hg ci -m1
322 322 $ hg up -q 0
323 323 $ hg ci -qAm1 b
324 324
325 325 $ hg merge foo
326 326 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
327 327 (branch merge, don't forget to commit)
328 328 $ hg ci --debug -m merge
329 329 reusing manifest from p1 (no file change)
330 330 committing changelog
331 331 updating the branch cache
332 332 committed changeset 3:036823e24692218324d4af43b07ff89f8a000096
333 333 $ hg log -GT'{l} branch={branch}'
334 334 @ 3:036823e24692 p=2,1 m=1:686dbf0aeca4 f=[] branch=default
335 335 |\
336 336 | o 2:64d01526d4c2 p=0,-1 m=1:686dbf0aeca4 f=["b"] branch=default
337 337 | |
338 338 o | 1:da38c8e00727 p=0,-1 m=0:8515d4bfda76 f=[] branch=foo
339 339 |/
340 340 o 0:487a0a245cea p=-1,-1 m=0:8515d4bfda76 f=["a"] branch=default
341 341
342 342
343 343 $ cd ..
344 344 $ check_convert_identity named-branch-p2
345 345
346 346 A file changed once at both parents, but amended to have identical content:
347 347
348 348 $ hg init amend-p1
349 349 $ cd amend-p1
350 350 $ touch a
351 351 $ hg ci -qAm0 a
352 352 $ echo foo > a
353 353 $ hg ci -m1
354 354 $ hg up -q 0
355 355 $ echo bar > a
356 356 $ hg ci -qm2
357 357 $ echo foo > a
358 358 $ hg ci -qm3 --amend
359 359
360 360 $ hg merge
361 361 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
362 362 (branch merge, don't forget to commit)
363 363 $ hg ci --debug -m merge
364 364 reusing manifest from p1 (no file change)
365 365 committing changelog
366 366 updating the branch cache
367 367 committed changeset 3:314e5bc5adf5c58ea571efabe33eedba20a201aa
368 368 $ hg log -GT'{l} branch={branch}'
369 369 @ 3:314e5bc5adf5 p=2,1 m=1:d33ea248bd73 f=[] branch=default
370 370 |\
371 371 | o 2:de9c64f226a3 p=0,-1 m=1:d33ea248bd73 f=["a"] branch=default
372 372 | |
373 373 o | 1:6a74aec01b3c p=0,-1 m=1:d33ea248bd73 f=["a"] branch=default
374 374 |/
375 375 o 0:487a0a245cea p=-1,-1 m=0:8515d4bfda76 f=["a"] branch=default
376 376
377 377
378 378 $ cd ..
379 379 $ check_convert_identity amend-p1
General Comments 0
You need to be logged in to leave comments. Login now