Show More
@@ -439,7 +439,7 b' def demo(ui, repo, *args, **opts):' | |||
|
439 | 439 | baseui = ui |
|
440 | 440 | else: |
|
441 | 441 | baseui = repo.baseui |
|
442 |
repo = localrepo. |
|
|
442 | repo = localrepo.instance(baseui, tmpdir, create=True) | |
|
443 | 443 | ui.setconfig('keyword', fn, '', 'keyword') |
|
444 | 444 | svn = ui.configbool('keywordset', 'svn') |
|
445 | 445 | # explicitly set keywordset for demo output |
@@ -426,7 +426,13 b' class localrepository(object):' | |||
|
426 | 426 | 'bisect.state', |
|
427 | 427 | } |
|
428 | 428 | |
|
429 |
def __init__(self, baseui, path, |
|
|
429 | def __init__(self, baseui, path, intents=None): | |
|
430 | """Create a new local repository instance. | |
|
431 | ||
|
432 | Most callers should use ``hg.repository()`` or ``localrepo.instance()`` | |
|
433 | for obtaining a new repository object. | |
|
434 | """ | |
|
435 | ||
|
430 | 436 | self.requirements = set() |
|
431 | 437 | self.filtername = None |
|
432 | 438 | # wvfs: rooted at the repository root, used to access the working copy |
@@ -475,31 +481,12 b' class localrepository(object):' | |||
|
475 | 481 | self.supported.add('exp-compression-%s' % name) |
|
476 | 482 | |
|
477 | 483 | if not self.vfs.isdir(): |
|
478 | if create: | |
|
479 | self.requirements = newreporequirements(self.ui) | |
|
480 | ||
|
481 | if not self.wvfs.exists(): | |
|
482 | self.wvfs.makedirs() | |
|
483 | self.vfs.makedir(notindexed=True) | |
|
484 | ||
|
485 | if 'store' in self.requirements: | |
|
486 | self.vfs.mkdir("store") | |
|
487 | ||
|
488 | # create an invalid changelog | |
|
489 | self.vfs.append( | |
|
490 | "00changelog.i", | |
|
491 | '\0\0\0\2' # represents revlogv2 | |
|
492 | ' dummy changelog to prevent using the old repo layout' | |
|
493 | ) | |
|
494 | else: | |
|
495 | 484 |
|
|
496 | 485 |
|
|
497 | 486 |
|
|
498 | 487 |
|
|
499 | 488 |
|
|
500 | 489 |
|
|
501 | elif create: | |
|
502 | raise error.RepoError(_("repository %s already exists") % path) | |
|
503 | 490 | else: |
|
504 | 491 | try: |
|
505 | 492 | self.requirements = scmutil.readrequires( |
@@ -546,8 +533,6 b' class localrepository(object):' | |||
|
546 | 533 | else: # standard vfs |
|
547 | 534 | self.svfs.audit = self._getsvfsward(self.svfs.audit) |
|
548 | 535 | self._applyopenerreqs() |
|
549 | if create: | |
|
550 | self._writerequirements() | |
|
551 | 536 | |
|
552 | 537 | self._dirstatevalidatewarned = False |
|
553 | 538 | |
@@ -2396,8 +2381,15 b' def undoname(fn):' | |||
|
2396 | 2381 | return os.path.join(base, name.replace('journal', 'undo', 1)) |
|
2397 | 2382 | |
|
2398 | 2383 | def instance(ui, path, create, intents=None): |
|
2399 | return localrepository(ui, util.urllocalpath(path), create, | |
|
2400 | intents=intents) | |
|
2384 | if create: | |
|
2385 | vfs = vfsmod.vfs(path, expandpath=True, realpath=True) | |
|
2386 | ||
|
2387 | if vfs.exists('.hg'): | |
|
2388 | raise error.RepoError(_('repository %s already exists') % path) | |
|
2389 | ||
|
2390 | createrepository(ui, vfs) | |
|
2391 | ||
|
2392 | return localrepository(ui, util.urllocalpath(path), intents=intents) | |
|
2401 | 2393 | |
|
2402 | 2394 | def islocal(path): |
|
2403 | 2395 | return True |
@@ -2447,3 +2439,34 b' def newreporequirements(ui):' | |||
|
2447 | 2439 | requirements.add('internal-phase') |
|
2448 | 2440 | |
|
2449 | 2441 | return requirements |
|
2442 | ||
|
2443 | def createrepository(ui, wdirvfs): | |
|
2444 | """Create a new repository in a vfs. | |
|
2445 | ||
|
2446 | ``wdirvfs`` is a vfs instance pointing at the working directory. | |
|
2447 | ``requirements`` is a set of requirements for the new repository. | |
|
2448 | """ | |
|
2449 | requirements = newreporequirements(ui) | |
|
2450 | ||
|
2451 | if not wdirvfs.exists(): | |
|
2452 | wdirvfs.makedirs() | |
|
2453 | ||
|
2454 | hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg')) | |
|
2455 | hgvfs.makedir(notindexed=True) | |
|
2456 | ||
|
2457 | if b'store' in requirements: | |
|
2458 | hgvfs.mkdir(b'store') | |
|
2459 | ||
|
2460 | # We create an invalid changelog outside the store so very old | |
|
2461 | # Mercurial versions (which didn't know about the requirements | |
|
2462 | # file) encounter an error on reading the changelog. This | |
|
2463 | # effectively locks out old clients and prevents them from | |
|
2464 | # mucking with a repo in an unknown format. | |
|
2465 | # | |
|
2466 | # The revlog header has version 2, which won't be recognized by | |
|
2467 | # such old clients. | |
|
2468 | hgvfs.append(b'00changelog.i', | |
|
2469 | b'\0\0\0\2 dummy changelog to prevent using the old repo ' | |
|
2470 | b'layout') | |
|
2471 | ||
|
2472 | scmutil.writerequires(hgvfs, requirements) |
General Comments 0
You need to be logged in to leave comments.
Login now