Patchwork [8,of,8] changectx: use names api to simplify and extend node lookup

login
register
mail settings
Submitter Sean Farley
Date Dec. 15, 2014, 12:37 a.m.
Message ID <d096475df70e5c6b9ddf.1418603876@laptop.local>
Download mbox | patch
Permalink /patch/7101/
State Accepted
Headers show

Comments

Sean Farley - Dec. 15, 2014, 12:37 a.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1413527274 25200
#      Thu Oct 16 23:27:54 2014 -0700
# Node ID d096475df70e5c6b9ddfde2752749d94eadbfa0c
# Parent  85c150b347a9fc6c717864ba4f7e2d60812b5fad
changectx: use names api to simplify and extend node lookup

Previously, changectx had to know about each type of name (bookmark, tag, etc.)
to look up. Now, we use repo.namenodes to simplify (and extend) this.
Pierre-Yves David - Dec. 15, 2014, 2:10 a.m.
On 12/14/2014 04:37 PM, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley@gmail.com>
> # Date 1413527274 25200
> #      Thu Oct 16 23:27:54 2014 -0700
> # Node ID d096475df70e5c6b9ddfde2752749d94eadbfa0c
> # Parent  85c150b347a9fc6c717864ba4f7e2d60812b5fad
> changectx: use names api to simplify and extend node lookup
>
> Previously, changectx had to know about each type of name (bookmark, tag, etc.)
> to look up. Now, we use repo.namenodes to simplify (and extend) this.

I've pushed to the clowncopter an updated version of this series.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -405,14 +405,18 @@  class changectx(basectx):
                 except error.FilteredLookupError:
                     raise
                 except (TypeError, LookupError):
                     pass
 
-            if changeid in repo._bookmarks:
-                self._node = repo._bookmarks[changeid]
+            # lookup bookmarks through the name interface
+            try:
+                self._node = repo.names.singlenode(changeid)
                 self._rev = repo.changelog.rev(self._node)
                 return
+            except KeyError:
+                pass
+
             if changeid in repo._tagscache.tags:
                 self._node = repo._tagscache.tags[changeid]
                 self._rev = repo.changelog.rev(self._node)
                 return
             try: