Patchwork D9126: changing-files: add clean computation of changed files for roots

login
register
mail settings
Submitter phabricator
Date Sept. 30, 2020, 1:11 p.m.
Message ID <differential-rev-PHID-DREV-puxxr47bjstlh67db67o-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47342/
State Superseded
Headers show

Comments

phabricator - Sept. 30, 2020, 1:11 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/metadata.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/metadata.py b/mercurial/metadata.py
--- a/mercurial/metadata.py
+++ b/mercurial/metadata.py
@@ -227,6 +227,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)
@@ -241,6 +245,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
     """