Patchwork [1,of,2] hg: extract post share update logic into own function

login
register
mail settings
Submitter Gregory Szorc
Date Feb. 21, 2016, 1:56 a.m.
Message ID <3f46918f408fc5594934.1456019772@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/13280/
State Accepted
Headers show

Comments

Gregory Szorc - Feb. 21, 2016, 1:56 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1456018919 28800
#      Sat Feb 20 17:41:59 2016 -0800
# Node ID 3f46918f408fc5594934991a21e704ee6f33a3b2
# Parent  1f036626b633a057498a619afb9907728a085061
hg: extract post share update logic into own function

A future patch will introduce a new caller that needs to perform
an update. Extract the code so we don't duplicate it.

Patch

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -231,30 +231,17 @@  def share(ui, source, dest=None, update=
             raise
 
     requirements += 'shared\n'
     destvfs.write('requires', requirements)
     destvfs.write('sharedpath', sharedpath)
 
     r = repository(ui, destwvfs.base)
     postshare(srcrepo, r, bookmarks=bookmarks)
-
-    if update:
-        r.ui.status(_("updating working directory\n"))
-        if update is not True:
-            checkout = update
-        for test in (checkout, 'default', 'tip'):
-            if test is None:
-                continue
-            try:
-                uprev = r.lookup(test)
-                break
-            except error.RepoLookupError:
-                continue
-        _update(r, uprev)
+    _postshareupdate(r, update, checkout=checkout)
 
 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
@@ -267,16 +254,37 @@  def postshare(sourcerepo, destrepo, book
         fp.write("default = %s\n" % default)
         fp.close()
 
     if bookmarks:
         fp = destrepo.vfs('shared', 'w')
         fp.write('bookmarks\n')
         fp.close()
 
+def _postshareupdate(repo, update, checkout=None):
+    """Maybe perform a working directory update after a shared repo is created.
+
+    ``update`` can be a boolean or a revision to update to.
+    """
+    if not update:
+        return
+
+    repo.ui.status(_("updating working directory\n"))
+    if update is not True:
+        checkout = update
+    for test in (checkout, 'default', 'tip'):
+        if test is None:
+            continue
+        try:
+            uprev = repo.lookup(test)
+            break
+        except error.RepoLookupError:
+            continue
+    _update(repo, uprev)
+
 def copystore(ui, srcrepo, destpath):
     '''copy files from store of srcrepo in destpath
 
     returns destlock
     '''
     destlock = None
     try:
         hardlink = None