# HG changeset patch
# User Stanislau Hlebik <st...@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.

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
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to