Mercurial > hg
changeset 43147:54e943b28101
sidedatacopies: move various copies related function to the copies modules
We will need to access these logic form the copies module. So we move them from
their higher level module to the lower level `copies` module. We cannot use them
from their top level module as it would create cycles.
Differential Revision: https://phab.mercurial-scm.org/D6954
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sun, 06 Oct 2019 23:36:51 -0400 |
parents | 0171483b082f |
children | 843da18386d5 |
files | mercurial/changelog.py mercurial/context.py mercurial/copies.py mercurial/scmutil.py |
diffstat | 4 files changed, 87 insertions(+), 85 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/changelog.py Wed Oct 09 22:59:38 2019 +0200 +++ b/mercurial/changelog.py Sun Oct 06 23:36:51 2019 -0400 @@ -16,6 +16,7 @@ from .thirdparty import attr from . import ( + copies, encoding, error, pycompat, @@ -89,61 +90,6 @@ return b"\0".join(items) -def encodecopies(files, copies): - items = [] - for i, dst in enumerate(files): - if dst in copies: - items.append(b'%d\0%s' % (i, copies[dst])) - if len(items) != len(copies): - raise error.ProgrammingError( - b'some copy targets missing from file list' - ) - return b"\n".join(items) - - -def decodecopies(files, data): - try: - copies = {} - if not data: - return copies - for l in data.split(b'\n'): - strindex, src = l.split(b'\0') - i = int(strindex) - dst = files[i] - copies[dst] = src - return copies - except (ValueError, IndexError): - # Perhaps someone had chosen the same key name (e.g. "p1copies") and - # 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(b'%d' % i) - return b'\n'.join(indices) - - -def decodefileindices(files, data): - try: - subset = [] - if not data: - return subset - for strindex in data.split(b'\n'): - i = int(strindex) - if i < 0 or i >= len(files): - return None - subset.append(files[i]) - return subset - except (ValueError, IndexError): - # Perhaps someone had chosen the same key name (e.g. "added") and - # used different syntax for the value. - return None - - def stripdesc(desc): """strip trailing whitespace and leading and trailing empty lines""" return b'\n'.join([l.rstrip() for l in desc.splitlines()]).strip(b'\n') @@ -368,7 +314,7 @@ rawindices = self.extra.get(b'filesadded') if rawindices is None: return None - return decodefileindices(self.files, rawindices) + return copies.decodefileindices(self.files, rawindices) @property def filesremoved(self): @@ -378,7 +324,7 @@ rawindices = self.extra.get(b'filesremoved') if rawindices is None: return None - return decodefileindices(self.files, rawindices) + return copies.decodefileindices(self.files, rawindices) @property def p1copies(self): @@ -388,7 +334,7 @@ rawcopies = self.extra.get(b'p1copies') if rawcopies is None: return None - return decodecopies(self.files, rawcopies) + return copies.decodecopies(self.files, rawcopies) @property def p2copies(self): @@ -398,7 +344,7 @@ rawcopies = self.extra.get(b'p2copies') if rawcopies is None: return None - return decodecopies(self.files, rawcopies) + return copies.decodecopies(self.files, rawcopies) @property def description(self): @@ -711,13 +657,13 @@ ): extra.pop(name, None) if p1copies is not None: - p1copies = encodecopies(sortedfiles, p1copies) + p1copies = copies.encodecopies(sortedfiles, p1copies) if p2copies is not None: - p2copies = encodecopies(sortedfiles, p2copies) + p2copies = copies.encodecopies(sortedfiles, p2copies) if filesadded is not None: - filesadded = encodefileindices(sortedfiles, filesadded) + filesadded = copies.encodefileindices(sortedfiles, filesadded) if filesremoved is not None: - filesremoved = encodefileindices(sortedfiles, filesremoved) + filesremoved = copies.encodefileindices(sortedfiles, filesremoved) if self._copiesstorage == b'extra': extrasentries = p1copies, p2copies, filesadded, filesremoved if extra is None and any(x is not None for x in extrasentries):
--- a/mercurial/context.py Wed Oct 09 22:59:38 2019 +0200 +++ b/mercurial/context.py Sun Oct 06 23:36:51 2019 -0400 @@ -546,7 +546,7 @@ filesadded = None if filesadded is None: if compute_on_none: - filesadded = scmutil.computechangesetfilesadded(self) + filesadded = copies.computechangesetfilesadded(self) else: filesadded = [] return filesadded @@ -565,7 +565,7 @@ filesremoved = None if filesremoved is None: if compute_on_none: - filesremoved = scmutil.computechangesetfilesremoved(self) + filesremoved = copies.computechangesetfilesremoved(self) else: filesremoved = [] return filesremoved
--- a/mercurial/copies.py Wed Oct 09 22:59:38 2019 +0200 +++ b/mercurial/copies.py Sun Oct 06 23:36:51 2019 -0400 @@ -14,6 +14,7 @@ from .i18n import _ from . import ( + error, match as matchmod, node, pathutil, @@ -855,6 +856,26 @@ wctx[dst].markcopied(src) +def computechangesetfilesadded(ctx): + """return the list of files added in a changeset + """ + added = [] + for f in ctx.files(): + if not any(f in p for p in ctx.parents()): + added.append(f) + return added + + +def computechangesetfilesremoved(ctx): + """return the list of files removed in a changeset + """ + removed = [] + for f in ctx.files(): + if f not in ctx: + removed.append(f) + return removed + + def computechangesetcopies(ctx): """return the copies data for a changeset @@ -879,3 +900,58 @@ elif src in p2 and p2[src].filenode() == srcnode: p2copies[dst] = src return p1copies, p2copies + + +def encodecopies(files, copies): + items = [] + for i, dst in enumerate(files): + if dst in copies: + items.append(b'%d\0%s' % (i, copies[dst])) + if len(items) != len(copies): + raise error.ProgrammingError( + b'some copy targets missing from file list' + ) + return b"\n".join(items) + + +def decodecopies(files, data): + try: + copies = {} + if not data: + return copies + for l in data.split(b'\n'): + strindex, src = l.split(b'\0') + i = int(strindex) + dst = files[i] + copies[dst] = src + return copies + except (ValueError, IndexError): + # Perhaps someone had chosen the same key name (e.g. "p1copies") and + # 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(b'%d' % i) + return b'\n'.join(indices) + + +def decodefileindices(files, data): + try: + subset = [] + if not data: + return subset + for strindex in data.split(b'\n'): + i = int(strindex) + if i < 0 or i >= len(files): + return None + subset.append(files[i]) + return subset + except (ValueError, IndexError): + # Perhaps someone had chosen the same key name (e.g. "added") and + # used different syntax for the value. + return None
--- a/mercurial/scmutil.py Wed Oct 09 22:59:38 2019 +0200 +++ b/mercurial/scmutil.py Sun Oct 06 23:36:51 2019 -0400 @@ -2219,23 +2219,3 @@ mark, mark, ) - - -def computechangesetfilesadded(ctx): - """return the list of files added in a changeset - """ - added = [] - for f in ctx.files(): - if not any(f in p for p in ctx.parents()): - added.append(f) - return added - - -def computechangesetfilesremoved(ctx): - """return the list of files removed in a changeset - """ - removed = [] - for f in ctx.files(): - if f not in ctx: - removed.append(f) - return removed