xref: /OpenGrok/tools/src/main/python/opengrok_tools/scm/repofactory.py (revision ae5b3cb81c9e71cf489cd9e38e66f063f1180c30)
12d57dc69SVladimir Kotal#
22d57dc69SVladimir Kotal# CDDL HEADER START
32d57dc69SVladimir Kotal#
42d57dc69SVladimir Kotal# The contents of this file are subject to the terms of the
52d57dc69SVladimir Kotal# Common Development and Distribution License (the "License").
62d57dc69SVladimir Kotal# You may not use this file except in compliance with the License.
72d57dc69SVladimir Kotal#
82d57dc69SVladimir Kotal# See LICENSE.txt included in this distribution for the specific
92d57dc69SVladimir Kotal# language governing permissions and limitations under the License.
102d57dc69SVladimir Kotal#
112d57dc69SVladimir Kotal# When distributing Covered Code, include this CDDL HEADER in each
122d57dc69SVladimir Kotal# file and include the License file at LICENSE.txt.
132d57dc69SVladimir Kotal# If applicable, add the following below this CDDL HEADER, with the
142d57dc69SVladimir Kotal# fields enclosed by brackets "[]" replaced with your own identifying
152d57dc69SVladimir Kotal# information: Portions Copyright [yyyy] [name of copyright owner]
162d57dc69SVladimir Kotal#
172d57dc69SVladimir Kotal# CDDL HEADER END
182d57dc69SVladimir Kotal#
192d57dc69SVladimir Kotal
202d57dc69SVladimir Kotal#
21009ba170SVladimir Kotal# Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
222d57dc69SVladimir Kotal#
232d57dc69SVladimir Kotal# Portions Copyright 2020 Robert Williams
242d57dc69SVladimir Kotal
252d57dc69SVladimir Kotalimport logging
262d57dc69SVladimir Kotal
272d57dc69SVladimir Kotalfrom .cvs import CVSRepository
282d57dc69SVladimir Kotalfrom .git import GitRepository
292d57dc69SVladimir Kotalfrom .mercurial import MercurialRepository
302d57dc69SVladimir Kotalfrom .perforce import PerforceRepository
312d57dc69SVladimir Kotalfrom .repo import RepoRepository
322d57dc69SVladimir Kotalfrom .svn import SubversionRepository
332d57dc69SVladimir Kotalfrom .teamware import TeamwareRepository
342d57dc69SVladimir Kotal
35009ba170SVladimir Kotal
362d57dc69SVladimir Kotaldef get_repository(path, repo_type, project,
372d57dc69SVladimir Kotal                   commands=None, env=None, hooks=None, timeout=None):
382d57dc69SVladimir Kotal    """
39*ae5b3cb8SVladimir Kotal    :param path: full path for the working directory
40*ae5b3cb8SVladimir Kotal    :param repo_type: repository type name
412d57dc69SVladimir Kotal    :param project: project name
422d57dc69SVladimir Kotal    :param commands: commands dictionary with paths to SCM utilities
432d57dc69SVladimir Kotal    :param env: environment variables dictionary
442d57dc69SVladimir Kotal    :param hooks: hook dictionary
452d57dc69SVladimir Kotal    :param timeout: timeout in seconds
462d57dc69SVladimir Kotal    :return: a Repository derived object according to the type specified
472d57dc69SVladimir Kotal    or None if given repository type cannot be found.
482d57dc69SVladimir Kotal    """
492d57dc69SVladimir Kotal
50009ba170SVladimir Kotal    logger = logging.getLogger(__name__)
51009ba170SVladimir Kotal
522d57dc69SVladimir Kotal    repo_lower = repo_type.lower()
532d57dc69SVladimir Kotal
54*ae5b3cb8SVladimir Kotal    logger.debug("Constructing repository object of type '{}' for path '{}'".
55*ae5b3cb8SVladimir Kotal                 format(repo_type, path))
562d57dc69SVladimir Kotal
572d57dc69SVladimir Kotal    if not commands:
582d57dc69SVladimir Kotal        commands = {}
592d57dc69SVladimir Kotal
602d57dc69SVladimir Kotal    if repo_lower in ["mercurial", "hg"]:
61*ae5b3cb8SVladimir Kotal        return MercurialRepository(repo_type, logger, path, project,
622d57dc69SVladimir Kotal                                   commands.get("hg"),
632d57dc69SVladimir Kotal                                   env, hooks, timeout)
642d57dc69SVladimir Kotal    elif repo_lower in ["teamware", "sccs"]:
65*ae5b3cb8SVladimir Kotal        return TeamwareRepository(repo_type, logger, path, project,
662d57dc69SVladimir Kotal                                  commands.get("teamware"),
672d57dc69SVladimir Kotal                                  env, hooks, timeout)
682d57dc69SVladimir Kotal    elif repo_lower == "cvs":
69*ae5b3cb8SVladimir Kotal        return CVSRepository(repo_type, logger, path, project,
702d57dc69SVladimir Kotal                             commands.get("cvs"),
712d57dc69SVladimir Kotal                             env, hooks, timeout)
722d57dc69SVladimir Kotal    elif repo_lower in ["svn", "subversion"]:
73*ae5b3cb8SVladimir Kotal        return SubversionRepository(repo_type, logger, path, project,
742d57dc69SVladimir Kotal                                    commands.get("svn"),
752d57dc69SVladimir Kotal                                    env, hooks, timeout)
762d57dc69SVladimir Kotal    elif repo_lower == "git":
77*ae5b3cb8SVladimir Kotal        return GitRepository(repo_type, logger, path, project,
782d57dc69SVladimir Kotal                             commands.get("git"),
792d57dc69SVladimir Kotal                             env, hooks, timeout)
802d57dc69SVladimir Kotal    elif repo_lower == "perforce":
81*ae5b3cb8SVladimir Kotal        return PerforceRepository(repo_type, logger, path, project,
822d57dc69SVladimir Kotal                                  commands.get("perforce"),
832d57dc69SVladimir Kotal                                  env, hooks, timeout)
842d57dc69SVladimir Kotal    elif repo_lower == "repo":
85*ae5b3cb8SVladimir Kotal        return RepoRepository(repo_type, logger, path, project,
862d57dc69SVladimir Kotal                              commands.get("repo"),
872d57dc69SVladimir Kotal                              env, hooks, timeout)
882d57dc69SVladimir Kotal    else:
892d57dc69SVladimir Kotal        logger.warning("Unsupported repository type {}: {}".
902d57dc69SVladimir Kotal                       format(repo_type, path))
912d57dc69SVladimir Kotal        return None
92