[PATCH 3 of 8 RFC] localrepo: add "workingdir" symbol to specify workingctx by command (BC)

Yuya Nishihara yuya at tcha.org
Tue Aug 19 17:56:17 CDT 2014


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1408247327 -32400
#      Sun Aug 17 12:48:47 2014 +0900
# Node ID 304c88eafb4283e72af2eae5e6a442c255052385
# Parent  c14c51bf90582e64114bf5b274d1871558699c6a
localrepo: add "workingdir" symbol to specify workingctx by command (BC)

Currently most commands cannot handle workingctx and may raise AttributeError,
TypeError, ValueError, etc.  Maybe the use of "workingdir" should be banned at
scmutil.revrange() by default until it can be handled or rejected by major
commands.  But this RFC patch series does not include it.

This patch adds minimal test of "hg status" that should be able to accept
workingctx revision.

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -333,7 +333,7 @@ class changelog(revlog.revlog):
             branch = extra.get("branch")
             if branch in ("default", ""):
                 del extra["branch"]
-            elif branch in (".", "null", "tip"):
+            elif branch in (".", "null", "tip", "workingdir"):
                 raise error.RevlogError(_('the name \'%s\' is reserved')
                                         % branch)
         if extra:
diff --git a/mercurial/help/revisions.txt b/mercurial/help/revisions.txt
--- a/mercurial/help/revisions.txt
+++ b/mercurial/help/revisions.txt
@@ -27,3 +27,6 @@ The reserved name "." indicates the work
 working directory is checked out, it is equivalent to null. If an
 uncommitted merge is in progress, "." is the revision of the first
 parent.
+
+The reserved name "workingdir" indicates the working directory. This is
+the pseudo revision to be made by the next commit.
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -445,7 +445,7 @@ class localrepository(object):
     def __getitem__(self, changeid):
         if changeid is None:
             return context.workingctx(self)
-        if changeid == len(self):
+        if changeid == len(self) or changeid == 'workingdir':
             return context.workingctx(self, changeid=len(self))
         return context.changectx(self, changeid)
 
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -54,7 +54,7 @@ def nochangesfound(ui, repo, excluded=No
 def checknewlabel(repo, lbl, kind):
     # Do not use the "kind" parameter in ui output.
     # It makes strings difficult to translate.
-    if lbl in ['tip', '.', 'null']:
+    if lbl in ['tip', '.', 'null', 'workingdir']:
         raise util.Abort(_("the name '%s' is reserved") % lbl)
     for c in (':', '\0', '\n', '\r'):
         if c in lbl:
diff --git a/tests/test-branches.t b/tests/test-branches.t
--- a/tests/test-branches.t
+++ b/tests/test-branches.t
@@ -56,6 +56,9 @@ reserved names
   $ hg branch .
   abort: the name '.' is reserved
   [255]
+  $ hg branch workingdir
+  abort: the name 'workingdir' is reserved
+  [255]
 
 invalid characters
 
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -893,6 +893,9 @@ Test a help topic
       The reserved name "." indicates the working directory parent. If no
       working directory is checked out, it is equivalent to null. If an
       uncommitted merge is in progress, "." is the revision of the first parent.
+  
+      The reserved name "workingdir" indicates the working directory. This is
+      the pseudo revision to be made by the next commit.
 
 Test templating help
 
@@ -2055,6 +2058,10 @@ Dish up an empty repo; serve it cold.
   uncommitted merge is in progress, "." is the revision of the first
   parent.
   </p>
+  <p>
+  The reserved name "workingdir" indicates the working directory. This is
+  the pseudo revision to be made by the next commit.
+  </p>
   
   </div>
   </div>
diff --git a/tests/test-status.t b/tests/test-status.t
--- a/tests/test-status.t
+++ b/tests/test-status.t
@@ -198,6 +198,16 @@ Check 'status -q' and some combinations
   $ rm deleted
   $ hg copy modified copied
 
+Specify workingdir revision explicitly, that should be the same as "hg status"
+
+  $ hg status --change workingdir
+  M modified
+  A added
+  A copied
+  R removed
+  ! deleted
+  ? unknown
+
 Run status with 2 different flags.
 Check if result is the same or different.
 If result is not as expected, raise error
diff --git a/tests/test-tag.t b/tests/test-tag.t
--- a/tests/test-tag.t
+++ b/tests/test-tag.t
@@ -52,6 +52,9 @@ specified)
   $ hg tag null
   abort: the name 'null' is reserved
   [255]
+  $ hg tag workingdir
+  abort: the name 'workingdir' is reserved
+  [255]
   $ hg tag "bleah"
   abort: tag 'bleah' already exists (use -f to force)
   [255]


More information about the Mercurial-devel mailing list