Patchwork [5,of,7] localrepo: map integer and hex wdir identifiers to workingctx

login
register
mail settings
Submitter Yuya Nishihara
Date June 3, 2017, 2:39 p.m.
Message ID <cee3aecb6c45796eb7a7.1496500769@mimosa>
Download mbox | patch
Permalink /patch/21160/
State Accepted
Headers show

Comments

Yuya Nishihara - June 3, 2017, 2:39 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1471599635 -32400
#      Fri Aug 19 18:40:35 2016 +0900
# Node ID cee3aecb6c45796eb7a79b995c04dd83289bfd76
# Parent  a516f6ea75b353f71a935063598ef7add5914db5
localrepo: map integer and hex wdir identifiers to workingctx

changectx.__init__() is slightly modified to take str(wdirrev) as a valid
integer revision (and raise WdirUnsupported exception.)

Test will be added by the next patch.
Yuya Nishihara - June 5, 2017, 3:57 p.m.
On Sat, 03 Jun 2017 23:39:29 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1471599635 -32400
> #      Fri Aug 19 18:40:35 2016 +0900
> # Node ID cee3aecb6c45796eb7a79b995c04dd83289bfd76
> # Parent  a516f6ea75b353f71a935063598ef7add5914db5
> localrepo: map integer and hex wdir identifiers to workingctx

I should note that this _could_ mean wdir node would get more accessible
over the wire protocol and hgweb. I think that's okay to expose server's
working directory, and both getbundle and hgweb crash if wdir node specified,
but I might be wrong.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -23,6 +23,7 @@  from .node import (
     short,
     wdirid,
     wdirnodes,
+    wdirrev,
 )
 from . import (
     encoding,
@@ -471,7 +472,7 @@  class changectx(basectx):
                 l = len(repo.changelog)
                 if r < 0:
                     r += l
-                if r < 0 or r >= l:
+                if r < 0 or r >= l and r != wdirrev:
                     raise ValueError
                 self._rev = r
                 self._node = repo.changelog.node(r)
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -20,7 +20,6 @@  from .node import (
     hex,
     nullid,
     short,
-    wdirrev,
 )
 from . import (
     bookmarks,
@@ -564,13 +563,17 @@  class localrepository(object):
             return nullid
 
     def __getitem__(self, changeid):
-        if changeid is None or changeid == wdirrev:
+        if changeid is None:
             return context.workingctx(self)
         if isinstance(changeid, slice):
+            # wdirrev isn't contiguous so the slice shouldn't include it
             return [context.changectx(self, i)
                     for i in xrange(*changeid.indices(len(self)))
                     if i not in self.changelog.filteredrevs]
-        return context.changectx(self, changeid)
+        try:
+            return context.changectx(self, changeid)
+        except error.WdirUnsupported:
+            return context.workingctx(self)
 
     def __contains__(self, changeid):
         """True if the given changeid exists