Show More
@@ -49,10 +49,6 b' from . import (' | |||||
49 | vfs as vfsmod, |
|
49 | vfs as vfsmod, | |
50 | ) |
|
50 | ) | |
51 |
|
51 | |||
52 | from .utils import ( |
|
|||
53 | stringutil, |
|
|||
54 | ) |
|
|||
55 |
|
||||
56 | release = lock.release |
|
52 | release = lock.release | |
57 |
|
53 | |||
58 | # shared features |
|
54 | # shared features | |
@@ -261,44 +257,13 b' def share(ui, source, dest=None, update=' | |||||
261 | rev, checkout = addbranchrevs(srcrepo, srcrepo, branches, None) |
|
257 | rev, checkout = addbranchrevs(srcrepo, srcrepo, branches, None) | |
262 | else: |
|
258 | else: | |
263 | srcrepo = source.local() |
|
259 | srcrepo = source.local() | |
264 | origsource = source = srcrepo.url() |
|
|||
265 | checkout = None |
|
260 | checkout = None | |
266 |
|
261 | |||
267 | sharedpath = srcrepo.sharedpath # if our source is already sharing |
|
262 | r = repository(ui, dest, create=True, createopts={ | |
268 |
|
263 | 'sharedrepo': srcrepo, | ||
269 | destwvfs = vfsmod.vfs(dest, realpath=True) |
|
264 | 'sharedrelative': relative, | |
270 | destvfs = vfsmod.vfs(os.path.join(destwvfs.base, '.hg'), realpath=True) |
|
265 | }) | |
271 |
|
||||
272 | if destvfs.lexists(): |
|
|||
273 | raise error.Abort(_('destination already exists')) |
|
|||
274 |
|
||||
275 | if not destwvfs.isdir(): |
|
|||
276 | destwvfs.makedirs() |
|
|||
277 | destvfs.makedir() |
|
|||
278 |
|
266 | |||
279 | requirements = '' |
|
|||
280 | try: |
|
|||
281 | requirements = srcrepo.vfs.read('requires') |
|
|||
282 | except IOError as inst: |
|
|||
283 | if inst.errno != errno.ENOENT: |
|
|||
284 | raise |
|
|||
285 |
|
||||
286 | if relative: |
|
|||
287 | try: |
|
|||
288 | sharedpath = os.path.relpath(sharedpath, destvfs.base) |
|
|||
289 | requirements += 'relshared\n' |
|
|||
290 | except (IOError, ValueError) as e: |
|
|||
291 | # ValueError is raised on Windows if the drive letters differ on |
|
|||
292 | # each path |
|
|||
293 | raise error.Abort(_('cannot calculate relative path'), |
|
|||
294 | hint=stringutil.forcebytestr(e)) |
|
|||
295 | else: |
|
|||
296 | requirements += 'shared\n' |
|
|||
297 |
|
||||
298 | destvfs.write('requires', requirements) |
|
|||
299 | destvfs.write('sharedpath', sharedpath) |
|
|||
300 |
|
||||
301 | r = repository(ui, destwvfs.base) |
|
|||
302 | postshare(srcrepo, r, bookmarks=bookmarks, defaultpath=defaultpath) |
|
267 | postshare(srcrepo, r, bookmarks=bookmarks, defaultpath=defaultpath) | |
303 | _postshareupdate(r, update, checkout=checkout) |
|
268 | _postshareupdate(r, update, checkout=checkout) | |
304 | return r |
|
269 | return r |
@@ -2714,6 +2714,17 b' def newreporequirements(ui, createopts=N' | |||||
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') | |
@@ -2771,7 +2782,11 b' def filterknowncreateopts(ui, createopts' | |||||
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 = { |
|
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 | |||
@@ -2780,6 +2795,17 b' def createrepository(ui, path, createopt' | |||||
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 | |||
@@ -2803,12 +2829,24 b' def createrepository(ui, path, createopt' | |||||
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 | |
@@ -2825,6 +2863,10 b' def createrepository(ui, path, createopt' | |||||
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. |
@@ -399,8 +399,8 b' test shared clones using relative paths ' | |||||
399 | ../../orig/.hg (no-eol) |
|
399 | ../../orig/.hg (no-eol) | |
400 | $ grep shared thisdir/*/.hg/requires |
|
400 | $ grep shared thisdir/*/.hg/requires | |
401 | thisdir/abs/.hg/requires:shared |
|
401 | thisdir/abs/.hg/requires:shared | |
|
402 | thisdir/rel/.hg/requires:relshared | |||
402 | thisdir/rel/.hg/requires:shared |
|
403 | thisdir/rel/.hg/requires:shared | |
403 | thisdir/rel/.hg/requires:relshared |
|
|||
404 |
|
404 | |||
405 | test that relative shared paths aren't relative to $PWD |
|
405 | test that relative shared paths aren't relative to $PWD | |
406 |
|
406 |
General Comments 0
You need to be logged in to leave comments.
Login now