Code merging method and device, electronic equipment and medium

By inputting the syntax tree of branch code into merge suggestions to generate models, generating merge suggestions and performing code merging processing, the problems of low efficiency and high error rate when manually checksum merging code are solved, and more efficient and accurate code merging is achieved.

CN119806626APending Publication Date: 2025-04-11CHINA TELECOM ARTIFICIAL INTELLIGENCE TECHNOLOGY (BEIJING) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411808716.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-09
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

In the process of large-scale software development, manual checksum merge branch code is inefficient and has high error rate, especially when the code volume is large and the logic is complex.

Method used

Reduce manual intervention by obtaining the syntax tree of branch code and entering pre-trained merge suggestions to generate the model, generate merge suggestions and perform code merge processing based on the suggestions.

Benefits of technology

It improves the efficiency and accuracy of code merging processing, reduces the manual error rate, and makes the code merging process in large-scale software development more efficient and reliable.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119806626A_ABST
    Figure CN119806626A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a code merging method and device, electronic equipment and a medium. The method comprises the steps that whether a branch conflict exists between a first branch code and a second branch code or not is judged; if the branch conflict exists between the first branch code and the second branch code, obtaining a first conflict code in the first branch code, and obtaining a second conflict code in the second branch code; syntax trees of the first branch code and the second branch code are generated respectively; inputting the syntax tree of the first branch code, the syntax tree of the second branch code, the first conflict code and the second conflict code into a combination suggestion generation model obtained by pre-training, and obtaining a combination suggestion generated by the combination suggestion generation model; and according to the merging suggestion, performing code merging processing on the first branch code and the second branch code to obtain a merged code. According to the embodiment of the invention, the merging suggestions are obtained according to the syntax tree and the conflict codes, so that the efficiency and accuracy of code merging are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a code merging method, device, electronic device and computer-readable storage medium. Background Art

[0002] With the continuous updating and iteration of software development technology and the increasing demand of the Internet market, software has gradually developed from single functions to diversified and integrated directions, and large-scale software has emerged. Large-scale software development is a highly complex task. In order to ensure the successful development of large-scale software projects, the development team needs to have rich technical experience, rigorous process management and efficient collaboration capabilities.

[0003] During the development process, after multiple teams complete branch codes of different functions, these branch codes are merged. In the related art, if branch conflicts occur during the merging process, it is usually necessary to manually verify the branch codes and modify the branch codes to resolve the branch conflicts and complete the merging process.

[0004] When the branch code to be verified is large in size and has complex logic, manual verification of the code is inefficient and has a high error rate. Summary of the invention

[0005] In view of the above problems, embodiments of the present invention are proposed to provide a code merging method, device, electronic device and computer-readable storage medium that overcome the above problems or at least partially solve the above problems.

[0006] On the one hand, an embodiment of the present invention provides a code merging method, the method comprising:

[0007] Obtain a first branch code and a second branch code;

[0008] Determine whether there is a branch conflict between the first branch code and the second branch code;

[0009] If there is a branch conflict between the first branch code and the second branch code, obtaining a first conflict code in the first branch code, and obtaining a second conflict code in the second branch code;

[0010] Generating syntax trees of the first branch code and the second branch code respectively;

[0011] Inputting the syntax tree of the first branch code, the syntax tree of the second branch code, the first conflict code, and the second conflict code into a pre-trained merge suggestion generation model to obtain a merge suggestion generated by the merge suggestion generation model;

[0012] According to the merging suggestion, code merging processing is performed on the first branch code and the second branch code to obtain a merged code.

[0013] Optionally, the method further comprises:

[0014] Detecting whether there is an error in the merged code;

[0015] If there is an error in the merge code, inputting error information into the merge suggestion generation model;

[0016] Obtaining a merge suggestion generated again by the merge suggestion generation model according to the error information;

[0017] According to the regenerated merge suggestion, code merging processing is performed on the first branch code and the second branch code to obtain a merged code.

[0018] Optionally, the method further comprises:

[0019] determining a number of times erroneous information is input into the merge suggestion generation model;

[0020] When the number of times reaches the number threshold, the code merging process is terminated.

[0021] Optionally, before determining whether there is a branch conflict between the first branch code and the second branch code, the method further includes:

[0022] Get code standards;

[0023] Determine whether the first branch code and the second branch code meet the specification requirements according to the code specification;

[0024] If the first branch code or the second branch code does not meet the specification requirements, a violation document is generated to allow the user to determine whether to modify the first branch code or the second branch code.

[0025] Optionally, the method further comprises:

[0026] If there is no branch conflict between the first branch code and the second branch code, code merging processing is performed on the first branch code and the second branch code.

[0027] Optionally, the method further comprises:

[0028] If there is no error in the merged code, the first branch code or the second branch code is updated according to the merged code.

[0029] Optionally, the detecting whether the merged code has an error includes:

[0030] Performing a logic check on the merged code to determine whether there is a logic error in the merged code; and performing a function check on the merged code to determine whether there is a function error in the merged code.

[0031] On the other hand, an embodiment of the present invention provides a code merging device, the device comprising:

[0032] A first acquisition module, used to acquire a first branch code and a second branch code;

[0033] A conflict judgment module, used to judge whether there is a branch conflict between the first branch code and the second branch code;

[0034] a second acquisition module, configured to acquire a first conflicting code in the first branch code and acquire a second conflicting code in the second branch code if there is a branch conflict between the first branch code and the second branch code;

[0035] A syntax tree generation module, used to generate syntax trees of the first branch code and the second branch code respectively;

[0036] A first suggestion acquisition module is used to input the syntax tree of the first branch code, the syntax tree of the second branch code, the first conflict code, and the second conflict code into a pre-trained merge suggestion generation model to obtain a merge suggestion generated by the merge suggestion generation model;

[0037] The first merging processing module is used to perform code merging processing on the first branch code and the second branch code according to the merging suggestion to obtain a merged code.

[0038] On the other hand, an embodiment of the present invention provides an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the steps of the code merging method described above when executed by the processor.

[0039] On the other hand, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the code merging method described above are implemented.

[0040] The embodiments of the present invention include the following advantages:

[0041] First, determine whether there is a branch conflict between the first branch code and the second branch code. If there is a branch conflict between the two, obtain the first conflict code in the first branch code and the second conflict code in the second branch code. Generate syntax trees for the first branch code and the second branch code respectively, input the syntax tree of the first branch code, the syntax tree of the second branch code, the first conflict code and the second conflict code into a pre-trained merge suggestion generation model, and obtain a merge suggestion generated by the merge suggestion generation model. After the merge suggestion is generated by the merge suggestion generation model, the first branch code and the second branch code are directly merged according to the merge suggestion, which improves the efficiency of the code merging process compared to manual code analysis.

[0042] In addition, the syntax trees of the first branch code and the second branch code are input into the merge suggestion generation model, so that the merge suggestion generation model can more correctly understand the code structure and code logic based on the syntax trees. The conflicting code with branch conflicts is input into the merge suggestion generation model, so that the merge suggestion generation model can locate the conflict problem more quickly. By improving the efficiency of the merge suggestion generation model in generating merge suggestions and the correctness of the merge suggestions, code merging is made more efficient and accurate. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative labor.

[0044] Figure 1 is a flowchart of a code merging method provided by an embodiment of the present invention;

[0045] Figure 2 is an application flow chart of a code merging method provided by an embodiment of the present invention;

[0046] Figure 3 It is a structural block diagram of a code merging device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0047] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0048] In a multi-person collaborative development environment, each development team may be responsible for different functions or modules. After multiple teams complete branch codes for different functions, these branch codes are merged. Different branches are used to develop different functions or fix different vulnerabilities. By merging branches, these functions or fixes scattered on various branches can be integrated together to form a complete code base that contains all the latest changes.

[0049] In the related art, if a branch conflict occurs during the merge process, it is usually necessary to manually verify the branch code and modify the branch code to resolve the branch conflict and complete the merge process.

[0050] The embodiment of the present invention reduces manual workload by inputting branch codes and syntax trees corresponding to the branch codes into a model, generating merging suggestions from the model, and then performing code merging processing on the branch codes according to the merging suggestions. At the same time, the reference model improves the merging success rate.

[0051] Figure 1 The present invention provides a flowchart of the steps of a code merging method.

[0052] like Figure 1 As shown, the method may specifically include the following steps:

[0053] Step 101, obtaining a first branch code and a second branch code;

[0054] Git is a distributed version control system that can help developers develop and maintain code more efficiently. Git allows you to create multiple branches in a project and develop on different branches. Each developer can independently develop different functions on their own branches. In addition, Git can track file changes, record each modification, and use a hash algorithm to identify each modified version to ensure the uniqueness and integrity of each version. Developers can view the file history at any time to understand the details of each modification, and can trace back to any version to avoid incorrect modifications.

[0055] Branch merging is an important function in Git, which can merge different branches into one branch, making code management more flexible and efficient. Usually, after the user switches to the target branch, he specifies the branch to be merged, and Git will automatically merge the commits of the branch to be merged into the target branch.

[0056] Specifically, there is a pre-provided code repository, and there are at least two branch codes in the code repository. The user saves the address of the pre-provided code repository to the system, so that the system can access the code repository and obtain the code in the code repository.

[0057] Then, the user specifies a first branch and a second branch, both of which are used for code merging, one of the first branch and the second branch is a target branch, and the other is a merge branch.

[0058] In a code merge operation, the target branch refers to the target of the merge operation, which is used to receive the changes of the merge branch, while the merge branch refers to the branch merged into the target branch. Usually, after the code merge operation is completed, the target branch is retained and the merge branch can be deleted.

[0059] After the user specifies the first branch and the second branch to be merged, the system will automatically obtain the latest code of the first branch and the second branch for subsequent operations.

[0060] In some embodiments, before step 102, the method further includes:

[0061] Get code standards;

[0062] Determine whether the first branch code and the second branch code meet the specification requirements according to the code specification;

[0063] If the first branch code or the second branch code does not meet the specification requirements, a violation document is generated to allow the user to determine whether to modify the first branch code or the second branch code.

[0064] After the system obtains the first branch code and the second branch code, it will determine whether the first branch code and the second branch code meet the specification requirements according to the code specification, that is, check the code quality. By judging whether the first branch code and the second branch code meet the code specification, it can help developers discover and fix potential problems and vulnerabilities in advance, thereby improving the success rate of subsequent code merging.

[0065] The code specification may be a code specification customized by the user according to project requirements, or may be a general code specification set in advance by the system, which is not limited by the present invention.

[0066] In some embodiments, the static analysis tool ESLint is used to check the code quality and determine whether the code complies with the code specification. The ESLint plug-in system allows developers to write custom rules and extensions, so it has high flexibility and scalability and can meet various project requirements.

[0067] In other embodiments, other tools may also be used to perform code standard determination, which is not limited by the present invention.

[0068] If the first branch code or the second branch code is judged not to meet the specification requirements, a violation document will be generated, which includes the specific type of violation, the violation description, and the severity of the violation.

[0069] After the violation document is generated, it will be sent to the user, who will decide whether to modify the corresponding code part. The user can choose to ignore these violations and continue the subsequent merge operation. Or the user can choose to modify them and re-merge the code.

[0070] Step 102, determining whether there is a branch conflict between the first branch code and the second branch code;

[0071] A merge conflict refers to a situation where the system cannot automatically merge two different branches or versions of code and requires manual intervention. Merge conflicts usually occur when the same part of the code in two different branches is modified by the developer. The system finds that the same part of the same file has been modified and the modified content is inconsistent. It cannot automatically merge the changes, which will cause a merge conflict.

[0072] After the system obtains the first branch code and the second branch code, it will determine whether there is a branch conflict between the first branch code and the second branch code according to its detection mechanism.

[0073] Specifically, the system automatically compares the changes of the two branch codes, especially the same parts of the same files. If both branches modify the same part of the same file, and these modifications cannot be automatically merged, that is, it is impossible to determine which branch should keep the modifications made, then it is determined that there is a branch conflict between the first branch code and the second branch code.

[0074] In the related art, when a branch conflict occurs, a developer usually analyzes the conflicting code, manually edits the code, and retains or modifies the corresponding code portion to resolve the branch conflict.

[0075] In some embodiments, the method further comprises:

[0076] If there is no branch conflict between the first branch code and the second branch code, code merging processing is performed on the first branch code and the second branch code.

[0077] After determining that there is no branch conflict between the first branch code and the second branch code, the code of one branch is directly applied to the other branch to complete the code merging process.

[0078] When there is no branch conflict between the first branch code and the second branch code, the code merge process is performed directly without calling the merge suggestion generation model, which saves model resources and controls costs.

[0079] Step 103: if there is a branch conflict between the first branch code and the second branch code, a first conflict code in the first branch code is obtained, and a second conflict code in the second branch code is obtained;

[0080] When it is determined that there is a branch conflict between the first branch code and the second branch code, the specific code in which the branch conflict exists in the first branch code and the second branch code is located, and the starting position and the ending position of the conflicting code are marked.

[0081] According to the located specific codes having branch conflicts in the first branch code and the second branch code, the first conflicting code in the first branch code and the second conflicting code in the second branch code are respectively acquired.

[0082] It is worth noting that the conflicting code includes the code where the branch conflict occurs and the code called by the code where the branch conflict occurs. The conflicting code takes the method as the smallest unit.

[0083] The first conflict code and the second conflict code are used to input into the merge suggestion generation model to help the merge suggestion generation model generate more accurate merge suggestions.

[0084] Step 104, generating syntax trees of the first branch code and the second branch code respectively;

[0085] A syntax tree is a tree structure used to represent the syntax structure of program code. During the program compilation process, the syntax tree is one of the intermediate representations generated by the compiler. In compilers and interpreters, syntax trees are often used to convert source code into executable form or interpret source code. Syntax trees provide an intuitive way to display the hierarchy and syntax relationships of code, which helps improve the readability and maintainability of code during code reading, debugging, and maintenance.

[0086] In some embodiments, the ANTLR parsing tool is used to parse the first branch code to obtain the syntax tree of the first branch code, and the second branch code is parsed to obtain the syntax tree of the second branch code. ANTLR can generate an efficient parser according to the grammar rules defined by the user, and process complex grammatical structures, including context-free grammars and context-dependent grammars. At the same time, ANTLR supports a variety of programming languages, including Java, C++, Python, C#, JavaScript, etc., so as to meet various project requirements and select the appropriate language for development.

[0087] In other embodiments, other parsing tools may also be used to generate a syntax tree, and the present invention is not limited to this.

[0088] In some embodiments, after parsing the syntax tree according to the first branch code and the second branch code, the syntax tree format is converted into XML format. XML format data can be directly used as input data for the merge suggestion generation model, so that data does not need to be changed during input, which improves input efficiency.

[0089] The syntax tree of the first branch code and the syntax tree of the second branch code are used to input the merge suggestion generation model to help the merge suggestion generation model understand the code structure and code logic of the first branch and the second branch, thereby generating more accurate merge suggestions.

[0090] Step 105, inputting the syntax tree of the first branch code, the syntax tree of the second branch code, the first conflict code, and the second conflict code into a pre-trained merge suggestion generation model to obtain a merge suggestion generated by the merge suggestion generation model;

[0091] The syntax trees of the first branch code and the second branch code are input into the merge suggestion generation model, so that the merge suggestion generation model can more correctly understand the code structure and code logic based on the syntax trees. The first conflict code and the second conflict code with branch conflicts are input into the merge suggestion generation model, so that the merge suggestion generation model can locate the conflict problem more quickly. Thereby, the efficiency of the merge suggestion generation model in generating merge suggestions is improved, and the accuracy of the merge suggestions is also improved.

[0092] The merge suggestion generation model in the embodiment of the present invention is trained in the following way:

[0093] The present invention selects to use the 405 billion parameters of Llama3.1 as the basic model, and then performs targeted training on it to obtain a merged suggestion generation model.

[0094] Llama3.1 supports an extended context length of 128K, which enables the model to process longer text inputs and is suitable for long text summaries, complex conversations, and multi-step problem solving. At the same time, the open source nature of Llama3.1 allows it to be fine-tuned into other models and supports deployment in any environment, with high customizability and flexibility.

[0095] In other embodiments, other models may also be used as basic models, and the present invention is not limited to this.

[0096] 1) Sample collection

[0097] The sample data sources of the merge suggestion generation model come from two parts. One part comes from GitHub's high-quality code merge records. We screen these records to obtain records that resolve branch conflicts, which total about 300,000. This part of data can be guaranteed to be basically correct and is used as training data.

[0098] The other part is the records of resolving branch conflicts when merging projects in actual company projects, which totals about 2,700 records. This part of data is used as benchmark data to ensure the correctness of the results and is used as fine-tuning data and test data.

[0099] 2) Training data production

[0100] The collected sample data is parsed using the ANTLR parsing tool in the syntax tree format to obtain a syntax tree.

[0101] In addition, the syntax tree parsed by ANTLR is converted into XML format and can be directly input into the model as input data, eliminating the need to modify or adjust the data itself, reducing extra work caused by incompatible data formats or the need to adjust data to fit the model.

[0102] 3) Data pre-training

[0103] The loss function used in the embodiment of the present invention is:

[0104]

[0105] Where J is the loss function, p(x i ) is the prediction result of the model, q(x i ) is the result of training data, μ is the penalty coefficient, and 0.15 is used as the penalty rate in the present invention. is the number of logical errors.

[0106] The cross entropy loss function is used to calculate the difference between the predicted merged result and the manually merged target. The merged loss and the logical detection loss are weighted and merged to optimize the accuracy of the merged result and the correctness of the logic during training.

[0107] In addition, the embodiment of the present invention uses a masked language model approach to help the merged suggestion generation model grasp the syntax, common programming patterns and styles of the code.

[0108] The training data set obtained in step 2) is used to complete the model training according to the set loss function to obtain the merge suggestion generation model. Through the benchmark training of 300,000 data, the merge suggestion generation model can better understand the syntax tree, so as to have better targeted processing capabilities for branch merging.

[0109] 4) Fine-tune the model

[0110] We used a sample set of records from solving branch conflicts in some actual company projects to further fine-tune the parameters of the merge suggestion generation model. During the fine-tuning process, the merge suggestion generation model learned how to identify branch conflicts during code merges and provide more correct merge suggestions.

[0111] 5) Model testing

[0112] We used the remaining branch conflict resolution records of actual company projects to test the merge suggestion generation model. By comparison, we found that the correctness of merges increased by 20% when the syntax tree was input compared to when the syntax tree was not input.

[0113] In addition, during the actual use of the merge suggestion generation model, data can be collected regularly to retrain and fine-tune the merge suggestion generation model to continuously improve its ability to merge codes and resolve conflicts.

[0114] Step 106: According to the merging suggestion, code merging processing is performed on the first branch code and the second branch code to obtain a merged code.

[0115] The merge suggestion includes conflict analysis and modification suggestion, wherein the conflict analysis includes analysis of the cause of the branch conflict and the modification suggestion includes a specific modification method for the first conflict code or the second conflict code.

[0116] Conflict analysis can help users better understand the causes of branch conflicts, while modification suggestions are specific modification methods given by the merge suggestion generation model.

[0117] Specifically, the specific modification method given by the merge suggestion generation model may be to modify the first conflicting code alone, may be to modify the second conflicting code alone, or may be to modify the first conflicting code and the second conflicting code together.

[0118] According to the specific modification method given by the merge suggestion generation model, after modifying the first branch code or the second branch code, the code of one branch is applied to the other branch to complete the code merging process and obtain the merged code.

[0119] In some embodiments, the method further comprises the following steps:

[0120] Detecting whether there is an error in the merged code;

[0121] If there is an error in the merge code, inputting error information into the merge suggestion generation model;

[0122] Obtaining a merge suggestion generated again by the merge suggestion generation model according to the error information;

[0123] According to the regenerated merge suggestion, code merging processing is performed on the first branch code and the second branch code to obtain a merged code.

[0124] After the merge code is obtained according to the merge suggestion given by the merge suggestion generation model, the merge code needs to be tested. By testing whether there is an error in the merge code, the correctness of the merge suggestion given by the merge suggestion generation model is verified.

[0125] If there is an error in the merge code, the error information is input to the merge suggestion generation model, which includes the error type and error description. The merge suggestion generation model analyzes the possible problems of the merge suggestions generated before based on the error information, and generates merge suggestions again based on these problems for a more comprehensive consideration. By combining error information and context, merge suggestions are generated multiple times, which improves the correctness of merge suggestions.

[0126] In some embodiments, the detecting whether the merged code has an error comprises the following detailed steps:

[0127] Performing a logic check on the merged code to determine whether there is a logic error in the merged code; and performing a function check on the merged code to determine whether there is a function error in the merged code.

[0128] Specifically, the logic check can be to compile the merged code using a compiler, and if the compilation is successful, there is no logic error. In other embodiments, other methods can also be used to perform the logic check, and the present invention is not limited to this.

[0129] Function detection can be to use existing unit test, integration test and code automation test model to test the merged code, if the test passes, there is no functional error. In other embodiments, other methods can also be adopted to perform function detection, and the present invention does not limit this.

[0130] Logic testing focuses on the implementation of the logical relationship and business rules within the code, while functional testing focuses on whether the functions of the code are correctly implemented according to the functional requirements. Through these two tests, it can be ensured that the code can meet user needs in both logic and function dimensions.

[0131] In some embodiments, the method further comprises:

[0132] The number of times that error information is input to the merge suggestion generation model is determined; when the number reaches a threshold, the code merge process is terminated.

[0133] Specifically, when there is an error in the merged code, the number of times the error information is input to the merge suggestion generation model will be recorded while the error information is input to the merge suggestion generation model. When the number of times the error information is input reaches a preset number threshold, the code merge process is terminated.

[0134] Terminating the code merging process means canceling the entire merging operation, and restoring the code data to the state before executing step 101 .

[0135] By setting the number threshold, it is possible to avoid the system falling into an endless loop of generating merge suggestions when there are always errors in the merge code. In some embodiments, the number threshold is set to 5 times. In other embodiments, the number threshold can be set to other values ​​according to actual needs, and the present invention is not limited to this.

[0136] In some embodiments, when the number of times the error information is input reaches a preset number threshold, the code merging process is terminated and the code merging operation is judged to have failed. Based on this process, the system generates an error report and sends it to the user. The error report includes detailed error information to help the user understand the cause of the error.

[0137] In some embodiments, the method further comprises:

[0138] If there is no error in the merged code, the first branch code or the second branch code is updated according to the merged code.

[0139] When it is determined through testing that the merged code generated according to the merge suggestion does not have errors, the first branch code or the second branch code is updated according to the merged code, thereby completing the entire code merge operation.

[0140] After the entire code merge operation is completed, the system generates a merge report and sends it to the user. The merge report includes the merged code snippets, test results, and any possible warnings to help users understand the status of the code merge.

[0141] The code merging method provided by the embodiment of the present invention first determines whether there is a branch conflict between the first branch code and the second branch code. If there is a branch conflict between the two, the first conflict code in the first branch code and the second conflict code in the second branch code are obtained. The syntax trees of the first branch code and the second branch code are respectively generated, and the syntax tree of the first branch code, the syntax tree of the second branch code, the first conflict code and the second conflict code are input into a pre-trained merge suggestion generation model to obtain a merge suggestion generated by the merge suggestion generation model. After the merge suggestion is generated by the merge suggestion generation model, the first branch code and the second branch code are directly subjected to code merging processing according to the merge suggestion, which improves the efficiency of the code merging processing compared to the manual code analysis method.

[0142] In addition, the syntax trees of the first branch code and the second branch code are input into the merge suggestion generation model, so that the merge suggestion generation model can more correctly understand the code structure and code logic based on the syntax trees. The conflicting code with branch conflicts is input into the merge suggestion generation model, so that the merge suggestion generation model can locate the conflict problem more quickly. By improving the efficiency of the merge suggestion generation model in generating merge suggestions and the correctness of the merge suggestions, code merging is made more efficient and accurate.

[0143] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0144] Figure 2 The present invention provides an application flow chart of a code merging method.

[0145] In order to enable those skilled in the art to better understand the embodiments of the present invention, Figure 2 , an example is used to illustrate the embodiment of the present invention:

[0146] 1) Enter the code repository address

[0147] The user enters the address of the pre-provided code repository in the system interaction interface, so that the system can access the code repository and obtain the code in the code repository.

[0148] 2) Specify the branch to be merged

[0149] The user specifies the branches that need to be merged, one of which is the target branch and the other is the merge branch.

[0150] 3) Code analysis and preprocessing

[0151] After the user specifies the target branch and merge branch, the system will obtain the latest code of the target branch and merge branch.

[0152] After obtaining the code, use the static analysis tool ESLint to check the code quality to ensure that the code meets the code standards set by the user in advance. If the user does not provide a code standard, the default code standard provided by the system will be used for checking.

[0153] 4) Conflict Detection

[0154] The system detects whether there is a conflict between the target branch code and the merge branch code. If there is no conflict between the target branch code and the merge branch code, the code merge operation is performed directly and the process ends.

[0155] 5) Calling the model

[0156] If the system detects that there is a conflict between the target branch code and the merge branch code, the syntax trees of the target branch and the merge branch are generated respectively. The generated syntax trees of the target branch and the merge branch and the conflicting codes of the target branch and the merge branch are input into the merge suggestion generation model to obtain the merge suggestion generated by the merge suggestion generation model.

[0157] 6) Perform the merge

[0158] Code merging is performed according to the merging suggestions generated by the merging suggestion generation model to obtain merged code.

[0159] 7) Save the merge record

[0160] The merging process and the merging suggestions generated by the merging suggestion generation model are recorded to facilitate subsequent analysis and improvement of the merging suggestion generation model.

[0161] 8) Logic detection

[0162] The merged code is compiled using a compiler. If an error occurs during compilation, the branch is rolled back. Based on the error information generated during compilation, a new merge suggestion is generated by the merge suggestion generation model, and the merge is executed again from step 6).

[0163] If the compilation is successful, it is determined that there are no logical problems in the merged code, and subsequent functional testing is performed on the merged code.

[0164] 9) Functional testing

[0165] Use the existing unit test, integration test and code automation test model to test the merged code. If an error occurs during the test, the branch will be rolled back. Based on the error information generated during the test, the merge suggestion generation model will regenerate a new merge suggestion and start the merge again from step 6).

[0166] If the detection is successful, it is determined that there are no functional problems with the merged code and subsequent operations are performed.

[0167] 10) Output the merged report

[0168] If the merged code has no logical or functional problems, the merge is successful and the target branch is updated based on the merged code. A merge report is generated at the same time, which includes the merged code snippets, test results, and any possible warnings to help users understand the status of the code merge.

[0169] Figure 3 It is a structural block diagram of a code merging device provided by an embodiment of the present invention.

[0170] like Figure 3 As shown, a code merging device provided by an embodiment of the present invention may specifically include the following modules:

[0171] A first acquisition module 201 is used to acquire a first branch code and a second branch code;

[0172] Specifically, there is a pre-provided code repository, and there are at least two branch codes in the code repository. The user saves the address of the pre-provided code repository to the system, so that the system can access the code repository and obtain the code in the code repository.

[0173] Then, the user specifies a first branch and a second branch, both of which are used for code merging, one of the first branch and the second branch being a target branch, and the other being a merge branch.

[0174] In a code merge operation, the target branch refers to the target of the merge operation, which is used to receive the changes of the merge branch, while the merge branch refers to the branch merged into the target branch. Usually, after the code merge operation is completed, the target branch is retained and the merge branch can be deleted.

[0175] After the user specifies the first branch and the second branch to be merged, the system will automatically obtain the latest code of the first branch and the second branch for subsequent operations.

[0176] A conflict determination module 202 is used to determine whether there is a branch conflict between the first branch code and the second branch code;

[0177] After the system obtains the first branch code and the second branch code, it will determine whether there is a branch conflict between the first branch code and the second branch code according to its detection mechanism.

[0178] Specifically, the system automatically compares the changes of the two branch codes, especially the same parts of the same files. If both branches modify the same part of the same file, and these modifications cannot be automatically merged, that is, it is impossible to determine which branch should keep the modifications made, then it is determined that there is a branch conflict between the first branch code and the second branch code.

[0179] A second acquisition module 203 is configured to acquire a first conflicting code in the first branch code and a second conflicting code in the second branch code if there is a branch conflict between the first branch code and the second branch code;

[0180] When it is determined that there is a branch conflict between the first branch code and the second branch code, the specific code in which the branch conflict exists in the first branch code and the second branch code is located, and the starting position and the ending position of the conflicting code are marked.

[0181] According to the located specific codes having branch conflicts in the first branch code and the second branch code, the first conflicting code in the first branch code and the second conflicting code in the second branch code are respectively acquired.

[0182] It is worth noting that the conflicting code includes the code where the branch conflict occurs and the code called by the code where the branch conflict occurs. The conflicting code takes the method as the smallest unit.

[0183] The first conflict code and the second conflict code are used to input into the merge suggestion generation model to help the merge suggestion generation model generate more accurate merge suggestions.

[0184] A syntax tree generating module 204, used to generate syntax trees of the first branch code and the second branch code respectively;

[0185] In some embodiments, the ANTLR parsing tool is used to parse the first branch code to obtain the syntax tree of the first branch code, and the second branch code is parsed to obtain the syntax tree of the second branch code. ANTLR can generate an efficient parser according to the grammar rules defined by the user, and process complex grammatical structures, including context-free grammars and context-dependent grammars. At the same time, ANTLR supports a variety of programming languages, including Java, C++, Python, C#, JavaScript, etc., so as to meet various project requirements and select the appropriate language for development.

[0186] The syntax tree of the first branch code and the syntax tree of the second branch code are used to input the merge suggestion generation model to help the merge suggestion generation model understand the code structure and code logic of the first branch and the second branch, thereby generating more accurate merge suggestions.

[0187] A first suggestion acquisition module 205 is used to input the syntax tree of the first branch code, the syntax tree of the second branch code, the first conflict code, and the second conflict code into a pre-trained merge suggestion generation model to obtain a merge suggestion generated by the merge suggestion generation model;

[0188] The syntax trees of the first branch code and the second branch code are input into the merge suggestion generation model, so that the merge suggestion generation model can more correctly understand the code structure and code logic based on the syntax trees. The first conflict code and the second conflict code with branch conflicts are input into the merge suggestion generation model, so that the merge suggestion generation model can locate the conflict problem more quickly. Thereby, the efficiency of the merge suggestion generation model in generating merge suggestions is improved, and the accuracy of the merge suggestions is also improved.

[0189] The first merging processing module 206 is used to perform code merging processing on the first branch code and the second branch code according to the merging suggestion to obtain a merged code.

[0190] The merge suggestion includes conflict analysis and modification suggestion, wherein the conflict analysis includes analysis of the cause of the branch conflict and the modification suggestion includes a specific modification method for the first conflict code or the second conflict code.

[0191] Specifically, the specific modification method given by the merge suggestion generation model may be to modify the first conflicting code alone, may be to modify the second conflicting code alone, or may be to modify the first conflicting code and the second conflicting code together.

[0192] According to the specific modification method given by the merge suggestion generation model, after modifying the first branch code or the second branch code, the code of one branch is applied to the other branch to complete the code merging process and obtain the merged code.

[0193] In some embodiments, the apparatus further comprises:

[0194] An error detection module, used to detect whether there is an error in the merged code;

[0195] In some embodiments, the error detection module includes:

[0196] A logic error detection submodule, used to perform logic detection on the merged code to determine whether there is a logic error in the merged code;

[0197] The functional error detection submodule is used to perform functional detection on the merged code to determine whether there is a functional error in the merged code.

[0198] Specifically, the logic check can be to compile the merged code using a compiler, and if the compilation is successful, there is no logic error. In other embodiments, other methods can also be used to perform the logic check, and the present invention is not limited to this.

[0199] Function detection can be to use existing unit test, integration test and code automation test model to test the merged code, if the test passes, there is no functional error. In other embodiments, other methods can also be adopted to perform function detection, and the present invention does not limit this.

[0200] Logic testing focuses on the implementation of the logical relationship and business rules within the code, while functional testing focuses on whether the functions of the code are correctly implemented according to the functional requirements. Through these two tests, it can be ensured that the code can meet user needs in both logic and function dimensions.

[0201] In some embodiments, the apparatus further comprises:

[0202] An information input module, used for inputting error information to the merge suggestion generation model if there is an error in the merge code;

[0203] A second suggestion acquisition module is used to obtain a merge suggestion generated again by the merge suggestion generation model according to the error information;

[0204] The second merging processing module is used to perform code merging processing on the first branch code and the second branch code according to the regenerated merging suggestion to obtain a merged code.

[0205] After the merge code is obtained according to the merge suggestion given by the merge suggestion generation model, the merge code needs to be tested. By testing whether there is an error in the merge code, the correctness of the merge suggestion given by the merge suggestion generation model is verified.

[0206] If there is an error in the merge code, the error information is input to the merge suggestion generation model, which includes the error type and error description. The merge suggestion generation model analyzes the possible problems of the merge suggestions generated before based on the error information, and generates merge suggestions again based on these problems for a more comprehensive consideration. By combining error information and context, merge suggestions are generated multiple times, which improves the correctness of merge suggestions.

[0207] In some embodiments, the apparatus further comprises:

[0208] A number determination module, used to determine the number of times erroneous information is input into the merge suggestion generation model;

[0209] The termination processing module is used to terminate the code merging process when the number of times reaches a threshold value.

[0210] Specifically, when there is an error in the merged code, the number of times the error information is input to the merge suggestion generation model will be recorded while the error information is input to the merge suggestion generation model. When the number of times the error information is input reaches a preset number threshold, the code merge process is terminated.

[0211] Terminating the code merge process means canceling the entire merge operation and restoring the code data to its original state.

[0212] By setting the number threshold, it is possible to avoid the system falling into an endless loop of generating merge suggestions when there are always errors in the merge code. In some embodiments, the number threshold is set to 5 times. In other embodiments, the number threshold can be set to other values ​​according to actual needs, and the present invention is not limited to this.

[0213] In some embodiments, the apparatus further comprises:

[0214] A specification acquisition module is used to obtain code specifications;

[0215] A specification judgment module, used to judge whether the first branch code and the second branch code meet the specification requirements according to the code specification;

[0216] The document generation module is used to generate a violation document if the first branch code or the second branch code does not meet the specification requirements so that the user can determine whether to modify the first branch code or the second branch code.

[0217] After the system obtains the first branch code and the second branch code, it will determine whether the first branch code and the second branch code meet the specification requirements according to the code specification, that is, check the code quality. By judging whether the first branch code and the second branch code meet the code specification, it can help developers discover and fix potential problems and vulnerabilities in advance, thereby improving the success rate of subsequent code merging.

[0218] The code specification may be a code specification customized by the user according to project requirements, or may be a general code specification set in advance by the system, which is not limited by the present invention.

[0219] In some embodiments, the static analysis tool ESLint is used to check the code quality and determine whether the code complies with the code specification. The ESLint plug-in system allows developers to write custom rules and extensions, so it has high flexibility and scalability and can meet various project requirements.

[0220] In other embodiments, other tools may also be used to perform code standard determination, which is not limited by the present invention.

[0221] If the first branch code or the second branch code is judged not to meet the specification requirements, a violation document will be generated, which includes the specific type of violation, the violation description, and the severity of the violation.

[0222] After the violation document is generated, it will be sent to the user, who will decide whether to modify the corresponding code part. The user can choose to ignore these violations and continue the subsequent merge operation. Or the user can choose to modify them and re-merge the code.

[0223] In some embodiments, the apparatus further comprises:

[0224] The third merging processing module is used to perform code merging processing on the first branch code and the second branch code if there is no branch conflict between the first branch code and the second branch code.

[0225] After determining that there is no branch conflict between the first branch code and the second branch code, the code of one branch is directly applied to the other branch to complete the code merging process.

[0226] When there is no branch conflict between the first branch code and the second branch code, the code merge process is performed directly without calling the merge suggestion generation model, which saves model resources and controls costs.

[0227] In some embodiments, the apparatus further comprises:

[0228] An updating module is used to update the first branch code or the second branch code according to the merged code if there is no error in the merged code.

[0229] When it is determined through testing that the merged code generated according to the merge suggestion does not have errors, the first branch code or the second branch code is updated according to the merged code, thereby completing the entire code merge operation.

[0230] After the entire code merge operation is completed, the system generates a merge report and sends it to the user. The merge report includes the merged code snippets, test results, and any possible warnings to help users understand the status of the code merge.

[0231] In an embodiment of the present invention, it is first determined whether there is a branch conflict between the first branch code and the second branch code. If there is a branch conflict between the two, the first conflict code in the first branch code and the second conflict code in the second branch code are obtained. The syntax trees of the first branch code and the second branch code are generated respectively, and the syntax tree of the first branch code, the syntax tree of the second branch code, the first conflict code and the second conflict code are input into a pre-trained merge suggestion generation model to obtain a merge suggestion generated by the merge suggestion generation model. After the merge suggestion is generated by the merge suggestion generation model, the first branch code and the second branch code are directly merged according to the merge suggestion, which improves the efficiency of the code merging process compared to the manual code analysis method.

[0232] In addition, the syntax trees of the first branch code and the second branch code are input into the merge suggestion generation model, so that the merge suggestion generation model can more correctly understand the code structure and code logic based on the syntax trees. The conflicting code with branch conflicts is input into the merge suggestion generation model, so that the merge suggestion generation model can locate the conflict problem more quickly. By improving the efficiency of the merge suggestion generation model in generating merge suggestions and the correctness of the merge suggestions, code merging is made more efficient and accurate.

[0233] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0234] An embodiment of the present invention further provides an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, the various processes of the above-mentioned code merging method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0235] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the various processes of the above-mentioned code merging method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0236] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0237] It will be appreciated by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0238] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0239] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0240] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0241] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.

[0242] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0243] The above is a detailed introduction to a code merging method, device, electronic device and computer-readable storage medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A code merging method, characterized in that: The method comprises: Obtain a first branch code and a second branch code; Determine whether there is a branch conflict between the first branch code and the second branch code; If there is a branch conflict between the first branch code and the second branch code, obtaining a first conflict code in the first branch code, and obtaining a second conflict code in the second branch code; Generating syntax trees of the first branch code and the second branch code respectively; Inputting the syntax tree of the first branch code, the syntax tree of the second branch code, the first conflict code, and the second conflict code into a pre-trained merge suggestion generation model to obtain a merge suggestion generated by the merge suggestion generation model; According to the merging suggestion, code merging processing is performed on the first branch code and the second branch code to obtain a merged code.

2. The method according to claim 1, characterized in that: The method further comprises: Detecting whether there is an error in the merged code; If there is an error in the merge code, inputting error information into the merge suggestion generation model; Obtaining a merge suggestion generated again by the merge suggestion generation model according to the error information; According to the regenerated merge suggestion, code merging processing is performed on the first branch code and the second branch code to obtain a merged code.

3. The method according to claim 2, characterized in that The method further comprises: determining a number of times erroneous information is input into the merge suggestion generation model; When the number of times reaches the number threshold, the code merging process is terminated.

4. The method according to claim 1, characterized in that: Before determining whether there is a branch conflict between the first branch code and the second branch code, the method further includes: Get code standards; Determine whether the first branch code and the second branch code meet the specification requirements according to the code specification; If the first branch code or the second branch code does not meet the specification requirements, a violation document is generated to allow the user to determine whether to modify the first branch code or the second branch code.

5. The method according to claim 1, characterized in that The method further comprises: If there is no branch conflict between the first branch code and the second branch code, code merging processing is performed on the first branch code and the second branch code.

6. The method according to claim 2, characterized in that The method further comprises: If there is no error in the merged code, the first branch code or the second branch code is updated according to the merged code.

7. The method according to claim 2, characterized in that The detecting whether the merged code has an error includes: Performing a logic check on the merged code to determine whether there is a logic error in the merged code; and performing a function check on the merged code to determine whether there is a function error in the merged code.

8. A code merging device, characterized in that: The device comprises: A first acquisition module, used to acquire a first branch code and a second branch code; A conflict judgment module, used to judge whether there is a branch conflict between the first branch code and the second branch code; a second acquisition module, configured to acquire a first conflicting code in the first branch code and acquire a second conflicting code in the second branch code if there is a branch conflict between the first branch code and the second branch code; A syntax tree generation module, used to generate syntax trees of the first branch code and the second branch code respectively; A first suggestion acquisition module is used to input the syntax tree of the first branch code, the syntax tree of the second branch code, the first conflict code, and the second conflict code into a pre-trained merge suggestion generation model to obtain a merge suggestion generated by the merge suggestion generation model; The first merging processing module is used to perform code merging processing on the first branch code and the second branch code according to the merging suggestion to obtain a merged code.

9. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the steps of the code merging method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the code merging method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Online collaborative programming processing method and device and storage medium

    CN118132049A

  • SQL (Structured Query Language) statement generation method and device based on large language model

    CN118277406A