annotate hgext/largefiles/lfcommands.py @ 15230:697289c5d415

largefiles: improve help Extension help taken from the URL formerly in the text (https://developers.kilnhg.com/Repo/Kiln/largefiles/largefiles/File/usage.txt) and improved.
author Greg Ward <greg@gerg.ca>
date Tue, 11 Oct 2011 21:10:03 -0400
parents ee625de3541e
children 6e809bb4f969
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
1 # Copyright 2009-2010 Gregory P. Ward
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
2 # Copyright 2009-2010 Intelerad Medical Systems Incorporated
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
3 # Copyright 2010-2011 Fog Creek Software
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
4 # Copyright 2010-2011 Unity Technologies
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
5 #
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
6 # This software may be used and distributed according to the terms of the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
7 # GNU General Public License version 2 or any later version.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
8
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
9 '''High-level command functions: lfadd() et. al, plus the cmdtable.'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
10
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
11 import os
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
12 import shutil
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
13
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
14 from mercurial import util, match as match_, hg, node, context, error
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
15 from mercurial.i18n import _
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
16
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
17 import lfutil
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
18 import basestore
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
19
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
20 # -- Commands ----------------------------------------------------------
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
21
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
22 def lfconvert(ui, src, dest, *pats, **opts):
15230
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
23 '''convert a normal repository to a largefiles repository
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
24
15230
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
25 Convert repository SOURCE to a new repository DEST, identical to
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
26 SOURCE except that certain files will be converted as largefiles:
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
27 specifically, any file that matches any PATTERN *or* whose size is
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
28 above the minimum size threshold is converted as a largefile. The
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
29 size used to determine whether or not to track a file as a
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
30 largefile is the size of the first version of the file. The
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
31 minimum size can be specified either with --size or in
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
32 configuration as ``largefiles.size``.
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
33
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
34 After running this command you will need to make sure that
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
35 largefiles is enabled anywhere you intend to push the new
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
36 repository.
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
37
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
38 Use --tonormal to convert largefiles back to normal files; after
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
39 this, the DEST repository can be used without largefiles at all.'''
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
40
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
41 if opts['tonormal']:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
42 tolfile = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
43 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
44 tolfile = True
15227
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
45 size = lfutil.getminsize(ui, True, opts.get('size'), default=None)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
46 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
47 rsrc = hg.repository(ui, src)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
48 if not rsrc.local():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
49 raise util.Abort(_('%s is not a local Mercurial repo') % src)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
50 except error.RepoError, err:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
51 ui.traceback()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
52 raise util.Abort(err.args[0])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
53 if os.path.exists(dest):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
54 if not os.path.isdir(dest):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
55 raise util.Abort(_('destination %s already exists') % dest)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
56 elif os.listdir(dest):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
57 raise util.Abort(_('destination %s is not empty') % dest)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
58 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
59 ui.status(_('initializing destination %s\n') % dest)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
60 rdst = hg.repository(ui, dest, create=True)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
61 if not rdst.local():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
62 raise util.Abort(_('%s is not a local Mercurial repo') % dest)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
63 except error.RepoError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
64 ui.traceback()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
65 raise util.Abort(_('%s is not a repo') % dest)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
66
15171
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
67 success = False
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
68 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
69 # Lock destination to prevent modification while it is converted to.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
70 # Don't need to lock src because we are just reading from its history
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
71 # which can't change.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
72 dst_lock = rdst.lock()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
73
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
74 # Get a list of all changesets in the source. The easy way to do this
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
75 # is to simply walk the changelog, using changelog.nodesbewteen().
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
76 # Take a look at mercurial/revlog.py:639 for more details.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
77 # Use a generator instead of a list to decrease memory usage
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
78 ctxs = (rsrc[ctx] for ctx in rsrc.changelog.nodesbetween(None,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
79 rsrc.heads())[0])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
80 revmap = {node.nullid: node.nullid}
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
81 if tolfile:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
82 lfiles = set()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
83 normalfiles = set()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
84 if not pats:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
85 pats = ui.config(lfutil.longname, 'patterns', default=())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
86 if pats:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
87 pats = pats.split(' ')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
88 if pats:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
89 matcher = match_.match(rsrc.root, '', list(pats))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
90 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
91 matcher = None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
92
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
93 lfiletohash = {}
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
94 for ctx in ctxs:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
95 ui.progress(_('converting revisions'), ctx.rev(),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
96 unit=_('revision'), total=rsrc['tip'].rev())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
97 _lfconvert_addchangeset(rsrc, rdst, ctx, revmap,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
98 lfiles, normalfiles, matcher, size, lfiletohash)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
99 ui.progress(_('converting revisions'), None)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
100
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
101 if os.path.exists(rdst.wjoin(lfutil.shortname)):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
102 shutil.rmtree(rdst.wjoin(lfutil.shortname))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
103
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
104 for f in lfiletohash.keys():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
105 if os.path.isfile(rdst.wjoin(f)):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
106 os.unlink(rdst.wjoin(f))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
107 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
108 os.removedirs(os.path.dirname(rdst.wjoin(f)))
15171
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
109 except OSError:
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
110 pass
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
111
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
112 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
113 for ctx in ctxs:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
114 ui.progress(_('converting revisions'), ctx.rev(),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
115 unit=_('revision'), total=rsrc['tip'].rev())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
116 _addchangeset(ui, rsrc, rdst, ctx, revmap)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
117
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
118 ui.progress(_('converting revisions'), None)
15171
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
119 success = True
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
120 finally:
15171
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
121 if not success:
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
122 # we failed, remove the new directory
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
123 shutil.rmtree(rdst.root)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
124 dst_lock.release()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
125
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
126 def _addchangeset(ui, rsrc, rdst, ctx, revmap):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
127 # Convert src parents to dst parents
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
128 parents = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
129 for p in ctx.parents():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
130 parents.append(revmap[p.node()])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
131 while len(parents) < 2:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
132 parents.append(node.nullid)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
133
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
134 # Generate list of changed files
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
135 files = set(ctx.files())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
136 if node.nullid not in parents:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
137 mc = ctx.manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
138 mp1 = ctx.parents()[0].manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
139 mp2 = ctx.parents()[1].manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
140 files |= (set(mp1) | set(mp2)) - set(mc)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
141 for f in mc:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
142 if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, None):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
143 files.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
144
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
145 def getfilectx(repo, memctx, f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
146 if lfutil.standin(f) in files:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
147 # if the file isn't in the manifest then it was removed
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
148 # or renamed, raise IOError to indicate this
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
149 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
150 fctx = ctx.filectx(lfutil.standin(f))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
151 except error.LookupError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
152 raise IOError()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
153 renamed = fctx.renamed()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
154 if renamed:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
155 renamed = lfutil.splitstandin(renamed[0])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
156
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
157 hash = fctx.data().strip()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
158 path = lfutil.findfile(rsrc, hash)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
159 ### TODO: What if the file is not cached?
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
160 data = ''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
161 fd = None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
162 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
163 fd = open(path, 'rb')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
164 data = fd.read()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
165 finally:
15172
fb1dcd2aae2a largefiles: fix multistatement line
Matt Mackall <mpm@selenic.com>
parents: 15171
diff changeset
166 if fd:
fb1dcd2aae2a largefiles: fix multistatement line
Matt Mackall <mpm@selenic.com>
parents: 15171
diff changeset
167 fd.close()
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
168 return context.memfilectx(f, data, 'l' in fctx.flags(),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
169 'x' in fctx.flags(), renamed)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
170 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
171 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
172 fctx = ctx.filectx(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
173 except error.LookupError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
174 raise IOError()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
175 renamed = fctx.renamed()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
176 if renamed:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
177 renamed = renamed[0]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
178 data = fctx.data()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
179 if f == '.hgtags':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
180 newdata = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
181 for line in data.splitlines():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
182 id, name = line.split(' ', 1)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
183 newdata.append('%s %s\n' % (node.hex(revmap[node.bin(id)]),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
184 name))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
185 data = ''.join(newdata)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
186 return context.memfilectx(f, data, 'l' in fctx.flags(),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
187 'x' in fctx.flags(), renamed)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
188
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
189 dstfiles = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
190 for file in files:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
191 if lfutil.isstandin(file):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
192 dstfiles.append(lfutil.splitstandin(file))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
193 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
194 dstfiles.append(file)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
195 # Commit
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
196 mctx = context.memctx(rdst, parents, ctx.description(), dstfiles,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
197 getfilectx, ctx.user(), ctx.date(), ctx.extra())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
198 ret = rdst.commitctx(mctx)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
199 rdst.dirstate.setparents(ret)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
200 revmap[ctx.node()] = rdst.changelog.tip()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
201
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
202 def _lfconvert_addchangeset(rsrc, rdst, ctx, revmap, lfiles, normalfiles,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
203 matcher, size, lfiletohash):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
204 # Convert src parents to dst parents
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
205 parents = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
206 for p in ctx.parents():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
207 parents.append(revmap[p.node()])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
208 while len(parents) < 2:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
209 parents.append(node.nullid)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
210
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
211 # Generate list of changed files
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
212 files = set(ctx.files())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
213 if node.nullid not in parents:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
214 mc = ctx.manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
215 mp1 = ctx.parents()[0].manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
216 mp2 = ctx.parents()[1].manifest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
217 files |= (set(mp1) | set(mp2)) - set(mc)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
218 for f in mc:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
219 if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, None):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
220 files.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
221
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
222 dstfiles = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
223 for f in files:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
224 if f not in lfiles and f not in normalfiles:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
225 islfile = _islfile(f, ctx, matcher, size)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
226 # If this file was renamed or copied then copy
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
227 # the lfileness of its predecessor
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
228 if f in ctx.manifest():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
229 fctx = ctx.filectx(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
230 renamed = fctx.renamed()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
231 renamedlfile = renamed and renamed[0] in lfiles
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
232 islfile |= renamedlfile
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
233 if 'l' in fctx.flags():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
234 if renamedlfile:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
235 raise util.Abort(
15170
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15168
diff changeset
236 _('Renamed/copied largefile %s becomes symlink')
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15168
diff changeset
237 % f)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
238 islfile = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
239 if islfile:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
240 lfiles.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
241 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
242 normalfiles.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
243
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
244 if f in lfiles:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
245 dstfiles.append(lfutil.standin(f))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
246 # lfile in manifest if it has not been removed/renamed
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
247 if f in ctx.manifest():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
248 if 'l' in ctx.filectx(f).flags():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
249 if renamed and renamed[0] in lfiles:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
250 raise util.Abort(_('largefile %s becomes symlink') % f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
251
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
252 # lfile was modified, update standins
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
253 fullpath = rdst.wjoin(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
254 lfutil.createdir(os.path.dirname(fullpath))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
255 m = util.sha1('')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
256 m.update(ctx[f].data())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
257 hash = m.hexdigest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
258 if f not in lfiletohash or lfiletohash[f] != hash:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
259 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
260 fd = open(fullpath, 'wb')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
261 fd.write(ctx[f].data())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
262 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
263 if fd:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
264 fd.close()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
265 executable = 'x' in ctx[f].flags()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
266 os.chmod(fullpath, lfutil.getmode(executable))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
267 lfutil.writestandin(rdst, lfutil.standin(f), hash,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
268 executable)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
269 lfiletohash[f] = hash
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
270 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
271 # normal file
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
272 dstfiles.append(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
273
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
274 def getfilectx(repo, memctx, f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
275 if lfutil.isstandin(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
276 # if the file isn't in the manifest then it was removed
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
277 # or renamed, raise IOError to indicate this
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
278 srcfname = lfutil.splitstandin(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
279 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
280 fctx = ctx.filectx(srcfname)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
281 except error.LookupError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
282 raise IOError()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
283 renamed = fctx.renamed()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
284 if renamed:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
285 # standin is always a lfile because lfileness
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
286 # doesn't change after rename or copy
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
287 renamed = lfutil.standin(renamed[0])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
288
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
289 return context.memfilectx(f, lfiletohash[srcfname], 'l' in
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
290 fctx.flags(), 'x' in fctx.flags(), renamed)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
291 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
292 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
293 fctx = ctx.filectx(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
294 except error.LookupError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
295 raise IOError()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
296 renamed = fctx.renamed()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
297 if renamed:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
298 renamed = renamed[0]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
299
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
300 data = fctx.data()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
301 if f == '.hgtags':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
302 newdata = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
303 for line in data.splitlines():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
304 id, name = line.split(' ', 1)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
305 newdata.append('%s %s\n' % (node.hex(revmap[node.bin(id)]),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
306 name))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
307 data = ''.join(newdata)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
308 return context.memfilectx(f, data, 'l' in fctx.flags(),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
309 'x' in fctx.flags(), renamed)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
310
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
311 # Commit
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
312 mctx = context.memctx(rdst, parents, ctx.description(), dstfiles,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
313 getfilectx, ctx.user(), ctx.date(), ctx.extra())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
314 ret = rdst.commitctx(mctx)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
315 rdst.dirstate.setparents(ret)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
316 revmap[ctx.node()] = rdst.changelog.tip()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
317
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
318 def _islfile(file, ctx, matcher, size):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
319 '''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
320 A file is a lfile if it matches a pattern or is over
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
321 the given size.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
322 '''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
323 # Never store hgtags or hgignore as lfiles
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
324 if file == '.hgtags' or file == '.hgignore' or file == '.hgsigs':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
325 return False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
326 if matcher and matcher(file):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
327 return True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
328 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
329 return ctx.filectx(file).size() >= size * 1024 * 1024
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
330 except error.LookupError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
331 return False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
332
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
333 def uploadlfiles(ui, rsrc, rdst, files):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
334 '''upload largefiles to the central store'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
335
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
336 # Don't upload locally. All largefiles are in the system wide cache
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
337 # so the other repo can just get them from there.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
338 if not files or rdst.local():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
339 return
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
340
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
341 store = basestore._openstore(rsrc, rdst, put=True)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
342
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
343 at = 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
344 files = filter(lambda h: not store.exists(h), files)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
345 for hash in files:
15170
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15168
diff changeset
346 ui.progress(_('uploading largefiles'), at, unit='largefile',
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15168
diff changeset
347 total=len(files))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
348 source = lfutil.findfile(rsrc, hash)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
349 if not source:
15170
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15168
diff changeset
350 raise util.Abort(_('Missing largefile %s needs to be uploaded')
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15168
diff changeset
351 % hash)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
352 # XXX check for errors here
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
353 store.put(source, hash)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
354 at += 1
15173
3d27a8ff895f largefiles: mark a string for translation
Matt Mackall <mpm@selenic.com>
parents: 15172
diff changeset
355 ui.progress(_('uploading largefiles'), None)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
356
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
357 def verifylfiles(ui, repo, all=False, contents=False):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
358 '''Verify that every big file revision in the current changeset
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
359 exists in the central store. With --contents, also verify that
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
360 the contents of each big file revision are correct (SHA-1 hash
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
361 matches the revision ID). With --all, check every changeset in
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
362 this repository.'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
363 if all:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
364 # Pass a list to the function rather than an iterator because we know a
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
365 # list will work.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
366 revs = range(len(repo))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
367 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
368 revs = ['.']
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
369
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
370 store = basestore._openstore(repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
371 return store.verify(revs, contents=contents)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
372
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
373 def cachelfiles(ui, repo, node):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
374 '''cachelfiles ensures that all largefiles needed by the specified revision
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
375 are present in the repository's largefile cache.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
376
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
377 returns a tuple (cached, missing). cached is the list of files downloaded
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
378 by this operation; missing is the list of files that were needed but could
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
379 not be found.'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
380 lfiles = lfutil.listlfiles(repo, node)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
381 toget = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
382
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
383 for lfile in lfiles:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
384 expectedhash = repo[node][lfutil.standin(lfile)].data().strip()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
385 # if it exists and its hash matches, it might have been locally
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
386 # modified before updating and the user chose 'local'. in this case,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
387 # it will not be in any store, so don't look for it.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
388 if (not os.path.exists(repo.wjoin(lfile)) \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
389 or expectedhash != lfutil.hashfile(repo.wjoin(lfile))) and \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
390 not lfutil.findfile(repo, expectedhash):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
391 toget.append((lfile, expectedhash))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
392
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
393 if toget:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
394 store = basestore._openstore(repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
395 ret = store.get(toget)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
396 return ret
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
397
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
398 return ([], [])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
399
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
400 def updatelfiles(ui, repo, filelist=None, printmessage=True):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
401 wlock = repo.wlock()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
402 try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
403 lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
404 lfiles = set(lfutil.listlfiles(repo)) | set(lfdirstate)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
405
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
406 if filelist is not None:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
407 lfiles = [f for f in lfiles if f in filelist]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
408
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
409 printed = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
410 if printmessage and lfiles:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
411 ui.status(_('getting changed largefiles\n'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
412 printed = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
413 cachelfiles(ui, repo, '.')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
414
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
415 updated, removed = 0, 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
416 for i in map(lambda f: _updatelfile(repo, lfdirstate, f), lfiles):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
417 # increment the appropriate counter according to _updatelfile's
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
418 # return value
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
419 updated += i > 0 and i or 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
420 removed -= i < 0 and i or 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
421 if printmessage and (removed or updated) and not printed:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
422 ui.status(_('getting changed largefiles\n'))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
423 printed = True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
424
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
425 lfdirstate.write()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
426 if printed and printmessage:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
427 ui.status(_('%d largefiles updated, %d removed\n') % (updated,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
428 removed))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
429 finally:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
430 wlock.release()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
431
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
432 def _updatelfile(repo, lfdirstate, lfile):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
433 '''updates a single largefile and copies the state of its standin from
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
434 the repository's dirstate to its state in the lfdirstate.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
435
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
436 returns 1 if the file was modified, -1 if the file was removed, 0 if the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
437 file was unchanged, and None if the needed largefile was missing from the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
438 cache.'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
439 ret = 0
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
440 abslfile = repo.wjoin(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
441 absstandin = repo.wjoin(lfutil.standin(lfile))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
442 if os.path.exists(absstandin):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
443 if os.path.exists(absstandin+'.orig'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
444 shutil.copyfile(abslfile, abslfile+'.orig')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
445 expecthash = lfutil.readstandin(repo, lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
446 if expecthash != '' and \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
447 (not os.path.exists(abslfile) or \
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
448 expecthash != lfutil.hashfile(abslfile)):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
449 if not lfutil.copyfromcache(repo, expecthash, lfile):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
450 return None # don't try to set the mode or update the dirstate
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
451 ret = 1
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
452 mode = os.stat(absstandin).st_mode
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
453 if mode != os.stat(abslfile).st_mode:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
454 os.chmod(abslfile, mode)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
455 ret = 1
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
456 else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
457 if os.path.exists(abslfile):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
458 os.unlink(abslfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
459 ret = -1
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
460 state = repo.dirstate[lfutil.standin(lfile)]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
461 if state == 'n':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
462 lfdirstate.normal(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
463 elif state == 'r':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
464 lfdirstate.remove(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
465 elif state == 'a':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
466 lfdirstate.add(lfile)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
467 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
468 lfdirstate.drop(lfile)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
469 return ret
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
470
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
471 # -- hg commands declarations ------------------------------------------------
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
472
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
473
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
474 cmdtable = {
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
475 'lfconvert': (lfconvert,
15230
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
476 [('s', 'size', '',
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
477 _('minimum size (MB) for files to be converted '
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
478 'as largefiles'),
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
479 'SIZE'),
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
480 ('', 'tonormal', False,
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
481 _('convert from a largefiles repo to a normal repo')),
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
482 ],
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
483 _('hg lfconvert SOURCE DEST [FILE ...]')),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
484 }