Patchwork D6933: context: clarify the various mode in the _copies property cache

login
register
mail settings
Submitter phabricator
Date Oct. 1, 2019, 12:33 p.m.
Message ID <differential-rev-PHID-DREV-k2rv2jfncfeyxz53j7sd-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/41882/
State Superseded
Headers show

Comments

phabricator - Oct. 1, 2019, 12:33 p.m.
marmoute created this revision.
marmoute added reviewers: martinvonz, durin42.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The previous code was compact but a bit dense. The new proposed code deal with
  each mode separately, there are some duplicated lines, but the meaning of each
  mode stand out.
  
  One of the benefit it to make it simpler to add further mode in the future.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6933

AFFECTED FILES
  mercurial/context.py

CHANGE DETAILS




To: marmoute, martinvonz, durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - Oct. 1, 2019, 4:23 p.m.
martinvonz added inline comments.

INLINE COMMENTS

> context.py:502-504
> +            # Otherwise (config said to read only from filelog, or we are in
> +            # compatiblity mode and there is not data in the changeset), we get
> +            # the copy metadata from the filelogs.

This needs to be split up (the "compatibility" case is now further up)

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6933/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6933

To: marmoute, martinvonz, durin42, #hg-reviewers, pulkit
Cc: mercurial-devel

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -490,14 +490,21 @@ 
         # In compatibility mode, we return copy data from the changeset if
         # it was recorded there, and otherwise we fall back to getting it from
         # the filelogs (below).
-        if (source == 'changeset-only' or
-            (source == 'compatibility' and p1copies is not None)):
-            return p1copies or {}, p2copies or {}
-
-        # Otherwise (config said to read only from filelog, or we are in
-        # compatiblity mode and there is not data in the changeset), we get
-        # the copy metadata from the filelogs.
-        return super(changectx, self)._copies
+        if source == 'changeset-only':
+            if p1copies is None:
+                p1copies = {}
+            if p2copies is None:
+                p2copies = {}
+        elif source == 'compatibility':
+            if p1copies is None:
+                p1copies, p2copies = super(changectx, self)._copies
+        else:
+            # Otherwise (config said to read only from filelog, or we are in
+            # compatiblity mode and there is not data in the changeset), we get
+            # the copy metadata from the filelogs.
+            p1copies, p2copies = super(changectx, self)._copies
+        return p1copies, p2copies
+
     def description(self):
         return self._changeset.description
     def branch(self):