set -> uniq idom

set is unstable
This commit is contained in:
Costa Shulyupin 2018-08-08 09:03:47 +03:00
parent 3de9ab0e8b
commit 37ec4a8d0d
1 changed files with 12 additions and 18 deletions

View File

@ -116,9 +116,9 @@ def extract_referer_test():
def func_referers_git_grep(name): def func_referers_git_grep(name):
res = set() res = list()
r = None r = None
for line in popen(r'git grep --no-index --word-regexp --show-function ' for line in popen(r'git grep --threads 1 --no-index --word-regexp --show-function '
r'"^\s.*\b%s" ' r'"^\s.*\b%s" '
r'**.\[hc\] **.cpp **.cc **.hh || true' % (name)): r'**.\[hc\] **.cpp **.cc **.hh || true' % (name)):
# Filter out names in comment afer function, # Filter out names in comment afer function,
@ -133,7 +133,7 @@ def func_referers_git_grep(name):
r = None r = None
break break
if r and r != name and r not in black_list: if r and r != name and r not in black_list:
res.add(r) res.append(r)
r = None r = None
r = extract_referer(line) r = extract_referer(line)
return res return res
@ -149,15 +149,15 @@ def func_referers_cscope(name):
print("Recommended: cscope -bkR", file=sys.stderr) print("Recommended: cscope -bkR", file=sys.stderr)
cscope_warned = True cscope_warned = True
return [] return []
res = set([l.split()[1] for l in popen(r'cscope -d -L3 "%s"' % res = list(dict.fromkeys([l.split()[1] for l in popen(r'cscope -d -L3 "%s"' %
(name)) if l not in black_list]) (name)) if l not in black_list]))
if not res: if not res:
res = func_referers_git_grep(name) res = func_referers_git_grep(name)
return res return res
def func_referers_all(name): def func_referers_all(name):
return set(func_referers_git_grep(name) + func_referers_cscope(name)) return list(dict.fromkeys(func_referers_git_grep(name) + func_referers_cscope(name)))
def referers_tree(name, referer=None, printed=None, level=0): def referers_tree(name, referer=None, printed=None, level=0):
@ -204,13 +204,10 @@ def referers_dep(name, referer=None, printed=None, level=0):
return return
if level > level_limit - 2: if level > level_limit - 2:
return '' return ''
referers = set(referer(name)) referers = referer(name)
if referers: if referers:
printed.add(name) printed.add(name)
print(name, end=': ') print("%s:" % (name), ' '.join(referers))
for a in referers:
print(a, end=' ')
print()
for a in referers: for a in referers:
referers_dep(a, referer, printed, level + 1) referers_dep(a, referer, printed, level + 1)
else: else:
@ -256,20 +253,17 @@ def call_dep(node, printed=None, level=0):
printed = set() printed = set()
if node in printed: if node in printed:
return return
calls = set() calls = list()
for a in [line.split()[1] for line in for a in [line.split()[1] for line in
popen('cscope -d -L2 "%s"' % (node))]: popen('cscope -d -L2 "%s"' % (node))]:
if a in black_list: if a in black_list:
continue continue
calls.add(a) calls.append(a)
if calls: if calls:
if level < level_limit - 1: if level < level_limit - 1:
printed.add(node) printed.add(node)
print(node, end=': ') print("%s:" % (node), ' '.join(list(dict.fromkeys(calls))))
for a in calls: for a in list(dict.fromkeys(calls)):
print(a, end=' ')
print()
for a in calls:
call_dep(a, printed, level + 1) call_dep(a, printed, level + 1)
else: else:
pass pass