copies: document the current algorithm step
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 14 Dec 2020 11:32:20 +0100
changeset 46148 70a9eb899637
parent 46146 d109dda4a3e7
child 46149 294d5aca4ff5
copies: document the current algorithm step We are about to reorganise everything and we document the "old" way to clarify the change that leads to the "new way". Differential Revision: https://phab.mercurial-scm.org/D9581
mercurial/copies.py
--- a/mercurial/copies.py	Sat Dec 12 15:27:58 2020 +0530
+++ b/mercurial/copies.py	Mon Dec 14 11:32:20 2020 +0100
@@ -1,3 +1,4 @@
+# coding: utf8
 # copies.py - copy detection for Mercurial
 #
 # Copyright 2008 Matt Mackall <mpm@selenic.com>
@@ -351,14 +352,21 @@
     isancestor = cached_is_ancestor(isancestor)
 
     all_copies = {}
+    # iterate over all the "parent" side of copy tracing "edge"
     for r in revs:
+        # fetch potential previously computed data for that parent
         copies = all_copies.pop(r, None)
         if copies is None:
             # this is a root
             copies = {}
+
+        # iterate over all known children to chain the existing data with the
+        # data from the parent → child edge.
         for i, c in enumerate(children[r]):
             p1, p2, changes = revinfo(c)
             childcopies = {}
+
+            # select the right parent → child edge
             if r == p1:
                 parent = 1
                 if changes is not None:
@@ -372,6 +380,8 @@
                 childcopies = {
                     dst: src for dst, src in childcopies.items() if match(dst)
                 }
+
+            # chain the data in the edge with the existing data
             newcopies = copies
             if childcopies:
                 newcopies = copies.copy()
@@ -392,6 +402,9 @@
                             # could be avoided.
                             newcopies = copies.copy()
                         newcopies[f] = (c, None)
+
+            # check potential need to combine the data from another parent (for
+            # that child). See comment below for details.
             othercopies = all_copies.get(c)
             if othercopies is None:
                 all_copies[c] = newcopies
@@ -418,6 +431,7 @@
                 copies = _merge_copies_dict(minor, major, isancestor, changes)
                 all_copies[c] = copies
 
+    # filter out internal details and return a {dest: source mapping}
     final_copies = {}
     for dest, (tt, source) in all_copies[targetrev].items():
         if source is not None: