From 14174ee798296b328217da9493075b81eca4fb42 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 20 2018 15:20:09 +0000 Subject: Move _get_parent_repo_path to pagure.utils as get_parent_repo_path Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py index 63a112f..65d92d8 100644 --- a/pagure/ui/fork.py +++ b/pagure/ui/fork.py @@ -33,24 +33,13 @@ import pagure.lib.tasks import pagure.forms from pagure.config import config as pagure_config from pagure.ui import UI_NS -from pagure.utils import login_required, __get_file_in_tree +from pagure.utils import ( + login_required, __get_file_in_tree, get_parent_repo_path) _log = logging.getLogger(__name__) -def _get_parent_repo_path(repo): - """ Return the path of the parent git repository corresponding to the - provided Repository object from the DB. - """ - if repo.parent: - parentpath = os.path.join( - pagure_config['GIT_FOLDER'], repo.parent.path) - else: - parentpath = os.path.join(pagure_config['GIT_FOLDER'], repo.path) - - return parentpath - def _get_parent_request_repo_path(repo): """ Return the path of the parent git repository corresponding to the @@ -326,7 +315,7 @@ def request_pull_to_diff_or_patch( else: repo_from = request.project_from repopath = pagure.utils.get_repo_path(repo_from) - parentpath = _get_parent_repo_path(repo_from) + parentpath = get_parent_repo_path(repo_from) repo_obj = pygit2.Repository(repopath) orig_repo = pygit2.Repository(parentpath) @@ -1105,7 +1094,7 @@ def new_request_pull( repo_obj = flask.g.repo_obj if not project_to: - parentpath = _get_parent_repo_path(repo) + parentpath = get_parent_repo_path(repo) orig_repo = pygit2.Repository(parentpath) else: p_namespace = None diff --git a/pagure/utils.py b/pagure/utils.py index 0a82058..0808ecd 100644 --- a/pagure/utils.py +++ b/pagure/utils.py @@ -357,3 +357,16 @@ def split_project_fullname(project_name): _, user, namespace, project_name = project_items return (user, namespace, project_name) + + +def get_parent_repo_path(repo): + """ Return the path of the parent git repository corresponding to the + provided Repository object from the DB. + """ + if repo.parent: + parentpath = os.path.join( + pagure_config['GIT_FOLDER'], repo.parent.path) + else: + parentpath = os.path.join(pagure_config['GIT_FOLDER'], repo.path) + + return parentpath