comparison mercurial/hg.py @ 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 43c00ca887d1
children 5184089f5d30
comparison
equal deleted inserted replaced
27353:98e59d9e0d77 27354:bced7180db19
233 requirements += 'shared\n' 233 requirements += 'shared\n'
234 destvfs.write('requires', requirements) 234 destvfs.write('requires', requirements)
235 destvfs.write('sharedpath', sharedpath) 235 destvfs.write('sharedpath', sharedpath)
236 236
237 r = repository(ui, destwvfs.base) 237 r = repository(ui, destwvfs.base)
238 238 postshare(srcrepo, r, bookmarks=bookmarks)
239 default = srcrepo.ui.config('paths', 'default')
240 if default:
241 fp = r.vfs("hgrc", "w", text=True)
242 fp.write("[paths]\n")
243 fp.write("default = %s\n" % default)
244 fp.close()
245 239
246 if update: 240 if update:
247 r.ui.status(_("updating working directory\n")) 241 r.ui.status(_("updating working directory\n"))
248 if update is not True: 242 if update is not True:
249 checkout = update 243 checkout = update
255 break 249 break
256 except error.RepoLookupError: 250 except error.RepoLookupError:
257 continue 251 continue
258 _update(r, uprev) 252 _update(r, uprev)
259 253
254 def postshare(sourcerepo, destrepo, bookmarks=True):
255 """Called after a new shared repo is created.
256
257 The new repo only has a requirements file and pointer to the source.
258 This function configures additional shared data.
259
260 Extensions can wrap this function and write additional entries to
261 destrepo/.hg/shared to indicate additional pieces of data to be shared.
262 """
263 default = sourcerepo.ui.config('paths', 'default')
264 if default:
265 fp = destrepo.vfs("hgrc", "w", text=True)
266 fp.write("[paths]\n")
267 fp.write("default = %s\n" % default)
268 fp.close()
269
260 if bookmarks: 270 if bookmarks:
261 fp = r.vfs('shared', 'w') 271 fp = destrepo.vfs('shared', 'w')
262 fp.write('bookmarks\n') 272 fp.write('bookmarks\n')
263 fp.close() 273 fp.close()
264 274
265 def copystore(ui, srcrepo, destpath): 275 def copystore(ui, srcrepo, destpath):
266 '''copy files from store of srcrepo in destpath 276 '''copy files from store of srcrepo in destpath