##// END OF EJS Templates
largefiles: replace invocation of os.path module by vfs in overrides.py...
liscju -
r28715:a7f7b7ac default
parent child Browse files
Show More
@@ -1,1404 +1,1404 b''
1 # Copyright 2009-2010 Gregory P. Ward
1 # Copyright 2009-2010 Gregory P. Ward
2 # Copyright 2009-2010 Intelerad Medical Systems Incorporated
2 # Copyright 2009-2010 Intelerad Medical Systems Incorporated
3 # Copyright 2010-2011 Fog Creek Software
3 # Copyright 2010-2011 Fog Creek Software
4 # Copyright 2010-2011 Unity Technologies
4 # Copyright 2010-2011 Unity Technologies
5 #
5 #
6 # This software may be used and distributed according to the terms of the
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.
7 # GNU General Public License version 2 or any later version.
8
8
9 '''Overridden Mercurial commands and functions for the largefiles extension'''
9 '''Overridden Mercurial commands and functions for the largefiles extension'''
10
10
11 import os
11 import os
12 import copy
12 import copy
13
13
14 from mercurial import hg, util, cmdutil, scmutil, match as match_, \
14 from mercurial import hg, util, cmdutil, scmutil, match as match_, \
15 archival, pathutil, registrar, revset, error
15 archival, pathutil, registrar, revset, error
16 from mercurial.i18n import _
16 from mercurial.i18n import _
17
17
18 import lfutil
18 import lfutil
19 import lfcommands
19 import lfcommands
20 import basestore
20 import basestore
21
21
22 # -- Utility functions: commonly/repeatedly needed functionality ---------------
22 # -- Utility functions: commonly/repeatedly needed functionality ---------------
23
23
24 def composelargefilematcher(match, manifest):
24 def composelargefilematcher(match, manifest):
25 '''create a matcher that matches only the largefiles in the original
25 '''create a matcher that matches only the largefiles in the original
26 matcher'''
26 matcher'''
27 m = copy.copy(match)
27 m = copy.copy(match)
28 lfile = lambda f: lfutil.standin(f) in manifest
28 lfile = lambda f: lfutil.standin(f) in manifest
29 m._files = filter(lfile, m._files)
29 m._files = filter(lfile, m._files)
30 m._fileroots = set(m._files)
30 m._fileroots = set(m._files)
31 m._always = False
31 m._always = False
32 origmatchfn = m.matchfn
32 origmatchfn = m.matchfn
33 m.matchfn = lambda f: lfile(f) and origmatchfn(f)
33 m.matchfn = lambda f: lfile(f) and origmatchfn(f)
34 return m
34 return m
35
35
36 def composenormalfilematcher(match, manifest, exclude=None):
36 def composenormalfilematcher(match, manifest, exclude=None):
37 excluded = set()
37 excluded = set()
38 if exclude is not None:
38 if exclude is not None:
39 excluded.update(exclude)
39 excluded.update(exclude)
40
40
41 m = copy.copy(match)
41 m = copy.copy(match)
42 notlfile = lambda f: not (lfutil.isstandin(f) or lfutil.standin(f) in
42 notlfile = lambda f: not (lfutil.isstandin(f) or lfutil.standin(f) in
43 manifest or f in excluded)
43 manifest or f in excluded)
44 m._files = filter(notlfile, m._files)
44 m._files = filter(notlfile, m._files)
45 m._fileroots = set(m._files)
45 m._fileroots = set(m._files)
46 m._always = False
46 m._always = False
47 origmatchfn = m.matchfn
47 origmatchfn = m.matchfn
48 m.matchfn = lambda f: notlfile(f) and origmatchfn(f)
48 m.matchfn = lambda f: notlfile(f) and origmatchfn(f)
49 return m
49 return m
50
50
51 def installnormalfilesmatchfn(manifest):
51 def installnormalfilesmatchfn(manifest):
52 '''installmatchfn with a matchfn that ignores all largefiles'''
52 '''installmatchfn with a matchfn that ignores all largefiles'''
53 def overridematch(ctx, pats=(), opts=None, globbed=False,
53 def overridematch(ctx, pats=(), opts=None, globbed=False,
54 default='relpath', badfn=None):
54 default='relpath', badfn=None):
55 if opts is None:
55 if opts is None:
56 opts = {}
56 opts = {}
57 match = oldmatch(ctx, pats, opts, globbed, default, badfn=badfn)
57 match = oldmatch(ctx, pats, opts, globbed, default, badfn=badfn)
58 return composenormalfilematcher(match, manifest)
58 return composenormalfilematcher(match, manifest)
59 oldmatch = installmatchfn(overridematch)
59 oldmatch = installmatchfn(overridematch)
60
60
61 def installmatchfn(f):
61 def installmatchfn(f):
62 '''monkey patch the scmutil module with a custom match function.
62 '''monkey patch the scmutil module with a custom match function.
63 Warning: it is monkey patching the _module_ on runtime! Not thread safe!'''
63 Warning: it is monkey patching the _module_ on runtime! Not thread safe!'''
64 oldmatch = scmutil.match
64 oldmatch = scmutil.match
65 setattr(f, 'oldmatch', oldmatch)
65 setattr(f, 'oldmatch', oldmatch)
66 scmutil.match = f
66 scmutil.match = f
67 return oldmatch
67 return oldmatch
68
68
69 def restorematchfn():
69 def restorematchfn():
70 '''restores scmutil.match to what it was before installmatchfn
70 '''restores scmutil.match to what it was before installmatchfn
71 was called. no-op if scmutil.match is its original function.
71 was called. no-op if scmutil.match is its original function.
72
72
73 Note that n calls to installmatchfn will require n calls to
73 Note that n calls to installmatchfn will require n calls to
74 restore the original matchfn.'''
74 restore the original matchfn.'''
75 scmutil.match = getattr(scmutil.match, 'oldmatch')
75 scmutil.match = getattr(scmutil.match, 'oldmatch')
76
76
77 def installmatchandpatsfn(f):
77 def installmatchandpatsfn(f):
78 oldmatchandpats = scmutil.matchandpats
78 oldmatchandpats = scmutil.matchandpats
79 setattr(f, 'oldmatchandpats', oldmatchandpats)
79 setattr(f, 'oldmatchandpats', oldmatchandpats)
80 scmutil.matchandpats = f
80 scmutil.matchandpats = f
81 return oldmatchandpats
81 return oldmatchandpats
82
82
83 def restorematchandpatsfn():
83 def restorematchandpatsfn():
84 '''restores scmutil.matchandpats to what it was before
84 '''restores scmutil.matchandpats to what it was before
85 installmatchandpatsfn was called. No-op if scmutil.matchandpats
85 installmatchandpatsfn was called. No-op if scmutil.matchandpats
86 is its original function.
86 is its original function.
87
87
88 Note that n calls to installmatchandpatsfn will require n calls
88 Note that n calls to installmatchandpatsfn will require n calls
89 to restore the original matchfn.'''
89 to restore the original matchfn.'''
90 scmutil.matchandpats = getattr(scmutil.matchandpats, 'oldmatchandpats',
90 scmutil.matchandpats = getattr(scmutil.matchandpats, 'oldmatchandpats',
91 scmutil.matchandpats)
91 scmutil.matchandpats)
92
92
93 def addlargefiles(ui, repo, isaddremove, matcher, **opts):
93 def addlargefiles(ui, repo, isaddremove, matcher, **opts):
94 large = opts.get('large')
94 large = opts.get('large')
95 lfsize = lfutil.getminsize(
95 lfsize = lfutil.getminsize(
96 ui, lfutil.islfilesrepo(repo), opts.get('lfsize'))
96 ui, lfutil.islfilesrepo(repo), opts.get('lfsize'))
97
97
98 lfmatcher = None
98 lfmatcher = None
99 if lfutil.islfilesrepo(repo):
99 if lfutil.islfilesrepo(repo):
100 lfpats = ui.configlist(lfutil.longname, 'patterns', default=[])
100 lfpats = ui.configlist(lfutil.longname, 'patterns', default=[])
101 if lfpats:
101 if lfpats:
102 lfmatcher = match_.match(repo.root, '', list(lfpats))
102 lfmatcher = match_.match(repo.root, '', list(lfpats))
103
103
104 lfnames = []
104 lfnames = []
105 m = matcher
105 m = matcher
106
106
107 wctx = repo[None]
107 wctx = repo[None]
108 for f in repo.walk(match_.badmatch(m, lambda x, y: None)):
108 for f in repo.walk(match_.badmatch(m, lambda x, y: None)):
109 exact = m.exact(f)
109 exact = m.exact(f)
110 lfile = lfutil.standin(f) in wctx
110 lfile = lfutil.standin(f) in wctx
111 nfile = f in wctx
111 nfile = f in wctx
112 exists = lfile or nfile
112 exists = lfile or nfile
113
113
114 # addremove in core gets fancy with the name, add doesn't
114 # addremove in core gets fancy with the name, add doesn't
115 if isaddremove:
115 if isaddremove:
116 name = m.uipath(f)
116 name = m.uipath(f)
117 else:
117 else:
118 name = m.rel(f)
118 name = m.rel(f)
119
119
120 # Don't warn the user when they attempt to add a normal tracked file.
120 # Don't warn the user when they attempt to add a normal tracked file.
121 # The normal add code will do that for us.
121 # The normal add code will do that for us.
122 if exact and exists:
122 if exact and exists:
123 if lfile:
123 if lfile:
124 ui.warn(_('%s already a largefile\n') % name)
124 ui.warn(_('%s already a largefile\n') % name)
125 continue
125 continue
126
126
127 if (exact or not exists) and not lfutil.isstandin(f):
127 if (exact or not exists) and not lfutil.isstandin(f):
128 # In case the file was removed previously, but not committed
128 # In case the file was removed previously, but not committed
129 # (issue3507)
129 # (issue3507)
130 if not repo.wvfs.exists(f):
130 if not repo.wvfs.exists(f):
131 continue
131 continue
132
132
133 abovemin = (lfsize and
133 abovemin = (lfsize and
134 repo.wvfs.lstat(f).st_size >= lfsize * 1024 * 1024)
134 repo.wvfs.lstat(f).st_size >= lfsize * 1024 * 1024)
135 if large or abovemin or (lfmatcher and lfmatcher(f)):
135 if large or abovemin or (lfmatcher and lfmatcher(f)):
136 lfnames.append(f)
136 lfnames.append(f)
137 if ui.verbose or not exact:
137 if ui.verbose or not exact:
138 ui.status(_('adding %s as a largefile\n') % name)
138 ui.status(_('adding %s as a largefile\n') % name)
139
139
140 bad = []
140 bad = []
141
141
142 # Need to lock, otherwise there could be a race condition between
142 # Need to lock, otherwise there could be a race condition between
143 # when standins are created and added to the repo.
143 # when standins are created and added to the repo.
144 with repo.wlock():
144 with repo.wlock():
145 if not opts.get('dry_run'):
145 if not opts.get('dry_run'):
146 standins = []
146 standins = []
147 lfdirstate = lfutil.openlfdirstate(ui, repo)
147 lfdirstate = lfutil.openlfdirstate(ui, repo)
148 for f in lfnames:
148 for f in lfnames:
149 standinname = lfutil.standin(f)
149 standinname = lfutil.standin(f)
150 lfutil.writestandin(repo, standinname, hash='',
150 lfutil.writestandin(repo, standinname, hash='',
151 executable=lfutil.getexecutable(repo.wjoin(f)))
151 executable=lfutil.getexecutable(repo.wjoin(f)))
152 standins.append(standinname)
152 standins.append(standinname)
153 if lfdirstate[f] == 'r':
153 if lfdirstate[f] == 'r':
154 lfdirstate.normallookup(f)
154 lfdirstate.normallookup(f)
155 else:
155 else:
156 lfdirstate.add(f)
156 lfdirstate.add(f)
157 lfdirstate.write()
157 lfdirstate.write()
158 bad += [lfutil.splitstandin(f)
158 bad += [lfutil.splitstandin(f)
159 for f in repo[None].add(standins)
159 for f in repo[None].add(standins)
160 if f in m.files()]
160 if f in m.files()]
161
161
162 added = [f for f in lfnames if f not in bad]
162 added = [f for f in lfnames if f not in bad]
163 return added, bad
163 return added, bad
164
164
165 def removelargefiles(ui, repo, isaddremove, matcher, **opts):
165 def removelargefiles(ui, repo, isaddremove, matcher, **opts):
166 after = opts.get('after')
166 after = opts.get('after')
167 m = composelargefilematcher(matcher, repo[None].manifest())
167 m = composelargefilematcher(matcher, repo[None].manifest())
168 try:
168 try:
169 repo.lfstatus = True
169 repo.lfstatus = True
170 s = repo.status(match=m, clean=not isaddremove)
170 s = repo.status(match=m, clean=not isaddremove)
171 finally:
171 finally:
172 repo.lfstatus = False
172 repo.lfstatus = False
173 manifest = repo[None].manifest()
173 manifest = repo[None].manifest()
174 modified, added, deleted, clean = [[f for f in list
174 modified, added, deleted, clean = [[f for f in list
175 if lfutil.standin(f) in manifest]
175 if lfutil.standin(f) in manifest]
176 for list in (s.modified, s.added,
176 for list in (s.modified, s.added,
177 s.deleted, s.clean)]
177 s.deleted, s.clean)]
178
178
179 def warn(files, msg):
179 def warn(files, msg):
180 for f in files:
180 for f in files:
181 ui.warn(msg % m.rel(f))
181 ui.warn(msg % m.rel(f))
182 return int(len(files) > 0)
182 return int(len(files) > 0)
183
183
184 result = 0
184 result = 0
185
185
186 if after:
186 if after:
187 remove = deleted
187 remove = deleted
188 result = warn(modified + added + clean,
188 result = warn(modified + added + clean,
189 _('not removing %s: file still exists\n'))
189 _('not removing %s: file still exists\n'))
190 else:
190 else:
191 remove = deleted + clean
191 remove = deleted + clean
192 result = warn(modified, _('not removing %s: file is modified (use -f'
192 result = warn(modified, _('not removing %s: file is modified (use -f'
193 ' to force removal)\n'))
193 ' to force removal)\n'))
194 result = warn(added, _('not removing %s: file has been marked for add'
194 result = warn(added, _('not removing %s: file has been marked for add'
195 ' (use forget to undo)\n')) or result
195 ' (use forget to undo)\n')) or result
196
196
197 # Need to lock because standin files are deleted then removed from the
197 # Need to lock because standin files are deleted then removed from the
198 # repository and we could race in-between.
198 # repository and we could race in-between.
199 with repo.wlock():
199 with repo.wlock():
200 lfdirstate = lfutil.openlfdirstate(ui, repo)
200 lfdirstate = lfutil.openlfdirstate(ui, repo)
201 for f in sorted(remove):
201 for f in sorted(remove):
202 if ui.verbose or not m.exact(f):
202 if ui.verbose or not m.exact(f):
203 # addremove in core gets fancy with the name, remove doesn't
203 # addremove in core gets fancy with the name, remove doesn't
204 if isaddremove:
204 if isaddremove:
205 name = m.uipath(f)
205 name = m.uipath(f)
206 else:
206 else:
207 name = m.rel(f)
207 name = m.rel(f)
208 ui.status(_('removing %s\n') % name)
208 ui.status(_('removing %s\n') % name)
209
209
210 if not opts.get('dry_run'):
210 if not opts.get('dry_run'):
211 if not after:
211 if not after:
212 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
212 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
213
213
214 if opts.get('dry_run'):
214 if opts.get('dry_run'):
215 return result
215 return result
216
216
217 remove = [lfutil.standin(f) for f in remove]
217 remove = [lfutil.standin(f) for f in remove]
218 # If this is being called by addremove, let the original addremove
218 # If this is being called by addremove, let the original addremove
219 # function handle this.
219 # function handle this.
220 if not isaddremove:
220 if not isaddremove:
221 for f in remove:
221 for f in remove:
222 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
222 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
223 repo[None].forget(remove)
223 repo[None].forget(remove)
224
224
225 for f in remove:
225 for f in remove:
226 lfutil.synclfdirstate(repo, lfdirstate, lfutil.splitstandin(f),
226 lfutil.synclfdirstate(repo, lfdirstate, lfutil.splitstandin(f),
227 False)
227 False)
228
228
229 lfdirstate.write()
229 lfdirstate.write()
230
230
231 return result
231 return result
232
232
233 # For overriding mercurial.hgweb.webcommands so that largefiles will
233 # For overriding mercurial.hgweb.webcommands so that largefiles will
234 # appear at their right place in the manifests.
234 # appear at their right place in the manifests.
235 def decodepath(orig, path):
235 def decodepath(orig, path):
236 return lfutil.splitstandin(path) or path
236 return lfutil.splitstandin(path) or path
237
237
238 # -- Wrappers: modify existing commands --------------------------------
238 # -- Wrappers: modify existing commands --------------------------------
239
239
240 def overrideadd(orig, ui, repo, *pats, **opts):
240 def overrideadd(orig, ui, repo, *pats, **opts):
241 if opts.get('normal') and opts.get('large'):
241 if opts.get('normal') and opts.get('large'):
242 raise error.Abort(_('--normal cannot be used with --large'))
242 raise error.Abort(_('--normal cannot be used with --large'))
243 return orig(ui, repo, *pats, **opts)
243 return orig(ui, repo, *pats, **opts)
244
244
245 def cmdutiladd(orig, ui, repo, matcher, prefix, explicitonly, **opts):
245 def cmdutiladd(orig, ui, repo, matcher, prefix, explicitonly, **opts):
246 # The --normal flag short circuits this override
246 # The --normal flag short circuits this override
247 if opts.get('normal'):
247 if opts.get('normal'):
248 return orig(ui, repo, matcher, prefix, explicitonly, **opts)
248 return orig(ui, repo, matcher, prefix, explicitonly, **opts)
249
249
250 ladded, lbad = addlargefiles(ui, repo, False, matcher, **opts)
250 ladded, lbad = addlargefiles(ui, repo, False, matcher, **opts)
251 normalmatcher = composenormalfilematcher(matcher, repo[None].manifest(),
251 normalmatcher = composenormalfilematcher(matcher, repo[None].manifest(),
252 ladded)
252 ladded)
253 bad = orig(ui, repo, normalmatcher, prefix, explicitonly, **opts)
253 bad = orig(ui, repo, normalmatcher, prefix, explicitonly, **opts)
254
254
255 bad.extend(f for f in lbad)
255 bad.extend(f for f in lbad)
256 return bad
256 return bad
257
257
258 def cmdutilremove(orig, ui, repo, matcher, prefix, after, force, subrepos):
258 def cmdutilremove(orig, ui, repo, matcher, prefix, after, force, subrepos):
259 normalmatcher = composenormalfilematcher(matcher, repo[None].manifest())
259 normalmatcher = composenormalfilematcher(matcher, repo[None].manifest())
260 result = orig(ui, repo, normalmatcher, prefix, after, force, subrepos)
260 result = orig(ui, repo, normalmatcher, prefix, after, force, subrepos)
261 return removelargefiles(ui, repo, False, matcher, after=after,
261 return removelargefiles(ui, repo, False, matcher, after=after,
262 force=force) or result
262 force=force) or result
263
263
264 def overridestatusfn(orig, repo, rev2, **opts):
264 def overridestatusfn(orig, repo, rev2, **opts):
265 try:
265 try:
266 repo._repo.lfstatus = True
266 repo._repo.lfstatus = True
267 return orig(repo, rev2, **opts)
267 return orig(repo, rev2, **opts)
268 finally:
268 finally:
269 repo._repo.lfstatus = False
269 repo._repo.lfstatus = False
270
270
271 def overridestatus(orig, ui, repo, *pats, **opts):
271 def overridestatus(orig, ui, repo, *pats, **opts):
272 try:
272 try:
273 repo.lfstatus = True
273 repo.lfstatus = True
274 return orig(ui, repo, *pats, **opts)
274 return orig(ui, repo, *pats, **opts)
275 finally:
275 finally:
276 repo.lfstatus = False
276 repo.lfstatus = False
277
277
278 def overridedirty(orig, repo, ignoreupdate=False):
278 def overridedirty(orig, repo, ignoreupdate=False):
279 try:
279 try:
280 repo._repo.lfstatus = True
280 repo._repo.lfstatus = True
281 return orig(repo, ignoreupdate)
281 return orig(repo, ignoreupdate)
282 finally:
282 finally:
283 repo._repo.lfstatus = False
283 repo._repo.lfstatus = False
284
284
285 def overridelog(orig, ui, repo, *pats, **opts):
285 def overridelog(orig, ui, repo, *pats, **opts):
286 def overridematchandpats(ctx, pats=(), opts=None, globbed=False,
286 def overridematchandpats(ctx, pats=(), opts=None, globbed=False,
287 default='relpath', badfn=None):
287 default='relpath', badfn=None):
288 """Matcher that merges root directory with .hglf, suitable for log.
288 """Matcher that merges root directory with .hglf, suitable for log.
289 It is still possible to match .hglf directly.
289 It is still possible to match .hglf directly.
290 For any listed files run log on the standin too.
290 For any listed files run log on the standin too.
291 matchfn tries both the given filename and with .hglf stripped.
291 matchfn tries both the given filename and with .hglf stripped.
292 """
292 """
293 if opts is None:
293 if opts is None:
294 opts = {}
294 opts = {}
295 matchandpats = oldmatchandpats(ctx, pats, opts, globbed, default,
295 matchandpats = oldmatchandpats(ctx, pats, opts, globbed, default,
296 badfn=badfn)
296 badfn=badfn)
297 m, p = copy.copy(matchandpats)
297 m, p = copy.copy(matchandpats)
298
298
299 if m.always():
299 if m.always():
300 # We want to match everything anyway, so there's no benefit trying
300 # We want to match everything anyway, so there's no benefit trying
301 # to add standins.
301 # to add standins.
302 return matchandpats
302 return matchandpats
303
303
304 pats = set(p)
304 pats = set(p)
305
305
306 def fixpats(pat, tostandin=lfutil.standin):
306 def fixpats(pat, tostandin=lfutil.standin):
307 if pat.startswith('set:'):
307 if pat.startswith('set:'):
308 return pat
308 return pat
309
309
310 kindpat = match_._patsplit(pat, None)
310 kindpat = match_._patsplit(pat, None)
311
311
312 if kindpat[0] is not None:
312 if kindpat[0] is not None:
313 return kindpat[0] + ':' + tostandin(kindpat[1])
313 return kindpat[0] + ':' + tostandin(kindpat[1])
314 return tostandin(kindpat[1])
314 return tostandin(kindpat[1])
315
315
316 if m._cwd:
316 if m._cwd:
317 hglf = lfutil.shortname
317 hglf = lfutil.shortname
318 back = util.pconvert(m.rel(hglf)[:-len(hglf)])
318 back = util.pconvert(m.rel(hglf)[:-len(hglf)])
319
319
320 def tostandin(f):
320 def tostandin(f):
321 # The file may already be a standin, so truncate the back
321 # The file may already be a standin, so truncate the back
322 # prefix and test before mangling it. This avoids turning
322 # prefix and test before mangling it. This avoids turning
323 # 'glob:../.hglf/foo*' into 'glob:../.hglf/../.hglf/foo*'.
323 # 'glob:../.hglf/foo*' into 'glob:../.hglf/../.hglf/foo*'.
324 if f.startswith(back) and lfutil.splitstandin(f[len(back):]):
324 if f.startswith(back) and lfutil.splitstandin(f[len(back):]):
325 return f
325 return f
326
326
327 # An absolute path is from outside the repo, so truncate the
327 # An absolute path is from outside the repo, so truncate the
328 # path to the root before building the standin. Otherwise cwd
328 # path to the root before building the standin. Otherwise cwd
329 # is somewhere in the repo, relative to root, and needs to be
329 # is somewhere in the repo, relative to root, and needs to be
330 # prepended before building the standin.
330 # prepended before building the standin.
331 if os.path.isabs(m._cwd):
331 if os.path.isabs(m._cwd):
332 f = f[len(back):]
332 f = f[len(back):]
333 else:
333 else:
334 f = m._cwd + '/' + f
334 f = m._cwd + '/' + f
335 return back + lfutil.standin(f)
335 return back + lfutil.standin(f)
336
336
337 pats.update(fixpats(f, tostandin) for f in p)
337 pats.update(fixpats(f, tostandin) for f in p)
338 else:
338 else:
339 def tostandin(f):
339 def tostandin(f):
340 if lfutil.splitstandin(f):
340 if lfutil.splitstandin(f):
341 return f
341 return f
342 return lfutil.standin(f)
342 return lfutil.standin(f)
343 pats.update(fixpats(f, tostandin) for f in p)
343 pats.update(fixpats(f, tostandin) for f in p)
344
344
345 for i in range(0, len(m._files)):
345 for i in range(0, len(m._files)):
346 # Don't add '.hglf' to m.files, since that is already covered by '.'
346 # Don't add '.hglf' to m.files, since that is already covered by '.'
347 if m._files[i] == '.':
347 if m._files[i] == '.':
348 continue
348 continue
349 standin = lfutil.standin(m._files[i])
349 standin = lfutil.standin(m._files[i])
350 # If the "standin" is a directory, append instead of replace to
350 # If the "standin" is a directory, append instead of replace to
351 # support naming a directory on the command line with only
351 # support naming a directory on the command line with only
352 # largefiles. The original directory is kept to support normal
352 # largefiles. The original directory is kept to support normal
353 # files.
353 # files.
354 if standin in repo[ctx.node()]:
354 if standin in repo[ctx.node()]:
355 m._files[i] = standin
355 m._files[i] = standin
356 elif m._files[i] not in repo[ctx.node()] \
356 elif m._files[i] not in repo[ctx.node()] \
357 and repo.wvfs.isdir(standin):
357 and repo.wvfs.isdir(standin):
358 m._files.append(standin)
358 m._files.append(standin)
359
359
360 m._fileroots = set(m._files)
360 m._fileroots = set(m._files)
361 m._always = False
361 m._always = False
362 origmatchfn = m.matchfn
362 origmatchfn = m.matchfn
363 def lfmatchfn(f):
363 def lfmatchfn(f):
364 lf = lfutil.splitstandin(f)
364 lf = lfutil.splitstandin(f)
365 if lf is not None and origmatchfn(lf):
365 if lf is not None and origmatchfn(lf):
366 return True
366 return True
367 r = origmatchfn(f)
367 r = origmatchfn(f)
368 return r
368 return r
369 m.matchfn = lfmatchfn
369 m.matchfn = lfmatchfn
370
370
371 ui.debug('updated patterns: %s\n' % sorted(pats))
371 ui.debug('updated patterns: %s\n' % sorted(pats))
372 return m, pats
372 return m, pats
373
373
374 # For hg log --patch, the match object is used in two different senses:
374 # For hg log --patch, the match object is used in two different senses:
375 # (1) to determine what revisions should be printed out, and
375 # (1) to determine what revisions should be printed out, and
376 # (2) to determine what files to print out diffs for.
376 # (2) to determine what files to print out diffs for.
377 # The magic matchandpats override should be used for case (1) but not for
377 # The magic matchandpats override should be used for case (1) but not for
378 # case (2).
378 # case (2).
379 def overridemakelogfilematcher(repo, pats, opts, badfn=None):
379 def overridemakelogfilematcher(repo, pats, opts, badfn=None):
380 wctx = repo[None]
380 wctx = repo[None]
381 match, pats = oldmatchandpats(wctx, pats, opts, badfn=badfn)
381 match, pats = oldmatchandpats(wctx, pats, opts, badfn=badfn)
382 return lambda rev: match
382 return lambda rev: match
383
383
384 oldmatchandpats = installmatchandpatsfn(overridematchandpats)
384 oldmatchandpats = installmatchandpatsfn(overridematchandpats)
385 oldmakelogfilematcher = cmdutil._makenofollowlogfilematcher
385 oldmakelogfilematcher = cmdutil._makenofollowlogfilematcher
386 setattr(cmdutil, '_makenofollowlogfilematcher', overridemakelogfilematcher)
386 setattr(cmdutil, '_makenofollowlogfilematcher', overridemakelogfilematcher)
387
387
388 try:
388 try:
389 return orig(ui, repo, *pats, **opts)
389 return orig(ui, repo, *pats, **opts)
390 finally:
390 finally:
391 restorematchandpatsfn()
391 restorematchandpatsfn()
392 setattr(cmdutil, '_makenofollowlogfilematcher', oldmakelogfilematcher)
392 setattr(cmdutil, '_makenofollowlogfilematcher', oldmakelogfilematcher)
393
393
394 def overrideverify(orig, ui, repo, *pats, **opts):
394 def overrideverify(orig, ui, repo, *pats, **opts):
395 large = opts.pop('large', False)
395 large = opts.pop('large', False)
396 all = opts.pop('lfa', False)
396 all = opts.pop('lfa', False)
397 contents = opts.pop('lfc', False)
397 contents = opts.pop('lfc', False)
398
398
399 result = orig(ui, repo, *pats, **opts)
399 result = orig(ui, repo, *pats, **opts)
400 if large or all or contents:
400 if large or all or contents:
401 result = result or lfcommands.verifylfiles(ui, repo, all, contents)
401 result = result or lfcommands.verifylfiles(ui, repo, all, contents)
402 return result
402 return result
403
403
404 def overridedebugstate(orig, ui, repo, *pats, **opts):
404 def overridedebugstate(orig, ui, repo, *pats, **opts):
405 large = opts.pop('large', False)
405 large = opts.pop('large', False)
406 if large:
406 if large:
407 class fakerepo(object):
407 class fakerepo(object):
408 dirstate = lfutil.openlfdirstate(ui, repo)
408 dirstate = lfutil.openlfdirstate(ui, repo)
409 orig(ui, fakerepo, *pats, **opts)
409 orig(ui, fakerepo, *pats, **opts)
410 else:
410 else:
411 orig(ui, repo, *pats, **opts)
411 orig(ui, repo, *pats, **opts)
412
412
413 # Before starting the manifest merge, merge.updates will call
413 # Before starting the manifest merge, merge.updates will call
414 # _checkunknownfile to check if there are any files in the merged-in
414 # _checkunknownfile to check if there are any files in the merged-in
415 # changeset that collide with unknown files in the working copy.
415 # changeset that collide with unknown files in the working copy.
416 #
416 #
417 # The largefiles are seen as unknown, so this prevents us from merging
417 # The largefiles are seen as unknown, so this prevents us from merging
418 # in a file 'foo' if we already have a largefile with the same name.
418 # in a file 'foo' if we already have a largefile with the same name.
419 #
419 #
420 # The overridden function filters the unknown files by removing any
420 # The overridden function filters the unknown files by removing any
421 # largefiles. This makes the merge proceed and we can then handle this
421 # largefiles. This makes the merge proceed and we can then handle this
422 # case further in the overridden calculateupdates function below.
422 # case further in the overridden calculateupdates function below.
423 def overridecheckunknownfile(origfn, repo, wctx, mctx, f, f2=None):
423 def overridecheckunknownfile(origfn, repo, wctx, mctx, f, f2=None):
424 if lfutil.standin(repo.dirstate.normalize(f)) in wctx:
424 if lfutil.standin(repo.dirstate.normalize(f)) in wctx:
425 return False
425 return False
426 return origfn(repo, wctx, mctx, f, f2)
426 return origfn(repo, wctx, mctx, f, f2)
427
427
428 # The manifest merge handles conflicts on the manifest level. We want
428 # The manifest merge handles conflicts on the manifest level. We want
429 # to handle changes in largefile-ness of files at this level too.
429 # to handle changes in largefile-ness of files at this level too.
430 #
430 #
431 # The strategy is to run the original calculateupdates and then process
431 # The strategy is to run the original calculateupdates and then process
432 # the action list it outputs. There are two cases we need to deal with:
432 # the action list it outputs. There are two cases we need to deal with:
433 #
433 #
434 # 1. Normal file in p1, largefile in p2. Here the largefile is
434 # 1. Normal file in p1, largefile in p2. Here the largefile is
435 # detected via its standin file, which will enter the working copy
435 # detected via its standin file, which will enter the working copy
436 # with a "get" action. It is not "merge" since the standin is all
436 # with a "get" action. It is not "merge" since the standin is all
437 # Mercurial is concerned with at this level -- the link to the
437 # Mercurial is concerned with at this level -- the link to the
438 # existing normal file is not relevant here.
438 # existing normal file is not relevant here.
439 #
439 #
440 # 2. Largefile in p1, normal file in p2. Here we get a "merge" action
440 # 2. Largefile in p1, normal file in p2. Here we get a "merge" action
441 # since the largefile will be present in the working copy and
441 # since the largefile will be present in the working copy and
442 # different from the normal file in p2. Mercurial therefore
442 # different from the normal file in p2. Mercurial therefore
443 # triggers a merge action.
443 # triggers a merge action.
444 #
444 #
445 # In both cases, we prompt the user and emit new actions to either
445 # In both cases, we prompt the user and emit new actions to either
446 # remove the standin (if the normal file was kept) or to remove the
446 # remove the standin (if the normal file was kept) or to remove the
447 # normal file and get the standin (if the largefile was kept). The
447 # normal file and get the standin (if the largefile was kept). The
448 # default prompt answer is to use the largefile version since it was
448 # default prompt answer is to use the largefile version since it was
449 # presumably changed on purpose.
449 # presumably changed on purpose.
450 #
450 #
451 # Finally, the merge.applyupdates function will then take care of
451 # Finally, the merge.applyupdates function will then take care of
452 # writing the files into the working copy and lfcommands.updatelfiles
452 # writing the files into the working copy and lfcommands.updatelfiles
453 # will update the largefiles.
453 # will update the largefiles.
454 def overridecalculateupdates(origfn, repo, p1, p2, pas, branchmerge, force,
454 def overridecalculateupdates(origfn, repo, p1, p2, pas, branchmerge, force,
455 acceptremote, *args, **kwargs):
455 acceptremote, *args, **kwargs):
456 overwrite = force and not branchmerge
456 overwrite = force and not branchmerge
457 actions, diverge, renamedelete = origfn(
457 actions, diverge, renamedelete = origfn(
458 repo, p1, p2, pas, branchmerge, force, acceptremote, *args, **kwargs)
458 repo, p1, p2, pas, branchmerge, force, acceptremote, *args, **kwargs)
459
459
460 if overwrite:
460 if overwrite:
461 return actions, diverge, renamedelete
461 return actions, diverge, renamedelete
462
462
463 # Convert to dictionary with filename as key and action as value.
463 # Convert to dictionary with filename as key and action as value.
464 lfiles = set()
464 lfiles = set()
465 for f in actions:
465 for f in actions:
466 splitstandin = lfutil.splitstandin(f)
466 splitstandin = lfutil.splitstandin(f)
467 if splitstandin in p1:
467 if splitstandin in p1:
468 lfiles.add(splitstandin)
468 lfiles.add(splitstandin)
469 elif lfutil.standin(f) in p1:
469 elif lfutil.standin(f) in p1:
470 lfiles.add(f)
470 lfiles.add(f)
471
471
472 for lfile in sorted(lfiles):
472 for lfile in sorted(lfiles):
473 standin = lfutil.standin(lfile)
473 standin = lfutil.standin(lfile)
474 (lm, largs, lmsg) = actions.get(lfile, (None, None, None))
474 (lm, largs, lmsg) = actions.get(lfile, (None, None, None))
475 (sm, sargs, smsg) = actions.get(standin, (None, None, None))
475 (sm, sargs, smsg) = actions.get(standin, (None, None, None))
476 if sm in ('g', 'dc') and lm != 'r':
476 if sm in ('g', 'dc') and lm != 'r':
477 if sm == 'dc':
477 if sm == 'dc':
478 f1, f2, fa, move, anc = sargs
478 f1, f2, fa, move, anc = sargs
479 sargs = (p2[f2].flags(), False)
479 sargs = (p2[f2].flags(), False)
480 # Case 1: normal file in the working copy, largefile in
480 # Case 1: normal file in the working copy, largefile in
481 # the second parent
481 # the second parent
482 usermsg = _('remote turned local normal file %s into a largefile\n'
482 usermsg = _('remote turned local normal file %s into a largefile\n'
483 'use (l)argefile or keep (n)ormal file?'
483 'use (l)argefile or keep (n)ormal file?'
484 '$$ &Largefile $$ &Normal file') % lfile
484 '$$ &Largefile $$ &Normal file') % lfile
485 if repo.ui.promptchoice(usermsg, 0) == 0: # pick remote largefile
485 if repo.ui.promptchoice(usermsg, 0) == 0: # pick remote largefile
486 actions[lfile] = ('r', None, 'replaced by standin')
486 actions[lfile] = ('r', None, 'replaced by standin')
487 actions[standin] = ('g', sargs, 'replaces standin')
487 actions[standin] = ('g', sargs, 'replaces standin')
488 else: # keep local normal file
488 else: # keep local normal file
489 actions[lfile] = ('k', None, 'replaces standin')
489 actions[lfile] = ('k', None, 'replaces standin')
490 if branchmerge:
490 if branchmerge:
491 actions[standin] = ('k', None, 'replaced by non-standin')
491 actions[standin] = ('k', None, 'replaced by non-standin')
492 else:
492 else:
493 actions[standin] = ('r', None, 'replaced by non-standin')
493 actions[standin] = ('r', None, 'replaced by non-standin')
494 elif lm in ('g', 'dc') and sm != 'r':
494 elif lm in ('g', 'dc') and sm != 'r':
495 if lm == 'dc':
495 if lm == 'dc':
496 f1, f2, fa, move, anc = largs
496 f1, f2, fa, move, anc = largs
497 largs = (p2[f2].flags(), False)
497 largs = (p2[f2].flags(), False)
498 # Case 2: largefile in the working copy, normal file in
498 # Case 2: largefile in the working copy, normal file in
499 # the second parent
499 # the second parent
500 usermsg = _('remote turned local largefile %s into a normal file\n'
500 usermsg = _('remote turned local largefile %s into a normal file\n'
501 'keep (l)argefile or use (n)ormal file?'
501 'keep (l)argefile or use (n)ormal file?'
502 '$$ &Largefile $$ &Normal file') % lfile
502 '$$ &Largefile $$ &Normal file') % lfile
503 if repo.ui.promptchoice(usermsg, 0) == 0: # keep local largefile
503 if repo.ui.promptchoice(usermsg, 0) == 0: # keep local largefile
504 if branchmerge:
504 if branchmerge:
505 # largefile can be restored from standin safely
505 # largefile can be restored from standin safely
506 actions[lfile] = ('k', None, 'replaced by standin')
506 actions[lfile] = ('k', None, 'replaced by standin')
507 actions[standin] = ('k', None, 'replaces standin')
507 actions[standin] = ('k', None, 'replaces standin')
508 else:
508 else:
509 # "lfile" should be marked as "removed" without
509 # "lfile" should be marked as "removed" without
510 # removal of itself
510 # removal of itself
511 actions[lfile] = ('lfmr', None,
511 actions[lfile] = ('lfmr', None,
512 'forget non-standin largefile')
512 'forget non-standin largefile')
513
513
514 # linear-merge should treat this largefile as 're-added'
514 # linear-merge should treat this largefile as 're-added'
515 actions[standin] = ('a', None, 'keep standin')
515 actions[standin] = ('a', None, 'keep standin')
516 else: # pick remote normal file
516 else: # pick remote normal file
517 actions[lfile] = ('g', largs, 'replaces standin')
517 actions[lfile] = ('g', largs, 'replaces standin')
518 actions[standin] = ('r', None, 'replaced by non-standin')
518 actions[standin] = ('r', None, 'replaced by non-standin')
519
519
520 return actions, diverge, renamedelete
520 return actions, diverge, renamedelete
521
521
522 def mergerecordupdates(orig, repo, actions, branchmerge):
522 def mergerecordupdates(orig, repo, actions, branchmerge):
523 if 'lfmr' in actions:
523 if 'lfmr' in actions:
524 lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
524 lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
525 for lfile, args, msg in actions['lfmr']:
525 for lfile, args, msg in actions['lfmr']:
526 # this should be executed before 'orig', to execute 'remove'
526 # this should be executed before 'orig', to execute 'remove'
527 # before all other actions
527 # before all other actions
528 repo.dirstate.remove(lfile)
528 repo.dirstate.remove(lfile)
529 # make sure lfile doesn't get synclfdirstate'd as normal
529 # make sure lfile doesn't get synclfdirstate'd as normal
530 lfdirstate.add(lfile)
530 lfdirstate.add(lfile)
531 lfdirstate.write()
531 lfdirstate.write()
532
532
533 return orig(repo, actions, branchmerge)
533 return orig(repo, actions, branchmerge)
534
534
535
535
536 # Override filemerge to prompt the user about how they wish to merge
536 # Override filemerge to prompt the user about how they wish to merge
537 # largefiles. This will handle identical edits without prompting the user.
537 # largefiles. This will handle identical edits without prompting the user.
538 def overridefilemerge(origfn, premerge, repo, mynode, orig, fcd, fco, fca,
538 def overridefilemerge(origfn, premerge, repo, mynode, orig, fcd, fco, fca,
539 labels=None):
539 labels=None):
540 if not lfutil.isstandin(orig) or fcd.isabsent() or fco.isabsent():
540 if not lfutil.isstandin(orig) or fcd.isabsent() or fco.isabsent():
541 return origfn(premerge, repo, mynode, orig, fcd, fco, fca,
541 return origfn(premerge, repo, mynode, orig, fcd, fco, fca,
542 labels=labels)
542 labels=labels)
543
543
544 ahash = fca.data().strip().lower()
544 ahash = fca.data().strip().lower()
545 dhash = fcd.data().strip().lower()
545 dhash = fcd.data().strip().lower()
546 ohash = fco.data().strip().lower()
546 ohash = fco.data().strip().lower()
547 if (ohash != ahash and
547 if (ohash != ahash and
548 ohash != dhash and
548 ohash != dhash and
549 (dhash == ahash or
549 (dhash == ahash or
550 repo.ui.promptchoice(
550 repo.ui.promptchoice(
551 _('largefile %s has a merge conflict\nancestor was %s\n'
551 _('largefile %s has a merge conflict\nancestor was %s\n'
552 'keep (l)ocal %s or\ntake (o)ther %s?'
552 'keep (l)ocal %s or\ntake (o)ther %s?'
553 '$$ &Local $$ &Other') %
553 '$$ &Local $$ &Other') %
554 (lfutil.splitstandin(orig), ahash, dhash, ohash),
554 (lfutil.splitstandin(orig), ahash, dhash, ohash),
555 0) == 1)):
555 0) == 1)):
556 repo.wwrite(fcd.path(), fco.data(), fco.flags())
556 repo.wwrite(fcd.path(), fco.data(), fco.flags())
557 return True, 0, False
557 return True, 0, False
558
558
559 def copiespathcopies(orig, ctx1, ctx2, match=None):
559 def copiespathcopies(orig, ctx1, ctx2, match=None):
560 copies = orig(ctx1, ctx2, match=match)
560 copies = orig(ctx1, ctx2, match=match)
561 updated = {}
561 updated = {}
562
562
563 for k, v in copies.iteritems():
563 for k, v in copies.iteritems():
564 updated[lfutil.splitstandin(k) or k] = lfutil.splitstandin(v) or v
564 updated[lfutil.splitstandin(k) or k] = lfutil.splitstandin(v) or v
565
565
566 return updated
566 return updated
567
567
568 # Copy first changes the matchers to match standins instead of
568 # Copy first changes the matchers to match standins instead of
569 # largefiles. Then it overrides util.copyfile in that function it
569 # largefiles. Then it overrides util.copyfile in that function it
570 # checks if the destination largefile already exists. It also keeps a
570 # checks if the destination largefile already exists. It also keeps a
571 # list of copied files so that the largefiles can be copied and the
571 # list of copied files so that the largefiles can be copied and the
572 # dirstate updated.
572 # dirstate updated.
573 def overridecopy(orig, ui, repo, pats, opts, rename=False):
573 def overridecopy(orig, ui, repo, pats, opts, rename=False):
574 # doesn't remove largefile on rename
574 # doesn't remove largefile on rename
575 if len(pats) < 2:
575 if len(pats) < 2:
576 # this isn't legal, let the original function deal with it
576 # this isn't legal, let the original function deal with it
577 return orig(ui, repo, pats, opts, rename)
577 return orig(ui, repo, pats, opts, rename)
578
578
579 # This could copy both lfiles and normal files in one command,
579 # This could copy both lfiles and normal files in one command,
580 # but we don't want to do that. First replace their matcher to
580 # but we don't want to do that. First replace their matcher to
581 # only match normal files and run it, then replace it to just
581 # only match normal files and run it, then replace it to just
582 # match largefiles and run it again.
582 # match largefiles and run it again.
583 nonormalfiles = False
583 nonormalfiles = False
584 nolfiles = False
584 nolfiles = False
585 installnormalfilesmatchfn(repo[None].manifest())
585 installnormalfilesmatchfn(repo[None].manifest())
586 try:
586 try:
587 result = orig(ui, repo, pats, opts, rename)
587 result = orig(ui, repo, pats, opts, rename)
588 except error.Abort as e:
588 except error.Abort as e:
589 if str(e) != _('no files to copy'):
589 if str(e) != _('no files to copy'):
590 raise e
590 raise e
591 else:
591 else:
592 nonormalfiles = True
592 nonormalfiles = True
593 result = 0
593 result = 0
594 finally:
594 finally:
595 restorematchfn()
595 restorematchfn()
596
596
597 # The first rename can cause our current working directory to be removed.
597 # The first rename can cause our current working directory to be removed.
598 # In that case there is nothing left to copy/rename so just quit.
598 # In that case there is nothing left to copy/rename so just quit.
599 try:
599 try:
600 repo.getcwd()
600 repo.getcwd()
601 except OSError:
601 except OSError:
602 return result
602 return result
603
603
604 def makestandin(relpath):
604 def makestandin(relpath):
605 path = pathutil.canonpath(repo.root, repo.getcwd(), relpath)
605 path = pathutil.canonpath(repo.root, repo.getcwd(), relpath)
606 return os.path.join(repo.wjoin(lfutil.standin(path)))
606 return repo.wvfs.join(lfutil.standin(path))
607
607
608 fullpats = scmutil.expandpats(pats)
608 fullpats = scmutil.expandpats(pats)
609 dest = fullpats[-1]
609 dest = fullpats[-1]
610
610
611 if os.path.isdir(dest):
611 if os.path.isdir(dest):
612 if not os.path.isdir(makestandin(dest)):
612 if not os.path.isdir(makestandin(dest)):
613 os.makedirs(makestandin(dest))
613 os.makedirs(makestandin(dest))
614
614
615 try:
615 try:
616 # When we call orig below it creates the standins but we don't add
616 # When we call orig below it creates the standins but we don't add
617 # them to the dir state until later so lock during that time.
617 # them to the dir state until later so lock during that time.
618 wlock = repo.wlock()
618 wlock = repo.wlock()
619
619
620 manifest = repo[None].manifest()
620 manifest = repo[None].manifest()
621 def overridematch(ctx, pats=(), opts=None, globbed=False,
621 def overridematch(ctx, pats=(), opts=None, globbed=False,
622 default='relpath', badfn=None):
622 default='relpath', badfn=None):
623 if opts is None:
623 if opts is None:
624 opts = {}
624 opts = {}
625 newpats = []
625 newpats = []
626 # The patterns were previously mangled to add the standin
626 # The patterns were previously mangled to add the standin
627 # directory; we need to remove that now
627 # directory; we need to remove that now
628 for pat in pats:
628 for pat in pats:
629 if match_.patkind(pat) is None and lfutil.shortname in pat:
629 if match_.patkind(pat) is None and lfutil.shortname in pat:
630 newpats.append(pat.replace(lfutil.shortname, ''))
630 newpats.append(pat.replace(lfutil.shortname, ''))
631 else:
631 else:
632 newpats.append(pat)
632 newpats.append(pat)
633 match = oldmatch(ctx, newpats, opts, globbed, default, badfn=badfn)
633 match = oldmatch(ctx, newpats, opts, globbed, default, badfn=badfn)
634 m = copy.copy(match)
634 m = copy.copy(match)
635 lfile = lambda f: lfutil.standin(f) in manifest
635 lfile = lambda f: lfutil.standin(f) in manifest
636 m._files = [lfutil.standin(f) for f in m._files if lfile(f)]
636 m._files = [lfutil.standin(f) for f in m._files if lfile(f)]
637 m._fileroots = set(m._files)
637 m._fileroots = set(m._files)
638 origmatchfn = m.matchfn
638 origmatchfn = m.matchfn
639 m.matchfn = lambda f: (lfutil.isstandin(f) and
639 m.matchfn = lambda f: (lfutil.isstandin(f) and
640 (f in manifest) and
640 (f in manifest) and
641 origmatchfn(lfutil.splitstandin(f)) or
641 origmatchfn(lfutil.splitstandin(f)) or
642 None)
642 None)
643 return m
643 return m
644 oldmatch = installmatchfn(overridematch)
644 oldmatch = installmatchfn(overridematch)
645 listpats = []
645 listpats = []
646 for pat in pats:
646 for pat in pats:
647 if match_.patkind(pat) is not None:
647 if match_.patkind(pat) is not None:
648 listpats.append(pat)
648 listpats.append(pat)
649 else:
649 else:
650 listpats.append(makestandin(pat))
650 listpats.append(makestandin(pat))
651
651
652 try:
652 try:
653 origcopyfile = util.copyfile
653 origcopyfile = util.copyfile
654 copiedfiles = []
654 copiedfiles = []
655 def overridecopyfile(src, dest):
655 def overridecopyfile(src, dest):
656 if (lfutil.shortname in src and
656 if (lfutil.shortname in src and
657 dest.startswith(repo.wjoin(lfutil.shortname))):
657 dest.startswith(repo.wjoin(lfutil.shortname))):
658 destlfile = dest.replace(lfutil.shortname, '')
658 destlfile = dest.replace(lfutil.shortname, '')
659 if not opts['force'] and os.path.exists(destlfile):
659 if not opts['force'] and os.path.exists(destlfile):
660 raise IOError('',
660 raise IOError('',
661 _('destination largefile already exists'))
661 _('destination largefile already exists'))
662 copiedfiles.append((src, dest))
662 copiedfiles.append((src, dest))
663 origcopyfile(src, dest)
663 origcopyfile(src, dest)
664
664
665 util.copyfile = overridecopyfile
665 util.copyfile = overridecopyfile
666 result += orig(ui, repo, listpats, opts, rename)
666 result += orig(ui, repo, listpats, opts, rename)
667 finally:
667 finally:
668 util.copyfile = origcopyfile
668 util.copyfile = origcopyfile
669
669
670 lfdirstate = lfutil.openlfdirstate(ui, repo)
670 lfdirstate = lfutil.openlfdirstate(ui, repo)
671 for (src, dest) in copiedfiles:
671 for (src, dest) in copiedfiles:
672 if (lfutil.shortname in src and
672 if (lfutil.shortname in src and
673 dest.startswith(repo.wjoin(lfutil.shortname))):
673 dest.startswith(repo.wjoin(lfutil.shortname))):
674 srclfile = src.replace(repo.wjoin(lfutil.standin('')), '')
674 srclfile = src.replace(repo.wjoin(lfutil.standin('')), '')
675 destlfile = dest.replace(repo.wjoin(lfutil.standin('')), '')
675 destlfile = dest.replace(repo.wjoin(lfutil.standin('')), '')
676 destlfiledir = os.path.dirname(repo.wjoin(destlfile)) or '.'
676 destlfiledir = repo.wvfs.dirname(repo.wjoin(destlfile)) or '.'
677 if not os.path.isdir(destlfiledir):
677 if not os.path.isdir(destlfiledir):
678 os.makedirs(destlfiledir)
678 os.makedirs(destlfiledir)
679 if rename:
679 if rename:
680 os.rename(repo.wjoin(srclfile), repo.wjoin(destlfile))
680 os.rename(repo.wjoin(srclfile), repo.wjoin(destlfile))
681
681
682 # The file is gone, but this deletes any empty parent
682 # The file is gone, but this deletes any empty parent
683 # directories as a side-effect.
683 # directories as a side-effect.
684 util.unlinkpath(repo.wjoin(srclfile), True)
684 util.unlinkpath(repo.wjoin(srclfile), True)
685 lfdirstate.remove(srclfile)
685 lfdirstate.remove(srclfile)
686 else:
686 else:
687 util.copyfile(repo.wjoin(srclfile),
687 util.copyfile(repo.wjoin(srclfile),
688 repo.wjoin(destlfile))
688 repo.wjoin(destlfile))
689
689
690 lfdirstate.add(destlfile)
690 lfdirstate.add(destlfile)
691 lfdirstate.write()
691 lfdirstate.write()
692 except error.Abort as e:
692 except error.Abort as e:
693 if str(e) != _('no files to copy'):
693 if str(e) != _('no files to copy'):
694 raise e
694 raise e
695 else:
695 else:
696 nolfiles = True
696 nolfiles = True
697 finally:
697 finally:
698 restorematchfn()
698 restorematchfn()
699 wlock.release()
699 wlock.release()
700
700
701 if nolfiles and nonormalfiles:
701 if nolfiles and nonormalfiles:
702 raise error.Abort(_('no files to copy'))
702 raise error.Abort(_('no files to copy'))
703
703
704 return result
704 return result
705
705
706 # When the user calls revert, we have to be careful to not revert any
706 # When the user calls revert, we have to be careful to not revert any
707 # changes to other largefiles accidentally. This means we have to keep
707 # changes to other largefiles accidentally. This means we have to keep
708 # track of the largefiles that are being reverted so we only pull down
708 # track of the largefiles that are being reverted so we only pull down
709 # the necessary largefiles.
709 # the necessary largefiles.
710 #
710 #
711 # Standins are only updated (to match the hash of largefiles) before
711 # Standins are only updated (to match the hash of largefiles) before
712 # commits. Update the standins then run the original revert, changing
712 # commits. Update the standins then run the original revert, changing
713 # the matcher to hit standins instead of largefiles. Based on the
713 # the matcher to hit standins instead of largefiles. Based on the
714 # resulting standins update the largefiles.
714 # resulting standins update the largefiles.
715 def overriderevert(orig, ui, repo, ctx, parents, *pats, **opts):
715 def overriderevert(orig, ui, repo, ctx, parents, *pats, **opts):
716 # Because we put the standins in a bad state (by updating them)
716 # Because we put the standins in a bad state (by updating them)
717 # and then return them to a correct state we need to lock to
717 # and then return them to a correct state we need to lock to
718 # prevent others from changing them in their incorrect state.
718 # prevent others from changing them in their incorrect state.
719 with repo.wlock():
719 with repo.wlock():
720 lfdirstate = lfutil.openlfdirstate(ui, repo)
720 lfdirstate = lfutil.openlfdirstate(ui, repo)
721 s = lfutil.lfdirstatestatus(lfdirstate, repo)
721 s = lfutil.lfdirstatestatus(lfdirstate, repo)
722 lfdirstate.write()
722 lfdirstate.write()
723 for lfile in s.modified:
723 for lfile in s.modified:
724 lfutil.updatestandin(repo, lfutil.standin(lfile))
724 lfutil.updatestandin(repo, lfutil.standin(lfile))
725 for lfile in s.deleted:
725 for lfile in s.deleted:
726 if (os.path.exists(repo.wjoin(lfutil.standin(lfile)))):
726 if (repo.wvfs.exists(lfutil.standin(lfile))):
727 os.unlink(repo.wjoin(lfutil.standin(lfile)))
727 repo.wvfs.unlink(lfutil.standin(lfile))
728
728
729 oldstandins = lfutil.getstandinsstate(repo)
729 oldstandins = lfutil.getstandinsstate(repo)
730
730
731 def overridematch(mctx, pats=(), opts=None, globbed=False,
731 def overridematch(mctx, pats=(), opts=None, globbed=False,
732 default='relpath', badfn=None):
732 default='relpath', badfn=None):
733 if opts is None:
733 if opts is None:
734 opts = {}
734 opts = {}
735 match = oldmatch(mctx, pats, opts, globbed, default, badfn=badfn)
735 match = oldmatch(mctx, pats, opts, globbed, default, badfn=badfn)
736 m = copy.copy(match)
736 m = copy.copy(match)
737
737
738 # revert supports recursing into subrepos, and though largefiles
738 # revert supports recursing into subrepos, and though largefiles
739 # currently doesn't work correctly in that case, this match is
739 # currently doesn't work correctly in that case, this match is
740 # called, so the lfdirstate above may not be the correct one for
740 # called, so the lfdirstate above may not be the correct one for
741 # this invocation of match.
741 # this invocation of match.
742 lfdirstate = lfutil.openlfdirstate(mctx.repo().ui, mctx.repo(),
742 lfdirstate = lfutil.openlfdirstate(mctx.repo().ui, mctx.repo(),
743 False)
743 False)
744
744
745 def tostandin(f):
745 def tostandin(f):
746 standin = lfutil.standin(f)
746 standin = lfutil.standin(f)
747 if standin in ctx or standin in mctx:
747 if standin in ctx or standin in mctx:
748 return standin
748 return standin
749 elif standin in repo[None] or lfdirstate[f] == 'r':
749 elif standin in repo[None] or lfdirstate[f] == 'r':
750 return None
750 return None
751 return f
751 return f
752 m._files = [tostandin(f) for f in m._files]
752 m._files = [tostandin(f) for f in m._files]
753 m._files = [f for f in m._files if f is not None]
753 m._files = [f for f in m._files if f is not None]
754 m._fileroots = set(m._files)
754 m._fileroots = set(m._files)
755 origmatchfn = m.matchfn
755 origmatchfn = m.matchfn
756 def matchfn(f):
756 def matchfn(f):
757 if lfutil.isstandin(f):
757 if lfutil.isstandin(f):
758 return (origmatchfn(lfutil.splitstandin(f)) and
758 return (origmatchfn(lfutil.splitstandin(f)) and
759 (f in ctx or f in mctx))
759 (f in ctx or f in mctx))
760 return origmatchfn(f)
760 return origmatchfn(f)
761 m.matchfn = matchfn
761 m.matchfn = matchfn
762 return m
762 return m
763 oldmatch = installmatchfn(overridematch)
763 oldmatch = installmatchfn(overridematch)
764 try:
764 try:
765 orig(ui, repo, ctx, parents, *pats, **opts)
765 orig(ui, repo, ctx, parents, *pats, **opts)
766 finally:
766 finally:
767 restorematchfn()
767 restorematchfn()
768
768
769 newstandins = lfutil.getstandinsstate(repo)
769 newstandins = lfutil.getstandinsstate(repo)
770 filelist = lfutil.getlfilestoupdate(oldstandins, newstandins)
770 filelist = lfutil.getlfilestoupdate(oldstandins, newstandins)
771 # lfdirstate should be 'normallookup'-ed for updated files,
771 # lfdirstate should be 'normallookup'-ed for updated files,
772 # because reverting doesn't touch dirstate for 'normal' files
772 # because reverting doesn't touch dirstate for 'normal' files
773 # when target revision is explicitly specified: in such case,
773 # when target revision is explicitly specified: in such case,
774 # 'n' and valid timestamp in dirstate doesn't ensure 'clean'
774 # 'n' and valid timestamp in dirstate doesn't ensure 'clean'
775 # of target (standin) file.
775 # of target (standin) file.
776 lfcommands.updatelfiles(ui, repo, filelist, printmessage=False,
776 lfcommands.updatelfiles(ui, repo, filelist, printmessage=False,
777 normallookup=True)
777 normallookup=True)
778
778
779 # after pulling changesets, we need to take some extra care to get
779 # after pulling changesets, we need to take some extra care to get
780 # largefiles updated remotely
780 # largefiles updated remotely
781 def overridepull(orig, ui, repo, source=None, **opts):
781 def overridepull(orig, ui, repo, source=None, **opts):
782 revsprepull = len(repo)
782 revsprepull = len(repo)
783 if not source:
783 if not source:
784 source = 'default'
784 source = 'default'
785 repo.lfpullsource = source
785 repo.lfpullsource = source
786 result = orig(ui, repo, source, **opts)
786 result = orig(ui, repo, source, **opts)
787 revspostpull = len(repo)
787 revspostpull = len(repo)
788 lfrevs = opts.get('lfrev', [])
788 lfrevs = opts.get('lfrev', [])
789 if opts.get('all_largefiles'):
789 if opts.get('all_largefiles'):
790 lfrevs.append('pulled()')
790 lfrevs.append('pulled()')
791 if lfrevs and revspostpull > revsprepull:
791 if lfrevs and revspostpull > revsprepull:
792 numcached = 0
792 numcached = 0
793 repo.firstpulled = revsprepull # for pulled() revset expression
793 repo.firstpulled = revsprepull # for pulled() revset expression
794 try:
794 try:
795 for rev in scmutil.revrange(repo, lfrevs):
795 for rev in scmutil.revrange(repo, lfrevs):
796 ui.note(_('pulling largefiles for revision %s\n') % rev)
796 ui.note(_('pulling largefiles for revision %s\n') % rev)
797 (cached, missing) = lfcommands.cachelfiles(ui, repo, rev)
797 (cached, missing) = lfcommands.cachelfiles(ui, repo, rev)
798 numcached += len(cached)
798 numcached += len(cached)
799 finally:
799 finally:
800 del repo.firstpulled
800 del repo.firstpulled
801 ui.status(_("%d largefiles cached\n") % numcached)
801 ui.status(_("%d largefiles cached\n") % numcached)
802 return result
802 return result
803
803
804 revsetpredicate = registrar.revsetpredicate()
804 revsetpredicate = registrar.revsetpredicate()
805
805
806 @revsetpredicate('pulled()')
806 @revsetpredicate('pulled()')
807 def pulledrevsetsymbol(repo, subset, x):
807 def pulledrevsetsymbol(repo, subset, x):
808 """Changesets that just has been pulled.
808 """Changesets that just has been pulled.
809
809
810 Only available with largefiles from pull --lfrev expressions.
810 Only available with largefiles from pull --lfrev expressions.
811
811
812 .. container:: verbose
812 .. container:: verbose
813
813
814 Some examples:
814 Some examples:
815
815
816 - pull largefiles for all new changesets::
816 - pull largefiles for all new changesets::
817
817
818 hg pull -lfrev "pulled()"
818 hg pull -lfrev "pulled()"
819
819
820 - pull largefiles for all new branch heads::
820 - pull largefiles for all new branch heads::
821
821
822 hg pull -lfrev "head(pulled()) and not closed()"
822 hg pull -lfrev "head(pulled()) and not closed()"
823
823
824 """
824 """
825
825
826 try:
826 try:
827 firstpulled = repo.firstpulled
827 firstpulled = repo.firstpulled
828 except AttributeError:
828 except AttributeError:
829 raise error.Abort(_("pulled() only available in --lfrev"))
829 raise error.Abort(_("pulled() only available in --lfrev"))
830 return revset.baseset([r for r in subset if r >= firstpulled])
830 return revset.baseset([r for r in subset if r >= firstpulled])
831
831
832 def overrideclone(orig, ui, source, dest=None, **opts):
832 def overrideclone(orig, ui, source, dest=None, **opts):
833 d = dest
833 d = dest
834 if d is None:
834 if d is None:
835 d = hg.defaultdest(source)
835 d = hg.defaultdest(source)
836 if opts.get('all_largefiles') and not hg.islocal(d):
836 if opts.get('all_largefiles') and not hg.islocal(d):
837 raise error.Abort(_(
837 raise error.Abort(_(
838 '--all-largefiles is incompatible with non-local destination %s') %
838 '--all-largefiles is incompatible with non-local destination %s') %
839 d)
839 d)
840
840
841 return orig(ui, source, dest, **opts)
841 return orig(ui, source, dest, **opts)
842
842
843 def hgclone(orig, ui, opts, *args, **kwargs):
843 def hgclone(orig, ui, opts, *args, **kwargs):
844 result = orig(ui, opts, *args, **kwargs)
844 result = orig(ui, opts, *args, **kwargs)
845
845
846 if result is not None:
846 if result is not None:
847 sourcerepo, destrepo = result
847 sourcerepo, destrepo = result
848 repo = destrepo.local()
848 repo = destrepo.local()
849
849
850 # When cloning to a remote repo (like through SSH), no repo is available
850 # When cloning to a remote repo (like through SSH), no repo is available
851 # from the peer. Therefore the largefiles can't be downloaded and the
851 # from the peer. Therefore the largefiles can't be downloaded and the
852 # hgrc can't be updated.
852 # hgrc can't be updated.
853 if not repo:
853 if not repo:
854 return result
854 return result
855
855
856 # If largefiles is required for this repo, permanently enable it locally
856 # If largefiles is required for this repo, permanently enable it locally
857 if 'largefiles' in repo.requirements:
857 if 'largefiles' in repo.requirements:
858 fp = repo.vfs('hgrc', 'a', text=True)
858 fp = repo.vfs('hgrc', 'a', text=True)
859 try:
859 try:
860 fp.write('\n[extensions]\nlargefiles=\n')
860 fp.write('\n[extensions]\nlargefiles=\n')
861 finally:
861 finally:
862 fp.close()
862 fp.close()
863
863
864 # Caching is implicitly limited to 'rev' option, since the dest repo was
864 # Caching is implicitly limited to 'rev' option, since the dest repo was
865 # truncated at that point. The user may expect a download count with
865 # truncated at that point. The user may expect a download count with
866 # this option, so attempt whether or not this is a largefile repo.
866 # this option, so attempt whether or not this is a largefile repo.
867 if opts.get('all_largefiles'):
867 if opts.get('all_largefiles'):
868 success, missing = lfcommands.downloadlfiles(ui, repo, None)
868 success, missing = lfcommands.downloadlfiles(ui, repo, None)
869
869
870 if missing != 0:
870 if missing != 0:
871 return None
871 return None
872
872
873 return result
873 return result
874
874
875 def overriderebase(orig, ui, repo, **opts):
875 def overriderebase(orig, ui, repo, **opts):
876 if not util.safehasattr(repo, '_largefilesenabled'):
876 if not util.safehasattr(repo, '_largefilesenabled'):
877 return orig(ui, repo, **opts)
877 return orig(ui, repo, **opts)
878
878
879 resuming = opts.get('continue')
879 resuming = opts.get('continue')
880 repo._lfcommithooks.append(lfutil.automatedcommithook(resuming))
880 repo._lfcommithooks.append(lfutil.automatedcommithook(resuming))
881 repo._lfstatuswriters.append(lambda *msg, **opts: None)
881 repo._lfstatuswriters.append(lambda *msg, **opts: None)
882 try:
882 try:
883 return orig(ui, repo, **opts)
883 return orig(ui, repo, **opts)
884 finally:
884 finally:
885 repo._lfstatuswriters.pop()
885 repo._lfstatuswriters.pop()
886 repo._lfcommithooks.pop()
886 repo._lfcommithooks.pop()
887
887
888 def overridearchivecmd(orig, ui, repo, dest, **opts):
888 def overridearchivecmd(orig, ui, repo, dest, **opts):
889 repo.unfiltered().lfstatus = True
889 repo.unfiltered().lfstatus = True
890
890
891 try:
891 try:
892 return orig(ui, repo.unfiltered(), dest, **opts)
892 return orig(ui, repo.unfiltered(), dest, **opts)
893 finally:
893 finally:
894 repo.unfiltered().lfstatus = False
894 repo.unfiltered().lfstatus = False
895
895
896 def hgwebarchive(orig, web, req, tmpl):
896 def hgwebarchive(orig, web, req, tmpl):
897 web.repo.lfstatus = True
897 web.repo.lfstatus = True
898
898
899 try:
899 try:
900 return orig(web, req, tmpl)
900 return orig(web, req, tmpl)
901 finally:
901 finally:
902 web.repo.lfstatus = False
902 web.repo.lfstatus = False
903
903
904 def overridearchive(orig, repo, dest, node, kind, decode=True, matchfn=None,
904 def overridearchive(orig, repo, dest, node, kind, decode=True, matchfn=None,
905 prefix='', mtime=None, subrepos=None):
905 prefix='', mtime=None, subrepos=None):
906 # For some reason setting repo.lfstatus in hgwebarchive only changes the
906 # For some reason setting repo.lfstatus in hgwebarchive only changes the
907 # unfiltered repo's attr, so check that as well.
907 # unfiltered repo's attr, so check that as well.
908 if not repo.lfstatus and not repo.unfiltered().lfstatus:
908 if not repo.lfstatus and not repo.unfiltered().lfstatus:
909 return orig(repo, dest, node, kind, decode, matchfn, prefix, mtime,
909 return orig(repo, dest, node, kind, decode, matchfn, prefix, mtime,
910 subrepos)
910 subrepos)
911
911
912 # No need to lock because we are only reading history and
912 # No need to lock because we are only reading history and
913 # largefile caches, neither of which are modified.
913 # largefile caches, neither of which are modified.
914 if node is not None:
914 if node is not None:
915 lfcommands.cachelfiles(repo.ui, repo, node)
915 lfcommands.cachelfiles(repo.ui, repo, node)
916
916
917 if kind not in archival.archivers:
917 if kind not in archival.archivers:
918 raise error.Abort(_("unknown archive type '%s'") % kind)
918 raise error.Abort(_("unknown archive type '%s'") % kind)
919
919
920 ctx = repo[node]
920 ctx = repo[node]
921
921
922 if kind == 'files':
922 if kind == 'files':
923 if prefix:
923 if prefix:
924 raise error.Abort(
924 raise error.Abort(
925 _('cannot give prefix when archiving to files'))
925 _('cannot give prefix when archiving to files'))
926 else:
926 else:
927 prefix = archival.tidyprefix(dest, kind, prefix)
927 prefix = archival.tidyprefix(dest, kind, prefix)
928
928
929 def write(name, mode, islink, getdata):
929 def write(name, mode, islink, getdata):
930 if matchfn and not matchfn(name):
930 if matchfn and not matchfn(name):
931 return
931 return
932 data = getdata()
932 data = getdata()
933 if decode:
933 if decode:
934 data = repo.wwritedata(name, data)
934 data = repo.wwritedata(name, data)
935 archiver.addfile(prefix + name, mode, islink, data)
935 archiver.addfile(prefix + name, mode, islink, data)
936
936
937 archiver = archival.archivers[kind](dest, mtime or ctx.date()[0])
937 archiver = archival.archivers[kind](dest, mtime or ctx.date()[0])
938
938
939 if repo.ui.configbool("ui", "archivemeta", True):
939 if repo.ui.configbool("ui", "archivemeta", True):
940 write('.hg_archival.txt', 0o644, False,
940 write('.hg_archival.txt', 0o644, False,
941 lambda: archival.buildmetadata(ctx))
941 lambda: archival.buildmetadata(ctx))
942
942
943 for f in ctx:
943 for f in ctx:
944 ff = ctx.flags(f)
944 ff = ctx.flags(f)
945 getdata = ctx[f].data
945 getdata = ctx[f].data
946 if lfutil.isstandin(f):
946 if lfutil.isstandin(f):
947 if node is not None:
947 if node is not None:
948 path = lfutil.findfile(repo, getdata().strip())
948 path = lfutil.findfile(repo, getdata().strip())
949
949
950 if path is None:
950 if path is None:
951 raise error.Abort(
951 raise error.Abort(
952 _('largefile %s not found in repo store or system cache')
952 _('largefile %s not found in repo store or system cache')
953 % lfutil.splitstandin(f))
953 % lfutil.splitstandin(f))
954 else:
954 else:
955 path = lfutil.splitstandin(f)
955 path = lfutil.splitstandin(f)
956
956
957 f = lfutil.splitstandin(f)
957 f = lfutil.splitstandin(f)
958
958
959 getdata = lambda: util.readfile(path)
959 getdata = lambda: util.readfile(path)
960 write(f, 'x' in ff and 0o755 or 0o644, 'l' in ff, getdata)
960 write(f, 'x' in ff and 0o755 or 0o644, 'l' in ff, getdata)
961
961
962 if subrepos:
962 if subrepos:
963 for subpath in sorted(ctx.substate):
963 for subpath in sorted(ctx.substate):
964 sub = ctx.workingsub(subpath)
964 sub = ctx.workingsub(subpath)
965 submatch = match_.subdirmatcher(subpath, matchfn)
965 submatch = match_.subdirmatcher(subpath, matchfn)
966 sub._repo.lfstatus = True
966 sub._repo.lfstatus = True
967 sub.archive(archiver, prefix, submatch)
967 sub.archive(archiver, prefix, submatch)
968
968
969 archiver.done()
969 archiver.done()
970
970
971 def hgsubrepoarchive(orig, repo, archiver, prefix, match=None):
971 def hgsubrepoarchive(orig, repo, archiver, prefix, match=None):
972 if not repo._repo.lfstatus:
972 if not repo._repo.lfstatus:
973 return orig(repo, archiver, prefix, match)
973 return orig(repo, archiver, prefix, match)
974
974
975 repo._get(repo._state + ('hg',))
975 repo._get(repo._state + ('hg',))
976 rev = repo._state[1]
976 rev = repo._state[1]
977 ctx = repo._repo[rev]
977 ctx = repo._repo[rev]
978
978
979 if ctx.node() is not None:
979 if ctx.node() is not None:
980 lfcommands.cachelfiles(repo.ui, repo._repo, ctx.node())
980 lfcommands.cachelfiles(repo.ui, repo._repo, ctx.node())
981
981
982 def write(name, mode, islink, getdata):
982 def write(name, mode, islink, getdata):
983 # At this point, the standin has been replaced with the largefile name,
983 # At this point, the standin has been replaced with the largefile name,
984 # so the normal matcher works here without the lfutil variants.
984 # so the normal matcher works here without the lfutil variants.
985 if match and not match(f):
985 if match and not match(f):
986 return
986 return
987 data = getdata()
987 data = getdata()
988
988
989 archiver.addfile(prefix + repo._path + '/' + name, mode, islink, data)
989 archiver.addfile(prefix + repo._path + '/' + name, mode, islink, data)
990
990
991 for f in ctx:
991 for f in ctx:
992 ff = ctx.flags(f)
992 ff = ctx.flags(f)
993 getdata = ctx[f].data
993 getdata = ctx[f].data
994 if lfutil.isstandin(f):
994 if lfutil.isstandin(f):
995 if ctx.node() is not None:
995 if ctx.node() is not None:
996 path = lfutil.findfile(repo._repo, getdata().strip())
996 path = lfutil.findfile(repo._repo, getdata().strip())
997
997
998 if path is None:
998 if path is None:
999 raise error.Abort(
999 raise error.Abort(
1000 _('largefile %s not found in repo store or system cache')
1000 _('largefile %s not found in repo store or system cache')
1001 % lfutil.splitstandin(f))
1001 % lfutil.splitstandin(f))
1002 else:
1002 else:
1003 path = lfutil.splitstandin(f)
1003 path = lfutil.splitstandin(f)
1004
1004
1005 f = lfutil.splitstandin(f)
1005 f = lfutil.splitstandin(f)
1006
1006
1007 getdata = lambda: util.readfile(os.path.join(prefix, path))
1007 getdata = lambda: util.readfile(os.path.join(prefix, path))
1008
1008
1009 write(f, 'x' in ff and 0o755 or 0o644, 'l' in ff, getdata)
1009 write(f, 'x' in ff and 0o755 or 0o644, 'l' in ff, getdata)
1010
1010
1011 for subpath in sorted(ctx.substate):
1011 for subpath in sorted(ctx.substate):
1012 sub = ctx.workingsub(subpath)
1012 sub = ctx.workingsub(subpath)
1013 submatch = match_.subdirmatcher(subpath, match)
1013 submatch = match_.subdirmatcher(subpath, match)
1014 sub._repo.lfstatus = True
1014 sub._repo.lfstatus = True
1015 sub.archive(archiver, prefix + repo._path + '/', submatch)
1015 sub.archive(archiver, prefix + repo._path + '/', submatch)
1016
1016
1017 # If a largefile is modified, the change is not reflected in its
1017 # If a largefile is modified, the change is not reflected in its
1018 # standin until a commit. cmdutil.bailifchanged() raises an exception
1018 # standin until a commit. cmdutil.bailifchanged() raises an exception
1019 # if the repo has uncommitted changes. Wrap it to also check if
1019 # if the repo has uncommitted changes. Wrap it to also check if
1020 # largefiles were changed. This is used by bisect, backout and fetch.
1020 # largefiles were changed. This is used by bisect, backout and fetch.
1021 def overridebailifchanged(orig, repo, *args, **kwargs):
1021 def overridebailifchanged(orig, repo, *args, **kwargs):
1022 orig(repo, *args, **kwargs)
1022 orig(repo, *args, **kwargs)
1023 repo.lfstatus = True
1023 repo.lfstatus = True
1024 s = repo.status()
1024 s = repo.status()
1025 repo.lfstatus = False
1025 repo.lfstatus = False
1026 if s.modified or s.added or s.removed or s.deleted:
1026 if s.modified or s.added or s.removed or s.deleted:
1027 raise error.Abort(_('uncommitted changes'))
1027 raise error.Abort(_('uncommitted changes'))
1028
1028
1029 def postcommitstatus(orig, repo, *args, **kwargs):
1029 def postcommitstatus(orig, repo, *args, **kwargs):
1030 repo.lfstatus = True
1030 repo.lfstatus = True
1031 try:
1031 try:
1032 return orig(repo, *args, **kwargs)
1032 return orig(repo, *args, **kwargs)
1033 finally:
1033 finally:
1034 repo.lfstatus = False
1034 repo.lfstatus = False
1035
1035
1036 def cmdutilforget(orig, ui, repo, match, prefix, explicitonly):
1036 def cmdutilforget(orig, ui, repo, match, prefix, explicitonly):
1037 normalmatcher = composenormalfilematcher(match, repo[None].manifest())
1037 normalmatcher = composenormalfilematcher(match, repo[None].manifest())
1038 bad, forgot = orig(ui, repo, normalmatcher, prefix, explicitonly)
1038 bad, forgot = orig(ui, repo, normalmatcher, prefix, explicitonly)
1039 m = composelargefilematcher(match, repo[None].manifest())
1039 m = composelargefilematcher(match, repo[None].manifest())
1040
1040
1041 try:
1041 try:
1042 repo.lfstatus = True
1042 repo.lfstatus = True
1043 s = repo.status(match=m, clean=True)
1043 s = repo.status(match=m, clean=True)
1044 finally:
1044 finally:
1045 repo.lfstatus = False
1045 repo.lfstatus = False
1046 forget = sorted(s.modified + s.added + s.deleted + s.clean)
1046 forget = sorted(s.modified + s.added + s.deleted + s.clean)
1047 forget = [f for f in forget if lfutil.standin(f) in repo[None].manifest()]
1047 forget = [f for f in forget if lfutil.standin(f) in repo[None].manifest()]
1048
1048
1049 for f in forget:
1049 for f in forget:
1050 if lfutil.standin(f) not in repo.dirstate and not \
1050 if lfutil.standin(f) not in repo.dirstate and not \
1051 repo.wvfs.isdir(lfutil.standin(f)):
1051 repo.wvfs.isdir(lfutil.standin(f)):
1052 ui.warn(_('not removing %s: file is already untracked\n')
1052 ui.warn(_('not removing %s: file is already untracked\n')
1053 % m.rel(f))
1053 % m.rel(f))
1054 bad.append(f)
1054 bad.append(f)
1055
1055
1056 for f in forget:
1056 for f in forget:
1057 if ui.verbose or not m.exact(f):
1057 if ui.verbose or not m.exact(f):
1058 ui.status(_('removing %s\n') % m.rel(f))
1058 ui.status(_('removing %s\n') % m.rel(f))
1059
1059
1060 # Need to lock because standin files are deleted then removed from the
1060 # Need to lock because standin files are deleted then removed from the
1061 # repository and we could race in-between.
1061 # repository and we could race in-between.
1062 with repo.wlock():
1062 with repo.wlock():
1063 lfdirstate = lfutil.openlfdirstate(ui, repo)
1063 lfdirstate = lfutil.openlfdirstate(ui, repo)
1064 for f in forget:
1064 for f in forget:
1065 if lfdirstate[f] == 'a':
1065 if lfdirstate[f] == 'a':
1066 lfdirstate.drop(f)
1066 lfdirstate.drop(f)
1067 else:
1067 else:
1068 lfdirstate.remove(f)
1068 lfdirstate.remove(f)
1069 lfdirstate.write()
1069 lfdirstate.write()
1070 standins = [lfutil.standin(f) for f in forget]
1070 standins = [lfutil.standin(f) for f in forget]
1071 for f in standins:
1071 for f in standins:
1072 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
1072 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
1073 rejected = repo[None].forget(standins)
1073 rejected = repo[None].forget(standins)
1074
1074
1075 bad.extend(f for f in rejected if f in m.files())
1075 bad.extend(f for f in rejected if f in m.files())
1076 forgot.extend(f for f in forget if f not in rejected)
1076 forgot.extend(f for f in forget if f not in rejected)
1077 return bad, forgot
1077 return bad, forgot
1078
1078
1079 def _getoutgoings(repo, other, missing, addfunc):
1079 def _getoutgoings(repo, other, missing, addfunc):
1080 """get pairs of filename and largefile hash in outgoing revisions
1080 """get pairs of filename and largefile hash in outgoing revisions
1081 in 'missing'.
1081 in 'missing'.
1082
1082
1083 largefiles already existing on 'other' repository are ignored.
1083 largefiles already existing on 'other' repository are ignored.
1084
1084
1085 'addfunc' is invoked with each unique pairs of filename and
1085 'addfunc' is invoked with each unique pairs of filename and
1086 largefile hash value.
1086 largefile hash value.
1087 """
1087 """
1088 knowns = set()
1088 knowns = set()
1089 lfhashes = set()
1089 lfhashes = set()
1090 def dedup(fn, lfhash):
1090 def dedup(fn, lfhash):
1091 k = (fn, lfhash)
1091 k = (fn, lfhash)
1092 if k not in knowns:
1092 if k not in knowns:
1093 knowns.add(k)
1093 knowns.add(k)
1094 lfhashes.add(lfhash)
1094 lfhashes.add(lfhash)
1095 lfutil.getlfilestoupload(repo, missing, dedup)
1095 lfutil.getlfilestoupload(repo, missing, dedup)
1096 if lfhashes:
1096 if lfhashes:
1097 lfexists = basestore._openstore(repo, other).exists(lfhashes)
1097 lfexists = basestore._openstore(repo, other).exists(lfhashes)
1098 for fn, lfhash in knowns:
1098 for fn, lfhash in knowns:
1099 if not lfexists[lfhash]: # lfhash doesn't exist on "other"
1099 if not lfexists[lfhash]: # lfhash doesn't exist on "other"
1100 addfunc(fn, lfhash)
1100 addfunc(fn, lfhash)
1101
1101
1102 def outgoinghook(ui, repo, other, opts, missing):
1102 def outgoinghook(ui, repo, other, opts, missing):
1103 if opts.pop('large', None):
1103 if opts.pop('large', None):
1104 lfhashes = set()
1104 lfhashes = set()
1105 if ui.debugflag:
1105 if ui.debugflag:
1106 toupload = {}
1106 toupload = {}
1107 def addfunc(fn, lfhash):
1107 def addfunc(fn, lfhash):
1108 if fn not in toupload:
1108 if fn not in toupload:
1109 toupload[fn] = []
1109 toupload[fn] = []
1110 toupload[fn].append(lfhash)
1110 toupload[fn].append(lfhash)
1111 lfhashes.add(lfhash)
1111 lfhashes.add(lfhash)
1112 def showhashes(fn):
1112 def showhashes(fn):
1113 for lfhash in sorted(toupload[fn]):
1113 for lfhash in sorted(toupload[fn]):
1114 ui.debug(' %s\n' % (lfhash))
1114 ui.debug(' %s\n' % (lfhash))
1115 else:
1115 else:
1116 toupload = set()
1116 toupload = set()
1117 def addfunc(fn, lfhash):
1117 def addfunc(fn, lfhash):
1118 toupload.add(fn)
1118 toupload.add(fn)
1119 lfhashes.add(lfhash)
1119 lfhashes.add(lfhash)
1120 def showhashes(fn):
1120 def showhashes(fn):
1121 pass
1121 pass
1122 _getoutgoings(repo, other, missing, addfunc)
1122 _getoutgoings(repo, other, missing, addfunc)
1123
1123
1124 if not toupload:
1124 if not toupload:
1125 ui.status(_('largefiles: no files to upload\n'))
1125 ui.status(_('largefiles: no files to upload\n'))
1126 else:
1126 else:
1127 ui.status(_('largefiles to upload (%d entities):\n')
1127 ui.status(_('largefiles to upload (%d entities):\n')
1128 % (len(lfhashes)))
1128 % (len(lfhashes)))
1129 for file in sorted(toupload):
1129 for file in sorted(toupload):
1130 ui.status(lfutil.splitstandin(file) + '\n')
1130 ui.status(lfutil.splitstandin(file) + '\n')
1131 showhashes(file)
1131 showhashes(file)
1132 ui.status('\n')
1132 ui.status('\n')
1133
1133
1134 def summaryremotehook(ui, repo, opts, changes):
1134 def summaryremotehook(ui, repo, opts, changes):
1135 largeopt = opts.get('large', False)
1135 largeopt = opts.get('large', False)
1136 if changes is None:
1136 if changes is None:
1137 if largeopt:
1137 if largeopt:
1138 return (False, True) # only outgoing check is needed
1138 return (False, True) # only outgoing check is needed
1139 else:
1139 else:
1140 return (False, False)
1140 return (False, False)
1141 elif largeopt:
1141 elif largeopt:
1142 url, branch, peer, outgoing = changes[1]
1142 url, branch, peer, outgoing = changes[1]
1143 if peer is None:
1143 if peer is None:
1144 # i18n: column positioning for "hg summary"
1144 # i18n: column positioning for "hg summary"
1145 ui.status(_('largefiles: (no remote repo)\n'))
1145 ui.status(_('largefiles: (no remote repo)\n'))
1146 return
1146 return
1147
1147
1148 toupload = set()
1148 toupload = set()
1149 lfhashes = set()
1149 lfhashes = set()
1150 def addfunc(fn, lfhash):
1150 def addfunc(fn, lfhash):
1151 toupload.add(fn)
1151 toupload.add(fn)
1152 lfhashes.add(lfhash)
1152 lfhashes.add(lfhash)
1153 _getoutgoings(repo, peer, outgoing.missing, addfunc)
1153 _getoutgoings(repo, peer, outgoing.missing, addfunc)
1154
1154
1155 if not toupload:
1155 if not toupload:
1156 # i18n: column positioning for "hg summary"
1156 # i18n: column positioning for "hg summary"
1157 ui.status(_('largefiles: (no files to upload)\n'))
1157 ui.status(_('largefiles: (no files to upload)\n'))
1158 else:
1158 else:
1159 # i18n: column positioning for "hg summary"
1159 # i18n: column positioning for "hg summary"
1160 ui.status(_('largefiles: %d entities for %d files to upload\n')
1160 ui.status(_('largefiles: %d entities for %d files to upload\n')
1161 % (len(lfhashes), len(toupload)))
1161 % (len(lfhashes), len(toupload)))
1162
1162
1163 def overridesummary(orig, ui, repo, *pats, **opts):
1163 def overridesummary(orig, ui, repo, *pats, **opts):
1164 try:
1164 try:
1165 repo.lfstatus = True
1165 repo.lfstatus = True
1166 orig(ui, repo, *pats, **opts)
1166 orig(ui, repo, *pats, **opts)
1167 finally:
1167 finally:
1168 repo.lfstatus = False
1168 repo.lfstatus = False
1169
1169
1170 def scmutiladdremove(orig, repo, matcher, prefix, opts=None, dry_run=None,
1170 def scmutiladdremove(orig, repo, matcher, prefix, opts=None, dry_run=None,
1171 similarity=None):
1171 similarity=None):
1172 if opts is None:
1172 if opts is None:
1173 opts = {}
1173 opts = {}
1174 if not lfutil.islfilesrepo(repo):
1174 if not lfutil.islfilesrepo(repo):
1175 return orig(repo, matcher, prefix, opts, dry_run, similarity)
1175 return orig(repo, matcher, prefix, opts, dry_run, similarity)
1176 # Get the list of missing largefiles so we can remove them
1176 # Get the list of missing largefiles so we can remove them
1177 lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
1177 lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
1178 unsure, s = lfdirstate.status(match_.always(repo.root, repo.getcwd()), [],
1178 unsure, s = lfdirstate.status(match_.always(repo.root, repo.getcwd()), [],
1179 False, False, False)
1179 False, False, False)
1180
1180
1181 # Call into the normal remove code, but the removing of the standin, we want
1181 # Call into the normal remove code, but the removing of the standin, we want
1182 # to have handled by original addremove. Monkey patching here makes sure
1182 # to have handled by original addremove. Monkey patching here makes sure
1183 # we don't remove the standin in the largefiles code, preventing a very
1183 # we don't remove the standin in the largefiles code, preventing a very
1184 # confused state later.
1184 # confused state later.
1185 if s.deleted:
1185 if s.deleted:
1186 m = copy.copy(matcher)
1186 m = copy.copy(matcher)
1187
1187
1188 # The m._files and m._map attributes are not changed to the deleted list
1188 # The m._files and m._map attributes are not changed to the deleted list
1189 # because that affects the m.exact() test, which in turn governs whether
1189 # because that affects the m.exact() test, which in turn governs whether
1190 # or not the file name is printed, and how. Simply limit the original
1190 # or not the file name is printed, and how. Simply limit the original
1191 # matches to those in the deleted status list.
1191 # matches to those in the deleted status list.
1192 matchfn = m.matchfn
1192 matchfn = m.matchfn
1193 m.matchfn = lambda f: f in s.deleted and matchfn(f)
1193 m.matchfn = lambda f: f in s.deleted and matchfn(f)
1194
1194
1195 removelargefiles(repo.ui, repo, True, m, **opts)
1195 removelargefiles(repo.ui, repo, True, m, **opts)
1196 # Call into the normal add code, and any files that *should* be added as
1196 # Call into the normal add code, and any files that *should* be added as
1197 # largefiles will be
1197 # largefiles will be
1198 added, bad = addlargefiles(repo.ui, repo, True, matcher, **opts)
1198 added, bad = addlargefiles(repo.ui, repo, True, matcher, **opts)
1199 # Now that we've handled largefiles, hand off to the original addremove
1199 # Now that we've handled largefiles, hand off to the original addremove
1200 # function to take care of the rest. Make sure it doesn't do anything with
1200 # function to take care of the rest. Make sure it doesn't do anything with
1201 # largefiles by passing a matcher that will ignore them.
1201 # largefiles by passing a matcher that will ignore them.
1202 matcher = composenormalfilematcher(matcher, repo[None].manifest(), added)
1202 matcher = composenormalfilematcher(matcher, repo[None].manifest(), added)
1203 return orig(repo, matcher, prefix, opts, dry_run, similarity)
1203 return orig(repo, matcher, prefix, opts, dry_run, similarity)
1204
1204
1205 # Calling purge with --all will cause the largefiles to be deleted.
1205 # Calling purge with --all will cause the largefiles to be deleted.
1206 # Override repo.status to prevent this from happening.
1206 # Override repo.status to prevent this from happening.
1207 def overridepurge(orig, ui, repo, *dirs, **opts):
1207 def overridepurge(orig, ui, repo, *dirs, **opts):
1208 # XXX Monkey patching a repoview will not work. The assigned attribute will
1208 # XXX Monkey patching a repoview will not work. The assigned attribute will
1209 # be set on the unfiltered repo, but we will only lookup attributes in the
1209 # be set on the unfiltered repo, but we will only lookup attributes in the
1210 # unfiltered repo if the lookup in the repoview object itself fails. As the
1210 # unfiltered repo if the lookup in the repoview object itself fails. As the
1211 # monkey patched method exists on the repoview class the lookup will not
1211 # monkey patched method exists on the repoview class the lookup will not
1212 # fail. As a result, the original version will shadow the monkey patched
1212 # fail. As a result, the original version will shadow the monkey patched
1213 # one, defeating the monkey patch.
1213 # one, defeating the monkey patch.
1214 #
1214 #
1215 # As a work around we use an unfiltered repo here. We should do something
1215 # As a work around we use an unfiltered repo here. We should do something
1216 # cleaner instead.
1216 # cleaner instead.
1217 repo = repo.unfiltered()
1217 repo = repo.unfiltered()
1218 oldstatus = repo.status
1218 oldstatus = repo.status
1219 def overridestatus(node1='.', node2=None, match=None, ignored=False,
1219 def overridestatus(node1='.', node2=None, match=None, ignored=False,
1220 clean=False, unknown=False, listsubrepos=False):
1220 clean=False, unknown=False, listsubrepos=False):
1221 r = oldstatus(node1, node2, match, ignored, clean, unknown,
1221 r = oldstatus(node1, node2, match, ignored, clean, unknown,
1222 listsubrepos)
1222 listsubrepos)
1223 lfdirstate = lfutil.openlfdirstate(ui, repo)
1223 lfdirstate = lfutil.openlfdirstate(ui, repo)
1224 unknown = [f for f in r.unknown if lfdirstate[f] == '?']
1224 unknown = [f for f in r.unknown if lfdirstate[f] == '?']
1225 ignored = [f for f in r.ignored if lfdirstate[f] == '?']
1225 ignored = [f for f in r.ignored if lfdirstate[f] == '?']
1226 return scmutil.status(r.modified, r.added, r.removed, r.deleted,
1226 return scmutil.status(r.modified, r.added, r.removed, r.deleted,
1227 unknown, ignored, r.clean)
1227 unknown, ignored, r.clean)
1228 repo.status = overridestatus
1228 repo.status = overridestatus
1229 orig(ui, repo, *dirs, **opts)
1229 orig(ui, repo, *dirs, **opts)
1230 repo.status = oldstatus
1230 repo.status = oldstatus
1231 def overriderollback(orig, ui, repo, **opts):
1231 def overriderollback(orig, ui, repo, **opts):
1232 with repo.wlock():
1232 with repo.wlock():
1233 before = repo.dirstate.parents()
1233 before = repo.dirstate.parents()
1234 orphans = set(f for f in repo.dirstate
1234 orphans = set(f for f in repo.dirstate
1235 if lfutil.isstandin(f) and repo.dirstate[f] != 'r')
1235 if lfutil.isstandin(f) and repo.dirstate[f] != 'r')
1236 result = orig(ui, repo, **opts)
1236 result = orig(ui, repo, **opts)
1237 after = repo.dirstate.parents()
1237 after = repo.dirstate.parents()
1238 if before == after:
1238 if before == after:
1239 return result # no need to restore standins
1239 return result # no need to restore standins
1240
1240
1241 pctx = repo['.']
1241 pctx = repo['.']
1242 for f in repo.dirstate:
1242 for f in repo.dirstate:
1243 if lfutil.isstandin(f):
1243 if lfutil.isstandin(f):
1244 orphans.discard(f)
1244 orphans.discard(f)
1245 if repo.dirstate[f] == 'r':
1245 if repo.dirstate[f] == 'r':
1246 repo.wvfs.unlinkpath(f, ignoremissing=True)
1246 repo.wvfs.unlinkpath(f, ignoremissing=True)
1247 elif f in pctx:
1247 elif f in pctx:
1248 fctx = pctx[f]
1248 fctx = pctx[f]
1249 repo.wwrite(f, fctx.data(), fctx.flags())
1249 repo.wwrite(f, fctx.data(), fctx.flags())
1250 else:
1250 else:
1251 # content of standin is not so important in 'a',
1251 # content of standin is not so important in 'a',
1252 # 'm' or 'n' (coming from the 2nd parent) cases
1252 # 'm' or 'n' (coming from the 2nd parent) cases
1253 lfutil.writestandin(repo, f, '', False)
1253 lfutil.writestandin(repo, f, '', False)
1254 for standin in orphans:
1254 for standin in orphans:
1255 repo.wvfs.unlinkpath(standin, ignoremissing=True)
1255 repo.wvfs.unlinkpath(standin, ignoremissing=True)
1256
1256
1257 lfdirstate = lfutil.openlfdirstate(ui, repo)
1257 lfdirstate = lfutil.openlfdirstate(ui, repo)
1258 orphans = set(lfdirstate)
1258 orphans = set(lfdirstate)
1259 lfiles = lfutil.listlfiles(repo)
1259 lfiles = lfutil.listlfiles(repo)
1260 for file in lfiles:
1260 for file in lfiles:
1261 lfutil.synclfdirstate(repo, lfdirstate, file, True)
1261 lfutil.synclfdirstate(repo, lfdirstate, file, True)
1262 orphans.discard(file)
1262 orphans.discard(file)
1263 for lfile in orphans:
1263 for lfile in orphans:
1264 lfdirstate.drop(lfile)
1264 lfdirstate.drop(lfile)
1265 lfdirstate.write()
1265 lfdirstate.write()
1266 return result
1266 return result
1267
1267
1268 def overridetransplant(orig, ui, repo, *revs, **opts):
1268 def overridetransplant(orig, ui, repo, *revs, **opts):
1269 resuming = opts.get('continue')
1269 resuming = opts.get('continue')
1270 repo._lfcommithooks.append(lfutil.automatedcommithook(resuming))
1270 repo._lfcommithooks.append(lfutil.automatedcommithook(resuming))
1271 repo._lfstatuswriters.append(lambda *msg, **opts: None)
1271 repo._lfstatuswriters.append(lambda *msg, **opts: None)
1272 try:
1272 try:
1273 result = orig(ui, repo, *revs, **opts)
1273 result = orig(ui, repo, *revs, **opts)
1274 finally:
1274 finally:
1275 repo._lfstatuswriters.pop()
1275 repo._lfstatuswriters.pop()
1276 repo._lfcommithooks.pop()
1276 repo._lfcommithooks.pop()
1277 return result
1277 return result
1278
1278
1279 def overridecat(orig, ui, repo, file1, *pats, **opts):
1279 def overridecat(orig, ui, repo, file1, *pats, **opts):
1280 ctx = scmutil.revsingle(repo, opts.get('rev'))
1280 ctx = scmutil.revsingle(repo, opts.get('rev'))
1281 err = 1
1281 err = 1
1282 notbad = set()
1282 notbad = set()
1283 m = scmutil.match(ctx, (file1,) + pats, opts)
1283 m = scmutil.match(ctx, (file1,) + pats, opts)
1284 origmatchfn = m.matchfn
1284 origmatchfn = m.matchfn
1285 def lfmatchfn(f):
1285 def lfmatchfn(f):
1286 if origmatchfn(f):
1286 if origmatchfn(f):
1287 return True
1287 return True
1288 lf = lfutil.splitstandin(f)
1288 lf = lfutil.splitstandin(f)
1289 if lf is None:
1289 if lf is None:
1290 return False
1290 return False
1291 notbad.add(lf)
1291 notbad.add(lf)
1292 return origmatchfn(lf)
1292 return origmatchfn(lf)
1293 m.matchfn = lfmatchfn
1293 m.matchfn = lfmatchfn
1294 origbadfn = m.bad
1294 origbadfn = m.bad
1295 def lfbadfn(f, msg):
1295 def lfbadfn(f, msg):
1296 if not f in notbad:
1296 if not f in notbad:
1297 origbadfn(f, msg)
1297 origbadfn(f, msg)
1298 m.bad = lfbadfn
1298 m.bad = lfbadfn
1299
1299
1300 origvisitdirfn = m.visitdir
1300 origvisitdirfn = m.visitdir
1301 def lfvisitdirfn(dir):
1301 def lfvisitdirfn(dir):
1302 if dir == lfutil.shortname:
1302 if dir == lfutil.shortname:
1303 return True
1303 return True
1304 ret = origvisitdirfn(dir)
1304 ret = origvisitdirfn(dir)
1305 if ret:
1305 if ret:
1306 return ret
1306 return ret
1307 lf = lfutil.splitstandin(dir)
1307 lf = lfutil.splitstandin(dir)
1308 if lf is None:
1308 if lf is None:
1309 return False
1309 return False
1310 return origvisitdirfn(lf)
1310 return origvisitdirfn(lf)
1311 m.visitdir = lfvisitdirfn
1311 m.visitdir = lfvisitdirfn
1312
1312
1313 for f in ctx.walk(m):
1313 for f in ctx.walk(m):
1314 fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(),
1314 fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(),
1315 pathname=f)
1315 pathname=f)
1316 lf = lfutil.splitstandin(f)
1316 lf = lfutil.splitstandin(f)
1317 if lf is None or origmatchfn(f):
1317 if lf is None or origmatchfn(f):
1318 # duplicating unreachable code from commands.cat
1318 # duplicating unreachable code from commands.cat
1319 data = ctx[f].data()
1319 data = ctx[f].data()
1320 if opts.get('decode'):
1320 if opts.get('decode'):
1321 data = repo.wwritedata(f, data)
1321 data = repo.wwritedata(f, data)
1322 fp.write(data)
1322 fp.write(data)
1323 else:
1323 else:
1324 hash = lfutil.readstandin(repo, lf, ctx.rev())
1324 hash = lfutil.readstandin(repo, lf, ctx.rev())
1325 if not lfutil.inusercache(repo.ui, hash):
1325 if not lfutil.inusercache(repo.ui, hash):
1326 store = basestore._openstore(repo)
1326 store = basestore._openstore(repo)
1327 success, missing = store.get([(lf, hash)])
1327 success, missing = store.get([(lf, hash)])
1328 if len(success) != 1:
1328 if len(success) != 1:
1329 raise error.Abort(
1329 raise error.Abort(
1330 _('largefile %s is not in cache and could not be '
1330 _('largefile %s is not in cache and could not be '
1331 'downloaded') % lf)
1331 'downloaded') % lf)
1332 path = lfutil.usercachepath(repo.ui, hash)
1332 path = lfutil.usercachepath(repo.ui, hash)
1333 fpin = open(path, "rb")
1333 fpin = open(path, "rb")
1334 for chunk in util.filechunkiter(fpin, 128 * 1024):
1334 for chunk in util.filechunkiter(fpin, 128 * 1024):
1335 fp.write(chunk)
1335 fp.write(chunk)
1336 fpin.close()
1336 fpin.close()
1337 fp.close()
1337 fp.close()
1338 err = 0
1338 err = 0
1339 return err
1339 return err
1340
1340
1341 def mergeupdate(orig, repo, node, branchmerge, force,
1341 def mergeupdate(orig, repo, node, branchmerge, force,
1342 *args, **kwargs):
1342 *args, **kwargs):
1343 matcher = kwargs.get('matcher', None)
1343 matcher = kwargs.get('matcher', None)
1344 # note if this is a partial update
1344 # note if this is a partial update
1345 partial = matcher and not matcher.always()
1345 partial = matcher and not matcher.always()
1346 with repo.wlock():
1346 with repo.wlock():
1347 # branch | | |
1347 # branch | | |
1348 # merge | force | partial | action
1348 # merge | force | partial | action
1349 # -------+-------+---------+--------------
1349 # -------+-------+---------+--------------
1350 # x | x | x | linear-merge
1350 # x | x | x | linear-merge
1351 # o | x | x | branch-merge
1351 # o | x | x | branch-merge
1352 # x | o | x | overwrite (as clean update)
1352 # x | o | x | overwrite (as clean update)
1353 # o | o | x | force-branch-merge (*1)
1353 # o | o | x | force-branch-merge (*1)
1354 # x | x | o | (*)
1354 # x | x | o | (*)
1355 # o | x | o | (*)
1355 # o | x | o | (*)
1356 # x | o | o | overwrite (as revert)
1356 # x | o | o | overwrite (as revert)
1357 # o | o | o | (*)
1357 # o | o | o | (*)
1358 #
1358 #
1359 # (*) don't care
1359 # (*) don't care
1360 # (*1) deprecated, but used internally (e.g: "rebase --collapse")
1360 # (*1) deprecated, but used internally (e.g: "rebase --collapse")
1361
1361
1362 lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
1362 lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
1363 unsure, s = lfdirstate.status(match_.always(repo.root,
1363 unsure, s = lfdirstate.status(match_.always(repo.root,
1364 repo.getcwd()),
1364 repo.getcwd()),
1365 [], False, False, False)
1365 [], False, False, False)
1366 pctx = repo['.']
1366 pctx = repo['.']
1367 for lfile in unsure + s.modified:
1367 for lfile in unsure + s.modified:
1368 lfileabs = repo.wvfs.join(lfile)
1368 lfileabs = repo.wvfs.join(lfile)
1369 if not os.path.exists(lfileabs):
1369 if not repo.wvfs.exists(lfileabs):
1370 continue
1370 continue
1371 lfhash = lfutil.hashrepofile(repo, lfile)
1371 lfhash = lfutil.hashrepofile(repo, lfile)
1372 standin = lfutil.standin(lfile)
1372 standin = lfutil.standin(lfile)
1373 lfutil.writestandin(repo, standin, lfhash,
1373 lfutil.writestandin(repo, standin, lfhash,
1374 lfutil.getexecutable(lfileabs))
1374 lfutil.getexecutable(lfileabs))
1375 if (standin in pctx and
1375 if (standin in pctx and
1376 lfhash == lfutil.readstandin(repo, lfile, '.')):
1376 lfhash == lfutil.readstandin(repo, lfile, '.')):
1377 lfdirstate.normal(lfile)
1377 lfdirstate.normal(lfile)
1378 for lfile in s.added:
1378 for lfile in s.added:
1379 lfutil.updatestandin(repo, lfutil.standin(lfile))
1379 lfutil.updatestandin(repo, lfutil.standin(lfile))
1380 lfdirstate.write()
1380 lfdirstate.write()
1381
1381
1382 oldstandins = lfutil.getstandinsstate(repo)
1382 oldstandins = lfutil.getstandinsstate(repo)
1383
1383
1384 result = orig(repo, node, branchmerge, force, *args, **kwargs)
1384 result = orig(repo, node, branchmerge, force, *args, **kwargs)
1385
1385
1386 newstandins = lfutil.getstandinsstate(repo)
1386 newstandins = lfutil.getstandinsstate(repo)
1387 filelist = lfutil.getlfilestoupdate(oldstandins, newstandins)
1387 filelist = lfutil.getlfilestoupdate(oldstandins, newstandins)
1388 if branchmerge or force or partial:
1388 if branchmerge or force or partial:
1389 filelist.extend(s.deleted + s.removed)
1389 filelist.extend(s.deleted + s.removed)
1390
1390
1391 lfcommands.updatelfiles(repo.ui, repo, filelist=filelist,
1391 lfcommands.updatelfiles(repo.ui, repo, filelist=filelist,
1392 normallookup=partial)
1392 normallookup=partial)
1393
1393
1394 return result
1394 return result
1395
1395
1396 def scmutilmarktouched(orig, repo, files, *args, **kwargs):
1396 def scmutilmarktouched(orig, repo, files, *args, **kwargs):
1397 result = orig(repo, files, *args, **kwargs)
1397 result = orig(repo, files, *args, **kwargs)
1398
1398
1399 filelist = [lfutil.splitstandin(f) for f in files if lfutil.isstandin(f)]
1399 filelist = [lfutil.splitstandin(f) for f in files if lfutil.isstandin(f)]
1400 if filelist:
1400 if filelist:
1401 lfcommands.updatelfiles(repo.ui, repo, filelist=filelist,
1401 lfcommands.updatelfiles(repo.ui, repo, filelist=filelist,
1402 printmessage=False, normallookup=True)
1402 printmessage=False, normallookup=True)
1403
1403
1404 return result
1404 return result
General Comments 0
You need to be logged in to leave comments. Login now