Patchwork D9197: changing-files: add a shorthand property to check for copy relevant info

login
register
mail settings
Submitter phabricator
Date Oct. 13, 2020, 10:40 a.m.
Message ID <differential-rev-PHID-DREV-q42zs77pfmj7vpx5javw-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47445/
State Superseded
Headers show

Comments

phabricator - Oct. 13, 2020, 10:40 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We are going to reuse this change in more place, so we factor it out first.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/changelog.py
  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
@@ -75,6 +75,16 @@ 
             and self.copied_from_p2 == other.copied_from_p2
         )
 
+    @property
+    def has_copies_info(self):
+        return bool(
+            self.removed
+            or self.merged
+            or self.salvaged
+            or self.copied_from_p1
+            or self.copied_from_p2
+        )
+
     @util.propertycache
     def added(self):
         """files actively added in the changeset
@@ -244,8 +254,7 @@ 
 
 
 def _process_root(ctx):
-    """compute the appropriate changed files for a changeset with no parents
-    """
+    """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()
@@ -255,8 +264,7 @@ 
 
 
 def _process_linear(parent_ctx, children_ctx, parent=1):
-    """compute the appropriate changed files for a changeset with a single parent
-    """
+    """compute the appropriate changed files for a changeset with a single parent"""
     md = ChangingFiles()
     parent_manifest = parent_ctx.manifest()
     children_manifest = children_ctx.manifest()
@@ -505,8 +513,7 @@ 
 
 
 def computechangesetfilesadded(ctx):
-    """return the list of files added in a changeset
-    """
+    """return the list of files added in a changeset"""
     added = []
     for f in ctx.files():
         if not any(f in p for p in ctx.parents()):
@@ -570,8 +577,7 @@ 
 
 
 def computechangesetfilesremoved(ctx):
-    """return the list of files removed in a changeset
-    """
+    """return the list of files removed in a changeset"""
     removed = []
     for f in ctx.files():
         if f not in ctx:
@@ -583,8 +589,7 @@ 
 
 
 def computechangesetfilesmerged(ctx):
-    """return the list of files merged in a changeset
-    """
+    """return the list of files merged in a changeset"""
     merged = []
     if len(ctx.parents()) < 2:
         return merged
diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -91,8 +91,8 @@ 
 
 
 class appender(object):
-    '''the changelog index must be updated last on disk, so we use this class
-    to delay writes to it'''
+    """the changelog index must be updated last on disk, so we use this class
+    to delay writes to it"""
 
     def __init__(self, vfs, name, mode, buf):
         self.data = buf
@@ -583,13 +583,7 @@ 
         flags = 0
         sidedata = None
         if self._copiesstorage == b'changeset-sidedata':
-            if (
-                files.removed
-                or files.merged
-                or files.salvaged
-                or files.copied_from_p1
-                or files.copied_from_p2
-            ):
+            if files.has_copies_info:
                 flags |= flagutil.REVIDX_HASCOPIESINFO
             sidedata = metadata.encode_files_sidedata(files)