author | Taapas Agrawal <taapas2897@gmail.com> |
Tue, 16 Jul 2019 01:59:28 +0530 | |
changeset 42613 | 35ebdbb38efb |
parent 41775 | a86e22007b54 |
child 43076 | 2372284d9457 |
permissions | -rw-r--r-- |
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.''' |
29308
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
10 |
from __future__ import absolute_import |
15168 | 11 |
|
29308
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
12 |
import errno |
29341
0d83ad967bf8
cleanup: replace uses of util.(md5|sha1|sha256|sha512) with hashlib.\1
Augie Fackler <raf@durin42.com>
parents:
29317
diff
changeset
|
13 |
import hashlib |
29308
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
14 |
import os |
15168 | 15 |
import shutil |
16 |
||
17 |
from mercurial.i18n import _ |
|
18 |
||
29308
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
19 |
from mercurial import ( |
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
20 |
cmdutil, |
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
21 |
context, |
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
22 |
error, |
41061
98681293c890
largefiles: port commands to exthelper
Matt Harbison <matt_harbison@yahoo.com>
parents:
40675
diff
changeset
|
23 |
exthelper, |
29308
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
24 |
hg, |
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
25 |
lock, |
29317
5ec25534ef4f
largefiles: rename match_ to matchmod import in lfcommands
liscju <piotr.listkiewicz@gmail.com>
parents:
29308
diff
changeset
|
26 |
match as matchmod, |
29308
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
27 |
node, |
35348
576ba8194fa8
py3: handle keyword arguments correctly in hgext/largefiles/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35186
diff
changeset
|
28 |
pycompat, |
29308
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
29 |
scmutil, |
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
30 |
util, |
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
31 |
) |
25325
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
32 |
|
29308
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
33 |
from ..convert import ( |
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
34 |
convcmd, |
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
35 |
filemap, |
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
36 |
) |
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
37 |
|
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
38 |
from . import ( |
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
39 |
lfutil, |
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
40 |
storefactory |
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
41 |
) |
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
42 |
|
8c378a7d2aa6
py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents:
29305
diff
changeset
|
43 |
release = lock.release |
15168 | 44 |
|
45 |
# -- Commands ---------------------------------------------------------- |
|
46 |
||
41061
98681293c890
largefiles: port commands to exthelper
Matt Harbison <matt_harbison@yahoo.com>
parents:
40675
diff
changeset
|
47 |
eh = exthelper.exthelper() |
21242
4c94229c51fb
largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21088
diff
changeset
|
48 |
|
41061
98681293c890
largefiles: port commands to exthelper
Matt Harbison <matt_harbison@yahoo.com>
parents:
40675
diff
changeset
|
49 |
@eh.command('lfconvert', |
21242
4c94229c51fb
largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21088
diff
changeset
|
50 |
[('s', 'size', '', |
4c94229c51fb
largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21088
diff
changeset
|
51 |
_('minimum size (MB) for files to be converted as largefiles'), 'SIZE'), |
4c94229c51fb
largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21088
diff
changeset
|
52 |
('', 'to-normal', False, |
4c94229c51fb
largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21088
diff
changeset
|
53 |
_('convert from a largefiles repo to a normal repo')), |
4c94229c51fb
largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21088
diff
changeset
|
54 |
], |
21770
15d434bee41c
largefiles: define norepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21689
diff
changeset
|
55 |
_('hg lfconvert SOURCE DEST [FILE ...]'), |
21785
a730b002c5db
largefiles: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21770
diff
changeset
|
56 |
norepo=True, |
a730b002c5db
largefiles: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21770
diff
changeset
|
57 |
inferrepo=True) |
15168 | 58 |
def lfconvert(ui, src, dest, *pats, **opts): |
15230 | 59 |
'''convert a normal repository to a largefiles repository |
15168 | 60 |
|
15230 | 61 |
Convert repository SOURCE to a new repository DEST, identical to |
62 |
SOURCE except that certain files will be converted as largefiles: |
|
63 |
specifically, any file that matches any PATTERN *or* whose size is |
|
64 |
above the minimum size threshold is converted as a largefile. The |
|
65 |
size used to determine whether or not to track a file as a |
|
66 |
largefile is the size of the first version of the file. The |
|
67 |
minimum size can be specified either with --size or in |
|
68 |
configuration as ``largefiles.size``. |
|
69 |
||
70 |
After running this command you will need to make sure that |
|
71 |
largefiles is enabled anywhere you intend to push the new |
|
72 |
repository. |
|
73 |
||
15332
0db47b8d025f
largefiles: rename lfconvert --tonormal option to --to-normal
Greg Ward <greg@gerg.ca>
parents:
15317
diff
changeset
|
74 |
Use --to-normal to convert largefiles back to normal files; after |
15230 | 75 |
this, the DEST repository can be used without largefiles at all.''' |
15168 | 76 |
|
35348
576ba8194fa8
py3: handle keyword arguments correctly in hgext/largefiles/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35186
diff
changeset
|
77 |
opts = pycompat.byteskwargs(opts) |
15332
0db47b8d025f
largefiles: rename lfconvert --tonormal option to --to-normal
Greg Ward <greg@gerg.ca>
parents:
15317
diff
changeset
|
78 |
if opts['to_normal']: |
15168 | 79 |
tolfile = False |
80 |
else: |
|
81 |
tolfile = True |
|
15227
a7686abf73a6
largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents:
15224
diff
changeset
|
82 |
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
|
83 |
|
0e58513cc59a
largefiles: rearrange how lfconvert detects non-local repos
Greg Ward <greg@gerg.ca>
parents:
15339
diff
changeset
|
84 |
if not hg.islocal(src): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25660
diff
changeset
|
85 |
raise error.Abort(_('%s is not a local Mercurial repo') % src) |
15340
0e58513cc59a
largefiles: rearrange how lfconvert detects non-local repos
Greg Ward <greg@gerg.ca>
parents:
15339
diff
changeset
|
86 |
if not hg.islocal(dest): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25660
diff
changeset
|
87 |
raise error.Abort(_('%s is not a local Mercurial repo') % dest) |
15340
0e58513cc59a
largefiles: rearrange how lfconvert detects non-local repos
Greg Ward <greg@gerg.ca>
parents:
15339
diff
changeset
|
88 |
|
15339
be1377d19018
largefiles: test lfconvert error handling; remove redundant code
Greg Ward <greg@gerg.ca>
parents:
15332
diff
changeset
|
89 |
rsrc = hg.repository(ui, src) |
be1377d19018
largefiles: test lfconvert error handling; remove redundant code
Greg Ward <greg@gerg.ca>
parents:
15332
diff
changeset
|
90 |
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
|
91 |
rdst = hg.repository(ui, dest, create=True) |
15168 | 92 |
|
15171
547da6115d1d
largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents:
15170
diff
changeset
|
93 |
success = False |
16717
1eede2ea2041
largefiles: use wlock for lfconvert (issue3444)
Mads Kiilerich <mads@kiilerich.com>
parents:
16551
diff
changeset
|
94 |
dstwlock = dstlock = None |
15168 | 95 |
try: |
96 |
# Get a list of all changesets in the source. The easy way to do this |
|
17424
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
17299
diff
changeset
|
97 |
# is to simply walk the changelog, using changelog.nodesbetween(). |
15168 | 98 |
# Take a look at mercurial/revlog.py:639 for more details. |
99 |
# Use a generator instead of a list to decrease memory usage |
|
100 |
ctxs = (rsrc[ctx] for ctx in rsrc.changelog.nodesbetween(None, |
|
101 |
rsrc.heads())[0]) |
|
102 |
revmap = {node.nullid: node.nullid} |
|
103 |
if tolfile: |
|
25325
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
104 |
# Lock destination to prevent modification while it is converted to. |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
105 |
# Don't need to lock src because we are just reading from its |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
106 |
# history which can't change. |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
107 |
dstwlock = rdst.wlock() |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
108 |
dstlock = rdst.lock() |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
109 |
|
15168 | 110 |
lfiles = set() |
111 |
normalfiles = set() |
|
112 |
if not pats: |
|
34756
3f3c6d12095d
configitems: register the 'largefiles.patterns' config
Boris Feld <boris.feld@octobus.net>
parents:
34083
diff
changeset
|
113 |
pats = ui.configlist(lfutil.longname, 'patterns') |
15168 | 114 |
if pats: |
29317
5ec25534ef4f
largefiles: rename match_ to matchmod import in lfcommands
liscju <piotr.listkiewicz@gmail.com>
parents:
29308
diff
changeset
|
115 |
matcher = matchmod.match(rsrc.root, '', list(pats)) |
15168 | 116 |
else: |
117 |
matcher = None |
|
118 |
||
119 |
lfiletohash = {} |
|
39390
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
120 |
with ui.makeprogress(_('converting revisions'), |
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
121 |
unit=_('revisions'), |
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
122 |
total=rsrc['tip'].rev()) as progress: |
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
123 |
for ctx in ctxs: |
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
124 |
progress.update(ctx.rev()) |
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
125 |
_lfconvert_addchangeset(rsrc, rdst, ctx, revmap, |
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
126 |
lfiles, normalfiles, matcher, size, lfiletohash) |
15168 | 127 |
|
28559
30863ca01c6b
largefiles: replace invocation of os.path module by vfs in lfcommands.py
liscju <piotr.listkiewicz@gmail.com>
parents:
28464
diff
changeset
|
128 |
if rdst.wvfs.exists(lfutil.shortname): |
30863ca01c6b
largefiles: replace invocation of os.path module by vfs in lfcommands.py
liscju <piotr.listkiewicz@gmail.com>
parents:
28464
diff
changeset
|
129 |
rdst.wvfs.rmtree(lfutil.shortname) |
15168 | 130 |
|
131 |
for f in lfiletohash.keys(): |
|
28559
30863ca01c6b
largefiles: replace invocation of os.path module by vfs in lfcommands.py
liscju <piotr.listkiewicz@gmail.com>
parents:
28464
diff
changeset
|
132 |
if rdst.wvfs.isfile(f): |
30863ca01c6b
largefiles: replace invocation of os.path module by vfs in lfcommands.py
liscju <piotr.listkiewicz@gmail.com>
parents:
28464
diff
changeset
|
133 |
rdst.wvfs.unlink(f) |
15168 | 134 |
try: |
28559
30863ca01c6b
largefiles: replace invocation of os.path module by vfs in lfcommands.py
liscju <piotr.listkiewicz@gmail.com>
parents:
28464
diff
changeset
|
135 |
rdst.wvfs.removedirs(rdst.wvfs.dirname(f)) |
15171
547da6115d1d
largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents:
15170
diff
changeset
|
136 |
except OSError: |
15168 | 137 |
pass |
138 |
||
15303
07811b3b119b
largefiles: include 'largefiles' in converted repository requirements
Eli Carter <eli.carter@tektronix.com>
parents:
15255
diff
changeset
|
139 |
# 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
|
140 |
# to the destination repository's requirements. |
07811b3b119b
largefiles: include 'largefiles' in converted repository requirements
Eli Carter <eli.carter@tektronix.com>
parents:
15255
diff
changeset
|
141 |
if lfiles: |
07811b3b119b
largefiles: include 'largefiles' in converted repository requirements
Eli Carter <eli.carter@tektronix.com>
parents:
15255
diff
changeset
|
142 |
rdst.requirements.add('largefiles') |
07811b3b119b
largefiles: include 'largefiles' in converted repository requirements
Eli Carter <eli.carter@tektronix.com>
parents:
15255
diff
changeset
|
143 |
rdst._writerequirements() |
15168 | 144 |
else: |
25325
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
145 |
class lfsource(filemap.filemap_source): |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
146 |
def __init__(self, ui, source): |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
147 |
super(lfsource, self).__init__(ui, source, None) |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
148 |
self.filemapper.rename[lfutil.shortname] = '.' |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
149 |
|
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
150 |
def getfile(self, name, rev): |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
151 |
realname, realrev = rev |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
152 |
f = super(lfsource, self).getfile(name, rev) |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
153 |
|
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
154 |
if (not realname.startswith(lfutil.shortnameslash) |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
155 |
or f[0] is None): |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
156 |
return f |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
157 |
|
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
158 |
# Substitute in the largefile data for the hash |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
159 |
hash = f[0].strip() |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
160 |
path = lfutil.findfile(rsrc, hash) |
15168 | 161 |
|
25325
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
162 |
if path is None: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25660
diff
changeset
|
163 |
raise error.Abort(_("missing largefile for '%s' in %s") |
25325
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
164 |
% (realname, realrev)) |
27774
8ceaaf63ca80
largefiles: use util.readfile in lfconvert
Bryan O'Sullivan <bryano@fb.com>
parents:
27651
diff
changeset
|
165 |
return util.readfile(path), f[1] |
25325
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
166 |
|
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
167 |
class converter(convcmd.converter): |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
168 |
def __init__(self, ui, source, dest, revmapfile, opts): |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
169 |
src = lfsource(ui, source) |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
170 |
|
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
171 |
super(converter, self).__init__(ui, src, dest, revmapfile, |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
172 |
opts) |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
173 |
|
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
174 |
found, missing = downloadlfiles(ui, rsrc) |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
175 |
if missing != 0: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25660
diff
changeset
|
176 |
raise error.Abort(_("all largefiles must be present locally")) |
25325
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
177 |
|
25560
2b2108c35bfc
largefiles: restore the original converter class after lfconvert --to-normal
Matt Harbison <matt_harbison@yahoo.com>
parents:
25508
diff
changeset
|
178 |
orig = convcmd.converter |
25325
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
179 |
convcmd.converter = converter |
25560
2b2108c35bfc
largefiles: restore the original converter class after lfconvert --to-normal
Matt Harbison <matt_harbison@yahoo.com>
parents:
25508
diff
changeset
|
180 |
|
2b2108c35bfc
largefiles: restore the original converter class after lfconvert --to-normal
Matt Harbison <matt_harbison@yahoo.com>
parents:
25508
diff
changeset
|
181 |
try: |
35179
4abfe4169259
largefiles: explicitly set the source and sink types to 'hg' for lfconvert
Matt Harbison <matt_harbison@yahoo.com>
parents:
34756
diff
changeset
|
182 |
convcmd.convert(ui, src, dest, source_type='hg', dest_type='hg') |
25560
2b2108c35bfc
largefiles: restore the original converter class after lfconvert --to-normal
Matt Harbison <matt_harbison@yahoo.com>
parents:
25508
diff
changeset
|
183 |
finally: |
2b2108c35bfc
largefiles: restore the original converter class after lfconvert --to-normal
Matt Harbison <matt_harbison@yahoo.com>
parents:
25508
diff
changeset
|
184 |
convcmd.converter = orig |
15171
547da6115d1d
largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents:
15170
diff
changeset
|
185 |
success = True |
15168 | 186 |
finally: |
25325
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
187 |
if tolfile: |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
188 |
rdst.dirstate.clear() |
fcd2f9b06629
largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents:
24788
diff
changeset
|
189 |
release(dstlock, dstwlock) |
15171
547da6115d1d
largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents:
15170
diff
changeset
|
190 |
if not success: |
547da6115d1d
largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents:
15170
diff
changeset
|
191 |
# we failed, remove the new directory |
547da6115d1d
largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents:
15170
diff
changeset
|
192 |
shutil.rmtree(rdst.root) |
15168 | 193 |
|
194 |
def _lfconvert_addchangeset(rsrc, rdst, ctx, revmap, lfiles, normalfiles, |
|
195 |
matcher, size, lfiletohash): |
|
196 |
# Convert src parents to dst parents |
|
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
197 |
parents = _convertparents(ctx, revmap) |
15168 | 198 |
|
199 |
# Generate list of changed files |
|
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
200 |
files = _getchangedfiles(ctx, parents) |
15168 | 201 |
|
202 |
dstfiles = [] |
|
203 |
for f in files: |
|
204 |
if f not in lfiles and f not in normalfiles: |
|
205 |
islfile = _islfile(f, ctx, matcher, size) |
|
206 |
# If this file was renamed or copied then copy |
|
17424
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
17299
diff
changeset
|
207 |
# the largefile-ness of its predecessor |
15168 | 208 |
if f in ctx.manifest(): |
209 |
fctx = ctx.filectx(f) |
|
41775
a86e22007b54
largefiles: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents:
41598
diff
changeset
|
210 |
renamed = fctx.copysource() |
39710
7375a9ab0149
filectx: fix return of renamed
Sean Farley <sean@farley.io>
parents:
39390
diff
changeset
|
211 |
if renamed is None: |
7375a9ab0149
filectx: fix return of renamed
Sean Farley <sean@farley.io>
parents:
39390
diff
changeset
|
212 |
# the code below assumes renamed to be a boolean or a list |
7375a9ab0149
filectx: fix return of renamed
Sean Farley <sean@farley.io>
parents:
39390
diff
changeset
|
213 |
# and won't quite work with the value None |
7375a9ab0149
filectx: fix return of renamed
Sean Farley <sean@farley.io>
parents:
39390
diff
changeset
|
214 |
renamed = False |
41775
a86e22007b54
largefiles: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents:
41598
diff
changeset
|
215 |
renamedlfile = renamed and renamed in lfiles |
15168 | 216 |
islfile |= renamedlfile |
217 |
if 'l' in fctx.flags(): |
|
218 |
if renamedlfile: |
|
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25660
diff
changeset
|
219 |
raise error.Abort( |
15380
a53888685a6c
largefiles: fix uppercase in abort message
Martin Geisler <mg@aragost.com>
parents:
15371
diff
changeset
|
220 |
_('renamed/copied largefile %s becomes symlink') |
15170
c1a4a3220711
largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents:
15168
diff
changeset
|
221 |
% f) |
15168 | 222 |
islfile = False |
223 |
if islfile: |
|
224 |
lfiles.add(f) |
|
225 |
else: |
|
226 |
normalfiles.add(f) |
|
227 |
||
228 |
if f in lfiles: |
|
31618
8228bc8fed8c
largefiles: avoid redundant standin() invocations
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
31613
diff
changeset
|
229 |
fstandin = lfutil.standin(f) |
8228bc8fed8c
largefiles: avoid redundant standin() invocations
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
31613
diff
changeset
|
230 |
dstfiles.append(fstandin) |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
231 |
# largefile in manifest if it has not been removed/renamed |
15168 | 232 |
if f in ctx.manifest(): |
15808
62098aeb1e15
largefiles: don't reference uninitialized variable (issue3092)
Levi Bard <levi@unity3d.com>
parents:
15793
diff
changeset
|
233 |
fctx = ctx.filectx(f) |
62098aeb1e15
largefiles: don't reference uninitialized variable (issue3092)
Levi Bard <levi@unity3d.com>
parents:
15793
diff
changeset
|
234 |
if 'l' in fctx.flags(): |
41775
a86e22007b54
largefiles: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents:
41598
diff
changeset
|
235 |
renamed = fctx.copysource() |
a86e22007b54
largefiles: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents:
41598
diff
changeset
|
236 |
if renamed and renamed in lfiles: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25660
diff
changeset
|
237 |
raise error.Abort(_('largefile %s becomes symlink') % f) |
15168 | 238 |
|
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
239 |
# largefile was modified, update standins |
29341
0d83ad967bf8
cleanup: replace uses of util.(md5|sha1|sha256|sha512) with hashlib.\1
Augie Fackler <raf@durin42.com>
parents:
29317
diff
changeset
|
240 |
m = hashlib.sha1('') |
15168 | 241 |
m.update(ctx[f].data()) |
40675
9fcf8084ada8
py3: use node.hex(m.digest()) instead of m.hexdigest()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39710
diff
changeset
|
242 |
hash = node.hex(m.digest()) |
15168 | 243 |
if f not in lfiletohash or lfiletohash[f] != hash: |
19089
0509ae083ec1
largefiles: use repo.wwrite for writing standins (issue3909)
Mads Kiilerich <madski@unity3d.com>
parents:
18976
diff
changeset
|
244 |
rdst.wwrite(f, ctx[f].data(), ctx[f].flags()) |
15168 | 245 |
executable = 'x' in ctx[f].flags() |
31618
8228bc8fed8c
largefiles: avoid redundant standin() invocations
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
31613
diff
changeset
|
246 |
lfutil.writestandin(rdst, fstandin, hash, |
15168 | 247 |
executable) |
248 |
lfiletohash[f] = hash |
|
249 |
else: |
|
250 |
# normal file |
|
251 |
dstfiles.append(f) |
|
252 |
||
253 |
def getfilectx(repo, memctx, f): |
|
31613
5c1d3f1b8f44
largefiles: omit redundant isstandin() before splitstandin()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
31612
diff
changeset
|
254 |
srcfname = lfutil.splitstandin(f) |
5c1d3f1b8f44
largefiles: omit redundant isstandin() before splitstandin()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
31612
diff
changeset
|
255 |
if srcfname is not None: |
15168 | 256 |
# if the file isn't in the manifest then it was removed |
31612
c93cdfa131a8
misc: update descriptions about removed file for filectxfn
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
30269
diff
changeset
|
257 |
# or renamed, return None to indicate this |
15168 | 258 |
try: |
259 |
fctx = ctx.filectx(srcfname) |
|
260 |
except error.LookupError: |
|
22296
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
22197
diff
changeset
|
261 |
return None |
41775
a86e22007b54
largefiles: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents:
41598
diff
changeset
|
262 |
renamed = fctx.copysource() |
15168 | 263 |
if renamed: |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
264 |
# standin is always a largefile because largefile-ness |
15168 | 265 |
# doesn't change after rename or copy |
41775
a86e22007b54
largefiles: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents:
41598
diff
changeset
|
266 |
renamed = lfutil.standin(renamed) |
15168 | 267 |
|
35400
8a0cac20a1ad
memfilectx: make changectx argument mandatory in constructor (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
35348
diff
changeset
|
268 |
return context.memfilectx(repo, memctx, f, |
8a0cac20a1ad
memfilectx: make changectx argument mandatory in constructor (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
35348
diff
changeset
|
269 |
lfiletohash[srcfname] + '\n', |
21689
503bb3af70fe
memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents:
21242
diff
changeset
|
270 |
'l' in fctx.flags(), 'x' in fctx.flags(), |
503bb3af70fe
memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents:
21242
diff
changeset
|
271 |
renamed) |
15168 | 272 |
else: |
21689
503bb3af70fe
memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents:
21242
diff
changeset
|
273 |
return _getnormalcontext(repo, ctx, f, revmap) |
15168 | 274 |
|
275 |
# Commit |
|
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
276 |
_commitcontext(rdst, parents, ctx, dstfiles, getfilectx, revmap) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
277 |
|
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
278 |
def _commitcontext(rdst, parents, ctx, dstfiles, getfilectx, revmap): |
15168 | 279 |
mctx = context.memctx(rdst, parents, ctx.description(), dstfiles, |
280 |
getfilectx, ctx.user(), ctx.date(), ctx.extra()) |
|
281 |
ret = rdst.commitctx(mctx) |
|
23276
4be754832829
largefiles: move "copyalltostore" invocation into "markcommitted"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23189
diff
changeset
|
282 |
lfutil.copyalltostore(rdst, ret) |
16551
ebf6d38c9063
localrepo: add setparents() to adjust dirstate copies (issue3407)
Patrick Mezard <patrick@mezard.eu>
parents:
16439
diff
changeset
|
283 |
rdst.setparents(ret) |
15168 | 284 |
revmap[ctx.node()] = rdst.changelog.tip() |
285 |
||
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
286 |
# Generate list of changed files |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
287 |
def _getchangedfiles(ctx, parents): |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
288 |
files = set(ctx.files()) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
289 |
if node.nullid not in parents: |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
290 |
mc = ctx.manifest() |
41400
4a409c19831f
largefiles: avoid walking full manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
41397
diff
changeset
|
291 |
for pctx in ctx.parents(): |
4a409c19831f
largefiles: avoid walking full manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
41397
diff
changeset
|
292 |
for fn in pctx.manifest().diff(mc): |
4a409c19831f
largefiles: avoid walking full manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
41397
diff
changeset
|
293 |
files.add(fn) |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
294 |
return files |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
295 |
|
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
296 |
# Convert src parents to dst parents |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
297 |
def _convertparents(ctx, revmap): |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
298 |
parents = [] |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
299 |
for p in ctx.parents(): |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
300 |
parents.append(revmap[p.node()]) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
301 |
while len(parents) < 2: |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
302 |
parents.append(node.nullid) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
303 |
return parents |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
304 |
|
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
305 |
# Get memfilectx for a normal file |
21689
503bb3af70fe
memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents:
21242
diff
changeset
|
306 |
def _getnormalcontext(repo, ctx, f, revmap): |
15811
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 |
fctx = ctx.filectx(f) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
309 |
except error.LookupError: |
22296
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
22197
diff
changeset
|
310 |
return None |
41775
a86e22007b54
largefiles: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents:
41598
diff
changeset
|
311 |
renamed = fctx.copysource() |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
312 |
|
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
313 |
data = fctx.data() |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
314 |
if f == '.hgtags': |
21689
503bb3af70fe
memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents:
21242
diff
changeset
|
315 |
data = _converttags (repo.ui, revmap, data) |
35400
8a0cac20a1ad
memfilectx: make changectx argument mandatory in constructor (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
35348
diff
changeset
|
316 |
return context.memfilectx(repo, ctx, f, data, 'l' in fctx.flags(), |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
317 |
'x' in fctx.flags(), renamed) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
318 |
|
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
319 |
# Remap tag data using a revision map |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
320 |
def _converttags(ui, revmap, data): |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
321 |
newdata = [] |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
322 |
for line in data.splitlines(): |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
323 |
try: |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
324 |
id, name = line.split(' ', 1) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
325 |
except ValueError: |
20868
5db105f216c3
i18n: fix "% inside _()" problems
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20063
diff
changeset
|
326 |
ui.warn(_('skipping incorrectly formatted tag %s\n') |
5db105f216c3
i18n: fix "% inside _()" problems
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20063
diff
changeset
|
327 |
% line) |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
328 |
continue |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
329 |
try: |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
330 |
newid = node.bin(id) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
331 |
except TypeError: |
20868
5db105f216c3
i18n: fix "% inside _()" problems
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20063
diff
changeset
|
332 |
ui.warn(_('skipping incorrectly formatted id %s\n') |
5db105f216c3
i18n: fix "% inside _()" problems
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20063
diff
changeset
|
333 |
% id) |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
334 |
continue |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
335 |
try: |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
336 |
newdata.append('%s %s\n' % (node.hex(revmap[newid]), |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
337 |
name)) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
338 |
except KeyError: |
16231
ce292f1379ba
i18n: fix all remaining uses of % inside _()
Matt Mackall <mpm@selenic.com>
parents:
15909
diff
changeset
|
339 |
ui.warn(_('no mapping for id %s\n') % id) |
15811
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
340 |
continue |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
341 |
return ''.join(newdata) |
b9886dde3649
largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents:
15809
diff
changeset
|
342 |
|
15168 | 343 |
def _islfile(file, ctx, matcher, size): |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15230
diff
changeset
|
344 |
'''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
|
345 |
matcher matches it or it is larger than size.''' |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15230
diff
changeset
|
346 |
# never store special .hg* files as largefiles |
15168 | 347 |
if file == '.hgtags' or file == '.hgignore' or file == '.hgsigs': |
348 |
return False |
|
349 |
if matcher and matcher(file): |
|
350 |
return True |
|
351 |
try: |
|
352 |
return ctx.filectx(file).size() >= size * 1024 * 1024 |
|
353 |
except error.LookupError: |
|
354 |
return False |
|
355 |
||
356 |
def uploadlfiles(ui, rsrc, rdst, files): |
|
357 |
'''upload largefiles to the central store''' |
|
358 |
||
15317
41f371150ccb
largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15313
diff
changeset
|
359 |
if not files: |
15168 | 360 |
return |
361 |
||
29355
85868ecf2c0d
largefiles: make storefactory._openstore public
liscju <piotr.listkiewicz@gmail.com>
parents:
29341
diff
changeset
|
362 |
store = storefactory.openstore(rsrc, rdst, put=True) |
15168 | 363 |
|
364 |
at = 0 |
|
17127
9e1616307c4c
largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16727
diff
changeset
|
365 |
ui.debug("sending statlfile command for %d largefiles\n" % len(files)) |
9e1616307c4c
largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16727
diff
changeset
|
366 |
retval = store.exists(files) |
36311
b9da10f310f4
largfiles: replace filter() with listcomp when result needs to be a list
Augie Fackler <augie@google.com>
parents:
35563
diff
changeset
|
367 |
files = [h for h in files if not retval[h]] |
17127
9e1616307c4c
largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16727
diff
changeset
|
368 |
ui.debug("%d largefiles need to be uploaded\n" % len(files)) |
9e1616307c4c
largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16727
diff
changeset
|
369 |
|
39390
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
370 |
with ui.makeprogress(_('uploading largefiles'), unit=_('files'), |
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
371 |
total=len(files)) as progress: |
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
372 |
for hash in files: |
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
373 |
progress.update(at) |
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
374 |
source = lfutil.findfile(rsrc, hash) |
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
375 |
if not source: |
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
376 |
raise error.Abort(_('largefile %s missing from store' |
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
377 |
' (needs to be uploaded)') % hash) |
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
378 |
# XXX check for errors here |
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
379 |
store.put(source, hash) |
a65ad9b22a00
largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents:
38407
diff
changeset
|
380 |
at += 1 |
15168 | 381 |
|
382 |
def verifylfiles(ui, repo, all=False, contents=False): |
|
18574
4db9e31ae605
largefiles: docstrings for verify methods
Mads Kiilerich <mads@kiilerich.com>
parents:
18294
diff
changeset
|
383 |
'''Verify that every largefile revision in the current changeset |
15168 | 384 |
exists in the central store. With --contents, also verify that |
18574
4db9e31ae605
largefiles: docstrings for verify methods
Mads Kiilerich <mads@kiilerich.com>
parents:
18294
diff
changeset
|
385 |
the contents of each local largefile file revision are correct (SHA-1 hash |
15168 | 386 |
matches the revision ID). With --all, check every changeset in |
387 |
this repository.''' |
|
388 |
if all: |
|
25508
b8fd605b0c88
largefiles: ignore hidden changesets with 'verify --large --lfa'
Matt Harbison <matt_harbison@yahoo.com>
parents:
25326
diff
changeset
|
389 |
revs = repo.revs('all()') |
15168 | 390 |
else: |
391 |
revs = ['.'] |
|
392 |
||
29355
85868ecf2c0d
largefiles: make storefactory._openstore public
liscju <piotr.listkiewicz@gmail.com>
parents:
29341
diff
changeset
|
393 |
store = storefactory.openstore(repo) |
15168 | 394 |
return store.verify(revs, contents=contents) |
395 |
||
16700
28001e8a5149
largefiles: optimize performance when updating (issue3440)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16691
diff
changeset
|
396 |
def cachelfiles(ui, repo, node, filelist=None): |
15168 | 397 |
'''cachelfiles ensures that all largefiles needed by the specified revision |
398 |
are present in the repository's largefile cache. |
|
399 |
||
400 |
returns a tuple (cached, missing). cached is the list of files downloaded |
|
401 |
by this operation; missing is the list of files that were needed but could |
|
402 |
not be found.''' |
|
403 |
lfiles = lfutil.listlfiles(repo, node) |
|
16700
28001e8a5149
largefiles: optimize performance when updating (issue3440)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16691
diff
changeset
|
404 |
if filelist: |
28001e8a5149
largefiles: optimize performance when updating (issue3440)
Na'Tosha Bard <natosha@unity3d.com>
parents:
16691
diff
changeset
|
405 |
lfiles = set(lfiles) & set(filelist) |
15168 | 406 |
toget = [] |
407 |
||
31654
1af4a1641bdb
largefiles: avoid redundant changectx looking up at each repetitions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
31618
diff
changeset
|
408 |
ctx = repo[node] |
15168 | 409 |
for lfile in lfiles: |
18728
1e636f7b1cfe
largefiles: simplify cachelfiles - don't spend a lot of time checking hashes
Mads Kiilerich <madski@unity3d.com>
parents:
18727
diff
changeset
|
410 |
try: |
31740
a40e979b9d97
largefiles: use readasstandin() to read hex hash directly from filectx
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
31735
diff
changeset
|
411 |
expectedhash = lfutil.readasstandin(ctx[lfutil.standin(lfile)]) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25560
diff
changeset
|
412 |
except IOError as err: |
18728
1e636f7b1cfe
largefiles: simplify cachelfiles - don't spend a lot of time checking hashes
Mads Kiilerich <madski@unity3d.com>
parents:
18727
diff
changeset
|
413 |
if err.errno == errno.ENOENT: |
1e636f7b1cfe
largefiles: simplify cachelfiles - don't spend a lot of time checking hashes
Mads Kiilerich <madski@unity3d.com>
parents:
18727
diff
changeset
|
414 |
continue # node must be None and standin wasn't found in wctx |
1e636f7b1cfe
largefiles: simplify cachelfiles - don't spend a lot of time checking hashes
Mads Kiilerich <madski@unity3d.com>
parents:
18727
diff
changeset
|
415 |
raise |
1e636f7b1cfe
largefiles: simplify cachelfiles - don't spend a lot of time checking hashes
Mads Kiilerich <madski@unity3d.com>
parents:
18727
diff
changeset
|
416 |
if not lfutil.findfile(repo, expectedhash): |
15168 | 417 |
toget.append((lfile, expectedhash)) |
418 |
||
419 |
if toget: |
|
29355
85868ecf2c0d
largefiles: make storefactory._openstore public
liscju <piotr.listkiewicz@gmail.com>
parents:
29341
diff
changeset
|
420 |
store = storefactory.openstore(repo) |
15168 | 421 |
ret = store.get(toget) |
422 |
return ret |
|
423 |
||
424 |
return ([], []) |
|
425 |
||
16691
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
426 |
def downloadlfiles(ui, repo, rev=None): |
34083
08346a8fa65f
cleanup: rename "matchfn" to "match" where obviously a matcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
32375
diff
changeset
|
427 |
match = scmutil.match(repo[None], [repo.wjoin(lfutil.shortname)], {}) |
16691
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
428 |
def prepare(ctx, fns): |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
429 |
pass |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
430 |
totalsuccess = 0 |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
431 |
totalmissing = 0 |
18722
f0aa8bbffe60
largefiles: fix download of largefiles from an empty list of changesets
Mads Kiilerich <madski@unity3d.com>
parents:
18294
diff
changeset
|
432 |
if rev != []: # walkchangerevs on empty list would return all revs |
34083
08346a8fa65f
cleanup: rename "matchfn" to "match" where obviously a matcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
32375
diff
changeset
|
433 |
for ctx in cmdutil.walkchangerevs(repo, match, {'rev' : rev}, |
18722
f0aa8bbffe60
largefiles: fix download of largefiles from an empty list of changesets
Mads Kiilerich <madski@unity3d.com>
parents:
18294
diff
changeset
|
434 |
prepare): |
f0aa8bbffe60
largefiles: fix download of largefiles from an empty list of changesets
Mads Kiilerich <madski@unity3d.com>
parents:
18294
diff
changeset
|
435 |
success, missing = cachelfiles(ui, repo, ctx.node()) |
f0aa8bbffe60
largefiles: fix download of largefiles from an empty list of changesets
Mads Kiilerich <madski@unity3d.com>
parents:
18294
diff
changeset
|
436 |
totalsuccess += len(success) |
f0aa8bbffe60
largefiles: fix download of largefiles from an empty list of changesets
Mads Kiilerich <madski@unity3d.com>
parents:
18294
diff
changeset
|
437 |
totalmissing += len(missing) |
16691
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
438 |
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
|
439 |
if totalmissing > 0: |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
440 |
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
|
441 |
return totalsuccess, totalmissing |
7d6a660ca151
largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents:
16687
diff
changeset
|
442 |
|
23189
fb139f5553d6
largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23139
diff
changeset
|
443 |
def updatelfiles(ui, repo, filelist=None, printmessage=None, |
24788
b8c3a0994b37
largefiles: always consider updatelfiles 'checked' parameter set
Mads Kiilerich <madski@unity3d.com>
parents:
24180
diff
changeset
|
444 |
normallookup=False): |
23189
fb139f5553d6
largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23139
diff
changeset
|
445 |
'''Update largefiles according to standins in the working directory |
fb139f5553d6
largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23139
diff
changeset
|
446 |
|
fb139f5553d6
largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23139
diff
changeset
|
447 |
If ``printmessage`` is other than ``None``, it means "print (or |
fb139f5553d6
largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23139
diff
changeset
|
448 |
ignore, for false) message forcibly". |
fb139f5553d6
largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23139
diff
changeset
|
449 |
''' |
fb139f5553d6
largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23139
diff
changeset
|
450 |
statuswriter = lfutil.getstatuswriter(ui, repo, printmessage) |
27820
d2e9cc9edc08
with: use context manager for wlock in updatelfiles
Bryan O'Sullivan <bryano@fb.com>
parents:
27774
diff
changeset
|
451 |
with repo.wlock(): |
15168 | 452 |
lfdirstate = lfutil.openlfdirstate(ui, repo) |
453 |
lfiles = set(lfutil.listlfiles(repo)) | set(lfdirstate) |
|
454 |
||
455 |
if filelist is not None: |
|
22197
f72d73937853
largefiles: update lfdirstate for unchanged largefiles during linear merging
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22095
diff
changeset
|
456 |
filelist = set(filelist) |
15168 | 457 |
lfiles = [f for f in lfiles if f in filelist] |
458 |
||
20063
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
459 |
update = {} |
35168
b175e54c1103
largefiles: pay attention to dropped standin files when updating largefiles
Matt Harbison <matt_harbison@yahoo.com>
parents:
34756
diff
changeset
|
460 |
dropped = set() |
15168 | 461 |
updated, removed = 0, 0 |
28559
30863ca01c6b
largefiles: replace invocation of os.path module by vfs in lfcommands.py
liscju <piotr.listkiewicz@gmail.com>
parents:
28464
diff
changeset
|
462 |
wvfs = repo.wvfs |
31654
1af4a1641bdb
largefiles: avoid redundant changectx looking up at each repetitions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
31618
diff
changeset
|
463 |
wctx = repo[None] |
20062
452f68738f69
largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
20061
diff
changeset
|
464 |
for lfile in lfiles: |
41568
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
465 |
lfileorig = os.path.relpath( |
41598
e89e78a725ee
largefiles: migrate to scmutil.backuppath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41568
diff
changeset
|
466 |
scmutil.backuppath(ui, repo, lfile), |
28559
30863ca01c6b
largefiles: replace invocation of os.path module by vfs in lfcommands.py
liscju <piotr.listkiewicz@gmail.com>
parents:
28464
diff
changeset
|
467 |
start=repo.root) |
41568
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
468 |
standin = lfutil.standin(lfile) |
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
469 |
standinorig = os.path.relpath( |
41598
e89e78a725ee
largefiles: migrate to scmutil.backuppath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41568
diff
changeset
|
470 |
scmutil.backuppath(ui, repo, standin), |
28559
30863ca01c6b
largefiles: replace invocation of os.path module by vfs in lfcommands.py
liscju <piotr.listkiewicz@gmail.com>
parents:
28464
diff
changeset
|
471 |
start=repo.root) |
41568
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
472 |
if wvfs.exists(standin): |
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
473 |
if (wvfs.exists(standinorig) and |
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
474 |
wvfs.exists(lfile)): |
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
475 |
shutil.copyfile(wvfs.join(lfile), |
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
476 |
wvfs.join(lfileorig)) |
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
477 |
wvfs.unlinkpath(standinorig) |
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
478 |
expecthash = lfutil.readasstandin(wctx[standin]) |
24788
b8c3a0994b37
largefiles: always consider updatelfiles 'checked' parameter set
Mads Kiilerich <madski@unity3d.com>
parents:
24180
diff
changeset
|
479 |
if expecthash != '': |
31654
1af4a1641bdb
largefiles: avoid redundant changectx looking up at each repetitions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
31618
diff
changeset
|
480 |
if lfile not in wctx: # not switched to normal file |
41568
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
481 |
if repo.dirstate[standin] != '?': |
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
482 |
wvfs.unlinkpath(lfile, ignoremissing=True) |
35168
b175e54c1103
largefiles: pay attention to dropped standin files when updating largefiles
Matt Harbison <matt_harbison@yahoo.com>
parents:
34756
diff
changeset
|
483 |
else: |
41568
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
484 |
dropped.add(lfile) |
35168
b175e54c1103
largefiles: pay attention to dropped standin files when updating largefiles
Matt Harbison <matt_harbison@yahoo.com>
parents:
34756
diff
changeset
|
485 |
|
23139
e53f6b72a0e4
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
486 |
# use normallookup() to allocate an entry in largefiles |
24180
d8e0c591781c
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
23893
diff
changeset
|
487 |
# dirstate to prevent lfilesrepo.status() from reporting |
d8e0c591781c
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
23893
diff
changeset
|
488 |
# missing files as removed. |
20063
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
489 |
lfdirstate.normallookup(lfile) |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
490 |
update[lfile] = expecthash |
20062
452f68738f69
largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
20061
diff
changeset
|
491 |
else: |
452f68738f69
largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
20061
diff
changeset
|
492 |
# Remove lfiles for which the standin is deleted, unless the |
452f68738f69
largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
20061
diff
changeset
|
493 |
# lfile is added to the repository again. This happens when a |
452f68738f69
largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
20061
diff
changeset
|
494 |
# largefile is converted back to a normal file: the standin |
452f68738f69
largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
20061
diff
changeset
|
495 |
# disappears, but a new (normal) file appears as the lfile. |
41568
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
496 |
if (wvfs.exists(lfile) and |
31654
1af4a1641bdb
largefiles: avoid redundant changectx looking up at each repetitions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
31618
diff
changeset
|
497 |
repo.dirstate.normalize(lfile) not in wctx): |
41568
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
498 |
wvfs.unlinkpath(lfile) |
20062
452f68738f69
largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents:
20061
diff
changeset
|
499 |
removed += 1 |
20063
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
500 |
|
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
501 |
# largefile processing might be slow and be interrupted - be prepared |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
502 |
lfdirstate.write() |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
503 |
|
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
504 |
if lfiles: |
35168
b175e54c1103
largefiles: pay attention to dropped standin files when updating largefiles
Matt Harbison <matt_harbison@yahoo.com>
parents:
34756
diff
changeset
|
505 |
lfiles = [f for f in lfiles if f not in dropped] |
b175e54c1103
largefiles: pay attention to dropped standin files when updating largefiles
Matt Harbison <matt_harbison@yahoo.com>
parents:
34756
diff
changeset
|
506 |
|
b175e54c1103
largefiles: pay attention to dropped standin files when updating largefiles
Matt Harbison <matt_harbison@yahoo.com>
parents:
34756
diff
changeset
|
507 |
for f in dropped: |
b175e54c1103
largefiles: pay attention to dropped standin files when updating largefiles
Matt Harbison <matt_harbison@yahoo.com>
parents:
34756
diff
changeset
|
508 |
repo.wvfs.unlinkpath(lfutil.standin(f)) |
b175e54c1103
largefiles: pay attention to dropped standin files when updating largefiles
Matt Harbison <matt_harbison@yahoo.com>
parents:
34756
diff
changeset
|
509 |
|
b175e54c1103
largefiles: pay attention to dropped standin files when updating largefiles
Matt Harbison <matt_harbison@yahoo.com>
parents:
34756
diff
changeset
|
510 |
# This needs to happen for dropped files, otherwise they stay in |
b175e54c1103
largefiles: pay attention to dropped standin files when updating largefiles
Matt Harbison <matt_harbison@yahoo.com>
parents:
34756
diff
changeset
|
511 |
# the M state. |
b175e54c1103
largefiles: pay attention to dropped standin files when updating largefiles
Matt Harbison <matt_harbison@yahoo.com>
parents:
34756
diff
changeset
|
512 |
lfutil.synclfdirstate(repo, lfdirstate, f, normallookup) |
b175e54c1103
largefiles: pay attention to dropped standin files when updating largefiles
Matt Harbison <matt_harbison@yahoo.com>
parents:
34756
diff
changeset
|
513 |
|
23189
fb139f5553d6
largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23139
diff
changeset
|
514 |
statuswriter(_('getting changed largefiles\n')) |
20063
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
515 |
cachelfiles(ui, repo, None, lfiles) |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
516 |
|
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
517 |
for lfile in lfiles: |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
518 |
update1 = 0 |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
519 |
|
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
520 |
expecthash = update.get(lfile) |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
521 |
if expecthash: |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
522 |
if not lfutil.copyfromcache(repo, expecthash, lfile): |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
523 |
# failed ... but already removed and set to normallookup |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
524 |
continue |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
525 |
# Synchronize largefile dirstate to the last modified |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
526 |
# time of the file |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
527 |
lfdirstate.normal(lfile) |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
528 |
update1 = 1 |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
529 |
|
30269
d71db0e3b7b9
largefiles: clarify variable name holding file mode
Mads Kiilerich <madski@unity3d.com>
parents:
30141
diff
changeset
|
530 |
# copy the exec mode of largefile standin from the repository's |
20063
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
531 |
# dirstate to its state in the lfdirstate. |
41568
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
532 |
standin = lfutil.standin(lfile) |
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
533 |
if wvfs.exists(standin): |
30269
d71db0e3b7b9
largefiles: clarify variable name holding file mode
Mads Kiilerich <madski@unity3d.com>
parents:
30141
diff
changeset
|
534 |
# exec is decided by the users permissions using mask 0o100 |
41568
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
535 |
standinexec = wvfs.stat(standin).st_mode & 0o100 |
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
536 |
st = wvfs.stat(lfile) |
30269
d71db0e3b7b9
largefiles: clarify variable name holding file mode
Mads Kiilerich <madski@unity3d.com>
parents:
30141
diff
changeset
|
537 |
mode = st.st_mode |
d71db0e3b7b9
largefiles: clarify variable name holding file mode
Mads Kiilerich <madski@unity3d.com>
parents:
30141
diff
changeset
|
538 |
if standinexec != mode & 0o100: |
d71db0e3b7b9
largefiles: clarify variable name holding file mode
Mads Kiilerich <madski@unity3d.com>
parents:
30141
diff
changeset
|
539 |
# first remove all X bits, then shift all R bits to X |
d71db0e3b7b9
largefiles: clarify variable name holding file mode
Mads Kiilerich <madski@unity3d.com>
parents:
30141
diff
changeset
|
540 |
mode &= ~0o111 |
30141
c01acee367ec
largefiles: when setting/clearing x bit on largefiles, don't change other bits
Mads Kiilerich <madski@unity3d.com>
parents:
29355
diff
changeset
|
541 |
if standinexec: |
30269
d71db0e3b7b9
largefiles: clarify variable name holding file mode
Mads Kiilerich <madski@unity3d.com>
parents:
30141
diff
changeset
|
542 |
mode |= (mode >> 2) & 0o111 & ~util.umask |
41568
641c8b66a825
largefiles: drop "rel" prefix from filename variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41400
diff
changeset
|
543 |
wvfs.chmod(lfile, mode) |
20063
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
544 |
update1 = 1 |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
545 |
|
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
546 |
updated += update1 |
8a021cd38719
largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents:
20062
diff
changeset
|
547 |
|
22095
cb62d77c7a01
largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21934
diff
changeset
|
548 |
lfutil.synclfdirstate(repo, lfdirstate, lfile, normallookup) |
15168 | 549 |
|
550 |
lfdirstate.write() |
|
23189
fb139f5553d6
largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23139
diff
changeset
|
551 |
if lfiles: |
fb139f5553d6
largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23139
diff
changeset
|
552 |
statuswriter(_('%d largefiles updated, %d removed\n') % (updated, |
15168 | 553 |
removed)) |
554 |
||
41061
98681293c890
largefiles: port commands to exthelper
Matt Harbison <matt_harbison@yahoo.com>
parents:
40675
diff
changeset
|
555 |
@eh.command('lfpull', |
21242
4c94229c51fb
largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21088
diff
changeset
|
556 |
[('r', 'rev', [], _('pull largefiles for these revisions')) |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32337
diff
changeset
|
557 |
] + cmdutil.remoteopts, |
21242
4c94229c51fb
largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21088
diff
changeset
|
558 |
_('-r REV... [-e CMD] [--remotecmd CMD] [SOURCE]')) |
18976
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
559 |
def lfpull(ui, repo, source="default", **opts): |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
560 |
"""pull largefiles for the specified revisions from the specified source |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
561 |
|
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
562 |
Pull largefiles that are referenced from local changesets but missing |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
563 |
locally, pulling from a remote repository to the local cache. |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
564 |
|
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
565 |
If SOURCE is omitted, the 'default' path will be used. |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
566 |
See :hg:`help urls` for more information. |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
567 |
|
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
568 |
.. container:: verbose |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
569 |
|
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
570 |
Some examples: |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
571 |
|
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
572 |
- pull largefiles for all branch heads:: |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
573 |
|
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
574 |
hg lfpull -r "head() and not closed()" |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
575 |
|
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
576 |
- pull largefiles on the default branch:: |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
577 |
|
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
578 |
hg lfpull -r "branch(default)" |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
579 |
""" |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
580 |
repo.lfpullsource = source |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
581 |
|
35348
576ba8194fa8
py3: handle keyword arguments correctly in hgext/largefiles/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35186
diff
changeset
|
582 |
revs = opts.get(r'rev', []) |
18976
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
583 |
if not revs: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25660
diff
changeset
|
584 |
raise error.Abort(_('no revisions specified')) |
18976
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
585 |
revs = scmutil.revrange(repo, revs) |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
586 |
|
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
587 |
numcached = 0 |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
588 |
for rev in revs: |
37743
25136e03012e
lfcommands: use %d on known-int in format string
Augie Fackler <augie@google.com>
parents:
36311
diff
changeset
|
589 |
ui.note(_('pulling largefiles for revision %d\n') % rev) |
18976
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
590 |
(cached, missing) = cachelfiles(ui, repo, rev) |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
591 |
numcached += len(cached) |
6734951e2d24
largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents:
18974
diff
changeset
|
592 |
ui.status(_("%d largefiles cached\n") % numcached) |
35563
4aa6ed598323
largefiles: add a 'debuglfput' command to put largefile into the store
Boris Feld <boris.feld@octobus.net>
parents:
35400
diff
changeset
|
593 |
|
41061
98681293c890
largefiles: port commands to exthelper
Matt Harbison <matt_harbison@yahoo.com>
parents:
40675
diff
changeset
|
594 |
@eh.command('debuglfput', |
35563
4aa6ed598323
largefiles: add a 'debuglfput' command to put largefile into the store
Boris Feld <boris.feld@octobus.net>
parents:
35400
diff
changeset
|
595 |
[] + cmdutil.remoteopts, |
4aa6ed598323
largefiles: add a 'debuglfput' command to put largefile into the store
Boris Feld <boris.feld@octobus.net>
parents:
35400
diff
changeset
|
596 |
_('FILE')) |
4aa6ed598323
largefiles: add a 'debuglfput' command to put largefile into the store
Boris Feld <boris.feld@octobus.net>
parents:
35400
diff
changeset
|
597 |
def debuglfput(ui, repo, filepath, **kwargs): |
4aa6ed598323
largefiles: add a 'debuglfput' command to put largefile into the store
Boris Feld <boris.feld@octobus.net>
parents:
35400
diff
changeset
|
598 |
hash = lfutil.hashfile(filepath) |
4aa6ed598323
largefiles: add a 'debuglfput' command to put largefile into the store
Boris Feld <boris.feld@octobus.net>
parents:
35400
diff
changeset
|
599 |
storefactory.openstore(repo).put(filepath, hash) |
4aa6ed598323
largefiles: add a 'debuglfput' command to put largefile into the store
Boris Feld <boris.feld@octobus.net>
parents:
35400
diff
changeset
|
600 |
ui.write('%s\n' % hash) |
4aa6ed598323
largefiles: add a 'debuglfput' command to put largefile into the store
Boris Feld <boris.feld@octobus.net>
parents:
35400
diff
changeset
|
601 |
return 0 |