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