Patchwork [2,of,2,remotenames-ext] remotenames: selectivepull, add _listremotebookmarks

login
register
mail settings
Submitter Stanislau Hlebik
Date Feb. 21, 2017, 3:23 p.m.
Message ID <f49560facf4802449ab1.1487690604@devvm1840.lla2.facebook.com>
Download mbox | patch
Permalink /patch/18690/
State Accepted
Headers show

Comments

Stanislau Hlebik - Feb. 21, 2017, 3:23 p.m.
# HG changeset patch
# User Stanislau Hlebik <stash@fb.com>
# Date 1487690190 28800
#      Tue Feb 21 07:16:30 2017 -0800
# Node ID f49560facf4802449ab15aaf9b12287754619990
# Parent  cf04161615a48d42a2bb6181060ae9be8ceaa467
remotenames: selectivepull, add _listremotebookmarks

Adding a separate function to fetch only selected bookmarks from the server
allows extensions to wrap it. For example, infinitepush extensions
(https://bitbucket.org/facebook/hg-experimental/src/
98384e8d1db6534f7e5df08080f8ebf57688d380/infinitepush/?at=default) can wrap
this function and return bookmarks that are not present on hg server but
stored in a separate storage.
Sean Farley - March 9, 2017, 11:24 p.m.
Stanislau Hlebik <stash@fb.com> writes:

> # HG changeset patch
> # User Stanislau Hlebik <stash@fb.com>
> # Date 1487690190 28800
> #      Tue Feb 21 07:16:30 2017 -0800
> # Node ID f49560facf4802449ab15aaf9b12287754619990
> # Parent  cf04161615a48d42a2bb6181060ae9be8ceaa467
> remotenames: selectivepull, add _listremotebookmarks
>
> Adding a separate function to fetch only selected bookmarks from the server
> allows extensions to wrap it. For example, infinitepush extensions
> (https://bitbucket.org/facebook/hg-experimental/src/
> 98384e8d1db6534f7e5df08080f8ebf57688d380/infinitepush/?at=default) can wrap
> this function and return bookmarks that are not present on hg server but
> stored in a separate storage.

Sorry for the delay; been on vacation. I'll queue these now.

Patch

diff --git a/remotenames.py b/remotenames.py
--- a/remotenames.py
+++ b/remotenames.py
@@ -85,19 +85,18 @@ 
 def _isselectivepull(ui):
     return ui.configbool('remotenames', 'selectivepull', False)
 
-def _getselectivepulldefaultbookmarks(ui, remotebookmarks):
+def _getselectivepulldefaultbookmarks(ui):
     default_books = ui.configlist('remotenames', 'selectivepulldefault')
     if not default_books:
         raise error.Abort(_('no default bookmarks specified for selectivepull'))
+    return default_books
 
+def _listremotebookmarks(remote, bookmarks):
+    remotebookmarks = remote.listkeys('bookmarks')
     result = {}
-    for default_book in default_books:
-        if default_book in remotebookmarks:
-            result[default_book] = remotebookmarks[default_book]
-
-    if not default_books:
-        raise error.Abort(
-            _('default bookmarks %s are not found on remote') % default_books)
+    for book in bookmarks:
+        if book in remotebookmarks:
+            result[book] = remotebookmarks[book]
     return result
 
 def _trypullremotebookmark(mayberemotebookmark, repo, ui):
@@ -122,7 +121,6 @@ 
         ui.warn(_('`%s` found remotely\n') % mayberemotebookmark)
 
 def expull(orig, repo, remote, *args, **kwargs):
-    remotebookmarks = remote.listkeys('bookmarks')
     if _isselectivepull(repo.ui):
         # if selectivepull is enabled then we don't save all of the remote
         # bookmarks in remotenames file. Instead we save only bookmarks that
@@ -135,23 +133,21 @@ 
         # Selectivepull is helpful when server has too many remote bookmarks
         # because it may slow down clients.
         path = activepath(repo.ui, remote)
-        bookmarks = {}
+        remotebookmarkslist = []
         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)
+            remotebookmarkslist = list(readbookmarknames(repo, path))
+        if not remotebookmarkslist:
+            remotebookmarkslist = _getselectivepulldefaultbookmarks(repo.ui)
 
         if kwargs.get('bookmarks'):
-            for bookmark in kwargs['bookmarks']:
-                bookmarks[bookmark] = remotebookmarks[bookmark]
+            remotebookmarkslist.extend(kwargs['bookmarks'])
+            bookmarks = _listremotebookmarks(remote, remotebookmarkslist)
         else:
+            bookmarks = _listremotebookmarks(remote, remotebookmarkslist)
             heads = kwargs.get('heads') or []
             # heads may be passed as positional args
             if len(args) > 0:
@@ -163,7 +159,7 @@ 
             kwargs['bookmarks'] = bookmarks
             kwargs['heads'] = heads
     else:
-        bookmarks = remotebookmarks
+        bookmarks = remote.listkeys('bookmarks')
 
     res = orig(repo, remote, *args, **kwargs)
     pullremotenames(repo, remote, bookmarks)