Patchwork obsutil: clarify the access to "repo"

login
register
mail settings
Submitter Boris Feld
Date Nov. 5, 2018, 10:42 a.m.
Message ID <f4f31bac4057231d9700.1541414539@localhost.localdomain>
Download mbox | patch
Permalink /patch/36362/
State Superseded
Headers show

Comments

Boris Feld - Nov. 5, 2018, 10:42 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1526995577 -7200
#      Tue May 22 15:26:17 2018 +0200
# Node ID f4f31bac4057231d97000967cb731ac0da25f30b
# Parent  e0dea186ab6edfab124b1dfd84237a4b8142f13b
# EXP-Topic gratuitous-cleanup
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r f4f31bac4057
obsutil: clarify the access to "repo"

We use the variable multiple times and we might use it even more in the
future. We use a temporary variable instead.
Yuya Nishihara - Nov. 5, 2018, 11:29 a.m.
On Mon, 05 Nov 2018 11:42:19 +0100, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1526995577 -7200
> #      Tue May 22 15:26:17 2018 +0200
> # Node ID f4f31bac4057231d97000967cb731ac0da25f30b
> # Parent  e0dea186ab6edfab124b1dfd84237a4b8142f13b
> # EXP-Topic gratuitous-cleanup
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r f4f31bac4057
> obsutil: clarify the access to "repo"
> 
> We use the variable multiple times and we might use it even more in the
> future. We use a temporary variable instead.
> 
> diff --git a/mercurial/obsutil.py b/mercurial/obsutil.py
> --- a/mercurial/obsutil.py
> +++ b/mercurial/obsutil.py
> @@ -397,11 +397,14 @@ def _cmpdiff(leftctx, rightctx):
>      This is a first and basic implementation, with many shortcoming.
>      """
>      diffopts = diffutil.diffallopts(leftctx.repo().ui, {'git': True})
> +
> +    # lefctx._repo and right_ctx._repo are the same here
> +    repo = leftctx._repo

Can you update the leftctx.repo() in the first line as well? It's better
to use repo() instead of _repo.

Patch

diff --git a/mercurial/obsutil.py b/mercurial/obsutil.py
--- a/mercurial/obsutil.py
+++ b/mercurial/obsutil.py
@@ -397,11 +397,14 @@  def _cmpdiff(leftctx, rightctx):
     This is a first and basic implementation, with many shortcoming.
     """
     diffopts = diffutil.diffallopts(leftctx.repo().ui, {'git': True})
+
+    # lefctx._repo and right_ctx._repo are the same here
+    repo = leftctx._repo
     # Leftctx or right ctx might be filtered, so we need to use the contexts
     # with an unfiltered repository to safely compute the diff
-    leftunfi = leftctx._repo.unfiltered()[leftctx.rev()]
+    leftunfi = repo.unfiltered()[leftctx.rev()]
     leftdiff = leftunfi.diff(opts=diffopts)
-    rightunfi = rightctx._repo.unfiltered()[rightctx.rev()]
+    rightunfi = repo.unfiltered()[rightctx.rev()]
     rightdiff = rightunfi.diff(opts=diffopts)
 
     left, right = (0, 0)