Code change-based difference processing method and device, terminal and storage medium
By automating the analysis of code differences, the problem of time-consuming and labor-intensive manual code change queries has been solved, thus improving the testing efficiency of software projects.
Patent Information
- Application Number
- CN202211321159.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-26
- Publication Date
- 2026-02-13
- Estimated Expiration
- 2042-10-26
AI Technical Summary
In the process of software project development and testing, manually checking code changes consumes a lot of time and manpower, affecting the project completion schedule.
By identifying the differences between the code commit records of each comparison branch of the target project, the project source code is obtained, compiled into a JAR package, and the class files are traversed to obtain the start and end lines of code. Based on the difference information, the code differences are automatically analyzed.
It improves the efficiency of finding differences between code changes and the original code, saves manpower and time, and improves testing efficiency.
Smart Images

Figure CN115576600B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a difference processing method and device based on code change, a terminal and a storage medium. BACKGROUND
[0002] In the software project development test process, by querying the change information of the project code, the software project is tested in a targeted manner, which can improve the project test efficiency.
[0003] In the related art, the git diff command is used to view the code differences between different versions of the project and the detailed information of the code changes. For testers, they are more concerned about the changes in business functions, and the business functions correspond to the methods of the project code. Therefore, the testers often manually view the code, query the changed methods by viewing the code changes, and perform business testing in a targeted manner. However, the manual code query method requires a lot of time and labor costs, and in the case of tight project resources, it affects the project completion progress. SUMMARY
[0004] The embodiments of the present application provide a difference processing method and device based on code change, a terminal and a storage medium, which can improve the search efficiency of the difference methods before and after the code change.
[0005] The embodiments of the present application provide a difference processing method based on code change, comprising:
[0006] Determine the code difference information between the code commit records corresponding to each comparison branch of the target project that needs to be compared, wherein different comparison branches are used to manage different versions of the target project;
[0007] Obtain the project source code corresponding to each code commit record;
[0008] Compile each project source code into an independently running JAR package, and read the JAR package into a JAR file entry;
[0009] Iterate through all files in the JAR file entry to determine the class files in the JAR file entry;
[0010] Obtain the starting code line and the ending code line corresponding to each method in the class file;
[0011] Determine the difference methods between each project source code according to the code difference information, the starting code line and the ending code line corresponding to each method, and obtain the difference comparison results between each code commit record.
[0012] Correspondingly, the embodiments of the present application also provide a difference processing device based on code change, comprising:
[0013] The first determining unit is configured to determine code difference information between code commit records corresponding to respective comparison branches of a target project that need to be compared, wherein different comparison branches are used to manage different versions of the target project.
[0014] The first obtaining unit is configured to obtain project source codes corresponding to respective code commit records.
[0015] The compiling unit is configured to compile the respective project source codes into independent JAR packages respectively, and read the JAR packages into JAR file entries.
[0016] The second determining unit is configured to traverse all files in the JAR file entries, and determine class files in the JAR file entries.
[0017] The second obtaining unit is configured to obtain a starting code line and an ending code line corresponding to each method in the class files.
[0018] The third determining unit is configured to determine difference methods between the respective project source codes according to the code difference information, the starting code line and the ending code line corresponding to each method, and obtain difference comparison results between the respective code commit records.
[0019] In some embodiments, the third determining unit comprises:
[0020] The matching subunit is configured to match the difference code line with the starting code line and the ending code line corresponding to each method according to the difference type.
[0021] The first determining subunit is configured to determine a method corresponding to the starting code line and the ending code line that are successfully matched with the difference code line, and obtain the difference method.
[0022] In some embodiments, the matching subunit is specifically configured to:
[0023] match the added code line with the starting code line and the ending code line corresponding to each method.
[0024] In some embodiments, the third determining unit further comprises:
[0025] The first obtaining subunit is configured to, if the added code line fails to be matched with the starting code line and the ending code line of each method, obtain a method corresponding to a code block to which the added code line belongs as the difference method.
[0026] In some embodiments, the matching subunit is specifically configured to:
[0027] match the modified code line with the starting code line and the ending code line corresponding to each method.
[0028] In some embodiments, the matching subunit is specifically used for:
[0029] The deleted code line is matched with the start and end code lines corresponding to each method.
[0030] In some embodiments, the first determining unit includes:
[0031] The second determination subunit is used to determine the specified code commit record corresponding to each comparison branch;
[0032] The second acquisition subunit is used to obtain code difference information between different versions of the target project submitted by each specified code commit record based on the identifier of each specified code commit record.
[0033] Accordingly, embodiments of this application also provide a terminal, including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes any of the code change-based difference processing methods provided in embodiments of this application.
[0034] Accordingly, embodiments of this application also provide a storage medium storing multiple instructions adapted for loading by a processor to execute the above-described code change-based differential processing method.
[0035] This application first determines the code difference information between the code commit records corresponding to each comparison branch of the target project that needs to be compared. Then, it obtains the project source code corresponding to each code commit record. It compiles each project source code into an independently runnable JAR package and reads the JAR package into a JAR file entry. It traverses all files in the JAR file entry and determines the class files in the JAR file entry. It obtains the start line and end line of code corresponding to each method in the class file. Based on the code difference information and the start line and end line of code corresponding to each method, it determines the difference methods between the source codes of each project and obtains the difference comparison results between each code commit record. In this way, the efficiency of finding the difference methods before and after code changes can be improved. Attached Figure Description
[0036] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0037] Figure 1 This is a flowchart illustrating a method for handling differences based on code changes, provided in an embodiment of this application.
[0038] Figure 2 A structural block diagram of a code change-based difference processing apparatus provided by an embodiment of the present application is provided.
[0039] Figure 3 A structural schematic diagram of a terminal provided by an embodiment of the present application is provided. DETAILED DESCRIPTION
[0040] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of protection of the present application.
[0041] The embodiments of the present application provide a code change-based difference processing method and device, a storage medium and a terminal. Specifically, the code change-based difference processing method of the embodiments of the present application can be executed by a terminal, where the terminal can be a server or the like. The server can be a standalone physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud service, cloud database, cloud computing, cloud function, cloud storage, network service, cloud communication, middleware service, domain name service, security service, CDN, and big data and artificial intelligence platform.
[0042] For example, the terminal can be a server, which can determine code difference information between code commit records corresponding to each comparison branch of a target project that needs to be compared, where different comparison branches are used to manage different versions of the target project; obtain project source codes corresponding to each code commit record; compile each project source code into a JAR package that can run independently, and read the JAR package into a JAR file entry; traverse all files in the JAR file entry to determine class files in the JAR file entry; obtain a starting code line and an ending code line corresponding to each method in the class files; determine difference methods between each project source code according to the code difference information, the starting code line and the ending code line corresponding to each method, and obtain a difference comparison result between each code commit record.
[0043] Based on the above problems, the embodiments of the present application provide a code change-based difference processing method and device, a terminal and a storage medium, which can improve the search efficiency of difference methods before and after code changes.
[0044] The following will be described in detail. It should be noted that the order of the following embodiments is not limited as the preferred order of the embodiments.
[0045] The embodiment of the present application provides a difference processing method based on code change, which can be executed by a terminal or a server. The embodiment of the present application takes the example of the difference processing method based on code change executed by the server.
[0046] Please refer to Figure 1 , Figure 1 A flowchart of a difference processing method based on code change provided by the embodiment of the present application. The specific process of the difference processing method based on code change can be as follows:
[0047] 101, determining the code difference information between the code commit records corresponding to each comparison branch of the target project which needs to be compared.
[0048] Wherein, the target project refers to a software project which needs to be version managed. The target project can have multiple versions, and the project codes of different versions of the target project can exist differences.
[0049] In the embodiment of the present application, the version of the target project can be managed by using Git, which is an open source distributed version control system, can effectively and quickly handle the version management of projects from very small to very large, and is also an open source version control software.
[0050] Specifically, when the target project is managed by using Git, a branch can be created to manage the version of the target project. A branch can represent an independent development line, and the branch can be separated from the development main line of the target project, and then work continuously without affecting the main line.
[0051] For example, the version of the target project can include a first version, a second version and a third version, etc., a first branch can be created to manage the target project of the first version, a second branch can be created to manage the target project of the second version, and a third branch can be created to manage the target project of the third version, etc., and the work of each branch does not affect each other.
[0052] Specifically, when the project stored in Git is changed, a commit object is saved when the changed project is committed in Git. The commit object includes a pointer to the snapshot of the staging content, the author and the related auxiliary information. The branch in Git is actually a variable pointer to the commit object.
[0053] In the embodiments of the present application, the comparison branch refers to a branch corresponding to a different version of the target project selected by the user for difference comparison. For example, the version of the target project selected by the user for difference comparison can include a first version and a second version, and the comparison branch can include a first branch and a second branch.
[0054] Different comparison branches are used to manage different versions of the target project.
[0055] In some embodiments, in order to quickly obtain the difference information of the target project corresponding to different comparison branches, the step of "determining the code difference information between the code commit records corresponding to each comparison branch of the target project for which difference comparison is required" can include the following operations:
[0056] Determine the specified code commit record corresponding to each comparison branch.
[0057] According to the identifier of each specified code commit record, obtain the code difference information between different versions of the target project submitted by each specified code commit record.
[0058] In the embodiments of the present application, the code commit record refers to a commit object generated after the modified target project is submitted after modification. Specifically, after the code of the modified target project is submitted, a 40-bit hash value can be generated in the local version library as the unique identifier of the code submission, that is, the identifier of the code commit record.
[0059] For example, the comparison branch can include branchA and branchB. The code commit record of the HEAD of branchA, that is, commitA, can be obtained through a Git command or on a Gitlab page, and the code commit record of the HEAD of branchB, that is, commitB, can be obtained through a Git command or on a Gitlab page.
[0060] GitLab is an open source project for repository management system, using Git as a code management tool and building a web service based on it. The HEAD is a pointer referenced by the current branch, which always points to a commit, and the default is the last commit.
[0061] In some embodiments, the jgit dependency package can be introduced in the program code through a POM file to realize the analysis on the target project. The POM is the abbreviation of Project object Model, which is a file in the Maven project, expressed by XML, and named pom.xml. In Maven, a Project often contains a configuration file; including the defect tracking system related to the developer, organization and license, item URL item and dependency, and base. It contains everything related to this project. Among them, jgit is a java code commit Git plug-in that can connect Git remote warehouse through code, establish a local version library, and perform pull, commit, push and other operations.
[0062] Specifically, according to the identification of each specified code commit record, the code difference information between different versions of the target project submitted by each specified code commit record can be obtained, which can include: through git.diff(setNewTree(newTreelter)setOldTree(oldTreelter))call, the difference entity list information between two code commit records (commitA, commitB) can be obtained, which can include: difference file name, difference type, difference line information, difference code detailed information, etc. Among them, the difference type can include: ADD / DELETE / modify MODIFY, etc.
[0063] Among them, the git diff command compares different files, that is, compares the differences between the files in the staging area and the working area. The git diff command displays the differences between files that have been written to the staging area and have been modified but have not yet been written to the staging area.
[0064] 102、Obtain the project source code corresponding to each code commit record.
[0065] Specifically, the project source code corresponding to each code commit record is obtained from the project source code management platform through the gitlcone command. The gitlcone command can be used to copy a Git repository to the local, so that the developer can view the project locally, or make modifications, etc.
[0066] For example, the comparison branches can include: branchA and branchB, the commit record of branchA can be commitA, and the commit record of branchB can be commitB. Specifically, the project source code of the comparison branch branchA and the commit record commitA is obtained through the gitlcone command, and the project source code of the comparison branch branchB and the commit record commitB is obtained through the gitlcone command.
[0067] 103. Compile each project source code into a JAR package that can run independently, and read the JAR package into the JAR file entry.
[0068] Specifically, the project source code can be compiled into a JAR package that can run independently by using the mvn clean package command.
[0069] The mvn clean package command is a set of commands, and the executed commands can include: maven-clean-plugin: executing cleaning to delete the existing target directory, maven-resources-plugin: executing processing of resource files, maven-compiler-plugin: compiling all source files to generate class files under the target\classes directory, maven-surefire-plugin: running test cases, maven-jar-plugin: packaging the generated files after compilation, etc. The execution sequence of the mvn clean package can be as follows:
[0070] (1) Using the cleaning plug-in: maven-clean-plugin: executing cleaning to delete the existing target directory;
[0071] (2) Using the resource plug-in: maven-resources-plugin: executing processing of resource files;
[0072] (3) Using the compilation plug-in: maven-compiler-plugin: compiling all source files to generate class files under the target\classes directory;
[0073] (4) Using the resource plug-in: maven-resources-plugin: executing processing of test resource files;
[0074] (5) Using the compilation plug-in: maven-compiler-plugin: compiling all source codes under the test directory;
[0075] (6) Using the plug-in: maven-surefire-plugin: running test cases;
[0076] (7) Use plug-in: maven-jar-plugin: package the file generated after compilation, the package name is default: artifactId-version, such as the JAR file generated in this example: rtp-front-1.0-SNAPSHOT, the package file is saved in the target directory.
[0077] Wherein, the JAR file entry is also called jarEntry. The packaging of the JAR file is based on the standard method of the solution of JAVA technology. It allows developers to package all related contents (.class, pictures, sounds, and all supporting files) into one file. The JAR format supports compression, authentication, version number and many other features. The jarEntry can be used to read files from the JAR file.
[0078] Wherein, reading the JAR package into the JAR file entry can be achieved by specifying the jar package path, reading the contents of the JAR package into the jarEntry, that is, reading each file in the JAR package.
[0079] 104. Traverse all files in the JAR file entry to determine the class file in the JAR file entry.
[0080] Wherein, determining the class file in the JAR file entry can be achieved by judging whether the file ends with the.class file suffix. When traversing the files in the JAR file entry, if it is detected that the file is a file ending with the.class file suffix, it is determined that the file is a class file; if it is detected that the file is not a file ending with the.class file suffix, the next file in the JAR file entry is analyzed.
[0081] 105. Get the starting code line and the ending code line corresponding to each method in the class file.
[0082] After determining the class file in the JAR file entry, the class file can be analyzed by ClassParser.parse. That is, the class file is analyzed by the class analyzer.
[0083] In some embodiments, analyzing the class file by ClassParser.parse can include the following operations:
[0084] Get the method set under the class file;
[0085] Traverse the method set to get the starting code line and the ending code line corresponding to each method.
[0086] First, get the class name path of the class file by getClassName, and then get the set of all methods under the class by getMethods.
[0087] Specifically, the method set of the class is traversed, and the starting code line and the ending code line of each method are obtained through getLineNumberTable.
[0088] The getClassName function can be used to obtain the class name of the class to which the specified window belongs; the getMethods function can be used to obtain the class method; and the getLineNumberTable function can be used to obtain the code line.
[0089] Specifically, the implementation code of obtaining the starting code line and the ending code line of each method through getLineNumberTable can be as follows:
[0090] string changeType;
[0091] string filename;
[0092] list <numberentry>numberList;
[0093] FileHeader fhleheader;DiffEntry diffentry;
[0094] @Data
[0095] public static class numberentry{
[0096] int beginAnum;
[0097] int endAnum;
[0098] int beginBnum; / / Change the starting line
[0099] int endBnum; / / End line of the change
[0100] 106. Based on the code difference information, the starting and ending lines of code for each method, determine the difference methods between the source code of each project, and obtain the difference comparison results between each code commit record.
[0101] In some embodiments, code difference information may include at least the difference type and the difference line of code. To quickly obtain the differences in code methods between different code commit records, the step "determine the difference methods between the source code of each project based on the code difference information, the starting line of code and the ending line of code corresponding to each method" may include the following operations:
[0102] Based on the difference type, the difference code line is matched with the start and end code lines corresponding to each method;
[0103] Determine the methods corresponding to the starting and ending lines of code that successfully match the differencing lines, and obtain the differencing methods.
[0104] Specifically, the difference type refers to the type of code difference between different code commit records. For example, the difference type can include: addition type, which means adding a new line of code; modification type, which means modifying the original line of code; and deletion type, which means deleting the original line of code. A difference line of code refers to the different code between different code commit records.
[0105] Specifically, determining the methods corresponding to the starting and ending lines of code that successfully match the differing code lines, that is, identifying the methods corresponding to the starting and ending lines of code that include the differing code lines, yields the differing methods. The differing methods refer to the different methods included in the code between different code commit records.
[0106] In some embodiments, the difference type can be an addition type, that is, new code is added in the original code, then the difference code line is added, and the step of "matching the difference code line with the start code line and the end code line corresponding to each method according to the difference type" can include the following operations:
[0107] Matching the added code line with the start code line and the end code line corresponding to each method.
[0108] Specifically, the added code line is compared with the start code line and the end code line corresponding to each method to determine which method the added code line belongs to, thereby determining the method to which the added code line belongs, and obtaining the difference method.
[0109] In some embodiments, when the difference type is an addition type, the added code line corresponding to the addition type can be a code line in the added method. In order to obtain an accurate difference method set, the following steps can also be included:
[0110] If the added code line fails to match the start code line and the end code line of each method, the method corresponding to the code block to which the added code line belongs is obtained as the difference method.
[0111] Specifically, if the added code line does not belong to the start code line and the end code line of each method, it is determined that the added code line fails to match the start code line and the end code line of each method. Further, the method name of the code block corresponding to the added code line is queried, and the method corresponding to the method name is obtained. The method is an added method, that is, a difference method.
[0112] In some embodiments, the difference type can be a modification type, that is, the original code is modified, then the difference code line is modified, and the step of "matching the difference code line with the start code line and the end code line corresponding to each method according to the difference type" can include the following operations:
[0113] Matching the modified code line with the start code line and the end code line corresponding to each method.
[0114] Specifically, the modified code line is compared with the start code line and the end code line corresponding to each method to determine which method the modified code line belongs to, thereby determining the method to which the modified code line belongs, and obtaining the difference method.
[0115] In some embodiments, the difference type can be a deletion type, that is, the original code is deleted, then the difference code line is deleted, and the step of "matching the difference code line with the start code line and the end code line corresponding to each method according to the difference type" can include the following operations:
[0116] The deleted code line is matched with the start code line and the end code line corresponding to each method.
[0117] Specifically, the deleted code line is compared with the start code line and the end code line corresponding to each method, to determine which method the deleted code belongs to, thereby determining the method to which the deleted code line belongs, and obtaining the difference method.
[0118] In the embodiment of the application, all the difference code lines in the obtained code difference information are compared with the start code line and the end code line corresponding to each method in the class file in the JAR package, to obtain all the difference methods, and all the difference methods are grouped to obtain a difference method set, which includes the difference methods in the code between different code commit records to be compared. In this way, the code difference and the class file are analyzed in an automated manner, the difference method set is found, and a large amount of manpower cost and search time are saved.
[0119] In some embodiments, after the difference method set is obtained, a tester can test the business functions of the target project in a targeted manner through the difference method set, thereby improving the quality of the target project.
[0120] The embodiment of the application discloses a difference processing method based on code changes, which comprises the following steps: determining the code difference information between the code commit records corresponding to each comparison branch of a target project to be compared in difference, wherein different comparison branches are used to manage different versions of the target project; obtaining the project source code corresponding to each code commit record; compiling each project source code into an independently running JAR package, and reading the JAR package into a JAR file entry; traversing all the files in the JAR file entry, and determining the class file in the JAR file entry; obtaining the start code line and the end code line corresponding to each method in the class file; determining the difference method between each project source code according to the code difference information, the start code line and the end code line corresponding to each method, and obtaining the difference comparison result between each code commit record. After the relationship between the method and the code line is obtained by combining the analysis of the class file, the difference method can be accurately found through the difference code line. In this way, the search efficiency of the difference method before and after the code change can be improved.
[0121] In order to better implement the difference processing method based on code changes provided by the embodiment of the application, the embodiment of the application further provides a difference processing device based on code changes based on the above-mentioned difference processing method based on code changes. The meanings of the nouns are the same as those in the above-mentioned difference processing method based on code changes, and the specific implementation details can be referred to the description in the method embodiment.
[0122] Referring to Figure 2 , Figure 2 A structural block diagram of a code change-based difference processing apparatus provided for an embodiment of the present application, the apparatus comprising:
[0123] A first determining unit 301 configured to determine code difference information between code commit records corresponding to respective comparison branches of a target project that need to be compared for differences, wherein different comparison branches are used to manage different versions of the target project;
[0124] A first obtaining unit 302 configured to obtain project source codes corresponding to respective code commit records;
[0125] A compiling unit 303 configured to compile respective project source codes into JAR packages that can run independently, and read the JAR packages into JAR file entries;
[0126] A second determining unit 304 configured to traverse all files in the JAR file entries, and determine class files in the JAR file entries;
[0127] A second obtaining unit 305 configured to obtain a starting code line and an ending code line corresponding to each method in the class files;
[0128] A third determining unit 306 configured to determine difference methods between respective project source codes according to the code difference information, the starting code line and the ending code line corresponding to each method, and obtain difference comparison results between respective code commit records.
[0129] In some embodiments, the third determining unit 306 can comprise:
[0130] A matching sub-unit configured to match the difference code line with the starting code line and the ending code line corresponding to each method according to the difference type;
[0131] A first determining sub-unit configured to determine a method corresponding to the starting code line and the ending code line that match the difference code line successfully, and obtain the difference method.
[0132] In some embodiments, the matching sub-unit can be specifically configured to:
[0133] match the added code line with the starting code line and the ending code line corresponding to each method.
[0134] In some embodiments, the third determining unit 306 can further comprise:
[0135] The first obtaining subunit is configured to, if the new code line fails to match the start code line and the end code line of each method, obtain a method corresponding to a code block to which the new code line belongs as the difference method.
[0136] In some embodiments, the matching subunit can be specifically configured to:
[0137] match the modified code line with the start code line and the end code line corresponding to each method.
[0138] In some embodiments, the matching subunit can be specifically configured to:
[0139] match the deleted code line with the start code line and the end code line corresponding to each method.
[0140] In some embodiments, the first determining unit 301 can include:
[0141] The second determining subunit is configured to determine the specified code commit record corresponding to each comparison branch.
[0142] The second obtaining subunit is configured to obtain the code difference information between different versions of the target project submitted by each specified code commit record according to the identifier of each specified code commit record.
[0143] Embodiments of the present application disclose a code change-based difference processing apparatus. A first determining unit 301 determines code difference information between code commit records corresponding to each comparison branch of a target project that needs to be compared for differences, wherein different comparison branches are used to manage different versions of the target project. A first obtaining unit 302 obtains project source code corresponding to each code commit record. A compiling unit 303 compiles each project source code into a JAR package that can run independently, and reads the JAR package into a JAR file entry. A second determining unit 304 traverses all files in the JAR file entry and determines class files in the JAR file entry. A second obtaining unit 305 obtains a start code line and an end code line corresponding to each method in the class files. A third determining unit 306 determines difference methods between each project source code according to the code difference information, the start code line and the end code line corresponding to each method, and obtains a difference comparison result between each code commit record. In this way, the efficiency of finding difference methods before and after code changes can be improved.
[0144] Correspondingly, the embodiments of the present application also provide a terminal, which can be a server. As shown in Figure 3 Figure 3 A structural schematic diagram of a terminal is provided in the embodiments of the present application. The terminal 400 includes a processor 401 having one or more processing cores, a memory 402 having one or more computer readable storage media, and a computer program stored in the memory 402 and executable on the processor. The processor 401 is electrically connected to the memory 402. Those skilled in the art can understand that the terminal structure shown in the figure does not constitute a limitation on the terminal, and can include more or fewer components than shown in the figure, or combine certain components, or different component arrangements.
[0145] The processor 401 is the control center of the terminal 400, and connects all parts of the terminal 400 through various interfaces and lines. By running or loading the software programs and / or modules stored in the memory 402 and calling the data stored in the memory 402, the processor 401 performs various functions of the terminal 400 and processes data, thereby overall monitoring the terminal 400.
[0146] In the embodiments of the present application, the processor 401 in the terminal 400 loads the instructions corresponding to the processes of one or more application programs into the memory 402, and runs the application programs stored in the memory 402 by the processor 401, thereby realizing various functions according to the following steps:
[0147] Determine the code difference information between the code commit records corresponding to each comparison branch of the target project, wherein different comparison branches are used to manage different versions of the target project;
[0148] Obtain the project source code corresponding to each code commit record;
[0149] Compile each project source code into a JAR package that can run independently, and read the JAR package into a JAR file entry;
[0150] Traverse all files in the JAR file entry to determine the class files in the JAR file entry;
[0151] Obtain the starting code line and the ending code line corresponding to each method in the class file;
[0152] Determine the difference methods between each project source code according to the code difference information, the starting code line and the ending code line corresponding to each method, and obtain the difference comparison results between each code commit record.
[0153] The specific implementation of each operation can be referred to the previous embodiments, which will not be described here.
[0154] Optionally, as Figure 3 As shown, the terminal 400 further includes a touch display screen 403, a radio frequency circuit 404, an audio circuit 405, an input unit 406, and a power supply 407. The processor 401 is electrically connected with the touch display screen 403, the radio frequency circuit 404, the audio circuit 405, the input unit 406, and the power supply 407, respectively. Those skilled in the art can understand that Figure 3 The terminal structure shown in the figure does not constitute a limitation on the terminal, and can include more or fewer components than shown, or combine certain components, or different component arrangements.
[0155] The touch display screen 403 can be used to display a graphical user interface and receive operation instructions generated by a user acting on the graphical user interface. The touch display screen 403 can include a display panel and a touch panel. The display panel can be used to display messages input by a user or provided to a user and various graphical user interfaces of the terminal, which can be composed of graphics, text, icons, videos, and any combination thereof. Optionally, the display panel can be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc. The touch panel can be used to collect touch operations (such as operations of a user using a finger, a stylus, or any suitable object or accessory on or near the touch panel) of a user on or near it and generate corresponding operation instructions, and the operation instructions execute corresponding programs. Optionally, the touch panel can include two parts, a touch detection device and a touch controller. The touch detection device detects the touch position of a user and detects signals generated by touch operations, and transmits the signals to the touch controller; the touch controller receives touch messages from the touch detection device and converts them into touch coordinates, and then sends them to the processor 401, and can also receive commands from the processor 401 and execute them. The touch panel can cover the display panel, and when the touch panel detects a touch operation on or near it, it transmits to the processor 401 to determine the type of the touch event, and then the processor 401 provides corresponding visual output on the display panel according to the type of the touch event. In the embodiments of the present application, the touch panel and the display panel can be integrated into the touch display screen 403 to realize input and output functions. However, in some embodiments, the touch panel and the touch panel can realize input and output functions as two independent components. That is, the touch display screen 403 can also realize input functions as part of the input unit 406.
[0156] In the embodiments of the present application, the game application executed by the processor 401 generates a graphical user interface on the touch display screen 403, and the virtual scene in the graphical user interface includes at least one skill control area, and the skill control area includes at least one skill control. The touch display screen 403 is configured to present the graphical user interface and receive operation instructions generated by the user acting on the graphical user interface.
[0157] The radio frequency circuit 404 can be configured to transceive radio frequency signals, so as to establish wireless communication with a network device or other terminal, and transceive signals between the network device or other terminal.
[0158] The audio circuit 405 can be configured to provide an audio interface between the user and the terminal through a speaker and a microphone. The audio circuit 405 can convert the received audio data into an electrical signal and transmit the electrical signal to the speaker, so that the speaker converts the electrical signal into a sound signal and outputs the sound signal. On the other hand, the microphone collects a sound signal and converts the sound signal into an electrical signal, and the audio circuit 405 receives the electrical signal and converts the electrical signal into audio data. The audio data is output to the processor 401 for processing, and then transmitted to another terminal through the radio frequency circuit 404, or output to the memory 402 for further processing. The audio circuit 405 can also include a jack for connecting an external earphone to the terminal.
[0159] The input unit 406 can be configured to receive inputted numbers, character messages or user feature messages (such as fingerprint, iris, face message, etc.), and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
[0160] The power supply 407 is configured to supply power to each component of the terminal 400. Optionally, the power supply 407 can be logically connected to the processor 401 through a power management system, so as to realize functions such as charge management, discharge management and power consumption management through the power management system. The power supply 407 can also include one or more than one direct current or alternating current power supply, a recharging system, a power supply failure detection circuit, a power supply converter or inverter, a power supply state indicator and any other components.
[0161] Although Figure 3 The terminal 400 can also include a camera, a sensor, a wireless fidelity module, a Bluetooth module and the like, which are not described herein.
[0162] In the above embodiments, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the related description of other embodiments.
[0163] As can be seen, the terminal provided in the embodiment can determine the code difference information between the code commit records corresponding to each comparison branch of the target project that needs to be compared, wherein different comparison branches are used to manage different versions of the target project; obtain the project source code corresponding to each code commit record; compile each project source code into a JAR package that can run independently, and read the JAR package into a JAR file entry; traverse all files in the JAR file entry to determine class files in the JAR file entry; obtain the starting code line and the ending code line corresponding to each method in the class file; determine the difference method between each project source code according to the code difference information, the starting code line and the ending code line corresponding to each method, and obtain the difference comparison result between each code commit record.
[0164] Those skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructions or controlled by instructions related to hardware, which can be stored in a computer readable storage medium and loaded and executed by a processor.
[0165] To this end, the embodiment of the present application provides a computer readable storage medium, which stores a plurality of computer programs capable of being loaded by a processor to execute the steps in any of the difference processing methods based on code changes provided by the embodiments of the present application. For example, the computer program can execute the following steps:
[0166] Determine the code difference information between the code commit records corresponding to each comparison branch of the target project that needs to be compared, wherein different comparison branches are used to manage different versions of the target project;
[0167] Obtain the project source code corresponding to each code commit record;
[0168] Compile each project source code into a JAR package that can run independently, and read the JAR package into a JAR file entry;
[0169] Traverse all files in the JAR file entry to determine class files in the JAR file entry;
[0170] Obtain the starting code line and the ending code line corresponding to each method in the class file;
[0171] Determine the difference method between each project source code according to the code difference information, the starting code line and the ending code line corresponding to each method, and obtain the difference comparison result between each code commit record.
[0172] The specific implementation of each operation can be referred to the above embodiments, which will not be repeated here.
[0173] The storage medium can include a read-only memory (ROM), a random access memory (RAM), a magnetic disk, an optical disk, or the like.
[0174] Due to the computer program stored in the storage medium, the steps of any of the code change-based difference processing methods provided by the embodiments of the present application can be executed, thus achieving the beneficial effects of any of the code change-based difference processing methods provided by the embodiments of the present application. Details are described above, and will not be repeated here.
[0175] The above describes in detail the code change-based difference processing method, device, storage medium, and terminal provided by the embodiments of the present application. The principles and implementation manners of the present application are described by applying specific examples. The above description of the embodiments is only used to help understand the method of the present application and its core idea. Meanwhile, for those skilled in the art, the specific implementation manners and application ranges can be changed according to the idea of the present application. In summary, the content of the specification should not be understood as a limitation of the present application.< / numberentry>
Claims
1. A code change-based difference processing method characterized by comprising: The method comprises: determining code difference information between code submission records corresponding to each comparison branch of a target project requiring difference comparison, wherein different comparison branches are used to manage different versions of the target project; obtaining project source codes corresponding to each code submission record; compiling each project source code into an independently running JAR package, and reading the JAR package into a JAR file entry; traversing all files in the JAR file entry to determine class files in the JAR file entry; obtaining a starting code line and an ending code line corresponding to each method in the class file; determining difference methods between each project source code according to the code difference information, the starting code line and the ending code line corresponding to each method, to obtain difference comparison results between each code submission record.
2. The method of claim 1, wherein, The code difference information at least comprises a difference type and a difference code line; The determination of the difference methods between each project source code according to the code difference information, the starting code line and the ending code line corresponding to each method comprises: matching the difference code line with the starting code line and the ending code line corresponding to each method according to the difference type; and determining a method corresponding to the starting code line and the ending code line matched successfully with the difference code line as the difference method.
3. The method of claim 2, wherein, The difference type is an addition type, and the difference code line is an added code line; The matching of the difference code line with the starting code line and the ending code line corresponding to each method according to the difference type comprises: matching the added code line with the starting code line and the ending code line corresponding to each method.
4. The method of claim 3, wherein, Further comprising: if the added code line fails to be matched with the starting code line and the ending code line of each method, obtaining a method corresponding to a code block to which the added code line belongs as the difference method.
5. The method of claim 2, wherein, The difference type is a modification type, and the difference code line is a modified code line; The matching of the difference code line with the starting code line and the ending code line corresponding to each method according to the difference type comprises: matching the modified code line with the starting code line and the ending code line corresponding to each method.
6. The method of claim 2, wherein, The difference type is a deletion type, and the difference code line is a deleted code line; The matching of the difference code line with the starting code line and the ending code line corresponding to each method according to the difference type comprises: matching the deleted code line with the starting code line and the ending code line corresponding to each method.
7. The method of claim 1, wherein, The determination of the code difference information between code submission records corresponding to each comparison branch of the target project requiring difference comparison comprises: determining specified code submission records corresponding to each comparison branch; obtaining code difference information between different versions of the target project submitted by each specified code submission record according to an identifier of each specified code submission record.
8. A code change-based difference processing apparatus characterized by comprising: The apparatus comprises: a first determination unit configured to determine code difference information between code submission records corresponding to each comparison branch of a target project requiring difference comparison, wherein different comparison branches are used to manage different versions of the target project; A first obtaining unit, configured to obtain project source codes corresponding to respective code commit records; A compiling unit, configured to compile the respective project source codes into JAR packages respectively, and read the JAR packages into JAR file entries; A second determining unit, configured to traverse all files in the JAR file entries, and determine class files in the JAR file entries; A second obtaining unit, configured to obtain a starting code line and an ending code line corresponding to each method in the class files; A third determining unit, configured to determine difference methods between the respective project source codes according to the code difference information, the starting code line and the ending code line corresponding to each method, and obtain a difference comparison result between the respective code commit records.
9. A terminal comprising a memory, a processor and a computer program stored on the memory and running on the processor, wherein, The processor implements the code change-based difference processing method in any one of claims 1 to 7 when executing the program.
10. A storage medium, characterized by The storage medium stores a plurality of instructions, which are adapted to be loaded by the processor to execute the code change-based difference processing method in any one of claims 1 to 7.
Citation Information
Patent Citations
Software version evolution comparison analysis method based on AST
CN107203468A
Application test method and device based on call dependency relationship
CN112380130A