mirror of
https://github.com/ejwa/gitinspector.git
synced 2024-09-27 18:01:30 +02: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
9
blame.py
9
blame.py
@ -91,13 +91,14 @@ class Blame:
|
|||||||
lines = ls_tree_r.readlines()
|
lines = ls_tree_r.readlines()
|
||||||
|
|
||||||
for i, row in enumerate(lines):
|
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 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 "") + \
|
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 = BlameThread(blame_string, FileDiff.get_extension(row), self.blames, row.strip())
|
||||||
thread.daemon = True
|
thread.daemon = True
|
||||||
thread.start()
|
thread.start()
|
||||||
|
14
changes.py
14
changes.py
@ -23,7 +23,6 @@ import codecs
|
|||||||
import extensions
|
import extensions
|
||||||
import filtering
|
import filtering
|
||||||
import interval
|
import interval
|
||||||
import re
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import terminal
|
import terminal
|
||||||
@ -45,18 +44,12 @@ class FileDiff:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_extension(string):
|
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 = string.split("|")[0].strip().strip("{}").strip("\"").strip("'")
|
||||||
string = codecs.getdecoder('unicode_escape')(string.strip())[0]
|
|
||||||
return os.path.splitext(string)[1][1:]
|
return os.path.splitext(string)[1][1:]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_filename(string):
|
def get_filename(string):
|
||||||
string = string.encode("utf-8", "replace")
|
return string.split("|")[0].strip().strip("{}").strip("\"").strip("'")
|
||||||
string = string.decode("utf-8", "replace")
|
|
||||||
string = string.split("|")[0].strip().strip("{}").strip("\"").strip("'")
|
|
||||||
return codecs.getdecoder('unicode_escape')(string.strip())[0]
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_valid_extension(string):
|
def is_valid_extension(string):
|
||||||
@ -75,7 +68,7 @@ class Commit:
|
|||||||
if commit_line.__len__() == 4:
|
if commit_line.__len__() == 4:
|
||||||
self.date = commit_line[0]
|
self.date = commit_line[0]
|
||||||
self.sha = commit_line[1]
|
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()
|
self.message = commit_line[3].strip()
|
||||||
|
|
||||||
def add_filediff(self, filediff):
|
def add_filediff(self, filediff):
|
||||||
@ -105,7 +98,10 @@ class Changes:
|
|||||||
lines = git_log_r.readlines()
|
lines = git_log_r.readlines()
|
||||||
|
|
||||||
for i in lines:
|
for i in lines:
|
||||||
|
i = codecs.getdecoder("unicode_escape")(i.strip())[0]
|
||||||
|
i = i.encode("latin-1", "replace")
|
||||||
i = i.decode("utf-8", "replace")
|
i = i.decode("utf-8", "replace")
|
||||||
|
|
||||||
if Commit.is_commit_line(i) or i == lines[-1]:
|
if Commit.is_commit_line(i) or i == lines[-1]:
|
||||||
if found_valid_extension:
|
if found_valid_extension:
|
||||||
self.commits.append(commit)
|
self.commits.append(commit)
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from outputable import Outputable
|
from outputable import Outputable
|
||||||
from changes import FileDiff
|
from changes import FileDiff
|
||||||
|
import codecs
|
||||||
import comment
|
import comment
|
||||||
import filtering
|
import filtering
|
||||||
import missing
|
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
|
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():
|
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 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")
|
file_r = open(i.strip(), "rb")
|
||||||
extension = FileDiff.get_extension(i)
|
extension = FileDiff.get_extension(i)
|
||||||
lines = MetricsLogic.get_eloc(file_r, extension)
|
lines = MetricsLogic.get_eloc(file_r, extension)
|
||||||
|
Loading…
Reference in New Issue
Block a user