A potential conflict code block detection method and system based on AST division pruning

CN122963915APending Publication Date: 2026-10-23FUDAN UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510467111.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-15
Publication Date
2026-10-23

AI Technical Summary

Technical Problem

当代码的注释或格式发生变更时,即使这些修改对代码逻辑并无实质性影响,行合并算法也可能误报冲突

Benefits of technology

本发明提供了一种基于AST划分剪枝的潜在冲突代码块检测方法及系统,旨在解决现有技术中冲突检测过程中的低效和误报问题,通过利用AST解析工具对多个待合并的代码文件进行解析,并对其进行划分处理,形成结构化的代码块集合。通过对比和分析代码块的签名和内容相似度,精确地检测出潜在的冲突区域。与传统的基于行的合并方法不同,本发明通过在代码块层次上进行精细划分和剪枝,有效缩小了冲突范围,从而提高了冲突检测的效率和准确性。该系统适用于多种版本控制和分支管理场景,能够快速识别并标记潜在的冲突代码块,减少人工干预,提升开发效率,降低冲突处理的复杂度。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122963915A_ABST
    Figure CN122963915A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of software code merging, and provides a potential conflict code block detection method and system based on AST division and pruning, which comprises the following steps: responding to a conflict code block detection request; analyzing an original file and at least one modified branch file through an AST analysis tool to generate corresponding AST structures; dividing the AST structures into a plurality of independent code blocks, and generating unique code block signatures according to the structural characteristics of the code blocks, so as to identify and distinguish the code blocks; traversing the code blocks in the original file and the modified branch file, establishing a corresponding relationship by comparing the parent nodes, signatures and content similarity of the code blocks, and detecting and marking the code blocks with potential conflicts. The code blocks are finely divided and pruned at the code block level, the conflict range is effectively reduced, the efficiency and accuracy of conflict detection are improved, the method is suitable for various version control and branch management scenes, potential conflict code blocks can be quickly identified and marked, and manual intervention is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of software code merging technology, and in particular to a method and system for detecting potential conflicting code blocks based on AST partitioning and pruning. Background Technology

[0002] As modern software projects continue to grow in scale, developers increasingly face the challenge of collaborative development with multiple developers. To resolve potential conflicts that can arise when multiple developers simultaneously modify the same part of the code, version control systems (VCS) such as Git are widely used in team collaboration. After developers complete their branch development, they use tools like Git to merge the code, bringing the updates from the branch to the main branch. However, during the merging process, multiple developers often modify the same code area simultaneously, leading to "merge conflicts." In such cases, manual intervention from the developers is required to resolve the conflicts.

[0003] Line-based merge algorithms remain the most commonly used merging method. While they can detect changes to file lines, they have significant limitations. When code comments or formatting change, even if these modifications don't substantially affect the code logic, line-based merge algorithms may falsely report conflicts. Furthermore, syntactic adjustments (such as changes to variable or function names) may not affect the semantics of the code but can still trigger merge conflicts. Therefore, traditional line-based merge algorithms often lead to false alarms, increasing the burden on developers when resolving conflicts.

[0004] Therefore, a merging method is needed that can deeply understand code syntax and semantics. This method should reduce false positives when detecting potential conflicts and consider actual semantic changes in the code during the merging process, rather than simply relying on line-level comparisons. By performing syntactic analysis on the code and combining it with intelligent pruning strategies, the scope of potential conflicts can be significantly narrowed, thereby improving merging efficiency. Summary of the Invention

[0005] To address the aforementioned problems, this invention proposes a method and system for detecting potential conflicting code blocks based on Abstract Syntax Tree (AST) partitioning and pruning, aiming to improve the efficiency and accuracy of conflict detection during code merging. By parsing the code file to be merged, the code is structurally partitioned using AST, and a unique code block signature is generated based on the characteristics of each code block. Subsequently, code blocks are matched based on signature and content similarity, and potentially conflicting code blocks are marked and analyzed. Through pruning techniques, irrelevant code blocks are filtered out, narrowing the detection range of potential conflicts, thereby accelerating the identification and resolution of conflicting code blocks, ultimately optimizing the code merging process, and ensuring the correctness and stability of the merging results. The above-mentioned objective of this invention is achieved through the following technical solutions: This invention provides a method for detecting potential conflicting code blocks based on AST partitioning and pruning, comprising the following steps: Step S1: Respond to conflicting code block detection requests; Step S2: Based on the conflict code block detection request, parse the original file and at least two modified branch files using an AST parsing tool to generate the corresponding AST structure; divide the AST structure into several independent code blocks, and generate a unique code block signature based on the structural characteristics of the code blocks to identify and distinguish the code blocks; Step S3: Traverse the code blocks in the original file and the modified branch file, establish a correspondence by comparing the parent node, signature and content similarity of each code block, and detect and mark code blocks with potential conflicts.

[0006] Furthermore, in step S2, the AST structure is divided into several independent code blocks, including: Traverse the nodes at each declaration level in the AST structure and classify them according to their type and structural characteristics. Divide the nodes into corresponding code block types, including functions, member variables, enumeration values, inner classes, constructors, initializers, and detached comments. The identified inner classes are recursively partitioned to ensure that the nesting structure of the inner classes is analyzed and categorized.

[0007] Further, in step S2, a unique code block signature is generated based on the structural characteristics of the code block to identify and distinguish the code block, including: The fully qualified class name of each code block is recursively identified as the parent class name of the code block. When the code block is an inner class, the path of the fully qualified class name is formed by including all the parent class names of the inner class. Assign specific prefix symbols based on the code block type to help identify the type of code block; Generate a corresponding code block name for each code block type. The code block name for function code blocks and constructors consists of the corresponding identifier plus the parameter list; the code block name for initializers and detached comments uses the first 8 bits of the hash value generated by the MD5 algorithm from the content digest; member variables, enumeration values, and inner classes directly use their names as code block names.

[0008] A unique code block signature is formed by combining the parent class name, prefix symbol, and code block name, which is used for code block identification, matching, and conflict detection.

[0009] Furthermore, in step S3, the correspondence includes no change, update, insertion, deletion, move, and move and update.

[0010] Furthermore, in step S3, the calculation steps for content similarity are as follows: Reconstruct the code using AST parsing tools to standardize the content format of code blocks; Determine whether the lengths of the two code blocks being compared have reached a preset threshold; When the code block length reaches a preset threshold, the content similarity is calculated by the ratio of the Lewinstein distance between the two code blocks to the maximum length of the two code blocks. When the length of a code block does not reach the preset threshold, the content similarity is calculated by the ratio of the length of the longest common substring of the two code blocks to the maximum length of the two code blocks.

[0011] Further, in step S3, a correspondence is established by comparing the parent node, signature, and content similarity of each code block, and code blocks with potential conflicts are detected and marked, including: Determine the correspondence between code blocks in the original file and the modified branch file; By comparing the parent nodes, signatures, and content similarity of code blocks between the modified branch files and the original files, a correspondence between each modified branch file and the original file is established; wherein the correspondence involves at least two modified branch files and the original file. Merge all modified branch files; If at least two modified branch files correspond to the original files in a way that is an opposite of any of the following: deletion, update, insertion, move, or move and update, then there is a potential conflict during the merge process. There are no potential conflicts during the merge process when only one modified branch file has an update, insert, delete, move, or move and update relationship with the original file, while the relationships between the remaining modified branch files and the original file remain unchanged, or when all modified branch files have a delete relationship with the original file.

[0012] Based on the same inventive concept, this invention provides a potential conflict code block detection system based on AST partitioning and pruning, employing the conflict code block detection method described above, including: The response module is used to respond to conflict code block detection requests. The data processing module is used to parse the original file and at least one modified branch file based on the conflict code block detection request using an AST parsing tool, generating the corresponding AST structure; dividing the AST structure into several independent code blocks, and generating a unique code block signature based on the structural characteristics of the code blocks to identify and distinguish them. The results output module is used to traverse the code blocks in the original file and the modified branch file. It establishes a correspondence by comparing the parent node, signature and content similarity of each code block, and detects and marks code blocks with potential conflicts.

[0013] Furthermore, the data processing module includes: The code block partitioning unit is used to traverse each node in the AST structure and classify the nodes according to their type and structural characteristics, dividing the nodes into corresponding code block types, including functions, member variables, enumeration values, inner classes, constructors, initializers, and detached comments; the identified inner classes are recursively partitioned to ensure that the nested structure of the inner class is analyzed and classified.

[0014] The signature generation unit recursively confirms the complete class name of each code block as the parent class name of the code block. When the code block is an inner class, it includes the names of all parent classes of the inner class to form the complete class name path. It assigns a specific prefix symbol according to the code block type to help identify the type of code block. It generates a corresponding code block name for each code block type. It combines the parent class name, prefix symbol and code block name to form a unique code block signature for code block identification, matching and conflict detection.

[0015] Furthermore, the result output module includes: The detection unit is used to determine the correspondence between code blocks in the original file and the modified branch file; The marking unit is used to establish a correspondence between each modified branch file and the original file by comparing the parent nodes, signatures, and content similarity of code blocks between the modified branch files and the original files. This correspondence involves at least two modified branch files and their corresponding original files. During the merging of all modified branch files, if at least two modified branch files and their corresponding original files have any of the following opposing relationships: deletion, update, insertion, move, or move and update, then a potential conflict exists during the marking merge process. If only one modified branch file and its corresponding original file have an update, insertion, deletion, move, or move and update relationship, and the remaining modified branch files and their corresponding original files have no change, or if all modified branch files and their corresponding original files have a deletion relationship, then no potential conflict exists during the marking merge process.

[0016] Furthermore, content similarity is assessed by reconstructing the code using an AST parsing tool to unify the content format of code blocks; it also checks whether the lengths of the two compared code blocks reach a preset threshold; when the code block lengths reach the preset threshold, the content similarity is calculated using the ratio of the Levenstein distance between the two code blocks to the maximum length of the two code blocks; when the code block lengths do not reach the preset threshold, the content similarity is calculated using the ratio of the length of the longest common substring of the two code blocks to the maximum length of the two code blocks.

[0017] Compared with the prior art, the present invention has at least one of the following beneficial effects: This invention provides a method and system for detecting potential conflicting code blocks based on AST partitioning and pruning. It aims to solve the inefficiencies and false positives in existing conflict detection processes. By utilizing AST parsing tools to analyze multiple code files to be merged and partitioning them into a structured set of code blocks, potential conflict areas are accurately detected through comparison and analysis of the code block signatures and content similarity. Unlike traditional line-based merging methods, this invention effectively narrows the scope of conflicts through fine-grained partitioning and pruning at the code block level, thereby improving the efficiency and accuracy of conflict detection. This system is applicable to various version control and branch management scenarios, enabling rapid identification and marking of potential conflicting code blocks, reducing manual intervention, improving development efficiency, and lowering the complexity of conflict handling. Attached Figure Description

[0018] Figure 1 This is a flowchart illustrating the steps of the potential conflict code block detection method based on AST partitioning and pruning in this invention. Figure 2 This is a schematic diagram illustrating the working principle of the potential conflict code block detection method based on AST partitioning and pruning in this invention. Figure 3 This is a schematic diagram illustrating the implementation process of the potential conflict code block detection method based on AST partitioning and pruning in this invention. Detailed Implementation

[0019] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0020] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in this specification means the presence of the stated features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.

[0021] First Embodiment In existing technologies, line-based merging methods suffer from low conflict detection efficiency and high false positives in multi-developer collaborative scenarios, especially when dealing with format adjustments, comment updates, or minor syntax changes, which are often misjudged as conflicts, leading to unnecessary manual intervention. Meanwhile, syntax tree (AST)-based detection methods fail to effectively consider contextual information and syntax hierarchy within code blocks when handling more complex code structures, thus affecting the accuracy of conflict detection.

[0022] Based on their consideration of these problems, the inventors proposed a potential conflict code block detection method based on AST partitioning and pruning. The aim is to quickly filter out conflict-free code blocks and narrow down the scope of potential conflict code blocks. Through further code block partitioning, combined with code block signatures and content similarity, it accurately identifies potential conflict code blocks and effectively reduces the false positive rate. This method utilizes AST parsing tools to analyze the files to be merged, and through code block partitioning and pruning optimization, ensures that only potentially conflicting code blocks are analyzed in depth, thereby improving the efficiency and accuracy of conflict detection.

[0023] To achieve the above objectives, this invention utilizes an AST parsing tool to parse three code files to be merged, generating corresponding ASTs. Based on the AST information, the code is divided, and corresponding signatures are generated to uniquely identify code blocks. Subsequently, modifications to the code blocks are analyzed and pruned based on both the code block signatures and similarity, thereby significantly narrowing down the range of potentially conflicting code blocks and achieving rapid detection of conflicting code blocks. Specific implementation methods are as follows: like Figure 1 As shown, this invention provides a method for detecting potential conflicting code blocks based on AST partitioning and pruning, including the following steps: Step S1: Respond to conflicting code block detection requests; Step S2: Based on the conflict code block detection request, the original file and at least one modified branch file are parsed using an AST parsing tool to generate the corresponding AST structure; the AST structure is divided into several independent code blocks, and a unique code block signature is generated based on the structural characteristics of the code blocks to identify and distinguish the code blocks; For example, in response to a conflict code block detection request, the received three files to be merged are: the original file (hereinafter referred to as the base file), the modified file evolved from branch a (hereinafter referred to as file a), and the modified file evolved from branch b (hereinafter referred to as file b). During this process, an AST parsing tool is used to parse these three files.

[0024] The tool performs syntactic analysis on each file, generating a corresponding Abstract Syntax Tree (AST) structure. Based on the AST structure, the system extracts all code blocks from each file and performs detailed analysis and partitioning of these blocks. For each file, the AST parsing tool structures each function (Method), member variable (Field), inner class (InnerClass), enumeration (Enum), constructor, initializer, and detached comment (Comment) into independent nodes, generating a unique identifier for each node. This method clearly understands the structure of each piece of code. For inner classes, further recursive partitioning is performed until all code blocks have no child blocks. Simultaneously, a signature is assigned to several generated code blocks, ensuring its uniqueness within the code block set corresponding to each file. The code block signature consists of the following: the parent class name of the code block, the prefix identifier corresponding to the code block type, and the name of the code block.

[0025] Step S3: Traverse the code blocks in the original file and the modified branch file, establish a correspondence by comparing the parent node, signature and content similarity of each code block, and detect and mark code blocks with potential conflicts.

[0026] Based on research of real code repositories, the results show that conflicting code blocks account for approximately 2% of the total code blocks in each file to be merged. This finding is used to prune and divide the code blocks in the files to be merged, narrowing down the range of potentially conflicting code and achieving more efficient conflict detection.

[0027] Furthermore, in step S2, the AST structure is divided into several independent code blocks, including: Traverse the nodes at each declaration level in the AST structure and classify them according to their type and structural characteristics. Divide the nodes into corresponding code block types, including functions, member variables, enumeration values, inner classes, constructors, initializers, and detached comments. It should be specifically noted that, in this application, the nodes at the declaration level mainly refer to declarative elements in the program, such as variables, functions, classes, enumerations, constructors, and other basic components. These declarative elements are used to define the core structure and logic of the program, and during code merging and conflict detection, these declarative elements are often the source of conflicts. Since multiple branch files may modify the same declaration section, nodes at the declaration level become key nodes for identifying conflicts during the merging process.

[0028] Specifically, nodes at the declaration level carry core information about the structure, such as function definitions, variable declarations and types, and class structure and attributes. By traversing and parsing these nodes, potential conflict areas can be precisely located, especially when the same function, variable, or class is modified in parallel across multiple branches. This step, by analyzing these declaration nodes, efficiently identifies potential conflicts and classifies and marks them based on node type and structural characteristics, thereby improving the accuracy and efficiency of the merging process.

[0029] The identified inner classes are recursively partitioned to ensure that the nesting structure of the inner classes is analyzed and categorized.

[0030] Further, in step S2, a unique code block signature is generated based on the structural characteristics of the code block to identify and distinguish the code block, including: The fully qualified class name of each code block is recursively identified as the parent class name of the code block. When the code block is an inner class, the path of the fully qualified class name is formed by including all the parent class names of the inner class. Assign specific prefix symbols based on the code block type to help identify the type of code block; Generate a corresponding code block name for each code block type. The code block name for function code blocks and constructors consists of the corresponding identifier plus the parameter list; the code block name for initializers and detached comments uses the first 8 bits of the hash value generated by the MD5 algorithm from the content digest; member variables, enumeration values, and inner classes directly use their names as code block names.

[0031] A unique code block signature is formed by combining the parent class name, prefix symbol, and code block name, which is used for code block identification, matching, and conflict detection.

[0032] Furthermore, in step S3, the correspondence includes no change, update, insertion, deletion, move, and move and update. That is, the code block correspondence between file base and file a / file b is established according to the parent node of the code block, the code block signature, and its content similarity, including NO_CAHNGE, UPDATE, INSERT, DELETE, MOVE, and MOVE_UPDATE.

[0033] Furthermore, in step S3, the calculation steps for content similarity are as follows: The code is reconstructed using AST parsing tools to unify the content format of code blocks, thereby reducing the impact of factors such as code style and indentation on content similarity calculation. Determine whether the lengths of the two code blocks being compared have reached a preset threshold; When the code block length reaches a preset threshold, for example, a preset threshold of 64 characters, the content similarity is calculated by the ratio of the Levenstein distance between the two code blocks to the maximum length of the two code blocks. When the length of a code block does not reach a preset threshold, such as a preset threshold of 64 characters, the content similarity is calculated by the ratio of the length of the longest common substring of the two code blocks to the maximum length of the two code blocks.

[0034] It should be noted that the steps for constructing the correspondence are as follows: When two code blocks have the same signature and content, their relationship is NO_CHANGE, meaning there is no change. When two code blocks have the same code block signature but different content, or when two code blocks have different code block signatures and their content similarity is higher than the threshold s (s is generally 0.5) and they have the same parent node, it is UPDATE, i.e., an update. When two code blocks have different signatures, a content similarity of 1, and different parent nodes, it is called MOVE.

[0035] When two code blocks have different signatures, the content similarity threshold s ≤ content similarity < 1, and the parent nodes are different, MOVE_UPDATE means move and update; Code blocks belonging to file a / file b that do not conform to the above criteria are INSERT (insertion), and code blocks belonging to file base are DELETE (deletion).

[0036] Further, in step S3, a correspondence is established by comparing the parent node, signature, and content similarity of each code block, and code blocks with potential conflicts are detected and marked, including: Determine the correspondence between code blocks in the original file and the modified branch file; By comparing the parent nodes, signatures, and content similarity of code blocks between the modified branch files and the original files, a correspondence between each modified branch file and the original file is established; wherein the correspondence involves at least two modified branch files and the original file. Merge all modified branch files; If at least two modified branch files correspond to the original files in a way that is an opposite of any of the following: deletion, update, insertion, move, or move and update, then there is a potential conflict during the merge process. There are no potential conflicts during the merge process when only one modified branch file has an update, insert, delete, move, or move and update relationship with the original file, while the relationships between the remaining modified branch files and the original file remain unchanged, or when all modified branch files have a delete relationship with the original file.

[0037] Second Embodiment Based on the same inventive concept, this invention provides a potential conflict code block detection system based on AST partitioning and pruning, employing the conflict code block detection method described above, including: The response module is used to respond to conflict code block detection requests. The data processing module is used to parse the original file and at least one modified branch file based on the conflict code block detection request using an AST parsing tool, generating the corresponding AST structure; dividing the AST structure into several independent code blocks, and generating a unique code block signature based on the structural characteristics of the code blocks to identify and distinguish them. The results output module is used to traverse the code blocks in the original file and the modified branch file. It establishes a correspondence by comparing the parent node, signature and content similarity of each code block, and detects and marks code blocks with potential conflicts.

[0038] Furthermore, the data processing module includes: The code block partitioning unit is used to traverse the nodes at each declaration level in the AST structure and classify them according to the type and structural characteristics of the nodes, dividing the nodes into corresponding code block types, including functions, member variables, enumeration values, inner classes, constructors, initializers, and detached comments; the identified inner classes are recursively partitioned to ensure that the nested structure of the inner classes is analyzed and classified.

[0039] The signature generation unit recursively confirms the complete class name of each code block as the parent class name of the code block. When the code block is an inner class, it includes the names of all parent classes of the inner class to form the complete class name path. It assigns a specific prefix symbol according to the code block type to help identify the type of code block. It generates a corresponding code block name for each code block type. It combines the parent class name, prefix symbol and code block name to form a unique code block signature for code block identification, matching and conflict detection.

[0040] Furthermore, the result output module includes: The detection unit is used to determine the correspondence between code blocks in the original file and the modified branch file; The marking unit is used to establish a correspondence between each modified branch file and the original file by comparing the parent nodes, signatures, and content similarity of code blocks between the modified branch files and the original files. This correspondence involves at least two modified branch files and their corresponding original files. During the merging of all modified branch files, if at least two modified branch files and their corresponding original files have any of the following opposing relationships: deletion, update, insertion, move, or move and update, then a potential conflict exists during the marking merge process. If only one modified branch file and its corresponding original file have an update, insertion, deletion, move, or move and update relationship, and the remaining modified branch files and their corresponding original files have no change, or if all modified branch files and their corresponding original files have a deletion relationship, then no potential conflict exists during the marking merge process.

[0041] Furthermore, content similarity is assessed by reconstructing the code using an AST parsing tool to unify the content format of code blocks; it also checks whether the lengths of the two compared code blocks reach a preset threshold; when the code block lengths reach the preset threshold, the content similarity is calculated using the ratio of the Levenstein distance between the two code blocks to the maximum length of the two code blocks; and when the code block lengths reach the preset threshold, the content similarity is calculated using the ratio of the length of the longest common substring of the two code blocks to the maximum length of the two code blocks.

[0042] Third Embodiment With the prevalence of multi-person collaboration in software development, how to quickly and accurately identify and resolve code conflicts has become an urgent technical problem. Based on the limitations of existing technologies, this invention proposes a potential conflict detection method that involves code block segmentation, signature generation, and content similarity analysis. Specifically, by analyzing and segmenting the code blocks in the code file to be merged using an AST parsing tool, a unique signature is generated for each code block, and these signatures and content similarity are used to match the code blocks, thereby detecting potential conflicts. This method effectively narrows the scope of potential conflict detection, significantly improves detection efficiency, and reduces unnecessary false alarms. In a third embodiment, this invention is further applied to the code merging process in multi-branch development, particularly for detecting code conflicts across multiple branches in complex projects.

[0043] like Figure 2 As shown, Figure 2 This embodiment demonstrates five main steps: generating an AST, dividing code blocks, generating a signature, establishing a correspondence between code blocks, filtering based on the correspondence, and detecting potentially conflicting code blocks. The specific process has been described in the first embodiment and will not be repeated here.

[0044] Figure 3The diagram illustrates the implementation process, showing the detection procedure for potential conflicts in the code block of function f in files base, a, and b. The specific implementation is as follows: This invention presents an example of a process for detecting potential conflicts in the code block of function f in files base, file a, and file b. First, an AST parser is used to parse files base, file a, and file b, generating corresponding ASTs: AST-base, AST-a, and AST-b. Then, based on the node information in the ASTs, the original files are divided into several code blocks, forming code block sets -base, -a, and -b. Next, a signature is generated for each code block. For example, for function f in file a, its parent class is class A, and its class name is A; the code block type of function f is function, with the corresponding prefix identifier "#"; the name of function f is f, and it has no parameters. Therefore, the signature of the code block corresponding to function f in file base is A#f. Next, the code blocks in all code block sets -base are traversed. It is found that code blocks with the signature A#f exist in both code block sets -a and -b, but their contents are all different (the code block from file base calls function foo, the code block from file a calls function foo1, and the code block from file b calls function foo2). Therefore, according to the principle that two code blocks with the same signature but different content similarity threshold s (typically 0.5) and the same parent node are considered UPDATE, the correspondence between A#f(base) and A#f(a), and between A#f(base) and A#f(b) is UPDATE. Finally, the code blocks in all code block sets -base are traversed again. For the code block with the signature A#f(base), it is found that its correspondence with A#f(a) and A#f(b) is UPDATE. Therefore, it is concluded that there is a potential conflict between code blocks A#f(base) and A#f(a) and A#f(b).

[0045] The advantage lies in utilizing the research finding that conflicting code blocks in each file to be merged account for approximately 2% of the total file code blocks. This allows for the division and pruning of code blocks in the files to be merged, narrowing down the range of potential conflicting code and achieving more efficient conflicting code block detection.

[0046] Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the present invention. Any person skilled in the art can make possible changes and modifications to the technical solutions of the present invention by utilizing the methods and techniques disclosed above without departing from the spirit and scope of the present invention. Therefore, any simple modifications, equivalent changes and alterations made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solutions of the present invention shall fall within the protection scope of the technical solutions of the present invention.

Claims

1. A method for detecting potential conflicting code blocks based on AST partitioning and pruning, characterized in that, Includes the following steps: Step S1: Respond to conflicting code block detection requests; Step S2: Based on the conflict code block detection request, the original file and at least two modified branch files are parsed using an AST parsing tool to generate the corresponding AST structure; the AST structure is divided into several independent code blocks, and a unique code block signature is generated based on the structural characteristics of the code blocks to identify and distinguish the code blocks; Step S3: Traverse the code blocks in the original file and the modified branch file, establish a correspondence by comparing the parent node, signature and content similarity of each code block, and detect and mark code blocks with potential conflicts.

2. The conflict code block detection method according to claim 1, characterized in that, In step S2, the AST structure is divided into several independent code blocks, including: Traverse the nodes at each declaration level in the AST structure and classify them according to their type and structural characteristics. Divide the nodes into corresponding code block types, including functions, member variables, enumeration values, inner classes, constructors, initializers, and detached comments. The identified inner classes are recursively partitioned to ensure that the nested structure of the inner classes is analyzed and categorized.

3. The conflict code block detection method according to claim 2, characterized in that, In step S2, a unique code block signature is generated based on the structural characteristics of the code block to identify and distinguish the code block, including: The complete class name of each code block is recursively confirmed as the parent class name of the code block. When the code block is an inner class, the path of the complete class name is formed by including all the parent class names of the inner class. Assign a specific prefix symbol based on the code block type to help identify the type of code block; For each code block type, a corresponding code block name is generated. The code block name of the function code block and the constructor consists of the corresponding identifier plus the parameter list. The code block name of the initializer and the free comment uses the first 8 bits of the hash value generated by the MD5 algorithm using the content digest. The member variable, the enumeration value and the inner class directly use their names as the code block name. The unique code block signature is formed by combining the parent class name, prefix symbol, and code block name, and is used for code block identification, matching, and conflict detection.

4. The conflict code block detection method according to claim 1, characterized in that, In step S3, the correspondence includes no change, update, insertion, deletion, movement, and movement and update.

5. The conflict code block detection method according to claim 4, characterized in that, In step S3, the calculation steps for the content similarity are as follows: The code was reconstructed using AST parsing tools to unify the content format of the code blocks. Determine whether the lengths of the two code blocks being compared have reached a preset threshold; When the length of the code block reaches a preset threshold, the content similarity is calculated by the ratio of the Levenstein distance between the two code blocks to the maximum length of the two code blocks. When the length of the code block does not reach the preset threshold, the content similarity is calculated by the ratio of the length of the longest common substring of the two code blocks to the maximum length of the two code blocks.

6. The conflict code block detection method according to claim 5, characterized in that, In step S3, a correspondence is established by comparing the parent node, signature, and content similarity of each code block, and code blocks with potential conflicts are detected and marked, including: By comparing the parent node, signature, and content similarity of the code blocks between the modified branch file and the original file, a correspondence between each modified branch file and the original file is established; wherein, the correspondence involves at least two correspondences between the modified branch file and the original file. Merge all the modified branch files; If at least two of the modified branch files correspond to the original file in a manner that is any one of the opposing relationships of deletion, update, insertion, move, and move and update, then the potential conflict exists during the merging process. When only one of the modified branch files corresponds to the original file in the manner of update, insertion, deletion, move, or move and update, and the correspondence between the remaining modified branch files and the original file is unchanged, or when the correspondence between all the modified branch files and the original file is deletion, then there is no potential conflict during the merging process.

7. A potential conflict code block detection system based on AST partitioning and pruning, employing the conflict code block detection method as described in any one of claims 1 to 6, characterized in that, include: The response module is used to respond to conflict code block detection requests. The data processing module is used to parse the original file and at least one modified branch file using an AST parsing tool according to the conflict code block detection request, and generate a corresponding AST structure; divide the AST structure into several independent code blocks, and generate a unique code block signature based on the structural characteristics of the code blocks to identify and distinguish the code blocks. The results output module is used to traverse the code blocks in the original file and the modified branch file, establish a correspondence by comparing the parent node, signature and content similarity of each code block, detect and mark code blocks with potential conflicts, wherein the correspondence includes no change, update, insertion, deletion, move and move and update.

8. The potential conflict code block detection system according to claim 7, characterized in that, The data processing module includes: The code block partitioning unit is used to traverse the nodes of each declaration level in the AST structure and classify them according to the type and structural characteristics of the nodes, dividing the nodes into corresponding code block types, including functions, member variables, enumeration values, inner classes, constructors, initializers and detached comments; the identified inner classes are recursively partitioned to ensure that the nested structure of the inner classes is analyzed and classified. The signature generation unit recursively confirms the complete class name of each code block as the parent class name of the code block. When the code block is an inner class, it includes all the parent class names of the inner class to form the path of the complete class name. It assigns a specific prefix symbol according to the code block type to help identify the type of code block. It generates a corresponding code block name for each code block type. It combines the parent class name, prefix symbol, and code block name to form a unique code block signature for code block identification, matching, and conflict detection.

9. The potential conflict code block detection system according to claim 8, characterized in that, The results output module includes: The detection unit is used to determine the correspondence between the code blocks in the original file and the modified branch file; A marking unit is used to establish a correspondence between each modified branch file and the original file by comparing the parent node, signature, and content similarity of the code blocks between the modified branch file and the original file; wherein the correspondence involves at least two correspondences between the modified branch files and the original file; during the merging of all modified branch files; if at least two correspondences between the modified branch files and the original file are any one of the opposing relationships of deletion, update, insertion, move, and move and update, then the potential conflict exists in the merging process; if only one correspondence between the modified branch file and the original file is update, insertion, deletion, move, or move and update, and the correspondences between the remaining modified branch files and the original file are unchanged, or if the correspondence between all modified branch files and the original file is deletion, then the potential conflict does not exist in the merging process.

10. The potential conflict code block detection system according to claim 8, characterized in that, The content similarity is determined by reconstructing the code using an AST parsing tool to unify the content format of the code blocks; it is then determined whether the lengths of the two compared code blocks reach a preset threshold; when the code block lengths reach the preset threshold, the content similarity is calculated using the ratio of the Levinstein distance between the two code blocks to the maximum length of the two code blocks; when the code block lengths do not reach the preset threshold, the content similarity is calculated using the ratio of the length of the longest common substring of the two code blocks to the maximum length of the two code blocks.