|
53 | 53 |
|
54 | 54 | from diffuse import utils |
55 | 55 | from diffuse import constants |
56 | | -from diffuse.vcs.folder_set import FolderSet |
57 | | -from diffuse.vcs.bzr import Bzr |
58 | | -from diffuse.vcs.cvs import Cvs |
59 | | -from diffuse.vcs.darcs import Darcs |
60 | | -from diffuse.vcs.git import Git |
61 | | -from diffuse.vcs.hg import Hg |
62 | | -from diffuse.vcs.mtn import Mtn |
63 | | -from diffuse.vcs.rcs import Rcs |
64 | | -from diffuse.vcs.svk import Svk |
65 | | -from diffuse.vcs.svn import Svn |
| 56 | +from diffuse.vcs.vcs_registry import VcsRegistry |
66 | 57 |
|
67 | 58 | if not hasattr(__builtins__, 'WindowsError'): |
68 | 59 | # define 'WindowsError' so 'except' statements will work on all platforms |
@@ -1192,191 +1183,7 @@ def convert_to_format(s, format): |
1192 | 1183 | s += '\r' |
1193 | 1184 | return s |
1194 | 1185 |
|
1195 | | -# returns the Windows drive or share from a from an absolute path |
1196 | | -def drive_from_path(s): |
1197 | | - c = s.split(os.sep) |
1198 | | - if len(c) > 3 and c[0] == '' and c[1] == '': |
1199 | | - return os.path.join(c[:4]) |
1200 | | - return c[0] |
1201 | | - |
1202 | | -# escape arguments for use with bash |
1203 | | -def bashEscape(s): |
1204 | | - return "'" + s.replace("'", "'\\''") + "'" |
1205 | | - |
1206 | | -# utility method to help find folders used by version control systems |
1207 | | -def _find_parent_dir_with(path, dir_name): |
1208 | | - while True: |
1209 | | - name = os.path.join(path, dir_name) |
1210 | | - if os.path.isdir(name): |
1211 | | - return path |
1212 | | - newpath = os.path.dirname(path) |
1213 | | - if newpath == path: |
1214 | | - break |
1215 | | - path = newpath |
1216 | | - |
1217 | | -def _get_bzr_repo(path, prefs): |
1218 | | - p = _find_parent_dir_with(path, '.bzr') |
1219 | | - if p: |
1220 | | - return Bzr(p) |
1221 | | - |
1222 | | -def _get_cvs_repo(path, prefs): |
1223 | | - if os.path.isdir(os.path.join(path, 'CVS')): |
1224 | | - return Cvs(path) |
1225 | | - |
1226 | | -def _get_darcs_repo(path, prefs): |
1227 | | - p = _find_parent_dir_with(path, '_darcs') |
1228 | | - if p: |
1229 | | - return Darcs(p) |
1230 | | - |
1231 | | -def _get_git_repo(path, prefs): |
1232 | | - if 'GIT_DIR' in os.environ: |
1233 | | - try: |
1234 | | - d = path |
1235 | | - ss = utils.popenReadLines(d, [ prefs.getString('git_bin'), 'rev-parse', '--show-prefix' ], prefs, 'git_bash') |
1236 | | - if len(ss) > 0: |
1237 | | - # be careful to handle trailing slashes |
1238 | | - d = d.split(os.sep) |
1239 | | - if d[-1] != '': |
1240 | | - d.append('') |
1241 | | - ss = strip_eol(ss[0]).split('/') |
1242 | | - if ss[-1] != '': |
1243 | | - ss.append('') |
1244 | | - n = len(ss) |
1245 | | - if n <= len(d): |
1246 | | - del d[-n:] |
1247 | | - if len(d) == 0: |
1248 | | - d = os.curdir |
1249 | | - else: |
1250 | | - d = os.sep.join(d) |
1251 | | - return Git(d) |
1252 | | - except (IOError, OSError, WindowsError): |
1253 | | - # working tree not found |
1254 | | - pass |
1255 | | - # search for .git directory (project) or .git file (submodule) |
1256 | | - while True: |
1257 | | - name = os.path.join(path, '.git') |
1258 | | - if os.path.isdir(name) or os.path.isfile(name): |
1259 | | - return Git(path) |
1260 | | - newpath = os.path.dirname(path) |
1261 | | - if newpath == path: |
1262 | | - break |
1263 | | - path = newpath |
1264 | | - |
1265 | | -def _get_hg_repo(path, prefs): |
1266 | | - p = _find_parent_dir_with(path, '.hg') |
1267 | | - if p: |
1268 | | - return Hg(p) |
1269 | | - |
1270 | | -def _get_mtn_repo(path, prefs): |
1271 | | - p = _find_parent_dir_with(path, '_MTN') |
1272 | | - if p: |
1273 | | - return Mtn(p) |
1274 | | - |
1275 | | -def _get_rcs_repo(path, prefs): |
1276 | | - if os.path.isdir(os.path.join(path, 'RCS')): |
1277 | | - return Rcs(path) |
1278 | | - |
1279 | | - # [rfailliot] this code doesn't seem to work, but was in 0.4.8 too. |
1280 | | - # I'm letting it here until further tests are done, but it is possible |
1281 | | - # this code never actually worked. |
1282 | | - try: |
1283 | | - for s in os.listdir(path): |
1284 | | - if s.endswith(',v') and os.path.isfile(os.path.join(path, s)): |
1285 | | - return Rcs(path) |
1286 | | - except OSError: |
1287 | | - # the user specified an invalid folder name |
1288 | | - pass |
1289 | | - |
1290 | | -def _get_svn_repo(path, prefs): |
1291 | | - p = _find_parent_dir_with(path, '.svn') |
1292 | | - if p: |
1293 | | - return Svn(p) |
1294 | | - |
1295 | | -def _get_svk_repo(path, prefs): |
1296 | | - name = path |
1297 | | - # parse the ~/.svk/config file to discover which directories are part of |
1298 | | - # SVK repositories |
1299 | | - if utils.isWindows(): |
1300 | | - name = name.upper() |
1301 | | - svkroot = os.environ.get('SVKROOT', None) |
1302 | | - if svkroot is None: |
1303 | | - svkroot = os.path.expanduser('~/.svk') |
1304 | | - svkconfig = os.path.join(svkroot, 'config') |
1305 | | - if os.path.isfile(svkconfig): |
1306 | | - try: |
1307 | | - # find working copies by parsing the config file |
1308 | | - f = open(svkconfig, 'r') |
1309 | | - ss = readlines(f) |
1310 | | - f.close() |
1311 | | - projs, sep = [], os.sep |
1312 | | - # find the separator character |
1313 | | - for s in ss: |
1314 | | - if s.startswith(' sep: ') and len(s) > 7: |
1315 | | - sep = s[7] |
1316 | | - # find the project directories |
1317 | | - i = 0 |
1318 | | - while i < len(ss): |
1319 | | - s = ss[i] |
1320 | | - i += 1 |
1321 | | - if s.startswith(' hash: '): |
1322 | | - while i < len(ss) and ss[i].startswith(' '): |
1323 | | - s = ss[i] |
1324 | | - i += 1 |
1325 | | - if s.endswith(': ') and i < len(ss) and ss[i].startswith(' depotpath: '): |
1326 | | - key = s[4:-2].replace(sep, os.sep) |
1327 | | - # parse directory path |
1328 | | - j, n, tt = 0, len(key), [] |
1329 | | - while j < n: |
1330 | | - if key[j] == '"': |
1331 | | - # quoted string |
1332 | | - j += 1 |
1333 | | - while j < n: |
1334 | | - if key[j] == '"': |
1335 | | - j += 1 |
1336 | | - break |
1337 | | - elif key[j] == '\\': |
1338 | | - # escaped character |
1339 | | - j += 1 |
1340 | | - if j < n: |
1341 | | - tt.append(key[j]) |
1342 | | - j += 1 |
1343 | | - else: |
1344 | | - tt.append(key[j]) |
1345 | | - j += 1 |
1346 | | - key = ''.join(tt).replace(sep, os.sep) |
1347 | | - if utils.isWindows(): |
1348 | | - key = key.upper() |
1349 | | - projs.append(key) |
1350 | | - break |
1351 | | - # check if the file belongs to one of the project directories |
1352 | | - if FolderSet(projs).contains(name): |
1353 | | - return Svk(path) |
1354 | | - except IOError: |
1355 | | - utils.logError(_('Error parsing %s.') % (svkconfig, )) |
1356 | | - |
1357 | | -class VCSs: |
1358 | | - def __init__(self): |
1359 | | - # initialise the VCS objects |
1360 | | - self._get_repo = { 'bzr': _get_bzr_repo, 'cvs': _get_cvs_repo, 'darcs': _get_darcs_repo, 'git': _get_git_repo, 'hg': _get_hg_repo, 'mtn': _get_mtn_repo, 'rcs': _get_rcs_repo, 'svk': _get_svk_repo, 'svn': _get_svn_repo } |
1361 | | - |
1362 | | - def setSearchOrder(self, ordering): |
1363 | | - self._search_order = ordering |
1364 | | - |
1365 | | - # determines which VCS to use for files in the named folder |
1366 | | - def findByFolder(self, path, prefs): |
1367 | | - path = os.path.abspath(path) |
1368 | | - for vcs in prefs.getString('vcs_search_order').split(): |
1369 | | - if vcs in self._get_repo: |
1370 | | - repo = self._get_repo[vcs](path, prefs) |
1371 | | - if repo: |
1372 | | - return repo |
1373 | | - |
1374 | | - # determines which VCS to use for the named file |
1375 | | - def findByFilename(self, name, prefs): |
1376 | | - if name is not None: |
1377 | | - return self.findByFolder(os.path.dirname(name), prefs) |
1378 | | - |
1379 | | -theVCSs = VCSs() |
| 1186 | +theVCSs = VcsRegistry() |
1380 | 1187 |
|
1381 | 1188 | # utility method to step advance an adjustment |
1382 | 1189 | def step_adjustment(adj, delta): |
|
0 commit comments