Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hg.py @ 15078:193e7018dc8c
hg: extract copying the store out of clone
author | Simon Heimberg <simohe@besonet.ch> |
---|---|
date | Thu, 11 Aug 2011 00:03:16 +0200 |
parents | 4c523a2af6e7 |
children | dbdb777502dc |
comparison
equal
deleted
inserted
replaced
15076:89d9f92f6fdd | 15078:193e7018dc8c |
---|---|
171 uprev = r.lookup(test) | 171 uprev = r.lookup(test) |
172 break | 172 break |
173 except error.RepoLookupError: | 173 except error.RepoLookupError: |
174 continue | 174 continue |
175 _update(r, uprev) | 175 _update(r, uprev) |
176 | |
177 def copystore(ui, srcrepo, destpath): | |
178 '''copy files from store of srcrepo in destpath | |
179 | |
180 returns destlock | |
181 ''' | |
182 destlock = None | |
183 try: | |
184 hardlink = None | |
185 num = 0 | |
186 for f in srcrepo.store.copylist(): | |
187 src = os.path.join(srcrepo.sharedpath, f) | |
188 dst = os.path.join(destpath, f) | |
189 dstbase = os.path.dirname(dst) | |
190 if dstbase and not os.path.exists(dstbase): | |
191 os.mkdir(dstbase) | |
192 if os.path.exists(src): | |
193 if dst.endswith('data'): | |
194 # lock to avoid premature writing to the target | |
195 destlock = lock.lock(os.path.join(dstbase, "lock")) | |
196 hardlink, n = util.copyfiles(src, dst, hardlink) | |
197 num += n | |
198 if hardlink: | |
199 ui.debug("linked %d files\n" % num) | |
200 else: | |
201 ui.debug("copied %d files\n" % num) | |
202 return destlock | |
203 except: | |
204 release(destlock) | |
205 raise | |
176 | 206 |
177 def clone(ui, peeropts, source, dest=None, pull=False, rev=None, | 207 def clone(ui, peeropts, source, dest=None, pull=False, rev=None, |
178 update=True, stream=False, branch=None): | 208 update=True, stream=False, branch=None): |
179 """Make a copy of an existing repository. | 209 """Make a copy of an existing repository. |
180 | 210 |
285 dircleanup.close() | 315 dircleanup.close() |
286 raise util.Abort(_("destination '%s' already exists") | 316 raise util.Abort(_("destination '%s' already exists") |
287 % dest) | 317 % dest) |
288 raise | 318 raise |
289 | 319 |
290 hardlink = None | 320 destlock = copystore(ui, srcrepo, destpath) |
291 num = 0 | |
292 for f in srcrepo.store.copylist(): | |
293 src = os.path.join(srcrepo.sharedpath, f) | |
294 dst = os.path.join(destpath, f) | |
295 dstbase = os.path.dirname(dst) | |
296 if dstbase and not os.path.exists(dstbase): | |
297 os.mkdir(dstbase) | |
298 if os.path.exists(src): | |
299 if dst.endswith('data'): | |
300 # lock to avoid premature writing to the target | |
301 destlock = lock.lock(os.path.join(dstbase, "lock")) | |
302 hardlink, n = util.copyfiles(src, dst, hardlink) | |
303 num += n | |
304 if hardlink: | |
305 ui.debug("linked %d files\n" % num) | |
306 else: | |
307 ui.debug("copied %d files\n" % num) | |
308 | 321 |
309 # we need to re-init the repo after manually copying the data | 322 # we need to re-init the repo after manually copying the data |
310 # into it | 323 # into it |
311 destrepo = repository(remoteui(ui, peeropts), dest) | 324 destrepo = repository(remoteui(ui, peeropts), dest) |
312 srcrepo.hook('outgoing', source='clone', | 325 srcrepo.hook('outgoing', source='clone', |