mirror of
https://github.com/ejwa/gitinspector.git
synced 2024-09-28 18:31:30 +02:00
Added a handle_comment_block() function in the comment module.
This function moves most of the logic of handling comments into the comment module itself, thus avoiding duplicated code and allowing for a cleaner solution.
This commit is contained in:
parent
f20b826d2d
commit
bb72cc8f02
@ -67,16 +67,8 @@ class BlameThread(threading.Thread):
|
|||||||
if self.blames.get((author, self.filename), None) == None:
|
if self.blames.get((author, self.filename), None) == None:
|
||||||
self.blames[(author, self.filename)] = BlameEntry()
|
self.blames[(author, self.filename)] = BlameEntry()
|
||||||
|
|
||||||
if comment.is_comment(self.extension, content):
|
(comments, is_inside_comment) = comment.handle_comment_block(is_inside_comment, self.extension, content)
|
||||||
self.blames[(author, self.filename)].comments += 1
|
self.blames[(author, self.filename)].comments += comments
|
||||||
if is_inside_comment:
|
|
||||||
if comment.has_comment_end(self.extension, content):
|
|
||||||
is_inside_comment = False
|
|
||||||
else:
|
|
||||||
self.blames[(author, self.filename)].comments += 1
|
|
||||||
elif comment.has_comment_begining(self.extension, content) and not comment.has_comment_end(self.extension, content):
|
|
||||||
is_inside_comment = True
|
|
||||||
|
|
||||||
self.blames[(author, self.filename)].rows += 1
|
self.blames[(author, self.filename)].rows += 1
|
||||||
__blame_lock__.release() # ...to here.
|
__blame_lock__.release() # ...to here.
|
||||||
|
|
||||||
|
@ -32,6 +32,22 @@ __comment__ = {"java": "//", "c": "//", "cpp": "//", "h": "//", "hpp": "//", "pl
|
|||||||
|
|
||||||
__comment_markers_must_be_at_begining__ = {"tex": True}
|
__comment_markers_must_be_at_begining__ = {"tex": True}
|
||||||
|
|
||||||
|
def __has_comment_begining__(extension, string):
|
||||||
|
if __comment_markers_must_be_at_begining__.get(extension, None) == True:
|
||||||
|
return string.find(__comment_begining__[extension]) == 0
|
||||||
|
elif __comment_begining__.get(extension, None) != None and string.find(__comment_end__[extension], 2) == -1:
|
||||||
|
return string.find(__comment_begining__[extension]) != -1
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def __has_comment_end__(extension, string):
|
||||||
|
if __comment_markers_must_be_at_begining__.get(extension, None) == True:
|
||||||
|
return string.find(__comment_end__[extension]) == 0
|
||||||
|
elif __comment_end__.get(extension, None) != None:
|
||||||
|
return string.find(__comment_end__[extension]) != -1
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
def is_comment(extension, string):
|
def is_comment(extension, string):
|
||||||
if __comment_begining__.get(extension, None) != None and string.strip().startswith(__comment_begining__[extension]):
|
if __comment_begining__.get(extension, None) != None and string.strip().startswith(__comment_begining__[extension]):
|
||||||
return True
|
return True
|
||||||
@ -42,18 +58,17 @@ def is_comment(extension, string):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def has_comment_begining(extension, string):
|
def handle_comment_block(is_inside_comment, extension, content):
|
||||||
if __comment_markers_must_be_at_begining__.get(extension, None) == True:
|
comments = 0
|
||||||
return string.find(__comment_begining__[extension]) == 0
|
|
||||||
elif __comment_begining__.get(extension, None) != None and string.find(__comment_end__[extension], 2) == -1:
|
|
||||||
return string.find(__comment_begining__[extension]) != -1
|
|
||||||
|
|
||||||
return False
|
if is_comment(extension, content):
|
||||||
|
comments += 1
|
||||||
|
if is_inside_comment:
|
||||||
|
if __has_comment_end__(extension, content):
|
||||||
|
is_inside_comment = False
|
||||||
|
else:
|
||||||
|
comments += 1
|
||||||
|
elif __has_comment_begining__(extension, content) and not __has_comment_end__(extension, content):
|
||||||
|
is_inside_comment = True
|
||||||
|
|
||||||
def has_comment_end(extension, string):
|
return (comments, is_inside_comment)
|
||||||
if __comment_markers_must_be_at_begining__.get(extension, None) == True:
|
|
||||||
return string.find(__comment_end__[extension]) == 0
|
|
||||||
elif __comment_end__.get(extension, None) != None:
|
|
||||||
return string.find(__comment_end__[extension]) != -1
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
@ -57,10 +57,7 @@ class MetricsLogic:
|
|||||||
|
|
||||||
for j in file_r.readlines():
|
for j in file_r.readlines():
|
||||||
j = j.decode("utf-8", "replace")
|
j = j.decode("utf-8", "replace")
|
||||||
if is_inside_comment and comment.has_comment_end(extension, j):
|
(is_inside_comment, _) = comment.handle_comment_block(is_inside_comment, extension, j)
|
||||||
is_inside_comment = False
|
|
||||||
elif comment.has_comment_begining(extension, j):
|
|
||||||
is_inside_comment = True
|
|
||||||
|
|
||||||
if not is_inside_comment and not comment.is_comment(extension, j):
|
if not is_inside_comment and not comment.is_comment(extension, j):
|
||||||
eloc_counter += 1
|
eloc_counter += 1
|
||||||
|
Loading…
Reference in New Issue
Block a user