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