Show More
@@ -65,10 +65,14 b" testedwith = 'ships-with-hg-core'" | |||||
65 |
|
65 | |||
66 | @command('share', |
|
66 | @command('share', | |
67 | [('U', 'noupdate', None, _('do not create a working directory')), |
|
67 | [('U', 'noupdate', None, _('do not create a working directory')), | |
68 |
('B', 'bookmarks', None, _('also share bookmarks')) |
|
68 | ('B', 'bookmarks', None, _('also share bookmarks')), | |
|
69 | ('', 'relative', None, _('point to source using a relative path ' | |||
|
70 | '(EXPERIMENTAL)')), | |||
|
71 | ], | |||
69 | _('[-U] [-B] SOURCE [DEST]'), |
|
72 | _('[-U] [-B] SOURCE [DEST]'), | |
70 | norepo=True) |
|
73 | norepo=True) | |
71 |
def share(ui, source, dest=None, noupdate=False, bookmarks=False |
|
74 | def share(ui, source, dest=None, noupdate=False, bookmarks=False, | |
|
75 | relative=False): | |||
72 | """create a new shared repository |
|
76 | """create a new shared repository | |
73 |
|
77 | |||
74 | Initialize a new repository and working directory that shares its |
|
78 | Initialize a new repository and working directory that shares its | |
@@ -87,7 +91,7 b' def share(ui, source, dest=None, noupdat' | |||||
87 | """ |
|
91 | """ | |
88 |
|
92 | |||
89 | return hg.share(ui, source, dest=dest, update=not noupdate, |
|
93 | return hg.share(ui, source, dest=dest, update=not noupdate, | |
90 | bookmarks=bookmarks) |
|
94 | bookmarks=bookmarks, relative=relative) | |
91 |
|
95 | |||
92 | @command('unshare', [], '') |
|
96 | @command('unshare', [], '') | |
93 | def unshare(ui, repo): |
|
97 | def unshare(ui, repo): |
@@ -55,6 +55,17 b' This requirement is set when a repositor' | |||||
55 |
|
55 | |||
56 | The requirement was added in Mercurial 1.3 (released July 2009). |
|
56 | The requirement was added in Mercurial 1.3 (released July 2009). | |
57 |
|
57 | |||
|
58 | relshared | |||
|
59 | ========= | |||
|
60 | ||||
|
61 | Derivative of ``shared``; the location of the store is relative to the | |||
|
62 | store of this repository. | |||
|
63 | ||||
|
64 | This requirement is set when a repository is created via :hg:`share` | |||
|
65 | using the ``--relative`` option. | |||
|
66 | ||||
|
67 | The requirement was added in Mercurial 4.2 (released May 2017). | |||
|
68 | ||||
58 | dotencode |
|
69 | dotencode | |
59 | ========= |
|
70 | ========= | |
60 |
|
71 |
@@ -195,7 +195,8 b' def defaultdest(source):' | |||||
195 | return '' |
|
195 | return '' | |
196 | return os.path.basename(os.path.normpath(path)) |
|
196 | return os.path.basename(os.path.normpath(path)) | |
197 |
|
197 | |||
198 |
def share(ui, source, dest=None, update=True, bookmarks=True, defaultpath=None |
|
198 | def share(ui, source, dest=None, update=True, bookmarks=True, defaultpath=None, | |
|
199 | relative=False): | |||
199 | '''create a shared repository''' |
|
200 | '''create a shared repository''' | |
200 |
|
201 | |||
201 | if not islocal(source): |
|
202 | if not islocal(source): | |
@@ -235,7 +236,16 b' def share(ui, source, dest=None, update=' | |||||
235 | if inst.errno != errno.ENOENT: |
|
236 | if inst.errno != errno.ENOENT: | |
236 | raise |
|
237 | raise | |
237 |
|
238 | |||
238 | requirements += 'shared\n' |
|
239 | if relative: | |
|
240 | try: | |||
|
241 | sharedpath = os.path.relpath(sharedpath, destvfs.base) | |||
|
242 | requirements += 'relshared\n' | |||
|
243 | except IOError as e: | |||
|
244 | raise error.Abort(_('cannot calculate relative path'), | |||
|
245 | hint=str(e)) | |||
|
246 | else: | |||
|
247 | requirements += 'shared\n' | |||
|
248 | ||||
239 | destvfs.write('requires', requirements) |
|
249 | destvfs.write('requires', requirements) | |
240 | destvfs.write('sharedpath', sharedpath) |
|
250 | destvfs.write('sharedpath', sharedpath) | |
241 |
|
251 |
@@ -244,7 +244,7 b' class localrepository(object):' | |||||
244 | supportedformats = set(('revlogv1', 'generaldelta', 'treemanifest', |
|
244 | supportedformats = set(('revlogv1', 'generaldelta', 'treemanifest', | |
245 | 'manifestv2')) |
|
245 | 'manifestv2')) | |
246 | _basesupported = supportedformats | set(('store', 'fncache', 'shared', |
|
246 | _basesupported = supportedformats | set(('store', 'fncache', 'shared', | |
247 | 'dotencode')) |
|
247 | 'relshared', 'dotencode')) | |
248 | openerreqs = set(('revlogv1', 'generaldelta', 'treemanifest', 'manifestv2')) |
|
248 | openerreqs = set(('revlogv1', 'generaldelta', 'treemanifest', 'manifestv2')) | |
249 | filtername = None |
|
249 | filtername = None | |
250 |
|
250 | |||
@@ -325,8 +325,11 b' class localrepository(object):' | |||||
325 |
|
325 | |||
326 | self.sharedpath = self.path |
|
326 | self.sharedpath = self.path | |
327 | try: |
|
327 | try: | |
328 |
|
|
328 | sharedpath = self.vfs.read("sharedpath").rstrip('\n') | |
329 | realpath=True) |
|
329 | if 'relshared' in self.requirements: | |
|
330 | sharedpath = self.vfs.join(sharedpath) | |||
|
331 | vfs = scmutil.vfs(sharedpath, realpath=True) | |||
|
332 | ||||
330 | s = vfs.base |
|
333 | s = vfs.base | |
331 | if not vfs.exists(): |
|
334 | if not vfs.exists(): | |
332 | raise error.RepoError( |
|
335 | raise error.RepoError( |
@@ -358,6 +358,41 b' verify bookmark behavior after unshare' | |||||
358 | bm4 5:92793bfc8cad |
|
358 | bm4 5:92793bfc8cad | |
359 | $ cd .. |
|
359 | $ cd .. | |
360 |
|
360 | |||
|
361 | test shared clones using relative paths work | |||
|
362 | ||||
|
363 | $ mkdir thisdir | |||
|
364 | $ hg init thisdir/orig | |||
|
365 | $ hg share -U thisdir/orig thisdir/abs | |||
|
366 | $ hg share -U --relative thisdir/abs thisdir/rel | |||
|
367 | $ cat thisdir/rel/.hg/sharedpath | |||
|
368 | ../../orig/.hg (no-eol) | |||
|
369 | $ grep shared thisdir/*/.hg/requires | |||
|
370 | thisdir/abs/.hg/requires:shared | |||
|
371 | thisdir/rel/.hg/requires:shared | |||
|
372 | thisdir/rel/.hg/requires:relshared | |||
|
373 | ||||
|
374 | test that relative shared paths aren't relative to $PWD | |||
|
375 | ||||
|
376 | $ cd thisdir | |||
|
377 | $ hg -R rel root | |||
|
378 | $TESTTMP/thisdir/rel | |||
|
379 | $ cd .. | |||
|
380 | ||||
|
381 | now test that relative paths really are relative, survive across | |||
|
382 | renames and changes of PWD | |||
|
383 | ||||
|
384 | $ hg -R thisdir/abs root | |||
|
385 | $TESTTMP/thisdir/abs | |||
|
386 | $ hg -R thisdir/rel root | |||
|
387 | $TESTTMP/thisdir/rel | |||
|
388 | $ mv thisdir thatdir | |||
|
389 | $ hg -R thatdir/abs root | |||
|
390 | abort: .hg/sharedpath points to nonexistent directory $TESTTMP/thisdir/orig/.hg! | |||
|
391 | [255] | |||
|
392 | $ hg -R thatdir/rel root | |||
|
393 | $TESTTMP/thatdir/rel | |||
|
394 | $ rm -r thatdir | |||
|
395 | ||||
361 | Explicitly kill daemons to let the test exit on Windows |
|
396 | Explicitly kill daemons to let the test exit on Windows | |
362 |
|
397 | |||
363 | $ killdaemons.py |
|
398 | $ killdaemons.py |
General Comments 0
You need to be logged in to leave comments.
Login now