commit: move sorting of added and removed files list to lower level
authorMartin von Zweigbergk <martinvonz@google.com>
Tue, 14 May 2019 16:30:38 -0700
changeset 42347 6310180662f5
parent 42346 38d85ec06552
child 42348 de65ae32b82d
commit: move sorting of added and removed files list to lower level localrepo.commitctx() has lists of all changed files, as well as lists of added and removed files. The list of all files is unsorted and changelog.add() will sort it. Let's also sort the lists of added and removed files at a lower level (manifestrevlog.add()) for consistency. It also seems safer to do it there, just before we write them to the store. That way other callers won't be able to create invalid commits (or whatever the consequence is) by passing in unsorted lists. Also, alternative storages may not care that the lists are sorted. I don't think this will be a performance problem (someone should have fixed the sorting in changelog.add() if it were). Differential Revision: https://phab.mercurial-scm.org/D6390
mercurial/localrepo.py
mercurial/manifest.py
--- a/mercurial/localrepo.py	Wed Apr 24 09:39:40 2019 -0700
+++ b/mercurial/localrepo.py	Tue May 14 16:30:38 2019 -0700
@@ -2641,8 +2641,8 @@
                         raise
 
                 # update manifest
-                removed = [f for f in sorted(removed) if f in m1 or f in m2]
-                drop = [f for f in removed if f in m]
+                removed = [f for f in removed if f in m1 or f in m2]
+                drop = sorted([f for f in removed if f in m])
                 for f in drop:
                     del m[f]
                 files = changed + removed
--- a/mercurial/manifest.py	Wed Apr 24 09:39:40 2019 -0700
+++ b/mercurial/manifest.py	Tue May 14 16:30:38 2019 -0700
@@ -1486,8 +1486,8 @@
 
             _checkforbidden(added)
             # combine the changed lists into one sorted iterator
-            work = heapq.merge([(x, False) for x in added],
-                               [(x, True) for x in removed])
+            work = heapq.merge([(x, False) for x in sorted(added)],
+                               [(x, True) for x in sorted(removed)])
 
             arraytext, deltatext = m.fastdelta(self.fulltextcache[p1], work)
             cachedelta = self._revlog.rev(p1), deltatext