D6954: sidedatacopies: move various copies related function to the copies modules
Closed by commit rHG54e943b28101: sidedatacopies: move various copies related function to the copies modules (authored by marmoute). This revision was automatically updated to reflect the committed changes. This revision was not accepted when it landed; it landed in state "Needs Review". REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D6954?vs=17024=17028 CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D6954/new/ REVISION DETAIL https://phab.mercurial-scm.org/D6954 AFFECTED FILES mercurial/changelog.py mercurial/context.py mercurial/copies.py mercurial/scmutil.py CHANGE DETAILS diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -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 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, @@ -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 diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -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 diff --git a/mercurial/changelog.py b/mercurial/changelog.py --- a/mercurial/changelog.py +++ b/mercurial/changelog.py @@ -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,
D6954: sidedatacopies: move various copies related function to the copies modules
marmoute updated this revision to Diff 17024. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D6954?vs=17009=17024 CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D6954/new/ REVISION DETAIL https://phab.mercurial-scm.org/D6954 AFFECTED FILES mercurial/changelog.py mercurial/context.py mercurial/copies.py mercurial/scmutil.py CHANGE DETAILS diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -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 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, @@ -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 diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -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 diff --git a/mercurial/changelog.py b/mercurial/changelog.py --- a/mercurial/changelog.py +++ b/mercurial/changelog.py @@ -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
D6954: sidedatacopies: move various copies related function to the copies modules
marmoute updated this revision to Diff 17009. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D6954?vs=16955=17009 CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D6954/new/ REVISION DETAIL https://phab.mercurial-scm.org/D6954 AFFECTED FILES mercurial/changelog.py mercurial/context.py mercurial/copies.py mercurial/scmutil.py CHANGE DETAILS diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -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 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, @@ -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 diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -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 diff --git a/mercurial/changelog.py b/mercurial/changelog.py --- a/mercurial/changelog.py +++ b/mercurial/changelog.py @@ -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
D6954: sidedatacopies: move various copies related function to the copies modules
marmoute updated this revision to Diff 16955. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D6954?vs=16786=16955 CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D6954/new/ REVISION DETAIL https://phab.mercurial-scm.org/D6954 AFFECTED FILES mercurial/changelog.py mercurial/context.py mercurial/copies.py mercurial/scmutil.py CHANGE DETAILS diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -2218,23 +2218,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 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, @@ -854,6 +855,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 @@ -878,3 +899,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 diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -544,9 +544,9 @@ filesadded = [] elif source == b'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): @@ -561,9 +561,9 @@ filesremoved = [] elif source == b'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/changelog.py b/mercurial/changelog.py --- a/mercurial/changelog.py +++ b/mercurial/changelog.py @@ -16,6 +16,7 @@ from .thirdparty import attr from . import ( +copies, encoding, error,
D6954: sidedatacopies: move various copies related function to the copies modules
marmoute created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY 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. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D6954 AFFECTED FILES mercurial/changelog.py mercurial/context.py mercurial/copies.py mercurial/scmutil.py CHANGE DETAILS 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 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/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)