# HG changeset patch # User Pierre-Yves David # Date 2019-06-12 12:42:22 # Node ID 87c4cd89b539880fc157e319a5fc690011e31c49 # Parent 3cffc7bbec26415308a935cf8076b0ea5c8e4f8f changectx: extract explicit computechangesetfilesadded method from context Right now, the logic around changeset centric added files data are buried into the "changectx" code. We extract this code in a dedicated method (in the scmutil module) for clarity. This clarity will help to explicitly compute and caches these data in the future. diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -459,12 +459,7 @@ class changectx(basectx): (source == 'compatibility' and self._changeset.filesadded is not None)): return self._changeset.filesadded or [] - - added = [] - for f in self.files(): - if not any(f in p for p in self.parents()): - added.append(f) - return added + return scmutil.computechangesetfilesadded(self) def filesremoved(self): source = self._repo.ui.config('experimental', 'copies.read-from') if (source == 'changeset-only' or diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -1984,3 +1984,12 @@ def bookmarkrevs(repo, mark): "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