[PATCH 1 of 4 V2] context.status: wipe deleted/unknown/ignored fields when reversed

Martin von Zweigbergk martinvonz at google.com
Fri Nov 14 05:37:45 UTC 2014


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1415911625 28800
#      Thu Nov 13 12:47:05 2014 -0800
# Node ID 5a00e3a896a5e57c28fdde2a687297e4ea501c87
# Parent  394c79df66c39923477528b2ea2092b6944b965b
context.status: wipe deleted/unknown/ignored fields when reversed

It makes no sense to request reverse status (i.e. changes from the
working copy to its parent) and then look at the deleted, unknown or
ignored fields. If you do, you would get the result from the forward
status (changes from parent to the working copy). Instead of giving a
nonsensical answer to a nonsensical question, let's put None values in
place of the lists, so any caller trying to iterate over the lists
will break.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -304,9 +304,12 @@
         r = ctx2._buildstatus(ctx1, r, match, listignored, listclean,
                               listunknown)
 
+        r = scmutil.status(*r)
         if reversed:
-            # reverse added and removed
-            r[1], r[2] = r[2], r[1]
+            # Reverse added and removed. Deleted, unknown and ignored make no
+            # sense to reverse; use None to prevent users from iterating..
+            r = scmutil.status(r.modified, r.removed, r.added, None, None, None,
+                               r.clean)
 
         if listsubrepos:
             for subpath, sub in scmutil.itersubrepos(ctx1, ctx2):
@@ -323,10 +326,10 @@
                                            "subrepository: %s\n") % subpath)
 
         for l in r:
-            l.sort()
+            if l is not None:
+                l.sort()
 
-        # we return a tuple to signify that this list isn't changing
-        return scmutil.status(*r)
+        return r
 
 
 def makememctx(repo, parents, text, user, date, branch, files, store,
diff --git a/tests/test-context.py.out b/tests/test-context.py.out
--- a/tests/test-context.py.out
+++ b/tests/test-context.py.out
@@ -2,7 +2,7 @@
 ASCII   : Gr?ezi!
 Latin-1 : Grüezi!
 UTF-8   : Grüezi!
-<status modified=['foo'], added=[], removed=[], deleted=[], unknown=[], ignored=[], clean=[]>
+<status modified=['foo'], added=[], removed=[], deleted=None, unknown=None, ignored=None, clean=[]>
 diff --git a/foo b/foo
 
 --- a/foo


More information about the Mercurial-devel mailing list