Patchwork [3,of,3] commands: inline definition of localrepo.parents() and drop the method

login
register
mail settings
Submitter Augie Fackler
Date Dec. 1, 2015, 5:20 p.m.
Message ID <e1bc3626fe140f5e32b8.1448990435@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/11710/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Augie Fackler - Dec. 1, 2015, 5:20 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1447290435 18000
#      Wed Nov 11 20:07:15 2015 -0500
# Node ID e1bc3626fe140f5e32b88f931577a8426425a747
# Parent  c35c8a27f30f9406e9b0dbda47d294106e029429
commands: inline definition of localrepo.parents() and drop the method

localrepo.parents() has relatively few users, and most of those were
actually implicitly looking at the wctx, which is now made explicit
via repo[None].
Yuya Nishihara - Dec. 2, 2015, 12:42 p.m.
On Tue, 01 Dec 2015 12:20:35 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1447290435 18000
> #      Wed Nov 11 20:07:15 2015 -0500
> # Node ID e1bc3626fe140f5e32b88f931577a8426425a747
> # Parent  c35c8a27f30f9406e9b0dbda47d294106e029429
> commands: inline definition of localrepo.parents() and drop the method
> 
> localrepo.parents() has relatively few users, and most of those were
> actually implicitly looking at the wctx, which is now made explicit
> via repo[None].

Really nice. Flagged this as (API) and pushed the series to the clowncopter.

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -441,7 +441,7 @@  def rebase(ui, repo, **opts):
                                              targetancestors)
                 storestatus(repo, originalwd, target, state, collapsef, keepf,
                             keepbranchesf, external, activebookmark)
-                if len(repo.parents()) == 2:
+                if len(repo[None].parents()) == 2:
                     repo.ui.debug('resuming interrupted rebase\n')
                 else:
                     try:
@@ -930,7 +930,7 @@  def restorestatus(repo):
 def needupdate(repo, state):
     '''check whether we should `update --clean` away from a merge, or if
     somehow the working dir got forcibly updated, e.g. by older hg'''
-    parents = [p.rev() for p in repo.parents()]
+    parents = [p.rev() for p in repo[None].parents()]
 
     # Are we in a merge state at all?
     if len(parents) < 2:
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1190,7 +1190,7 @@  def branch(ui, repo, label=None, **opts)
             ui.status(_('reset working directory to branch %s\n') % label)
         elif label:
             if not opts.get('force') and label in repo.branchmap():
-                if label not in [p.branch() for p in repo.parents()]:
+                if label not in [p.branch() for p in repo[None].parents()]:
                     raise error.Abort(_('a branch of the same name already'
                                        ' exists'),
                                      # i18n: "it" refers to an existing branch
@@ -1600,8 +1600,8 @@  def commit(ui, repo, *pats, **opts):
         if not bheads:
             raise error.Abort(_('can only close branch heads'))
         elif opts.get('amend'):
-            if repo.parents()[0].p1().branch() != branch and \
-                    repo.parents()[0].p2().branch() != branch:
+            if repo[None].parents()[0].p1().branch() != branch and \
+                    repo[None].parents()[0].p2().branch() != branch:
                 raise error.Abort(_('can only close branch heads'))
 
     if opts.get('amend'):
@@ -4545,7 +4545,7 @@  def import_(ui, repo, patch1=None, *patc
                 tr = repo.transaction('import')
             else:
                 dsguard = cmdutil.dirstateguard(repo, 'import')
-            parents = repo.parents()
+            parents = repo[None].parents()
             for patchurl in patches:
                 if patchurl == '-':
                     ui.status(_('applying patch from stdin\n'))
@@ -4565,7 +4565,7 @@  def import_(ui, repo, patch1=None, *patc
                         haspatch = True
                         ui.note(msg + '\n')
                     if update or opts.get('exact'):
-                        parents = repo.parents()
+                        parents = repo[None].parents()
                     else:
                         parents = [repo[node]]
                     if rej:
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -852,10 +852,6 @@  class localrepository(object):
     def changectx(self, changeid):
         return self[changeid]
 
-    def parents(self, changeid=None):
-        '''get list of changectxs for parents of changeid'''
-        return self[changeid].parents()
-
     def setparents(self, p1, p2=nullid):
         self.dirstate.beginparentchange()
         copies = self.dirstate.setparents(p1, p2)
@@ -1170,7 +1166,7 @@  class localrepository(object):
                         % self.dirstate.branch())
 
             self.dirstate.invalidate()
-            parents = tuple([p.rev() for p in self.parents()])
+            parents = tuple([p.rev() for p in self[None].parents()])
             if len(parents) > 1:
                 ui.status(_('working directory now based on '
                             'revisions %d and %d\n') % parents)