Mercurial > public > mercurial-scm > hg-stable
diff mercurial/changelog.py @ 42141:0e41f40b01cc
copies: add config option for writing copy metadata to file and/or changset
This introduces a config option that lets you choose to write copy
metadata to the changeset extras instead of to filelog. There's also
an option to write it to both places. I imagine that may possibly be
useful when transitioning an existing repo.
The copy metadata is stored as two fields in extras: one for copies
since p1 and one for copies since p2.
I may need to add more information later in order to make copy tracing
faster. Specifically, I'm thinking out recording which files were
added or removed so that copies._chaincopies() doesn't have to look at
the manifest for that. But that would just be an optimization and that
can be added once we know if it's necessary.
I have also considered saving space by using replacing the destination
file path by an index into the "files" list, but that can also be
changed later (but before the feature is ready to release).
Differential Revision: https://phab.mercurial-scm.org/D6183
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 27 Dec 2017 19:49:36 -0800 |
parents | caa067ee21dc |
children | 5382d8f8530b |
line wrap: on
line diff
--- a/mercurial/changelog.py Thu Apr 04 13:46:49 2019 +0200 +++ b/mercurial/changelog.py Wed Dec 27 19:49:36 2017 -0800 @@ -80,6 +80,13 @@ ] return "\0".join(items) +def encodecopies(copies): + items = [ + '%s\0%s' % (k, copies[k]) + for k in sorted(copies) + ] + return "\n".join(items) + def stripdesc(desc): """strip trailing whitespace and leading and trailing empty lines""" return '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n') @@ -533,7 +540,7 @@ return l[3:] def add(self, manifest, files, desc, transaction, p1, p2, - user, date=None, extra=None): + user, date=None, extra=None, p1copies=None, p2copies=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. @@ -562,6 +569,13 @@ elif branch in (".", "null", "tip"): raise error.StorageError(_('the name \'%s\' is reserved') % branch) + if (p1copies or p2copies) and extra is None: + extra = {} + if p1copies: + extra['p1copies'] = encodecopies(p1copies) + if p2copies: + extra['p2copies'] = encodecopies(p2copies) + if extra: extra = encodeextra(extra) parseddate = "%s %s" % (parseddate, extra)