# HG changeset patch # User Gregory Szorc # Date 2015-12-13 03:20:29 # Node ID bced7180db19a0d786ee2a97bb7e923b385a0fde # Parent 98e59d9e0d77afdef103e9375ba1d3eeccf9827e 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. diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -235,13 +235,7 @@ def share(ui, source, dest=None, update= 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 @@ def share(ui, source, dest=None, update= 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()