Mercurial > hg
annotate hgext/largefiles/lfcommands.py @ 17068:a86e110430f6
histedit: remove use of reduce() builtin spotted by check-code
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Wed, 27 Jun 2012 18:42:48 -0500 |
parents | 3e24ce3de5f1 |
children | 9e1616307c4c |
rev | line source |
---|---|
15168 | 1 # Copyright 2009-2010 Gregory P. Ward |
2 # Copyright 2009-2010 Intelerad Medical Systems Incorporated | |
3 # Copyright 2010-2011 Fog Creek Software | |
4 # Copyright 2010-2011 Unity Technologies | |
5 # | |
6 # This software may be used and distributed according to the terms of the | |
7 # GNU General Public License version 2 or any later version. | |
8 | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15230
diff
changeset
|
9 '''High-level command function for lfconvert, plus the cmdtable.''' |
15168 | 10 |
11 import os | |
12 import shutil | |
13 | |
16691
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
14 from mercurial import util, match as match_, hg, node, context, error, \ |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
15 cmdutil, scmutil |
15168 | 16 from mercurial.i18n import _ |
16717
1eede2ea2041
largefiles: use wlock for lfconvert (issue3444)
Mads Kiilerich <mads@kiilerich.com>
parents:
16551
diff
changeset
|
17 from mercurial.lock import release |
15168 | 18 |
19 import lfutil | |
20 import basestore | |
21 | |
22 # -- Commands ---------------------------------------------------------- | |
23 | |
24 def lfconvert(ui, src, dest, *pats, **opts): | |
15230 | 25 '''convert a normal repository to a largefiles repository |
15168 | 26 |
15230 | 27 Convert repository SOURCE to a new repository DEST, identical to |
28 SOURCE except that certain files will be converted as largefiles: | |
29 specifically, any file that matches any PATTERN *or* whose size is | |
30 above the minimum size threshold is converted as a largefile. The | |
31 size used to determine whether or not to track a file as a | |
32 largefile is the size of the first version of the file. The | |
33 minimum size can be specified either with --size or in | |
34 configuration as ``largefiles.size``. | |
35 | |
36 After running this command you will need to make sure that | |
37 largefiles is enabled anywhere you intend to push the new | |
38 repository. | |
39 | |
15332
0db47b8d025f
largefiles: rename lfconvert --tonormal option to --to-normal
Greg Ward <greg@gerg.ca>
parents:
15317
diff
changeset
|
40 Use --to-normal to convert largefiles back to normal files; after |
15230 | 41 this, the DEST repository can be used without largefiles at all.''' |
15168 | 42 |
15332
0db47b8d025f
largefiles: rename lfconvert --tonormal option to --to-normal
Greg Ward <greg@gerg.ca>
parents:
15317
diff
changeset
|
43 if opts['to_normal']: |
15168 | 44 tolfile = False |
45 else: | |
46 tolfile = True | |
15227
a7686abf73a6
largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents:
15224
diff
changeset
|
47 size = lfutil.getminsize(ui, True, opts.get('size'), default=None) |
15340
0e58513cc59a
largefiles: rearrange how lfconvert detects non-local repos
Greg Ward <greg@gerg.ca>
parents:
15339
diff
changeset
|
48 |
0e58513cc59a
largefiles: rearrange how lfconvert detects non-local repos
Greg Ward <greg@gerg.ca>
parents:
15339
diff
changeset
|
49 if not hg.islocal(src): |
0e58513cc59a
largefiles: rearrange how lfconvert detects non-local repos
Greg Ward <greg@gerg.ca>
parents:
15339
diff
changeset
|
50 raise util.Abort(_('%s is not a local Mercurial repo') % src) |
0e58513cc59a
largefiles: rearrange how lfconvert detects non-local repos
Greg Ward <greg@gerg.ca>
parents:
15339
diff
changeset
|
51 if not hg.islocal(dest): |
0e58513cc59a
largefiles: rearrange how lfconvert detects non-local repos
Greg Ward <greg@gerg.ca>
parents:
15339
diff
changeset
|
52 raise util.Abort(_('%s is not a local Mercurial repo') % dest) |
0e58513cc59a
largefiles: rearrange how lfconvert detects non-local repos
Greg Ward <greg@gerg.ca>
parents:
15339
diff
changeset
|
53 |
15339
be1377d19018
largefiles: test lfconvert error handling; remove redundant code
Greg Ward <greg@gerg.ca>
parents:
15332
diff
changeset
|
54 rsrc = hg.repository(ui, src) |
be1377d19018
largefiles: test lfconvert error handling; remove redundant code
Greg Ward <greg@gerg.ca>
parents:
15332
diff
changeset
|
55 ui.status(_('initializing destination %s\n') % dest) |
be1377d19018
largefiles: test lfconvert error handling; remove redundant code
Greg Ward <greg@gerg.ca>
parents:
15332
diff
changeset
|
56 rdst = hg.repository(ui, dest, create=True) |
15168 | 57 |
15171
547da6115d1d
largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents:
15170
diff
changeset
|
58 success = False |
16717
1eede2ea2041
largefiles: use wlock for lfconvert (issue3444)
Mads Kiilerich <mads@kiilerich.com>
parents:
16551
diff
changeset
|
59 dstwlock = dstlock = None |
15168 | 60 try: |
61 # Lock destination to prevent modification while it is converted to. | |
62 # Don't need to lock src because we are just reading from its history | |
63 # which can't change. | |
16717
1eede2ea2041
largefiles: use wlock for lfconvert (issue3444)
Mads Kiilerich <mads@kiilerich.com>
parents:
16551
diff
changeset
|
64 dstwlock = rdst.wlock() |
16247
d87d9d8a8e03
largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents:
16231
diff
changeset
|
65 dstlock = rdst.lock() |
15168 | 66 |
67 # Get a list of all changesets in the source. The easy way to do this | |
68 # is to simply walk the changelog, using changelog.nodesbewteen(). | |
69 # Take a look at mercurial/revlog.py:639 for more details. | |
70 # Use a generator instead of a list to decrease memory usage | |
71 ctxs = (rsrc[ctx] for ctx in rsrc.changelog.nodesbetween(None, | |
72 rsrc.heads())[0]) | |
73 revmap = {node.nullid: node.nullid} | |
74 if tolfile: | |
75 lfiles = set() | |
76 normalfiles = set() | |
77 if not pats: | |
15579
6c5e6ebe0812
largefiles: use "ui.configlist()" to get largefiles.patterns configuration
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15472
diff
changeset
|
78 pats = ui.configlist(lfutil.longname, 'patterns', default=[]) |
15168 | 79 if pats: |
80 matcher = match_.match(rsrc.root, '', list(pats)) | |
81 else: | |
82 matcher = None | |
83 | |
84 lfiletohash = {} | |
85 for ctx in ctxs: | |
86 ui.progress(_('converting revisions'), ctx.rev(), | |
87 unit=_('revision'), total=rsrc['tip'].rev()) | |
88 _lfconvert_addchangeset(rsrc, rdst, ctx, revmap, | |
89 lfiles, normalfiles, matcher, size, lfiletohash) | |
90 ui.progress(_('converting revisions'), None) | |
91 | |
92 if os.path.exists(rdst.wjoin(lfutil.shortname)): | |
93 shutil.rmtree(rdst.wjoin(lfutil.shortname)) | |
94 | |
95 for f in lfiletohash.keys(): | |
96 if os.path.isfile(rdst.wjoin(f)): | |
97 os.unlink(rdst.wjoin(f)) | |
98 try: | |
99 os.removedirs(os.path.dirname(rdst.wjoin(f))) | |
15171
547da6115d1d
largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents:
15170
diff
changeset
|
100 except OSError: |
15168 | 101 pass |
102 | |
15303
07811b3b119b
largefiles: include 'largefiles' in converted repository requirements
Eli Carter <eli.carter@tektronix.com>
parents:
15255
diff
changeset
|
103 # If there were any files converted to largefiles, add largefiles |
07811b3b119b
largefiles: include 'largefiles' in converted repository requirements
Eli Carter <eli.carter@tektronix.com>
parents:
15255
diff
changeset
|
104 # to the destination repository's requirements. |
07811b3b119b
largefiles: include 'largefiles' in converted repository requirements
Eli Carter <eli.carter@tektronix.com>
parents:
15255
diff
changeset
|
105 if lfiles: |
07811b3b119b
largefiles: include 'largefiles' in converted repository requirements
Eli Carter <eli.carter@tektronix.com>
parents:
15255
diff
changeset
|
106 rdst.requirements.add('largefiles') |
07811b3b119b
largefiles: include 'largefiles' in converted repository requirements
Eli Carter <eli.carter@tektronix.com>
parents:
15255
diff
changeset
|
107 rdst._writerequirements() |
15168 | 108 else: |
109 for ctx in ctxs: | |
110 ui.progress(_('converting revisions'), ctx.rev(), | |
111 unit=_('revision'), total=rsrc['tip'].rev()) | |
112 _addchangeset(ui, rsrc, rdst, ctx, revmap) | |
113 | |
114 ui.progress(_('converting revisions'), None) | |
15171
547da6115d1d
largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents:
15170
diff
changeset
|
115 success = True |
15168 | 116 finally: |
16717
1eede2ea2041
largefiles: use wlock for lfconvert (issue3444)
Mads Kiilerich <mads@kiilerich.com>
parents:
16551
diff
changeset
|
117 rdst.dirstate.clear() |
1eede2ea2041
largefiles: use wlock for lfconvert (issue3444)
Mads Kiilerich <mads@kiilerich.com>
parents:
16551
diff
changeset
|
118 release(dstlock, dstwlock) |
15171
547da6115d1d
largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents:
15170
diff
changeset
|
119 if not success: |
547da6115d1d
largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents:
15170
diff
changeset
|
120 # we failed, remove the new directory |
547da6115d1d
largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents:
15170
diff
changeset
|
121 shutil.rmtree(rdst.root) |
15168 | 122 |
123 def _addchangeset(ui, rsrc, rdst, ctx, revmap): | |
124 # Convert src parents to dst parents | |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
125 parents = _convertparents(ctx, revmap) |
15168 | 126 |
127 # Generate list of changed files | |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
128 files = _getchangedfiles(ctx, parents) |
15168 | 129 |
130 def getfilectx(repo, memctx, f): | |
131 if lfutil.standin(f) in files: | |
132 # if the file isn't in the manifest then it was removed | |
133 # or renamed, raise IOError to indicate this | |
134 try: | |
135 fctx = ctx.filectx(lfutil.standin(f)) | |
136 except error.LookupError: | |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
16551
diff
changeset
|
137 raise IOError |
15168 | 138 renamed = fctx.renamed() |
139 if renamed: | |
140 renamed = lfutil.splitstandin(renamed[0]) | |
141 | |
142 hash = fctx.data().strip() | |
143 path = lfutil.findfile(rsrc, hash) | |
144 ### TODO: What if the file is not cached? | |
145 data = '' | |
146 fd = None | |
147 try: | |
148 fd = open(path, 'rb') | |
149 data = fd.read() | |
150 finally: | |
15172
fb1dcd2aae2a
largefiles: fix multistatement line
Matt Mackall <mpm@selenic.com>
parents:
15171
diff
changeset
|
151 if fd: |
fb1dcd2aae2a
largefiles: fix multistatement line
Matt Mackall <mpm@selenic.com>
parents:
15171
diff
changeset
|
152 fd.close() |
15168 | 153 return context.memfilectx(f, data, 'l' in fctx.flags(), |
154 'x' in fctx.flags(), renamed) | |
155 else: | |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
156 return _getnormalcontext(repo.ui, ctx, f, revmap) |
15168 | 157 |
158 dstfiles = [] | |
159 for file in files: | |
160 if lfutil.isstandin(file): | |
161 dstfiles.append(lfutil.splitstandin(file)) | |
162 else: | |
163 dstfiles.append(file) | |
164 # Commit | |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
165 _commitcontext(rdst, parents, ctx, dstfiles, getfilectx, revmap) |
15168 | 166 |
167 def _lfconvert_addchangeset(rsrc, rdst, ctx, revmap, lfiles, normalfiles, | |
168 matcher, size, lfiletohash): | |
169 # Convert src parents to dst parents | |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
170 parents = _convertparents(ctx, revmap) |
15168 | 171 |
172 # Generate list of changed files | |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
173 files = _getchangedfiles(ctx, parents) |
15168 | 174 |
175 dstfiles = [] | |
176 for f in files: | |
177 if f not in lfiles and f not in normalfiles: | |
178 islfile = _islfile(f, ctx, matcher, size) | |
179 # If this file was renamed or copied then copy | |
180 # the lfileness of its predecessor | |
181 if f in ctx.manifest(): | |
182 fctx = ctx.filectx(f) | |
183 renamed = fctx.renamed() | |
184 renamedlfile = renamed and renamed[0] in lfiles | |
185 islfile |= renamedlfile | |
186 if 'l' in fctx.flags(): | |
187 if renamedlfile: | |
188 raise util.Abort( | |
15380
a53888685a6c
largefiles: fix uppercase in abort message
Martin Geisler <mg@aragost.com>
parents:
15371
diff
changeset
|
189 _('renamed/copied largefile %s becomes symlink') |
15170
c1a4a3220711
largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents:
15168
diff
changeset
|
190 % f) |
15168 | 191 islfile = False |
192 if islfile: | |
193 lfiles.add(f) | |
194 else: | |
195 normalfiles.add(f) | |
196 | |
197 if f in lfiles: | |
198 dstfiles.append(lfutil.standin(f)) | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
199 # largefile in manifest if it has not been removed/renamed |
15168 | 200 if f in ctx.manifest(): |
15808
62098aeb1e15
largefiles: don't reference uninitialized variable (issue3092)
Levi Bard <levi@unity3d.com>
parents:
15793
diff
changeset
|
201 fctx = ctx.filectx(f) |
62098aeb1e15
largefiles: don't reference uninitialized variable (issue3092)
Levi Bard <levi@unity3d.com>
parents:
15793
diff
changeset
|
202 if 'l' in fctx.flags(): |
62098aeb1e15
largefiles: don't reference uninitialized variable (issue3092)
Levi Bard <levi@unity3d.com>
parents:
15793
diff
changeset
|
203 renamed = fctx.renamed() |
15168 | 204 if renamed and renamed[0] in lfiles: |
205 raise util.Abort(_('largefile %s becomes symlink') % f) | |
206 | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
207 # largefile was modified, update standins |
15168 | 208 fullpath = rdst.wjoin(f) |
15371
f26ed4ea46d8
largefiles: remove lfutil.createdir, replace calls with util.makedirs
Hao Lian <hao@fogcreek.com>
parents:
15340
diff
changeset
|
209 util.makedirs(os.path.dirname(fullpath)) |
15168 | 210 m = util.sha1('') |
211 m.update(ctx[f].data()) | |
212 hash = m.hexdigest() | |
213 if f not in lfiletohash or lfiletohash[f] != hash: | |
214 try: | |
215 fd = open(fullpath, 'wb') | |
216 fd.write(ctx[f].data()) | |
217 finally: | |
218 if fd: | |
219 fd.close() | |
220 executable = 'x' in ctx[f].flags() | |
221 os.chmod(fullpath, lfutil.getmode(executable)) | |
222 lfutil.writestandin(rdst, lfutil.standin(f), hash, | |
223 executable) | |
224 lfiletohash[f] = hash | |
225 else: | |
226 # normal file | |
227 dstfiles.append(f) | |
228 | |
229 def getfilectx(repo, memctx, f): | |
230 if lfutil.isstandin(f): | |
231 # if the file isn't in the manifest then it was removed | |
232 # or renamed, raise IOError to indicate this | |
233 srcfname = lfutil.splitstandin(f) | |
234 try: | |
235 fctx = ctx.filectx(srcfname) | |
236 except error.LookupError: | |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
16551
diff
changeset
|
237 raise IOError |
15168 | 238 renamed = fctx.renamed() |
239 if renamed: | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
240 # standin is always a largefile because largefile-ness |
15168 | 241 # doesn't change after rename or copy |
242 renamed = lfutil.standin(renamed[0]) | |
243 | |
15313
3eb1a90ea409
largefiles: fix newline for lfconverted repos
Eli Carter <eli.carter@tektronix.com>
parents:
15303
diff
changeset
|
244 return context.memfilectx(f, lfiletohash[srcfname] + '\n', 'l' in |
15168 | 245 fctx.flags(), 'x' in fctx.flags(), renamed) |
246 else: | |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
247 return _getnormalcontext(repo.ui, ctx, f, revmap) |
15168 | 248 |
249 # Commit | |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
250 _commitcontext(rdst, parents, ctx, dstfiles, getfilectx, revmap) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
251 |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
252 def _commitcontext(rdst, parents, ctx, dstfiles, getfilectx, revmap): |
15168 | 253 mctx = context.memctx(rdst, parents, ctx.description(), dstfiles, |
254 getfilectx, ctx.user(), ctx.date(), ctx.extra()) | |
255 ret = rdst.commitctx(mctx) | |
16551
ebf6d38c9063
localrepo: add setparents() to adjust dirstate copies (issue3407)
Patrick Mezard <patrick@mezard.eu>
parents:
16439
diff
changeset
|
256 rdst.setparents(ret) |
15168 | 257 revmap[ctx.node()] = rdst.changelog.tip() |
258 | |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
259 # Generate list of changed files |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
260 def _getchangedfiles(ctx, parents): |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
261 files = set(ctx.files()) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
262 if node.nullid not in parents: |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
263 mc = ctx.manifest() |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
264 mp1 = ctx.parents()[0].manifest() |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
265 mp2 = ctx.parents()[1].manifest() |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
266 files |= (set(mp1) | set(mp2)) - set(mc) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
267 for f in mc: |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
268 if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, None): |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
269 files.add(f) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
270 return files |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
271 |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
272 # Convert src parents to dst parents |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
273 def _convertparents(ctx, revmap): |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
274 parents = [] |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
275 for p in ctx.parents(): |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
276 parents.append(revmap[p.node()]) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
277 while len(parents) < 2: |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
278 parents.append(node.nullid) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
279 return parents |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
280 |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
281 # Get memfilectx for a normal file |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
282 def _getnormalcontext(ui, ctx, f, revmap): |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
283 try: |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
284 fctx = ctx.filectx(f) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
285 except error.LookupError: |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
16551
diff
changeset
|
286 raise IOError |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
287 renamed = fctx.renamed() |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
288 if renamed: |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
289 renamed = renamed[0] |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
290 |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
291 data = fctx.data() |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
292 if f == '.hgtags': |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
293 data = _converttags (ui, revmap, data) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
294 return context.memfilectx(f, data, 'l' in fctx.flags(), |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
295 'x' in fctx.flags(), renamed) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
296 |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
297 # Remap tag data using a revision map |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
298 def _converttags(ui, revmap, data): |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
299 newdata = [] |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
300 for line in data.splitlines(): |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
301 try: |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
302 id, name = line.split(' ', 1) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
303 except ValueError: |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
304 ui.warn(_('skipping incorrectly formatted tag %s\n' |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
305 % line)) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
306 continue |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
307 try: |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
308 newid = node.bin(id) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
309 except TypeError: |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
310 ui.warn(_('skipping incorrectly formatted id %s\n' |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
311 % id)) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
312 continue |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
313 try: |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
314 newdata.append('%s %s\n' % (node.hex(revmap[newid]), |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
315 name)) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
316 except KeyError: |
16231
ce292f1379ba
i18n: fix all remaining uses of % inside _()
Matt Mackall <mpm@selenic.com>
parents:
15909
diff
changeset
|
317 ui.warn(_('no mapping for id %s\n') % id) |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
318 continue |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
319 return ''.join(newdata) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
320 |
15168 | 321 def _islfile(file, ctx, matcher, size): |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15230
diff
changeset
|
322 '''Return true if file should be considered a largefile, i.e. |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15230
diff
changeset
|
323 matcher matches it or it is larger than size.''' |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15230
diff
changeset
|
324 # never store special .hg* files as largefiles |
15168 | 325 if file == '.hgtags' or file == '.hgignore' or file == '.hgsigs': |
326 return False | |
327 if matcher and matcher(file): | |
328 return True | |
329 try: | |
330 return ctx.filectx(file).size() >= size * 1024 * 1024 | |
331 except error.LookupError: | |
332 return False | |
333 | |
334 def uploadlfiles(ui, rsrc, rdst, files): | |
335 '''upload largefiles to the central store''' | |
336 | |
15317
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15313
diff
changeset
|
337 if not files: |
15168 | 338 return |
339 | |
340 store = basestore._openstore(rsrc, rdst, put=True) | |
341 | |
342 at = 0 | |
343 files = filter(lambda h: not store.exists(h), files) | |
344 for hash in files: | |
15170
c1a4a3220711
largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents:
15168
diff
changeset
|
345 ui.progress(_('uploading largefiles'), at, unit='largefile', |
c1a4a3220711
largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents:
15168
diff
changeset
|
346 total=len(files)) |
15168 | 347 source = lfutil.findfile(rsrc, hash) |
348 if not source: | |
15253
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
349 raise util.Abort(_('largefile %s missing from store' |
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
350 ' (needs to be uploaded)') % hash) |
15168 | 351 # XXX check for errors here |
352 store.put(source, hash) | |
353 at += 1 | |
15173
3d27a8ff895f
largefiles: mark a string for translation
Matt Mackall <mpm@selenic.com>
parents:
15172
diff
changeset
|
354 ui.progress(_('uploading largefiles'), None) |
15168 | 355 |
356 def verifylfiles(ui, repo, all=False, contents=False): | |
357 '''Verify that every big file revision in the current changeset | |
358 exists in the central store. With --contents, also verify that | |
359 the contents of each big file revision are correct (SHA-1 hash | |
360 matches the revision ID). With --all, check every changeset in | |
361 this repository.''' | |
362 if all: | |
363 # Pass a list to the function rather than an iterator because we know a | |
364 # list will work. | |
365 revs = range(len(repo)) | |
366 else: | |
367 revs = ['.'] | |
368 | |
369 store = basestore._openstore(repo) | |
370 return store.verify(revs, contents=contents) | |
371 | |
16700
28001e8a5149
largefiles: optimize performance when updating (issue3440)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16691
diff
changeset
|
372 def cachelfiles(ui, repo, node, filelist=None): |
15168 | 373 '''cachelfiles ensures that all largefiles needed by the specified revision |
374 are present in the repository's largefile cache. | |
375 | |
376 returns a tuple (cached, missing). cached is the list of files downloaded | |
377 by this operation; missing is the list of files that were needed but could | |
378 not be found.''' | |
379 lfiles = lfutil.listlfiles(repo, node) | |
16700
28001e8a5149
largefiles: optimize performance when updating (issue3440)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16691
diff
changeset
|
380 if filelist: |
28001e8a5149
largefiles: optimize performance when updating (issue3440)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16691
diff
changeset
|
381 lfiles = set(lfiles) & set(filelist) |
15168 | 382 toget = [] |
383 | |
384 for lfile in lfiles: | |
15860
3ecce805ac13
largefiles: correctly download new largefiles when merging
Na'Tosha Bard <natosha@unity3d.com>
parents:
15811
diff
changeset
|
385 # If we are mid-merge, then we have to trust the standin that is in the |
3ecce805ac13
largefiles: correctly download new largefiles when merging
Na'Tosha Bard <natosha@unity3d.com>
parents:
15811
diff
changeset
|
386 # working copy to have the correct hashvalue. This is because the |
3ecce805ac13
largefiles: correctly download new largefiles when merging
Na'Tosha Bard <natosha@unity3d.com>
parents:
15811
diff
changeset
|
387 # original hg.merge() already updated the standin as part of the normal |
3ecce805ac13
largefiles: correctly download new largefiles when merging
Na'Tosha Bard <natosha@unity3d.com>
parents:
15811
diff
changeset
|
388 # merge process -- we just have to udpate the largefile to match. |
15905
634d49a8b6db
largefiles: correctly handle newly added largefile on other side of merge
Na'Tosha Bard <natosha@unity3d.com>
parents:
15860
diff
changeset
|
389 if (getattr(repo, "_ismerging", False) and |
634d49a8b6db
largefiles: correctly handle newly added largefile on other side of merge
Na'Tosha Bard <natosha@unity3d.com>
parents:
15860
diff
changeset
|
390 os.path.exists(repo.wjoin(lfutil.standin(lfile)))): |
15860
3ecce805ac13
largefiles: correctly download new largefiles when merging
Na'Tosha Bard <natosha@unity3d.com>
parents:
15811
diff
changeset
|
391 expectedhash = lfutil.readstandin(repo, lfile) |
3ecce805ac13
largefiles: correctly download new largefiles when merging
Na'Tosha Bard <natosha@unity3d.com>
parents:
15811
diff
changeset
|
392 else: |
3ecce805ac13
largefiles: correctly download new largefiles when merging
Na'Tosha Bard <natosha@unity3d.com>
parents:
15811
diff
changeset
|
393 expectedhash = repo[node][lfutil.standin(lfile)].data().strip() |
3ecce805ac13
largefiles: correctly download new largefiles when merging
Na'Tosha Bard <natosha@unity3d.com>
parents:
15811
diff
changeset
|
394 |
15168 | 395 # if it exists and its hash matches, it might have been locally |
396 # modified before updating and the user chose 'local'. in this case, | |
397 # it will not be in any store, so don't look for it. | |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
398 if ((not os.path.exists(repo.wjoin(lfile)) or |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
399 expectedhash != lfutil.hashfile(repo.wjoin(lfile))) and |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
400 not lfutil.findfile(repo, expectedhash)): |
15168 | 401 toget.append((lfile, expectedhash)) |
402 | |
403 if toget: | |
404 store = basestore._openstore(repo) | |
405 ret = store.get(toget) | |
406 return ret | |
407 | |
408 return ([], []) | |
409 | |
16691
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
410 def downloadlfiles(ui, repo, rev=None): |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
411 matchfn = scmutil.match(repo[None], |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
412 [repo.wjoin(lfutil.shortname)], {}) |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
413 def prepare(ctx, fns): |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
414 pass |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
415 totalsuccess = 0 |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
416 totalmissing = 0 |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
417 for ctx in cmdutil.walkchangerevs(repo, matchfn, {'rev' : rev}, |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
418 prepare): |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
419 success, missing = cachelfiles(ui, repo, ctx.node()) |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
420 totalsuccess += len(success) |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
421 totalmissing += len(missing) |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
422 ui.status(_("%d additional largefiles cached\n") % totalsuccess) |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
423 if totalmissing > 0: |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
424 ui.status(_("%d largefiles failed to download\n") % totalmissing) |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
425 return totalsuccess, totalmissing |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
426 |
15168 | 427 def updatelfiles(ui, repo, filelist=None, printmessage=True): |
428 wlock = repo.wlock() | |
429 try: | |
430 lfdirstate = lfutil.openlfdirstate(ui, repo) | |
431 lfiles = set(lfutil.listlfiles(repo)) | set(lfdirstate) | |
432 | |
433 if filelist is not None: | |
434 lfiles = [f for f in lfiles if f in filelist] | |
435 | |
436 printed = False | |
437 if printmessage and lfiles: | |
438 ui.status(_('getting changed largefiles\n')) | |
439 printed = True | |
16700
28001e8a5149
largefiles: optimize performance when updating (issue3440)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16691
diff
changeset
|
440 cachelfiles(ui, repo, '.', lfiles) |
15168 | 441 |
442 updated, removed = 0, 0 | |
443 for i in map(lambda f: _updatelfile(repo, lfdirstate, f), lfiles): | |
444 # increment the appropriate counter according to _updatelfile's | |
445 # return value | |
446 updated += i > 0 and i or 0 | |
447 removed -= i < 0 and i or 0 | |
448 if printmessage and (removed or updated) and not printed: | |
449 ui.status(_('getting changed largefiles\n')) | |
450 printed = True | |
451 | |
452 lfdirstate.write() | |
453 if printed and printmessage: | |
454 ui.status(_('%d largefiles updated, %d removed\n') % (updated, | |
455 removed)) | |
456 finally: | |
457 wlock.release() | |
458 | |
459 def _updatelfile(repo, lfdirstate, lfile): | |
460 '''updates a single largefile and copies the state of its standin from | |
461 the repository's dirstate to its state in the lfdirstate. | |
462 | |
463 returns 1 if the file was modified, -1 if the file was removed, 0 if the | |
464 file was unchanged, and None if the needed largefile was missing from the | |
465 cache.''' | |
466 ret = 0 | |
467 abslfile = repo.wjoin(lfile) | |
468 absstandin = repo.wjoin(lfutil.standin(lfile)) | |
469 if os.path.exists(absstandin): | |
470 if os.path.exists(absstandin+'.orig'): | |
471 shutil.copyfile(abslfile, abslfile+'.orig') | |
472 expecthash = lfutil.readstandin(repo, lfile) | |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
473 if (expecthash != '' and |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
474 (not os.path.exists(abslfile) or |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
475 expecthash != lfutil.hashfile(abslfile))): |
15168 | 476 if not lfutil.copyfromcache(repo, expecthash, lfile): |
15472
6a7e874390b0
largefiles: treat status of cache missed largefiles as "missing" correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15380
diff
changeset
|
477 # use normallookup() to allocate entry in largefiles dirstate, |
16247
d87d9d8a8e03
largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents:
16231
diff
changeset
|
478 # because lack of it misleads lfilesrepo.status() into |
15472
6a7e874390b0
largefiles: treat status of cache missed largefiles as "missing" correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15380
diff
changeset
|
479 # recognition that such cache missing files are REMOVED. |
6a7e874390b0
largefiles: treat status of cache missed largefiles as "missing" correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15380
diff
changeset
|
480 lfdirstate.normallookup(lfile) |
6a7e874390b0
largefiles: treat status of cache missed largefiles as "missing" correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15380
diff
changeset
|
481 return None # don't try to set the mode |
15168 | 482 ret = 1 |
483 mode = os.stat(absstandin).st_mode | |
484 if mode != os.stat(abslfile).st_mode: | |
485 os.chmod(abslfile, mode) | |
486 ret = 1 | |
487 else: | |
15663
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15579
diff
changeset
|
488 # Remove lfiles for which the standin is deleted, unless the |
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15579
diff
changeset
|
489 # lfile is added to the repository again. This happens when a |
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15579
diff
changeset
|
490 # largefile is converted back to a normal file: the standin |
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15579
diff
changeset
|
491 # disappears, but a new (normal) file appears as the lfile. |
9036c7d106bf
largefiles: handle merges between normal files and largefiles (issue3084)
Martin Geisler <mg@aragost.com>
parents:
15579
diff
changeset
|
492 if os.path.exists(abslfile) and lfile not in repo[None]: |
15900
29defa7d20f6
largefiles: remove empty directories upon update (issue3202)
Patrick Mezard <pmezard@gmail.com>
parents:
15663
diff
changeset
|
493 util.unlinkpath(abslfile) |
15168 | 494 ret = -1 |
495 state = repo.dirstate[lfutil.standin(lfile)] | |
496 if state == 'n': | |
15793
3ef07ecdb0d5
largefiles: correctly handle dirstate status when rebasing
Na'Tosha Bard <natosha@unity3d.com>
parents:
15663
diff
changeset
|
497 # When rebasing, we need to synchronize the standin and the largefile, |
3ef07ecdb0d5
largefiles: correctly handle dirstate status when rebasing
Na'Tosha Bard <natosha@unity3d.com>
parents:
15663
diff
changeset
|
498 # because otherwise the largefile will get reverted. But for commit's |
3ef07ecdb0d5
largefiles: correctly handle dirstate status when rebasing
Na'Tosha Bard <natosha@unity3d.com>
parents:
15663
diff
changeset
|
499 # sake, we have to mark the file as unclean. |
3ef07ecdb0d5
largefiles: correctly handle dirstate status when rebasing
Na'Tosha Bard <natosha@unity3d.com>
parents:
15663
diff
changeset
|
500 if getattr(repo, "_isrebasing", False): |
3ef07ecdb0d5
largefiles: correctly handle dirstate status when rebasing
Na'Tosha Bard <natosha@unity3d.com>
parents:
15663
diff
changeset
|
501 lfdirstate.normallookup(lfile) |
3ef07ecdb0d5
largefiles: correctly handle dirstate status when rebasing
Na'Tosha Bard <natosha@unity3d.com>
parents:
15663
diff
changeset
|
502 else: |
3ef07ecdb0d5
largefiles: correctly handle dirstate status when rebasing
Na'Tosha Bard <natosha@unity3d.com>
parents:
15663
diff
changeset
|
503 lfdirstate.normal(lfile) |
15168 | 504 elif state == 'r': |
505 lfdirstate.remove(lfile) | |
506 elif state == 'a': | |
507 lfdirstate.add(lfile) | |
508 elif state == '?': | |
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15173
diff
changeset
|
509 lfdirstate.drop(lfile) |
15168 | 510 return ret |
511 | |
16439
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
512 def catlfile(repo, lfile, rev, filename): |
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
513 hash = lfutil.readstandin(repo, lfile, rev) |
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
514 if not lfutil.inusercache(repo.ui, hash): |
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
515 store = basestore._openstore(repo) |
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
516 success, missing = store.get([(lfile, hash)]) |
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
517 if len(success) != 1: |
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
518 raise util.Abort( |
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
519 _('largefile %s is not in cache and could not be downloaded') |
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
520 % lfile) |
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
521 path = lfutil.usercachepath(repo.ui, hash) |
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
522 fpout = cmdutil.makefileobj(repo, filename) |
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
523 fpin = open(path, "rb") |
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
524 fpout.write(fpin.read()) |
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
525 fpout.close() |
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
526 fpin.close() |
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
527 return 0 |
290850e7aa43
largefiles: fix cat for largefiles (issue3352)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16247
diff
changeset
|
528 |
15168 | 529 # -- hg commands declarations ------------------------------------------------ |
530 | |
531 cmdtable = { | |
532 'lfconvert': (lfconvert, | |
15230 | 533 [('s', 'size', '', |
534 _('minimum size (MB) for files to be converted ' | |
535 'as largefiles'), | |
536 'SIZE'), | |
15332
0db47b8d025f
largefiles: rename lfconvert --tonormal option to --to-normal
Greg Ward <greg@gerg.ca>
parents:
15317
diff
changeset
|
537 ('', 'to-normal', False, |
15230 | 538 _('convert from a largefiles repo to a normal repo')), |
539 ], | |
15168 | 540 _('hg lfconvert SOURCE DEST [FILE ...]')), |
541 } |