Patchwork remotenames: selectivepull, update to the unknown bookmark tries to pull it

login
register
mail settings
Submitter Stanislau Hlebik
Date Aug. 12, 2016, 10:08 a.m.
Message ID <ecc99b9467e510bdd7ac.1470996485@dev1918.lla1.facebook.com>
Download mbox | patch
Permalink /patch/16258/
State Superseded
Headers show

Comments

Stanislau Hlebik - Aug. 12, 2016, 10:08 a.m.
# HG changeset patch
# User Stanislau Hlebik <stash@fb.com>
# Date 1470996226 25200
#      Fri Aug 12 03:03:46 2016 -0700
# Node ID ecc99b9467e510bdd7ac6f0093457f26f962b3d7
# Parent  34e09d7db15c7d4e964b737d2af539a22cdcbc22
remotenames: selectivepull, update to the unknown bookmark tries to pull it

Part of Selective Pull project (see https://www.mercurial-scm.org/wiki/SelectivePullPlan for details).
If Selective Pull is enabled, then we want to be able to check out
revision even if it's not present locally, but present on remote server.
If rev or node is not present locally, new request is issued to find
it remotely. If it is present remotely then it's pulled.

Test Plan:
Run remotenames tests

Patch

diff --git a/remotenames.py b/remotenames.py
--- a/remotenames.py
+++ b/remotenames.py
@@ -215,6 +215,31 @@ 
     return bookmarks
 
 def updatecmd(orig, ui, repo, node=None, rev=None, **kwargs):
+    if rev and node:
+        raise error.Abort(_("please specify just one revision"))
+
+    isselectivepull = repo.ui.configbool('remotenames', 'selectivepull', False)
+    if isselectivepull and ('date' not in kwargs or not kwargs['date']):
+        # Make sure that rev or node is present in the repo.
+        # Otherwise pull it from remote
+        try:
+            scmutil.revsingle(repo, rev or node)
+        except (error.RepoLookupError, error.Abort):
+            mayberemotebookmark = rev or node
+            ui.status(_('`%s` not found. Assuming it is a remote bookmark '
+                        'and trying to pull it\n') % mayberemotebookmark)
+            revrenames = dict((v, k) for k, v in _getrenames(ui).iteritems())
+            remote, rname = splitremotename(mayberemotebookmark)
+            paths = dict((path, url) for path, url in ui.configitems('paths'))
+            if remote in revrenames:
+                source = revrenames[remote]
+            elif remote in paths:
+                source = remote
+            else:
+                source = 'default'
+                rname = mayberemotebookmark
+            commands.pull(ui, repo, source=source, bookmark=[rname])
+
     book = kwargs.get('bookmark')
     if book:
         del kwargs['bookmark']
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
@@ -156,3 +156,44 @@ 
   $ hg bookmarks --remote
      default/master            1:0238718db2b1
      secondremote/master       1:0238718db2b1
+
+Update to the remote bookmark
+  $ hg update thirdbook
+  `thirdbook` not found. Assuming it is a remote bookmark and trying to pull it
+  pulling from ssh://user@dummy/remoterepo
+  no changes found
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg book --verbose
+  no bookmarks set
+  $ hg book --remote
+     default/master            1:0238718db2b1
+     default/thirdbook         0:1449e7934ec1
+     secondremote/master       1:0238718db2b1
+
+Trying to update to unknown bookmark
+  $ hg update unknownbook
+  `unknownbook` not found. Assuming it is a remote bookmark and trying to pull it
+  pulling from ssh://user@dummy/remoterepo
+  abort: remote bookmark unknownbook not found!
+  [255]
+
+Update to the remote bookmark from secondremote
+  $ hg update secondremote/secondbook
+  `secondremote/secondbook` not found. Assuming it is a remote bookmark and trying to pull it
+  pulling from ssh://user@dummy/secondremoterepo
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  (run 'hg update' to get a working copy)
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg book --remote
+     default/master            1:0238718db2b1
+     default/thirdbook         0:1449e7934ec1
+     secondremote/master       1:0238718db2b1
+     secondremote/secondbook   4:0022441e80e5
+
+Update make sure revsets work
+  $ hg up '.^'
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved