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