Acquisition method and device of to-be-reviewed code, electronic equipment and storage medium

By combining the development code and branch version code in the code repository to generate code to be reviewed, the problem of excessive submission changes in the code to be reviewed during code review is solved, and the review efficiency is improved.

CN119322630APending Publication Date: 2025-01-17SHENZHEN LEXIN SOFTWARE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411101155.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-12
Publication Date
2025-01-17

AI Technical Summary

Technical Problem

During the software development process, when code review, the code to be reviewed contains a large number of changes not submitted, which affects the review efficiency, and it is difficult to focus on the code changes submitted this time.

Method used

By obtaining the development code submitted by the user and determining whether there is branch version code in the code repository, if it exists, merge the development code and branch version code to obtain the merged code, perform differences comparisons to generate the code to be reviewed, eliminate the reviewed changes, and improve the Review efficiency.

Benefits of technology

It effectively reduces the proportion of non-submitted changes in the code to be reviewed, making it easier for reviewers to pay attention to the changes in this submission, and improves the efficiency of code review.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119322630A_ABST
    Figure CN119322630A_ABST
Patent Text Reader

Abstract

The invention provides a to-be-reviewed code obtaining method and device, electronic equipment and a storage medium, and relates to the technical field of computers. After it is determined that a development code newly submitted by a user and a branch version code of the latest version do not take a main version code of the same version as the development basis, the to-be-reviewed code is obtained; on the basis of a main version code corresponding to a development code newly submitted by a user, a branch version code of the latest version is merged to obtain a merged code, the merged code comprises changes on the main version code and code lines examined in the development code, and therefore the merged code closest to the development code in content is constructed. By performing difference comparison on the combined code and the development code, the obtained code to be reviewed does not display the reviewed change in the main version code and the branch version code any more, and the proportion of the modified / newly added code in the submitted code to be reviewed is increased, so that the reviewer can more easily pay attention to the change of the submitted code; and the code review efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for obtaining a code to be reviewed. Background Art

[0002] In the software development process, code review is a key quality assurance activity that allows developers to check and discuss newly submitted code before the code is finally merged into the code base. As one of the core functions of the code review tool, Diff calculation helps reviewers determine what changes have occurred in the code since the last review, that is, to determine the code to be reviewed, so that code reviewers can complete the review of the user's newly submitted code by reading the code to be reviewed.

[0003] Currently, when determining the code to be reviewed, most of the time, the difference between the newly submitted code by the user and the latest version of the code on the main branch of the same project is compared. In this way, the code changes made by the developer in this submission and the code changes on the main branch are all written into the code to be reviewed, which ultimately results in a large amount of code to be reviewed, affecting the review efficiency and making it inconvenient for reviewers to focus on the changes made in this submission. Summary of the invention

[0004] Based on this, it is necessary to provide a method, device, electronic device and storage medium for obtaining the code to be reviewed in response to the above technical problems, so as to streamline the code to be reviewed, accurately display the code changes in this submission, and reduce the proportion of other codes in the code to be reviewed except for the changes made in this submission, so as to reduce the workload of code review.

[0005] A method for obtaining code to be reviewed, the method comprising: obtaining development code of a target project submitted by a user; determining whether there is a branch version code of the target project in a code repository corresponding to the target project, the branch version code being a line of code in the code repository that has passed code review and has not been merged into a main version code, and the main version code being a basic line of code pre-divided for the target project in the code repository; if so, determining the latest version of the branch version code of the target project; determining whether the main version code referenced by the development code is the same as the main version code referenced by the branch version code of the latest version, so as to determine whether the development code is identical to the latest version of the branch version code. whether the branch version code of the version is developed based on the main version code of the same version; if the main version code referenced by the development code is different from the main version code referenced by the branch version code of the latest version, it is determined that the development code and the branch version code of the latest version are not developed based on the main version code of the same version, then the main version code corresponding to the development code and the branch version code of the latest version are merged to determine a merged code; the development code and the merged code are compared for difference to obtain a first type of difference code as the code to be reviewed, so as to review the changes made by the user in the development code by reviewing the code to be reviewed.

[0006] In an embodiment of the present application, the method also includes: if the development code and the latest version of the branch version code are developed based on the same version of the main version code, then the development code and the latest version of the branch version code are compared to obtain a second type of difference code as the code to be reviewed.

[0007] In an embodiment of the present application, before determining whether there is a branch version code of the target project in the code repository corresponding to the target project, the method further includes: when there are multiple copies of the development code, determining whether there is the development code that references the same main version code; if there is the development code that references the same main version code, performing a difference comparison on any two copies of the development code that reference the same main version code to obtain a third type of difference code as the code to be reviewed for the any two copies of the development code; if there is no development code that references the same main version code, executing the step of determining whether there is a branch version code of the target project in the code repository corresponding to the target project; when there is one copy of the development code, executing the step of determining whether there is a branch version code of the target project in the code repository corresponding to the target project.

[0008] In an embodiment of the present application, after determining whether there is a branch version code in the code repository corresponding to the target project, the method further includes: if not, determining the main version code referenced by the development code from the code repository; performing a difference comparison between the development code and the main version code referenced by the development code to obtain a fourth type of difference code as the code to be reviewed.

[0009] In an embodiment of the present application, determining whether the main version code referenced by the development code is the same as the main version code referenced by the branch version code of the latest version, so as to determine whether the development code and the branch version code of the latest version are developed based on the same version of the main version code, includes: determining, from among the main version codes of multiple versions in the code repository, the main version code with the greatest degree of overlap with the branch version code of the latest version, as the main version code referenced by the branch version code of the latest version; determining, from among the main version codes of multiple versions in the code repository, the main version code with the greatest degree of overlap with the development code, as the main version code referenced by the development code; if the main version code referenced by the development code is the same as the main version code referenced by the branch version code of the latest version, determining that the development code and the branch version code of the latest version are developed based on the same version of the main version code; if the main version code referenced by the development code is different from the main version code referenced by the branch version code of the latest version, determining that the development code and the branch version code of the latest version are not developed based on the same version of the main version code.

[0010] In an embodiment of the present application, before determining whether there is a branch version code in the code repository, the method also includes: obtaining the review strategy selected by the user for the development code; if the review strategy selected by the user is full review, performing a difference comparison between the development code and the main version code referenced by the development code to obtain a fourth type of difference code as the code to be reviewed; if the review strategy selected by the user is incremental review, executing the step of determining whether there is a branch version code of the target project in the code repository corresponding to the target project.

[0011] In the embodiment of the present application, the plurality of development codes include the development codes submitted by different users and / or the development codes for which no code to be reviewed has been determined under the target project.

[0012] A device for acquiring code to be reviewed, comprising: an acquisition module, used to acquire development code of a target project submitted by a user; a judgment module, used to judge whether there is a branch version code of the target project in a code repository corresponding to the target project, the branch version code being a line of code in the code repository that has passed code review and has not been merged into a main version code, and the main version code being a basic line of code pre-divided for the target project in the code repository; a first determination module, used to determine the latest version of the branch version code of the target project if it exists; a second determination module, used to determine whether the main version code referenced by the development code is the same as the main version code referenced by the branch version code of the latest version, so as to determine whether the development code a merging module, used to determine whether the development code and the latest version of the branch version code are based on the same version of the main version code as the development basis if the main version code referenced by the development code is different from the main version code referenced by the latest version of the branch version code, and then merge the main version code corresponding to the development code and the latest version of the branch version code to determine a merged code; a difference comparison module, used to compare the development code with the merged code to obtain a first type of difference code as the code to be reviewed, so as to review the changes made by the user in the development code by reviewing the code to be reviewed.

[0013] In an embodiment of the present application, the difference comparison module is used to compare the development code with the branch version code of the latest version if the development code and the branch version code of the latest version are developed based on the same version of the main version code, and obtain a second type of difference code as the code to be reviewed.

[0014] In an embodiment of the present application, the judgment module is further used to: when there are multiple copies of the development code, determine whether there is the development code that references the same major version code; if there is the development code that references the same major version code, perform a difference comparison on any two copies of the development code that reference the same major version code to obtain a third type of difference code as the code to be reviewed for the any two copies of the development code; if there is no development code that references the same major version code, execute the step of determining whether there is a branch version code of the target project in the code repository corresponding to the target project; when there is one copy of the development code, execute the step of determining whether there is a branch version code of the target project in the code repository corresponding to the target project.

[0015] In an embodiment of the present application, the difference comparison module is used to: if it does not exist, determine the main version code referenced by the development code from the code repository; compare the development code with the main version code referenced by the development code to obtain a fourth type of difference code as the code to be reviewed.

[0016] In an embodiment of the present application, the second determination module is used to: determine, from the main version codes of multiple versions in the code repository, the main version code with the greatest degree of overlap with the branch version code of the latest version, as the main version code referenced by the branch version code of the latest version; determine, from the main version codes of multiple versions in the code repository, the main version code with the greatest degree of overlap with the development code, as the main version code referenced by the development code; if the main version code referenced by the development code is the same as the main version code referenced by the branch version code of the latest version, then determine that the development code and the branch version code of the latest version are developed based on the same version of the main version code; if the main version code referenced by the development code is different from the main version code referenced by the branch version code of the latest version, then determine that the development code and the branch version code of the latest version are not developed based on the same version of the main version code.

[0017] In an embodiment of the present application, the judgment module is used to: obtain the review strategy selected by the user for the development code; if the review strategy selected by the user is full review, then compare the development code with the main version code referenced by the development code to obtain a fourth type of difference code as the code to be reviewed; if the review strategy selected by the user is incremental review, then execute the step of determining whether the branch version code of the target project exists in the code repository corresponding to the target project.

[0018] In the embodiment of the present application, the plurality of development codes include the development codes submitted by different users and / or the development codes for which no code to be reviewed has been determined under the target project.

[0019] An electronic device comprises a memory, a processor and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the method for obtaining the code to be reviewed as described in the above embodiment are implemented.

[0020] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the method for obtaining a code to be reviewed as described in the above embodiment.

[0021] In summary, the present application proposes a method, device, electronic device and storage medium for obtaining code to be reviewed. In practice, developers continuously submit new versions of code on a development branch under a certain project to update the project code according to actual needs. After obtaining the development code newly submitted by the user, the method determines whether the development code newly submitted by the user and the latest version of the branch version code are based on the same version of the main version code based on the branch version code and the main version code that have been reviewed in the code repository. If not, the branch version code of the latest version is merged on the basis of the main version code referenced by the development code newly submitted by the user to obtain the merged The merged code includes the main version code changes between the main version code referenced by the development code and the main version code referenced by the latest version of the branch version code, as well as the code lines in the development code that have been reviewed, so as to construct the merged code that is closest to the development code in content. By comparing the merged code and the development code, the obtained code to be reviewed no longer displays the changes that have been reviewed in the main version code and the changes that have been reviewed in the branch version code, thereby increasing the proportion of the changed code in this submission in the code to be reviewed, making it easier for reviewers to pay attention to the changes submitted this time, and improving the efficiency of code review. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0023] Figure 1 is a flowchart of a method for obtaining a code to be reviewed according to an exemplary embodiment of the present application;

[0024] Figure 2 It is a schematic diagram of a development branch and a main branch in a method for obtaining code to be reviewed according to an exemplary embodiment of the present application;

[0025] Figure 3 is a schematic diagram of a development branch and a main branch in a method for obtaining code to be reviewed according to another exemplary embodiment of the present application;

[0026] Figure 4 is a schematic diagram of a development branch and a main branch in a method for obtaining code to be reviewed according to another exemplary embodiment of the present application;

[0027] Figure 5 is a flowchart of a method for obtaining a code to be reviewed according to another exemplary embodiment of the present application;

[0028] Figure 6 is a flowchart of a method for obtaining a code to be reviewed according to another exemplary embodiment of the present application;

[0029] Figure 7 is a schematic block diagram of a device for obtaining a code to be reviewed according to another exemplary embodiment of the present application;

[0030] Figure 8 It is a schematic block diagram of an electronic device according to an exemplary embodiment of the present application. DETAILED DESCRIPTION

[0031] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. The embodiments described by reference to the drawings are exemplary and are intended to be used to explain the present application, and cannot be understood as limiting the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0032] The present invention provides a method for obtaining code to be reviewed, which can be used to extract the changes made by the user in the newly submitted code after the user / developer completes the development of new functions or the adjustment of the project code for a certain project, and exclude the changes from the main version code that have been reviewed. The method merges the branch version code of the latest version and the main version code corresponding to the development code newly submitted by the user to obtain a merged code, and uses the merged code to compare the difference with the development code to obtain the code to be reviewed, so that the reviewer can focus on the code changes of the branch version code.

[0033] Figure 1 is a flowchart of a method for obtaining a code to be reviewed according to an exemplary embodiment of the present application. Figure 1 As shown, the method for obtaining the code to be reviewed includes the following steps:

[0034] S101, obtaining the development code of the target project submitted by the user.

[0035] When a developer or user performs development work under a target project, he or she usually pulls the latest version of the main branch code (that is, the latest version of the main version code mentioned above) from the code repository and creates a development branch based on it.

[0036] Therefore, it is not difficult to understand that the code in the initial version dev_v0 of the development branch is the same as the main version code referenced when the development branch was created. After the user completes a development work, he submits the development code generated in this development work. The development code includes the new code lines / modified code lines, etc. based on the latest version of the main branch code pulled by the user. The development code in this application can be understood as a new submission in Git.

[0037] This application can be implemented based on Git (distributed version control system). Commit is an important operation in Git. When developers modify the project code / develop new features, they can save these modified / added codes to the code repository by committing. The commit operation can package one or more code changes into a change set and give it a unique identifier, which can be the hash value of this commit.

[0038] S102, determining whether there is a branch version code of the target project in the code repository corresponding to the target project, and if so, determining the branch version code of the latest version of the target project.

[0039] The branch version code is the code line in the code repository that has passed code review and has not been merged into the main version code, which is equivalent to the development branch code; the main version code is the basic code line in the code repository that is pre-divided for the target project, which is equivalent to the main branch code.

[0040] The project code stored in the code repository is usually divided into the main branch code and the development branch code, that is, the code repository can be set up with multiple branches, such as the main branch and the development branch. The code in the project that has been tested and can be stably executed can be divided into the main branch, such as the code corresponding to the project's operating environment; when new functions are to be developed based on the main branch, a development branch can be created. The code on the development branch can be understood as code that is in the development stage and is constantly being updated. In practice, the development branch can also be merged into the main branch as needed. At this time, the code of the main branch will be pushed forward to a new version, that is, a new node will be formed on the main branch.

[0041] like Figure 2 As shown, each node in the main branch master represents a version change, that is, a commit on the main branch, so the code version corresponding to each node on the main branch is different. In this application, the main branch code is expressed as the main version code, and the latest version of the main version code can be understood as the latest node on the main branch. Correspondingly, this application expresses the development branch code as the branch version code, and the latest version of the branch version code can be understood as the latest node on the development branch.

[0042] For example, after obtaining the user's new submission (that is, the development code newly submitted by the user), check whether there is a development branch that has not been merged into the main branch in the project code repository corresponding to the new submission. If so, record the latest node of the development branch, such as Figure 2 dev_v1 in the dev branch.

[0043] S103: Determine whether the main version code referenced by the development code is the same as the main version code referenced by the latest version of the branch version code, so as to determine whether the development code and the latest version of the branch version code are developed based on the same version of the main version code.

[0044] The development branch code in the development code can be determined through the development branch identifier set by the developer in the development code, and the main branch code serving as the development basis of the development branch code can be determined through the main branch identifier set by the developer in the development code.

[0045] Therefore, after receiving the submitted development code, the main branch identifier and the development branch identifier set in the development code can be referred to to parse the main branch code and the development branch code from the development code.

[0046] In the embodiment of the present application, when determining whether the development code and the branch version code of the latest version are based on the same version of the main version code, the main version code referenced by the development code and the main version code referenced by the development branch code of the latest version can be compared. If there is no difference between the two, it can be considered that the development code and the development branch code of the latest version are based on the same version of the main branch code. If there is a difference between the two, it can be considered that the development code and the development branch code of the latest version are not based on the same version of the main branch code.

[0047] For example, Figure 2 As shown in the figure, the main version code corresponding to dev_v1 is the main branch code of master_v0. After the developer completes the development of the dev_v1 node, he pulls the latest version of the main version code, and continues to develop the same function on this basis, and submits the newly developed code to the dev_v2 node. If the developer pulls the latest version of the main version code of master_v1, it can be considered that dev_v1 and dev_v2 are based on different main version codes as the development basis, where master_v1 can be a version formed by other developers making changes based on master_v0 and merging it into the main branch after approval.

[0048] S104, if the main version code referenced by the development code is different from the main version code referenced by the branch version code of the latest version, it is determined that the development code and the branch version code of the latest version are not developed based on the same version of the main version code, then the main version code corresponding to the development code and the branch version code of the latest version are merged to determine a merged code.

[0049] If the main version code corresponding to the development code and the latest version of the branch version code do not use the same version of the main version code as the development basis, it can be considered that the main version code has undergone one or more version updates before the development code is submitted. The development code is based on the updated main version code.

[0050] Therefore, in an embodiment of the present application, the main version code corresponding to the development code and the latest version of the branch version code are merged to obtain a merged code, so that the merged code includes the changes of the main version code after the version update, as well as the code lines submitted to the development branch and code reviewed before this submission.

[0051] S105 , performing a difference comparison between the development code and the merged code to obtain a first type of difference code as the code to be reviewed, so as to review the changes made by the user in the development code by reviewing the code to be reviewed.

[0052] The changes made in the development code can be understood as the lines of code added, deleted, modified, etc. by the developer based on the referenced main version code.

[0053] For example, create a temporary branch temp based on master, merge dev_v1 into the temporary branch temp, and use gitdiff temp dev_v2 to remove the code that has been changed on the main branch before the current development code is submitted from the code to be reviewed, and calculate the incremental changes of the dev branch itself.

[0054] In summary, the present application proposes a method for obtaining code to be reviewed. After obtaining the development code newly submitted by the user, the method determines whether the development code newly submitted by the user and the latest version of the branch version code are developed based on the same version of the main version code based on the branch version code and the main version code that have been reviewed in the code repository. If not, the branch version code of the latest version is merged on the basis of the main version code corresponding to the development code newly submitted by the user to obtain a merged code. The merged code includes the main version code changes between the main version code corresponding to the development code and the main version code corresponding to the latest version of the branch version code, as well as the branch version code that has been reviewed in the development code, so as to construct a merged code that is closest to the development code in content. By comparing the difference between the merged code and the development code, the obtained code to be reviewed no longer displays the changes that have been reviewed in the main version code and the branch version code, thereby increasing the proportion of the modified / newly added code submitted by the user in the code to be reviewed, making it easier for reviewers to pay attention to the changes submitted this time, and improving the efficiency of code review.

[0055] Based on the above embodiment, the method also includes: if the development code and the latest version of the branch version code are developed based on the same version of the main version code, then the development code and the latest version of the branch version code are compared to obtain a second type of difference code as the code to be reviewed.

[0056] For example, Figure 3 As shown in the figure, if the development code dev_v2 and the latest version of the branch version code dev_v1 are both based on the master branch code of the master_v0 version, the development code dev_v3 and the branch code dev_v1 are compared. For example, using the git diff function, dev_v2 and dev_v1 are compared. Since the main branch code in dev_v2 and dev_v1 is the same, and dev_v2 is a commit uploaded after dev_v1, the main branch code will not be displayed in the file obtained after the difference comparison, only the changes made by the developer on the development branch will be shown.

[0057] If dev_v2 is a development version update based on dev_v1, after comparing the differences between dev_v2 and dev_v1, the code that has been reviewed on the dev_v1 node will no longer be displayed in the code to be reviewed corresponding to dev_v3. In this way, the code that has been reviewed in dev_v2 will also be removed from the code to be reviewed, thereby reducing the amount of data in the code to be reviewed and increasing the proportion of code lines that have been changed in the current submission in the code to be reviewed.

[0058] Based on the above embodiment, before "determining whether there is a branch version code of the target project in the code repository corresponding to the target project" in the above step S102, the method further includes:

[0059] When there are multiple copies of the development code, determine whether there is any development code that references the same major version code; if there is any development code that references the same major version code, compare the differences between any two copies of the development code that reference the same major version code to obtain a third type of difference code as the code to be reviewed for the any two copies of the development code.

[0060] For example, Figure 4 As shown, before the current commit dev_v3, there is an unreviewed commit dev_v2. Both dev_v2 and dev_v3 are developed based on the main branch code of the master_v0 version. The git diff function is used to calculate the difference code between dev_v2 and dev_v3 as the code to be reviewed for dev_v3 and dev_v2. For example, after a difference comparison, the code to be reviewed may include code lines that exist in dev_v3 but not in dev_v2, and code lines that exist in dev_v2 but not in dev_v3. Among them, dev_v2 and dev_v3 may be development codes submitted by different developers, or different development codes submitted by the same developer.

[0061] If the development code that references the same major version code does not exist, continue to execute the step of "determining whether there is a branch version of the target project in the code repository corresponding to the target project" in the above step S102; when there is a copy of the development code, continue to execute the step of "determining whether there is a branch version code of the target project in the code repository corresponding to the target project" in the above step S102.

[0062] In this way, the changes that may appear on the main branch and the lines of code that have been reviewed in the newly submitted development code can be filtered out from the code to be reviewed. The new changes made on the development branch are displayed in a larger proportion in the code to be reviewed.

[0063] On the basis of the above-mentioned embodiment, the multiple copies of the development code include the development code submitted by different users, and / or the development code for which the code to be reviewed has not been determined under the target project. Therefore, when receiving multiple development codes at the same time, the embodiment of the present application can determine whether these development codes are based on the main version code of the same version as the development basis. If so, the code to be reviewed that shows the new changes of the development branch can be obtained only by comparing the differences of these development codes, thus saving the comparison process with the branch version code. The development codes submitted by different users can be understood as different developers adding different lines of code on the basis of the main version code of the same version. By comparing the differences of the two new development codes, the newly added lines of code in the two new development codes can be organized into the same copy of the code to be reviewed.

[0064] Based on the above embodiment, after "determining whether there is a branch version code in the code repository corresponding to the target project" in the above step S102, the method further includes:

[0065] If it does not exist, determining the main version code referenced by the development code from the code repository;

[0066] The development code is compared with the main version code referenced by the development code to obtain a fourth type of difference code as the code to be reviewed.

[0067] If the user submits the development code and finds that the development branch in the code repository has been merged into the main branch, the version that serves as the development basis for the development code is searched on the main branch. For example, the git merge-base function is used to determine the common parent node of the new submission and the main branch, such as Figure 4 dev_v1 in the code is the new change submitted by the user, and masetr_v0 is the common parent node of dev and master. The code to be reviewed can be obtained by passing the identifiers of master_v0 and dev_v1 to the function git diff. In this way, the code to be reviewed will filter out the changes made in the master_v1 version on the main branch, and only show the changes made by dev_v1 on the development branch.

[0068] Based on the above embodiments, Figure 5 As shown, in the above step S103, "determining whether the main version code referenced by the development code is the same as the main version code referenced by the branch version code of the latest version, so as to determine whether the development code and the branch version code of the latest version are developed based on the same version of the main version code" includes the following steps:

[0069] S501, determining, from among the main version codes of the multiple versions in the code repository, the main version code that has the greatest degree of overlap with the branch version code of the latest version as the main version code referenced by the branch version code of the latest version;

[0070] S502, determining, from among the main version codes of multiple versions in the code repository, a main version code that has the greatest degree of overlap with the development code, as the main version code referenced by the development code;

[0071] S503, if the main version code referenced by the development code is the same as the main version code referenced by the branch version code of the latest version, then determining that the development code and the branch version code of the latest version are developed based on the same version of the main version code;

[0072] S504: If the main version code referenced by the development code is different from the main version code referenced by the latest version branch version code, determine that the development code and the latest version branch version code are not developed based on the same version of the main version code.

[0073] For example, different nodes on the main branch represent different versions of the main version code, and different nodes on the development branch represent different versions of the branch version code; use git merge-base to find the nearest common parent node between dev_v1 and the main branch master, and the nearest common parent node between dev_v2 and the main branch master; if the two nearest common parent nodes are the same, such as master_v0, it is confirmed that dev_v1 and dev_v2 are based on the same version of the main version code master_v0. If the nearest common parent node between dev_v2 and the main branch master is master_v1, it can be considered that the developer pulled the master version code of the master_v1 version from the main branch when developing and generating a new commit of the dev-v2 version. The master version code of the master_v1 version has some changes such as new code lines / modified code lines / deleted code lines compared to the master version code of the master_v0 version. In this case, it is considered that dev_v1 and dev-v2 are not based on the same version of the main version code master_v0.

[0074] This application determines whether the two main version codes are the same by finding a main version code that is closest to the latest version of the branch version code, and finding a main version code that is closest to the development code. When the latest version of the branch version code and the development code have the same code lines on the main branch, the latest version of the branch version code is used as a reference for difference comparison, so that the main version code involved in the development code can be accurately eliminated from the code to be reviewed.

[0075] Based on the above embodiments, Figure 6 As shown, before "determining whether there is a branch version code in the code repository" in step S102, the method further includes:

[0076] S601, obtaining the review policy selected by the user for the development code;

[0077] The review strategy option can be set in the code review interactive platform, so that when users submit new development code, they can specify which review strategy to execute for the submission. The review strategy can include full review and incremental review.

[0078] S602: If the review strategy selected by the user is full review, the development code is compared with the main version code referenced by the development code to obtain a fourth type of difference code as the code to be reviewed.

[0079] If the review strategy selected by the user is full review, the newly submitted development code will be directly compared with the main version code it references, so that only the changes made by other developers on the main branch will be filtered out from the code to be reviewed, and the changes submitted by different submission nodes on the development branch will be included, and the development branch will be fully reviewed.

[0080] S603, if the review strategy selected by the user is incremental review, the step of determining whether there is a branch version code of the target project in the code repository corresponding to the target project is executed.

[0081] If the review strategy selected by the user is incremental review, the code close to the new submission is built based on the branch version code of the development branch, or multiple development codes based on the same version of the main version code are combined to determine the code to be reviewed, and the changes that have been reviewed on the development branch are screened out while the new changes on the main branch are screened out. The new changes on the development branch are displayed in the code to be reviewed.

[0082] In the embodiment of the present application, two different review strategies are provided for the user, so that the user can choose full review or incremental review according to needs, and the incremental code to be reviewed obtains adaptability in different scenarios.

[0083] The method for obtaining the code to be reviewed proposed in this application only shows changes that are not related to the main branch in the determined code to be reviewed, so that the reviewer can pay attention to and evaluate the relevant code of the development branch more quickly, effectively shorten the review time, reduce the error rate of code review, and improve the accuracy of review. At the same time, it reduces the consumption of computing resources during the code review process, greatly saves server resources, and reduces operating costs.

[0084] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0085] Figure 7 is a block diagram of a device for obtaining a code to be reviewed according to an exemplary embodiment of the present application, such as Figure 7 As shown, the apparatus 700 includes: an acquisition module 701 , a judgment module 702 , a first determination module 703 , a second determination module 704 , a merging module 705 and a difference comparison module 706 .

[0086] An acquisition module 701 is used to acquire the development code of the target project submitted by the user;

[0087] A judgment module 702 is used to judge whether there is a branch version code of the target project in the code repository corresponding to the target project, the branch version code is a code line in the code repository that has passed the code review and has not been merged into the main version code, and the main version code is a basic code line in the code repository that is pre-divided for the target project;

[0088] A first determination module 703 is used to determine the branch version code of the latest version of the target project if it exists;

[0089] The second determination module 704 is used to determine whether the main version code referenced by the development code is the same as the main version code referenced by the latest version of the branch version code, so as to determine whether the development code and the latest version of the branch version code are based on the same version of the main version code;

[0090] The merging module 705 is used for merging the main version code corresponding to the development code and the branch version code of the latest version to determine a merged code if the main version code referenced by the development code is different from the main version code referenced by the branch version code of the latest version, and determining that the development code and the branch version code of the latest version are not developed based on the same version of the main version code;

[0091] The difference comparison module 706 is used to compare the development code with the merged code to obtain a first type of difference code as the code to be reviewed, so as to review the changes made by the user in the development code by reviewing the code to be reviewed.

[0092] In an embodiment of the present application, the difference comparison module is used to compare the development code with the branch version code of the latest version if the development code and the branch version code of the latest version are developed based on the same version of the main version code, and obtain a second type of difference code as the code to be reviewed.

[0093] In an embodiment of the present application, the judgment module is further used to: when there are multiple copies of the development code, determine whether there is the development code that references the same major version code; if there is the development code that references the same major version code, perform a difference comparison on any two copies of the development code that reference the same major version code to obtain a third type of difference code as the code to be reviewed for the any two copies of the development code; if there is no development code that references the same major version code, execute the step of determining whether there is a branch version code of the target project in the code repository corresponding to the target project; when there is one copy of the development code, execute the step of determining whether there is a branch version code of the target project in the code repository corresponding to the target project.

[0094] In an embodiment of the present application, the difference comparison module is used to: if it does not exist, determine the main version code referenced by the development code from the code repository; compare the development code with the main version code referenced by the development code to obtain a fourth type of difference code as the code to be reviewed.

[0095] In an embodiment of the present application, the second determination module is used to: determine, from the main version codes of multiple versions in the code repository, the main version code with the greatest degree of overlap with the branch version code of the latest version, as the main version code referenced by the branch version code of the latest version; determine, from the main version codes of multiple versions in the code repository, the main version code with the greatest degree of overlap with the development code, as the main version code referenced by the development code; if the main version code referenced by the development code is the same as the main version code referenced by the branch version code of the latest version, then determine that the development code and the branch version code of the latest version are developed based on the same version of the main version code; if the main version code referenced by the development code is different from the main version code referenced by the branch version code of the latest version, then determine that the development code and the branch version code of the latest version are not developed based on the same version of the main version code.

[0096] In an embodiment of the present application, the judgment module is used to: obtain the review strategy selected by the user for the development code; if the review strategy selected by the user is full review, then compare the development code with the main version code corresponding to the development code to obtain a fourth type of difference code as the code to be reviewed; if the review strategy selected by the user is incremental review, then execute the step of determining whether the branch version code of the target project exists in the code repository corresponding to the target project.

[0097] In the embodiment of the present application, the plurality of development codes include the development codes submitted by different users and / or the development codes for which no code to be reviewed has been determined under the target project.

[0098] The present application proposes a device for obtaining code to be reviewed, so that the obtained code to be reviewed no longer displays the changes that have been reviewed in the main version code and the branch version code, increases the proportion of the modified / newly added code in this submission in the code to be reviewed, makes it easier for reviewers to pay attention to the changes submitted this time, and improves the efficiency of code review.

[0099] To implement the above embodiment, the embodiment of the present application also proposes an electronic device 800, including a memory 801, a processor 802, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the method for obtaining the code to be reviewed as described in the above embodiment are implemented.

[0100] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0101] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0102] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A method for obtaining code to be reviewed, characterized in that: The method comprises: Obtain the development code of the target project submitted by the user; Determine whether there is a branch version code of the target project in the code repository corresponding to the target project, the branch version code being a code line in the code repository that has passed code review and has not been merged into the main version code, and the main version code being a basic code line in the code repository that is pre-divided for the target project; If so, determine the branch version code of the latest version of the target project; Determine whether the main version code referenced by the development code is the same as the main version code referenced by the branch version code of the latest version, so as to determine whether the development code and the branch version code of the latest version are developed based on the same version of the main version code; If the main version code referenced by the development code is different from the main version code referenced by the branch version code of the latest version, it is determined that the development code and the branch version code of the latest version are not developed based on the same version of the main version code, then the main version code referenced by the development code and the branch version code of the latest version are merged to determine a merged code; The development code and the merged code are compared for differences to obtain a first type of difference code as the code to be reviewed, so as to review the changes made by the user in the development code by reviewing the code to be reviewed.

2. The method according to claim 1, characterized in that The method further comprises: If the development code and the latest version of the branch version code are developed based on the same version of the main version code, the development code and the latest version of the branch version code are compared to obtain a second type of difference code as the code to be reviewed.

3. The method according to claim 1, characterized in that Before determining whether there is a branch version code of the target project in the code repository corresponding to the target project, the method further includes: When there are multiple copies of the development code, determining whether there is a development code that references the same major version code; If there are development codes that reference the same major version code, any two development codes that reference the same major version code are compared for differences to obtain a third type of difference code as the code to be reviewed for the any two development codes; If the development code that references the same major version code does not exist, executing the step of determining whether the branch version code of the target project exists in the code repository corresponding to the target project; When there is a copy of the development code, the step of determining whether there is a branch version code of the target project in the code repository corresponding to the target project is performed.

4. The method according to claim 1, characterized in that After determining whether there is a branch version code in the code repository corresponding to the target project, the method further includes: If it does not exist, determining the main version code referenced by the development code from the code repository; The development code is compared with the main version code referenced by the development code to obtain a fourth type of difference code as the code to be reviewed.

5. The method according to claim 1, characterized in that The determining whether the main version code referenced by the development code is the same as the main version code referenced by the branch version code of the latest version, so as to determine whether the development code and the branch version code of the latest version are based on the same version of the main version code as a development basis, includes: Determine, from among the main version codes of the multiple versions in the code repository, the main version code with the greatest degree of overlap with the branch version code of the latest version, as the main version code referenced by the branch version code of the latest version; Determine, from among the multiple versions of main version codes in the code repository, a main version code with the greatest degree of overlap with the development code, as the main version code referenced by the development code; If the main version code referenced by the development code is the same as the main version code referenced by the branch version code of the latest version, then it is determined that the development code and the branch version code of the latest version are developed based on the same version of the main version code; If the main version code referenced by the development code is different from the main version code referenced by the latest version branch version code, it is determined that the development code and the latest version branch version code are not developed based on the same version of the main version code.

6. The method according to claim 1, characterized in that Before determining whether there is a branch version code in the code repository, the method further includes: Obtaining the review policy selected by the user for the development code; If the review strategy selected by the user is full review, the development code is compared with the main version code referenced by the development code to obtain a fourth type of difference code as the code to be reviewed; If the review strategy selected by the user is incremental review, the step of determining whether the branch version code of the target project exists in the code repository corresponding to the target project is executed.

7. The method according to claim 3, characterized in that The multiple copies of the development codes include the development codes submitted by different users and / or the development codes for which no code to be reviewed has been determined under the target project.

8. A device for obtaining a code to be reviewed, characterized in that: include: The acquisition module is used to obtain the development code of the target project submitted by the user; A judgment module is used to judge whether there is a branch version code of the target project in the code repository corresponding to the target project, the branch version code is a code line in the code repository that has passed the code review and has not been merged into the main version code, and the main version code is a basic code line in the code repository that is pre-divided for the target project; A first determination module, configured to determine the branch version code of the latest version of the target project, if any; The second determination module is used to determine whether the main version code referenced by the development code is the same as the main version code referenced by the latest version of the branch version code, so as to determine whether the development code and the latest version of the branch version code are based on the same version of the main version code; a merging module, configured to, if the main version code referenced by the development code is different from the main version code referenced by the branch version code of the latest version, determine that the development code and the branch version code of the latest version are not developed based on the same version of the main version code, then merge the main version code referenced by the development code and the branch version code of the latest version to determine a merged code; The difference comparison module is used to compare the development code and the merged code to obtain a first type of difference code as the code to be reviewed, so as to review the changes made by the user in the development code by reviewing the code to be reviewed.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the processor implements the steps of the method for obtaining the code to be reviewed as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method for obtaining the code to be reviewed as described in any one of claims 1 to 7 are implemented.