Mercurial > hg
annotate hgext/sparse.py @ 33649:377e8ddaebef stable
pathauditor: disable cache of audited paths by default (issue5628)
The initial attempt was to discard cache when appropriate, but it appears
to be error prone. We had to carefully inspect all places where audit() is
called e.g. without actually updating filesystem, before removing files and
directories, etc.
So, this patch disables the cache of audited paths by default, and enables
it only for the following cases:
- short-lived auditor objects
- repo.vfs, repo.svfs, and repo.cachevfs, which are managed directories
and considered sort of append-only (a file/directory would never be
replaced with a symlink)
There would be more cacheable vfs objects (e.g. mq.queue.opener), but I
decided not to inspect all of them in this patch. We can make them cached
later.
Benchmark result:
- using old clone of http://selenic.com/repo/linux-2.6/ (38319 files)
- on tmpfs
- run HGRCPATH=/dev/null hg up -q --time tip && hg up -q null
- try 4 times and take the last three results
original:
real 7.480 secs (user 1.140+22.760 sys 0.150+1.690)
real 8.010 secs (user 1.070+22.280 sys 0.170+2.120)
real 7.470 secs (user 1.120+22.390 sys 0.120+1.910)
clearcache (the other series):
real 7.680 secs (user 1.120+23.420 sys 0.140+1.970)
real 7.670 secs (user 1.110+23.620 sys 0.130+1.810)
real 7.740 secs (user 1.090+23.510 sys 0.160+1.940)
enable cache only for vfs and svfs (this series):
real 8.730 secs (user 1.500+25.190 sys 0.260+2.260)
real 8.750 secs (user 1.490+25.170 sys 0.250+2.340)
real 9.010 secs (user 1.680+25.340 sys 0.280+2.540)
remove cache function at all (for reference):
real 9.620 secs (user 1.440+27.120 sys 0.250+2.980)
real 9.420 secs (user 1.400+26.940 sys 0.320+3.130)
real 9.760 secs (user 1.530+27.270 sys 0.250+2.970)
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 26 Jul 2017 22:10:15 +0900 |
parents | 1d1779734c99 |
children | e1c56486d1aa |
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 |
33551
1d1779734c99
sparse: require [section] in sparse config files (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33496
diff
changeset
|
38 have ``[include]`` after ``[exclude]``. |
33294
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
39 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
40 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
|
41 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
|
42 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
|
43 root of the repository. |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
44 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
45 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
|
46 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
|
47 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
48 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
|
49 ``backend/``, and ``tools/``. ``frontend/`` and ``backend/`` correspond |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
50 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
|
51 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
|
52 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
|
53 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
54 # frontend.sparse |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
55 frontend/** |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
56 tools/** |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
57 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
58 # backend.sparse |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
59 backend/** |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
60 tools/** |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
61 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
62 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
|
63 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
|
64 certain files:: |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
65 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
66 [include] |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
67 backend/** |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
68 tools/** |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
69 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
70 [exclude] |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
71 tools/tests/** |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
72 """ |
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 from __future__ import absolute_import |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
75 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
76 from mercurial.i18n import _ |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
77 from mercurial import ( |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
78 cmdutil, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 commands, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 dirstate, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
81 error, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 extensions, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 hg, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
84 match as matchmod, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
85 registrar, |
33297
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33296
diff
changeset
|
86 sparse, |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
87 util, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
88 ) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
89 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
90 # 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
|
91 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
92 # 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
|
93 # leave the attribute unspecified. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
94 testedwith = 'ships-with-hg-core' |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
95 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
96 cmdtable = {} |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
97 command = registrar.command(cmdtable) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
98 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
99 def extsetup(ui): |
33299
41448fc51510
sparse: variable to track if sparse is enabled
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33298
diff
changeset
|
100 sparse.enabled = True |
41448fc51510
sparse: variable to track if sparse is enabled
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33298
diff
changeset
|
101 |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
102 _setupclone(ui) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
103 _setuplog(ui) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
104 _setupadd(ui) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
105 _setupdirstate(ui) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
106 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
107 def replacefilecache(cls, propname, replacement): |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
108 """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
|
109 cache invalidation condition.""" |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
110 origcls = cls |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
111 assert callable(replacement) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
112 while cls is not object: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
113 if propname in cls.__dict__: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
114 orig = cls.__dict__[propname] |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
115 setattr(cls, propname, replacement(orig)) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
116 break |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
117 cls = cls.__bases__[0] |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
118 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
119 if cls is object: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
120 raise AttributeError(_("type '%s' has no property '%s'") % (origcls, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
121 propname)) |
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 _setuplog(ui): |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
124 entry = commands.table['^log|history'] |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
125 entry[1].append(('', 'sparse', None, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
126 "limit to changesets affecting the sparse checkout")) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
127 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
128 def _logrevs(orig, repo, opts): |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
129 revs = orig(repo, opts) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
130 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
|
131 sparsematch = sparse.matcher(repo) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
132 def ctxmatch(rev): |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
133 ctx = repo[rev] |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
134 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
|
135 revs = revs.filter(ctxmatch) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
136 return revs |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
137 extensions.wrapfunction(cmdutil, '_logrevs', _logrevs) |
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 _clonesparsecmd(orig, ui, repo, *args, **opts): |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
140 include_pat = opts.get('include') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
141 exclude_pat = opts.get('exclude') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
142 enableprofile_pat = opts.get('enable_profile') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
143 include = exclude = enableprofile = False |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
144 if include_pat: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
145 pat = include_pat |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
146 include = True |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
147 if exclude_pat: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
148 pat = exclude_pat |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
149 exclude = True |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
150 if enableprofile_pat: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
151 pat = enableprofile_pat |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
152 enableprofile = True |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
153 if sum([include, exclude, enableprofile]) > 1: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
154 raise error.Abort(_("too many flags specified.")) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
155 if include or exclude or enableprofile: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
156 def clonesparse(orig, self, node, overwrite, *args, **kwargs): |
33374
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33373
diff
changeset
|
157 sparse.updateconfig(self.unfiltered(), pat, {}, include=include, |
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33373
diff
changeset
|
158 exclude=exclude, enableprofile=enableprofile) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
159 return orig(self, node, overwrite, *args, **kwargs) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
160 extensions.wrapfunction(hg, 'updaterepo', clonesparse) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
161 return orig(ui, repo, *args, **opts) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
162 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
163 def _setupclone(ui): |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
164 entry = commands.table['^clone'] |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
165 entry[1].append(('', 'enable-profile', [], |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
166 'enable a sparse profile')) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
167 entry[1].append(('', 'include', [], |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
168 'include sparse pattern')) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
169 entry[1].append(('', 'exclude', [], |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
170 'exclude sparse pattern')) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
171 extensions.wrapcommand(commands.table, 'clone', _clonesparsecmd) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
172 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
173 def _setupadd(ui): |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
174 entry = commands.table['^add'] |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
175 entry[1].append(('s', 'sparse', None, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
176 'also include directories of added files in sparse config')) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
177 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
178 def _add(orig, ui, repo, *pats, **opts): |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
179 if opts.get('sparse'): |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
180 dirs = set() |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
181 for pat in pats: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
182 dirname, basename = util.split(pat) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
183 dirs.add(dirname) |
33374
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33373
diff
changeset
|
184 sparse.updateconfig(repo, list(dirs), opts, include=True) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
185 return orig(ui, repo, *pats, **opts) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
186 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
187 extensions.wrapcommand(commands.table, 'add', _add) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
188 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
189 def _setupdirstate(ui): |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
190 """Modify the dirstate to prevent stat'ing excluded files, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
191 and to prevent modifications to files outside the checkout. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
192 """ |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
193 |
33496
258298f4712b
sparse: override dirstate.walk() instead of dirstate._ignore
Martin von Zweigbergk <martinvonz@google.com>
parents:
33374
diff
changeset
|
194 def walk(orig, self, match, subrepos, unknown, ignored, full=True): |
258298f4712b
sparse: override dirstate.walk() instead of dirstate._ignore
Martin von Zweigbergk <martinvonz@google.com>
parents:
33374
diff
changeset
|
195 match = matchmod.intersectmatchers(match, self._sparsematcher) |
258298f4712b
sparse: override dirstate.walk() instead of dirstate._ignore
Martin von Zweigbergk <martinvonz@google.com>
parents:
33374
diff
changeset
|
196 return orig(self, match, subrepos, unknown, ignored, full) |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33319
diff
changeset
|
197 |
33496
258298f4712b
sparse: override dirstate.walk() instead of dirstate._ignore
Martin von Zweigbergk <martinvonz@google.com>
parents:
33374
diff
changeset
|
198 extensions.wrapfunction(dirstate.dirstate, 'walk', walk) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
199 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
200 # dirstate.rebuild should not add non-matching files |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
201 def _rebuild(orig, self, parent, allfiles, changedfiles=None): |
33373
fb320398a21c
dirstate: expose a sparse matcher on dirstate (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33372
diff
changeset
|
202 matcher = self._sparsematcher |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33319
diff
changeset
|
203 if not matcher.always(): |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
204 allfiles = allfiles.matches(matcher) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
205 if changedfiles: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
206 changedfiles = [f for f in changedfiles if matcher(f)] |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
207 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
208 if changedfiles is not None: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
209 # 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
|
210 # when they are not found to be in allfiles |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
211 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
|
212 changedfiles = dirstatefilestoremove.union(changedfiles) |
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 return orig(self, parent, allfiles, changedfiles) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
215 extensions.wrapfunction(dirstate.dirstate, 'rebuild', _rebuild) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
216 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
217 # Prevent adding files that are outside the sparse checkout |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
218 editfuncs = ['normal', 'add', 'normallookup', 'copy', 'remove', 'merge'] |
33293
c9cbf4de27ba
sparse: rename command to debugsparse
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33292
diff
changeset
|
219 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
|
220 '`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
|
221 for func in editfuncs: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
222 def _wrapper(orig, self, *args): |
33373
fb320398a21c
dirstate: expose a sparse matcher on dirstate (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33372
diff
changeset
|
223 sparsematch = self._sparsematcher |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33319
diff
changeset
|
224 if not sparsematch.always(): |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
225 for f in args: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
226 if (f is not None and not sparsematch(f) and |
33372
4481f1fd27b1
sparse: use self instead of repo.dirstate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33371
diff
changeset
|
227 f not in self): |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
228 raise error.Abort(_("cannot add '%s' - it is outside " |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
229 "the sparse checkout") % f, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
230 hint=hint) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
231 return orig(self, *args) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
232 extensions.wrapfunction(dirstate.dirstate, func, _wrapper) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
233 |
33293
c9cbf4de27ba
sparse: rename command to debugsparse
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33292
diff
changeset
|
234 @command('^debugsparse', [ |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
235 ('I', 'include', False, _('include files in the sparse checkout')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
236 ('X', 'exclude', False, _('exclude files in the sparse checkout')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
237 ('d', 'delete', False, _('delete an include/exclude rule')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
238 ('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
|
239 ('', 'enable-profile', False, _('enables the specified profile')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
240 ('', 'disable-profile', False, _('disables the specified profile')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
241 ('', 'import-rules', False, _('imports rules from a file')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
242 ('', 'clear-rules', False, _('clears local include/exclude rules')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
243 ('', 'refresh', False, _('updates the working after sparseness changes')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
244 ('', 'reset', False, _('makes the repo full again')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
245 ] + commands.templateopts, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
246 _('[--OPTION] PATTERN...')) |
33293
c9cbf4de27ba
sparse: rename command to debugsparse
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33292
diff
changeset
|
247 def debugsparse(ui, repo, *pats, **opts): |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
248 """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
|
249 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
250 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
|
251 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
|
252 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
|
253 not affect files in history in any way. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
254 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
255 Passing no arguments prints the currently applied sparse rules. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
256 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
257 --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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 be preserved). |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
263 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
264 --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
|
265 immediate. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
266 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
267 --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
|
268 only necessary if .hg/sparse was changed by hand. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
269 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
270 --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
|
271 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
|
272 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
|
273 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
|
274 checkout will automatically be updated appropriately, depending on which |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
275 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
|
276 have been committed. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
277 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
278 --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
|
279 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
|
280 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
|
281 changes are applied immediately. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
282 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
283 --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
|
284 any enabled profiles in place. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
285 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
286 Returns 0 if editing the sparse checkout succeeds. |
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 include = opts.get('include') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
289 exclude = opts.get('exclude') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
290 force = opts.get('force') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
291 enableprofile = opts.get('enable_profile') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
292 disableprofile = opts.get('disable_profile') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
293 importrules = opts.get('import_rules') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
294 clearrules = opts.get('clear_rules') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
295 delete = opts.get('delete') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
296 refresh = opts.get('refresh') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
297 reset = opts.get('reset') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
298 count = sum([include, exclude, enableprofile, disableprofile, delete, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
299 importrules, refresh, clearrules, reset]) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
300 if count > 1: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
301 raise error.Abort(_("too many flags specified")) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
302 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
303 if count == 0: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
304 if repo.vfs.exists('sparse'): |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
305 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
|
306 temporaryincludes = sparse.readtemporaryincludes(repo) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
307 if temporaryincludes: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
308 ui.status(_("Temporarily Included Files (for merge/rebase):\n")) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
309 ui.status(("\n".join(temporaryincludes) + "\n")) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
310 else: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
311 ui.status(_('repo is not sparse\n')) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
312 return |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
313 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
314 if include or exclude or delete or reset or enableprofile or disableprofile: |
33374
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33373
diff
changeset
|
315 sparse.updateconfig(repo, pats, opts, include=include, exclude=exclude, |
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33373
diff
changeset
|
316 reset=reset, delete=delete, |
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33373
diff
changeset
|
317 enableprofile=enableprofile, |
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33373
diff
changeset
|
318 disableprofile=disableprofile, force=force) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
319 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
320 if importrules: |
33371
c6415195fa78
sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33370
diff
changeset
|
321 sparse.importfromfiles(repo, opts, pats, force=force) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
322 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
323 if clearrules: |
33354
4695f1829045
sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33353
diff
changeset
|
324 sparse.clearrules(repo, force=force) |
33289
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 if refresh: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
327 try: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
328 wlock = repo.wlock() |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
329 fcounts = map( |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
330 len, |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
331 sparse.refreshwdir(repo, repo.status(), sparse.matcher(repo), |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
332 force=force)) |
33355
9087f9997f42
sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33354
diff
changeset
|
333 sparse.printchanges(ui, opts, added=fcounts[0], dropped=fcounts[1], |
9087f9997f42
sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33354
diff
changeset
|
334 conflicting=fcounts[2]) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
335 finally: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
336 wlock.release() |