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

login
register
mail settings
Submitter Stanislau Hlebik
Date Aug. 22, 2016, 10:17 a.m.
Message ID <7dae93347fd658a55828.1471861036@dev1918.lla1.facebook.com>
Download mbox | patch
Permalink /patch/16378/
State Accepted
Delegated to: Durham Goode
Headers show

Comments

Stanislau Hlebik - Aug. 22, 2016, 10:17 a.m.
# HG changeset patch
# User Stanislau Hlebik <stash@fb.com>
# Date 1471860690 25200
#      Mon Aug 22 03:11:30 2016 -0700
# Node ID 7dae93347fd658a558284e55d27060e980f324f0
# 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. 22, 2016, 5:40 p.m.
Looks good to me.  Some comments inline, but I'd be fine with this being 
accepted.


On 8/22/16 3:17 AM, Stanislau Hlebik wrote:
> # HG changeset patch
> # User Stanislau Hlebik <stash@fb.com>
> # Date 1471860690 25200
> #      Mon Aug 22 03:11:30 2016 -0700
> # Node ID 7dae93347fd658a558284e55d27060e980f324f0
> # 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
>
> diff --git a/remotenames.py b/remotenames.py
> --- a/remotenames.py
> +++ b/remotenames.py
> @@ -17,6 +17,7 @@
>   import re
>   import errno
>   import shutil
> +import sys
>   import UserDict
>   
>   from mercurial import bookmarks
> @@ -76,6 +77,27 @@
>   def _isselectivepull(ui):
>       return ui.configbool('remotenames', 'selectivepull', False)
>   
> +def _trypullremotebookmark(mayberemotebookmark, repo, ui):
> +    ui.warn(_('`%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
> +
> +    try:
> +        commands.pull(ui, repo, source=source, bookmark=[bookmarkname])
> +    except Exception:
Catching 'Exception' is a bit of an anti-pattern (I think it will stop 
ctrl+c from working here too?), but in this case we really don't want 
the pull to interfere, so I guess it's fine for now.
> +        ui.warn(_('pull failed: %s\n') % sys.exc_info()[2])
> +    else:
> +        ui.warn(_('`%s` found remotely\n') % mayberemotebookmark)
> +
>   def expull(orig, repo, remote, *args, **kwargs):
>       remotebookmarks = remote.listkeys('bookmarks')
>       if _isselectivepull(repo.ui):
> @@ -217,6 +239,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)
What if both rev and node are None?  That can't happen at FB, but 
upstream supports "hg update" with no args.
> +        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
Sean Farley - Oct. 8, 2016, 1:08 p.m.
Stanislau Hlebik <stash@fb.com> writes:

> # HG changeset patch
> # User Stanislau Hlebik <stash@fb.com>
> # Date 1471860690 25200
> #      Mon Aug 22 03:11:30 2016 -0700
> # Node ID 7dae93347fd658a558284e55d27060e980f324f0
> # 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.

After sitting down together at the sprint, I was able to review these
and fix up the tests. Finally queued and pushed, thanks!

Patch

diff --git a/remotenames.py b/remotenames.py
--- a/remotenames.py
+++ b/remotenames.py
@@ -17,6 +17,7 @@ 
 import re
 import errno
 import shutil
+import sys
 import UserDict
 
 from mercurial import bookmarks
@@ -76,6 +77,27 @@ 
 def _isselectivepull(ui):
     return ui.configbool('remotenames', 'selectivepull', False)
 
+def _trypullremotebookmark(mayberemotebookmark, repo, ui):
+    ui.warn(_('`%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
+
+    try:
+        commands.pull(ui, repo, source=source, bookmark=[bookmarkname])
+    except Exception:
+        ui.warn(_('pull failed: %s\n') % sys.exc_info()[2])
+    else:
+        ui.warn(_('`%s` found remotely\n') % mayberemotebookmark)
+
 def expull(orig, repo, remote, *args, **kwargs):
     remotebookmarks = remote.listkeys('bookmarks')
     if _isselectivepull(repo.ui):
@@ -217,6 +239,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