annotate hgext/sparse.py @ 33291:74923cec6fdb

sparse: remove reference to hgwatchman This is a legacy extension. Now that the extension is in core, we only need to support what's in core, which is fsmonitor.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 01 Jul 2017 10:24:31 -0700
parents cd1c275c9482
children 1e9fd2c35ae3
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.
33289
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
20 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
21
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
22 from __future__ import absolute_import
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
23
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
24 import collections
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
25 import hashlib
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
26 import os
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
27
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
28 from mercurial.i18n import _
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
29 from mercurial.node import nullid
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
30 from mercurial import (
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
31 cmdutil,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
32 commands,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
33 context,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
34 dirstate,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
35 error,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
36 extensions,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
37 hg,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
38 localrepo,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
39 match as matchmod,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
40 merge as mergemod,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
41 registrar,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
42 util,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
43 )
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
44
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
45 # 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
46 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
47 # 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
48 # leave the attribute unspecified.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
49 testedwith = 'ships-with-hg-core'
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
50
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
51 cmdtable = {}
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
52 command = registrar.command(cmdtable)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
53
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
54 def uisetup(ui):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
55 _setupupdates(ui)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
56 _setupcommit(ui)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
57
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
58 def extsetup(ui):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
59 _setupclone(ui)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
60 _setuplog(ui)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
61 _setupadd(ui)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
62 _setupdirstate(ui)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
63 # if fsmonitor is enabled, tell it to use our hash function
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
64 try:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
65 fsmonitor = extensions.find('fsmonitor')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
66 def _hashignore(orig, ignore):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
67 return _hashmatcher(ignore)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
68 extensions.wrapfunction(fsmonitor, '_hashignore', _hashignore)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
69 except KeyError:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
70 pass
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
71
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
72 def reposetup(ui, repo):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
73 if not util.safehasattr(repo, 'dirstate'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
74 return
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 _wraprepo(ui, repo)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
77
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
78 def replacefilecache(cls, propname, replacement):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
79 """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
80 cache invalidation condition."""
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
81 origcls = cls
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
82 assert callable(replacement)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
83 while cls is not object:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
84 if propname in cls.__dict__:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
85 orig = cls.__dict__[propname]
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
86 setattr(cls, propname, replacement(orig))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
87 break
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
88 cls = cls.__bases__[0]
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 if cls is object:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
91 raise AttributeError(_("type '%s' has no property '%s'") % (origcls,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
92 propname))
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 def _setupupdates(ui):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
95 def _calculateupdates(orig, repo, wctx, mctx, ancestors, branchmerge, *arg,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
96 **kwargs):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
97 """Filter updates to only lay out files that match the sparse rules.
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 actions, diverge, renamedelete = orig(repo, wctx, mctx, ancestors,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
100 branchmerge, *arg, **kwargs)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
101
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
102 if not util.safehasattr(repo, 'sparsematch'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
103 return actions, diverge, renamedelete
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
104
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
105 files = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
106 prunedactions = {}
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
107 oldrevs = [pctx.rev() for pctx in wctx.parents()]
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
108 oldsparsematch = repo.sparsematch(*oldrevs)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
109
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
110 if branchmerge:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
111 # If we're merging, use the wctx filter, since we're merging into
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
112 # the wctx.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
113 sparsematch = repo.sparsematch(wctx.parents()[0].rev())
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
114 else:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
115 # If we're updating, use the target context's filter, since we're
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
116 # moving to the target context.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
117 sparsematch = repo.sparsematch(mctx.rev())
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 temporaryfiles = []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
120 for file, action in actions.iteritems():
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
121 type, args, msg = action
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
122 files.add(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
123 if sparsematch(file):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
124 prunedactions[file] = action
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
125 elif type == 'm':
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
126 temporaryfiles.append(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
127 prunedactions[file] = action
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
128 elif branchmerge:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
129 if type != 'k':
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
130 temporaryfiles.append(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
131 prunedactions[file] = action
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
132 elif type == 'f':
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
133 prunedactions[file] = action
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
134 elif file in wctx:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
135 prunedactions[file] = ('r', args, msg)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
136
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
137 if len(temporaryfiles) > 0:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
138 ui.status(_("temporarily included %d file(s) in the sparse checkout"
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
139 " for merging\n") % len(temporaryfiles))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
140 repo.addtemporaryincludes(temporaryfiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
141
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
142 # Add the new files to the working copy so they can be merged, etc
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
143 actions = []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
144 message = 'temporarily adding to sparse checkout'
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
145 wctxmanifest = repo[None].manifest()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
146 for file in temporaryfiles:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
147 if file in wctxmanifest:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
148 fctx = repo[None][file]
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
149 actions.append((file, (fctx.flags(), False), message))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
150
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
151 typeactions = collections.defaultdict(list)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
152 typeactions['g'] = actions
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
153 mergemod.applyupdates(repo, typeactions, repo[None], repo['.'],
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
154 False)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
155
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
156 dirstate = repo.dirstate
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
157 for file, flags, msg in actions:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
158 dirstate.normal(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
159
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
160 profiles = repo.getactiveprofiles()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
161 changedprofiles = profiles & files
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
162 # If an active profile changed during the update, refresh the checkout.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
163 # Don't do this during a branch merge, since all incoming changes should
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
164 # have been handled by the temporary includes above.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
165 if changedprofiles and not branchmerge:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
166 mf = mctx.manifest()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
167 for file in mf:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
168 old = oldsparsematch(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
169 new = sparsematch(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
170 if not old and new:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
171 flags = mf.flags(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
172 prunedactions[file] = ('g', (flags, False), '')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
173 elif old and not new:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
174 prunedactions[file] = ('r', [], '')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
175
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
176 return prunedactions, diverge, renamedelete
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 extensions.wrapfunction(mergemod, 'calculateupdates', _calculateupdates)
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 _update(orig, repo, node, branchmerge, *args, **kwargs):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
181 results = orig(repo, node, branchmerge, *args, **kwargs)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
182
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
183 # If we're updating to a location, clean up any stale temporary includes
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
184 # (ex: this happens during hg rebase --abort).
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
185 if not branchmerge and util.safehasattr(repo, 'sparsematch'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
186 repo.prunetemporaryincludes()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
187 return results
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 extensions.wrapfunction(mergemod, 'update', _update)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
190
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
191 def _setupcommit(ui):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
192 def _refreshoncommit(orig, self, node):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
193 """Refresh the checkout when commits touch .hgsparse
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
194 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
195 orig(self, node)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
196 repo = self._repo
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
197 if util.safehasattr(repo, 'getsparsepatterns'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
198 ctx = repo[node]
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
199 _, _, profiles = repo.getsparsepatterns(ctx.rev())
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
200 if set(profiles) & set(ctx.files()):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
201 origstatus = repo.status()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
202 origsparsematch = repo.sparsematch()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
203 _refresh(repo.ui, repo, origstatus, origsparsematch, True)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
204
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
205 repo.prunetemporaryincludes()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
206
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
207 extensions.wrapfunction(context.committablectx, 'markcommitted',
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
208 _refreshoncommit)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
209
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
210 def _setuplog(ui):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
211 entry = commands.table['^log|history']
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
212 entry[1].append(('', 'sparse', None,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
213 "limit to changesets affecting the sparse checkout"))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
214
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
215 def _logrevs(orig, repo, opts):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
216 revs = orig(repo, opts)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
217 if opts.get('sparse'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
218 sparsematch = repo.sparsematch()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
219 def ctxmatch(rev):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
220 ctx = repo[rev]
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
221 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
222 revs = revs.filter(ctxmatch)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
223 return revs
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
224 extensions.wrapfunction(cmdutil, '_logrevs', _logrevs)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
225
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
226 def _clonesparsecmd(orig, ui, repo, *args, **opts):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
227 include_pat = opts.get('include')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
228 exclude_pat = opts.get('exclude')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
229 enableprofile_pat = opts.get('enable_profile')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
230 include = exclude = enableprofile = False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
231 if include_pat:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
232 pat = include_pat
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
233 include = True
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
234 if exclude_pat:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
235 pat = exclude_pat
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
236 exclude = True
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
237 if enableprofile_pat:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
238 pat = enableprofile_pat
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
239 enableprofile = True
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
240 if sum([include, exclude, enableprofile]) > 1:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
241 raise error.Abort(_("too many flags specified."))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
242 if include or exclude or enableprofile:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
243 def clonesparse(orig, self, node, overwrite, *args, **kwargs):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
244 _config(self.ui, self.unfiltered(), pat, {}, include=include,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
245 exclude=exclude, enableprofile=enableprofile)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
246 return orig(self, node, overwrite, *args, **kwargs)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
247 extensions.wrapfunction(hg, 'updaterepo', clonesparse)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
248 return orig(ui, repo, *args, **opts)
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 def _setupclone(ui):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
251 entry = commands.table['^clone']
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
252 entry[1].append(('', 'enable-profile', [],
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
253 'enable a sparse profile'))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
254 entry[1].append(('', 'include', [],
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
255 'include sparse pattern'))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
256 entry[1].append(('', 'exclude', [],
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
257 'exclude sparse pattern'))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
258 extensions.wrapcommand(commands.table, 'clone', _clonesparsecmd)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
259
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
260 def _setupadd(ui):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
261 entry = commands.table['^add']
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
262 entry[1].append(('s', 'sparse', None,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
263 'also include directories of added files in sparse config'))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
264
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
265 def _add(orig, ui, repo, *pats, **opts):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
266 if opts.get('sparse'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
267 dirs = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
268 for pat in pats:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
269 dirname, basename = util.split(pat)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
270 dirs.add(dirname)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
271 _config(ui, repo, list(dirs), opts, include=True)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
272 return orig(ui, repo, *pats, **opts)
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 extensions.wrapcommand(commands.table, 'add', _add)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
275
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
276 def _setupdirstate(ui):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
277 """Modify the dirstate to prevent stat'ing excluded files,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
278 and to prevent modifications to files outside the checkout.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
279 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
280
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
281 def _dirstate(orig, repo):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
282 dirstate = orig(repo)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
283 dirstate.repo = repo
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
284 return dirstate
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
285 extensions.wrapfunction(
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
286 localrepo.localrepository.dirstate, 'func', _dirstate)
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 # 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
289 # property, which means normal function wrapping doesn't work.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
290 class ignorewrapper(object):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
291 def __init__(self, orig):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
292 self.orig = orig
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
293 self.origignore = None
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
294 self.func = None
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
295 self.sparsematch = None
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
296
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
297 def __get__(self, obj, type=None):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
298 repo = obj.repo
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
299 origignore = self.orig.__get__(obj)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
300 if not util.safehasattr(repo, 'sparsematch'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
301 return origignore
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 sparsematch = repo.sparsematch()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
304 if self.sparsematch != sparsematch or self.origignore != origignore:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
305 self.func = unionmatcher([origignore,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
306 negatematcher(sparsematch)])
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
307 self.sparsematch = sparsematch
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
308 self.origignore = origignore
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
309 return self.func
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
310
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
311 def __set__(self, obj, value):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
312 return self.orig.__set__(obj, value)
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 def __delete__(self, obj):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
315 return self.orig.__delete__(obj)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
316
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
317 replacefilecache(dirstate.dirstate, '_ignore', ignorewrapper)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
318
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
319 # dirstate.rebuild should not add non-matching files
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
320 def _rebuild(orig, self, parent, allfiles, changedfiles=None):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
321 if util.safehasattr(self.repo, 'sparsematch'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
322 matcher = self.repo.sparsematch()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
323 allfiles = allfiles.matches(matcher)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
324 if changedfiles:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
325 changedfiles = [f for f in changedfiles if matcher(f)]
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
326
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
327 if changedfiles is not None:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
328 # 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
329 # when they are not found to be in allfiles
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
330 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
331 changedfiles = dirstatefilestoremove.union(changedfiles)
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 return orig(self, parent, allfiles, changedfiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
334 extensions.wrapfunction(dirstate.dirstate, 'rebuild', _rebuild)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
335
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
336 # Prevent adding files that are outside the sparse checkout
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
337 editfuncs = ['normal', 'add', 'normallookup', 'copy', 'remove', 'merge']
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
338 hint = _('include file with `hg sparse --include <pattern>` or use ' +
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
339 '`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
340 for func in editfuncs:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
341 def _wrapper(orig, self, *args):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
342 repo = self.repo
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
343 if util.safehasattr(repo, 'sparsematch'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
344 dirstate = repo.dirstate
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
345 sparsematch = repo.sparsematch()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
346 for f in args:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
347 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
348 f not in dirstate):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
349 raise error.Abort(_("cannot add '%s' - it is outside "
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
350 "the sparse checkout") % f,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
351 hint=hint)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
352 return orig(self, *args)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
353 extensions.wrapfunction(dirstate.dirstate, func, _wrapper)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
354
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
355 def _wraprepo(ui, repo):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
356 class SparseRepo(repo.__class__):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
357 def readsparseconfig(self, raw):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
358 """Takes a string sparse config and returns the includes,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
359 excludes, and profiles it specified.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
360 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
361 includes = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
362 excludes = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
363 current = includes
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
364 profiles = []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
365 for line in raw.split('\n'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
366 line = line.strip()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
367 if not line or line.startswith('#'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
368 # empty or comment line, skip
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
369 continue
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
370 elif line.startswith('%include '):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
371 line = line[9:].strip()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
372 if line:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
373 profiles.append(line)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
374 elif line == '[include]':
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
375 if current != includes:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
376 raise error.Abort(_('.hg/sparse cannot have includes ' +
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
377 'after excludes'))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
378 continue
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
379 elif line == '[exclude]':
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
380 current = excludes
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
381 elif line:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
382 if line.strip().startswith('/'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
383 self.ui.warn(_('warning: sparse profile cannot use' +
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
384 ' paths starting with /, ignoring %s\n')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
385 % line)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
386 continue
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
387 current.add(line)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
388
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
389 return includes, excludes, profiles
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
390
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
391 def getsparsepatterns(self, rev):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
392 """Returns the include/exclude patterns specified by the
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
393 given rev.
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 not self.vfs.exists('sparse'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
396 return set(), set(), []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
397 if rev is None:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
398 raise error.Abort(_("cannot parse sparse patterns from " +
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
399 "working copy"))
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 raw = self.vfs.read('sparse')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
402 includes, excludes, profiles = self.readsparseconfig(raw)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
403
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
404 ctx = self[rev]
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
405 if profiles:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
406 visited = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
407 while profiles:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
408 profile = profiles.pop()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
409 if profile in visited:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
410 continue
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
411 visited.add(profile)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
412
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
413 try:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
414 raw = self.getrawprofile(profile, rev)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
415 except error.ManifestLookupError:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
416 msg = (
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
417 "warning: sparse profile '%s' not found "
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
418 "in rev %s - ignoring it\n" % (profile, ctx))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
419 if self.ui.configbool(
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
420 'sparse', 'missingwarning', True):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
421 self.ui.warn(msg)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
422 else:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
423 self.ui.debug(msg)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
424 continue
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
425 pincludes, pexcludes, subprofs = \
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
426 self.readsparseconfig(raw)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
427 includes.update(pincludes)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
428 excludes.update(pexcludes)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
429 for subprofile in subprofs:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
430 profiles.append(subprofile)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
431
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
432 profiles = visited
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
433
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
434 if includes:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
435 includes.add('.hg*')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
436 return includes, excludes, profiles
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
437
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
438 def getrawprofile(self, profile, changeid):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
439 try:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
440 simplecache = extensions.find('simplecache')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
441 node = self[changeid].hex()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
442 def func():
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
443 return self.filectx(profile, changeid=changeid).data()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
444 key = 'sparseprofile:%s:%s' % (profile.replace('/', '__'), node)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
445 return simplecache.memoize(func, key,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
446 simplecache.stringserializer, self.ui)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
447 except KeyError:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
448 return self.filectx(profile, changeid=changeid).data()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
449
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
450 def sparsechecksum(self, filepath):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
451 fh = open(filepath)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
452 return hashlib.sha1(fh.read()).hexdigest()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
453
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
454 def _sparsesignature(self, includetemp=True):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
455 """Returns the signature string representing the contents of the
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
456 current project sparse configuration. This can be used to cache the
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
457 sparse matcher for a given set of revs."""
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
458 signaturecache = self.signaturecache
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
459 signature = signaturecache.get('signature')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
460 if includetemp:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
461 tempsignature = signaturecache.get('tempsignature')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
462 else:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
463 tempsignature = 0
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
464
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
465 if signature is None or (includetemp and tempsignature is None):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
466 signature = 0
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
467 try:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
468 sparsepath = self.vfs.join('sparse')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
469 signature = self.sparsechecksum(sparsepath)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
470 except (OSError, IOError):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
471 pass
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
472 signaturecache['signature'] = signature
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
473
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
474 tempsignature = 0
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
475 if includetemp:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
476 try:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
477 tempsparsepath = self.vfs.join('tempsparse')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
478 tempsignature = self.sparsechecksum(tempsparsepath)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
479 except (OSError, IOError):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
480 pass
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
481 signaturecache['tempsignature'] = tempsignature
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
482 return '%s %s' % (str(signature), str(tempsignature))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
483
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
484 def invalidatecaches(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
485 self.invalidatesignaturecache()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
486 return super(SparseRepo, self).invalidatecaches()
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 def invalidatesignaturecache(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
489 self.signaturecache.clear()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
490
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
491 def sparsematch(self, *revs, **kwargs):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
492 """Returns the sparse match function for the given revs.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
493
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
494 If multiple revs are specified, the match function is the union
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
495 of all the revs.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
496
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
497 `includetemp` is used to indicate if the temporarily included file
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
498 should be part of the matcher.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
499 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
500 if not revs or revs == (None,):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
501 revs = [self.changelog.rev(node) for node in
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
502 self.dirstate.parents() if node != nullid]
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
503
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
504 includetemp = kwargs.get('includetemp', True)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
505 signature = self._sparsesignature(includetemp=includetemp)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
506
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
507 key = '%s %s' % (str(signature), ' '.join([str(r) for r in revs]))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
508
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
509 result = self.sparsecache.get(key, None)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
510 if result:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
511 return result
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 matchers = []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
514 for rev in revs:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
515 try:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
516 includes, excludes, profiles = self.getsparsepatterns(rev)
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 if includes or excludes:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
519 # Explicitly include subdirectories of includes so
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
520 # status will walk them down to the actual include.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
521 subdirs = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
522 for include in includes:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
523 dirname = os.path.dirname(include)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
524 # basename is used to avoid issues with absolute
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
525 # paths (which on Windows can include the drive).
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
526 while os.path.basename(dirname):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
527 subdirs.add(dirname)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
528 dirname = os.path.dirname(dirname)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
529
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
530 matcher = matchmod.match(self.root, '', [],
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
531 include=includes, exclude=excludes,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
532 default='relpath')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
533 if subdirs:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
534 matcher = forceincludematcher(matcher, subdirs)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
535 matchers.append(matcher)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
536 except IOError:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
537 pass
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
538
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
539 result = None
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
540 if not matchers:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
541 result = matchmod.always(self.root, '')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
542 elif len(matchers) == 1:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
543 result = matchers[0]
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
544 else:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
545 result = unionmatcher(matchers)
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 if kwargs.get('includetemp', True):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
548 tempincludes = self.gettemporaryincludes()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
549 result = forceincludematcher(result, tempincludes)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
550
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
551 self.sparsecache[key] = result
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
552
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
553 return result
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
554
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
555 def getactiveprofiles(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
556 revs = [self.changelog.rev(node) for node in
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
557 self.dirstate.parents() if node != nullid]
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
558
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
559 activeprofiles = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
560 for rev in revs:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
561 _, _, profiles = self.getsparsepatterns(rev)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
562 activeprofiles.update(profiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
563
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
564 return activeprofiles
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
565
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
566 def writesparseconfig(self, include, exclude, profiles):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
567 raw = '%s[include]\n%s\n[exclude]\n%s\n' % (
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
568 ''.join(['%%include %s\n' % p for p in sorted(profiles)]),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
569 '\n'.join(sorted(include)),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
570 '\n'.join(sorted(exclude)))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
571 self.vfs.write("sparse", raw)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
572 self.invalidatesignaturecache()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
573
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
574 def addtemporaryincludes(self, files):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
575 includes = self.gettemporaryincludes()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
576 for file in files:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
577 includes.add(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
578 self._writetemporaryincludes(includes)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
579
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
580 def gettemporaryincludes(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
581 existingtemp = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
582 if self.vfs.exists('tempsparse'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
583 raw = self.vfs.read('tempsparse')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
584 existingtemp.update(raw.split('\n'))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
585 return existingtemp
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
586
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
587 def _writetemporaryincludes(self, includes):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
588 raw = '\n'.join(sorted(includes))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
589 self.vfs.write('tempsparse', raw)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
590 self.invalidatesignaturecache()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
591
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
592 def prunetemporaryincludes(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
593 if repo.vfs.exists('tempsparse'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
594 origstatus = self.status()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
595 modified, added, removed, deleted, a, b, c = origstatus
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
596 if modified or added or removed or deleted:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
597 # Still have pending changes. Don't bother trying to prune.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
598 return
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
599
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
600 sparsematch = self.sparsematch(includetemp=False)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
601 dirstate = self.dirstate
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
602 actions = []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
603 dropped = []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
604 tempincludes = self.gettemporaryincludes()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
605 for file in tempincludes:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
606 if file in dirstate and not sparsematch(file):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
607 message = 'dropping temporarily included sparse files'
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
608 actions.append((file, None, message))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
609 dropped.append(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
610
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
611 typeactions = collections.defaultdict(list)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
612 typeactions['r'] = actions
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
613 mergemod.applyupdates(self, typeactions, self[None], self['.'],
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
614 False)
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 # Fix dirstate
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
617 for file in dropped:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
618 dirstate.drop(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
619
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
620 self.vfs.unlink('tempsparse')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
621 self.invalidatesignaturecache()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
622 msg = _("cleaned up %d temporarily added file(s) from the "
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
623 "sparse checkout\n")
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
624 ui.status(msg % len(tempincludes))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
625
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
626 if 'dirstate' in repo._filecache:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
627 repo.dirstate.repo = repo
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
628 repo.sparsecache = {}
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
629 repo.signaturecache = {}
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
630 repo.__class__ = SparseRepo
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
631
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
632 @command('^sparse', [
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
633 ('I', 'include', False, _('include files in the sparse checkout')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
634 ('X', 'exclude', False, _('exclude files in the sparse checkout')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
635 ('d', 'delete', False, _('delete an include/exclude rule')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
636 ('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
637 ('', 'enable-profile', False, _('enables the specified profile')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
638 ('', 'disable-profile', False, _('disables the specified profile')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
639 ('', 'import-rules', False, _('imports rules from a file')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
640 ('', 'clear-rules', False, _('clears local include/exclude rules')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
641 ('', 'refresh', False, _('updates the working after sparseness changes')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
642 ('', 'reset', False, _('makes the repo full again')),
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
643 ] + commands.templateopts,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
644 _('[--OPTION] PATTERN...'))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
645 def sparse(ui, repo, *pats, **opts):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
646 """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
647
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
648 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
649 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
650 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
651 not affect files in history in any way.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
652
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
653 Passing no arguments prints the currently applied sparse rules.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
654
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
655 --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
656 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
657 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
658 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
659 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
660 be preserved).
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
661
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
662 --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
663 immediate.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
664
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
665 --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
666 only necessary if .hg/sparse was changed by hand.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
667
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
668 --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
669 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
670 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
671 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
672 checkout will automatically be updated appropriately, depending on which
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
673 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
674 have been committed.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
675
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
676 --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
677 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
678 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
679 changes are applied immediately.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
680
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
681 --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
682 any enabled profiles in place.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
683
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
684 Returns 0 if editing the sparse checkout succeeds.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
685 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
686 include = opts.get('include')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
687 exclude = opts.get('exclude')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
688 force = opts.get('force')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
689 enableprofile = opts.get('enable_profile')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
690 disableprofile = opts.get('disable_profile')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
691 importrules = opts.get('import_rules')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
692 clearrules = opts.get('clear_rules')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
693 delete = opts.get('delete')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
694 refresh = opts.get('refresh')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
695 reset = opts.get('reset')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
696 count = sum([include, exclude, enableprofile, disableprofile, delete,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
697 importrules, refresh, clearrules, reset])
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
698 if count > 1:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
699 raise error.Abort(_("too many flags specified"))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
700
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
701 if count == 0:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
702 if repo.vfs.exists('sparse'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
703 ui.status(repo.vfs.read("sparse") + "\n")
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
704 temporaryincludes = repo.gettemporaryincludes()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
705 if temporaryincludes:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
706 ui.status(_("Temporarily Included Files (for merge/rebase):\n"))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
707 ui.status(("\n".join(temporaryincludes) + "\n"))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
708 else:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
709 ui.status(_('repo is not sparse\n'))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
710 return
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
711
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
712 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
713 _config(ui, repo, pats, opts, include=include, exclude=exclude,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
714 reset=reset, delete=delete, enableprofile=enableprofile,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
715 disableprofile=disableprofile, force=force)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
716
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
717 if importrules:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
718 _import(ui, repo, pats, opts, force=force)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
719
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
720 if clearrules:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
721 _clear(ui, repo, pats, force=force)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
722
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
723 if refresh:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
724 try:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
725 wlock = repo.wlock()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
726 fcounts = map(
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
727 len,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
728 _refresh(ui, repo, repo.status(), repo.sparsematch(), force))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
729 _verbose_output(ui, opts, 0, 0, 0, *fcounts)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
730 finally:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
731 wlock.release()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
732
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
733 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
734 delete=False, enableprofile=False, disableprofile=False,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
735 force=False):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
736 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
737 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
738 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
739 wlock = repo.wlock()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
740 try:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
741 oldsparsematch = repo.sparsematch()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
742
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
743 if repo.vfs.exists('sparse'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
744 raw = repo.vfs.read('sparse')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
745 oldinclude, oldexclude, oldprofiles = map(
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
746 set, repo.readsparseconfig(raw))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
747 else:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
748 oldinclude = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
749 oldexclude = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
750 oldprofiles = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
751
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
752 try:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
753 if reset:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
754 newinclude = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
755 newexclude = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
756 newprofiles = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
757 else:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
758 newinclude = set(oldinclude)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
759 newexclude = set(oldexclude)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
760 newprofiles = set(oldprofiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
761
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
762 oldstatus = repo.status()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
763
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
764 if any(pat.startswith('/') for pat in pats):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
765 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
766 % ([pat for pat in pats if pat.startswith('/')]))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
767 elif include:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
768 newinclude.update(pats)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
769 elif exclude:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
770 newexclude.update(pats)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
771 elif enableprofile:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
772 newprofiles.update(pats)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
773 elif disableprofile:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
774 newprofiles.difference_update(pats)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
775 elif delete:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
776 newinclude.difference_update(pats)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
777 newexclude.difference_update(pats)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
778
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
779 repo.writesparseconfig(newinclude, newexclude, newprofiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
780 fcounts = map(
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
781 len, _refresh(ui, repo, oldstatus, oldsparsematch, force))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
782
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
783 profilecount = (len(newprofiles - oldprofiles) -
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
784 len(oldprofiles - newprofiles))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
785 includecount = (len(newinclude - oldinclude) -
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
786 len(oldinclude - newinclude))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
787 excludecount = (len(newexclude - oldexclude) -
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
788 len(oldexclude - newexclude))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
789 _verbose_output(
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
790 ui, opts, profilecount, includecount, excludecount, *fcounts)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
791 except Exception:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
792 repo.writesparseconfig(oldinclude, oldexclude, oldprofiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
793 raise
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
794 finally:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
795 wlock.release()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
796
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
797 def _import(ui, repo, files, opts, force=False):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
798 with repo.wlock():
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
799 # load union of current active profile
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
800 revs = [repo.changelog.rev(node) for node in
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
801 repo.dirstate.parents() if node != nullid]
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
802
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
803 # read current configuration
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
804 raw = ''
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
805 if repo.vfs.exists('sparse'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
806 raw = repo.vfs.read('sparse')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
807 oincludes, oexcludes, oprofiles = repo.readsparseconfig(raw)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
808 includes, excludes, profiles = map(
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
809 set, (oincludes, oexcludes, oprofiles))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
810
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
811 # all active rules
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
812 aincludes, aexcludes, aprofiles = set(), set(), set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
813 for rev in revs:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
814 rincludes, rexcludes, rprofiles = repo.getsparsepatterns(rev)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
815 aincludes.update(rincludes)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
816 aexcludes.update(rexcludes)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
817 aprofiles.update(rprofiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
818
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
819 # 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
820 # part of the active rules.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
821 changed = False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
822 for file in files:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
823 with util.posixfile(util.expandpath(file)) as importfile:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
824 iincludes, iexcludes, iprofiles = repo.readsparseconfig(
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
825 importfile.read())
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
826 oldsize = len(includes) + len(excludes) + len(profiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
827 includes.update(iincludes - aincludes)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
828 excludes.update(iexcludes - aexcludes)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
829 profiles.update(set(iprofiles) - aprofiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
830 if len(includes) + len(excludes) + len(profiles) > oldsize:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
831 changed = True
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
832
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
833 profilecount = includecount = excludecount = 0
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
834 fcounts = (0, 0, 0)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
835
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
836 if changed:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
837 profilecount = len(profiles - aprofiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
838 includecount = len(includes - aincludes)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
839 excludecount = len(excludes - aexcludes)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
840
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
841 oldstatus = repo.status()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
842 oldsparsematch = repo.sparsematch()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
843 repo.writesparseconfig(includes, excludes, profiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
844
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
845 try:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
846 fcounts = map(
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
847 len, _refresh(ui, repo, oldstatus, oldsparsematch, force))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
848 except Exception:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
849 repo.writesparseconfig(oincludes, oexcludes, oprofiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
850 raise
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
851
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
852 _verbose_output(ui, opts, profilecount, includecount, excludecount,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
853 *fcounts)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
854
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
855 def _clear(ui, repo, files, force=False):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
856 with repo.wlock():
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
857 raw = ''
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
858 if repo.vfs.exists('sparse'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
859 raw = repo.vfs.read('sparse')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
860 includes, excludes, profiles = repo.readsparseconfig(raw)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
861
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
862 if includes or excludes:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
863 oldstatus = repo.status()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
864 oldsparsematch = repo.sparsematch()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
865 repo.writesparseconfig(set(), set(), profiles)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
866 _refresh(ui, repo, oldstatus, oldsparsematch, force)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
867
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
868 def _refresh(ui, repo, origstatus, origsparsematch, force):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
869 """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
870 sparsematch with the new sparsematch.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
871
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
872 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
873 or included (unless force=True).
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
874 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
875 modified, added, removed, deleted, unknown, ignored, clean = origstatus
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
876
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
877 # Verify there are no pending changes
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
878 pending = set()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
879 pending.update(modified)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
880 pending.update(added)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
881 pending.update(removed)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
882 sparsematch = repo.sparsematch()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
883 abort = False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
884 for file in pending:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
885 if not sparsematch(file):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
886 ui.warn(_("pending changes to '%s'\n") % file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
887 abort = not force
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
888 if abort:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
889 raise error.Abort(_("could not update sparseness due to " +
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
890 "pending changes"))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
891
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
892 # Calculate actions
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
893 dirstate = repo.dirstate
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
894 ctx = repo['.']
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
895 added = []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
896 lookup = []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
897 dropped = []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
898 mf = ctx.manifest()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
899 files = set(mf)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
900
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
901 actions = {}
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
902
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
903 for file in files:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
904 old = origsparsematch(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
905 new = sparsematch(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
906 # 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
907 # the dirstate yet.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
908 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
909 fl = mf.flags(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
910 if repo.wvfs.exists(file):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
911 actions[file] = ('e', (fl,), '')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
912 lookup.append(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
913 else:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
914 actions[file] = ('g', (fl, False), '')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
915 added.append(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
916 # 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
917 # the dirstate.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
918 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
919 dropped.append(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
920 if file not in pending:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
921 actions[file] = ('r', [], '')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
922
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
923 # 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
924 abort = False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
925 for file in lookup:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
926 ui.warn(_("pending changes to '%s'\n") % file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
927 abort = not force
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
928 if abort:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
929 raise error.Abort(_("cannot change sparseness due to " +
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
930 "pending changes (delete the files or use --force " +
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
931 "to bring them back dirty)"))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
932
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
933 # Check for files that were only in the dirstate.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
934 for file, state in dirstate.iteritems():
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
935 if not file in files:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
936 old = origsparsematch(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
937 new = sparsematch(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
938 if old and not new:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
939 dropped.append(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
940
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
941 # Apply changes to disk
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
942 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
943 for f, (m, args, msg) in actions.iteritems():
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
944 if m not in typeactions:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
945 typeactions[m] = []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
946 typeactions[m].append((f, args, msg))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
947 mergemod.applyupdates(repo, typeactions, repo[None], repo['.'], False)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
948
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
949 # Fix dirstate
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
950 for file in added:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
951 dirstate.normal(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
952
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
953 for file in dropped:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
954 dirstate.drop(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
955
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
956 for file in lookup:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
957 # 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
958 dirstate.normallookup(file)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
959
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
960 return added, dropped, lookup
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
961
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
962 def _verbose_output(ui, opts, profilecount, includecount, excludecount, added,
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
963 dropped, lookup):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
964 """Produce --verbose and templatable output
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
965
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
966 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
967 the sparse profile changed.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
968
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
969 """
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
970 with ui.formatter('sparse', opts) as fm:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
971 fm.startitem()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
972 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
973 profilecount)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
974 fm.condwrite(ui.verbose, 'include_rules_added',
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
975 'Include rule # change: %d\n', includecount)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
976 fm.condwrite(ui.verbose, 'exclude_rules_added',
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
977 'Exclude rule # change: %d\n', excludecount)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
978 # In 'plain' verbose mode, mergemod.applyupdates already outputs what
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
979 # 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
980 # framework. No point in repeating ourselves in that case.
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
981 if not fm.isplain():
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
982 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
983 added)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
984 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
985 dropped)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
986 fm.condwrite(ui.verbose, 'files_conflicting',
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
987 'Files conflicting: %d\n', lookup)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
988
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
989 class forceincludematcher(object):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
990 """A matcher that returns true for any of the forced includes before testing
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
991 against the actual matcher."""
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
992 def __init__(self, matcher, includes):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
993 self._matcher = matcher
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
994 self._includes = includes
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
995
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
996 def __call__(self, value):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
997 return value in self._includes or self._matcher(value)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
998
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
999 def always(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1000 return False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1001
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1002 def files(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1003 return []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1004
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1005 def isexact(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1006 return False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1007
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1008 def anypats(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1009 return True
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1010
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1011 def prefix(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1012 return False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1013
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1014 def hash(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1015 sha1 = hashlib.sha1()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1016 sha1.update(_hashmatcher(self._matcher))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1017 for include in sorted(self._includes):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1018 sha1.update(include + '\0')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1019 return sha1.hexdigest()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1020
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1021 class unionmatcher(object):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1022 """A matcher that is the union of several matchers."""
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1023 def __init__(self, matchers):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1024 self._matchers = matchers
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1025
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1026 def __call__(self, value):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1027 for match in self._matchers:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1028 if match(value):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1029 return True
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1030 return False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1031
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1032 def always(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1033 return False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1034
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1035 def files(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1036 return []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1037
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1038 def isexact(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1039 return False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1040
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1041 def anypats(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1042 return True
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1043
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1044 def prefix(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1045 return False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1046
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1047 def hash(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1048 sha1 = hashlib.sha1()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1049 for m in self._matchers:
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1050 sha1.update(_hashmatcher(m))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1051 return sha1.hexdigest()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1052
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1053 class negatematcher(object):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1054 def __init__(self, matcher):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1055 self._matcher = matcher
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1056
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1057 def __call__(self, value):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1058 return not self._matcher(value)
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1059
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1060 def always(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1061 return False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1062
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1063 def files(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1064 return []
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1065
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1066 def isexact(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1067 return False
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1068
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1069 def anypats(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1070 return True
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1071
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1072 def hash(self):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1073 sha1 = hashlib.sha1()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1074 sha1.update('negate')
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1075 sha1.update(_hashmatcher(self._matcher))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1076 return sha1.hexdigest()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1077
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1078 def _hashmatcher(matcher):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1079 if util.safehasattr(matcher, 'hash'):
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1080 return matcher.hash()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1081
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1082 sha1 = hashlib.sha1()
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1083 sha1.update(repr(matcher))
abd7dedbaa36 sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1084 return sha1.hexdigest()