changeset 45666:f6811e5bd994

changing-files: add clean computation of changed files for roots The `files` field is not reliable, so we need to compute things from scratch. We start with the simplest case root changesets. In the beginning they was nothing, then user said "let there be files" and there were added files. Differential Revision: https://phab.mercurial-scm.org/D9126
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 29 Sep 2020 22:38:08 +0200
parents 308ca5528ee6
children 0303fc1f43f8
files mercurial/metadata.py
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/metadata.py	Wed Sep 30 09:21:33 2020 +0200
+++ b/mercurial/metadata.py	Tue Sep 29 22:38:08 2020 +0200
@@ -226,6 +226,10 @@
 
 def compute_all_files_changes(ctx):
     """compute the files changed by a revision"""
+    p1 = ctx.p1()
+    p2 = ctx.p2()
+    if p1.rev() == node.nullrev and p2.rev() == node.nullrev:
+        return _process_root(ctx)
     filescopies = computechangesetcopies(ctx)
     filesadded = computechangesetfilesadded(ctx)
     filesremoved = computechangesetfilesremoved(ctx)
@@ -240,6 +244,17 @@
     return files
 
 
+def _process_root(ctx):
+    """compute the appropriate changed files for a changeset with no parents
+    """
+    # Simple, there was nothing before it, so everything is added.
+    md = ChangingFiles()
+    manifest = ctx.manifest()
+    for filename in manifest:
+        md.mark_added(filename)
+    return md
+
+
 def computechangesetfilesadded(ctx):
     """return the list of files added in a changeset
     """