##// END OF EJS Templates
hg.py: add islocal() and defaultdest() functions, refactor...
Vadim Gelfer -
r2719:532809ba default
parent child Browse files
Show More
@@ -57,6 +57,23 b' schemes = {'
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:
@@ -74,6 +91,10 b' def repository(ui, path=None, create=0):'
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.
@@ -90,7 +111,9 b' def clone(ui, source, dest=None, pull=Fa'
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)
@@ -105,8 +128,24 b' def clone(ui, source, dest=None, pull=Fa'
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)
@@ -121,8 +160,6 b' def clone(ui, source, dest=None, pull=Fa'
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)
@@ -133,7 +170,7 b' def clone(ui, source, dest=None, pull=Fa'
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
General Comments 0
You need to be logged in to leave comments. Login now