From d8f19f1152b35b9a9b5ea83b2feb5028bc281334 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 22 2014 10:48:09 +0000 Subject: Move the function __get_file_in_tree at the top level of the progit module --- diff --git a/progit/__init__.py b/progit/__init__.py index a05ecb1..9c77608 100644 --- a/progit/__init__.py +++ b/progit/__init__.py @@ -20,6 +20,7 @@ from logging.handlers import SMTPHandler import arrow import flask +import pygit2 from flask_fas_openid import FAS from functools import wraps from sqlalchemy.exc import SQLAlchemyError @@ -164,6 +165,22 @@ def auth_logout(): flask.flash('You have been logged out') return flask.redirect(flask.url_for('index')) + +def __get_file_in_tree(repo_obj, tree, filepath): + ''' Retrieve the entry corresponding to the provided filename in a + given tree. + ''' + filename = filepath[0] + if isinstance(tree, pygit2.Blob): + return + for el in tree: + if el.name == filename: + if len(filepath) == 1: + return repo_obj[el.oid] + else: + return __get_file_in_tree( + repo_obj, repo_obj[el.oid], filepath[1:]) + ## Import the application import progit.app diff --git a/progit/app.py b/progit/app.py index 3798627..e401ee8 100644 --- a/progit/app.py +++ b/progit/app.py @@ -23,7 +23,7 @@ from pygments.formatters import HtmlFormatter import progit.exceptions import progit.lib import progit.forms -from progit import APP, SESSION, LOG +from progit import APP, SESSION, LOG, __get_file_in_tree ### Application @@ -335,21 +335,7 @@ def view_file(repo, identifier, filename): commit = repo_obj[repo_obj.head.target] branchname = 'master' - def __get_file_in_tree(tree, filepath): - ''' Retrieve the entry corresponding to the provided filename in a - given tree. - ''' - filename = filepath[0] - if isinstance(tree, pygit2.Blob): - return - for el in tree: - if el.name == filename: - if len(filepath) == 1: - return repo_obj[el.oid] - else: - return __get_file_in_tree(repo_obj[el.oid], filepath[1:]) - - content = __get_file_in_tree(commit.tree, filename.split('/')) + content = __get_file_in_tree(repo_obj, commit.tree, filename.split('/')) if not content: flask.abort(404, 'File not found')