Mercurial > hg
diff mercurial/changelog.py @ 42406:f385ba70e4af
changelog: optionally store added and removed files in changeset extras
As mentioned in an earlier patch, copies._chain() is used a lot in the
changeset-centric version of pathcopies(). It is expensive because it
needs to look at the manifest in order to filter out copies whose
target file has since been removed. I want to store the sets of added
and removed files in the changeset in order to speed that up. This
patch does the writing part of that. It could easily be a separate
config, but it's currently tied to experimental.copies.write-to since
that's the only real use case (it will also make the {file_*} template
keywords faster, but I doubt that anyone cares enough about those to
write extra metadata for them).
The new information is stored in the changeset extras. Since they're
always subsets of the changeset's "files" list, they're stored as
indexes into that list. I've stored the indexes as stringified ints
separated by NUL bytes. The size of 00changelog.d for the hg repo
increased in size by 0.28% percent (compared to the size with only
copy information in the changesets, which in turn is 0.17% larger than
without copy information). We could store only the delta between the
indexes and we could store them in binary, but the chosen format is
more readable.
We could also have implemented this as a cache outside the
changelog. One advantage of doing it that way is that we would get the
speedups from the {file_*} template keywords also on old
repos. Another advantage is that it we can rewrite the cache if we
find a bug in how we calculate the set of files. A disadvantage is
that it would be more complex. Another is that it would surely use
more space. We already write the copy information to the changeset
extras, so it seems like a small step to also write these file sets.
Differential Revision: https://phab.mercurial-scm.org/D6416
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 14 May 2019 22:19:51 -0700 |
parents | 2a7109cc5a28 |
children | 602469a91550 |
line wrap: on
line diff
--- a/mercurial/changelog.py Thu Apr 18 13:35:02 2019 -0700 +++ b/mercurial/changelog.py Tue May 14 22:19:51 2019 -0700 @@ -99,6 +99,14 @@ # used different syntax for the value. return None +def encodefileindices(files, subset): + subset = set(subset) + indices = [] + for i, f in enumerate(files): + if f in subset: + indices.append('%d' % i) + return '\0'.join(indices) + def stripdesc(desc): """strip trailing whitespace and leading and trailing empty lines""" return '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n') @@ -564,7 +572,8 @@ return l[3:] def add(self, manifest, files, desc, transaction, p1, p2, - user, date=None, extra=None, p1copies=None, p2copies=None): + 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 # into a str object and the cached UTF-8 string is thus lost. @@ -593,17 +602,23 @@ elif branch in (".", "null", "tip"): raise error.StorageError(_('the name \'%s\' is reserved') % branch) - if (p1copies is not None or p2copies is not None) and extra is None: + extrasentries = p1copies, p2copies, filesadded, filesremoved + if extra is None and any(x is not None for x in extrasentries): extra = {} if p1copies is not None: extra['p1copies'] = encodecopies(p1copies) if p2copies is not None: extra['p2copies'] = encodecopies(p2copies) + sortedfiles = sorted(files) + if filesadded is not None: + extra['filesadded'] = encodefileindices(sortedfiles, filesadded) + if filesremoved is not None: + extra['filesremoved'] = encodefileindices(sortedfiles, filesremoved) if extra: extra = encodeextra(extra) parseddate = "%s %s" % (parseddate, extra) - l = [hex(manifest), user, parseddate] + sorted(files) + ["", desc] + l = [hex(manifest), user, parseddate] + sortedfiles + ["", desc] text = "\n".join(l) return self.addrevision(text, transaction, len(self), p1, p2)