Show More
@@ -209,12 +209,12 b' def clone(ui, source, dest=None, pull=Fa' | |||||
209 | if isinstance(source, str): |
|
209 | if isinstance(source, str): | |
210 | origsource = ui.expandpath(source) |
|
210 | origsource = ui.expandpath(source) | |
211 | source, branch = parseurl(origsource, branch) |
|
211 | source, branch = parseurl(origsource, branch) | |
212 |
src |
|
212 | srcrepo = repository(ui, source) | |
213 | else: |
|
213 | else: | |
214 |
src |
|
214 | srcrepo = source | |
215 | branch = (None, branch or []) |
|
215 | branch = (None, branch or []) | |
216 |
origsource = source = src |
|
216 | origsource = source = srcrepo.url() | |
217 |
rev, checkout = addbranchrevs(src |
|
217 | rev, checkout = addbranchrevs(srcrepo, srcrepo, branch, rev) | |
218 |
|
218 | |||
219 | if dest is None: |
|
219 | if dest is None: | |
220 | dest = defaultdest(source) |
|
220 | dest = defaultdest(source) | |
@@ -241,17 +241,17 b' def clone(ui, source, dest=None, pull=Fa' | |||||
241 | if self.dir_: |
|
241 | if self.dir_: | |
242 | self.rmtree(self.dir_, True) |
|
242 | self.rmtree(self.dir_, True) | |
243 |
|
243 | |||
244 |
src |
|
244 | srclock = destlock = dircleanup = None | |
245 | try: |
|
245 | try: | |
246 | abspath = origsource |
|
246 | abspath = origsource | |
247 | if islocal(origsource): |
|
247 | if islocal(origsource): | |
248 | abspath = os.path.abspath(util.localpath(origsource)) |
|
248 | abspath = os.path.abspath(util.localpath(origsource)) | |
249 |
|
249 | |||
250 | if islocal(dest): |
|
250 | if islocal(dest): | |
251 |
dir |
|
251 | dircleanup = DirCleanup(dest) | |
252 |
|
252 | |||
253 | copy = False |
|
253 | copy = False | |
254 |
if src |
|
254 | if srcrepo.cancopy() and islocal(dest): | |
255 | copy = not pull and not rev |
|
255 | copy = not pull and not rev | |
256 |
|
256 | |||
257 | if copy: |
|
257 | if copy: | |
@@ -260,40 +260,40 b' def clone(ui, source, dest=None, pull=Fa' | |||||
260 | # can end up with extra data in the cloned revlogs that's |
|
260 | # can end up with extra data in the cloned revlogs that's | |
261 | # not pointed to by changesets, thus causing verify to |
|
261 | # not pointed to by changesets, thus causing verify to | |
262 | # fail |
|
262 | # fail | |
263 |
src |
|
263 | srclock = srcrepo.lock(wait=False) | |
264 | except error.LockError: |
|
264 | except error.LockError: | |
265 | copy = False |
|
265 | copy = False | |
266 |
|
266 | |||
267 | if copy: |
|
267 | if copy: | |
268 |
src |
|
268 | srcrepo.hook('preoutgoing', throw=True, source='clone') | |
269 | hgdir = os.path.realpath(os.path.join(dest, ".hg")) |
|
269 | hgdir = os.path.realpath(os.path.join(dest, ".hg")) | |
270 | if not os.path.exists(dest): |
|
270 | if not os.path.exists(dest): | |
271 | os.mkdir(dest) |
|
271 | os.mkdir(dest) | |
272 | else: |
|
272 | else: | |
273 | # only clean up directories we create ourselves |
|
273 | # only clean up directories we create ourselves | |
274 |
dir |
|
274 | dircleanup.dir_ = hgdir | |
275 | try: |
|
275 | try: | |
276 |
dest |
|
276 | destpath = hgdir | |
277 |
util.makedir(dest |
|
277 | util.makedir(destpath, notindexed=True) | |
278 | except OSError, inst: |
|
278 | except OSError, inst: | |
279 | if inst.errno == errno.EEXIST: |
|
279 | if inst.errno == errno.EEXIST: | |
280 |
dir |
|
280 | dircleanup.close() | |
281 | raise util.Abort(_("destination '%s' already exists") |
|
281 | raise util.Abort(_("destination '%s' already exists") | |
282 | % dest) |
|
282 | % dest) | |
283 | raise |
|
283 | raise | |
284 |
|
284 | |||
285 | hardlink = None |
|
285 | hardlink = None | |
286 | num = 0 |
|
286 | num = 0 | |
287 |
for f in src |
|
287 | for f in srcrepo.store.copylist(): | |
288 |
src = os.path.join(src |
|
288 | src = os.path.join(srcrepo.sharedpath, f) | |
289 |
dst = os.path.join(dest |
|
289 | dst = os.path.join(destpath, f) | |
290 | dstbase = os.path.dirname(dst) |
|
290 | dstbase = os.path.dirname(dst) | |
291 | if dstbase and not os.path.exists(dstbase): |
|
291 | if dstbase and not os.path.exists(dstbase): | |
292 | os.mkdir(dstbase) |
|
292 | os.mkdir(dstbase) | |
293 | if os.path.exists(src): |
|
293 | if os.path.exists(src): | |
294 | if dst.endswith('data'): |
|
294 | if dst.endswith('data'): | |
295 | # lock to avoid premature writing to the target |
|
295 | # lock to avoid premature writing to the target | |
296 |
dest |
|
296 | destlock = lock.lock(os.path.join(dstbase, "lock")) | |
297 | hardlink, n = util.copyfiles(src, dst, hardlink) |
|
297 | hardlink, n = util.copyfiles(src, dst, hardlink) | |
298 | num += n |
|
298 | num += n | |
299 | if hardlink: |
|
299 | if hardlink: | |
@@ -303,82 +303,82 b' def clone(ui, source, dest=None, pull=Fa' | |||||
303 |
|
303 | |||
304 | # we need to re-init the repo after manually copying the data |
|
304 | # we need to re-init the repo after manually copying the data | |
305 | # into it |
|
305 | # into it | |
306 |
dest |
|
306 | destrepo = repository(ui, dest) | |
307 |
src |
|
307 | srcrepo.hook('outgoing', source='clone', | |
308 | node=node.hex(node.nullid)) |
|
308 | node=node.hex(node.nullid)) | |
309 | else: |
|
309 | else: | |
310 | try: |
|
310 | try: | |
311 |
dest |
|
311 | destrepo = repository(ui, dest, create=True) | |
312 | except OSError, inst: |
|
312 | except OSError, inst: | |
313 | if inst.errno == errno.EEXIST: |
|
313 | if inst.errno == errno.EEXIST: | |
314 |
dir |
|
314 | dircleanup.close() | |
315 | raise util.Abort(_("destination '%s' already exists") |
|
315 | raise util.Abort(_("destination '%s' already exists") | |
316 | % dest) |
|
316 | % dest) | |
317 | raise |
|
317 | raise | |
318 |
|
318 | |||
319 | revs = None |
|
319 | revs = None | |
320 | if rev: |
|
320 | if rev: | |
321 |
if 'lookup' not in src |
|
321 | if 'lookup' not in srcrepo.capabilities: | |
322 | raise util.Abort(_("src repository does not support " |
|
322 | raise util.Abort(_("src repository does not support " | |
323 | "revision lookup and so doesn't " |
|
323 | "revision lookup and so doesn't " | |
324 | "support clone by revision")) |
|
324 | "support clone by revision")) | |
325 |
revs = [src |
|
325 | revs = [srcrepo.lookup(r) for r in rev] | |
326 | checkout = revs[0] |
|
326 | checkout = revs[0] | |
327 |
if dest |
|
327 | if destrepo.local(): | |
328 |
dest |
|
328 | destrepo.clone(srcrepo, heads=revs, stream=stream) | |
329 |
elif src |
|
329 | elif srcrepo.local(): | |
330 |
src |
|
330 | srcrepo.push(destrepo, revs=revs) | |
331 | else: |
|
331 | else: | |
332 | raise util.Abort(_("clone from remote to remote not supported")) |
|
332 | raise util.Abort(_("clone from remote to remote not supported")) | |
333 |
|
333 | |||
334 |
if dir |
|
334 | if dircleanup: | |
335 |
dir |
|
335 | dircleanup.close() | |
336 |
|
336 | |||
337 |
if dest |
|
337 | if destrepo.local(): | |
338 |
fp = dest |
|
338 | fp = destrepo.opener("hgrc", "w", text=True) | |
339 | fp.write("[paths]\n") |
|
339 | fp.write("[paths]\n") | |
340 | fp.write("default = %s\n" % abspath) |
|
340 | fp.write("default = %s\n" % abspath) | |
341 | fp.close() |
|
341 | fp.close() | |
342 |
|
342 | |||
343 |
dest |
|
343 | destrepo.ui.setconfig('paths', 'default', abspath) | |
344 |
|
344 | |||
345 | if update: |
|
345 | if update: | |
346 | if update is not True: |
|
346 | if update is not True: | |
347 | checkout = update |
|
347 | checkout = update | |
348 |
if src |
|
348 | if srcrepo.local(): | |
349 |
checkout = src |
|
349 | checkout = srcrepo.lookup(update) | |
350 | for test in (checkout, 'default', 'tip'): |
|
350 | for test in (checkout, 'default', 'tip'): | |
351 | if test is None: |
|
351 | if test is None: | |
352 | continue |
|
352 | continue | |
353 | try: |
|
353 | try: | |
354 |
uprev = dest |
|
354 | uprev = destrepo.lookup(test) | |
355 | break |
|
355 | break | |
356 | except error.RepoLookupError: |
|
356 | except error.RepoLookupError: | |
357 | continue |
|
357 | continue | |
358 |
bn = dest |
|
358 | bn = destrepo[uprev].branch() | |
359 |
dest |
|
359 | destrepo.ui.status(_("updating to branch %s\n") % bn) | |
360 |
_update(dest |
|
360 | _update(destrepo, uprev) | |
361 |
|
361 | |||
362 | # clone all bookmarks |
|
362 | # clone all bookmarks | |
363 |
if dest |
|
363 | if destrepo.local() and srcrepo.capable("pushkey"): | |
364 |
rb = src |
|
364 | rb = srcrepo.listkeys('bookmarks') | |
365 | for k, n in rb.iteritems(): |
|
365 | for k, n in rb.iteritems(): | |
366 | try: |
|
366 | try: | |
367 |
m = dest |
|
367 | m = destrepo.lookup(n) | |
368 |
dest |
|
368 | destrepo._bookmarks[k] = m | |
369 | except error.RepoLookupError: |
|
369 | except error.RepoLookupError: | |
370 | pass |
|
370 | pass | |
371 | if rb: |
|
371 | if rb: | |
372 |
bookmarks.write(dest |
|
372 | bookmarks.write(destrepo) | |
373 |
elif src |
|
373 | elif srcrepo.local() and destrepo.capable("pushkey"): | |
374 |
for k, n in src |
|
374 | for k, n in srcrepo._bookmarks.iteritems(): | |
375 |
dest |
|
375 | destrepo.pushkey('bookmarks', k, '', hex(n)) | |
376 |
|
376 | |||
377 |
return src |
|
377 | return srcrepo, destrepo | |
378 | finally: |
|
378 | finally: | |
379 |
release(src |
|
379 | release(srclock, destlock) | |
380 |
if dir |
|
380 | if dircleanup is not None: | |
381 |
dir |
|
381 | dircleanup.cleanup() | |
382 |
|
382 | |||
383 | def _showstats(repo, stats): |
|
383 | def _showstats(repo, stats): | |
384 | repo.ui.status(_("%d files updated, %d files merged, " |
|
384 | repo.ui.status(_("%d files updated, %d files merged, " |
General Comments 0
You need to be logged in to leave comments.
Login now