[PATCH 2 of 2] hg: establish function for performing post-share actions
Augie Fackler
raf at durin42.com
Tue Dec 15 12:11:45 CST 2015
On Sun, Dec 13, 2015 at 02:10:40AM -0500, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1449976829 18000
> # Sat Dec 12 22:20:29 2015 -0500
> # Node ID 7ab9882693dd467e772e8d9da74a85986977d259
> # Parent b220b46d9b6cc53ca652397746a9262c320914ad
> hg: establish function for performing post-share actions
These are queued, thanks.
>
> 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
> @@ -234,15 +234,9 @@ def share(ui, source, dest=None, update=
> destvfs.write('requires', requirements)
> 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"))
> if update is not True:
> @@ -256,10 +250,26 @@ def share(ui, source, dest=None, update=
> except error.RepoLookupError:
> 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()
>
> def copystore(ui, srcrepo, destpath):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list