diff --git a/mercurial/changelog.py b/mercurial/changelog.py --- a/mercurial/changelog.py +++ b/mercurial/changelog.py @@ -18,6 +18,7 @@ ) from . import ( + copies, encoding, error, pycompat, @@ -84,55 +85,6 @@ ] return "\0".join(items) -def encodecopies(files, copies): - items = [] - for i, dst in enumerate(files): - if dst in copies: - items.append('%d\0%s' % (i, copies[dst])) - if len(items) != len(copies): - raise error.ProgrammingError('some copy targets missing from file list') - return "\n".join(items) - -def decodecopies(files, data): - try: - copies = {} - if not data: - return copies - for l in data.split('\n'): - strindex, src = l.split('\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('%d' % i) - return '\n'.join(indices) - -def decodefileindices(files, data): - try: - subset = [] - if not data: - return subset - for strindex in data.split('\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 '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n') @@ -344,7 +296,7 @@ else: rawindices = self.extra.get('filesadded') if rawindices is not None: - rawindices = decodefileindices(self.files, rawindices) + rawindices = copies.decodefileindices(self.files, rawindices) return rawindices @property @@ -354,7 +306,7 @@ else: rawindices = self.extra.get('filesremoved') if rawindices is not None: - rawindices = decodefileindices(self.files, rawindices) + rawindices = copies.decodefileindices(self.files, rawindices) return rawindices @property @@ -364,7 +316,7 @@ else: rawcopies = self.extra.get('p1copies') if rawcopies is not None: - rawcopies = decodecopies(self.files, rawcopies) + rawcopies = copies.decodecopies(self.files, rawcopies) return rawcopies @property @@ -374,7 +326,7 @@ else: rawcopies = self.extra.get('p2copies') if rawcopies is not None: - rawcopies = decodecopies(self.files, rawcopies) + rawcopies = copies.decodecopies(self.files, rawcopies) return rawcopies @property @@ -667,13 +619,13 @@ for name in ('p1copies', 'p2copies', 'filesadded', 'filesremoved'): 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 == 'extra': extrasentries = p1copies, p2copies, filesadded, filesremoved if extra is None and any(x is not None for x in extrasentries): diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -466,9 +466,9 @@ filesadded = [] elif source == 'compatibility': if filesadded is None: - filesadded = scmutil.computechangesetfilesadded(self) + filesadded = copies.computechangesetfilesadded(self) else: - filesadded = scmutil.computechangesetfilesadded(self) + filesadded = copies.computechangesetfilesadded(self) return filesadded def filesremoved(self): @@ -483,9 +483,9 @@ filesremoved = [] elif source == 'compatibility': if filesremoved is None: - filesremoved = scmutil.computechangesetfilesremoved(self) + filesremoved = copies.computechangesetfilesremoved(self) else: - filesremoved = scmutil.computechangesetfilesremoved(self) + filesremoved = copies.computechangesetfilesremoved(self) return filesremoved @propertycache diff --git a/mercurial/copies.py b/mercurial/copies.py --- a/mercurial/copies.py +++ b/mercurial/copies.py @@ -14,6 +14,7 @@ from .i18n import _ from . import ( + error, match as matchmod, node, pathutil, @@ -813,6 +814,25 @@ if dst in wctx: 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 @@ -837,3 +857,52 @@ 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('%d\0%s' % (i, copies[dst])) + if len(items) != len(copies): + raise error.ProgrammingError('some copy targets missing from file list') + return "\n".join(items) + +def decodecopies(files, data): + try: + copies = {} + if not data: + return copies + for l in data.split('\n'): + strindex, src = l.split('\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('%d' % i) + return '\n'.join(indices) + +def decodefileindices(files, data): + try: + subset = [] + if not data: + return subset + for strindex in data.split('\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 diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -2003,21 +2003,3 @@ "ancestors(head() and not bookmark(%s)) - " "ancestors(bookmark() and not bookmark(%s))", mark, 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