A directed graph-based code repository code block level conflict sorting and grouping method

By sorting and grouping code block-level conflicts in code repository based on directed graphs, the problem of inefficient conflict resolution when merging code repository branches in software development is solved, and more efficient conflict handling and compilation order recommendation is achieved.

CN115098109BActive Publication Date: 2024-11-22NANJING UNIV OF POSTS & TELECOMM
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210726119.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-24
Publication Date
2024-11-22
Estimated Expiration
2042-06-24

AI Technical Summary

Technical Problem

In software development, a large number of conflicts often occur when merging code warehouse branches, especially unstructured mergers can lead to false positives. The existing technology is inefficient when dealing with conflicts, especially when there are many conflicts and many lines of code. , resulting in a long time in conflict resolution.

Method used

Using directed graph-based method, the code block-level conflicts in the code repository are sorted and grouped. By constructing a dependency graph, traversing nodes to sort, and the conflicting code blocks in the same graph are allocated to the same group for developers to Resolve conflicts in an orderly manner. The specific steps include a method of extracting conflict files, constructing a dependency graph, merging graphs of different branches, traversing nodes to determine the conflict sort, and grouping the conflicts.

Benefits of technology

Improves the efficiency of conflict resolution, avoids repeated modifications caused by dependency errors, saves time, and allows separate modules to be compiled first after resolving a grouped conflict, thereby improving the efficiency of problem solving.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115098109B_ABST
    Figure CN115098109B_ABST
Patent Text Reader

Abstract

A method for sorting and grouping code block level conflicts in a code repository based on a directed graph, first extracts the list of conflicting files, the method names in the conflicting files, and the information of the conflicting code snippets and saves them; then constructs a dependency graph for all methods in the conflicting files on different branches; secondly, compares the nodes in the dependency graph and merges the dependency graphs constructed on different branches; then traverses the dependency graph, compares the full path name of the file, the method name, the start and end line numbers of the method carried by the node with the saved ones, and saves the full path name and method name of the conflicting file that meets the conditions according to the node sequence number from large to small; finally, the conflicting methods in the same dependency graph are grouped into the same group. This method can effectively sort the code block level existing in the current code repository, and effectively group the conflicts at the code block level to help developers solve conflicts in an orderly manner.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of computer technology, in particular to the field of software technology, and specifically relates to a code warehouse code block level conflict sorting and grouping method based on a directed graph. Background Art

[0002] In modern software development, developers rely on version control systems like Git to collaborate in branch-based development work. One disadvantage of this working model is that conflicts occur when merging contributions from different developers, reducing the efficiency of collaboration and introducing potential vulnerabilities. This situation becomes worse as refactoring becomes popular in software development and development, and a higher number of conflicts occur.

[0003] However, common problems in conflict merges are: for unstructured merges, it treats the code as plain text, so as long as the developer modifies the same line of code, a conflict will be reported, and there will be a large number of false positives in this case; for structured merges, it will reduce some false positives. But no matter which merge method is used, they will solve a large number of conflicts at once, which will take a lot of time, especially when there are a large number of conflicts and a large number of lines of code. This is the main challenge faced when merging code repository branches.

[0004] An effective solution to these problems is to group all the conflicts at the code block level into the same group. After the conflicts in the same group are resolved, the individual modules can be compiled first when all the problems are resolved, without having to wait for all conflicts to be resolved before compiling the entire project. This function of sorting conflicts at the code block level before resolving them should analyze and sort the full path names and method information of the nodes in the graph, accurately sort the conflicts at the code block level, and group the conflicts at the code block level in the same graph into the same group, helping developers to resolve conflicts in an orderly manner.

[0005] However, due to the dependencies between methods in the files of the code repository, the above solution does not actually achieve good results when the dependencies between methods in the files are relatively complex, and the efficiency of the conflict resolution process is low, which has certain shortcomings. Summary of the invention

[0006] The main work of the present invention is to propose a method for sorting code block-level conflicts occurring within a file based on a directed graph and grouping code block-level conflicts. First, the present invention focuses on the order of resolving code block-level conflicts in a code repository and grouping code block-level conflicts. First, the methods in all files on different branches in the code repository are converted from files to directed dependency graphs. Secondly, the graphs on different branches are merged. Then, the nodes in the graph are traversed using a graph traversal algorithm, and the code block-level conflicts are sorted according to the order in which the nodes are visited. After the sorting is completed, the code block-level conflicts are assigned to different groups based on whether they appear in the same graph.

[0007] A method for sorting and grouping code block level conflicts in a code repository based on a directed graph comprises the following steps:

[0008] Step 1: Extract all methods in the project conflict files in the code repository;

[0009] Step 2: construct a dependency graph based on the dependencies between methods. A graph should be constructed for each branch in the code repository.

[0010] Step 3, construct a new graph based on the dependency graph, in which the nodes contain out-degree, in-degree, full file path name, sequence number, method name, and line number where the method starts and ends;

[0011] Step 4: Obtain conflict information for the merge scenario in the code repository;

[0012] Step 5: sort each node in the graph, traverse the nodes in the graph to screen, and ensure the uniqueness of each node;

[0013] Step 6, merge the graphs on different branches and then match them to obtain a merged and matched graph;

[0014] Step 7, traverse the merged graph, and according to the size of the sequence number in the node, save the full path name of the conflicting file and the name of the conflicting method according to the node sequence number from large to small to achieve a sorting effect;

[0015] Step 8, traverse the merged graph, group the conflicting methods that appear in the same graph into the same group, and complete the final sorting and grouping.

[0016] Furthermore, in step 1, a list of conflicting files, all method names within the conflicting files, and the start and end line numbers of the conflicting code snippets are extracted.

[0017] Furthermore, in step 2, a list of conflicting files, all method names within the conflicting files, and the start and end line numbers of the conflicting code snippets are extracted.

[0018] Furthermore, in step 3, in the newly constructed graph, the sequence number is initially zero, the in-degree represents the number of methods that depend on this method, the out-degree represents the number of other methods that this method depends on, the edges in the graph represent the dependency relationship between two methods, and the directed edges point from one method to the method it depends on.

[0019] Furthermore, in step 5, the nodes with in-degree zero are traversed. Each time a point is reached, the in-degree of the node is increased by one, and the sequence number is also increased by one. If a node is reached from different in-degree zero nodes and the number of edges reaching this node is different, that is, the sequence number of this node is of different sizes, the larger one is retained and the smaller one is discarded to ensure the uniqueness of the sequence number of each node.

[0020] Furthermore, in step 6, the dependency graphs on different branches are merged into one graph, and traversal is performed starting from the node with in-degree zero for matching. The condition for successful matching is that the full path name and method name of the file carried by the node are the same as the full path name and method name of the file in the conflict file list. When the match is successful, the larger sequence number in the node is retained. For nodes that are not successfully matched, it means that the file content on different branches has been added or deleted. The node needs to be inserted into the merged graph according to its position relative to other nodes in the graph on its branch.

[0021] Furthermore, in step 7, the merged graph is traversed, and when the full file path name and method name in the node are the same as the full file path name and method name in the conflict file list, and the start and end line numbers of the conflicting code fragment are within the start and end line number range of the method, the full file path name and method name in the node are saved according to the node sequence number size from large to small.

[0022] The beneficial effects achieved by the present invention are as follows: when there are a large number of conflicts, the present invention can sort the conflicts and recommend an effective order for resolving conflicts to developers, thereby improving the efficiency of resolving conflict problems and avoiding repeated modifications caused by incorrect processing order of two conflicting blocks with dependencies, thereby saving time. Grouping can achieve the goal that the conflicts of a certain functional module can be processed in advance through compilation, thereby improving the efficiency of problem solving. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Figure 1 The present invention is a flowchart of constructing a dependency graph for methods in a file in an embodiment of the present invention.

[0024] Figure 2 The figure is a schematic diagram of the flow chart of code block level conflict sorting in the embodiment of the present invention.

[0025] Figure 3A schematic diagram of generating conflict sorting results based on a dependency graph in an embodiment of the present invention. DETAILED DESCRIPTION

[0026] The technical solution of the present invention is further described in detail below in conjunction with the accompanying drawings.

[0027] The present invention proposes a code repository code block level conflict sorting and grouping method based on a directed graph, which specifically includes the following steps:

[0028] Step 1: Extract the list of conflicting files, all method names in the conflicting files, and the start and end line numbers of the conflicting code snippets from the project in the code repository.

[0029] Step 2: Analyze the internal methods of the conflicting files on each branch in the code repository according to the files imported in the Java file and the dependencies in the pom file. The files imported in the Java file are all the files that this file depends on. Construct a dependency graph. Each node in the graph represents a method. The graph contains the file path and method name.

[0030] Step 3, construct a new graph based on the dependency graph in step 2, because the analysis of dependencies and the analysis of conflicting code blocks are not processed together. In addition, in order to facilitate the matching of the collected conflict information with the nodes, it is necessary to establish new nodes and traverse the old graph. The graph is constructed according to the order in which the nodes in the old graph are visited and the edges between the nodes. The structure of the new graph is the same as the old graph, but the difference is that the nodes carry more information. The nodes in the graph contain out-degree, in-degree, full file path name, sequence number, method name, method start and end line numbers, and conflicting code fragment line numbers. The sequence numbers are initially zero. The in-degree indicates the number of methods that depend on this method, and the out-degree indicates the number of other methods that this method depends on. The edges in the graph indicate that there is a dependency relationship between two methods. Because a method may depend on multiple methods, there will be multiple directed edges pointing to this node, and there will also be multiple directed edges from one node to different nodes.

[0031] Step 4: For the merge scenario in the code repository, obtain the conflict information, which includes the path of the conflicting file and the information of the conflicting method. Save the information of all the conflicting methods and the information of the file where the method is located into a file.

[0032] Step 5, sort each node in the graph. In the project, methods will eventually depend on some basic methods. A node with an in-degree of zero means that no method depends on this node, that is, these methods no longer depend on other methods. Therefore, the dependency graph composed of all methods must have a node with an in-degree of zero, and there is more than one point with an in-degree of zero. Therefore, we must start the traversal from these nodes with an in-degree of zero. Every time we reach a point, the in-degree of the node increases by one, and the sequence number also increases by one. If a node can be reached from different nodes with an in-degree of zero and the number of edges reaching this node is different, that is to say, the sequence number of this node has different sizes, choose to keep the larger one and discard the smaller one to ensure the uniqueness of the sequence number of each node.

[0033] Step 6: Merge the graphs of each branch in the code repository, match them according to the full path name and method name of the file carried in the node, and retain the successfully matched ones. If there are nodes that are not successfully matched, it means that the file content has changed. The unmatched nodes need to be inserted into the merged graph according to their relative positions to other nodes in the graph of the branch where they are located.

[0034] Step 7, traverse the merged graph to sort it, compare the full path name of the file where the conflicting method is located, the method name and the start and end line numbers of the conflicting code fragment collected in step 1 with the full path name of the file, the method name and the start and end line numbers of the method carried in the node, and collect the full path name and method information of the successfully matched file into the file according to the node number from large to small.

[0035] Step 8: Group the conflicts at the code block level. A project contains multiple modules, each with different functions. If there is dependency between modules, the files in the two modules will appear in the same graph. If there is no dependency between modules, the files in the two modules will exist in different graphs. Therefore, a project will have multiple graphs. Traverse each graph and group the conflicting files in each graph into the same group.

[0036] In step 1, a list of conflicting files, the full path names of the files, the conflicting code snippets, and the start and end line numbers of these conflicting code snippets are extracted from the project, and this information is saved in a file as input in the subsequent step of sorting the conflicting methods.

[0037] In step 2, the node of the dependency graph represents a method; the edge in the graph represents the dependency relationship between two methods. The edge points from one node to the node it depends on. A node may have multiple edges pointing to it based on the dependency relationship, and there may also be multiple edges starting from this node and pointing to other nodes.

[0038] In step 6, the dependency graphs on different branches are merged, and the comparison starts from the node with in-degree zero. The condition for node matching is that the full path name of the file carried by the node is the same and the method name is the same. If the node matches successfully, the node with a larger sequence number is copied as the new node. If the node does not match successfully, it is inserted into the merged graph according to its relative position with other nodes in the graph on its branch.

[0039] In step 7, the graph merged in step 6 is traversed, starting from the node with in-degree zero, and the information carried by each node is compared with the full path name, method name, and conflict code snippet information of the file where the code block-level conflict is located collected in step 1. If the full path name and method name of the file carried in the node exist in the conflict file list, and the start and end line numbers of the conflict code snippet saved in the conflict file list are within the start and end line number range of the method carried in the node, then the node is saved in the collection, and the saving order is from large to small according to the node serial number size. The larger the node serial number, the earlier the code block-level conflict should be processed, and the smaller the node serial number, the later the code block-level conflict should be processed.

[0040] In step 8, the conflicts at the code block level are grouped. The purpose of grouping is to resolve the conflicts in a group so that a single module can be compiled first. A project contains multiple modules. There are two situations between modules: one is that there is a dependency, and the other is that there is no dependency. Therefore, a project will construct multiple dependency graphs, create multiple groups, traverse each graph, and add the code block level conflicts that appear in the same graph to the same group to complete the grouping.

[0041] The work and contributions of the present invention are as follows:

[0042] 1. Get a list of conflicting files, all method names inside the conflicting files, and the start and end line numbers of the conflicting code snippets.

[0043] 2. Construct a dependency graph between methods. In this step, for multiple branches in the code repository, a dependency graph must be constructed for each branch. Because the method bodies in the files on the branches are different, the file dependency graphs constructed by different branches will be different. A node in the graph represents a method in the file.

[0044] 3. Construct a new graph based on the dependency graph. The nodes in the graph contain out-degree, in-degree, full file path name, sequence number, method name, line numbers of the start and end of the method, and line numbers of the conflicting code fragments. The in-degree indicates the number of methods that depend on this method, and the out-degree indicates the number of other methods that this method depends on. The edges in the graph indicate that there is a dependency relationship between two methods.

[0045] 4. Merge the directed graphs on different branches. Merge the graphs of each branch in the code repository. Match them according to the full path name and method name of the file carried in the node. Keep the matched ones. If there are nodes that are not matched successfully, insert them into the merged graph according to their positions relative to other nodes in the graph before the merge.

[0046] 5. Sort the conflicts at the code block level, traverse the directed graph, and compare the collected full path names, method names, and start and end line numbers of the conflicting files with the full path names, method names, and start and end line numbers of the methods carried in the nodes. If the full path names and method names of the files are the same and the start and end line numbers of the conflicting code fragments are within the range of the start and end line numbers of the methods in the nodes, then save the full path names and method information of the conflicting files in descending order of the sequence numbers in the nodes. The larger the sequence number of the node, the earlier the code block-level conflict should be processed, and the smaller the sequence number, the later the code block-level conflict should be processed.

[0047] 6. Group the conflicts at the code block level. The purpose of grouping is to enable a single module to be compiled first after resolving the conflicts in a group. A Java project contains multiple modules. There are two situations between modules. One is that there is a dependency relationship, and multiple modules together form a dependency graph. The other is that there is no dependency relationship. For the case where there is no dependency between modules, one module corresponds to a dependency graph, so a project will construct multiple independent graphs, each graph corresponds to a group. Each graph is traversed, and the conflicting methods in the same graph are added to the same group. After the code block level conflicts in each group are resolved, it means that the module can be compiled independently.

[0048] The above description is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiment. Any equivalent modifications or changes made by ordinary technicians in this field based on the contents disclosed by the present invention should be included in the protection scope recorded in the claims.

Claims

1. A code repository code block level conflict sorting and grouping method based on a directed graph, characterized by: The method comprises the following steps: Step 1: Extract all methods in the project conflict files in the code repository; Step 2: construct a dependency graph based on the dependencies between methods. A graph must be constructed for each branch in the code repository. In step 2, extract the list of conflicting files, all method names in the conflicting files, and the start and end line numbers of the conflicting code snippets; Step 3, construct a new graph based on the dependency graph, in which the nodes contain out-degree, in-degree, full file path name, sequence number, method name, and line number where the method starts and ends; In step 3, in the new graph constructed, the sequence number is initially zero, the in-degree represents the number of methods that depend on this method, the out-degree represents the number of other methods that this method depends on, and the edges in the graph represent the dependency relationship between two methods. A directed edge points from a method to the method it depends on. Step 4: Obtain conflict information for the merge scenario in the code repository; Step 5: sort each node in the graph, traverse the nodes in the graph to screen, and ensure the uniqueness of each node; In step 5, traverse the nodes with zero in-degree. Every time you reach a point, the in-degree of the node increases by one, and the sequence number also increases by one. If you reach a certain node from different nodes with zero in-degree and the number of edges reaching this node is different, that is, the sequence numbers of this node are different, choose to keep the larger one and discard the smaller one to ensure the uniqueness of the sequence number of each node; Step 6, merge the graphs on different branches and then match them to obtain a merged and matched graph; Step 7, traverse the merged graph, and according to the size of the sequence number in the node, save the full path name of the conflicting file and the name of the conflicting method according to the node sequence number from large to small to achieve a sorting effect; Step 8, traverse the merged graph, group the conflicting methods that appear in the same graph into the same group, and complete the final sorting and grouping.

2. According to the directed graph-based code repository code block level conflict sorting and grouping method according to claim 1, it is characterized by: In step 1, a list of conflicting files, all method names within the conflicting files, and the start and end line numbers of the conflicting code snippets are extracted.

3. According to the directed graph-based code repository code block level conflict sorting and grouping method according to claim 1, it is characterized by: In step 6, the dependency graphs on different branches are merged into one graph, and traversal is performed starting from the node with in-degree zero for matching. The condition for successful matching is that the full path name and method name of the file carried by the node are the same as the full path name and method name of the file in the conflict file list. When the match is successful, the larger sequence number in the node is retained. For nodes that are not matched successfully, it means that the file content on different branches has been added or deleted. The node needs to be inserted into the merged graph according to its position relative to other nodes in the graph on its branch.

4. According to the directed graph-based code repository code block level conflict sorting and grouping method according to claim 1, it is characterized by: In step 7, the merged graph is traversed. When the full file path name and method name in the node are the same as those in the conflict file list, and the start and end line numbers of the conflicting code snippet are within the start and end line number range of the method, the full file path name and method name in the node are saved according to the node sequence size from large to small.