From 6e538ffaa71f59cfb86b99dacf8c0afbb0ed15af Mon Sep 17 00:00:00 2001 From: Chuck Durfee Date: Mon, 17 Apr 2017 10:40:47 -0600 Subject: [PATCH 1/5] add Groovy support, copying Java syntax --- gitinspector/comment.py | 6 +++--- gitinspector/metrics.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gitinspector/comment.py b/gitinspector/comment.py index 2df26d1..02ec7e2 100644 --- a/gitinspector/comment.py +++ b/gitinspector/comment.py @@ -22,17 +22,17 @@ __comment_begining__ = {"java": "/*", "c": "/*", "cc": "/*", "cpp": "/*", "cs": "/*", "h": "/*", "hh": "/*", "hpp": "/*", "hs": "{-", "html": "", "php": "/*", "py": "\"\"\"", "glsl": "*/", "rb": "=end", "js": "*/", "jspx": "-->", "scala": "*/", "sql": "*/", "tex": "\\end{comment}", "xhtml": "-->", "xml": "-->", "ml": "*)", "mli": "*)", - "go": "*/", "ly": "%}", "ily": "%}"} + "go": "*/", "ly": "%}", "ily": "%}", "groovy": "*/"} __comment__ = {"java": "//", "c": "//", "cc": "//", "cpp": "//", "cs": "//", "h": "//", "hh": "//", "hpp": "//", "hs": "--", "pl": "#", "php": "//", "py": "#", "glsl": "//", "rb": "#", "robot": "#", "rs": "//", "rlib": "//", "js": "//", "scala": "//", "sql": "--", "tex": "%", "ada": "--", "ads": "--", "adb": "--", "pot": "#", "po": "#", "go": "//", - "ly": "%", "ily": "%"} + "ly": "%", "ily": "%", "groovy": "//"} __comment_markers_must_be_at_begining__ = {"tex": True} diff --git a/gitinspector/metrics.py b/gitinspector/metrics.py index d4aeead..a404bdc 100644 --- a/gitinspector/metrics.py +++ b/gitinspector/metrics.py @@ -24,9 +24,9 @@ from . import comment, filtering, interval __metric_eloc__ = {"java": 500, "c": 500, "cpp": 500, "cs": 500, "h": 300, "hpp": 300, "php": 500, "py": 500, "glsl": 1000, - "rb": 500, "js": 500, "sql": 1000, "xml": 1000} + "rb": 500, "js": 500, "sql": 1000, "xml": 1000, "groovy": 500} -__metric_cc_tokens__ = [[["java", "js", "c", "cc", "cpp"], ["else", r"for\s+\(.*\)", r"if\s+\(.*\)", r"case\s+\w+:", +__metric_cc_tokens__ = [[["java", "js", "c", "cc", "cpp","groovy"], ["else", r"for\s+\(.*\)", r"if\s+\(.*\)", r"case\s+\w+:", "default:", r"while\s+\(.*\)"], ["assert", "break", "continue", "return"]], [["cs"], ["else", r"for\s+\(.*\)", r"foreach\s+\(.*\)", r"goto\s+\w+:", r"if\s+\(.*\)", r"case\s+\w+:", From a723313691e008c2aa3f623d1ce6865667a7eb2a Mon Sep 17 00:00:00 2001 From: Chuck Durfee Date: Tue, 18 Apr 2017 12:34:45 -0600 Subject: [PATCH 2/5] guard against exceptions when commits is None due to extension filtering --- gitinspector/changes.py | 44 ++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/gitinspector/changes.py b/gitinspector/changes.py index 7816c08..2122e02 100644 --- a/gitinspector/changes.py +++ b/gitinspector/changes.py @@ -160,9 +160,10 @@ def run(self): filtering.set_filtered(commit.sha, "message")): is_filtered = True - if FileDiff.is_filediff_line(j) and not \ - filtering.set_filtered(FileDiff.get_filename(j)) and not is_filtered: - extensions.add_located(FileDiff.get_extension(j)) + if commit is not None: + if FileDiff.is_filediff_line(j) and not \ + filtering.set_filtered(FileDiff.get_filename(j)) and not is_filtered: + extensions.add_located(FileDiff.get_extension(j)) if FileDiff.is_valid_extension(j): found_valid_extension = True @@ -198,18 +199,14 @@ def __init__(self, repo, hard): first_hash = "" for i, entry in enumerate(lines): + entry = entry.decode("utf-8", "replace").strip() + second_hash = entry + ChangesThread.create(hard, self, first_hash, second_hash, i) if i % CHANGES_PER_THREAD == CHANGES_PER_THREAD - 1: - entry = entry.decode("utf-8", "replace").strip() - second_hash = entry - ChangesThread.create(hard, self, first_hash, second_hash, i) first_hash = entry + ".." - if format.is_interactive_format(): terminal.output_progress(progress_text, i, len(lines)) - else: - entry = entry.decode("utf-8", "replace").strip() - second_hash = entry - ChangesThread.create(hard, self, first_hash, second_hash, i) + # Make sure all threads have completed. for i in range(0, NUM_THREADS): @@ -220,15 +217,22 @@ def __init__(self, repo, hard): __thread_lock__.release() self.commits = [item for sublist in self.commits for item in sublist] - - if len(self.commits) > 0: - if interval.has_interval() and len(self.commits) > 0: - interval.set_ref(self.commits[-1].sha) - - self.first_commit_date = datetime.date(int(self.commits[0].date[0:4]), int(self.commits[0].date[5:7]), - int(self.commits[0].date[8:10])) - self.last_commit_date = datetime.date(int(self.commits[-1].date[0:4]), int(self.commits[-1].date[5:7]), - int(self.commits[-1].date[8:10])) + flatten = lambda l: [item for sublist in l for item in sublist] + self.commits = [x for x in flatten(self.commits) if x is not None] + + if self.commits: + first = self.commits[0] + last = self.commits[-1] + + if first and last: + if interval.has_interval() and last: + interval.set_ref(last.sha) + self.first_commit_date = self.get_commit_date(first) + self.last_commit_date = self.get_commit_date(last) + + @classmethod + def get_commit_date(cls, commit): + return datetime.date(int(commit.date[0:4]), int(commit.date[5:7]), int(commit.date[8:10])) def __iadd__(self, other): try: From 6e0f2e8e6893bd87f45c6aa692f2c340094d952f Mon Sep 17 00:00:00 2001 From: Chuck Durfee Date: Tue, 18 Apr 2017 12:41:00 -0600 Subject: [PATCH 3/5] Revert "add Groovy support, copying Java syntax" This reverts commit 6e538ffaa71f59cfb86b99dacf8c0afbb0ed15af. --- gitinspector/comment.py | 6 +++--- gitinspector/metrics.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gitinspector/comment.py b/gitinspector/comment.py index 02ec7e2..2df26d1 100644 --- a/gitinspector/comment.py +++ b/gitinspector/comment.py @@ -22,17 +22,17 @@ __comment_begining__ = {"java": "/*", "c": "/*", "cc": "/*", "cpp": "/*", "cs": "/*", "h": "/*", "hh": "/*", "hpp": "/*", "hs": "{-", "html": "", "php": "/*", "py": "\"\"\"", "glsl": "*/", "rb": "=end", "js": "*/", "jspx": "-->", "scala": "*/", "sql": "*/", "tex": "\\end{comment}", "xhtml": "-->", "xml": "-->", "ml": "*)", "mli": "*)", - "go": "*/", "ly": "%}", "ily": "%}", "groovy": "*/"} + "go": "*/", "ly": "%}", "ily": "%}"} __comment__ = {"java": "//", "c": "//", "cc": "//", "cpp": "//", "cs": "//", "h": "//", "hh": "//", "hpp": "//", "hs": "--", "pl": "#", "php": "//", "py": "#", "glsl": "//", "rb": "#", "robot": "#", "rs": "//", "rlib": "//", "js": "//", "scala": "//", "sql": "--", "tex": "%", "ada": "--", "ads": "--", "adb": "--", "pot": "#", "po": "#", "go": "//", - "ly": "%", "ily": "%", "groovy": "//"} + "ly": "%", "ily": "%"} __comment_markers_must_be_at_begining__ = {"tex": True} diff --git a/gitinspector/metrics.py b/gitinspector/metrics.py index a404bdc..d4aeead 100644 --- a/gitinspector/metrics.py +++ b/gitinspector/metrics.py @@ -24,9 +24,9 @@ from . import comment, filtering, interval __metric_eloc__ = {"java": 500, "c": 500, "cpp": 500, "cs": 500, "h": 300, "hpp": 300, "php": 500, "py": 500, "glsl": 1000, - "rb": 500, "js": 500, "sql": 1000, "xml": 1000, "groovy": 500} + "rb": 500, "js": 500, "sql": 1000, "xml": 1000} -__metric_cc_tokens__ = [[["java", "js", "c", "cc", "cpp","groovy"], ["else", r"for\s+\(.*\)", r"if\s+\(.*\)", r"case\s+\w+:", +__metric_cc_tokens__ = [[["java", "js", "c", "cc", "cpp"], ["else", r"for\s+\(.*\)", r"if\s+\(.*\)", r"case\s+\w+:", "default:", r"while\s+\(.*\)"], ["assert", "break", "continue", "return"]], [["cs"], ["else", r"for\s+\(.*\)", r"foreach\s+\(.*\)", r"goto\s+\w+:", r"if\s+\(.*\)", r"case\s+\w+:", From e58bf96d1aedb0987c38b004ebc467c912a67d99 Mon Sep 17 00:00:00 2001 From: Chuck Durfee Date: Mon, 17 Apr 2017 10:40:47 -0600 Subject: [PATCH 4/5] add Groovy support, copying Java syntax --- gitinspector/comment.py | 6 +++--- gitinspector/metrics.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gitinspector/comment.py b/gitinspector/comment.py index 2df26d1..02ec7e2 100644 --- a/gitinspector/comment.py +++ b/gitinspector/comment.py @@ -22,17 +22,17 @@ __comment_begining__ = {"java": "/*", "c": "/*", "cc": "/*", "cpp": "/*", "cs": "/*", "h": "/*", "hh": "/*", "hpp": "/*", "hs": "{-", "html": "", "php": "/*", "py": "\"\"\"", "glsl": "*/", "rb": "=end", "js": "*/", "jspx": "-->", "scala": "*/", "sql": "*/", "tex": "\\end{comment}", "xhtml": "-->", "xml": "-->", "ml": "*)", "mli": "*)", - "go": "*/", "ly": "%}", "ily": "%}"} + "go": "*/", "ly": "%}", "ily": "%}", "groovy": "*/"} __comment__ = {"java": "//", "c": "//", "cc": "//", "cpp": "//", "cs": "//", "h": "//", "hh": "//", "hpp": "//", "hs": "--", "pl": "#", "php": "//", "py": "#", "glsl": "//", "rb": "#", "robot": "#", "rs": "//", "rlib": "//", "js": "//", "scala": "//", "sql": "--", "tex": "%", "ada": "--", "ads": "--", "adb": "--", "pot": "#", "po": "#", "go": "//", - "ly": "%", "ily": "%"} + "ly": "%", "ily": "%", "groovy": "//"} __comment_markers_must_be_at_begining__ = {"tex": True} diff --git a/gitinspector/metrics.py b/gitinspector/metrics.py index d4aeead..a404bdc 100644 --- a/gitinspector/metrics.py +++ b/gitinspector/metrics.py @@ -24,9 +24,9 @@ from . import comment, filtering, interval __metric_eloc__ = {"java": 500, "c": 500, "cpp": 500, "cs": 500, "h": 300, "hpp": 300, "php": 500, "py": 500, "glsl": 1000, - "rb": 500, "js": 500, "sql": 1000, "xml": 1000} + "rb": 500, "js": 500, "sql": 1000, "xml": 1000, "groovy": 500} -__metric_cc_tokens__ = [[["java", "js", "c", "cc", "cpp"], ["else", r"for\s+\(.*\)", r"if\s+\(.*\)", r"case\s+\w+:", +__metric_cc_tokens__ = [[["java", "js", "c", "cc", "cpp","groovy"], ["else", r"for\s+\(.*\)", r"if\s+\(.*\)", r"case\s+\w+:", "default:", r"while\s+\(.*\)"], ["assert", "break", "continue", "return"]], [["cs"], ["else", r"for\s+\(.*\)", r"foreach\s+\(.*\)", r"goto\s+\w+:", r"if\s+\(.*\)", r"case\s+\w+:", From 23801ce71925fa3591a7eeb5a9d2785fd0e66c90 Mon Sep 17 00:00:00 2001 From: Chuck Durfee Date: Tue, 18 Apr 2017 12:43:08 -0600 Subject: [PATCH 5/5] Revert "guard against exceptions when commits is None due to extension filtering" This reverts commit a723313691e008c2aa3f623d1ce6865667a7eb2a. --- gitinspector/changes.py | 44 +++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/gitinspector/changes.py b/gitinspector/changes.py index 2122e02..7816c08 100644 --- a/gitinspector/changes.py +++ b/gitinspector/changes.py @@ -160,10 +160,9 @@ def run(self): filtering.set_filtered(commit.sha, "message")): is_filtered = True - if commit is not None: - if FileDiff.is_filediff_line(j) and not \ - filtering.set_filtered(FileDiff.get_filename(j)) and not is_filtered: - extensions.add_located(FileDiff.get_extension(j)) + if FileDiff.is_filediff_line(j) and not \ + filtering.set_filtered(FileDiff.get_filename(j)) and not is_filtered: + extensions.add_located(FileDiff.get_extension(j)) if FileDiff.is_valid_extension(j): found_valid_extension = True @@ -199,14 +198,18 @@ def __init__(self, repo, hard): first_hash = "" for i, entry in enumerate(lines): - entry = entry.decode("utf-8", "replace").strip() - second_hash = entry - ChangesThread.create(hard, self, first_hash, second_hash, i) if i % CHANGES_PER_THREAD == CHANGES_PER_THREAD - 1: + entry = entry.decode("utf-8", "replace").strip() + second_hash = entry + ChangesThread.create(hard, self, first_hash, second_hash, i) first_hash = entry + ".." + if format.is_interactive_format(): terminal.output_progress(progress_text, i, len(lines)) - + else: + entry = entry.decode("utf-8", "replace").strip() + second_hash = entry + ChangesThread.create(hard, self, first_hash, second_hash, i) # Make sure all threads have completed. for i in range(0, NUM_THREADS): @@ -217,22 +220,15 @@ def __init__(self, repo, hard): __thread_lock__.release() self.commits = [item for sublist in self.commits for item in sublist] - flatten = lambda l: [item for sublist in l for item in sublist] - self.commits = [x for x in flatten(self.commits) if x is not None] - - if self.commits: - first = self.commits[0] - last = self.commits[-1] - - if first and last: - if interval.has_interval() and last: - interval.set_ref(last.sha) - self.first_commit_date = self.get_commit_date(first) - self.last_commit_date = self.get_commit_date(last) - - @classmethod - def get_commit_date(cls, commit): - return datetime.date(int(commit.date[0:4]), int(commit.date[5:7]), int(commit.date[8:10])) + + if len(self.commits) > 0: + if interval.has_interval() and len(self.commits) > 0: + interval.set_ref(self.commits[-1].sha) + + self.first_commit_date = datetime.date(int(self.commits[0].date[0:4]), int(self.commits[0].date[5:7]), + int(self.commits[0].date[8:10])) + self.last_commit_date = datetime.date(int(self.commits[-1].date[0:4]), int(self.commits[-1].date[5:7]), + int(self.commits[-1].date[8:10])) def __iadd__(self, other): try: