Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 2597:5ba8be56fa8f
clone: move code into hg module. make doc better.
api in commands module is still same, but version in hg is best for
calling within python now.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Tue, 11 Jul 2006 16:18:53 -0700 |
parents | 911b56853fdd |
children | b898afee9d0d |
comparison
equal
deleted
inserted
replaced
2596:e3258cc3ed63 | 2597:5ba8be56fa8f |
---|---|
954 | 954 |
955 It is possible to specify an ssh:// URL as the destination, but no | 955 It is possible to specify an ssh:// URL as the destination, but no |
956 .hg/hgrc will be created on the remote side. Look at the help text | 956 .hg/hgrc will be created on the remote side. Look at the help text |
957 for the pull command for important details about ssh:// URLs. | 957 for the pull command for important details about ssh:// URLs. |
958 """ | 958 """ |
959 if dest is None: | |
960 dest = os.path.basename(os.path.normpath(source)) | |
961 | |
962 if os.path.exists(dest): | |
963 raise util.Abort(_("destination '%s' already exists"), dest) | |
964 | |
965 class Dircleanup(object): | |
966 def __init__(self, dir_): | |
967 self.rmtree = shutil.rmtree | |
968 self.dir_ = dir_ | |
969 def close(self): | |
970 self.dir_ = None | |
971 def __del__(self): | |
972 if self.dir_: | |
973 self.rmtree(self.dir_, True) | |
974 | |
975 if opts['ssh']: | 959 if opts['ssh']: |
976 ui.setconfig("ui", "ssh", opts['ssh']) | 960 ui.setconfig("ui", "ssh", opts['ssh']) |
977 if opts['remotecmd']: | 961 if opts['remotecmd']: |
978 ui.setconfig("ui", "remotecmd", opts['remotecmd']) | 962 ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
979 | 963 |
980 source = ui.expandpath(source) | 964 hg.clone(ui, ui.expandpath(source), dest, |
981 src_repo = hg.repository(ui, source) | 965 pull=opts['pull'], |
982 | 966 rev=opts['rev'], |
983 dest_repo = None | 967 update=not opts['noupdate']) |
984 try: | |
985 dest_repo = hg.repository(ui, dest) | |
986 raise util.Abort(_("destination '%s' already exists." % dest)) | |
987 except hg.RepoError: | |
988 dest_repo = hg.repository(ui, dest, create=1) | |
989 | |
990 dest_path = None | |
991 d = None | |
992 if dest_repo.local(): | |
993 dest_path = os.path.realpath(dest) | |
994 d = Dircleanup(dest_path) | |
995 | |
996 abspath = source | |
997 copy = False | |
998 if src_repo.local() and dest_repo.local(): | |
999 abspath = os.path.abspath(source) | |
1000 if not opts['pull'] and not opts['rev']: | |
1001 copy = True | |
1002 | |
1003 if copy: | |
1004 try: | |
1005 # we use a lock here because if we race with commit, we | |
1006 # can end up with extra data in the cloned revlogs that's | |
1007 # not pointed to by changesets, thus causing verify to | |
1008 # fail | |
1009 l1 = src_repo.lock() | |
1010 except lock.LockException: | |
1011 copy = False | |
1012 | |
1013 if copy: | |
1014 # we lock here to avoid premature writing to the target | |
1015 l2 = lock.lock(os.path.join(dest_path, ".hg", "lock")) | |
1016 | |
1017 # we need to remove the (empty) data dir in dest so copyfiles can do it's work | |
1018 os.rmdir( os.path.join(dest_path, ".hg", "data") ) | |
1019 files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i" | |
1020 for f in files.split(): | |
1021 src = os.path.join(source, ".hg", f) | |
1022 dst = os.path.join(dest_path, ".hg", f) | |
1023 try: | |
1024 util.copyfiles(src, dst) | |
1025 except OSError, inst: | |
1026 if inst.errno != errno.ENOENT: | |
1027 raise | |
1028 | |
1029 # we need to re-init the repo after manually copying the data into it | |
1030 dest_repo = hg.repository(ui, dest) | |
1031 | |
1032 else: | |
1033 revs = None | |
1034 if opts['rev']: | |
1035 if not src_repo.local(): | |
1036 error = _("clone -r not supported yet for remote repositories.") | |
1037 raise util.Abort(error) | |
1038 else: | |
1039 revs = [src_repo.lookup(rev) for rev in opts['rev']] | |
1040 | |
1041 if dest_repo.local(): | |
1042 dest_repo.pull(src_repo, heads = revs) | |
1043 elif src_repo.local(): | |
1044 src_repo.push(dest_repo, revs = revs) | |
1045 else: | |
1046 error = _("clone from remote to remote not supported.") | |
1047 raise util.Abort(error) | |
1048 | |
1049 if dest_repo.local(): | |
1050 f = dest_repo.opener("hgrc", "w", text=True) | |
1051 f.write("[paths]\n") | |
1052 f.write("default = %s\n" % abspath) | |
1053 f.close() | |
1054 | |
1055 if not opts['noupdate']: | |
1056 doupdate(dest_repo.ui, dest_repo) | |
1057 | |
1058 if d: | |
1059 d.close() | |
1060 | 968 |
1061 def commit(ui, repo, *pats, **opts): | 969 def commit(ui, repo, *pats, **opts): |
1062 """commit the specified files or all outstanding changes | 970 """commit the specified files or all outstanding changes |
1063 | 971 |
1064 Commit changes to the given files into the repository. | 972 Commit changes to the given files into the repository. |