From b7abc94fdb8a2a61c3033073881461eae385f9c3 Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Wed, 11 Jun 2008 17:37:54 +0200 Subject: [PATCH] gitstats: Made GitStats compatible with the latest version of git-python The most significant changes are that by default the trailing newline is removed. Also, the module name was changed from 'git-python' to just 'git'. --- src/git_stats/author.py | 2 +- src/git_stats/branch.py | 5 ++--- src/git_stats/commit.py | 20 +++++++++----------- src/git_stats/diff.py | 2 +- src/git_stats/index.py | 2 +- src/scripts/setupRepo.py | 4 ++-- src/stats.py | 2 +- 7 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/git_stats/author.py b/src/git_stats/author.py index 70f94ff..0d798b7 100644 --- a/src/git_stats/author.py +++ b/src/git_stats/author.py @@ -4,7 +4,7 @@ import os import sys from optparse import OptionParser -from git_python import Git +from git import Git from git_stats import commit diff --git a/src/git_stats/branch.py b/src/git_stats/branch.py index 10e58c7..b8887bc 100644 --- a/src/git_stats/branch.py +++ b/src/git_stats/branch.py @@ -4,7 +4,7 @@ import os import sys from optparse import OptionParser -from git_python import Git +from git import Git from git_stats import commit @@ -46,9 +46,8 @@ def branchList(commitFilter, includeRemotes=False): args.append(commitFilter) result = git.branch(*args) + branches = result.split('\n') - # cut off the last newline - branches = branches[:-1] result = [] diff --git a/src/git_stats/commit.py b/src/git_stats/commit.py index 968f553..3f9e772 100644 --- a/src/git_stats/commit.py +++ b/src/git_stats/commit.py @@ -6,7 +6,7 @@ import sys import re from optparse import OptionParser, Option, OptionValueError -from git_python import Git +from git import Git def _logContains(log, regexp): """Traverses the specified log and searches for the specified regexp. @@ -36,8 +36,7 @@ def check_commit(option, opt, value): if not rev: raise OptionValueError("Unknown commit '" + value + "'") - # Kick off the trailing newline - return rev[:-1] + return rev class CommitOption(Option): """This parser understands a new type, "commit" @@ -53,7 +52,8 @@ def prettyPrint(commits): git = Git(".") for commit in commits: - result = git.log("-1", "--name-only", commit) + # Enable raw output for the trailing newline, which is desired in this case + result = git.log("-1", "--name-only", commit, with_raw_output=True) print(result) def _makePathsRelative(paths): @@ -72,8 +72,7 @@ def _makePathsRelative(paths): # Get our 'distance' to the top prefix = git.rev_parse("--show-cdup") - # Cut of the trailing newline - prefix = prefix[:-1] + prefix = prefix # Make it relative for path in paths: @@ -93,7 +92,9 @@ def pathsTouchedBy(commit, ignoreAddedFiles): """ git = Git(".") - result = git.diff_tree("--name-status", "--no-commit-id", "-r", commit) + + # Enable raw output, we use the last empty line as delimitor + result = git.diff_tree("--name-status", "--no-commit-id", "-r", commit, with_raw_output=True) log = result.split('\n') @@ -136,8 +137,7 @@ def commitsThatTouched(paths, relative=False): touched = result.split('\n') - # Don't return the trailing empty one - return touched[:-1] + return touched def commitTouched(commit): """Shows what commit touched the same files as the specified commit. @@ -197,8 +197,6 @@ def commitList(logFilter=None, diffFilter=None): result = git.rev_list("HEAD") commits = result.split('\n') - # Cut off the last newline - commits = commits[:-1] if not logFilter and not diffFilter: return commits diff --git a/src/git_stats/diff.py b/src/git_stats/diff.py index 91e63df..fc560c3 100644 --- a/src/git_stats/diff.py +++ b/src/git_stats/diff.py @@ -5,7 +5,7 @@ import os import sys from optparse import OptionParser -from git_python import Git +from git import Git from git_stats import commit diff --git a/src/git_stats/index.py b/src/git_stats/index.py index 681c5cf..5ccd21f 100644 --- a/src/git_stats/index.py +++ b/src/git_stats/index.py @@ -4,7 +4,7 @@ import os import sys from optparse import OptionParser -from git_python import Git +from git import Git from git_stats import commit diff --git a/src/scripts/setupRepo.py b/src/scripts/setupRepo.py index 152df08..b614e5a 100755 --- a/src/scripts/setupRepo.py +++ b/src/scripts/setupRepo.py @@ -3,8 +3,8 @@ import os import tempfile -from git_python import Repo -from git_python import Git +from git import Repo +from git import Git repopath = os.path.join(tempfile.gettempdir(), "freshrepo") diff --git a/src/stats.py b/src/stats.py index 22cef25..e0507d2 100755 --- a/src/stats.py +++ b/src/stats.py @@ -17,7 +17,7 @@ dir = os.path.dirname(path) os.sys.path.insert(0, dir) -from git_python import Git +from git import Git from git_stats import author from git_stats import branch -- 2.11.4.GIT