Patchwork [5,of,6,remotenames-ext] selectivepull: add selectivepullenabled file

login
register
mail settings
Submitter Stanislau Hlebik
Date Jan. 30, 2017, 3:56 p.m.
Message ID <a96117003c763be640a9.1485791763@devvm1840.lla2.facebook.com>
Download mbox | patch
Permalink /patch/18281/
State Accepted
Headers show

Comments

Stanislau Hlebik - Jan. 30, 2017, 3:56 p.m.
# HG changeset patch
# User Stanislau Hlebik <stash@fb.com>
# Date 1485791649 28800
#      Mon Jan 30 07:54:09 2017 -0800
# Node ID a96117003c763be640a975d8128068d2bd3527c0
# Parent  25d873eac976b58ac99dabb3f0e62814bb2aa2f8
selectivepull: add selectivepullenabled file

'selectivepullenabled' file is used for transition between non-selectivepull
repo to selectivepull repo. It is used as indicator to whether
"non-interesting" bookmarks were removed from remotenames file.

Patch

diff --git a/remotenames.py b/remotenames.py
--- a/remotenames.py
+++ b/remotenames.py
@@ -46,6 +46,9 @@ 
 
 # namespace to use when recording an hg journal entry
 journalremotebookmarktype = 'remotebookmark'
+# name of the file that is used to mark that transition to selectivepull has
+# happened
+_selectivepullenabledfile = 'selectivepullenabled'
 
 def exbookcalcupdate(orig, ui, repo, checkout):
     '''Return a tuple (targetrev, movemarkfrom) indicating the rev to
@@ -123,9 +126,14 @@ 
         # because it may slow down clients.
         path = activepath(repo.ui, remote)
         bookmarks = {}
-        for bookmark in readbookmarknames(repo, path):
-            if bookmark in remotebookmarks:
-                bookmarks[bookmark] = remotebookmarks[bookmark]
+        if repo.vfs.exists(_selectivepullenabledfile):
+            # 'selectivepullenabled' file is used for transition between
+            # non-selectivepull repo to selectivepull repo. It is used as
+            # indicator to whether "non-interesting" bookmarks were removed
+            # from remotenames file.
+            for bookmark in readbookmarknames(repo, path):
+                if bookmark in remotebookmarks:
+                    bookmarks[bookmark] = remotebookmarks[bookmark]
         if not bookmarks:
             bookmarks = _getselectivepulldefaultbookmarks(repo.ui,
                                                           remotebookmarks)
@@ -149,6 +157,13 @@ 
 
     res = orig(repo, remote, *args, **kwargs)
     pullremotenames(repo, remote, bookmarks)
+    if repo.vfs.exists(_selectivepullenabledfile):
+        if not _isselectivepull(repo.ui):
+            repo.vfs.unlink(_selectivepullenabledfile)
+    else:
+        if _isselectivepull(repo.ui):
+            with repo.vfs(_selectivepullenabledfile, 'w') as f:
+                f.write('enabled') # content doesn't matter
     return res
 
 def pullremotenames(repo, remote, bookmarks):
diff --git a/tests/test-selective-pull.t b/tests/test-selective-pull.t
--- a/tests/test-selective-pull.t
+++ b/tests/test-selective-pull.t
@@ -200,3 +200,30 @@ 
 Update make sure revsets work
   $ hg up '.^'
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+Make another clone with selectivepull disabled
+  $ hg clone -q ssh://user@dummy/remoterepo localrepo2
+  $ cd localrepo2
+  $ hg book --remote
+     default/master            2:0238718db2b1
+     default/thirdbook         0:1449e7934ec1
+
+Enable selectivepull and make a pull. Make sure only master bookmark is left
+  $ cat >> .hg/hgrc << EOF
+  > [remotenames]
+  > selectivepull=True
+  > selectivepulldefault=master
+  > EOF
+  $ hg pull -q
+  $ hg book --remote
+     default/master            2:0238718db2b1
+
+Temporarily disable selectivepull, pull, enable it again and pull again.
+Make sure only master bookmark is present
+  $ hg pull --config remotenames.selectivepull=False -q
+  $ hg book --remote
+     default/master            2:0238718db2b1
+     default/thirdbook         0:1449e7934ec1
+  $ hg pull -q
+  $ hg book --remote
+     default/master            2:0238718db2b1