Patchwork [13,of,13,sparse,V2] sparse: move active profiles function into core

login
register
mail settings
Submitter Gregory Szorc
Date July 6, 2017, 7:36 p.m.
Message ID <1da756ef8cfc837e0f04.1499369799@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/22041/
State Accepted
Headers show

Comments

Gregory Szorc - July 6, 2017, 7:36 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1499369164 25200
#      Thu Jul 06 12:26:04 2017 -0700
# Node ID 1da756ef8cfc837e0f04379909fd0018f0461a76
# Parent  fe3ea142b7ce68527f208a22acda8b83e7271366
sparse: move active profiles function into core

Also includes some light formatting changes.
via Mercurial-devel - July 6, 2017, 9:29 p.m.
On Thu, Jul 6, 2017 at 12:36 PM, Gregory Szorc <gregory.szorc@gmail.com> wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1499369164 25200
> #      Thu Jul 06 12:26:04 2017 -0700
> # Node ID 1da756ef8cfc837e0f04379909fd0018f0461a76
> # Parent  fe3ea142b7ce68527f208a22acda8b83e7271366
> sparse: move active profiles function into core

Queued, thanks!

Patch

diff --git a/hgext/sparse.py b/hgext/sparse.py
--- a/hgext/sparse.py
+++ b/hgext/sparse.py
@@ -213,7 +213,7 @@  def _setupupdates(ui):
             for file, flags, msg in actions:
                 dirstate.normal(file)
 
-        profiles = repo.getactiveprofiles()
+        profiles = sparse.activeprofiles(repo)
         changedprofiles = profiles & files
         # If an active profile changed during the update, refresh the checkout.
         # Don't do this during a branch merge, since all incoming changes should
@@ -517,17 +517,6 @@  def _wraprepo(ui, repo):
 
             return result
 
-        def getactiveprofiles(self):
-            revs = [self.changelog.rev(node) for node in
-                    self.dirstate.parents() if node != nullid]
-
-            activeprofiles = set()
-            for rev in revs:
-                _, _, profiles = sparse.patternsforrev(self, rev)
-                activeprofiles.update(profiles)
-
-            return activeprofiles
-
         def writesparseconfig(self, include, exclude, profiles):
             raw = '%s[include]\n%s\n[exclude]\n%s\n' % (
                 ''.join(['%%include %s\n' % p for p in sorted(profiles)]),
diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -8,6 +8,7 @@ 
 from __future__ import absolute_import
 
 from .i18n import _
+from .node import nullid
 from . import (
     error,
 )
@@ -115,3 +116,13 @@  def patternsforrev(repo, rev):
         includes.add('.hg*')
 
     return includes, excludes, profiles
+
+def activeprofiles(repo):
+    revs = [repo.changelog.rev(node) for node in
+            repo.dirstate.parents() if node != nullid]
+
+    profiles = set()
+    for rev in revs:
+        profiles.update(patternsforrev(repo, rev)[2])
+
+    return profiles