From 109a94e1e7d00ce74ff332bd1a84b8255c593b00 Mon Sep 17 00:00:00 2001 From: Adam Waldenberg Date: Fri, 30 Oct 2015 23:29:03 +0100 Subject: [PATCH] The basedir module is no longer persistent (doesn't remember state). This is required in order for it to be callable multiple times for multiple repositories (Needed for #24). --- gitinspector/basedir.py | 41 +++++++++++++++++------------------- gitinspector/format.py | 10 ++++----- gitinspector/gitinspector.py | 2 +- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/gitinspector/basedir.py b/gitinspector/basedir.py index 4262afa..e68e143 100644 --- a/gitinspector/basedir.py +++ b/gitinspector/basedir.py @@ -27,31 +27,28 @@ def get_basedir(): else: return os.path.dirname(os.path.realpath(__file__)) -__git_basedir__ = None - def get_basedir_git(): - global __git_basedir__ + bare_command = subprocess.Popen(["git", "rev-parse", "--is-bare-repository"], bufsize=1, + stdout=subprocess.PIPE, stderr=open(os.devnull, "w")) - if not __git_basedir__: - bare_command = subprocess.Popen(["git", "rev-parse", "--is-bare-repository"], bufsize=1, - stdout=subprocess.PIPE, stderr=open(os.devnull, "w")) - isbare = bare_command.stdout.readlines() - bare_command.wait() - if bare_command.returncode != 0: - sys.exit(_("Error processing git repository at \"%s\"." % os.getcwd())) - isbare = (isbare[0].decode("utf-8", "replace").strip() == "true") - absolute_path = None + isbare = bare_command.stdout.readlines() + bare_command.wait() - if isbare: - absolute_path = subprocess.Popen(["git", "rev-parse", "--git-dir"], bufsize=1, stdout=subprocess.PIPE).stdout - else: - absolute_path = subprocess.Popen(["git", "rev-parse", "--show-toplevel"], bufsize=1, - stdout=subprocess.PIPE).stdout + if bare_command.returncode != 0: + sys.exit(_("Error processing git repository at \"%s\"." % os.getcwd())) - absolute_path = absolute_path.readlines() - if len(absolute_path) == 0: - sys.exit(_("Unable to determine absolute path of git repository.")) + isbare = (isbare[0].decode("utf-8", "replace").strip() == "true") + absolute_path = None - __git_basedir__ = absolute_path[0].decode("utf-8", "replace").strip() + if isbare: + absolute_path = subprocess.Popen(["git", "rev-parse", "--git-dir"], bufsize=1, stdout=subprocess.PIPE).stdout + else: + absolute_path = subprocess.Popen(["git", "rev-parse", "--show-toplevel"], bufsize=1, + stdout=subprocess.PIPE).stdout - return __git_basedir__ + absolute_path = absolute_path.readlines() + + if len(absolute_path) == 0: + sys.exit(_("Unable to determine absolute path of git repository.")) + + return absolute_path[0].decode("utf-8", "replace").strip() diff --git a/gitinspector/format.py b/gitinspector/format.py index bc2c84e..b4f2a5a 100644 --- a/gitinspector/format.py +++ b/gitinspector/format.py @@ -59,7 +59,7 @@ def __get_zip_file_content__(name, file_name="/html/flot.zip"): zip_file.close() return content.decode("utf-8", "replace") -def output_header(): +def output_header(repo): if __selected_format__ == "html" or __selected_format__ == "htmlembedded": base = basedir.get_basedir() html_header = __output_html_template__(base + "/html/html.header") @@ -80,7 +80,7 @@ def output_header(): else: jquery_js = " src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js\">" - print(html_header.format(title=_("Repository statistics for {0}").format(os.path.basename(basedir.get_basedir_git())), + print(html_header.format(title=_("Repository statistics for {0}").format(os.path.basename(repo)), jquery=jquery_js, jquery_tablesorter=tablesorter_js, jquery_flot=flot_js, @@ -92,7 +92,7 @@ def output_header(): "gitinspector", version.__version__), repo_text=_("Statistical information for the repository '{0}' was gathered on {1}.").format( - os.path.basename(basedir. get_basedir_git()), localization.get_date()), + os.path.basename(repo), localization.get_date()), show_minor_authors=_("Show minor authors"), hide_minor_authors=_("Hide minor authors"), show_minor_rows=_("Show rows with minor work"), @@ -102,11 +102,11 @@ def output_header(): elif __selected_format__ == "xml": print("") print("\t" + version.__version__ + "") - print("\t" + os.path.basename(basedir. get_basedir_git()) + "") + print("\t" + os.path.basename(repo) + "") print("\t" + time.strftime("%Y/%m/%d") + "") else: print(textwrap.fill(_("Statistical information for the repository '{0}' was gathered on {1}.").format( - os.path.basename(basedir.get_basedir_git()), localization.get_date()), width=terminal.get_size()[0])) + os.path.basename(repo), localization.get_date()), width=terminal.get_size()[0])) def output_footer(): if __selected_format__ == "html" or __selected_format__ == "htmlembedded": diff --git a/gitinspector/gitinspector.py b/gitinspector/gitinspector.py index 29260fe..cae0120 100644 --- a/gitinspector/gitinspector.py +++ b/gitinspector/gitinspector.py @@ -63,8 +63,8 @@ class Runner(object): os.chdir(self.repo) absolute_path = basedir.get_basedir_git() os.chdir(absolute_path) - format.output_header() + format.output_header(absolute_path) changes = Changes(self.hard) outputable.output(ChangesOutput(changes))