Mercurial > public > mercurial-scm > hg
annotate hgext/largefiles/reposetup.py @ 15783:927712d9853b
largefiles: remove a chunk of commented out code
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Sat, 07 Jan 2012 15:27:34 +0100 |
parents | 7b7f03502b5a |
children | 2c10ea43c801 |
rev | line source |
---|---|
15168 | 1 # Copyright 2009-2010 Gregory P. Ward |
2 # Copyright 2009-2010 Intelerad Medical Systems Incorporated | |
3 # Copyright 2010-2011 Fog Creek Software | |
4 # Copyright 2010-2011 Unity Technologies | |
5 # | |
6 # This software may be used and distributed according to the terms of the | |
7 # GNU General Public License version 2 or any later version. | |
8 | |
9 '''setup for largefiles repositories: reposetup''' | |
10 import copy | |
11 import types | |
12 import os | |
13 | |
15305 | 14 from mercurial import context, error, manifest, match as match_, node, util |
15168 | 15 from mercurial.i18n import _ |
16 | |
17 import lfcommands | |
18 import proto | |
19 import lfutil | |
20 | |
21 def reposetup(ui, repo): | |
22 # wire repositories should be given new wireproto functions but not the | |
23 # other largefiles modifications | |
24 if not repo.local(): | |
25 return proto.wirereposetup(ui, repo) | |
26 | |
27 for name in ('status', 'commitctx', 'commit', 'push'): | |
28 method = getattr(repo, name) | |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
29 if (isinstance(method, types.FunctionType) and |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
30 method.func_name == 'wrap'): |
15168 | 31 ui.warn(_('largefiles: repo method %r appears to have already been' |
32 ' wrapped by another extension: ' | |
33 'largefiles may behave incorrectly\n') | |
34 % name) | |
35 | |
36 class lfiles_repo(repo.__class__): | |
37 lfstatus = False | |
38 def status_nolfiles(self, *args, **kwargs): | |
39 return super(lfiles_repo, self).status(*args, **kwargs) | |
40 | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
41 # When lfstatus is set, return a context that gives the names |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
42 # of largefiles instead of their corresponding standins and |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
43 # identifies the largefiles as always binary, regardless of |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
44 # their actual contents. |
15168 | 45 def __getitem__(self, changeid): |
46 ctx = super(lfiles_repo, self).__getitem__(changeid) | |
47 if self.lfstatus: | |
48 class lfiles_manifestdict(manifest.manifestdict): | |
49 def __contains__(self, filename): | |
50 if super(lfiles_manifestdict, | |
51 self).__contains__(filename): | |
52 return True | |
53 return super(lfiles_manifestdict, | |
15628
2b40513384ca
largefiles: use lfutil functions
Martin Geisler <mg@aragost.com>
parents:
15626
diff
changeset
|
54 self).__contains__(lfutil.standin(filename)) |
15168 | 55 class lfiles_ctx(ctx.__class__): |
56 def files(self): | |
57 filenames = super(lfiles_ctx, self).files() | |
15628
2b40513384ca
largefiles: use lfutil functions
Martin Geisler <mg@aragost.com>
parents:
15626
diff
changeset
|
58 return [lfutil.splitstandin(f) or f for f in filenames] |
15168 | 59 def manifest(self): |
60 man1 = super(lfiles_ctx, self).manifest() | |
61 man1.__class__ = lfiles_manifestdict | |
62 return man1 | |
63 def filectx(self, path, fileid=None, filelog=None): | |
64 try: | |
65 result = super(lfiles_ctx, self).filectx(path, | |
66 fileid, filelog) | |
67 except error.LookupError: | |
68 # Adding a null character will cause Mercurial to | |
69 # identify this as a binary file. | |
70 result = super(lfiles_ctx, self).filectx( | |
15628
2b40513384ca
largefiles: use lfutil functions
Martin Geisler <mg@aragost.com>
parents:
15626
diff
changeset
|
71 lfutil.standin(path), fileid, filelog) |
15168 | 72 olddata = result.data |
73 result.data = lambda: olddata() + '\0' | |
74 return result | |
75 ctx.__class__ = lfiles_ctx | |
76 return ctx | |
77 | |
78 # Figure out the status of big files and insert them into the | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
79 # appropriate list in the result. Also removes standin files |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
80 # from the listing. Revert to the original status if |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
81 # self.lfstatus is False. |
15168 | 82 def status(self, node1='.', node2=None, match=None, ignored=False, |
83 clean=False, unknown=False, listsubrepos=False): | |
84 listignored, listclean, listunknown = ignored, clean, unknown | |
85 if not self.lfstatus: | |
15626
931dc4af0d95
largefiles: remove pre-1.7 compatibility code
Martin Geisler <mg@aragost.com>
parents:
15617
diff
changeset
|
86 return super(lfiles_repo, self).status(node1, node2, match, |
931dc4af0d95
largefiles: remove pre-1.7 compatibility code
Martin Geisler <mg@aragost.com>
parents:
15617
diff
changeset
|
87 listignored, listclean, listunknown, listsubrepos) |
15168 | 88 else: |
89 # some calls in this function rely on the old version of status | |
90 self.lfstatus = False | |
91 if isinstance(node1, context.changectx): | |
92 ctx1 = node1 | |
93 else: | |
94 ctx1 = repo[node1] | |
95 if isinstance(node2, context.changectx): | |
96 ctx2 = node2 | |
97 else: | |
98 ctx2 = repo[node2] | |
99 working = ctx2.rev() is None | |
100 parentworking = working and ctx1 == self['.'] | |
101 | |
102 def inctx(file, ctx): | |
103 try: | |
104 if ctx.rev() is None: | |
105 return file in ctx.manifest() | |
106 ctx[file] | |
107 return True | |
15171
547da6115d1d
largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents:
15170
diff
changeset
|
108 except KeyError: |
15168 | 109 return False |
110 | |
111 if match is None: | |
112 match = match_.always(self.root, self.getcwd()) | |
113 | |
15653
93c77d5b9752
largefiles: optimize status when files are specified (issue3144)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15630
diff
changeset
|
114 # First check if there were files specified on the |
93c77d5b9752
largefiles: optimize status when files are specified (issue3144)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15630
diff
changeset
|
115 # command line. If there were, and none of them were |
93c77d5b9752
largefiles: optimize status when files are specified (issue3144)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15630
diff
changeset
|
116 # largefiles, we should just bail here and let super |
93c77d5b9752
largefiles: optimize status when files are specified (issue3144)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15630
diff
changeset
|
117 # handle it -- thus gaining a big performance boost. |
93c77d5b9752
largefiles: optimize status when files are specified (issue3144)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15630
diff
changeset
|
118 lfdirstate = lfutil.openlfdirstate(ui, self) |
93c77d5b9752
largefiles: optimize status when files are specified (issue3144)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15630
diff
changeset
|
119 if match.files() and not match.anypats(): |
93c77d5b9752
largefiles: optimize status when files are specified (issue3144)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15630
diff
changeset
|
120 matchedfiles = [f for f in match.files() if f in lfdirstate] |
93c77d5b9752
largefiles: optimize status when files are specified (issue3144)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15630
diff
changeset
|
121 if not matchedfiles: |
93c77d5b9752
largefiles: optimize status when files are specified (issue3144)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15630
diff
changeset
|
122 return super(lfiles_repo, self).status(node1, node2, |
93c77d5b9752
largefiles: optimize status when files are specified (issue3144)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15630
diff
changeset
|
123 match, listignored, listclean, |
93c77d5b9752
largefiles: optimize status when files are specified (issue3144)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15630
diff
changeset
|
124 listunknown, listsubrepos) |
93c77d5b9752
largefiles: optimize status when files are specified (issue3144)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15630
diff
changeset
|
125 |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
126 # Create a copy of match that matches standins instead |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
127 # of largefiles. |
15168 | 128 def tostandin(file): |
129 if inctx(lfutil.standin(file), ctx2): | |
130 return lfutil.standin(file) | |
131 return file | |
132 | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
133 # Create a function that we can use to override what is |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
134 # normally the ignore matcher. We've already checked |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
135 # for ignored files on the first dirstate walk, and |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
136 # unecessarily re-checking here causes a huge performance |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
137 # hit because lfdirstate only knows about largefiles |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
138 def _ignoreoverride(self): |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
139 return False |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
140 |
15168 | 141 m = copy.copy(match) |
142 m._files = [tostandin(f) for f in m._files] | |
143 | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
144 # Get ignored files here even if we weren't asked for them; we |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
145 # must use the result here for filtering later |
15626
931dc4af0d95
largefiles: remove pre-1.7 compatibility code
Martin Geisler <mg@aragost.com>
parents:
15617
diff
changeset
|
146 result = super(lfiles_repo, self).status(node1, node2, m, |
931dc4af0d95
largefiles: remove pre-1.7 compatibility code
Martin Geisler <mg@aragost.com>
parents:
15617
diff
changeset
|
147 True, clean, unknown, listsubrepos) |
15168 | 148 if working: |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
149 # hold the wlock while we read largefiles and |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
150 # update the lfdirstate |
15168 | 151 wlock = repo.wlock() |
152 try: | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
153 # Any non-largefiles that were explicitly listed must be |
15168 | 154 # taken out or lfdirstate.status will report an error. |
155 # The status of these files was already computed using | |
156 # super's status. | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
157 # Override lfdirstate's ignore matcher to not do |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
158 # anything |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
159 orig_ignore = lfdirstate._ignore |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
160 lfdirstate._ignore = _ignoreoverride |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
161 |
15168 | 162 match._files = [f for f in match._files if f in |
163 lfdirstate] | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
164 # Don't waste time getting the ignored and unknown |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
165 # files again; we already have them |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
166 s = lfdirstate.status(match, [], False, |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
167 listclean, False) |
15168 | 168 (unsure, modified, added, removed, missing, unknown, |
169 ignored, clean) = s | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
170 # Replace the list of ignored and unknown files with |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
171 # the previously caclulated lists, and strip out the |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
172 # largefiles |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
173 lfiles = set(lfdirstate._map) |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
174 ignored = set(result[5]).difference(lfiles) |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
175 unknown = set(result[4]).difference(lfiles) |
15168 | 176 if parentworking: |
177 for lfile in unsure: | |
15629
5b66e55c0d93
largefiles: fix 'hg status' abort after merge
Martin Geisler <mg@aragost.com>
parents:
15385
diff
changeset
|
178 standin = lfutil.standin(lfile) |
5b66e55c0d93
largefiles: fix 'hg status' abort after merge
Martin Geisler <mg@aragost.com>
parents:
15385
diff
changeset
|
179 if standin not in ctx1: |
5b66e55c0d93
largefiles: fix 'hg status' abort after merge
Martin Geisler <mg@aragost.com>
parents:
15385
diff
changeset
|
180 # from second parent |
5b66e55c0d93
largefiles: fix 'hg status' abort after merge
Martin Geisler <mg@aragost.com>
parents:
15385
diff
changeset
|
181 modified.append(lfile) |
5b66e55c0d93
largefiles: fix 'hg status' abort after merge
Martin Geisler <mg@aragost.com>
parents:
15385
diff
changeset
|
182 elif ctx1[standin].data().strip() \ |
15168 | 183 != lfutil.hashfile(self.wjoin(lfile)): |
184 modified.append(lfile) | |
185 else: | |
186 clean.append(lfile) | |
187 lfdirstate.normal(lfile) | |
188 lfdirstate.write() | |
189 else: | |
190 tocheck = unsure + modified + added + clean | |
191 modified, added, clean = [], [], [] | |
192 | |
193 for lfile in tocheck: | |
194 standin = lfutil.standin(lfile) | |
195 if inctx(standin, ctx1): | |
196 if ctx1[standin].data().strip() != \ | |
197 lfutil.hashfile(self.wjoin(lfile)): | |
198 modified.append(lfile) | |
199 else: | |
200 clean.append(lfile) | |
201 else: | |
202 added.append(lfile) | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
203 # Replace the original ignore function |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
204 lfdirstate._ignore = orig_ignore |
15168 | 205 finally: |
206 wlock.release() | |
207 | |
208 for standin in ctx1.manifest(): | |
209 if not lfutil.isstandin(standin): | |
210 continue | |
211 lfile = lfutil.splitstandin(standin) | |
212 if not match(lfile): | |
213 continue | |
214 if lfile not in lfdirstate: | |
215 removed.append(lfile) | |
15663
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15629
diff
changeset
|
216 |
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15629
diff
changeset
|
217 # Filter result lists |
15168 | 218 result = list(result) |
15663
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15629
diff
changeset
|
219 |
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15629
diff
changeset
|
220 # Largefiles are not really removed when they're |
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15629
diff
changeset
|
221 # still in the normal dirstate. Likewise, normal |
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15629
diff
changeset
|
222 # files are not really removed if it's still in |
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15629
diff
changeset
|
223 # lfdirstate. This happens in merges where files |
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15629
diff
changeset
|
224 # change type. |
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15629
diff
changeset
|
225 removed = [f for f in removed if f not in repo.dirstate] |
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15629
diff
changeset
|
226 result[2] = [f for f in result[2] if f not in lfdirstate] |
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15629
diff
changeset
|
227 |
15168 | 228 # Unknown files |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
229 unknown = set(unknown).difference(ignored) |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
230 result[4] = [f for f in unknown |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
231 if (repo.dirstate[f] == '?' and |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
232 not lfutil.isstandin(f))] |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
233 # Ignored files were calculated earlier by the dirstate, |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
234 # and we already stripped out the largefiles from the list |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
235 result[5] = ignored |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
236 # combine normal files and largefiles |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
237 normals = [[fn for fn in filelist |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
238 if not lfutil.isstandin(fn)] |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
239 for filelist in result] |
15663
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15629
diff
changeset
|
240 lfiles = (modified, added, removed, missing, [], [], clean) |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
241 result = [sorted(list1 + list2) |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
242 for (list1, list2) in zip(normals, lfiles)] |
15168 | 243 else: |
244 def toname(f): | |
245 if lfutil.isstandin(f): | |
246 return lfutil.splitstandin(f) | |
247 return f | |
248 result = [[toname(f) for f in items] for items in result] | |
249 | |
250 if not listunknown: | |
251 result[4] = [] | |
252 if not listignored: | |
253 result[5] = [] | |
254 if not listclean: | |
255 result[6] = [] | |
256 self.lfstatus = True | |
257 return result | |
258 | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
259 # As part of committing, copy all of the largefiles into the |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
260 # cache. |
15168 | 261 def commitctx(self, *args, **kwargs): |
262 node = super(lfiles_repo, self).commitctx(*args, **kwargs) | |
263 ctx = self[node] | |
264 for filename in ctx.files(): | |
265 if lfutil.isstandin(filename) and filename in ctx.manifest(): | |
266 realfile = lfutil.splitstandin(filename) | |
15316
c65f5b6e26d4
largefiles: rename functions and methods to match desired behavior
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15312
diff
changeset
|
267 lfutil.copytostore(self, ctx.node(), realfile) |
15168 | 268 |
269 return node | |
270 | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
271 # Before commit, largefile standins have not had their |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
272 # contents updated to reflect the hash of their largefile. |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
273 # Do that here. |
15168 | 274 def commit(self, text="", user=None, date=None, match=None, |
275 force=False, editor=False, extra={}): | |
276 orig = super(lfiles_repo, self).commit | |
277 | |
278 wlock = repo.wlock() | |
279 try: | |
280 if getattr(repo, "_isrebasing", False): | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
281 # We have to take the time to pull down the new |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
282 # largefiles now. Otherwise if we are rebasing, |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
283 # any largefiles that were modified in the |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
284 # destination changesets get overwritten, either |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
285 # by the rebase or in the first commit after the |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
286 # rebase. |
15168 | 287 lfcommands.updatelfiles(repo.ui, repo) |
288 # Case 1: user calls commit with no specific files or | |
15250
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
289 # include/exclude patterns: refresh and commit all files that |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
290 # are "dirty". |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
291 if ((match is None) or |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
292 (not match.anypats() and not match.files())): |
15250
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
293 # Spend a bit of time here to get a list of files we know |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
294 # are modified so we can compare only against those. |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
295 # It can cost a lot of time (several seconds) |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
296 # otherwise to update all standins if the largefiles are |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
297 # large. |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
298 lfdirstate = lfutil.openlfdirstate(ui, self) |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
299 dirtymatch = match_.always(repo.root, repo.getcwd()) |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
300 s = lfdirstate.status(dirtymatch, [], False, False, False) |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
301 modifiedfiles = [] |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
302 for i in s: |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
303 modifiedfiles.extend(i) |
15168 | 304 lfiles = lfutil.listlfiles(self) |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
305 # this only loops through largefiles that exist (not |
15168 | 306 # removed/renamed) |
307 for lfile in lfiles: | |
15250
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
308 if lfile in modifiedfiles: |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
309 if os.path.exists(self.wjoin(lfutil.standin(lfile))): |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
310 # this handles the case where a rebase is being |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
311 # performed and the working copy is not updated |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
312 # yet. |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
313 if os.path.exists(self.wjoin(lfile)): |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
314 lfutil.updatestandin(self, |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
315 lfutil.standin(lfile)) |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
316 lfdirstate.normal(lfile) |
15168 | 317 for lfile in lfdirstate: |
15250
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
318 if lfile in modifiedfiles: |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
319 if not os.path.exists( |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
320 repo.wjoin(lfutil.standin(lfile))): |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
321 lfdirstate.drop(lfile) |
15168 | 322 lfdirstate.write() |
323 | |
324 return orig(text=text, user=user, date=date, match=match, | |
325 force=force, editor=editor, extra=extra) | |
326 | |
15253
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
327 for f in match.files(): |
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
328 if lfutil.isstandin(f): |
15168 | 329 raise util.Abort( |
15253
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
330 _('file "%s" is a largefile standin') % f, |
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
331 hint=('commit the largefile itself instead')) |
15168 | 332 |
333 # Case 2: user calls commit with specified patterns: refresh | |
334 # any matching big files. | |
335 smatcher = lfutil.composestandinmatcher(self, match) | |
336 standins = lfutil.dirstate_walk(self.dirstate, smatcher) | |
337 | |
338 # No matching big files: get out of the way and pass control to | |
339 # the usual commit() method. | |
340 if not standins: | |
341 return orig(text=text, user=user, date=date, match=match, | |
342 force=force, editor=editor, extra=extra) | |
343 | |
344 # Refresh all matching big files. It's possible that the | |
345 # commit will end up failing, in which case the big files will | |
346 # stay refreshed. No harm done: the user modified them and | |
347 # asked to commit them, so sooner or later we're going to | |
348 # refresh the standins. Might as well leave them refreshed. | |
349 lfdirstate = lfutil.openlfdirstate(ui, self) | |
350 for standin in standins: | |
351 lfile = lfutil.splitstandin(standin) | |
352 if lfdirstate[lfile] <> 'r': | |
353 lfutil.updatestandin(self, standin) | |
354 lfdirstate.normal(lfile) | |
355 else: | |
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15171
diff
changeset
|
356 lfdirstate.drop(lfile) |
15168 | 357 lfdirstate.write() |
358 | |
359 # Cook up a new matcher that only matches regular files or | |
360 # standins corresponding to the big files requested by the | |
361 # user. Have to modify _files to prevent commit() from | |
362 # complaining "not tracked" for big files. | |
363 lfiles = lfutil.listlfiles(repo) | |
364 match = copy.copy(match) | |
365 orig_matchfn = match.matchfn | |
366 | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
367 # Check both the list of largefiles and the list of |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
368 # standins because if a largefile was removed, it |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
369 # won't be in the list of largefiles at this point |
15168 | 370 match._files += sorted(standins) |
371 | |
372 actualfiles = [] | |
373 for f in match._files: | |
374 fstandin = lfutil.standin(f) | |
375 | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
376 # ignore known largefiles and standins |
15168 | 377 if f in lfiles or fstandin in standins: |
378 continue | |
379 | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
380 # append directory separator to avoid collisions |
15168 | 381 if not fstandin.endswith(os.sep): |
382 fstandin += os.sep | |
383 | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
384 # prevalidate matching standin directories |
15319
9da7e96cd5c2
largefiles: remove redundant any_ function
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
385 if util.any(st for st in match._files |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
386 if st.startswith(fstandin)): |
15168 | 387 continue |
388 actualfiles.append(f) | |
389 match._files = actualfiles | |
390 | |
391 def matchfn(f): | |
392 if orig_matchfn(f): | |
393 return f not in lfiles | |
394 else: | |
395 return f in standins | |
396 | |
397 match.matchfn = matchfn | |
398 return orig(text=text, user=user, date=date, match=match, | |
399 force=force, editor=editor, extra=extra) | |
400 finally: | |
401 wlock.release() | |
402 | |
403 def push(self, remote, force=False, revs=None, newbranch=False): | |
404 o = lfutil.findoutgoing(repo, remote, force) | |
405 if o: | |
406 toupload = set() | |
407 o = repo.changelog.nodesbetween(o, revs)[0] | |
408 for n in o: | |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
409 parents = [p for p in repo.changelog.parents(n) |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
410 if p != node.nullid] |
15168 | 411 ctx = repo[n] |
412 files = set(ctx.files()) | |
413 if len(parents) == 2: | |
414 mc = ctx.manifest() | |
415 mp1 = ctx.parents()[0].manifest() | |
416 mp2 = ctx.parents()[1].manifest() | |
417 for f in mp1: | |
418 if f not in mc: | |
419 files.add(f) | |
420 for f in mp2: | |
421 if f not in mc: | |
422 files.add(f) | |
423 for f in mc: | |
424 if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, | |
425 None): | |
426 files.add(f) | |
427 | |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
428 toupload = toupload.union( |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
429 set([ctx[f].data().strip() |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
430 for f in files |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
431 if lfutil.isstandin(f) and f in ctx])) |
15168 | 432 lfcommands.uploadlfiles(ui, self, remote, toupload) |
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15171
diff
changeset
|
433 return super(lfiles_repo, self).push(remote, force, revs, |
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15171
diff
changeset
|
434 newbranch) |
15168 | 435 |
436 repo.__class__ = lfiles_repo | |
437 | |
438 def checkrequireslfiles(ui, repo, **kwargs): | |
15319
9da7e96cd5c2
largefiles: remove redundant any_ function
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
439 if 'largefiles' not in repo.requirements and util.any( |
15168 | 440 lfutil.shortname+'/' in f[0] for f in repo.store.datafiles()): |
15312
8d862e7b96d4
largefiles: remove 1.9 compat code
Eli Carter <eli.carter@tektronix.com>
parents:
15305
diff
changeset
|
441 repo.requirements.add('largefiles') |
15168 | 442 repo._writerequirements() |
443 | |
444 ui.setconfig('hooks', 'changegroup.lfiles', checkrequireslfiles) | |
445 ui.setconfig('hooks', 'commit.lfiles', checkrequireslfiles) |