mirror of
https://github.com/ejwa/gitinspector.git
synced 2024-11-16 00:28:25 +01:00
Fixed the decoding of strings (Fixes issue 2).
It should now (hopefully) behave the same in all Python versions 2.6+.
This commit is contained in:
parent
c6771c0b9f
commit
cf40f16119
3 changed files with 16 additions and 15 deletions
9
blame.py
9
blame.py
|
@ -91,13 +91,14 @@ class Blame:
|
|||
lines = ls_tree_r.readlines()
|
||||
|
||||
for i, row in enumerate(lines):
|
||||
row = row.decode("utf-8", "replace").strip().strip("\"").strip("'")
|
||||
row = codecs.getdecoder('unicode_escape')(row.strip())[0]
|
||||
row = codecs.getdecoder("unicode_escape")(row.strip())[0]
|
||||
row = row.encode("latin-1", "replace")
|
||||
row = row.decode("utf-8", "replace").strip("\"").strip("'").strip()
|
||||
|
||||
if FileDiff.is_valid_extension(row) and not filtering.set_filtered(FileDiff.get_filename(row)):
|
||||
if not missing.add(row.strip()):
|
||||
if not missing.add(row):
|
||||
blame_string = "git blame -w {0} ".format("-C -C -M" if hard else "") + \
|
||||
interval.get_since() + interval.get_ref() + " -- \"" + row.strip() + "\""
|
||||
interval.get_since() + interval.get_ref() + " -- \"" + row + "\""
|
||||
thread = BlameThread(blame_string, FileDiff.get_extension(row), self.blames, row.strip())
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
|
|
14
changes.py
14
changes.py
|
@ -23,7 +23,6 @@ import codecs
|
|||
import extensions
|
||||
import filtering
|
||||
import interval
|
||||
import re
|
||||
import os
|
||||
import subprocess
|
||||
import terminal
|
||||
|
@ -45,18 +44,12 @@ class FileDiff:
|
|||
|
||||
@staticmethod
|
||||
def get_extension(string):
|
||||
string = string.encode("utf-8", "replace")
|
||||
string = string.decode("utf-8", "replace")
|
||||
string = string.split("|")[0].strip().strip("{}").strip("\"").strip("'")
|
||||
string = codecs.getdecoder('unicode_escape')(string.strip())[0]
|
||||
return os.path.splitext(string)[1][1:]
|
||||
|
||||
@staticmethod
|
||||
def get_filename(string):
|
||||
string = string.encode("utf-8", "replace")
|
||||
string = string.decode("utf-8", "replace")
|
||||
string = string.split("|")[0].strip().strip("{}").strip("\"").strip("'")
|
||||
return codecs.getdecoder('unicode_escape')(string.strip())[0]
|
||||
return string.split("|")[0].strip().strip("{}").strip("\"").strip("'")
|
||||
|
||||
@staticmethod
|
||||
def is_valid_extension(string):
|
||||
|
@ -75,7 +68,7 @@ class Commit:
|
|||
if commit_line.__len__() == 4:
|
||||
self.date = commit_line[0]
|
||||
self.sha = commit_line[1]
|
||||
self.author = re.sub("[^\w ]", "", commit_line[2].strip())
|
||||
self.author = commit_line[2].strip()
|
||||
self.message = commit_line[3].strip()
|
||||
|
||||
def add_filediff(self, filediff):
|
||||
|
@ -105,7 +98,10 @@ class Changes:
|
|||
lines = git_log_r.readlines()
|
||||
|
||||
for i in lines:
|
||||
i = codecs.getdecoder("unicode_escape")(i.strip())[0]
|
||||
i = i.encode("latin-1", "replace")
|
||||
i = i.decode("utf-8", "replace")
|
||||
|
||||
if Commit.is_commit_line(i) or i == lines[-1]:
|
||||
if found_valid_extension:
|
||||
self.commits.append(commit)
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
from __future__ import print_function
|
||||
from outputable import Outputable
|
||||
from changes import FileDiff
|
||||
import codecs
|
||||
import comment
|
||||
import filtering
|
||||
import missing
|
||||
|
@ -34,9 +35,12 @@ class MetricsLogic:
|
|||
ls_tree_r = subprocess.Popen("git ls-tree --name-only -r HEAD", shell=True, bufsize=1, stdout=subprocess.PIPE).stdout
|
||||
|
||||
for i in ls_tree_r.readlines():
|
||||
i = i.decode("utf-8", "replace")
|
||||
i = codecs.getdecoder("unicode_escape")(i.strip())[0]
|
||||
i = i.encode("latin-1", "replace")
|
||||
i = i.decode("utf-8", "replace").strip("\"").strip("'").strip()
|
||||
|
||||
if FileDiff.is_valid_extension(i) and not filtering.set_filtered(FileDiff.get_filename(i)):
|
||||
if not missing.add(i.strip()):
|
||||
if not missing.add(i):
|
||||
file_r = open(i.strip(), "rb")
|
||||
extension = FileDiff.get_extension(i)
|
||||
lines = MetricsLogic.get_eloc(file_r, extension)
|
||||
|
|
Loading…
Reference in a new issue