зеркало из https://github.com/mozilla/bugbug.git
Don't consider all functions with the same name as touched by a commit when only one of them is
This commit is contained in:
Родитель
7628d98da4
Коммит
0b707ec1d9
|
@ -408,9 +408,10 @@ def get_functions_from_metrics(metrics_space):
|
|||
return functions
|
||||
|
||||
|
||||
def get_touched_functions(metrics_space, deleted_lines, added_lines):
|
||||
touched_functions = set()
|
||||
touched_function_names = set()
|
||||
def get_touched_functions(
|
||||
metrics_space: dict, deleted_lines: Iterable[int], added_lines: Iterable[int]
|
||||
) -> List[Tuple[str, int, int]]:
|
||||
touched_functions_indexes = set()
|
||||
|
||||
functions = get_functions_from_metrics(metrics_space)
|
||||
|
||||
|
@ -424,7 +425,7 @@ def get_touched_functions(metrics_space, deleted_lines, added_lines):
|
|||
|
||||
# If the line belongs to this function, add the function to the set of touched functions.
|
||||
elif function["start_line"] <= line:
|
||||
touched_function_names.add(function["name"])
|
||||
touched_functions_indexes.add(functions.index(function))
|
||||
last_f += 1
|
||||
|
||||
# Get functions touched by added lines.
|
||||
|
@ -453,11 +454,13 @@ def get_touched_functions(metrics_space, deleted_lines, added_lines):
|
|||
get_touched(prev_functions, deleted_lines)
|
||||
|
||||
# Return touched functions, with their new positions.
|
||||
for function in functions:
|
||||
if function["name"] in touched_function_names:
|
||||
touched_functions.add(
|
||||
(function["name"], function["start_line"], function["end_line"])
|
||||
)
|
||||
touched_functions = []
|
||||
|
||||
for i in touched_functions_indexes:
|
||||
function = functions[i]
|
||||
touched_functions.append(
|
||||
(function["name"], function["start_line"], function["end_line"])
|
||||
)
|
||||
|
||||
return touched_functions
|
||||
|
||||
|
@ -636,7 +639,7 @@ def transform(hg: hglib.client, repo_dir: str, commit: Commit):
|
|||
stats["added_lines"],
|
||||
)
|
||||
if len(touched_functions) > 0:
|
||||
commit.functions[path] = list(touched_functions)
|
||||
commit.functions[path] = touched_functions
|
||||
|
||||
# Replace type with "Objective-C/C++" if rust-code-analysis detected this is an Objective-C/C++ file.
|
||||
if type_ == "C/C++" and metrics.get("language") == "obj-c/c++":
|
||||
|
|
|
@ -1789,7 +1789,7 @@ void func2() {
|
|||
[],
|
||||
)
|
||||
|
||||
assert touched_functions == set()
|
||||
assert touched_functions == []
|
||||
|
||||
metrics = code_analysis_server.metrics(
|
||||
"file.cpp",
|
||||
|
@ -1810,7 +1810,7 @@ void func2() {
|
|||
[1],
|
||||
)
|
||||
|
||||
assert touched_functions == {("func1", 1, 3)}
|
||||
assert set(touched_functions) == {("func1", 1, 3)}
|
||||
|
||||
metrics = code_analysis_server.metrics(
|
||||
"file.cpp",
|
||||
|
@ -1835,7 +1835,7 @@ void func4() {
|
|||
[6],
|
||||
)
|
||||
|
||||
assert touched_functions == {("func3", 5, 7), ("func1", 1, 3)}
|
||||
assert set(touched_functions) == {("func3", 5, 7), ("func1", 1, 3)}
|
||||
|
||||
metrics = code_analysis_server.metrics(
|
||||
"file.cpp",
|
||||
|
@ -1856,7 +1856,7 @@ void func2() {
|
|||
[6],
|
||||
)
|
||||
|
||||
assert touched_functions == {("func2", 5, 7)}
|
||||
assert set(touched_functions) == {("func2", 5, 7)}
|
||||
|
||||
metrics = code_analysis_server.metrics(
|
||||
"file.js",
|
||||
|
@ -1875,7 +1875,7 @@ let i = 0;
|
|||
[1, 4],
|
||||
)
|
||||
|
||||
assert touched_functions == {("func", 3, 5)}
|
||||
assert set(touched_functions) == {("func", 3, 5)}
|
||||
|
||||
metrics = code_analysis_server.metrics(
|
||||
"file.jsm",
|
||||
|
@ -1895,7 +1895,7 @@ let f = function() {
|
|||
[4],
|
||||
)
|
||||
|
||||
assert touched_functions == {("outer_func", 1, 6)}
|
||||
assert set(touched_functions) == {("outer_func", 1, 6)}
|
||||
|
||||
metrics = code_analysis_server.metrics(
|
||||
"file.jsm",
|
||||
|
@ -1915,7 +1915,32 @@ function inner_func() {
|
|||
[4],
|
||||
)
|
||||
|
||||
assert touched_functions == {("outer_func", 1, 6), ("inner_func", 3, 5)}
|
||||
assert set(touched_functions) == {("outer_func", 1, 6), ("inner_func", 3, 5)}
|
||||
|
||||
metrics = code_analysis_server.metrics(
|
||||
"file.jsm",
|
||||
"""function outer_func() {
|
||||
let i = 0;
|
||||
function inner_func() {
|
||||
let j = 0;
|
||||
}
|
||||
}
|
||||
|
||||
function inner_func() {
|
||||
let j = 0;
|
||||
}
|
||||
""",
|
||||
unit=False,
|
||||
)
|
||||
|
||||
# A function touched inside another function, and a function with the same name somewhere else.
|
||||
touched_functions = repository.get_touched_functions(
|
||||
metrics["spaces"],
|
||||
[],
|
||||
[4],
|
||||
)
|
||||
|
||||
assert set(touched_functions) == {("outer_func", 1, 6), ("inner_func", 3, 5)}
|
||||
|
||||
|
||||
def test_get_metrics():
|
||||
|
|
Загрузка…
Ссылка в новой задаче