comparison mercurial/localrepo.py @ 39996:dbcb466d0065

localrepo: define storage backend in creation options (API) We add an experimental config option to define the storage backend for new repositories. By default, it uses "revlogv1," which maps to the current and only modern supported repository format. We add a "backend" creation option to control which backend to use. It defaults to using the value from the config option. newreporequirements() will now barf if it sees a "backend" value that isn't "revlogv1." This forces extensions to monkeypatch the function to handle requirements derivation for custom backends. In order for this to "just work," we factored out obtaining the default creation options into its own function and made callers of newreporequirements() responsible for passing in valid data. Without this, direct callers of newreporequirements() wouldn't get the proper results. Differential Revision: https://phab.mercurial-scm.org/D4791
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 28 Sep 2018 09:46:50 -0700
parents 6962ebc8f817
children 83146d176c03
comparison
equal deleted inserted replaced
39995:582676acaf6d 39996:dbcb466d0065
2806 return makelocalrepository(ui, localpath, intents=intents) 2806 return makelocalrepository(ui, localpath, intents=intents)
2807 2807
2808 def islocal(path): 2808 def islocal(path):
2809 return True 2809 return True
2810 2810
2811 def newreporequirements(ui, createopts=None): 2811 def defaultcreateopts(ui, createopts=None):
2812 """Populate the default creation options for a repository.
2813
2814 A dictionary of explicitly requested creation options can be passed
2815 in. Missing keys will be populated.
2816 """
2817 createopts = dict(createopts or {})
2818
2819 if 'backend' not in createopts:
2820 # experimental config: storage.new-repo-backend
2821 createopts['backend'] = ui.config('storage', 'new-repo-backend')
2822
2823 return createopts
2824
2825 def newreporequirements(ui, createopts):
2812 """Determine the set of requirements for a new local repository. 2826 """Determine the set of requirements for a new local repository.
2813 2827
2814 Extensions can wrap this function to specify custom requirements for 2828 Extensions can wrap this function to specify custom requirements for
2815 new repositories. 2829 new repositories.
2816 """ 2830 """
2817 createopts = createopts or {}
2818
2819 # If the repo is being created from a shared repository, we copy 2831 # If the repo is being created from a shared repository, we copy
2820 # its requirements. 2832 # its requirements.
2821 if 'sharedrepo' in createopts: 2833 if 'sharedrepo' in createopts:
2822 requirements = set(createopts['sharedrepo'].requirements) 2834 requirements = set(createopts['sharedrepo'].requirements)
2823 if createopts.get('sharedrelative'): 2835 if createopts.get('sharedrelative'):
2824 requirements.add('relshared') 2836 requirements.add('relshared')
2825 else: 2837 else:
2826 requirements.add('shared') 2838 requirements.add('shared')
2827 2839
2828 return requirements 2840 return requirements
2841
2842 if 'backend' not in createopts:
2843 raise error.ProgrammingError('backend key not present in createopts; '
2844 'was defaultcreateopts() called?')
2845
2846 if createopts['backend'] != 'revlogv1':
2847 raise error.Abort(_('unable to determine repository requirements for '
2848 'storage backend: %s') % createopts['backend'])
2829 2849
2830 requirements = {'revlogv1'} 2850 requirements = {'revlogv1'}
2831 if ui.configbool('format', 'usestore'): 2851 if ui.configbool('format', 'usestore'):
2832 requirements.add('store') 2852 requirements.add('store')
2833 if ui.configbool('format', 'usefncache'): 2853 if ui.configbool('format', 'usefncache'):
2883 2903
2884 Extensions can wrap this function to filter out creation options 2904 Extensions can wrap this function to filter out creation options
2885 they know how to handle. 2905 they know how to handle.
2886 """ 2906 """
2887 known = { 2907 known = {
2908 'backend',
2888 'narrowfiles', 2909 'narrowfiles',
2889 'sharedrepo', 2910 'sharedrepo',
2890 'sharedrelative', 2911 'sharedrelative',
2891 'shareditems', 2912 'shareditems',
2892 } 2913 }
2899 ``path`` path to the new repo's working directory. 2920 ``path`` path to the new repo's working directory.
2900 ``createopts`` options for the new repository. 2921 ``createopts`` options for the new repository.
2901 2922
2902 The following keys for ``createopts`` are recognized: 2923 The following keys for ``createopts`` are recognized:
2903 2924
2925 backend
2926 The storage backend to use.
2904 narrowfiles 2927 narrowfiles
2905 Set up repository to support narrow file storage. 2928 Set up repository to support narrow file storage.
2906 sharedrepo 2929 sharedrepo
2907 Repository object from which storage should be shared. 2930 Repository object from which storage should be shared.
2908 sharedrelative 2931 sharedrelative
2910 stored as relative. By default, the pointer to the "parent" repo 2933 stored as relative. By default, the pointer to the "parent" repo
2911 is stored as an absolute path. 2934 is stored as an absolute path.
2912 shareditems 2935 shareditems
2913 Set of items to share to the new repository (in addition to storage). 2936 Set of items to share to the new repository (in addition to storage).
2914 """ 2937 """
2915 createopts = createopts or {} 2938 createopts = defaultcreateopts(ui, createopts=createopts)
2916 2939
2917 unknownopts = filterknowncreateopts(ui, createopts) 2940 unknownopts = filterknowncreateopts(ui, createopts)
2918 2941
2919 if not isinstance(unknownopts, dict): 2942 if not isinstance(unknownopts, dict):
2920 raise error.ProgrammingError('filterknowncreateopts() did not return ' 2943 raise error.ProgrammingError('filterknowncreateopts() did not return '