From 0d11f2b68b7492bea4bc7e1b0b6a96ce6600d21b Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Thu, 8 Feb 2024 21:38:23 +0800 Subject: [PATCH] =?UTF-8?q?database=5Ftools=E4=B8=AD=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=AF=94=E8=BE=83=E4=B8=A4=E4=B8=AAgit=20commit=E7=9A=84json?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E4=B8=8D=E5=90=8C=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BDgitdiff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/database_tools.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index e0d5f83f..6de58c4d 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -1882,7 +1882,23 @@ def UnitRectoMetadataText(data): #把data中的单元对应变为metadata.txt中 output += f"{units}\n\n" return output +def gitdiff(commitid1,commitid2,fileinrepo="题库0.3/Problems.json",tempfilepath = "临时文件/temp.json"): # 根据两个git 的commit id 比较某一个json文件的不同, 返回一个tuple, 第一项是新增key的变化, 第二项是同一个key下哪些字段变化了 + os.system(f"git show {commitid1}:{fileinrepo} > {tempfilepath}") + json1 = load_dict("临时文件/temp.json") + os.system(f"git show {commitid2}:{fileinrepo} > {tempfilepath}") + json2 = load_dict("临时文件/temp.json") + os.remove("临时文件/temp.json") + diff_list = [] + new_or_deleted_list = [id for id in json1.keys() if not id in json2.keys()] + [id for id in json2.keys() if not id in json1.keys()] + for id in [i for i in json1.keys() if i in json2.keys()]: + current_diff = [] + for field in json1[id]: + if not json1[id][field] == json2[id][field]: + current_diff.append(field) + if not current_diff == []: + diff_list.append((id,current_diff.copy())) + return (new_or_deleted_list,diff_list) if __name__ == "__main__": print("数据库工具, import用.") \ No newline at end of file