Patchwork [2,of,2,V2] remotenames: selectivepull, update to the unknown bookmark tries to pull it

login
register
mail settings
Submitter Stanislau Hlebik
Date Aug. 18, 2016, 10:53 a.m.
Message ID <956e82482a2cd431ab73.1471517613@dev1918.lla1.facebook.com>
Download mbox | patch
Permalink /patch/16353/
State Superseded
Headers show

Comments

Stanislau Hlebik - Aug. 18, 2016, 10:53 a.m.
# HG changeset patch
# User Stanislau Hlebik <stash@fb.com>
# Date 1471517316 25200
#      Thu Aug 18 03:48:36 2016 -0700
# Node ID 956e82482a2cd431ab73f2492fe4ae1e7efff15b
# Parent  866049ffa049dc598af834a035f27a06684d264d
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
Durham Goode - Aug. 18, 2016, 6:21 p.m.
I'd use 'hg email --flag remotenames-ext ...' when sending remotenames 
patches, so it's clear this series isn't for normal Mercurial.

A few inline comments, but overall looks good.

On 8/18/16 3:53 AM, Stanislau Hlebik wrote:
> # HG changeset patch
> # User Stanislau Hlebik <stash@fb.com>
> # Date 1471517316 25200
> #      Thu Aug 18 03:48:36 2016 -0700
> # Node ID 956e82482a2cd431ab73f2492fe4ae1e7efff15b
> # Parent  866049ffa049dc598af834a035f27a06684d264d
> remotenames: selectivepull, update to the unknown bookmark tries to pull it
>
> Part of Selective Pull project (see https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_wiki_SelectivePullPlan&d=DQIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=nuarHzhP1wi1T9iURRCj1A&m=Xi_7BpNL8bqVfsBjWGxHg2y4o8voQE5e2-jrnjrwm5s&s=Jbe2NmRU2jc4Sg3bEYC4YLhZhh9lP-CuZ0R3BB2zaDc&e=  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
>
> diff --git a/remotenames.py b/remotenames.py
> --- a/remotenames.py
> +++ b/remotenames.py
> @@ -76,6 +76,22 @@
>   def _isselectivepull(ui):
>       return ui.configbool('remotenames', 'selectivepull', False)
>   
> +def _trypullremotebookmark(mayberemotebookmark, repo, ui):
> +    ui.status(_('`%s` not found: assuming it is a remote bookmark '
> +                'and trying to pull it\n') % mayberemotebookmark)
> +    sourcerenames = dict((v, k) for k, v in _getrenames(ui).iteritems())
> +    remote, bookmarkname = splitremotename(mayberemotebookmark)
> +    paths = dict((path, url) for path, url in ui.configitems('paths'))
> +    if remote in sourcerenames:
> +        source = sourcerenames[remote]
What if the result of the rename isn't a valid path?
> +    elif remote in paths:
> +        source = remote
> +    else:
> +        source = 'default'
> +        bookmarkname = mayberemotebookmark
> +    commands.pull(ui, repo, source=source, bookmark=[bookmarkname])
What happens if the pull fails?  Do we throw a pull exception? Seems 
like we'd probably want to eat it (maybe with a message) and let the 
update continue and fail like normal.  That also fits in better with the 
function name 'tryxxx'
> +    ui.status(_('`%s` found remotely\n') % mayberemotebookmark)
I'd probably put this message (and the one above) on stderr (ui.warn).  
That way we don't interfere with any automation that's expecting certain 
stdout.

Patch

diff --git a/remotenames.py b/remotenames.py
--- a/remotenames.py
+++ b/remotenames.py
@@ -76,6 +76,22 @@ 
 def _isselectivepull(ui):
     return ui.configbool('remotenames', 'selectivepull', False)
 
+def _trypullremotebookmark(mayberemotebookmark, repo, ui):
+    ui.status(_('`%s` not found: assuming it is a remote bookmark '
+                'and trying to pull it\n') % mayberemotebookmark)
+    sourcerenames = dict((v, k) for k, v in _getrenames(ui).iteritems())
+    remote, bookmarkname = splitremotename(mayberemotebookmark)
+    paths = dict((path, url) for path, url in ui.configitems('paths'))
+    if remote in sourcerenames:
+        source = sourcerenames[remote]
+    elif remote in paths:
+        source = remote
+    else:
+        source = 'default'
+        bookmarkname = mayberemotebookmark
+    commands.pull(ui, repo, source=source, bookmark=[bookmarkname])
+    ui.status(_('`%s` found remotely\n') % mayberemotebookmark)
+
 def expull(orig, repo, remote, *args, **kwargs):
     remotebookmarks = remote.listkeys('bookmarks')
     if _isselectivepull(repo.ui):
@@ -217,6 +233,17 @@ 
     return bookmarks
 
 def updatecmd(orig, ui, repo, node=None, rev=None, **kwargs):
+    if rev and node:
+        raise error.Abort(_("please specify just one revision"))
+
+    if _isselectivepull(repo.ui) and not kwargs.get('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):
+            _trypullremotebookmark(rev or node, repo, ui)
+
     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,46 @@ 
   $ 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
+  `thirdbook` found remotely
+  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)
+  `secondremote/secondbook` found remotely
+  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