cmdrewrite: avoid accessing scmutil.status fields by index
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 15 Nov 2019 08:14:06 -0800
changeset 4941 c6fb901b7bc8
parent 4940 93c89814a5d8
child 4942 acc7e27fa5c6
cmdrewrite: avoid accessing scmutil.status fields by index Support for indexed access is going away in Mercurial. Accessing the fields by name is clearer anyway.
hgext3rd/evolve/cmdrewrite.py
--- a/hgext3rd/evolve/cmdrewrite.py	Thu Nov 07 23:10:26 2019 -0800
+++ b/hgext3rd/evolve/cmdrewrite.py	Fri Nov 15 08:14:06 2019 -0800
@@ -290,8 +290,10 @@
 
 def _touchedbetween(repo, source, dest, match=None):
     touched = set()
-    for files in repo.status(source, dest, match=match)[:3]:
-        touched.update(files)
+    st = repo.status(source, dest, match=match)
+    touched.update(st.modified)
+    touched.update(st.added)
+    touched.update(st.removed)
     return touched
 
 def _commitfiltered(repo, ctx, match, target=None, message=None, user=None,
@@ -363,8 +365,8 @@
         # and considering only the files which are changed between oldctx and
         # ctx, and the status of what changed between oldctx and ctx will help
         # us in defining the exact behavior
-        m, a, r = repo.status(oldctx, ctx, match=match)[:3]
-        for f in m:
+        st = repo.status(oldctx, ctx, match=match)
+        for f in st.modified:
             # These are files which are modified between oldctx and ctx which
             # contains two cases: 1) Were modified in oldctx and some
             # modifications are uncommitted
@@ -380,7 +382,7 @@
                 continue
             ds.normallookup(f)
 
-        for f in a:
+        for f in st.added:
             # These are the files which are added between oldctx and ctx(new
             # one), which means the files which were removed in oldctx
             # but uncommitted completely while making the ctx
@@ -393,7 +395,7 @@
                 continue
             ds.remove(f)
 
-        for f in r:
+        for f in st.removed:
             # These are files which are removed between oldctx and ctx, which
             # means the files which were added in oldctx and were completely
             # uncommitted in ctx. If a added file is partially uncommitted, that
@@ -407,21 +409,21 @@
                 continue
             ds.add(f)
     else:
-        m, a, r = repo.status(oldctx.p1(), oldctx, match=match)[:3]
-        for f in m:
+        st = repo.status(oldctx.p1(), oldctx, match=match)
+        for f in st.modified:
             if ds[f] == b'r':
                 # modified + removed -> removed
                 continue
             ds.normallookup(f)
 
-        for f in a:
+        for f in st.added:
             if ds[f] == b'r':
                 # added + removed -> unknown
                 ds.drop(f)
             elif ds[f] != b'a':
                 ds.add(f)
 
-        for f in r:
+        for f in st.removed:
             if ds[f] == b'a':
                 # removed + added -> normal
                 ds.normallookup(f)
@@ -433,8 +435,8 @@
     if interactive:
         # Interactive had different meaning of the variables so restoring the
         # original meaning to use them
-        m, a, r = repo.status(oldctx.p1(), oldctx, match=match)[:3]
-    for f in (m + a):
+        st = repo.status(oldctx.p1(), oldctx, match=match)
+    for f in (st.modified + st.added):
         src = oldctx[f].renamed()
         if src:
             oldcopies[f] = src[0]
@@ -1234,8 +1236,8 @@
         rewriteutil.presplitupdate(repo, ui, prev, ctx)
 
         def haschanges(matcher=None):
-            modified, added, removed, deleted = repo.status(match=matcher)[:4]
-            return modified or added or removed or deleted
+            st = repo.status(match=matcher)
+            return st.modified or st.added or st.removed or st.deleted
         msg = (b"HG: This is the original pre-split commit message. "
                b"Edit it as appropriate.\n\n")
         msg += ctx.description()
@@ -1298,10 +1300,12 @@
                         ui.status(_(b'discarding remaining changes\n'))
                         target = newcommits[0]
                         if pats:
-                            status = repo.status(match=matcher)[:4]
+                            status = repo.status(match=matcher)
                             dirty = set()
-                            for i in status:
-                                dirty.update(i)
+                            dirty.update(status.modified)
+                            dirty.update(status.added)
+                            dirty.update(status.removed)
+                            dirty.update(status.deleted)
                             dirty = sorted(dirty)
                             cmdutil.revert(ui, repo, repo[target],
                                            (target, node.nullid), *dirty)