changeset 27354:bced7180db19

hg: establish function for performing post-share actions As part of writing an extension that wished to share an arbitrary piece of data among shared repos, I had to reimplement a significant part of hg.share in order to obtain localrepository instances for the source and destination. This patch establishes a function in hg.py that will be called after a share is performed. It is passed localrepository instances so extensions can easily perform additional actions at share time. We move hgrc and shared file writing there because this function is a logical place for it. A side effect of the refactor is writing of the shared file now occurs before updating. This seems more appropriate and shouldn't have any impact on real world behavior.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 12 Dec 2015 22:20:29 -0500
parents 98e59d9e0d77
children b479fc425a81
files mercurial/hg.py
diffstat 1 files changed, 18 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py	Sat Dec 12 22:07:40 2015 -0500
+++ b/mercurial/hg.py	Sat Dec 12 22:20:29 2015 -0500
@@ -235,13 +235,7 @@
     destvfs.write('sharedpath', sharedpath)
 
     r = repository(ui, destwvfs.base)
-
-    default = srcrepo.ui.config('paths', 'default')
-    if default:
-        fp = r.vfs("hgrc", "w", text=True)
-        fp.write("[paths]\n")
-        fp.write("default = %s\n" % default)
-        fp.close()
+    postshare(srcrepo, r, bookmarks=bookmarks)
 
     if update:
         r.ui.status(_("updating working directory\n"))
@@ -257,8 +251,24 @@
                 continue
         _update(r, uprev)
 
+def postshare(sourcerepo, destrepo, bookmarks=True):
+    """Called after a new shared repo is created.
+
+    The new repo only has a requirements file and pointer to the source.
+    This function configures additional shared data.
+
+    Extensions can wrap this function and write additional entries to
+    destrepo/.hg/shared to indicate additional pieces of data to be shared.
+    """
+    default = sourcerepo.ui.config('paths', 'default')
+    if default:
+        fp = destrepo.vfs("hgrc", "w", text=True)
+        fp.write("[paths]\n")
+        fp.write("default = %s\n" % default)
+        fp.close()
+
     if bookmarks:
-        fp = r.vfs('shared', 'w')
+        fp = destrepo.vfs('shared', 'w')
         fp.write('bookmarks\n')
         fp.close()