xref: /OpenGrok/tools/src/main/python/opengrok_tools/scm/repofactory.py (revision ae5b3cb81c9e71cf489cd9e38e66f063f1180c30)
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# See LICENSE.txt included in this distribution for the specific
9# language governing permissions and limitations under the License.
10#
11# When distributing Covered Code, include this CDDL HEADER in each
12# file and include the License file at LICENSE.txt.
13# If applicable, add the following below this CDDL HEADER, with the
14# fields enclosed by brackets "[]" replaced with your own identifying
15# information: Portions Copyright [yyyy] [name of copyright owner]
16#
17# CDDL HEADER END
18#
19
20#
21# Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
22#
23# Portions Copyright 2020 Robert Williams
24
25import logging
26
27from .cvs import CVSRepository
28from .git import GitRepository
29from .mercurial import MercurialRepository
30from .perforce import PerforceRepository
31from .repo import RepoRepository
32from .svn import SubversionRepository
33from .teamware import TeamwareRepository
34
35
36def get_repository(path, repo_type, project,
37                   commands=None, env=None, hooks=None, timeout=None):
38    """
39    :param path: full path for the working directory
40    :param repo_type: repository type name
41    :param project: project name
42    :param commands: commands dictionary with paths to SCM utilities
43    :param env: environment variables dictionary
44    :param hooks: hook dictionary
45    :param timeout: timeout in seconds
46    :return: a Repository derived object according to the type specified
47    or None if given repository type cannot be found.
48    """
49
50    logger = logging.getLogger(__name__)
51
52    repo_lower = repo_type.lower()
53
54    logger.debug("Constructing repository object of type '{}' for path '{}'".
55                 format(repo_type, path))
56
57    if not commands:
58        commands = {}
59
60    if repo_lower in ["mercurial", "hg"]:
61        return MercurialRepository(repo_type, logger, path, project,
62                                   commands.get("hg"),
63                                   env, hooks, timeout)
64    elif repo_lower in ["teamware", "sccs"]:
65        return TeamwareRepository(repo_type, logger, path, project,
66                                  commands.get("teamware"),
67                                  env, hooks, timeout)
68    elif repo_lower == "cvs":
69        return CVSRepository(repo_type, logger, path, project,
70                             commands.get("cvs"),
71                             env, hooks, timeout)
72    elif repo_lower in ["svn", "subversion"]:
73        return SubversionRepository(repo_type, logger, path, project,
74                                    commands.get("svn"),
75                                    env, hooks, timeout)
76    elif repo_lower == "git":
77        return GitRepository(repo_type, logger, path, project,
78                             commands.get("git"),
79                             env, hooks, timeout)
80    elif repo_lower == "perforce":
81        return PerforceRepository(repo_type, logger, path, project,
82                                  commands.get("perforce"),
83                                  env, hooks, timeout)
84    elif repo_lower == "repo":
85        return RepoRepository(repo_type, logger, path, project,
86                              commands.get("repo"),
87                              env, hooks, timeout)
88    else:
89        logger.warning("Unsupported repository type {}: {}".
90                       format(repo_type, path))
91        return None
92