annotate hgext/sparse.py @ 33322:fa6c2c3064fd

sparse: move update action filtering into core This is a relatively straight port of the function. It is pretty large. So refactoring will be postponed to a subsequent commit.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 06 Jul 2017 16:17:35 -0700
parents d09e948dc303
children 252500520d60
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1 # sparse.py - allow sparse checkouts of the working directory
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
2 #
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
3 # Copyright 2014 Facebook, Inc.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
4 #
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
7
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
8 """allow sparse checkouts of the working directory (EXPERIMENTAL)
33290
cd1c275c9482 sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33289
diff changeset
9
cd1c275c9482 sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33289
diff changeset
10 (This extension is not yet protected by backwards compatibility
cd1c275c9482 sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33289
diff changeset
11 guarantees. Any aspect may break in future releases until this
cd1c275c9482 sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33289
diff changeset
12 notice is removed.)
cd1c275c9482 sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33289
diff changeset
13
cd1c275c9482 sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33289
diff changeset
14 This extension allows the working directory to only consist of a
cd1c275c9482 sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33289
diff changeset
15 subset of files for the revision. This allows specific files or
cd1c275c9482 sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33289
diff changeset
16 directories to be explicitly included or excluded. Many repository
cd1c275c9482 sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33289
diff changeset
17 operations have performance proportional to the number of files in
cd1c275c9482 sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33289
diff changeset
18 the working directory. So only realizing a subset of files in the
cd1c275c9482 sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33289
diff changeset
19 working directory can improve performance.
33294
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
20
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
21 Sparse Config Files
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
22 -------------------
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
23
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
24 The set of files that are part of a sparse checkout are defined by
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
25 a sparse config file. The file defines 3 things: includes (files to
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
26 include in the sparse checkout), excludes (files to exclude from the
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
27 sparse checkout), and profiles (links to other config files).
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
28
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
29 The file format is newline delimited. Empty lines and lines beginning
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
30 with ``#`` are ignored.
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
31
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
32 Lines beginning with ``%include `` denote another sparse config file
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
33 to include. e.g. ``%include tests.sparse``. The filename is relative
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
34 to the repository root.
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
35
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
36 The special lines ``[include]`` and ``[exclude]`` denote the section
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
37 for includes and excludes that follow, respectively. It is illegal to
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
38 have ``[include]`` after ``[exclude]``. If no sections are defined,
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
39 entries are assumed to be in the ``[include]`` section.
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
40
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
41 Non-special lines resemble file patterns to be added to either includes
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
42 or excludes. The syntax of these lines is documented by :hg:`help patterns`.
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
43 Patterns are interpreted as ``glob:`` by default and match against the
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
44 root of the repository.
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
45
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
46 Exclusion patterns take precedence over inclusion patterns. So even
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
47 if a file is explicitly included, an ``[exclude]`` entry can remove it.
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
48
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
49 For example, say you have a repository with 3 directories, ``frontend/``,
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
50 ``backend/``, and ``tools/``. ``frontend/`` and ``backend/`` correspond
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
51 to different projects and it is uncommon for someone working on one
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
52 to need the files for the other. But ``tools/`` contains files shared
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
53 between both projects. Your sparse config files may resemble::
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
54
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
55 # frontend.sparse
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
56 frontend/**
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
57 tools/**
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
58
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
59 # backend.sparse
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
60 backend/**
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
61 tools/**
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
62
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
63 Say the backend grows in size. Or there's a directory with thousands
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
64 of files you wish to exclude. You can modify the profile to exclude
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
65 certain files::
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
66
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
67 [include]
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
68 backend/**
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
69 tools/**
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
70
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
71 [exclude]
a5921ad2eb99 sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33293
diff changeset
72 tools/tests/**
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
73 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
74
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
75 from __future__ import absolute_import
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
76
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
77 from mercurial.i18n import _
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
78 from mercurial.node import nullid
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
79 from mercurial import (
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
80 cmdutil,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
81 commands,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
82 context,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
83 dirstate,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
84 error,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
85 extensions,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
86 hg,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
87 localrepo,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
88 match as matchmod,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
89 merge as mergemod,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
90 registrar,
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33296
diff changeset
91 sparse,
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
92 util,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
93 )
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
94
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
95 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
96 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
97 # be specifying the version(s) of Mercurial they are tested with, or
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
98 # leave the attribute unspecified.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
99 testedwith = 'ships-with-hg-core'
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
100
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
101 cmdtable = {}
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
102 command = registrar.command(cmdtable)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
103
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
104 def uisetup(ui):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
105 _setupupdates(ui)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
106 _setupcommit(ui)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
107
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
108 def extsetup(ui):
33299
41448fc51510 sparse: variable to track if sparse is enabled
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33298
diff changeset
109 sparse.enabled = True
41448fc51510 sparse: variable to track if sparse is enabled
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33298
diff changeset
110
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
111 _setupclone(ui)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
112 _setuplog(ui)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
113 _setupadd(ui)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
114 _setupdirstate(ui)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
115
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
116 def reposetup(ui, repo):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
117 if not util.safehasattr(repo, 'dirstate'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
118 return
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
119
33321
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
120 if 'dirstate' in repo._filecache:
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
121 repo.dirstate.repo = repo
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
122
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
123 def replacefilecache(cls, propname, replacement):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
124 """Replace a filecache property with a new class. This allows changing the
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
125 cache invalidation condition."""
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
126 origcls = cls
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
127 assert callable(replacement)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
128 while cls is not object:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
129 if propname in cls.__dict__:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
130 orig = cls.__dict__[propname]
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
131 setattr(cls, propname, replacement(orig))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
132 break
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
133 cls = cls.__bases__[0]
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
134
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
135 if cls is object:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
136 raise AttributeError(_("type '%s' has no property '%s'") % (origcls,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
137 propname))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
138
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
139 def _setupupdates(ui):
33322
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
140 extensions.wrapfunction(mergemod, 'calculateupdates',
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
141 sparse.calculateupdates)
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
142
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
143 def _setupcommit(ui):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
144 def _refreshoncommit(orig, self, node):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
145 """Refresh the checkout when commits touch .hgsparse
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
146 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
147 orig(self, node)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
148 repo = self._repo
33300
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
149
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
150 ctx = repo[node]
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
151 profiles = sparse.patternsforrev(repo, ctx.rev())[2]
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
152
33300
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
153 # profiles will only have data if sparse is enabled.
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
154 if set(profiles) & set(ctx.files()):
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
155 origstatus = repo.status()
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33319
diff changeset
156 origsparsematch = sparse.matcher(repo)
33300
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
157 _refresh(repo.ui, repo, origstatus, origsparsematch, True)
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
158
33321
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
159 sparse.prunetemporaryincludes(repo)
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
160
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
161 extensions.wrapfunction(context.committablectx, 'markcommitted',
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
162 _refreshoncommit)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
163
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
164 def _setuplog(ui):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
165 entry = commands.table['^log|history']
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
166 entry[1].append(('', 'sparse', None,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
167 "limit to changesets affecting the sparse checkout"))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
168
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
169 def _logrevs(orig, repo, opts):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
170 revs = orig(repo, opts)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
171 if opts.get('sparse'):
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33319
diff changeset
172 sparsematch = sparse.matcher(repo)
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
173 def ctxmatch(rev):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
174 ctx = repo[rev]
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
175 return any(f for f in ctx.files() if sparsematch(f))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
176 revs = revs.filter(ctxmatch)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
177 return revs
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
178 extensions.wrapfunction(cmdutil, '_logrevs', _logrevs)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
179
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
180 def _clonesparsecmd(orig, ui, repo, *args, **opts):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
181 include_pat = opts.get('include')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
182 exclude_pat = opts.get('exclude')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
183 enableprofile_pat = opts.get('enable_profile')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
184 include = exclude = enableprofile = False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
185 if include_pat:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
186 pat = include_pat
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
187 include = True
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
188 if exclude_pat:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
189 pat = exclude_pat
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
190 exclude = True
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
191 if enableprofile_pat:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
192 pat = enableprofile_pat
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
193 enableprofile = True
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
194 if sum([include, exclude, enableprofile]) > 1:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
195 raise error.Abort(_("too many flags specified."))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
196 if include or exclude or enableprofile:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
197 def clonesparse(orig, self, node, overwrite, *args, **kwargs):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
198 _config(self.ui, self.unfiltered(), pat, {}, include=include,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
199 exclude=exclude, enableprofile=enableprofile)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
200 return orig(self, node, overwrite, *args, **kwargs)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
201 extensions.wrapfunction(hg, 'updaterepo', clonesparse)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
202 return orig(ui, repo, *args, **opts)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
203
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
204 def _setupclone(ui):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
205 entry = commands.table['^clone']
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
206 entry[1].append(('', 'enable-profile', [],
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
207 'enable a sparse profile'))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
208 entry[1].append(('', 'include', [],
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
209 'include sparse pattern'))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
210 entry[1].append(('', 'exclude', [],
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
211 'exclude sparse pattern'))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
212 extensions.wrapcommand(commands.table, 'clone', _clonesparsecmd)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
213
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
214 def _setupadd(ui):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
215 entry = commands.table['^add']
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
216 entry[1].append(('s', 'sparse', None,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
217 'also include directories of added files in sparse config'))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
218
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
219 def _add(orig, ui, repo, *pats, **opts):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
220 if opts.get('sparse'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
221 dirs = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
222 for pat in pats:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
223 dirname, basename = util.split(pat)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
224 dirs.add(dirname)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
225 _config(ui, repo, list(dirs), opts, include=True)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
226 return orig(ui, repo, *pats, **opts)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
227
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
228 extensions.wrapcommand(commands.table, 'add', _add)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
229
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
230 def _setupdirstate(ui):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
231 """Modify the dirstate to prevent stat'ing excluded files,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
232 and to prevent modifications to files outside the checkout.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
233 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
234
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
235 def _dirstate(orig, repo):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
236 dirstate = orig(repo)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
237 dirstate.repo = repo
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
238 return dirstate
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
239 extensions.wrapfunction(
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
240 localrepo.localrepository.dirstate, 'func', _dirstate)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
241
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
242 # The atrocity below is needed to wrap dirstate._ignore. It is a cached
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
243 # property, which means normal function wrapping doesn't work.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
244 class ignorewrapper(object):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
245 def __init__(self, orig):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
246 self.orig = orig
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
247 self.origignore = None
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
248 self.func = None
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
249 self.sparsematch = None
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
250
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
251 def __get__(self, obj, type=None):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
252 repo = obj.repo
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
253 origignore = self.orig.__get__(obj)
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33319
diff changeset
254
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33319
diff changeset
255 sparsematch = sparse.matcher(repo)
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33319
diff changeset
256 if sparsematch.always():
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
257 return origignore
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
258
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
259 if self.sparsematch != sparsematch or self.origignore != origignore:
33319
3c84591e7321 match: move matchers from sparse into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33317
diff changeset
260 self.func = matchmod.unionmatcher([
3c84591e7321 match: move matchers from sparse into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33317
diff changeset
261 origignore, matchmod.negatematcher(sparsematch)])
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
262 self.sparsematch = sparsematch
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
263 self.origignore = origignore
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
264 return self.func
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
265
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
266 def __set__(self, obj, value):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
267 return self.orig.__set__(obj, value)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
268
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
269 def __delete__(self, obj):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
270 return self.orig.__delete__(obj)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
271
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
272 replacefilecache(dirstate.dirstate, '_ignore', ignorewrapper)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
273
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
274 # dirstate.rebuild should not add non-matching files
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
275 def _rebuild(orig, self, parent, allfiles, changedfiles=None):
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33319
diff changeset
276 matcher = sparse.matcher(self.repo)
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33319
diff changeset
277 if not matcher.always():
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
278 allfiles = allfiles.matches(matcher)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
279 if changedfiles:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
280 changedfiles = [f for f in changedfiles if matcher(f)]
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
281
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
282 if changedfiles is not None:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
283 # In _rebuild, these files will be deleted from the dirstate
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
284 # when they are not found to be in allfiles
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
285 dirstatefilestoremove = set(f for f in self if not matcher(f))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
286 changedfiles = dirstatefilestoremove.union(changedfiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
287
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
288 return orig(self, parent, allfiles, changedfiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
289 extensions.wrapfunction(dirstate.dirstate, 'rebuild', _rebuild)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
290
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
291 # Prevent adding files that are outside the sparse checkout
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
292 editfuncs = ['normal', 'add', 'normallookup', 'copy', 'remove', 'merge']
33293
c9cbf4de27ba sparse: rename command to debugsparse
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33292
diff changeset
293 hint = _('include file with `hg debugsparse --include <pattern>` or use ' +
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
294 '`hg add -s <file>` to include file directory while adding')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
295 for func in editfuncs:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
296 def _wrapper(orig, self, *args):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
297 repo = self.repo
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33319
diff changeset
298 sparsematch = sparse.matcher(repo)
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33319
diff changeset
299 if not sparsematch.always():
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
300 dirstate = repo.dirstate
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
301 for f in args:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
302 if (f is not None and not sparsematch(f) and
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
303 f not in dirstate):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
304 raise error.Abort(_("cannot add '%s' - it is outside "
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
305 "the sparse checkout") % f,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
306 hint=hint)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
307 return orig(self, *args)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
308 extensions.wrapfunction(dirstate.dirstate, func, _wrapper)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
309
33293
c9cbf4de27ba sparse: rename command to debugsparse
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33292
diff changeset
310 @command('^debugsparse', [
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
311 ('I', 'include', False, _('include files in the sparse checkout')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
312 ('X', 'exclude', False, _('exclude files in the sparse checkout')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
313 ('d', 'delete', False, _('delete an include/exclude rule')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
314 ('f', 'force', False, _('allow changing rules even with pending changes')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
315 ('', 'enable-profile', False, _('enables the specified profile')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
316 ('', 'disable-profile', False, _('disables the specified profile')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
317 ('', 'import-rules', False, _('imports rules from a file')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
318 ('', 'clear-rules', False, _('clears local include/exclude rules')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
319 ('', 'refresh', False, _('updates the working after sparseness changes')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
320 ('', 'reset', False, _('makes the repo full again')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
321 ] + commands.templateopts,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
322 _('[--OPTION] PATTERN...'))
33293
c9cbf4de27ba sparse: rename command to debugsparse
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33292
diff changeset
323 def debugsparse(ui, repo, *pats, **opts):
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
324 """make the current checkout sparse, or edit the existing checkout
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
325
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
326 The sparse command is used to make the current checkout sparse.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
327 This means files that don't meet the sparse condition will not be
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
328 written to disk, or show up in any working copy operations. It does
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
329 not affect files in history in any way.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
330
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
331 Passing no arguments prints the currently applied sparse rules.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
332
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
333 --include and --exclude are used to add and remove files from the sparse
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
334 checkout. The effects of adding an include or exclude rule are applied
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
335 immediately. If applying the new rule would cause a file with pending
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
336 changes to be added or removed, the command will fail. Pass --force to
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
337 force a rule change even with pending changes (the changes on disk will
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
338 be preserved).
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
339
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
340 --delete removes an existing include/exclude rule. The effects are
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
341 immediate.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
342
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
343 --refresh refreshes the files on disk based on the sparse rules. This is
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
344 only necessary if .hg/sparse was changed by hand.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
345
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
346 --enable-profile and --disable-profile accept a path to a .hgsparse file.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
347 This allows defining sparse checkouts and tracking them inside the
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
348 repository. This is useful for defining commonly used sparse checkouts for
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
349 many people to use. As the profile definition changes over time, the sparse
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
350 checkout will automatically be updated appropriately, depending on which
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
351 changeset is checked out. Changes to .hgsparse are not applied until they
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
352 have been committed.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
353
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
354 --import-rules accepts a path to a file containing rules in the .hgsparse
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
355 format, allowing you to add --include, --exclude and --enable-profile rules
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
356 in bulk. Like the --include, --exclude and --enable-profile switches, the
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
357 changes are applied immediately.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
358
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
359 --clear-rules removes all local include and exclude rules, while leaving
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
360 any enabled profiles in place.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
361
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
362 Returns 0 if editing the sparse checkout succeeds.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
363 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
364 include = opts.get('include')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
365 exclude = opts.get('exclude')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
366 force = opts.get('force')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
367 enableprofile = opts.get('enable_profile')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
368 disableprofile = opts.get('disable_profile')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
369 importrules = opts.get('import_rules')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
370 clearrules = opts.get('clear_rules')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
371 delete = opts.get('delete')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
372 refresh = opts.get('refresh')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
373 reset = opts.get('reset')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
374 count = sum([include, exclude, enableprofile, disableprofile, delete,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
375 importrules, refresh, clearrules, reset])
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
376 if count > 1:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
377 raise error.Abort(_("too many flags specified"))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
378
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
379 if count == 0:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
380 if repo.vfs.exists('sparse'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
381 ui.status(repo.vfs.read("sparse") + "\n")
33304
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
382 temporaryincludes = sparse.readtemporaryincludes(repo)
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
383 if temporaryincludes:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
384 ui.status(_("Temporarily Included Files (for merge/rebase):\n"))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
385 ui.status(("\n".join(temporaryincludes) + "\n"))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
386 else:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
387 ui.status(_('repo is not sparse\n'))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
388 return
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
389
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
390 if include or exclude or delete or reset or enableprofile or disableprofile:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
391 _config(ui, repo, pats, opts, include=include, exclude=exclude,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
392 reset=reset, delete=delete, enableprofile=enableprofile,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
393 disableprofile=disableprofile, force=force)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
394
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
395 if importrules:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
396 _import(ui, repo, pats, opts, force=force)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
397
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
398 if clearrules:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
399 _clear(ui, repo, pats, force=force)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
400
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
401 if refresh:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
402 try:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
403 wlock = repo.wlock()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
404 fcounts = map(
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
405 len,
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33319
diff changeset
406 _refresh(ui, repo, repo.status(), sparse.matcher(repo), force))
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
407 _verbose_output(ui, opts, 0, 0, 0, *fcounts)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
408 finally:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
409 wlock.release()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
410
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
411 def _config(ui, repo, pats, opts, include=False, exclude=False, reset=False,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
412 delete=False, enableprofile=False, disableprofile=False,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
413 force=False):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
414 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
415 Perform a sparse config update. Only one of the kwargs may be specified.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
416 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
417 wlock = repo.wlock()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
418 try:
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33319
diff changeset
419 oldsparsematch = sparse.matcher(repo)
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
420
33296
ee616196227c sparse: use vfs.tryread()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33295
diff changeset
421 raw = repo.vfs.tryread('sparse')
ee616196227c sparse: use vfs.tryread()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33295
diff changeset
422 if raw:
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
423 oldinclude, oldexclude, oldprofiles = map(
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33296
diff changeset
424 set, sparse.parseconfig(ui, raw))
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
425 else:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
426 oldinclude = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
427 oldexclude = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
428 oldprofiles = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
429
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
430 try:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
431 if reset:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
432 newinclude = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
433 newexclude = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
434 newprofiles = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
435 else:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
436 newinclude = set(oldinclude)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
437 newexclude = set(oldexclude)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
438 newprofiles = set(oldprofiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
439
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
440 oldstatus = repo.status()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
441
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
442 if any(pat.startswith('/') for pat in pats):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
443 ui.warn(_('warning: paths cannot start with /, ignoring: %s\n')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
444 % ([pat for pat in pats if pat.startswith('/')]))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
445 elif include:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
446 newinclude.update(pats)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
447 elif exclude:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
448 newexclude.update(pats)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
449 elif enableprofile:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
450 newprofiles.update(pats)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
451 elif disableprofile:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
452 newprofiles.difference_update(pats)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
453 elif delete:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
454 newinclude.difference_update(pats)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
455 newexclude.difference_update(pats)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
456
33303
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
457 sparse.writeconfig(repo, newinclude, newexclude, newprofiles)
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
458
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
459 fcounts = map(
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
460 len, _refresh(ui, repo, oldstatus, oldsparsematch, force))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
461
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
462 profilecount = (len(newprofiles - oldprofiles) -
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
463 len(oldprofiles - newprofiles))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
464 includecount = (len(newinclude - oldinclude) -
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
465 len(oldinclude - newinclude))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
466 excludecount = (len(newexclude - oldexclude) -
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
467 len(oldexclude - newexclude))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
468 _verbose_output(
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
469 ui, opts, profilecount, includecount, excludecount, *fcounts)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
470 except Exception:
33303
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
471 sparse.writeconfig(repo, oldinclude, oldexclude, oldprofiles)
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
472 raise
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
473 finally:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
474 wlock.release()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
475
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
476 def _import(ui, repo, files, opts, force=False):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
477 with repo.wlock():
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
478 # load union of current active profile
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
479 revs = [repo.changelog.rev(node) for node in
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
480 repo.dirstate.parents() if node != nullid]
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
481
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
482 # read current configuration
33296
ee616196227c sparse: use vfs.tryread()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33295
diff changeset
483 raw = repo.vfs.tryread('sparse')
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33296
diff changeset
484 oincludes, oexcludes, oprofiles = sparse.parseconfig(ui, raw)
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
485 includes, excludes, profiles = map(
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
486 set, (oincludes, oexcludes, oprofiles))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
487
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
488 # all active rules
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
489 aincludes, aexcludes, aprofiles = set(), set(), set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
490 for rev in revs:
33300
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
491 rincludes, rexcludes, rprofiles = sparse.patternsforrev(repo, rev)
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
492 aincludes.update(rincludes)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
493 aexcludes.update(rexcludes)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
494 aprofiles.update(rprofiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
495
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
496 # import rules on top; only take in rules that are not yet
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
497 # part of the active rules.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
498 changed = False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
499 for file in files:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
500 with util.posixfile(util.expandpath(file)) as importfile:
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33296
diff changeset
501 iincludes, iexcludes, iprofiles = sparse.parseconfig(
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33296
diff changeset
502 ui, importfile.read())
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
503 oldsize = len(includes) + len(excludes) + len(profiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
504 includes.update(iincludes - aincludes)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
505 excludes.update(iexcludes - aexcludes)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
506 profiles.update(set(iprofiles) - aprofiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
507 if len(includes) + len(excludes) + len(profiles) > oldsize:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
508 changed = True
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
509
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
510 profilecount = includecount = excludecount = 0
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
511 fcounts = (0, 0, 0)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
512
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
513 if changed:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
514 profilecount = len(profiles - aprofiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
515 includecount = len(includes - aincludes)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
516 excludecount = len(excludes - aexcludes)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
517
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
518 oldstatus = repo.status()
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33319
diff changeset
519 oldsparsematch = sparse.matcher(repo)
33303
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
520 sparse.writeconfig(repo, includes, excludes, profiles)
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
521
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
522 try:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
523 fcounts = map(
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
524 len, _refresh(ui, repo, oldstatus, oldsparsematch, force))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
525 except Exception:
33303
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
526 sparse.writeconfig(repo, oincludes, oexcludes, oprofiles)
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
527 raise
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
528
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
529 _verbose_output(ui, opts, profilecount, includecount, excludecount,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
530 *fcounts)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
531
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
532 def _clear(ui, repo, files, force=False):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
533 with repo.wlock():
33296
ee616196227c sparse: use vfs.tryread()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33295
diff changeset
534 raw = repo.vfs.tryread('sparse')
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33296
diff changeset
535 includes, excludes, profiles = sparse.parseconfig(ui, raw)
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
536
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
537 if includes or excludes:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
538 oldstatus = repo.status()
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33319
diff changeset
539 oldsparsematch = sparse.matcher(repo)
33303
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
540 sparse.writeconfig(repo, set(), set(), profiles)
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
541 _refresh(ui, repo, oldstatus, oldsparsematch, force)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
542
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
543 def _refresh(ui, repo, origstatus, origsparsematch, force):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
544 """Refreshes which files are on disk by comparing the old status and
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
545 sparsematch with the new sparsematch.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
546
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
547 Will raise an exception if a file with pending changes is being excluded
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
548 or included (unless force=True).
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
549 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
550 modified, added, removed, deleted, unknown, ignored, clean = origstatus
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
551
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
552 # Verify there are no pending changes
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
553 pending = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
554 pending.update(modified)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
555 pending.update(added)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
556 pending.update(removed)
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33319
diff changeset
557 sparsematch = sparse.matcher(repo)
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
558 abort = False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
559 for file in pending:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
560 if not sparsematch(file):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
561 ui.warn(_("pending changes to '%s'\n") % file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
562 abort = not force
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
563 if abort:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
564 raise error.Abort(_("could not update sparseness due to " +
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
565 "pending changes"))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
566
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
567 # Calculate actions
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
568 dirstate = repo.dirstate
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
569 ctx = repo['.']
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
570 added = []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
571 lookup = []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
572 dropped = []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
573 mf = ctx.manifest()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
574 files = set(mf)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
575
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
576 actions = {}
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
577
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
578 for file in files:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
579 old = origsparsematch(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
580 new = sparsematch(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
581 # Add files that are newly included, or that don't exist in
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
582 # the dirstate yet.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
583 if (new and not old) or (old and new and not file in dirstate):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
584 fl = mf.flags(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
585 if repo.wvfs.exists(file):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
586 actions[file] = ('e', (fl,), '')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
587 lookup.append(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
588 else:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
589 actions[file] = ('g', (fl, False), '')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
590 added.append(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
591 # Drop files that are newly excluded, or that still exist in
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
592 # the dirstate.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
593 elif (old and not new) or (not old and not new and file in dirstate):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
594 dropped.append(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
595 if file not in pending:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
596 actions[file] = ('r', [], '')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
597
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
598 # Verify there are no pending changes in newly included files
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
599 abort = False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
600 for file in lookup:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
601 ui.warn(_("pending changes to '%s'\n") % file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
602 abort = not force
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
603 if abort:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
604 raise error.Abort(_("cannot change sparseness due to " +
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
605 "pending changes (delete the files or use --force " +
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
606 "to bring them back dirty)"))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
607
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
608 # Check for files that were only in the dirstate.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
609 for file, state in dirstate.iteritems():
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
610 if not file in files:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
611 old = origsparsematch(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
612 new = sparsematch(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
613 if old and not new:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
614 dropped.append(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
615
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
616 # Apply changes to disk
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
617 typeactions = dict((m, []) for m in 'a f g am cd dc r dm dg m e k'.split())
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
618 for f, (m, args, msg) in actions.iteritems():
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
619 if m not in typeactions:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
620 typeactions[m] = []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
621 typeactions[m].append((f, args, msg))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
622 mergemod.applyupdates(repo, typeactions, repo[None], repo['.'], False)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
623
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
624 # Fix dirstate
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
625 for file in added:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
626 dirstate.normal(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
627
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
628 for file in dropped:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
629 dirstate.drop(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
630
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
631 for file in lookup:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
632 # File exists on disk, and we're bringing it back in an unknown state.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
633 dirstate.normallookup(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
634
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
635 return added, dropped, lookup
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
636
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
637 def _verbose_output(ui, opts, profilecount, includecount, excludecount, added,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
638 dropped, lookup):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
639 """Produce --verbose and templatable output
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
640
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
641 This specifically enables -Tjson, providing machine-readable stats on how
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
642 the sparse profile changed.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
643
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
644 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
645 with ui.formatter('sparse', opts) as fm:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
646 fm.startitem()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
647 fm.condwrite(ui.verbose, 'profiles_added', 'Profile # change: %d\n',
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
648 profilecount)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
649 fm.condwrite(ui.verbose, 'include_rules_added',
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
650 'Include rule # change: %d\n', includecount)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
651 fm.condwrite(ui.verbose, 'exclude_rules_added',
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
652 'Exclude rule # change: %d\n', excludecount)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
653 # In 'plain' verbose mode, mergemod.applyupdates already outputs what
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
654 # files are added or removed outside of the templating formatter
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
655 # framework. No point in repeating ourselves in that case.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
656 if not fm.isplain():
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
657 fm.condwrite(ui.verbose, 'files_added', 'Files added: %d\n',
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
658 added)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
659 fm.condwrite(ui.verbose, 'files_dropped', 'Files dropped: %d\n',
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
660 dropped)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
661 fm.condwrite(ui.verbose, 'files_conflicting',
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
662 'Files conflicting: %d\n', lookup)