Code migration method and device, equipment, medium and program product
Through automated detection and dependency comparison charts, the differences in code files can be accurately identified and migrated, solving the omission problems caused by manual migration and achieving efficient and accurate code migration.
Patent Information
- Application Number
- CN202510653429.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-20
- Publication Date
- 2025-09-05
AI Technical Summary
During the project update process, the existing technology requires manual migration of code files, which is prone to omissions, resulting in operational errors or non-compliance with actual needs.
By automatically detecting the differences between the source code files and the code files to be updated, a dependency comparison diagram is generated, the code to be migrated is accurately determined, and it is automatically migrated to the code files to be updated based on the dependency relationships, including code items that are missing, have incorrect dependencies, and have inconsistent external library versions.
It reduces omissions in the manual migration process, improves the accuracy and completeness of code migration, is applicable to both small and large code items, and increases applicability and practicality.
Smart Images

Figure CN120596071A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a code migration method, apparatus, device, medium, and program product. Background Art
[0002] In application project development, as the project system increases, in order to achieve low code, when updating the project, you can generate update code externally and then migrate the update code to the project code.
[0003] In some implementations, when the first project needs to be updated, the code files to be migrated in the second project can be migrated to the original project, so that the first project is updated based on the first project and the corresponding application is loaded using the updated first project. In this process, when migrating the updated part, manual migration is required during the migration process, and the code files to be migrated are directly migrated, which can easily lead to omissions, causing the first project to run incorrectly or not in accordance with the actual situation. Summary of the Invention
[0004] The embodiments of the present application provide a code migration method, apparatus, device, medium, and program product to reduce manual migration and code omissions.
[0005] In a first aspect, an embodiment of the present application provides a code migration method, comprising:
[0006] Obtaining a source code file and a code file to be updated; the source code file is an updated code file of the code file to be updated;
[0007] Determine at least one code to be migrated from the source code file and the code file to be updated, wherein the code to be migrated represents a code item having differences between the code item migrated from the source code file to the code file to be updated;
[0008] The at least one code to be migrated is migrated to the code file to be updated to obtain a target code file.
[0009] In an embodiment of the present application, when migrating the code to be migrated in the present application, at least one code to be migrated is automatically determined and automatically migrated to the code file to be updated. When automatically determining at least one code to be migrated, omissions can be reduced. In addition, the code to be migrated in the present application can be a small-volume code item or a large-volume code item, so the present application can also be applicable to small-volume code items, which can increase applicability.
[0010] In a possible implementation, determining at least one code to be migrated from the source code file and the code file to be updated includes:
[0011] respectively detecting at least one code item in the source code file and the code file to be updated;
[0012] Determining the dependency relationship between each code item included in the source code file and the code file to be updated;
[0013] generating a first dependency comparison graph according to at least one code item and a dependency relationship of the source code file;
[0014] generating a second dependency comparison graph according to at least one code item and dependency relationship of the code file to be updated;
[0015] At least one code to be migrated is determined according to the first dependency comparison graph and the second dependency comparison graph.
[0016] In an embodiment of the present application, at least one code item included in the source code file and the code file to be updated is detected respectively. By comparing the two dependency comparison graphs, the code items with differences can be accurately determined, and then the code to be migrated can be accurately determined.
[0017] In a possible implementation, the code item includes at least one common code mother file, common code sub-files under each of the common code mother files, style code text and function code text under each of the common code sub-files, and / or sub-module code files;
[0018] Detecting at least one code item in the source code file and the code file to be updated respectively, including:
[0019] Detecting at least one common code parent file, common code child files under each common code parent file, and at least one style code text and at least one function code text under each common code child file in the source code file and the code file to be updated respectively according to a code item dependency order;
[0020] And / or, the source code file and at least one submodule code file in the code file to be updated are detected respectively according to the code item dependency order.
[0021] By pulling down layer by layer according to the dependency order of the code items, the code items of different volumes or types are detected, so that at least one code item in the source code file and the code file to be updated can be accurately detected.
[0022] In the embodiment of the present application, the code items can be pulled down layer by layer according to their dependency order to detect the common code parent file, and then the common code child files can be pulled down layer by layer to detect the style code text and function code text. If a submodule code file exists, the submodule code file can also be detected according to the dependency order of the common code parent file.
[0023] In one possible implementation, the code to be migrated includes at least one of a first code to be migrated, a second code to be migrated, and a third code to be migrated;
[0024] The determining at least one code to be migrated according to the first dependency comparison graph and the second dependency comparison graph includes:
[0025] If it is determined from the first dependency comparison graph that there is a missing code item in the second dependency comparison graph, then the missing code item is determined as the first code to be migrated;
[0026] If a code item with an incorrect dependency relationship in the second dependency comparison graph is determined from the first dependency comparison graph, the code item with a correct dependency relationship in the first dependency comparison graph is determined as the second code to be migrated;
[0027] If it is determined from the first dependency comparison graph that the second dependency comparison graph has a code item with inconsistent external library version information, then the code item with inconsistent external library version information in the first dependency comparison graph is determined as the third-generation migration code;
[0028] After determining at least one code to be migrated according to the first dependency comparison graph and the second dependency comparison graph, the method further includes:
[0029] Determine a dependency relationship of at least one code to be migrated; the first code to be migrated is a first dependency relationship; the second code to be migrated is a second dependency relationship; and the third code to be migrated is a third dependency relationship.
[0030] In the embodiment of the present application, different types of codes to be migrated are determined according to different differences, thereby accurately determining the codes to be migrated. The types of codes to be migrated are diverse, and the applicability is wider.
[0031] In one possible implementation, migrating the at least one code to be migrated into the code file to be updated to obtain a target code file includes:
[0032] If the first code to be migrated exists, migrating the first code to be migrated to the code file to be updated according to the first dependency relationship to obtain a target code file;
[0033] If the second code to be migrated exists, deleting the code item with the wrong dependency in the code file to be updated, and migrating the second code to be migrated to the code file to be updated according to the second dependency to obtain a target code file;
[0034] If the third code to be migrated exists, the code items with inconsistent external library version information in the code file to be updated are deleted, and the third code to be migrated is migrated to the code file to be updated according to the third dependency relationship to obtain the target code file.
[0035] In the embodiment of the present application, different types of codes to be migrated are migrated to the code file to be updated using their respective corresponding dependency relationships, so different types of deletion can be achieved, thereby improving practicality.
[0036] In one possible implementation, the first code to be migrated is any public code file; the public code file includes a public code parent file or a public code child file; the first dependency relationship includes an external dependency relationship and an internal dependency relationship of the public code file;
[0037] If the first code to be migrated exists, migrating the first code to be migrated to the code file to be updated according to the first dependency relationship to obtain a target code file includes:
[0038] If the first code to be migrated is any public code file, the style code text and function code text under the public code file are migrated to the code file to be updated according to the corresponding internal dependency relationship, and the public code file formed by the migrated style code text and function code text satisfies the external dependency relationship to obtain the target code file.
[0039] In an embodiment of the present application, for any large-volume public code file, it can be further refined to migrate the small-volume style code text and function code text into the code file to be updated, thereby ensuring the integrity of the migration and reducing the possibility of omissions.
[0040] In one possible implementation, after migrating the at least one code to be migrated into the code file to be updated to obtain a target code file, the method includes:
[0041] If there is an operation to migrate the inconsistent version information of the external library, the code item corresponding to the migrated external library version is configured to obtain the configured target code file;
[0042] Detecting at least one code item included in a target detection code file and the dependency relationship between the code items to generate a structure detection result; the target detection code file is a target code file or a configured target code file;
[0043] After the structural detection is completed, a functional detection is performed on the target detection code file to generate a functional detection result;
[0044] A migration report is generated based on the structural detection results and the functional detection results; the migration report includes each migrated code item, the dependency relationship of each migrated code item, and optimization suggestions.
[0045] In the embodiment of the present application, in order to ensure integrity, the target detection code file is subjected to structural detection and functional detection, and a migration report is generated, which helps development users to perform maintenance and improves overall efficiency.
[0046] In a second aspect, an embodiment of the present application provides a code migration device, comprising:
[0047] An acquisition module, configured to acquire a source code file and a code file to be updated; the source code file being an updated code file of the code file to be updated;
[0048] a determination module, configured to determine at least one code to be migrated from the source code file and the code file to be updated, wherein the code to be migrated represents a code item having differences between the code item migrated from the source code file to the code file to be updated;
[0049] The migration module is configured to migrate the at least one code to be migrated to the code file to be updated to obtain a target code file.
[0050] In a possible implementation, the determining module is specifically configured to:
[0051] respectively detecting at least one code item in the source code file and the code file to be updated;
[0052] Determining the dependency relationship between each code item included in the source code file and the code file to be updated;
[0053] generating a first dependency comparison graph according to at least one code item and a dependency relationship of the source code file;
[0054] generating a second dependency comparison graph according to at least one code item and dependency relationship of the code file to be updated;
[0055] At least one code to be migrated is determined according to the first dependency comparison graph and the second dependency comparison graph.
[0056] In a possible implementation, the determining module is specifically configured to:
[0057] Detecting at least one common code parent file, common code child files under each common code parent file, and at least one style code text and at least one function code text under each common code child file in the source code file and the code file to be updated respectively according to a code item dependency order;
[0058] And / or, the source code file and at least one submodule code file in the code file to be updated are detected respectively according to the code item dependency order.
[0059] In one possible implementation, the determining module is specifically configured to:
[0060] If it is determined from the first dependency comparison graph that there is a missing code item in the second dependency comparison graph, then the missing code item is determined as the first code to be migrated;
[0061] If a code item with an incorrect dependency relationship in the second dependency comparison graph is determined from the first dependency comparison graph, the code item with a correct dependency relationship in the first dependency comparison graph is determined as the second code to be migrated;
[0062] If it is determined from the first dependency comparison graph that the second dependency comparison graph has a code item with inconsistent external library version information, then the code item with inconsistent external library version information in the first dependency comparison graph is determined as the third-generation migration code;
[0063] The determining module is further specifically configured to:
[0064] Determine a dependency relationship of at least one code to be migrated; the first code to be migrated is a first dependency relationship; the second code to be migrated is a second dependency relationship; and the third code to be migrated is a third dependency relationship.
[0065] In one possible implementation, the migration module is specifically configured to:
[0066] If the first code to be migrated exists, migrating the first code to be migrated to the code file to be updated according to the first dependency relationship to obtain a target code file;
[0067] If the second code to be migrated exists, deleting the code item with the wrong dependency in the code file to be updated, and migrating the second code to be migrated to the code file to be updated according to the second dependency to obtain a target code file;
[0068] If the third code to be migrated exists, the code items with inconsistent external library version information in the code file to be updated are deleted, and the third code to be migrated is migrated to the code file to be updated according to the third dependency relationship to obtain the target code file.
[0069] In one possible implementation, the first code to be migrated is any public code file; the public code file includes a public code parent file or a public code child file; the first dependency relationship includes an external dependency relationship and an internal dependency relationship of the public code file;
[0070] The migration module is specifically used for:
[0071] If the first code to be migrated is any public code file, the style code text and function code text under the public code file are migrated to the code file to be updated according to the corresponding internal dependency relationship, and the public code file formed by the migrated style code text and function code text satisfies the external dependency relationship to obtain the target code file.
[0072] In one possible implementation, the configuration and detection module is specifically configured to:
[0073] If there is an operation to migrate the inconsistent version information of the external library, the code item corresponding to the migrated external library version is configured to obtain the configured target code file;
[0074] Detecting at least one code item included in a target detection code file and the dependency relationship between the code items to generate a structure detection result; the target detection code file is a target code file or a configured target code file;
[0075] After the structural detection is completed, a functional detection is performed on the target detection code file to generate a functional detection result;
[0076] A migration report is generated based on the structural detection results and the functional detection results; the migration report includes each migrated code item, the dependency relationship of each migrated code item, and optimization suggestions.
[0077] In a third aspect, an embodiment of the present application provides a code migration device, comprising: a memory, a processor;
[0078] The memory stores computer-executable instructions;
[0079] The processor executes the computer-executable instructions stored in the memory, so that the processor executes the above first aspect and / or various possible implementations of the first aspect.
[0080] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the first aspect above and / or various possible implementation methods of the first aspect.
[0081] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the above first aspect and / or various possible implementation methods of the first aspect.
[0082] The code migration method, apparatus, device, medium and program product provided in the embodiments of the present application first determine at least one code to be migrated included in the acquired source code file and the code file to be updated, and the code to be migrated can reflect the difference between the two code files. Further, the code to be migrated is migrated to the code file to be updated, thereby obtaining the target code file. In the present application, when migrating the code to be migrated, at least one code to be migrated is automatically determined and automatically migrated to the code file to be updated. When the at least one code to be migrated is automatically determined, omissions can be reduced. In addition, the code to be migrated in the present application can be a small-volume code item or a large-volume code item, so the present application can also be applicable to small-volume code items, which can increase applicability. BRIEF DESCRIPTION OF THE DRAWINGS
[0083] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0084] Figure 1 A schematic diagram of an application scenario provided for this application;
[0085] Figure 2 A schematic diagram of a code migration method provided in an embodiment of the present application;
[0086] Figure 3 A schematic diagram of another code migration method provided in an embodiment of the present application;
[0087] Figure 4 A complete schematic diagram of code migration provided in an embodiment of the present application;
[0088] Figure 5 A schematic diagram of the structure of a code migration device provided in an embodiment of the present application;
[0089] Figure 6 A schematic diagram of the structure of the code migration device provided in an embodiment of the present application.
[0090] The above drawings illustrate specific embodiments of the present application, which will be described in more detail below. These drawings and the textual description are not intended to limit the scope of the present application in any way, but rather to illustrate the concepts of the present application to those skilled in the art by reference to specific embodiments. DETAILED DESCRIPTION
[0091] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
[0092] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.
[0093] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards, and corresponding operation entrances must be provided for users to choose to authorize or refuse.
[0094] For ease of understanding, below, combined with Figure 1 , describes the application scenarios to which the embodiments of the present application are applicable. Figure 1 This is a schematic diagram of an application scenario provided for this application. Figure 1 , including an electronic device 101. The electronic device 101 can be a computer, server, or other device. Specifically, the electronic device 101 obtains a source code file and a code file to be updated. Then, the electronic device 101 determines at least one code to be migrated from the source code file and the code file to be updated, and migrates the at least one code to be migrated to the code file to be updated to obtain a target code file. In this scenario, the target code file is the updated code file, and a target project can be generated based on the target code file.
[0095] In some implementations, when the first project needs to be updated, the code files to be migrated in the second project can be migrated to the original project, so that the first project is updated and the corresponding application is loaded using the updated first project. In the above process, the code file to be migrated is a large file, and the file to be migrated can also include more detailed code snippets, etc. In some implementations, when migrating the updated part, it is necessary to manually determine the code file to be migrated during the migration process and manually enter the command to migrate it. In some implementations, the code file to be migrated is directly migrated as a whole, so it is easy to miss something, resulting in the lack of certain code snippets in the updated first project, etc., which leads to errors in the operation of the first project or inconsistency with the actual situation.
[0096] In order to address the deficiencies of the prior art, the inventors of this solution have conducted creative research and designed a new solution. In the embodiment of this application, at least one code to be migrated is first determined from the source code file and the code file to be updated. The code to be migrated is a code item with differences between the two code files, and the code to be migrated is then migrated to the code file to be updated. In this application, when migrating the code to be migrated, the at least one code to be migrated and the migration are automated, thereby reducing the situation where manual intervention leads to missed migrations. In addition, the code to be migrated in this application can be code items of different sizes, so this application has a wide range of applications and can increase applicability.
[0097] The code migration in this application can be applied to any scenario related to code migration, such as project splitting and merging, project version merging and synchronization, and market customization (when customizing projects for different markets or customers, when a large number of code files or code snippets are shared between projects, code reuse and migration are required).
[0098] In this application, the integrated development environment or plug-in can provide a code prompt function, thereby determining the missing code items.
[0099] The object code files in this application can be used in application projects, such as web pages, applications or applets, etc., without limitation here.
[0100] In some implementations, manual management of submodule code files, code items with different external library version information, and other code items is required, which is prone to errors and increases maintenance difficulty. However, the present application can automatically migrate any type of code to be migrated, making maintenance simple and improving practicality.
[0101] It should be noted that when the external library version information is inconsistent, the target code file may not run normally.
[0102] It should be noted that after generating the migration report, the application can continue to automatically unit test the target detection code file to confirm that the corresponding project remains functionally good. If there is a problem, the code migration device can automatically debug it or prompt the developer to optimize or correct it.
[0103] The method of the present application is described below through specific embodiments. It should be noted that the following embodiments can exist independently or in combination with each other, and the same or similar contents will not be repeated in different embodiments.
[0104] Figure 2 This is a flow chart of a code migration method provided in an embodiment of the present application. Figure 2 , the method may include:
[0105] S201. Obtain a source code file and a code file to be updated; the source code file is an updated code file of the code file to be updated.
[0106] The execution subject of the embodiment of the present application is a code migration device, and the code migration device is located in a code migration device. The code migration device in the embodiment of the present application can be any electronic device, such as a computer or a server, etc., and is not limited here.
[0107] Among them, the source code file refers to the updated code file, and the source code file is updated based on the code file to be updated. If it is an update of a certain area in the code file to be updated, the source code file may only include the updated code file after the update of the area, or it may also include the code files of other areas that do not need to be updated.
[0108] The code file to be updated refers to the code file to which the code to be migrated needs to be migrated in order to update the code file.
[0109] It should be noted that the code file to be updated can be the main branch, and the source code file can be the root branch of the main branch. The code items that differ between the source code file and the code file to be updated are migrated to the code file to be updated.
[0110] Optionally, the source code file and the code file to be updated may be obtained from its own storage area, or from an external device, and there is no restriction here.
[0111] S202: Determine at least one code to be migrated from the source code file and the code file to be updated, where the code to be migrated represents a code item having differences between the code item migrated from the source code file and the code file to be updated.
[0112] The term "different code items" refers to code items whose code files to be updated differ from the source code files. The code to be migrated is included in the source code files. This includes missing code items, code items with correct dependencies, code items with inconsistent external library version information in the first dependency comparison diagram, and other code items, without limitation.
[0113] S203: Migrate at least one code to be migrated to a code file to be updated to obtain a target code file.
[0114] In some scenarios, the source code file is migrated and merged into the code file to be updated to obtain the target code file.
[0115] It should be noted that the code to be migrated can be a large-volume code item or a small-volume code item. When migrating a large-volume code item, the large-volume code item is further refined and the small-volume code items included in the large-volume code are migrated. In this application, both large-volume and small-volume code items can be automatically migrated, thereby increasing the applicability.
[0116] In an embodiment of the present application, when migrating the code to be migrated in the present application, at least one code to be migrated is automatically determined and automatically migrated to the code file to be updated. When automatically determining at least one code to be migrated, omissions can be reduced. In addition, the code to be migrated in the present application can be a small-volume code item or a large-volume code item, so the present application can also be applicable to small-volume code items, which can increase applicability.
[0117] At least one code to be migrated can be determined from the source code file and the code file to be updated in the following manner: Figure 3 This is a flowchart of another code migration method provided in this application embodiment. Figure 3 ,include:
[0118] S301: Detect at least one code item in a source code file and a code file to be updated respectively.
[0119] Optionally, the code migration device may adopt static code analysis and use abstract syntax tree technology to automatically identify at least one code item in the two code files.
[0120] The code items in the embodiment of the present application may have different sizes and different types, and there is a dependency relationship between the code items.
[0121] Optionally, the code item may include at least one of a common code file, a sub-module code file, and an external library file. The code item HIA may include a common code parent file and a common code child file in the common code file, and may also include style code text and function code text under the common code child file.
[0122] In the embodiment of the present application, the code item includes at least one common code mother file, common code sub-files under each common code mother file, style code text and function code text under each common code sub-file, and / or sub-module code file.
[0123] The style code text may include global cascading style text and local cascading style text. The style code text is a static code text.
[0124] The function code text may include common function text and tool function text. Function code text is a dynamic code text.
[0125] Among them, the public function text is a function that is shared and called. Its main purpose is to reduce code duplication and improve the maintainability and reusability of the code.
[0126] Among them, the tool function text is a special public function, which is mainly used to provide some general auxiliary functions.
[0127] At least one code item in the source code file and the code file to be updated can be detected separately in the following manner: at least one common code parent file, common code sub-files under each common code parent file, and at least one style code text and at least one function code text under the common code sub-file in the source code file and the code file to be updated can be detected separately in the order of code item dependency; and / or, at least one sub-module code file in the source code file and the code file to be updated can be detected separately in the order of code item dependency.
[0128] The code item dependency order refers to the dependency order of the large-volume code items layer by layer downward.
[0129] In the embodiment of the present application, the code items can be pulled down layer by layer according to their dependency order to detect the common code parent file, and then the common code child files can be pulled down layer by layer to detect the style code text and function code text. If a submodule code file exists, the submodule code file can also be detected according to the dependency order of the common code parent file.
[0130] It should be noted that the external dependencies of the common code parent file can depend on the sub-module code file, so the sub-module code file can be pulled down along this dependency order and detected.
[0131] The submodule code file is an independently managed nested repository, existing as a sub-code file of a source code file. The submodule code file is created using Git Submodule (Git for short) technology.
[0132] In one embodiment, the method may further include: detecting, according to the code item dependency order, a code item corresponding to at least one external library in the source code file and the code file to be updated.
[0133] Among them, external libraries refer to third-party libraries, frameworks or components that the project depends on. Among them, projects refer to the projects corresponding to the target code files. The projects can be application projects or mini-program projects, etc., and there is no restriction here.
[0134] In the embodiment of the present application, code items of different volumes or types are detected layer by layer according to the code item dependency order, so that at least one code item in the source code file and the code file to be updated can be accurately detected.
[0135] S302: Determine the dependency relationship between each code item included in the source code file and the code file to be updated.
[0136] Wherein, for the source code file, the dependency relationship is determined based on the dependency order of each code item included therein.
[0137] Wherein, for the code file to be updated, the dependency relationship is determined based on the dependency order of each code item included therein.
[0138] It should be noted that large code items depend on small code items. In the embodiment of the present application, there may be dependencies between various style code texts, between various function code texts, and between various style code texts and function code texts.
[0139] S303: Generate a first dependency comparison graph according to at least one code item and dependency relationship of the source code file.
[0140] S304: Generate a second dependency comparison graph according to at least one code item and dependency relationship of the code file to be updated.
[0141] It should be noted that the first dependency comparison diagram and the second dependency comparison diagram can respectively reflect the dependency relationship between the code items in their respective code files.
[0142] S305: Determine at least one code to be migrated according to the first dependency comparison graph and the second dependency comparison graph.
[0143] Furthermore, the two dependency comparison graphs are compared to find different code items therefrom, and then at least one code to be migrated can be determined from the first dependency comparison graph. In the present application, the volumes of the code to be migrated may be different.
[0144] In an embodiment of the present application, at least one code item included in the source code file and the code file to be updated is detected respectively. By comparing the two dependency comparison graphs, the code items with differences can be accurately determined, and then the code to be migrated can be accurately determined.
[0145] In the embodiment of the present application, the code to be migrated includes at least one of a first code to be migrated, a second code to be migrated, and a third code to be migrated.
[0146] At least one code to be migrated may be determined according to the first dependency comparison graph and the second dependency comparison graph in the following manner:
[0147] If it is determined from the first dependency comparison graph that there is a missing code item in the second dependency comparison graph, the missing code item is determined as the first code to be migrated.
[0148] For example, if the first dependency comparison graph includes three code items, namely code item 1, code item 2 and code item 3, wherein code item 1 depends on code item 2, and code item 2 depends on code item 3; the second dependency comparison graph includes two code items, namely code item 1 and code item 2, wherein code item 1 depends on code item 2, after comparison, it can be determined that there is a missing code item in the second dependency comparison graph. Therefore, the missing code item in the second dependency comparison graph is determined as the first code to be migrated, that is, code item 3.
[0149] If a code item with an incorrect dependency relationship in the second dependency comparison graph is determined from the first dependency comparison graph, the code item with a correct dependency relationship in the first dependency comparison graph is determined as the second code to be migrated.
[0150] For example, if the first dependency comparison diagram includes two code items, namely code item 1 and code item 3, wherein code item 1 depends on code item 3; the second dependency comparison diagram includes two code items, namely code item 1 and code item 2, wherein code item 1 depends on code item 2, wherein code item 2 has an incorrect dependency relationship, the code item with the correct dependency relationship, i.e., code item 3, is determined as the second code to be migrated.
[0151] If it is determined from the first dependency comparison graph that the code item in the second dependency comparison graph has inconsistent external library version information, the code item in the first dependency comparison graph with inconsistent external library version information is determined as the third-generation migration code.
[0152] For example, if the first dependency comparison diagram includes two code items, namely code item 1 and code item 3, wherein code item 1 depends on code item 3; and the second dependency comparison diagram includes two code items, namely code item 1 and code item 3, wherein code item 1 depends on code item 3, wherein the external library version information of code item 3 in the second dependency comparison diagram is inconsistent with the external library version information of code item 3 in the first dependency comparison diagram, wherein code item 3 is the code item corresponding to the external library. Further, code item 3 in the first dependency comparison diagram is determined as the third code to be migrated.
[0153] Optionally, code item 3 in the first dependency comparison diagram may be a code item with a higher version of the external library, and code item 3 in the second dependency comparison diagram may be a code item with a lower version of the external library. Therefore, the code item with a lower version of the external library in the code file to be updated needs to be updated, so code item 3 in the first dependency comparison diagram is determined as the third code to be migrated.
[0154] After determining at least one code to be migrated according to the first dependency comparison graph and the second dependency comparison graph, the method further includes:
[0155] Determine the dependency relationship of at least one code to be migrated; the first code to be migrated is a first dependency relationship; the second code to be migrated is a second dependency relationship; and the third code to be migrated is a third dependency relationship.
[0156] Optionally, the dependencies of at least one code item to be migrated may include internal dependencies or external dependencies. Internal dependencies refer to dependencies between code items included in the code item to be migrated, which are internal dependencies. External dependencies refer to dependencies between the code item to be migrated and other external code items.
[0157] In the embodiment of the present application, the types of codes to be migrated are diversified, thereby increasing the richness.
[0158] In the embodiment of the present application, different types of codes to be migrated are determined according to different differences, thereby accurately determining the codes to be migrated. The types of codes to be migrated are diverse, and the applicability is wider.
[0159] You can migrate at least one code to be migrated to the code file to be updated in the following way to obtain the target code file:
[0160] If the first code to be migrated exists, the first code to be migrated is migrated to the code file to be updated according to the first dependency relationship to obtain a target code file.
[0161] If the second code to be migrated exists, deleting the code item with the wrong dependency in the code file to be updated, and migrating the second code to be migrated to the code file to be updated according to the second dependency to obtain a target code file;
[0162] If there is a third code to be migrated, the code items with inconsistent external library version information in the code file to be updated are deleted, and the third code to be migrated is migrated to the code file to be updated according to the third dependency relationship to obtain a target code file.
[0163] Optionally, if the code to be migrated includes a first code to be migrated and a second code to be migrated, it is necessary to migrate the first code to be migrated to the code file to be updated according to the first dependency relationship, and migrate the second code to be migrated to the code file to be updated according to the second dependency relationship, and delete redundant code items to obtain the target code file. Alternatively, the code to be migrated may include the above three types of code to be migrated, and then migrate the codes to be migrated to the code file to be updated according to their respective corresponding dependency relationships, so as to obtain the target code file. The redundant code items include code items with incorrect dependency relationships and / or code items with inconsistent external library version information in the code file to be updated.
[0164] Optionally, if the code to be migrated includes only one type of code to be migrated, it is necessary to migrate the code to be migrated to the code file to be updated according to the dependency relationship corresponding to the code to be migrated, so as to obtain the target code file.
[0165] In the embodiment of the present application, different types of codes to be migrated are migrated to the code file to be updated using their respective corresponding dependency relationships, so different types of deletion can be achieved, thereby improving practicality.
[0166] In the embodiment of the present application, the first code to be migrated is any public code file; the public code file includes a public code parent file or a public code child file; the first dependency relationship includes an external dependency relationship and an internal dependency relationship of the public code file.
[0167] If there is a first code to be migrated, the first code to be migrated may be migrated to the code file to be updated according to the first dependency relationship to obtain a target code file in the following manner:
[0168] If the first code to be migrated is any public code file, the style code text and function code text under the public code file are migrated to the code file to be updated according to the corresponding internal dependency relationship, and the public code file formed by the migrated style code text and function code text satisfies the external dependency relationship to obtain the target code file.
[0169] For example, assuming the common code file is a common code mother file, at least one style code text and at least one function code text included in each common code child file under the common code mother file are migrated to the code file to be updated according to the corresponding internal dependencies. The above internal dependencies include the dependency between the common code mother file and its subordinate common code child files, the dependency between the style code text and the function code text in each common code child file, and the dependency between each common code child file.
[0170] For example, assuming that the common code file is a common code sub-file, at least one style code text and at least one function code text in the common code sub-file are migrated to the code file to be updated according to the corresponding internal dependencies. The above internal dependencies include the dependencies between the style code text and the function code text in the common code sub-file.
[0171] Optionally, the first code to be migrated may include at least one missing common code sub-file.
[0172] Optionally, the first code to be migrated may include part of the style code text and / or part of the mathematical function under a certain common code sub-file.
[0173] It should be noted that if the first code to be migrated is a public code file, it is necessary to start from more subdivided small-volume code items and migrate the small-volume style code text and function code text included therein to the code file to be updated.
[0174] In some implementations, the code files to be migrated are directly migrated. However, since the code files to be migrated are large and unstable, they are easily missed during the migration process. Therefore, when migrating large code items, they are easily missed and cannot be completely migrated. In the embodiments of the present application, even if the code to be migrated is a large public code file, the small code items contained therein are still migrated as units into the code files to be updated.
[0175] Optionally, the first code to be migrated may be a submodule code file, and the submodule code file is migrated to the code file to be updated according to the corresponding first dependency relationship.
[0176] Optionally, the first code to be migrated may be an external library file, and the external library file is migrated to the code file to be updated according to the corresponding first dependency relationship.
[0177] Optionally, the first code to be migrated may include at least one of any common code file, a submodule code file, and an external library file.
[0178] It should be noted that after the first code to be migrated is migrated to the code file to be updated, if other types of code to be migrated exist, the other types of code to be migrated can be migrated simultaneously or after the migration of the first code to be migrated, based on the migrated code file, to ultimately obtain the target code file. If no other types of code to be migrated exist, the migrated code file is the target code file.
[0179] It should be noted that the common code file formed by the migrated style code text and function code text constitutes the migrated code file.
[0180] It should be noted that the public code file formed by the migrated style code text and function code text satisfies the external dependency, that is, the external dependency of the public code file is consistent with the external dependency in the first dependency.
[0181] In an embodiment of the present application, for any large-volume public code file, it can be further refined to migrate the small-volume style code text and function code text into the code file to be updated, thereby ensuring the integrity of the migration and reducing the possibility of omissions.
[0182] The embodiment of the present application further includes, after migrating at least one code to be migrated into a code file to be updated to obtain a target code file, specifically:
[0183] Step 1: If there is an operation to migrate the inconsistent version information of the external library, the code item corresponding to the migrated external library version is configured to obtain the configured target code file.
[0184] Optionally, if there is inconsistency in the external library version information, the third code to be migrated is migrated, and the target code file is finally obtained.
[0185] The target code file includes code items corresponding to the migrated external library version, and the code items can be configured using a preset tool to obtain the configured target code file. The above configuration includes at least one of a run configuration, a conditional configuration, and a basic configuration for the code items corresponding to the migrated external library version.
[0186] Step 2: Detect at least one code item included in the target detection code file and the dependency relationship between the code items to generate a structure detection result.
[0187] The target detection code file is a target code file or a configured target code file.
[0188] Furthermore, an integrity check is performed on at least one code item included in the target detection code file, and dependency relationships between the code items are checked to implement structure detection, thereby generating a structure detection result.
[0189] Step 3: After the structural detection is completed, the target detection code file is functionally tested to generate functional test results.
[0190] Furthermore, a compilation test may be used to perform a functional test on the target test code file, and a functional test may be performed on each code item to determine whether each code item can run normally and generate a functional test result.
[0191] Step 4: Generate a migration report based on the structural and functional test results. The migration report includes each migrated code item, its dependencies, and optimization suggestions.
[0192] Optionally, the structure detection result may include each detected code item, the dependency relationship of each code item, each migrated code item and the dependency relationship of each migrated code item, or other items, which are not limited here.
[0193] Optionally, the functional test results may also include the operating status of each code item (for example, normal operation or abnormal operation), external library version optimization suggestions, potential problems that may exist in each code item, etc., which are not limited here.
[0194] Optionally, the structural test results and the functional test results are combined or integrated to generate a migration report.
[0195] In the embodiment of the present application, in order to ensure integrity, the target detection code file is subjected to structural detection and functional detection, and a migration report is generated, which helps development users to perform maintenance and improves overall efficiency.
[0196] In the embodiment of the present application, automated code migration can improve migration efficiency. The code migration device determines at least one code item and the dependency relationship between the code items, compares the dependency comparison graphs, determines the code to be migrated, and migrates the migrated code, so code migration is more efficient.
[0197] In the embodiment of the present application, during migration, migration can be performed based on small-volume code items, and code item detection is more accurate, thereby ensuring the integrity of code migration.
[0198] In the embodiments of the present application, automated code item detection and migration can avoid operational anomalies or functional errors caused by missing code items, thereby reducing debugging and repair time.
[0199] In an embodiment of the present application, two dependency comparison graphs can be compared to visualize the dependency relationship, and the dependency comparison graph can be displayed intuitively, thereby displaying the dependency structure, which helps to simplify code management and maintenance.
[0200] In the embodiment of the present application, adaptation can be performed based on internal dependencies and external dependencies, and code items of different external library version information can be migrated to achieve updates and improve compatibility.
[0201] Figure 4 This is a complete code migration diagram provided by the embodiment of this application. Figure 4 , specifically including:
[0202] S401: The code migration device obtains a source code file and a code file to be updated.
[0203] S402: The code migration device detects at least one code item in the source code file and the code file to be updated respectively.
[0204] S403: The code migration device determines the dependency relationship between each code item included in the source code file and the code file to be updated.
[0205] S404: The code migration device generates a first dependency comparison graph according to at least one code item and dependency relationship of the source code file.
[0206] S405: The code migration device generates a second dependency comparison graph according to at least one code item and dependency relationship of the code file to be updated.
[0207] S406: The code migration device determines at least one code to be migrated according to the first dependency comparison graph and the second dependency comparison graph.
[0208] S407: If the code migration device determines from the first dependency comparison graph that there is a missing code item in the second dependency comparison graph, the missing code item is determined as the first code to be migrated, and the corresponding internal dependency relationship and external dependency relationship are determined.
[0209] S408. If the first code to be migrated is any public code file, the code migration device migrates the style code text and function code text under the public code file to the code file to be updated according to the corresponding internal dependency relationship, and makes the public code file formed by the migrated style code text and function code text meet the external dependency relationship to obtain the target code file.
[0210] Figure 5 This is a schematic diagram of the structure of the code migration device provided in the embodiment of this application. Figure 5 , the code migration device 10 may include:
[0211] An acquisition module 11 is configured to acquire a source code file and a code file to be updated; the source code file is an updated code file of the code file to be updated;
[0212] A determination module 12 is configured to determine at least one code to be migrated from the source code file and the code file to be updated, where the code to be migrated represents a code item having differences between the code item migrated from the source code file and the code file to be updated;
[0213] The migration module 13 is configured to migrate at least one code to be migrated to a code file to be updated, so as to obtain a target code file.
[0214] In a possible implementation, the determination module 12 is specifically configured to:
[0215] Detecting at least one code item in the source code file and the code file to be updated respectively;
[0216] Determining the dependency relationship between each code item included in the source code file and the code file to be updated;
[0217] generating a first dependency comparison graph according to at least one code item and a dependency relationship of the source code file;
[0218] generating a second dependency comparison graph according to at least one code item and dependency relationship of the code file to be updated;
[0219] At least one code to be migrated is determined according to the first dependency comparison graph and the second dependency comparison graph.
[0220] In a possible implementation, the determination module is specifically configured to:
[0221] Detect at least one common code parent file, common code child files under each common code parent file, and at least one style code text and at least one function code text under each common code child file in the source code file and the code file to be updated respectively according to the code item dependency order;
[0222] And / or, at least one submodule code file in the source code file and the code file to be updated is detected respectively according to the code item dependency order.
[0223] In one possible implementation, the determination module 12 is specifically configured to:
[0224] If it is determined from the first dependency comparison graph that there is a missing code item in the second dependency comparison graph, the missing code item is determined as the first code to be migrated;
[0225] If a code item with an incorrect dependency relationship in the second dependency comparison graph is determined from the first dependency comparison graph, the code item with a correct dependency relationship in the first dependency comparison graph is determined as the second code to be migrated;
[0226] If it is determined from the first dependency comparison graph that a code item in the second dependency comparison graph has inconsistent external library version information, then the code item in the first dependency comparison graph with inconsistent external library version information is determined as the third-generation migration code;
[0227] The determination module 12 is further specifically configured to:
[0228] Determine the dependency relationship of at least one code to be migrated; the first code to be migrated is a first dependency relationship; the second code to be migrated is a second dependency relationship; and the third code to be migrated is a third dependency relationship.
[0229] In one possible implementation, the migration module 13 is specifically configured to:
[0230] If the first code to be migrated exists, migrating the first code to be migrated to the code file to be updated according to the first dependency relationship to obtain a target code file;
[0231] If the second code to be migrated exists, deleting the code item with the wrong dependency in the code file to be updated, and migrating the second code to be migrated to the code file to be updated according to the second dependency to obtain a target code file;
[0232] If there is a third code to be migrated, the code items with inconsistent external library version information in the code file to be updated are deleted, and the third code to be migrated is migrated to the code file to be updated according to the third dependency relationship to obtain a target code file.
[0233] In one possible implementation, the first code to be migrated is any public code file; the public code file includes a public code parent file or a public code child file; the first dependency relationship includes an external dependency relationship and an internal dependency relationship of the public code file;
[0234] The migration module 13 is specifically used for:
[0235] If the first code to be migrated is any public code file, the style code text and function code text under the public code file are migrated to the code file to be updated according to the corresponding internal dependency relationship, and the public code file formed by the migrated style code text and function code text satisfies the external dependency relationship to obtain the target code file.
[0236] In one possible implementation, the configuration and detection module is specifically configured to:
[0237] If there is an operation to migrate the inconsistent version information of the external library, the code item corresponding to the migrated external library version is configured to obtain the configured target code file;
[0238] Detecting at least one code item included in a target detection code file and the dependency relationship between the code items to generate a structure detection result; the target detection code file is a target code file or a configured target code file;
[0239] After the structural detection is completed, the target detection code file is subjected to functional detection to generate functional detection results;
[0240] A migration report is generated based on the structural and functional test results. The migration report includes each migrated code item, its dependencies, and optimization suggestions.
[0241] Figure 6 This is a schematic diagram of the structure of the code migration device provided in the embodiment of this application. Figure 6 The code migration device 20 may include a memory 21 and a processor 22. Exemplarily, the memory 21 and the processor 22 are interconnected via a bus 23.
[0242] The memory 21 is used to store program instructions;
[0243] The processor 22 is configured to execute the program instructions stored in the memory, so as to enable the data acquisition device 20 to execute the method shown in the above method embodiment.
[0244] The code migration device provided in the embodiment of the present application can execute the technical solution shown in the above method embodiment. Its implementation principles and beneficial effects are similar and will not be repeated here.
[0245] An embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the above method.
[0246] The embodiment of the present application may also provide a computer program product, including a computer program, which can implement the above method when executed by a processor.
[0247] All or part of the steps in the above-mentioned method embodiments may be accomplished by hardware associated with program instructions. The aforementioned program may be stored in a readable memory. When executed, the program performs the steps of the above-mentioned method embodiments. The aforementioned memory (storage medium) includes: read-only memory (ROM), random access memory (RAM), flash memory, hard disk, solid-state drive, magnetic tape, floppy disk, optical disc, and any combination thereof.
[0248] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processing unit of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0249] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0250] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 The steps for the function specified in one or more boxes.
[0251] Obviously, those skilled in the art may make various changes and modifications to the embodiments of the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the embodiments of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations.
[0252] In this application, the term "include" and its variations may refer to non-restrictive inclusion; the term "or" and its variations may refer to "and / or". In this application, the terms "first", "second", etc. are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. In this application, "plurality" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and subsequent associated objects are in an "or" relationship.
Claims
1. A code migration method, characterized in that: include: Get the source code files and the code files to be updated; The source code file is an updated code file of the code file to be updated; Determine at least one code to be migrated from the source code file and the code file to be updated, wherein the code to be migrated represents a code item having differences between the code item migrated from the source code file to the code file to be updated; The at least one code to be migrated is migrated to the code file to be updated to obtain a target code file.
2. The method according to claim 1, characterized in that The determining at least one code to be migrated from the source code file and the code file to be updated includes: respectively detecting at least one code item in the source code file and the code file to be updated; Determining the dependency relationship between each code item included in the source code file and the code file to be updated; generating a first dependency comparison graph according to at least one code item and a dependency relationship of the source code file; generating a second dependency comparison graph according to at least one code item and dependency relationship of the code file to be updated; At least one code to be migrated is determined according to the first dependency comparison graph and the second dependency comparison graph.
3. The method according to claim 2, characterized in that The code item includes at least one common code mother file, common code sub-files under each of the common code mother files, style code text and function code text under each of the common code sub-files, and / or sub-module code files; Detecting at least one code item in the source code file and the code file to be updated respectively, including: Detecting at least one common code parent file, common code child files under each common code parent file, and at least one style code text and at least one function code text under each common code child file in the source code file and the code file to be updated respectively according to a code item dependency order; And / or, the source code file and at least one submodule code file in the code file to be updated are detected respectively according to the code item dependency order.
4. The method according to claim 2, characterized in that The code to be migrated includes at least one of a first code to be migrated, a second code to be migrated, and a third code to be migrated; The determining at least one code to be migrated according to the first dependency comparison graph and the second dependency comparison graph includes: If it is determined from the first dependency comparison graph that there is a missing code item in the second dependency comparison graph, then the missing code item is determined as the first code to be migrated; If a code item with an incorrect dependency relationship in the second dependency comparison graph is determined from the first dependency comparison graph, the code item with a correct dependency relationship in the first dependency comparison graph is determined as the second code to be migrated; If it is determined from the first dependency comparison graph that the second dependency comparison graph has a code item with inconsistent external library version information, then the code item with inconsistent external library version information in the first dependency comparison graph is determined as the third-generation migration code; After determining at least one code to be migrated according to the first dependency comparison graph and the second dependency comparison graph, the method further includes: Determine a dependency relationship of at least one code to be migrated; the first code to be migrated is a first dependency relationship; the second code to be migrated is a second dependency relationship; and the third code to be migrated is a third dependency relationship.
5. The method according to claim 4, characterized in that Migrating the at least one code to be migrated into the code file to be updated to obtain a target code file includes: If the first code to be migrated exists, migrating the first code to be migrated to the code file to be updated according to the first dependency relationship to obtain a target code file; If the second code to be migrated exists, deleting the code item with the wrong dependency in the code file to be updated, and migrating the second code to be migrated to the code file to be updated according to the second dependency to obtain a target code file; If the third code to be migrated exists, the code items with inconsistent external library version information in the code file to be updated are deleted, and the third code to be migrated is migrated to the code file to be updated according to the third dependency relationship to obtain the target code file.
6. The method according to claim 5, characterized in that The first code to be migrated is any public code file; the public code file includes a public code parent file or a public code child file; the first dependency relationship includes an external dependency relationship and an internal dependency relationship of the public code file; If the first code to be migrated exists, migrating the first code to be migrated to the code file to be updated according to the first dependency relationship to obtain a target code file includes: If the first code to be migrated is any public code file, the style code text and function code text under the public code file are migrated to the code file to be updated according to the corresponding internal dependency relationship, and the public code file formed by the migrated style code text and function code text satisfies the external dependency relationship to obtain the target code file.
7. The method according to claim 1, characterized in that After migrating the at least one code to be migrated into the code file to be updated to obtain a target code file, the method includes: If there is an operation to migrate the inconsistent version information of the external library, the code item corresponding to the migrated external library version is configured to obtain the configured target code file; Detecting at least one code item included in a target detection code file and the dependency relationship between the code items to generate a structure detection result; the target detection code file is a target code file or a configured target code file; After the structural detection is completed, a functional detection is performed on the target detection code file to generate a functional detection result; A migration report is generated based on the structural detection results and the functional detection results; the migration report includes each migrated code item, the dependency relationship of each migrated code item, and optimization suggestions.
8. A code migration device, characterized in that: include: The acquisition module is used to obtain source code files and code files to be updated; The source code file is an updated code file of the code file to be updated; a determination module, configured to determine at least one code to be migrated from the source code file and the code file to be updated, wherein the code to be migrated represents a code item having differences between the code item migrated from the source code file to the code file to be updated; The migration module is configured to migrate the at least one code to be migrated to the code file to be updated to obtain a target code file.
9. A code migration device, characterized in that: include: Memory, processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the processor performs the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 7 when executed by a processor.
11. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 7 when executed by a processor.