Show More
@@ -272,8 +272,6 b' def clone(ui, source, dest = None, **opt' | |||||
272 | """make a copy of an existing repository""" |
|
272 | """make a copy of an existing repository""" | |
273 | source = ui.expandpath(source) |
|
273 | source = ui.expandpath(source) | |
274 |
|
274 | |||
275 | success = False |
|
|||
276 |
|
||||
277 | if dest is None: |
|
275 | if dest is None: | |
278 | dest = os.path.basename(os.path.normpath(source)) |
|
276 | dest = os.path.basename(os.path.normpath(source)) | |
279 |
|
277 | |||
@@ -281,45 +279,50 b' def clone(ui, source, dest = None, **opt' | |||||
281 | ui.warn("abort: destination '%s' already exists\n" % dest) |
|
279 | ui.warn("abort: destination '%s' already exists\n" % dest) | |
282 | return 1 |
|
280 | return 1 | |
283 |
|
281 | |||
284 | os.mkdir(dest) |
|
282 | class dircleanup: | |
285 |
|
283 | def __init__(self, dir): | ||
286 | try: |
|
284 | self.dir = dir | |
287 | link = 0 |
|
285 | os.mkdir(dir) | |
288 | if not source.startswith("http://"): |
|
286 | def close(self): | |
289 | d1 = os.stat(dest).st_dev |
|
287 | self.dir = None | |
290 | d2 = os.stat(source).st_dev |
|
288 | def __del__(self): | |
291 | if d1 == d2: link = 1 |
|
289 | if self.dir: | |
|
290 | import shutil | |||
|
291 | shutil.rmtree(self.dir, True) | |||
292 |
|
292 | |||
293 | if link: |
|
293 | d = dircleanup(dest) | |
294 | ui.note("copying by hardlink\n") |
|
|||
295 | util.system("cp -al '%s'/.hg '%s'/.hg" % (source, dest)) |
|
|||
296 | try: |
|
|||
297 | os.remove(os.path.join(dest, ".hg", "dirstate")) |
|
|||
298 | except: pass |
|
|||
299 |
|
294 | |||
300 | repo = hg.repository(ui, dest) |
|
295 | link = 0 | |
|
296 | if not source.startswith("http://"): | |||
|
297 | d1 = os.stat(dest).st_dev | |||
|
298 | d2 = os.stat(source).st_dev | |||
|
299 | if d1 == d2: link = 1 | |||
301 |
|
300 | |||
302 | else: |
|
301 | if link: | |
303 | repo = hg.repository(ui, dest, create=1) |
|
302 | ui.note("copying by hardlink\n") | |
304 | other = hg.repository(ui, source) |
|
303 | util.system("cp -al '%s'/.hg '%s'/.hg" % (source, dest)) | |
305 | fetch = repo.findincoming(other) |
|
304 | try: | |
306 | if fetch: |
|
305 | os.remove(os.path.join(dest, ".hg", "dirstate")) | |
307 | cg = other.changegroup(fetch) |
|
306 | except: pass | |
308 | repo.addchangegroup(cg) |
|
307 | ||
|
308 | repo = hg.repository(ui, dest) | |||
309 |
|
309 | |||
310 | f = repo.opener("hgrc", "w") |
|
310 | else: | |
311 | f.write("[paths]\n") |
|
311 | repo = hg.repository(ui, dest, create=1) | |
312 | f.write("default = %s\n" % source) |
|
312 | other = hg.repository(ui, source) | |
313 |
|
313 | fetch = repo.findincoming(other) | ||
314 | if not opts['noupdate']: |
|
314 | if fetch: | |
315 | update(ui, repo) |
|
315 | cg = other.changegroup(fetch) | |
|
316 | repo.addchangegroup(cg) | |||
316 |
|
317 | |||
317 | success = True |
|
318 | f = repo.opener("hgrc", "w") | |
|
319 | f.write("[paths]\n") | |||
|
320 | f.write("default = %s\n" % source) | |||
318 |
|
321 | |||
319 | finally: |
|
322 | if not opts['noupdate']: | |
320 | if not success: |
|
323 | update(ui, repo) | |
321 | import shutil |
|
324 | ||
322 | shutil.rmtree(dest, True) |
|
325 | d.close() | |
323 |
|
326 | |||
324 | def commit(ui, repo, *files, **opts): |
|
327 | def commit(ui, repo, *files, **opts): | |
325 | """commit the specified files or all outstanding changes""" |
|
328 | """commit the specified files or all outstanding changes""" |
General Comments 0
You need to be logged in to leave comments.
Login now