commitctx: directly pass a ChangingFiles object to changelog.add
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sat, 25 Jul 2020 15:55:09 +0200
changeset 45324 6c56277317c2
parent 45323 aea6a812f7cb
child 45325 c6eea5804551
commitctx: directly pass a ChangingFiles object to changelog.add We pass the rich object to the changelog and it read the field it needs.
mercurial/changelog.py
mercurial/commit.py
tests/test-convert-identity.t
--- a/mercurial/changelog.py	Sat Jul 25 15:49:12 2020 +0200
+++ b/mercurial/changelog.py	Sat Jul 25 15:55:09 2020 +0200
@@ -524,10 +524,6 @@
         user,
         date=None,
         extra=None,
-        p1copies=None,
-        p2copies=None,
-        filesadded=None,
-        filesremoved=None,
     ):
         # Convert to UTF-8 encoded bytestrings as the very first
         # thing: calling any method on a localstr object will turn it
@@ -559,19 +555,23 @@
                 raise error.StorageError(
                     _(b'the name \'%s\' is reserved') % branch
                 )
-        sortedfiles = sorted(files)
+        sortedfiles = sorted(files.touched)
         sidedata = None
         if self._copiesstorage == b'changeset-sidedata':
             sidedata = {}
+            p1copies = files.copied_from_p1
             if p1copies:
                 p1copies = metadata.encodecopies(sortedfiles, p1copies)
                 sidedata[sidedatamod.SD_P1COPIES] = p1copies
+            p2copies = files.copied_from_p2
             if p2copies:
                 p2copies = metadata.encodecopies(sortedfiles, p2copies)
                 sidedata[sidedatamod.SD_P2COPIES] = p2copies
+            filesadded = files.added
             if filesadded:
                 filesadded = metadata.encodefileindices(sortedfiles, filesadded)
                 sidedata[sidedatamod.SD_FILESADDED] = filesadded
+            filesremoved = files.removed
             if filesremoved:
                 filesremoved = metadata.encodefileindices(
                     sortedfiles, filesremoved
--- a/mercurial/commit.py	Sat Jul 25 15:49:12 2020 +0200
+++ b/mercurial/commit.py	Sat Jul 25 15:55:09 2020 +0200
@@ -84,7 +84,7 @@
         repo.changelog.delayupdate(tr)
         n = repo.changelog.add(
             mn,
-            files.touched,
+            files,
             ctx.description(),
             tr,
             p1.node(),
@@ -92,10 +92,6 @@
             user,
             ctx.date(),
             extra,
-            files.copied_from_p1,
-            files.copied_from_p2,
-            files.added,
-            files.removed,
         )
         xp1, xp2 = p1.hex(), p2 and p2.hex() or b''
         repo.hook(
--- a/tests/test-convert-identity.t	Sat Jul 25 15:49:12 2020 +0200
+++ b/tests/test-convert-identity.t	Sat Jul 25 15:55:09 2020 +0200
@@ -8,9 +8,10 @@
   > convert =
   > EOF
   $ cat <<'EOF' > changefileslist.py
-  > from mercurial import (changelog, extensions)
+  > from mercurial import (changelog, extensions, metadata)
   > def wrap(orig, clog, manifest, files, *args, **kwargs):
-  >   return orig(clog, manifest, [b"a"], *args, **kwargs)
+  >   files = metadata.ChangingFiles(touched=[b"a"])
+  >   return orig(clog, manifest, files, *args, **kwargs)
   > def extsetup(ui):
   >   extensions.wrapfunction(changelog.changelog, 'add', wrap)
   > EOF