cleanup: use p1() and p2() instead of parents()[0] and parents()[1]
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 25 Jan 2019 23:36:23 -0800
changeset 41397 0bd56c291359
parent 41396 3461814417f3
child 41398 2ff8994ac71d
cleanup: use p1() and p2() instead of parents()[0] and parents()[1] We have had these methods on both contexts and dirstate for a long time now. Differential Revision: https://phab.mercurial-scm.org/D5706
contrib/synthrepo.py
hgext/histedit.py
hgext/largefiles/lfcommands.py
hgext/largefiles/lfutil.py
hgext/shelve.py
hgext/strip.py
hgext/uncommit.py
mercurial/commands.py
mercurial/hgweb/webcommands.py
mercurial/revset.py
mercurial/sparse.py
mercurial/templatekw.py
tests/test-context.py
--- a/contrib/synthrepo.py	Mon Jan 21 15:29:14 2019 +0000
+++ b/contrib/synthrepo.py	Fri Jan 25 23:36:23 2019 -0800
@@ -349,7 +349,7 @@
     # to the modeled directory structure.
     initcount = int(opts['initfiles'])
     if initcount and initdirs:
-        pctx = repo[None].parents()[0]
+        pctx = repo[None].p1()
         dirs = set(pctx.dirs())
         files = {}
 
--- a/hgext/histedit.py	Mon Jan 21 15:29:14 2019 +0000
+++ b/hgext/histedit.py	Fri Jan 25 23:36:23 2019 -0800
@@ -575,7 +575,7 @@
 
 def applychanges(ui, repo, ctx, opts):
     """Merge changeset from ctx (only) in the current working directory"""
-    wcpar = repo.dirstate.parents()[0]
+    wcpar = repo.dirstate.p1()
     if ctx.p1().node() == wcpar:
         # edits are "in place" we do not need to make any merge,
         # just applies changes on parent for editing
@@ -608,7 +608,7 @@
         if not c.mutable():
             raise error.ParseError(
                 _("cannot fold into public change %s") % node.short(c.node()))
-    base = firstctx.parents()[0]
+    base = firstctx.p1()
 
     # commit a new version of the old changeset, including the update
     # collect all files which might be affected
@@ -693,7 +693,7 @@
 class pick(histeditaction):
     def run(self):
         rulectx = self.repo[self.node]
-        if rulectx.parents()[0].node() == self.state.parentctxnode:
+        if rulectx.p1().node() == self.state.parentctxnode:
             self.repo.ui.debug('node %s unchanged\n' % node.short(self.node))
             return rulectx, []
 
@@ -724,7 +724,7 @@
         super(fold, self).verify(prev, expected, seen)
         repo = self.repo
         if not prev:
-            c = repo[self.node].parents()[0]
+            c = repo[self.node].p1()
         elif not prev.verb in ('pick', 'base'):
             return
         else:
@@ -795,7 +795,7 @@
         return False
 
     def finishfold(self, ui, repo, ctx, oldctx, newnode, internalchanges):
-        parent = ctx.parents()[0].node()
+        parent = ctx.p1().node()
         hg.updaterepo(repo, parent, overwrite=False)
         ### prepare new commit data
         commitopts = {}
@@ -1902,7 +1902,7 @@
     actions = parserules(rules, state)
     warnverifyactions(ui, repo, actions, state, ctxs)
 
-    parentctxnode = repo[root].parents()[0].node()
+    parentctxnode = repo[root].p1().node()
 
     state.parentctxnode = parentctxnode
     state.actions = actions
--- a/hgext/largefiles/lfcommands.py	Mon Jan 21 15:29:14 2019 +0000
+++ b/hgext/largefiles/lfcommands.py	Fri Jan 25 23:36:23 2019 -0800
@@ -288,8 +288,8 @@
     files = set(ctx.files())
     if node.nullid not in parents:
         mc = ctx.manifest()
-        mp1 = ctx.parents()[0].manifest()
-        mp2 = ctx.parents()[1].manifest()
+        mp1 = ctx.p1().manifest()
+        mp2 = ctx.p2().manifest()
         files |= (set(mp1) | set(mp2)) - set(mc)
         for f in mc:
             if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, None):
--- a/hgext/largefiles/lfutil.py	Mon Jan 21 15:29:14 2019 +0000
+++ b/hgext/largefiles/lfutil.py	Fri Jan 25 23:36:23 2019 -0800
@@ -518,8 +518,8 @@
             files = set(ctx.files())
             if len(parents) == 2:
                 mc = ctx.manifest()
-                mp1 = ctx.parents()[0].manifest()
-                mp2 = ctx.parents()[1].manifest()
+                mp1 = ctx.p1().manifest()
+                mp2 = ctx.p2().manifest()
                 for f in mp1:
                     if f not in mc:
                         files.add(f)
--- a/hgext/shelve.py	Mon Jan 21 15:29:14 2019 +0000
+++ b/hgext/shelve.py	Fri Jan 25 23:36:23 2019 -0800
@@ -674,7 +674,7 @@
         hg.update(repo, wctx.node())
         files = []
         files.extend(shelvectx.files())
-        files.extend(shelvectx.parents()[0].files())
+        files.extend(shelvectx.p1().files())
 
         # revert will overwrite unknown files, so move them out of the way
         for file in repo.status(unknown=True).unknown:
@@ -809,7 +809,7 @@
     """Rebase restored commit from its original location to a destination"""
     # If the shelve is not immediately on top of the commit
     # we'll be merging with, rebase it to be on top.
-    if tmpwctx.node() == shelvectx.parents()[0].node():
+    if tmpwctx.node() == shelvectx.p1().node():
         return shelvectx
 
     overrides = {
--- a/hgext/strip.py	Mon Jan 21 15:29:14 2019 +0000
+++ b/hgext/strip.py	Fri Jan 25 23:36:23 2019 -0800
@@ -39,7 +39,7 @@
     if baserev:
         bctx = repo[baserev]
     else:
-        bctx = wctx.parents()[0]
+        bctx = wctx.p1()
     for s in sorted(wctx.substate):
         wctx.sub(s).bailifchanged(True)
         if s not in bctx.substate or bctx.sub(s).dirty():
--- a/hgext/uncommit.py	Mon Jan 21 15:29:14 2019 +0000
+++ b/hgext/uncommit.py	Fri Jan 25 23:36:23 2019 -0800
@@ -67,7 +67,7 @@
     files = (initialfiles - exclude)
     # return the p1 so that we don't create an obsmarker later
     if not keepcommit:
-        return ctx.parents()[0].node()
+        return ctx.p1().node()
 
     # Filter copies
     copied = copiesmod.pathcopies(base, ctx)
--- a/mercurial/commands.py	Mon Jan 21 15:29:14 2019 +0000
+++ b/mercurial/commands.py	Fri Jan 25 23:36:23 2019 -0800
@@ -1672,8 +1672,8 @@
         if not bheads:
             raise error.Abort(_('can only close branch heads'))
         elif opts.get('amend'):
-            if repo[None].parents()[0].p1().branch() != branch and \
-                    repo[None].parents()[0].p2().branch() != branch:
+            if repo[None].p1().p1().branch() != branch and \
+                    repo[None].p1().p2().branch() != branch:
                 raise error.Abort(_('can only close branch heads'))
 
     if opts.get('amend'):
--- a/mercurial/hgweb/webcommands.py	Mon Jan 21 15:29:14 2019 +0000
+++ b/mercurial/hgweb/webcommands.py	Fri Jan 25 23:36:23 2019 -0800
@@ -884,7 +884,7 @@
             leftlines = filelines(pfctx)
     else:
         rightlines = ()
-        pfctx = ctx.parents()[0][path]
+        pfctx = ctx.p1()[path]
         leftlines = filelines(pfctx)
 
     comparison = webutil.compare(context, leftlines, rightlines)
--- a/mercurial/revset.py	Mon Jan 21 15:29:14 2019 +0000
+++ b/mercurial/revset.py	Fri Jan 25 23:36:23 2019 -0800
@@ -471,7 +471,7 @@
             try:
                 r = cl.parentrevs(r)[0]
             except error.WdirUnsupported:
-                r = repo[r].parents()[0].rev()
+                r = repo[r].p1().rev()
         ps.add(r)
     return subset & ps
 
@@ -1572,7 +1572,7 @@
         try:
             ps.add(cl.parentrevs(r)[0])
         except error.WdirUnsupported:
-            ps.add(repo[r].parents()[0].rev())
+            ps.add(repo[r].p1().rev())
     ps -= {node.nullrev}
     # XXX we should turn this into a baseset instead of a set, smartset may do
     # some optimizations from the fact this is a baseset.
@@ -1691,7 +1691,7 @@
             try:
                 ps.add(cl.parentrevs(r)[0])
             except error.WdirUnsupported:
-                ps.add(repo[r].parents()[0].rev())
+                ps.add(repo[r].p1().rev())
         else:
             try:
                 parents = cl.parentrevs(r)
--- a/mercurial/sparse.py	Mon Jan 21 15:29:14 2019 +0000
+++ b/mercurial/sparse.py	Fri Jan 25 23:36:23 2019 -0800
@@ -336,7 +336,7 @@
     if branchmerge:
         # If we're merging, use the wctx filter, since we're merging into
         # the wctx.
-        sparsematch = matcher(repo, [wctx.parents()[0].rev()])
+        sparsematch = matcher(repo, [wctx.p1().rev()])
     else:
         # If we're updating, use the target context's filter, since we're
         # moving to the target context.
--- a/mercurial/templatekw.py	Mon Jan 21 15:29:14 2019 +0000
+++ b/mercurial/templatekw.py	Fri Jan 25 23:36:23 2019 -0800
@@ -796,7 +796,7 @@
     substate = ctx.substate
     if not substate:
         return compatlist(context, mapping, 'subrepo', [])
-    psubstate = ctx.parents()[0].substate or {}
+    psubstate = ctx.p1().substate or {}
     subrepos = []
     for sub in substate:
         if sub not in psubstate or substate[sub] != psubstate[sub]:
--- a/tests/test-context.py	Mon Jan 21 15:29:14 2019 +0000
+++ b/tests/test-context.py	Fri Jan 25 23:36:23 2019 -0800
@@ -63,7 +63,7 @@
 # test performing a status
 
 def getfilectx(repo, memctx, f):
-    fctx = memctx.parents()[0][f]
+    fctx = memctx.p1()[f]
     data, flags = fctx.data(), fctx.flags()
     if f == b'foo':
         data += b'bar\n'