[PATCH 2 of 4 RFC V2] localrepo: add "wc" symbol to specify workingctx by command (BC)

Yuya Nishihara yuya at tcha.org
Mon Mar 16 09:04:31 CDT 2015


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

The "wc" symbol will be used to annotate working-directory files.

Currently many commands and revsets cannot handle workingctx and may raise
AttributeError, TypeError, ValueError, etc. This problem will be addressed
by future patches.

This is a breaking change that makes the existing "wc" tag, bookmark or
branch not accessible by its name but using revset functions. If this change
isn't acceptable, we can add "wc()" function instead.

Pros and cons:

  "wc" symbol:
   - is easy to type
   - can be used as a first-class symbol to specify wctx by string
     (would avoid problems such as caff3675cba5)
  "wc()" function:
   - has no behavior change

List of commands that will potentially support "wc" revision:

  command   default  remarks
  --------  -------  -----------------------------------------------------
  annotate  p1       useful
  archive   p1       might be useful
  cat       p1       might be useful on Windows (no cat)
  diff      p1:wc    (default)
  export    p1       might be useful if wctx can have draft commit message
  files     wc       (default)
  grep      tip:0    might be useful
  identify  wc       (default)
  locate    wc       (default)
  log       tip:0    might be useful with -p or -G option
  parents   wc       (default)
  status    wc       (default)

This patch includes minimal test of "hg status" that should be able to handle
the workingctx revision.

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -366,7 +366,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", "wc"):
                 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 "wc" indicates the files in the working directory, that
+will be recorded in the next commit.
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -455,7 +455,7 @@ class localrepository(object):
         return dirstate.dirstate(self.vfs, self.ui, self.root, validate)
 
     def __getitem__(self, changeid):
-        if changeid is None:
+        if changeid is None or changeid == 'wc':
             return context.workingctx(self)
         if isinstance(changeid, slice):
             return [context.changectx(self, i)
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -107,7 +107,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', 'wc']:
         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 wc
+  abort: the name 'wc' 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
@@ -892,6 +892,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 "wc" indicates the files in the working directory, that
+      will be recorded in the next commit.
 
 Test templating help
 
@@ -2223,6 +2226,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 "wc" indicates the files in the working directory, that
+  will be recorded in 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
@@ -240,6 +240,17 @@ Check 'status -q' and some combinations
   $ rm deleted
   $ hg copy modified copied
 
+Specify working directory revision explicitly, that should be the same as
+"hg status"
+
+  $ hg status --change wc
+  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
@@ -53,6 +53,9 @@ specified)
   $ hg tag null
   abort: the name 'null' is reserved
   [255]
+  $ hg tag wc
+  abort: the name 'wc' is reserved
+  [255]
   $ hg tag "bleah"
   abort: tag 'bleah' already exists (use -f to force)
   [255]


More information about the Mercurial-devel mailing list