Patchwork [4,of,7] revlog: map rev(wdirid) to WdirUnsupported exception

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

Comments

Yuya Nishihara - June 3, 2017, 2:39 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1471700278 -32400
#      Sat Aug 20 22:37:58 2016 +0900
# Node ID a516f6ea75b353f71a935063598ef7add5914db5
# Parent  4e1430d8750d271a5812b96243e1ec68d3e6ebb4
revlog: map rev(wdirid) to WdirUnsupported exception

This will allow us to map repo["ff..."] to workingctx. _partialmatch() will
be updated later. I tried "return wdirrev" in place of raising the exception,
but earlier exception seemed better.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -26,6 +26,7 @@  from .node import (
     hex,
     nullid,
     nullrev,
+    wdirid,
     wdirrev,
 )
 from .i18n import _
@@ -416,6 +417,8 @@  class revlog(object):
             raise
         except RevlogError:
             # parsers.c radix tree lookup failed
+            if node == wdirid:
+                raise error.WdirUnsupported
             raise LookupError(node, self.indexfile, _('no node'))
         except KeyError:
             # pure python cache lookup failed
@@ -430,6 +433,8 @@  class revlog(object):
                 if v == node:
                     self._nodepos = r - 1
                     return r
+            if node == wdirid:
+                raise error.WdirUnsupported
             raise LookupError(node, self.indexfile, _('no node'))
 
     # Accessors for index entries.
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -190,6 +190,8 @@  def callcatch(ui, func):
         if inst.hint:
             ui.warn(_("(%s)\n") % inst.hint)
         return 1
+    except error.WdirUnsupported:
+        ui.warn(_("abort: working directory revision cannot be specified\n"))
     except error.Abort as inst:
         ui.warn(_("abort: %s\n") % inst)
         if inst.hint:
diff --git a/tests/test-debugcommands.t b/tests/test-debugcommands.t
--- a/tests/test-debugcommands.t
+++ b/tests/test-debugcommands.t
@@ -110,6 +110,12 @@  Test max chain len
       7     6    -1   ???   ???        ???  ???  ???    0     ???      ????           ?     1        2 (glob)
       8     7    -1   ???   ???        ???  ???  ???    0     ???      ????           ?     1        3 (glob)
 
+Test WdirUnsupported exception
+
+  $ hg debugdata -c ffffffffffffffffffffffffffffffffffffffff
+  abort: working directory revision cannot be specified
+  [255]
+
 Test cache warming command
 
   $ rm -rf .hg/cache/