Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
45248:4cde23ba076e | 45249:b3040b6739ce |
---|---|
66 with repo.lock(), repo.transaction(b"commit") as tr: | 66 with repo.lock(), repo.transaction(b"commit") as tr: |
67 r = _prepare_files(tr, ctx, error=error, origctx=origctx) | 67 r = _prepare_files(tr, ctx, error=error, origctx=origctx) |
68 mn, files, p1copies, p2copies, filesadded, filesremoved = r | 68 mn, files, p1copies, p2copies, filesadded, filesremoved = r |
69 | 69 |
70 extra = ctx.extra().copy() | 70 extra = ctx.extra().copy() |
71 | |
72 files = sorted(files) | |
73 if extra is not None: | |
74 for name in ( | |
75 b'p1copies', | |
76 b'p2copies', | |
77 b'filesadded', | |
78 b'filesremoved', | |
79 ): | |
80 extra.pop(name, None) | |
81 if repo.changelog._copiesstorage == b'extra': | |
82 extra = _extra_with_copies( | |
83 repo, extra, files, p1copies, p2copies, filesadded, filesremoved | |
84 ) | |
71 | 85 |
72 # update changelog | 86 # update changelog |
73 repo.ui.note(_(b"committing changelog\n")) | 87 repo.ui.note(_(b"committing changelog\n")) |
74 repo.changelog.delayupdate(tr) | 88 repo.changelog.delayupdate(tr) |
75 n = repo.changelog.add( | 89 n = repo.changelog.add( |
405 b'reusing manifest from p1 (listed files ' b'actually unchanged)\n' | 419 b'reusing manifest from p1 (listed files ' b'actually unchanged)\n' |
406 ) | 420 ) |
407 mn = p1.manifestnode() | 421 mn = p1.manifestnode() |
408 | 422 |
409 return mn | 423 return mn |
424 | |
425 | |
426 def _extra_with_copies( | |
427 repo, extra, files, p1copies, p2copies, filesadded, filesremoved | |
428 ): | |
429 """encode copy information into a `extra` dictionnary""" | |
430 extrasentries = p1copies, p2copies, filesadded, filesremoved | |
431 if extra is None and any(x is not None for x in extrasentries): | |
432 extra = {} | |
433 if p1copies is not None: | |
434 p1copies = metadata.encodecopies(files, p1copies) | |
435 extra[b'p1copies'] = p1copies | |
436 if p2copies is not None: | |
437 p2copies = metadata.encodecopies(files, p2copies) | |
438 extra[b'p2copies'] = p2copies | |
439 if filesadded is not None: | |
440 filesadded = metadata.encodefileindices(files, filesadded) | |
441 extra[b'filesadded'] = filesadded | |
442 if filesremoved is not None: | |
443 filesremoved = metadata.encodefileindices(files, filesremoved) | |
444 extra[b'filesremoved'] = filesremoved | |
445 return extra |