fix bug for first commit

This commit is contained in:
zy 2022-09-17 10:03:17 +08:00
parent db0a2e8818
commit b4f2df7930
1 changed files with 58 additions and 54 deletions

View File

@ -403,64 +403,68 @@ def factor_extractor(function_id_1: int, function_id_2: int, mysqlOp: MySQLOpera
parent_ids.append(parent.get("parent_id"))
related_methods = []
related_method_id = []
for id in parent_ids:
sql = """
select bm.id as method_id from `{tablename1}` bm, `{tablename2}` bcr where bcr.commit_id = {commit_id} and bcr.blob_id = bm.blob_id
""".format(
tablename1=blob_methods,
tablename2=blob_commit_relations,
commit_id=id,
)
mysqlOp.cursor.execute(sql)
related_methods.extend(mysqlOp.cursor.fetchall())
for related_method in related_methods:
related_method_id.append(related_method.get("method_id"))
target_change_1 = {}
sql_change_method_1 = """
select * from `{tablename}` where method_id_2 = {method_id}
""".format(
tablename=method_function_relations, method_id=first_pair.get("method_id_1")
)
mysqlOp.cursor.execute(sql_change_method_1)
change_method_1 = mysqlOp.cursor.fetchall()
change_method_id_1 = []
for change_method in change_method_1:
change_method_id_1.append(change_method.get("method_id_1"))
for i in range(len(change_method_id_1)):
if change_method_id_1[i] in related_method_id:
target_change_1 = change_method_1[i]
break
target_change_2 = {}
sql_change_method_2 = """
select * from `{tablename}` where method_id_2 = {method_id}
""".format(
tablename=method_function_relations, method_id=first_pair.get("method_id_2")
)
mysqlOp.cursor.execute(sql_change_method_2)
change_method_2 = mysqlOp.cursor.fetchall()
change_method_id_2 = []
for change_method in change_method_2:
change_method_id_2.append(change_method.get("method_id_2"))
for i in range(len(change_method_id_2)):
if change_method_id_2[i] in related_method_id:
target_change_2 = change_method_2[i]
break
if target_change_1 == {} or target_change_2 == {}:
if parents is None:
co_change = 0
consistant_change = 0
else:
co_change = 1
if (
target_change_1.get("change") == target_change_2.get("change")
and target_change_1.get("change") is not None
and target_change_2.get("change") is not None
):
consistant_change = 1
else:
for id in parent_ids:
sql = """
select bm.id as method_id from `{tablename1}` bm, `{tablename2}` bcr where bcr.commit_id = {commit_id} and bcr.blob_id = bm.blob_id
""".format(
tablename1=blob_methods,
tablename2=blob_commit_relations,
commit_id=id,
)
mysqlOp.cursor.execute(sql)
related_methods.extend(mysqlOp.cursor.fetchall())
for related_method in related_methods:
related_method_id.append(related_method.get("method_id"))
target_change_1 = {}
sql_change_method_1 = """
select * from `{tablename}` where method_id_2 = {method_id}
""".format(
tablename=method_function_relations, method_id=first_pair.get("method_id_1")
)
mysqlOp.cursor.execute(sql_change_method_1)
change_method_1 = mysqlOp.cursor.fetchall()
change_method_id_1 = []
for change_method in change_method_1:
change_method_id_1.append(change_method.get("method_id_1"))
for i in range(len(change_method_id_1)):
if change_method_id_1[i] in related_method_id:
target_change_1 = change_method_1[i]
break
target_change_2 = {}
sql_change_method_2 = """
select * from `{tablename}` where method_id_2 = {method_id}
""".format(
tablename=method_function_relations, method_id=first_pair.get("method_id_2")
)
mysqlOp.cursor.execute(sql_change_method_2)
change_method_2 = mysqlOp.cursor.fetchall()
change_method_id_2 = []
for change_method in change_method_2:
change_method_id_2.append(change_method.get("method_id_2"))
for i in range(len(change_method_id_2)):
if change_method_id_2[i] in related_method_id:
target_change_2 = change_method_2[i]
break
if target_change_1 == {} or target_change_2 == {}:
co_change = 0
consistant_change = 0
else:
co_change = 1
if (
target_change_1.get("change") == target_change_2.get("change")
and target_change_1.get("change") is not None
and target_change_2.get("change") is not None
):
consistant_change = 1
else:
consistant_change = 0
# TODO:main_author_same
sql_function_1_author = """