2712 Extensions can wrap this function to specify custom requirements for |
2712 Extensions can wrap this function to specify custom requirements for |
2713 new repositories. |
2713 new repositories. |
2714 """ |
2714 """ |
2715 createopts = createopts or {} |
2715 createopts = createopts or {} |
2716 |
2716 |
|
2717 # If the repo is being created from a shared repository, we copy |
|
2718 # its requirements. |
|
2719 if 'sharedrepo' in createopts: |
|
2720 requirements = set(createopts['sharedrepo'].requirements) |
|
2721 if createopts.get('sharedrelative'): |
|
2722 requirements.add('relshared') |
|
2723 else: |
|
2724 requirements.add('shared') |
|
2725 |
|
2726 return requirements |
|
2727 |
2717 requirements = {'revlogv1'} |
2728 requirements = {'revlogv1'} |
2718 if ui.configbool('format', 'usestore'): |
2729 if ui.configbool('format', 'usestore'): |
2719 requirements.add('store') |
2730 requirements.add('store') |
2720 if ui.configbool('format', 'usefncache'): |
2731 if ui.configbool('format', 'usefncache'): |
2721 requirements.add('fncache') |
2732 requirements.add('fncache') |
2769 with options not recognized by loaded code. |
2780 with options not recognized by loaded code. |
2770 |
2781 |
2771 Extensions can wrap this function to filter out creation options |
2782 Extensions can wrap this function to filter out creation options |
2772 they know how to handle. |
2783 they know how to handle. |
2773 """ |
2784 """ |
2774 known = {'narrowfiles'} |
2785 known = { |
|
2786 'narrowfiles', |
|
2787 'sharedrepo', |
|
2788 'sharedrelative', |
|
2789 } |
2775 |
2790 |
2776 return {k: v for k, v in createopts.items() if k not in known} |
2791 return {k: v for k, v in createopts.items() if k not in known} |
2777 |
2792 |
2778 def createrepository(ui, path, createopts=None): |
2793 def createrepository(ui, path, createopts=None): |
2779 """Create a new repository in a vfs. |
2794 """Create a new repository in a vfs. |
2780 |
2795 |
2781 ``path`` path to the new repo's working directory. |
2796 ``path`` path to the new repo's working directory. |
2782 ``createopts`` options for the new repository. |
2797 ``createopts`` options for the new repository. |
|
2798 |
|
2799 The following keys for ``createopts`` are recognized: |
|
2800 |
|
2801 narrowfiles |
|
2802 Set up repository to support narrow file storage. |
|
2803 sharedrepo |
|
2804 Repository object from which storage should be shared. |
|
2805 sharedrelative |
|
2806 Boolean indicating if the path to the shared repo should be |
|
2807 stored as relative. By default, the pointer to the "parent" repo |
|
2808 is stored as an absolute path. |
2783 """ |
2809 """ |
2784 createopts = createopts or {} |
2810 createopts = createopts or {} |
2785 |
2811 |
2786 unknownopts = filterknowncreateopts(ui, createopts) |
2812 unknownopts = filterknowncreateopts(ui, createopts) |
2787 |
2813 |
2801 |
2827 |
2802 hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg')) |
2828 hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg')) |
2803 if hgvfs.exists(): |
2829 if hgvfs.exists(): |
2804 raise error.RepoError(_('repository %s already exists') % path) |
2830 raise error.RepoError(_('repository %s already exists') % path) |
2805 |
2831 |
|
2832 if 'sharedrepo' in createopts: |
|
2833 sharedpath = createopts['sharedrepo'].sharedpath |
|
2834 |
|
2835 if createopts.get('sharedrelative'): |
|
2836 try: |
|
2837 sharedpath = os.path.relpath(sharedpath, hgvfs.base) |
|
2838 except (IOError, ValueError) as e: |
|
2839 # ValueError is raised on Windows if the drive letters differ |
|
2840 # on each path. |
|
2841 raise error.Abort(_('cannot calculate relative path'), |
|
2842 hint=stringutil.forcebytestr(e)) |
|
2843 |
2806 if not wdirvfs.exists(): |
2844 if not wdirvfs.exists(): |
2807 wdirvfs.makedirs() |
2845 wdirvfs.makedirs() |
2808 |
2846 |
2809 hgvfs.makedir(notindexed=True) |
2847 hgvfs.makedir(notindexed=True) |
2810 |
2848 |
2811 if b'store' in requirements: |
2849 if b'store' in requirements and 'sharedrepo' not in createopts: |
2812 hgvfs.mkdir(b'store') |
2850 hgvfs.mkdir(b'store') |
2813 |
2851 |
2814 # We create an invalid changelog outside the store so very old |
2852 # We create an invalid changelog outside the store so very old |
2815 # Mercurial versions (which didn't know about the requirements |
2853 # Mercurial versions (which didn't know about the requirements |
2816 # file) encounter an error on reading the changelog. This |
2854 # file) encounter an error on reading the changelog. This |
2823 b'\0\0\0\2 dummy changelog to prevent using the old repo ' |
2861 b'\0\0\0\2 dummy changelog to prevent using the old repo ' |
2824 b'layout') |
2862 b'layout') |
2825 |
2863 |
2826 scmutil.writerequires(hgvfs, requirements) |
2864 scmutil.writerequires(hgvfs, requirements) |
2827 |
2865 |
|
2866 # Write out file telling readers where to find the shared store. |
|
2867 if 'sharedrepo' in createopts: |
|
2868 hgvfs.write(b'sharedpath', sharedpath) |
|
2869 |
2828 def poisonrepository(repo): |
2870 def poisonrepository(repo): |
2829 """Poison a repository instance so it can no longer be used.""" |
2871 """Poison a repository instance so it can no longer be used.""" |
2830 # Perform any cleanup on the instance. |
2872 # Perform any cleanup on the instance. |
2831 repo.close() |
2873 repo.close() |
2832 |
2874 |