Mercurial > hg
diff mercurial/commit.py @ 45249:b3040b6739ce
commitctx: extract copy information encoding into extra into commit.py
The encoding of copy information into extra has multiple subcases and become
quite complicated (eg: empty list can be explicitly or implicitly stored for
example). In addition, it is niche experimental feature since as it affect the
hash, it is only suitable for user who don't mercurial for storage server side
(ie: Google).
Having this complexity part of the changelog will get in the way of further
cleanup. We could have to either move more of that logic into the changelog or
to move or extract more of the logic at the higher level. We take the second
approach and start gather logic in dedicated function in commit.py.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sat, 25 Jul 2020 15:13:25 +0200 |
parents | 4cde23ba076e |
children | efe8a67793b6 |
line wrap: on
line diff
--- a/mercurial/commit.py Sat Jul 25 14:59:55 2020 +0200 +++ b/mercurial/commit.py Sat Jul 25 15:13:25 2020 +0200 @@ -69,6 +69,20 @@ extra = ctx.extra().copy() + files = sorted(files) + if extra is not None: + for name in ( + b'p1copies', + b'p2copies', + b'filesadded', + b'filesremoved', + ): + extra.pop(name, None) + if repo.changelog._copiesstorage == b'extra': + extra = _extra_with_copies( + repo, extra, files, p1copies, p2copies, filesadded, filesremoved + ) + # update changelog repo.ui.note(_(b"committing changelog\n")) repo.changelog.delayupdate(tr) @@ -407,3 +421,25 @@ mn = p1.manifestnode() return mn + + +def _extra_with_copies( + repo, extra, files, p1copies, p2copies, filesadded, filesremoved +): + """encode copy information into a `extra` dictionnary""" + 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: + p1copies = metadata.encodecopies(files, p1copies) + extra[b'p1copies'] = p1copies + if p2copies is not None: + p2copies = metadata.encodecopies(files, p2copies) + extra[b'p2copies'] = p2copies + if filesadded is not None: + filesadded = metadata.encodefileindices(files, filesadded) + extra[b'filesadded'] = filesadded + if filesremoved is not None: + filesremoved = metadata.encodefileindices(files, filesremoved) + extra[b'filesremoved'] = filesremoved + return extra