indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Now that we can create a shared repository via creation options, we
  can handle other special actions related to share at repo creation time
  as well.
  
  One of the things we do after creating a shared repository is write
  out a .hg/shared file containing the list of additional things to
  share. Of which only "bookmarks" is supported.
  
  We add a creation option to hold the set of additional items to
  share. If items are defined, we write out the .hg/shared file at
  repo creation time.
  
  As part of this, we no longer hold the repo lock when writing the
  file. I'm pretty sure we don't care about the tiny race condition
  window. I'm also pretty sure the reason we used the lock was because
  the vfs auditor on the repo instance complained otherwise. Since the
  repo creation code doesn't have an audited vfs, we don't need to
  appease it.
  
  Because we no longer need to tell the post share hook what items
  are shared, the "bookmarks" argument to that function has been
  dropped, incurring an API change.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4708

AFFECTED FILES
  hgext/largefiles/overrides.py
  hgext/lfs/wrapper.py
  mercurial/hg.py
  mercurial/localrepo.py

CHANGE DETAILS

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -2786,6 +2786,7 @@
         'narrowfiles',
         'sharedrepo',
         'sharedrelative',
+        'shareditems',
     }
 
     return {k: v for k, v in createopts.items() if k not in known}
@@ -2806,6 +2807,8 @@
        Boolean indicating if the path to the shared repo should be
        stored as relative. By default, the pointer to the "parent" repo
        is stored as an absolute path.
+    shareditems
+       Set of items to share to the new repository (in addition to storage).
     """
     createopts = createopts or {}
 
@@ -2867,6 +2870,10 @@
     if 'sharedrepo' in createopts:
         hgvfs.write(b'sharedpath', sharedpath)
 
+    if createopts.get('shareditems'):
+        shared = b'\n'.join(sorted(createopts['shareditems'])) + b'\n'
+        hgvfs.write(b'shared', shared)
+
 def poisonrepository(repo):
     """Poison a repository instance so it can no longer be used."""
     # Perform any cleanup on the instance.
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -259,12 +259,17 @@
         srcrepo = source.local()
         checkout = None
 
+    shareditems = set()
+    if bookmarks:
+        shareditems.add(sharedbookmarks)
+
     r = repository(ui, dest, create=True, createopts={
         'sharedrepo': srcrepo,
         'sharedrelative': relative,
+        'shareditems': shareditems,
     })
 
-    postshare(srcrepo, r, bookmarks=bookmarks, defaultpath=defaultpath)
+    postshare(srcrepo, r, defaultpath=defaultpath)
     _postshareupdate(r, update, checkout=checkout)
     return r
 
@@ -315,7 +320,7 @@
 
     return newrepo
 
-def postshare(sourcerepo, destrepo, bookmarks=True, defaultpath=None):
+def postshare(sourcerepo, destrepo, defaultpath=None):
     """Called after a new shared repo is created.
 
     The new repo only has a requirements file and pointer to the source.
@@ -330,10 +335,6 @@
                     'default = %s\n')
         destrepo.vfs.write('hgrc', util.tonativeeol(template % default))
 
-    with destrepo.wlock():
-        if bookmarks:
-            destrepo.vfs.write('shared', sharedbookmarks + '\n')
-
 def _postshareupdate(repo, update, checkout=None):
     """Maybe perform a working directory update after a shared repo is created.
 
diff --git a/hgext/lfs/wrapper.py b/hgext/lfs/wrapper.py
--- a/hgext/lfs/wrapper.py
+++ b/hgext/lfs/wrapper.py
@@ -240,8 +240,8 @@
 
     return result
 
-def hgpostshare(orig, sourcerepo, destrepo, bookmarks=True, defaultpath=None):
-    orig(sourcerepo, destrepo, bookmarks, defaultpath)
+def hgpostshare(orig, sourcerepo, destrepo, defaultpath=None):
+    orig(sourcerepo, destrepo, defaultpath=defaultpath)
 
     # If lfs is required for this repo, permanently enable it locally
     if 'lfs' in destrepo.requirements:
diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -905,8 +905,8 @@
 
     return result
 
-def hgpostshare(orig, sourcerepo, destrepo, bookmarks=True, defaultpath=None):
-    orig(sourcerepo, destrepo, bookmarks, defaultpath)
+def hgpostshare(orig, sourcerepo, destrepo, defaultpath=None):
+    orig(sourcerepo, destrepo, defaultpath=defaultpath)
 
     # If largefiles is required for this repo, permanently enable it locally
     if 'largefiles' in destrepo.requirements:



To: indygreg, #hg-reviewers
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to