271 for name, path in ui.configitems("paths"): |
271 for name, path in ui.configitems("paths"): |
272 paths[name] = path |
272 paths[name] = path |
273 |
273 |
274 if source in paths: source = paths[source] |
274 if source in paths: source = paths[source] |
275 |
275 |
|
276 created = False |
|
277 |
276 if dest is None: |
278 if dest is None: |
277 dest = os.getcwd() |
279 dest = os.getcwd() |
278 elif not os.path.exists(dest): |
280 elif not os.path.exists(dest): |
279 os.makedirs(dest) |
281 os.mkdir(dest) |
280 |
282 created = True |
281 link = 0 |
283 |
282 if not source.startswith("http://"): |
284 try: |
283 source = os.path.realpath(source) |
285 dest = os.path.realpath(dest) |
284 d1 = os.stat(dest).st_dev |
286 |
285 d2 = os.stat(source).st_dev |
287 link = 0 |
286 if d1 == d2: link = 1 |
288 if not source.startswith("http://"): |
287 |
289 source = os.path.realpath(source) |
288 os.chdir(dest) |
290 d1 = os.stat(dest).st_dev |
289 |
291 d2 = os.stat(source).st_dev |
290 if link: |
292 if d1 == d2: link = 1 |
291 ui.debug("copying by hardlink\n") |
293 |
292 os.system("cp -al %s/.hg .hg" % source) |
294 os.chdir(dest) |
293 try: |
295 |
294 os.remove(".hg/dirstate") |
296 if link: |
295 except: pass |
297 ui.debug("copying by hardlink\n") |
296 |
298 os.system("cp -al %s/.hg .hg" % source) |
297 repo = hg.repository(ui, ".") |
299 try: |
298 |
300 os.remove(".hg/dirstate") |
299 else: |
301 except: pass |
300 repo = hg.repository(ui, ".", create=1) |
302 |
301 other = hg.repository(ui, source) |
303 repo = hg.repository(ui, ".") |
302 cg = repo.getchangegroup(other) |
304 |
303 repo.addchangegroup(cg) |
305 else: |
304 |
306 repo = hg.repository(ui, ".", create=1) |
305 f = repo.opener("hgrc", "w") |
307 other = hg.repository(ui, source) |
306 f.write("[paths]\n") |
308 cg = repo.getchangegroup(other) |
307 f.write("default = %s\n" % source) |
309 repo.addchangegroup(cg) |
308 |
310 |
309 if not opts['no-update']: |
311 f = repo.opener("hgrc", "w") |
310 update(ui, repo) |
312 f.write("[paths]\n") |
311 |
313 f.write("default = %s\n" % source) |
|
314 |
|
315 if not opts['no-update']: |
|
316 update(ui, repo) |
|
317 except: |
|
318 if created: |
|
319 import shutil |
|
320 shutil.rmtree(dest, True) |
|
321 raise |
|
322 |
312 def commit(ui, repo, *files, **opts): |
323 def commit(ui, repo, *files, **opts): |
313 """commit the specified files or all outstanding changes""" |
324 """commit the specified files or all outstanding changes""" |
314 text = opts['text'] |
325 text = opts['text'] |
315 if not text and opts['logfile']: |
326 if not text and opts['logfile']: |
316 try: text = open(opts['logfile']).read() |
327 try: text = open(opts['logfile']).read() |
560 paths = {} |
571 paths = {} |
561 for name, path in ui.configitems("paths"): |
572 for name, path in ui.configitems("paths"): |
562 paths[name] = path |
573 paths[name] = path |
563 |
574 |
564 if dest in paths: dest = paths[dest] |
575 if dest in paths: dest = paths[dest] |
565 |
576 |
566 if not dest.startswith("ssh://"): |
577 if not dest.startswith("ssh://"): |
567 ui.warn("abort: can only push to ssh:// destinations currently\n") |
578 ui.warn("abort: can only push to ssh:// destinations currently\n") |
568 return 1 |
579 return 1 |
569 |
580 |
570 m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', dest) |
581 m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', dest) |
605 files = relpath(repo, list(flist)) |
616 files = relpath(repo, list(flist)) |
606 if rc['files']: |
617 if rc['files']: |
607 files += open(rc['files']).read().splitlines() |
618 files += open(rc['files']).read().splitlines() |
608 |
619 |
609 rc['parent'] = map(repo.lookup, rc['parent']) |
620 rc['parent'] = map(repo.lookup, rc['parent']) |
610 |
621 |
611 repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent']) |
622 repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent']) |
612 |
623 |
613 def recover(ui, repo): |
624 def recover(ui, repo): |
614 """roll back an interrupted transaction""" |
625 """roll back an interrupted transaction""" |
615 repo.recover() |
626 repo.recover() |
616 |
627 |
617 def remove(ui, repo, file, *files): |
628 def remove(ui, repo, file, *files): |
624 |
635 |
625 def serve(ui, repo, **opts): |
636 def serve(ui, repo, **opts): |
626 """export the repository via HTTP""" |
637 """export the repository via HTTP""" |
627 hgweb.server(repo.root, opts["name"], opts["templates"], |
638 hgweb.server(repo.root, opts["name"], opts["templates"], |
628 opts["address"], opts["port"]) |
639 opts["address"], opts["port"]) |
629 |
640 |
630 def status(ui, repo): |
641 def status(ui, repo): |
631 '''show changed files in the working directory |
642 '''show changed files in the working directory |
632 |
643 |
633 C = changed |
644 C = changed |
634 A = added |
645 A = added |
643 for f in d: print "R", f |
654 for f in d: print "R", f |
644 for f in u: print "?", f |
655 for f in u: print "?", f |
645 |
656 |
646 def tag(ui, repo, name, rev = None, **opts): |
657 def tag(ui, repo, name, rev = None, **opts): |
647 """add a tag for the current tip or a given revision""" |
658 """add a tag for the current tip or a given revision""" |
648 |
659 |
649 if name == "tip": |
660 if name == "tip": |
650 ui.warn("abort: 'tip' is a reserved name!\n") |
661 ui.warn("abort: 'tip' is a reserved name!\n") |
651 return -1 |
662 return -1 |
652 |
663 |
653 (c, a, d, u) = repo.diffdir(repo.root) |
664 (c, a, d, u) = repo.diffdir(repo.root) |
753 "hg import [options] <patches>"), |
764 "hg import [options] <patches>"), |
754 "init": (init, [], 'hg init'), |
765 "init": (init, [], 'hg init'), |
755 "log": (log, [], 'hg log <file>'), |
766 "log": (log, [], 'hg log <file>'), |
756 "manifest": (manifest, [], 'hg manifest [rev]'), |
767 "manifest": (manifest, [], 'hg manifest [rev]'), |
757 "parents": (parents, [], 'hg parents [node]'), |
768 "parents": (parents, [], 'hg parents [node]'), |
758 "pull": (pull, |
769 "pull": (pull, |
759 [('u', 'update', None, 'update working directory')], |
770 [('u', 'update', None, 'update working directory')], |
760 'hg pull [options] [source]'), |
771 'hg pull [options] [source]'), |
761 "push": (push, [], 'hg push <destination>'), |
772 "push": (push, [], 'hg push <destination>'), |
762 "rawcommit": (rawcommit, |
773 "rawcommit": (rawcommit, |
763 [('p', 'parent', [], 'parent'), |
774 [('p', 'parent', [], 'parent'), |