Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/hg.py @ 2721:d1fa79e7b07e
merge with crew.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Fri, 28 Jul 2006 10:47:02 -0700 |
parents | 532809ba1db5 |
children | 400a4a502001 |
comparison
equal
deleted
inserted
replaced
2718:a593813241e5 | 2721:d1fa79e7b07e |
---|---|
55 'old-http': old_http, | 55 'old-http': old_http, |
56 'ssh': ssh_, | 56 'ssh': ssh_, |
57 'static-http': static_http, | 57 'static-http': static_http, |
58 } | 58 } |
59 | 59 |
60 remote_schemes = [ | |
61 'bundle', | |
62 'hg', | |
63 'http', | |
64 'https', | |
65 'old-http', | |
66 'ssh', | |
67 'static-http', | |
68 ] | |
69 | |
70 def islocal(repo): | |
71 '''return true if repo or path is local''' | |
72 if isinstance(repo, str): | |
73 c = repo.find(':') | |
74 return c <= 0 or repo[:c] not in remote_schemes | |
75 return repo.local() | |
76 | |
60 def repository(ui, path=None, create=0): | 77 def repository(ui, path=None, create=0): |
61 scheme = None | 78 scheme = None |
62 if path: | 79 if path: |
63 c = path.find(':') | 80 c = path.find(':') |
64 if c > 0: | 81 if c > 0: |
72 except TypeError: | 89 except TypeError: |
73 raise util.Abort(_('cannot create new repository over "%s" protocol') % | 90 raise util.Abort(_('cannot create new repository over "%s" protocol') % |
74 scheme) | 91 scheme) |
75 return ctor(ui, path) | 92 return ctor(ui, path) |
76 | 93 |
94 def defaultdest(source): | |
95 '''return default destination of clone if none is given''' | |
96 return os.path.basename(os.path.normpath(source)) | |
97 | |
77 def clone(ui, source, dest=None, pull=False, rev=None, update=True, | 98 def clone(ui, source, dest=None, pull=False, rev=None, update=True, |
78 stream=False): | 99 stream=False): |
79 """Make a copy of an existing repository. | 100 """Make a copy of an existing repository. |
80 | 101 |
81 Create a copy of an existing repository in a new directory. The | 102 Create a copy of an existing repository in a new directory. The |
88 pushes. | 109 pushes. |
89 | 110 |
90 If an exception is raised, the partly cloned/updated destination | 111 If an exception is raised, the partly cloned/updated destination |
91 repository will be deleted. | 112 repository will be deleted. |
92 | 113 |
93 Keyword arguments: | 114 Arguments: |
115 | |
116 source: repository object or URL | |
94 | 117 |
95 dest: URL of destination repository to create (defaults to base | 118 dest: URL of destination repository to create (defaults to base |
96 name of source repository) | 119 name of source repository) |
97 | 120 |
98 pull: always pull from source repository, even in local case | 121 pull: always pull from source repository, even in local case |
103 rev: revision to clone up to (implies pull=True) | 126 rev: revision to clone up to (implies pull=True) |
104 | 127 |
105 update: update working directory after clone completes, if | 128 update: update working directory after clone completes, if |
106 destination is local repository | 129 destination is local repository |
107 """ | 130 """ |
131 if isinstance(source, str): | |
132 src_repo = repository(ui, source) | |
133 else: | |
134 src_repo = source | |
135 source = src_repo.url() | |
136 | |
108 if dest is None: | 137 if dest is None: |
109 dest = os.path.basename(os.path.normpath(source)) | 138 dest = defaultdest(source) |
139 | |
140 def localpath(path): | |
141 if path.startswith('file://'): | |
142 return path[7:] | |
143 if path.startswith('file:'): | |
144 return path[5:] | |
145 return path | |
146 | |
147 dest = localpath(dest) | |
148 source = localpath(source) | |
110 | 149 |
111 if os.path.exists(dest): | 150 if os.path.exists(dest): |
112 raise util.Abort(_("destination '%s' already exists"), dest) | 151 raise util.Abort(_("destination '%s' already exists"), dest) |
113 | 152 |
114 class DirCleanup(object): | 153 class DirCleanup(object): |
119 self.dir_ = None | 158 self.dir_ = None |
120 def __del__(self): | 159 def __del__(self): |
121 if self.dir_: | 160 if self.dir_: |
122 self.rmtree(self.dir_, True) | 161 self.rmtree(self.dir_, True) |
123 | 162 |
124 src_repo = repository(ui, source) | |
125 | |
126 dest_repo = None | 163 dest_repo = None |
127 try: | 164 try: |
128 dest_repo = repository(ui, dest) | 165 dest_repo = repository(ui, dest) |
129 raise util.Abort(_("destination '%s' already exists." % dest)) | 166 raise util.Abort(_("destination '%s' already exists." % dest)) |
130 except RepoError: | 167 except RepoError: |
131 dest_repo = repository(ui, dest, create=True) | 168 dest_repo = repository(ui, dest, create=True) |
132 | 169 |
133 dest_path = None | 170 dest_path = None |
134 dir_cleanup = None | 171 dir_cleanup = None |
135 if dest_repo.local(): | 172 if dest_repo.local(): |
136 dest_path = os.path.realpath(dest) | 173 dest_path = os.path.realpath(dest_repo.root) |
137 dir_cleanup = DirCleanup(dest_path) | 174 dir_cleanup = DirCleanup(dest_path) |
138 | 175 |
139 abspath = source | 176 abspath = source |
140 copy = False | 177 copy = False |
141 if src_repo.local() and dest_repo.local(): | 178 if src_repo.local() and dest_repo.local(): |