Patchwork [3,of,6,remotenames-ext] selectivepull: add function to get default bookmarks

login
register
mail settings
Submitter Stanislau Hlebik
Date Jan. 30, 2017, 3:56 p.m.
Message ID <3e17b130293b0c659180.1485791761@devvm1840.lla2.facebook.com>
Download mbox | patch
Permalink /patch/18280/
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 3e17b130293b0c65918041ad4e51a32a909e4f48
# Parent  a7786a178d5cb9abed981c76e47588fffede7511
selectivepull: add function to get default bookmarks

Small refactoring: move logic to get default bookmarks to separate function

Patch

diff --git a/remotenames.py b/remotenames.py
--- a/remotenames.py
+++ b/remotenames.py
@@ -77,6 +77,16 @@ 
 def _isselectivepull(ui):
     return ui.configbool('remotenames', 'selectivepull', False)
 
+def _getselectivepulldefaultbookmarks(ui, remotebookmarks):
+    default_book = ui.config('remotenames', 'selectivepulldefault')
+    if not default_book:
+        raise error.Abort(_('no default bookmark specified for selectivepull'))
+    if default_book in remotebookmarks:
+        return {default_book: remotebookmarks[default_book]}
+    else:
+        raise error.Abort(
+            _('default bookmark %s is not found on remote') % default_book)
+
 def _trypullremotebookmark(mayberemotebookmark, repo, ui):
     ui.warn(_('`%s` not found: assuming it is a remote bookmark '
               'and trying to pull it\n') % mayberemotebookmark)
@@ -117,16 +127,8 @@ 
             if bookmark in remotebookmarks:
                 bookmarks[bookmark] = remotebookmarks[bookmark]
         if not bookmarks:
-            default_book = repo.ui.config('remotenames', 'selectivepulldefault')
-            if not default_book:
-                raise error.Abort(
-                    _('no default bookmark specified for selectivepull'))
-            if default_book in remotebookmarks:
-                bookmarks = {default_book: remotebookmarks[default_book]}
-            else:
-                raise error.Abort(
-                    _('default bookmark %s is not found on remote') %
-                    default_book)
+            bookmarks = _getselectivepulldefaultbookmarks(repo.ui,
+                                                          remotebookmarks)
 
         if kwargs.get('bookmarks'):
             for bookmark in kwargs['bookmarks']: