handle each commit one by one
This commit is contained in:
parent
79dee8f5c7
commit
778b275a52
|
@ -1,13 +1,17 @@
|
|||
import json
|
||||
from typing import List
|
||||
|
||||
from dulwich.objects import Commit
|
||||
|
||||
import GlobalConstants
|
||||
from models.MethodInfo import MethodInfo
|
||||
from models.RepoInfo import RepoInfo
|
||||
from MySQLOperator import MySQLOperator
|
||||
|
||||
|
||||
def extract_method_function_relations(repoInfo: RepoInfo, mysqlOp: MySQLOperator):
|
||||
def extract_method_function_relations(
|
||||
commit: Commit, repoInfo: RepoInfo, mysqlOp: MySQLOperator
|
||||
):
|
||||
blob_commit_relation_tablename = (
|
||||
"{ownername}{separator}{reponame}{separator}blob_commit_relations".format(
|
||||
ownername=repoInfo.ownername,
|
||||
|
@ -40,30 +44,22 @@ def extract_method_function_relations(repoInfo: RepoInfo, mysqlOp: MySQLOperator
|
|||
)
|
||||
)
|
||||
|
||||
def get_methods_4_commit(commit_sha: str = None) -> List[MethodInfo]:
|
||||
def get_methods_4_commit(commit_sha: str) -> List[MethodInfo]:
|
||||
|
||||
"""
|
||||
Function: get the methods related to a commit version
|
||||
params:
|
||||
- commit_sha: string format of sha value of commit. If commit_sha is None, get all the methods
|
||||
- commit_sha: string format of sha value of commit.
|
||||
return:
|
||||
- a list of MethodInfo objects
|
||||
"""
|
||||
if commit_sha is None:
|
||||
mysqlOp.cursor.execute(
|
||||
"select bm.id, bm.blob_sha, bm.start, bm.end, bm.method_name, bcr.commit_sha, bcr.filepath_sha from `{blob_commit_relation_tablename}` bcr, `{blob_method_tablename}` bm where bcr.blob_sha=bm.blob_sha".format(
|
||||
blob_commit_relation_tablename=blob_commit_relation_tablename,
|
||||
blob_method_tablename=blob_method_tablename,
|
||||
)
|
||||
)
|
||||
else:
|
||||
mysqlOp.cursor.execute(
|
||||
"select bm.id, bm.blob_sha, bm.start, bm.end, bm.method_name, bcr.commit_sha, bcr.filepath_sha from `{blob_commit_relation_tablename}` bcr, `{blob_method_tablename}` bm where bcr.blob_sha=bm.blob_sha and bcr.commit_sha=%s".format(
|
||||
blob_commit_relation_tablename=blob_commit_relation_tablename,
|
||||
blob_method_tablename=blob_method_tablename,
|
||||
),
|
||||
(commit_sha,),
|
||||
)
|
||||
mysqlOp.cursor.execute(
|
||||
"select bm.id, bm.blob_sha, bm.start, bm.end, bm.method_name, bcr.commit_sha, bcr.filepath_sha from `{blob_commit_relation_tablename}` bcr, `{blob_method_tablename}` bm where bcr.blob_sha=bm.blob_sha and bcr.commit_sha=%s".format(
|
||||
blob_commit_relation_tablename=blob_commit_relation_tablename,
|
||||
blob_method_tablename=blob_method_tablename,
|
||||
),
|
||||
(commit_sha,),
|
||||
)
|
||||
methods = mysqlOp.cursor.fetchall()
|
||||
|
||||
methodInfos = []
|
||||
|
@ -167,11 +163,13 @@ def extract_method_function_relations(repoInfo: RepoInfo, mysqlOp: MySQLOperator
|
|||
result = None
|
||||
return result
|
||||
|
||||
methods = get_methods_4_commit()
|
||||
methods = get_methods_4_commit(commit_sha=commit.id.decode())
|
||||
for method in methods:
|
||||
related_methods = get_related_methods(methodInfo=method)
|
||||
for related_method in related_methods:
|
||||
change = get_change(methodInfo_1=method, methodInfo_2=related_method)
|
||||
if change is not None:
|
||||
print("pause")
|
||||
change = json.dumps(change) if change is not None else change
|
||||
mysqlOp.cursor.execute(
|
||||
"insert into `{method_function_relation_tablename}` (`method_id_1`, `method_id_2`, `change`) values (%s, %s, %s)".format(
|
||||
|
|
Loading…
Reference in New Issue