diff --git a/blame.py b/blame.py index 031dafd..a894bbf 100644 --- a/blame.py +++ b/blame.py @@ -48,14 +48,15 @@ class Blame: if self.blames.get(author, None) == None: self.blames[author] = BlameEntry() - if comment.has_comment_begining(FileDiff.get_extension(i), content): - is_inside_comment = True - - if comment.is_comment(FileDiff.get_extension(i), content) or is_inside_comment: + if comment.is_comment(FileDiff.get_extension(i), content): self.blames[author].comments += 1 - - if comment.has_comment_end(FileDiff.get_extension(i), content): - is_inside_comment = False + if is_inside_comment: + if comment.has_comment_end(FileDiff.get_extension(i), content): + is_inside_comment = False + else: + self.blames[author].comments += 1 + elif comment.has_comment_begining(FileDiff.get_extension(i), content): + is_inside_comment = True self.blames[author].rows += 1 diff --git a/comment.py b/comment.py index 009d3c1..e6b7554 100644 --- a/comment.py +++ b/comment.py @@ -27,9 +27,9 @@ __comment__ = {"java": "//", "c": "//", "cpp": "//", "h": "//", "hpp": "//", "py "rb": "#", "js": "//", "sql": "--"} def is_comment(extension, string): - if __comment_begining__.get(extension, None) != None and string.strip().startswith(__comment__[extension]): + if __comment_begining__.get(extension, None) != None and string.strip().startswith(__comment_begining__[extension]): return True - if __comment_end__.get(extension, None) != None and string.strip().endswith(__comment__[extension]): + if __comment_end__.get(extension, None) != None and string.strip().endswith(__comment_end__[extension]): return True if __comment__.get(extension, None) != None and string.strip().startswith(__comment__[extension]): return True @@ -37,7 +37,7 @@ def is_comment(extension, string): return False def has_comment_begining(extension, string): - if __comment_begining__.get(extension, None) != None: + if __comment_begining__.get(extension, None) != None and string.find(__comment_end__[extension], 2) == -1: return string.find(__comment_begining__[extension]) != -1 else: return False diff --git a/metrics.py b/metrics.py index 89b779b..8c563dc 100644 --- a/metrics.py +++ b/metrics.py @@ -46,15 +46,14 @@ class Metrics: eloc_counter = 0 for j in file_r.readlines(): - if comment.has_comment_begining(extension, j): + if is_inside_comment and comment.has_comment_end(extension, j): + is_inside_comment = False + elif comment.has_comment_begining(extension, j): is_inside_comment = True - if not comment.is_comment(extension, j) and not is_inside_comment: + if not is_inside_comment and not comment.is_comment(extension, j): eloc_counter += 1 - if comment.has_comment_end(extension, j): - is_inside_comment = False - return eloc_counter def output(repo, hard):