Code processing method and device, electronic equipment and storage medium
By identifying and processing code differences information, and using dual-pointer technology to calculate the merge results, the accuracy and efficiency of code merging in collaborative development of multiple people is solved, and efficient code merging is achieved in low-code scenarios.
Patent Information
- Application Number
- CN202411455593.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-17
- Publication Date
- 2024-12-27
AI Technical Summary
During the process of co-developing code by multiple people, when merging different versions of code, it is difficult for the existing technology to handle code differences and conflicts efficiently and accurately, resulting in inaccurate or inefficient merge results.
By determining the difference information between the initial code and different codes, using key-value pair sets to identify different key values, and combining results are calculated based on these different key values, double-pointer technology is used to accurately determine the code combining results, and process arrays and JSON data modify information to improve merge accuracy.
It realizes efficient merging of multi-branch code in low-code scenarios, improves the efficiency of collaborative development of multiple people and the accuracy of merge results, and can handle modification conflicts in the code and generate appropriate merge results.
Smart Images

Figure CN119201071A_ABST
Abstract
Description
Technical Field
[0001] Disclosed are a code processing method, an apparatus, an electronic device, a storage medium, and a computer program product. Background Art
[0002] In the process of collaborative code development by multiple people, sometimes two codes need to be merged. For example, in the process of product development, different users are responsible for a part of the code development work. After multiple users have completed the development, the different codes can be merged into a new code. For another example, in the process of product iteration, two versions of code need to be merged into a new code. Summary of the invention
[0003] The present disclosure provides a code processing method, device, electronic device, storage medium and computer program product.
[0004] According to one aspect of the present disclosure, a code processing method is provided, including: determining first difference information between an initial code and a first code for a target task, and second difference information between the initial code and the second code; wherein the first code and the second code are obtained based on the initial code, the first difference information includes a first key-value pair set, and the second difference information includes a second key-value pair set; according to the first key-value pair set and the second key-value pair set, determining a first difference key value and a second difference key value; wherein the first key name of the first difference key value in the first key-value pair set is the same as the second key name of the second difference key value in the second key-value pair set; according to the first difference key value and the second difference key value, determining a merge result of the first code and the second code for executing the target task.
[0005] According to another aspect of the present disclosure, a code processing device is provided, including: a difference determination module, a key value determination module and a result determination module. The difference determination module is used to determine the first difference information between the initial code and the first code for the target task, and the second difference information between the initial code and the second code; wherein the first code and the second code are obtained based on the initial code, the first difference information includes a first key value pair set, and the second difference information includes a second key value pair set. The key value determination module is used to determine the first difference key value and the second difference key value according to the first key value pair set and the second key value pair set; wherein the first key name of the first difference key value in the first key value pair set is the same as the second key name of the second difference key value in the second key value pair set. The result determination module is used to determine the merged result of the first code and the second code according to the first difference key value and the second difference key value, for executing the target task.
[0006] According to another aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method provided by the present disclosure.
[0007] According to another aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable a computer to execute the method provided by the present disclosure.
[0008] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the method provided by the present disclosure is implemented.
[0009] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0011] Figure 1 is a schematic diagram of an application scenario of a code processing method and device according to an embodiment of the present disclosure;
[0012] Figure 2 is a schematic flow chart of a code processing method according to an embodiment of the present disclosure;
[0013] Figure 3 is a schematic flow chart of determining difference information between two codes according to an embodiment of the present disclosure;
[0014] Figure 4A is a schematic flow chart of a code processing method according to another embodiment of the present disclosure;
[0015] Figure 4B is a schematic diagram of visualizing the merging result according to an embodiment of the present disclosure;
[0016] Figure 5 is a schematic diagram of determining a merging result based on a double pointer according to an embodiment of the present disclosure;
[0017] Figure 6 is a schematic structural block diagram of a code processing device according to an embodiment of the present disclosure; and
[0018] Figure 7 It is a structural block diagram of an electronic device used to implement the code processing method of an embodiment of the present disclosure. DETAILED DESCRIPTION
[0019] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0020] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0021] In the technical solution of the present disclosure, the user's authorization or consent is obtained before obtaining or collecting the user's personal information.
[0022] Figure 1 It is a schematic diagram of an application scenario of the code processing method and device according to an embodiment of the present disclosure.
[0023] It should be noted that Figure 1 What is shown is merely an example of a system architecture to which the embodiments of the present disclosure can be applied, in order to help those skilled in the art understand the technical content of the present disclosure, but it does not mean that the embodiments of the present disclosure cannot be used in other devices, systems, environments or scenarios.
[0024] like Figure 1 As shown, the system architecture 100 according to this embodiment may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired and / or wireless communication links, etc.
[0025] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Terminal devices 101, 102, 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptops, desktop computers, etc.
[0026] The server 105 may be a server that provides various services, such as a background management server (only an example) that provides support for websites browsed by users using the terminal devices 101, 102, and 103. The background management server may analyze and process the received data such as user requests, and feed back the processing results (such as generating a combined result based on the initial code, the first code, and the second code selected by the user) to the terminal device.
[0027] It should be noted that the code processing method provided in the embodiment of the present disclosure can generally be executed by the server 105. Accordingly, the code processing device provided in the embodiment of the present disclosure can generally be set in the server 105. In some embodiments, the code processing method provided in the embodiment of the present disclosure can generally be executed by the terminal devices 101, 102, and 103. Accordingly, the code processing device provided in the embodiment of the present disclosure can generally be set in the terminal devices 101, 102, and 103.
[0028] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0029] Figure 2 is a schematic flowchart of a code processing method according to an embodiment of the present disclosure.
[0030] like Figure 2 As shown, the code processing method 200 may include operations S210 to S230.
[0031] In operation S210, first difference information between an initial code and a first code for a target task, and second difference information between the initial code and the second code are determined; wherein the first code and the second code are obtained based on the initial code, the first difference information includes a first key-value pair set, and the second difference information includes a second key-value pair set.
[0032] For example, the trunk code can be adjusted to obtain the branch code. For example, one user obtains the trunk code and modifies the trunk code according to actual needs to obtain a branch code; another user obtains the trunk code and modifies the trunk code differently according to actual needs to obtain another branch code. The above trunk code is the initial code, and the above two branch codes are the first code and the second code.
[0033] For example, the initial code and the first code may be compared to determine first difference information between the two, and the first difference information may reflect the change process from the initial code to the first code. The initial code and the second code may be compared to determine second difference information between the two, and the second difference information may reflect the change process from the initial code to the second code.
[0034] It should be noted that the code can record code information in the form of a key-value pair. For example, the key-value pair in the initial code includes an initial key name and an initial key value, and the first code and the second code both include a key-value pair. In addition, the first difference information includes a first key-value pair set, and the first key-value pair set includes a corresponding first key name and a first difference key value. The second difference information includes a second key-value pair set, and the second key-value pair set includes a corresponding second key name and a second difference key value.
[0035] In operation S220, a first difference key value and a second difference key value are determined according to the first key value pair set and the second key value pair set; wherein the first key name of the first difference key value in the first key value pair set is the same as the second key name of the second difference key value in the second key value pair set.
[0036] For example, you can traverse the first key name in the first key-value pair set, and then find the second key name that is the same as the first key name in the second key-value pair set. The key value corresponding to the first key name in the first difference information is the first difference key value, and the key value corresponding to the second key name in the second difference information is the second difference key value.
[0037] For example, the initial code may include multiple lines of code. Take a line of code as an example. The initial code of the line is "style: AAA". The first code modifies the line code to "style: BBB", and the second code modifies the line code to "style: CCC", wherein the initial key name, the first key name, and the second key name are all style, the initial key value in the initial code is AAA, the first key value in the first code is BBB, and the second key value in the second code is CCC. The first difference information can be recorded as style:{op: 'change', new: BBB, old: AAA}, and the second difference information can be recorded as style:{op: 'change', new: CCC, old: AAA}. The first difference key value value1 can be "op: 'change', new: BBB, old: AAA", and the second difference key value value2 can be "op: 'change', new: CCC, old: AAA", wherein op: 'change' can indicate that the modification type is edit.
[0038] In operation S230, a merge result of the first code and the second code is determined according to the first difference key value and the second difference key value, for executing the target task.
[0039] For example, if the first difference key value and the second difference key value are the same, it means that the first code and the second code have not been modified relative to the initial code, or the first code and the second code have been modified relative to the initial code and the modified contents are the same. In this case, only the first difference key value or the second difference key value can be added to the merged result.
[0040] For another example, if the first difference key value and the second difference key value are different, it means that at least one of the first code and the second code has been modified relative to the initial code. At this time, the first difference key value and the second difference key value can be added to the merge result, and the conflict between the two can be recorded.
[0041] It can be understood that the merging result obtained by merging the first code and the second code is a new code, which can be used to execute the target task. This embodiment does not limit the target task.
[0042] According to the technical solution provided by the embodiment of the present disclosure, the first difference information of the first code relative to the initial code and the second difference information of the second code relative to the initial code can be determined first, and then the first difference key value and the second difference key value corresponding to the same key name are found, and then the first difference key value and the second difference key value are used to merge the first code and the second code to obtain a merged result. In this way, two different first codes and second codes modified based on the same initial code can be merged, thereby realizing multi-branch code development with multi-person collaboration in a low-code scenario and achieving more efficient low-code application development and delivery.
[0043] Figure 3 is a schematic flowchart of determining difference information between two codes according to an embodiment of the present disclosure.
[0044] This embodiment describes the process of comparing two codes to obtain difference information. In this embodiment, the two codes to be compared are called code code1 and code code2. It can be understood that if the first difference information needs to be determined, the initial code in the above text can be used as code code1, and the first code in the above text can be used as code code2. If the second difference information needs to be determined, the initial code in the above text can be used as code code1, and the second code in the above text can be used as code code2.
[0045] In this embodiment, the method 310 of comparing two codes to obtain difference information may include operations S311 to S316.
[0046] In operation S311, the key names are traversed based on the code code1, for example, when a key name key1 is traversed, the key value value1 corresponding to the key name key1 can be determined.
[0047] In operation S312, another key name key2 identical to the key name key1 is searched in another code code2, and another key value value2 corresponding to the key name key2 in another code is determined.
[0048] In operation S313, it is determined whether the key value1 and the key value2 are arrays. If they are arrays, the process proceeds to operation S314, otherwise, the process proceeds to operation S315.
[0049] In operation S314, the key value value1 and the key value value2 are compared using the Myers algorithm to obtain difference information.
[0050] In operation S315 , the key value value1 and the key value value2 are compared to obtain difference information.
[0051] In operation S316, the difference information is recorded.
[0052] The above describes the process of comparing two codes to obtain difference information.
[0053] In other embodiments, in the process of actually comparing two codes, the output format after comparison can also be predefined. For example, modification includes adding, deleting, and editing. For adding, the comparison result can be recorded as {__op: 'add', __new: xxx, __old: null}. For deleting, the comparison result can be recorded as {__op: 'remove', __new: null, __old: xxx}. For editing, the comparison result can be recorded as {__op: 'change', __new: xxx, __old: xxx}.
[0054] During the comparison process, the user can specify the comparison granularity, which includes attribute granularity and component granularity. For example, the code to be compared is data in JSON format.
[0055] For example, to compare at the attribute granularity, you can pass in "key", which means to use the attribute in the comparison code as the comparison object, and the comparison result can be marked on the attribute in the code.
[0056] For another example, when comparing at the component granularity, the granularity is passed in "JSON", which means that the entire code snippet in the compared code is used as the comparison object, and the comparison result can be marked on the compared code snippet. In addition, the identifier (id) of the code snippet to be compared can be specified, so that the code snippets with the same identifier in code1 and code2 can be compared. In addition, ignored properties can be specified, so that ignored properties can be not compared during the comparison process.
[0057] It should be noted that the difference between attribute granularity and component granularity is that attribute granularity can represent the comparison of a single key-value pair, while a component is a code snippet, which can include multiple key-value pairs. Component granularity can represent the comparison of multiple key-value pairs in code code1 and multiple key-value pairs in code code2.
[0058] For example, code code1 is {id:1, type:2, style:22}, and code code2 is {id:1, type:2, style:332}. If the granularity is component granularity, the comparison result can be recorded as {id:1, type:2, style:22, __op: 'change', __new: xxx, __old: xxx}. If the granularity is attribute granularity, the comparison result can be recorded as {id:1, type:2, style:{__op: 'change', __new: 322, __old: 22}.
[0059] According to another embodiment of the present disclosure, the first difference key value includes an initial key value in the initial code and a first key value in the first code, and the second difference key value includes the initial key value and the second key value in the second code. The initial key name corresponding to the initial key value, the first key name corresponding to the first key value, and the second key name corresponding to the second key value are the same as each other, and the data types of the initial key value, the first key value, and the second key value are arrays. The above process of determining the merge result of the first code and the second code based on the first difference key value and the second difference key value may include: determining a first merged array based on the initial key value and the first key value. Determine a second merged array based on the initial key value and the second key value. Determine the merged result of the first code and the second code based on the first element in the first merged array and the second element in the second merged array.
[0060] For example, in the initial code, the initial key name is A, and the initial key value is [1, 2, 3, 4]. In the first code, the initial key name is A, and the first key value is [2, 3, 4, 1]. In the second code, the initial key name is A, and the second key value is [2, 1, 3, 4]. Then the first merged array Array1 is [1moveOut, 2, 3, 4, 1moveIn], which includes 5 first elements, where 1moveOut means moving "1" out, and 1moveIn means moving "1" in. The second merged array Array2 is [1moveOut, 2, 1moveIn, 3, 4], which includes 5 second elements. For example, the order of elements 2, 3, and 4 is retained in the merged result, and the position of element 1 moving in is explained.
[0061] In this embodiment, the first merged array and the second merged array are first merged, and the first merged array can reflect the modification of the elements in the array in the initial code by the first code. Similarly, the second merged array can reflect the modification of the elements in the array in the initial code by the second code. Therefore, based on the first merged array and the second merged array, not only the difference of the elements between the first code and the second code can be determined, but also the change process of the elements can be determined, so the accuracy of the merged result can be improved.
[0062] Exemplarily, the elements in the array include element names and element values. For example, the initial key value is [1, 2, 3, 4], which includes 4 elements. The element name of the first element can be recorded as key0, and the element value is 1; the element name of the second element can be recorded as key1, and the element value is 2; the element name of the third element can be recorded as key2, and the element value is 3; the element name of the fourth element can be recorded as key3, and the element value is 4.
[0063] The first element in the first merged array includes the first element name and the first element value. For example, the first merged array Array1 is [1moveOut, 2, 3, 4, 1moveIn], which includes 5 elements, the element name of the first element is key0, the element value is 1moveOut; the element name of the second element is key1, the element value is 2; the element name of the third element is key2, the element value is 3; the element name of the fourth element is key3, the element value is 4; the element name of the fifth element is key0, the element value is 1moveIn.
[0064] The second element in the second merged array includes the second element name and the second element value. For example, the second merged array Array2 is [1moveOut, 2, 1moveIn, 3, 4], which includes 5 elements. The element name of the first element is key0, and the element value is 1moveOut; the element name of the second element is key1, and the element value is 2; the element name of the third element is key0, and the element value is 1moveIn; the element name of the fourth element is key2, and the element value is 3; the element name of the fifth element is key3, and the element value is 4.
[0065] According to another embodiment of the present disclosure, a double pointer may be used to determine the merging result, where the double pointer includes a first pointer and a second pointer, the first pointer points to the first element in the first merged array, and the second pointer points to the second element in the second merged array.
[0066] For example, the above process of determining the merge result of the first code and the second code according to the first element in the first merge array and the second element in the second merge array may include: for the first element pointed to by the first pointer and the second element pointed to by the second pointer, according to the modification information of the first element value, the modification information of the second element value, and whether the first element name and the second element name are the same, determining the merge result. For example, the modification information may include whether the element has been modified, and in the case of modification, the modification type includes adding, deleting, editing and moving. Editing means changing an element from one element value to another element value. Moving may include moving out (for example, the modification type of the element 1moveOut in the above text is moving out) and moving in (for example, the modification type of the element 1moveIn in the above text is moving in). It should be noted that whether the element has been modified here refers to whether the element value of the element in the first code or the second code has changed relative to the initial code. After obtaining the merge result, it can also be determined whether the predetermined termination condition is met. If the predetermined termination condition is not met, at least one of the first pointer and the second pointer can be updated. After updating the first pointer and the second pointer, the above operation of determining the merge result can be re-executed to update the merge result. If the predetermined termination condition is met, the first pointer and the second pointer can no longer be updated. The predetermined termination condition includes, for example: the first pointer has pointed to the last first element in the first merged array, and the second pointer has pointed to the last second element in the second merged array.
[0067] This embodiment determines the merging result through the first element name, the modification information of the first element, the second element name, and the modification information of the second element, so that the elements in the array can be fully compared, thereby improving the accuracy of the merging result.
[0068] It should be noted that since the modification information of the first element value, the modification information of the second element value and whether the first element name and the second element name are the same correspond to multiple situations, the multiple situations and the processing logic for determining the merging results corresponding to each situation are explained below.
[0069] According to another embodiment of the present disclosure, the first case is: the first element name and the second element name are the same, and the first element value and the second element value are both modified. In this case, the process of determining the merge result and updating the pointer may include a first processing logic.
[0070] For example, the first processing logic includes: in response to determining that the modification type of the first element value and the second element value is deletion, adding a null value to the merged result. In response to determining that the modification type of the first element value and the second element value is editing, adding the first element value and the second element value to the merged result and marking that the first element value and the second element value are in conflict. In response to determining that the modification type of the first element value and the second element value is moving, adding the first movement information of the first element and the second movement information of the second element to the merged result. If the modification type of the second element value is other than deletion, editing and moving, the first element value and the second element value can be added to the merged result. The above operations will update the merged result. After updating the merged result, the first element pointed to by the first pointer and the second element pointed to by the second pointer are updated, for example, the first pointer is pointed to the next first element, and the second pointer is pointed to the next second element. Then, the corresponding situation of the new first element and the second element can be re-determined, and the corresponding processing logic is used to update the merged result until the predetermined termination condition is met.
[0071] According to another embodiment of the present disclosure, the second situation is: the first element name is the same as the second element name, and the first element value has been modified, and the second element value has not been modified. In this case, the process of determining the merge result and updating the pointer may include a second processing logic.
[0072] For example, the second processing logic includes: in response to determining that the modification type of the first element value is movement, adding the first movement information of the first element to the merged result. In response to determining that the modification type of the first element value is not movement, adding the original value of the first element value before modification (i.e., the element value in the initial code) to the merged result. The above operations will update the merged result. After updating the merged result, the first element pointed to by the first pointer can be updated, for example, the first pointer is pointed to the next first element, while the second element pointed to by the second pointer remains unchanged. Then the corresponding situation of the new first element and the second element can be re-determined, and the corresponding processing logic is adopted until the predetermined termination condition is met. In this embodiment, when the modification type of the first element is movement, the movement information is recorded. Since only the first element is processed and the second element is not processed at this time, only the first element pointed to by the first pointer is changed, and the second element pointed to by the second pointer is not changed.
[0073] According to another embodiment of the present disclosure, the third situation is: the first element name and the second element name are different, and the first element value has been modified, and the second element value has not been modified. In this case, the process of determining the merge result and updating the pointer may include a second processing logic. The second processing logic can refer to the above, and this embodiment will not be repeated.
[0074] According to another embodiment of the present disclosure, the fourth situation is: the first element name and the second element name are different, and the first element value has been modified, and the second element value has been modified. In this case, the process of determining the merge result and updating the pointer may include a second processing logic. The second processing logic can refer to the above, and this embodiment will not be repeated.
[0075] According to another embodiment of the present disclosure, the fifth situation is: the first element name and the second element name are the same, the first element value is not modified, and the second element value is modified. In this case, the process of determining the merge result and updating the pointer may include a third processing logic.
[0076] For example, the third processing logic includes: in response to determining that the modification type is move, adding the second movement information of the second element to the merged result. In response to determining that the modification type is not move, adding the second element value to the merged result. The above operations will update the merged result. After updating the merged result, the first element pointed to by the first pointer can be kept unchanged, and the second element pointed to by the second pointer can be updated, for example, the second pointer is pointed to the next second element. Then the situation corresponding to the new first element and the second element can be re-determined, and the corresponding processing logic is adopted until the predetermined termination condition is met. In this embodiment, when the modification type of the second element is move, the movement information is recorded. Since only the second element is processed and the first element is not processed at this time, only the second element pointed to by the second pointer is changed, and the first element pointed to by the first pointer is not changed.
[0077] According to another embodiment of the present disclosure, the sixth situation is: the first element name and the second element name are different, the first element value is not modified, and the second element value is modified. In this case, the process of determining the merge result and updating the pointer may include a third processing logic. The third processing logic can refer to the above, and this embodiment will not be repeated.
[0078] According to another embodiment of the present disclosure, the seventh situation is: the first element name and the second element name are the same, and the first element value is not modified, and the second element value is not modified. In this case, the process of determining the merge result and updating the pointer may include a fourth processing logic.
[0079] For example, the fourth processing logic includes: adding the element value of the first element and the second element value to the merged result, the above operation will update the merged result, and after updating the merged result, the first element pointed to by the first pointer and the second element pointed to by the second pointer can be updated. For example, the first pointer is pointed to the next first element, and the second pointer is pointed to the next second element, and then the corresponding situation of the new first element and the second element can be re-determined, and the corresponding processing logic is adopted until the predetermined termination condition is met.
[0080] According to another embodiment of the present disclosure, the eighth situation is: the first element name and the second element name are different, and the first element value is not modified, and the second element value is not modified. In this case, the process of determining the merge result and updating the pointer may include a fourth processing logic. The fourth processing logic can refer to the above, and this embodiment will not be repeated.
[0081] According to another embodiment of the present disclosure, after being processed by the above-mentioned first processing logic, second processing logic, third processing logic or fourth processing logic, a merge result can be obtained. The merge result includes the first movement information of the first element in the first merged array and the second movement information of the second element in the second merged array. Next, it can be determined whether the first movement information and the second movement information are the same. If they are the same, the element value corresponding to the first movement information can be added to the merge result, thereby updating the merged set. If they are different, it can be marked in the merge result that the first movement information and the second movement information are in conflict. It can be seen that this embodiment compares whether the first movement information and the second movement information of the same element are the same, so that it can accurately determine whether there is a conflict between the modifications of the first code and the second code for the element.
[0082] According to another embodiment of the present disclosure, the first movement information includes a corresponding first out-position and a first in-position. For example, the first movement information of an element is recorded as {key0, moveOut: 0, moveIn: 4}, indicating that the element named key0 is moved out from the 0th position and inserted into the 4th position. The second movement information includes a corresponding second out-position and a second in-position. For example, the second movement information of an element is recorded as {key0, moveOut: 0, moveIn: 2}, indicating that the element named key0 is moved out from the 0th position and inserted into the 2nd position. Next, the first target out-position in the first movement information and the second target out-position in the second movement information can be determined. The first target out-position and the second target out-position are the same. The first in-position corresponding to the first target out-position is the first target in-position, and the second in-position corresponding to the second target out-position is the second target in-position. Then, it can be determined whether the first target in-position and the second target in-position are the same. If they are the same, the element value corresponding to the first movement information can be added to the merged set and the first in-position can be recorded, thereby updating the merged set. If they are different, it can be marked that there is a conflict between the first target moving-in position and the second target moving-in position. For example, for the element named key0, the first target moving-out position and the second target moving-out position are both the 0th position, but the first target moving-in position is the 4th position, and the second target moving-in position is the 2nd position. The first target moving-in position and the second target moving-in position are different, so there is a conflict in the recorded moving-in position. It can be seen that this embodiment compares whether the first target moving-in position and the second target moving-in position of the same element are the same, so that it can accurately determine whether there is a conflict between the modification of the first code and the second code for the element.
[0083] Figure 4A is a schematic flowchart of a code processing method according to another embodiment of the present disclosure.
[0084] In this embodiment, taking the code as JSON data as an example, the code includes an initial code JSON_0, a first code JSON_1 and a second code JSON_2, and the code processing method 400 includes the following operations.
[0085] In operation S410, the two codes are compared to obtain difference information. For example, the initial code JSON_0 is compared with the first code JSON_1 to obtain first difference information Diff_1, and the initial code JSON_0 is compared with the second code JSON_2 to obtain second difference information Diff_2. The method of comparing the two codes can be referred to above, and will not be repeated in this embodiment.
[0086] In operation S421, the first key name is traversed based on the first difference information Diff_1 to obtain a first difference key value.
[0087] In operation S422, a second key name identical to the first key name is determined in the second difference information Diff_2, and then a second difference key value corresponding to the second key name is determined.
[0088] In operation S431, it is determined whether the data types of the first difference key value and the second difference key value are arrays. If not, operation S432 may be performed; if so, operation S433 may be performed.
[0089] In operation S432, the first difference key value is compared with the second difference key value, and conflict information is recorded.
[0090] For example, if the first key value and the second key value are the same, it means that neither the first code nor the second code has modified the compared key value, or the modification results are the same, so one of the first key value and the second key value can be added to the merge result.
[0091] For another example, if the first key value and the second key value are different, it means that both the first code and the second code modify the key value relative to the initial code, and the modification results are different. At this time, the first key value and the second key value can be added to the merged result, and the conflict between the first key value and the second key value can be recorded.
[0092] In operation S433, a merge result is determined based on the dual pointers.
[0093] For example, the merging result includes the first shift information of the first element in the first merged array and the second shift information of the second element in the second merged array. Next, it can be determined whether the first shift information and the second shift information are the same. If they are the same, operation S442 can be performed. If they are different, operation S443 can be performed.
[0094] In operation S442, the data is restored and the merge result is updated. For example, the element value corresponding to the first movement information is added to the merged set, thereby updating the merged result.
[0095] In operation S443, it is marked in the merged result that the first movement information and the second movement information are in conflict, so as to update the merged result.
[0096] Figure 4B is a schematic diagram of visualizing the merging result according to an embodiment of the present disclosure.
[0097] like Figure 4BAs shown, after obtaining the merge result, the merge result of the first code and the second code can be displayed to the user through the front-end page. For example, when there is a conflict between the first code and the second code in the modification of the same sub-code, the user can choose to merge according to the modification method of the first code, or choose to merge according to the modification method of the second code according to actual needs. When the comparison granularity is the attribute granularity, the sub-code can be an attribute, and an attribute can include a key-value pair. When the comparison granularity is the component granularity, the sub-code can be a code snippet, and a code snippet can include multiple key-value pairs.
[0098] Figure 5 It is a schematic diagram of determining a merging result based on double pointers according to an embodiment of the present disclosure.
[0099] In this embodiment, the method 533 for determining the merging result based on the double pointers may include the following operations.
[0100] In this embodiment, the double pointer includes a first pointer i and a second pointer j. The first pointer i points to the first element in the first merged array, and the second pointer j points to the second element in the second merged array. Each element includes an element name and an element value. The element name of the first element can be called the first element name, and the element value of the first element can be called the first element value. Similarly, the element name of the second element can be called the second element name, and the element value of the second element can be called the second element value.
[0101] For the first element pointed to by the first pointer i and the second element pointed to by the second pointer j, it can be determined whether the element name of the first element and the element name of the second element are the same. In the case where the element name of the first element and the element name of the second element are the same, it can be determined whether the element value of the first element and the element value of the second element are both modified.
[0102] If the element name of the first element is the same as the element name of the second element, and the element value of the first element and the element value of the second element are both modified, the first processing logic can be used. In the process of executing the first processing logic, it can be determined in turn whether the modification type is deletion, editing, or moving. If the modification type is deletion, a null value is added to the merged result. If the modification type is editing, the first element value and the second element value can be added to the merged result and the first element value and the second element value are marked as conflicting. If the modification type is moving, the first movement information of the first element and the second movement information of the second element are added to the merged result. If the modification type is other types other than deletion, editing, and moving, the first element value and the second element value can be added to the merged result. In addition, the first pointer i is pointed to the next first element, and the second pointer j is pointed to the next second element.
[0103] It is possible to determine whether the element value of the first element has been modified when the element name of the first element is different from the element name of the second element. It is also possible to determine whether the element value of the first element has been modified when the element name of the first element is the same as the element name of the second element, and the element value of the first element and the element value of the second element are not modified at the same time. If the element value of the first element has been modified, the second processing logic can be executed. In the process of executing the second processing logic, it can be determined whether the modification type of the first element is move, and if so, the move information is recorded, and the original value of the first element value before the modification is added to the merged result. If not, there is no need to record the move information, and the original value of the first element value before the modification is directly added to the merged result.
[0104] Next, if the element value of the first element is not modified, it can be determined whether the element value of the second element is modified. If it is modified, the third processing logic can be executed. In the process of executing the third processing logic, it can be determined whether the modification type of the second element is movement. If so, the movement information is recorded and the element value of the second element value is added to the merged result. If not, there is no need to record the movement information, and the element value of the second element value is directly added to the merged result.
[0105] If the element value of the first element and the element value of the second element are not modified, the fourth processing logic may be used. During the execution of the fourth processing logic, the element value of the first element and the second element value may be added to the merged result, and the first pointer i may point to the next first element, and the second pointer j may point to the next second element.
[0106] The above describes the process of determining the merging result based on the double pointers. It should be noted that the processing flow in this embodiment is only an example, and in other embodiments, the execution order of each judgment operation can be adjusted according to requirements.
[0107] Figure 6 It is a schematic structural block diagram of a code processing device according to an embodiment of the present disclosure.
[0108] like Figure 6 As shown, the code processing device 600 may include: a difference determination module 610 , a key value determination module 620 and a result determination module 630 .
[0109] The difference determination module 610 is used to determine first difference information between the initial code and the first code for the target task, and second difference information between the initial code and the second code; wherein the first code and the second code are obtained based on the initial code, the first difference information includes a first key-value pair set, and the second difference information includes a second key-value pair set.
[0110] The key value determination module 620 is used to determine the first difference key value and the second difference key value according to the first key value pair set and the second key value pair set; wherein the first key name of the first difference key value in the first key value pair set is the same as the second key name of the second difference key value in the second key value pair set.
[0111] The result determination module 630 is used to determine a merging result of the first code and the second code according to the first difference key value and the second difference key value, so as to execute the target task.
[0112] According to another embodiment of the present disclosure, the first difference key value includes the initial key value in the initial code and the first key value in the first code, and the second difference key value includes the initial key value and the second key value in the second code; when the data types of the initial key value, the first key value and the second key value are arrays, the result determination module includes: a first determination submodule, a second determination submodule and a third determination submodule. The first determination submodule is used to determine the first merged array according to the initial key value and the first key value. The second determination submodule is used to determine the second merged array according to the initial key value and the second key value. The third determination submodule is used to determine the merged result of the first code and the second code according to the first element in the first merged array and the second element in the second merged array.
[0113] According to another embodiment of the present disclosure, the first element in the first merged array includes a first element name and a first element value, and the second element in the second merged array includes a second element name and a second element value; the third determination submodule includes: a processing unit, for determining a merge result and updating at least one of the first pointer and the second pointer for the first element pointed to by the first pointer and the second element pointed to by the second pointer according to modification information of the first element value, modification information of the second element value, and whether the first element name and the second element name are the same.
[0114] According to another embodiment of the present disclosure, a processing unit includes: a first execution subunit, for performing the following operations when a first element name and a second element name are the same and both the first element value and the second element value have been modified: in response to determining that the modification type of the second element value is deletion, adding a null value to the merged result; in response to determining that the modification type of the second element value is editing, adding the first element value and the second element value to the merged result and marking that there is a conflict between the first element value and the second element value; in response to determining that the modification type of the second element value is move, adding first movement information of the first element and second movement information of the second element to the merged result; updating the first element pointed to by the first pointer and the second element pointed to by the second pointer.
[0115] According to another embodiment of the present disclosure, the processing unit includes: a second execution subunit, which is used to perform the following operations when it is determined that the first element name and the second element name are the same, the first element value has been modified, and the second element value has not been modified; or when it is determined that the first element name and the second element name are different, and the first element value has been modified: in response to determining that the modification type of the first element value is move, add the first movement information of the first element to the merge result; in response to determining that the modification type of the first element value is not move, add the original value of the first element value before modification to the merge result; update the first element pointed to by the first pointer, and keep the second element pointed to by the second pointer unchanged.
[0116] According to another embodiment of the present disclosure, the processing unit includes: a third execution subunit, for performing the following operations when it is determined that the value of the first element has not been modified and the value of the second element has been modified: in response to determining that the modification type is move, adding the second move information of the second element to the merge result; in response to determining that the modification type is not move, adding the second element value to the merge result; keeping the first element pointed to by the first pointer unchanged, and updating the second element pointed to by the second pointer.
[0117] According to another embodiment of the present disclosure, the processing unit includes: a first execution subunit, used to add the element value and the second element value of the first element to the merge result when it is determined that the first element value has not been modified and the second element value has not been modified; and update the first element pointed to by the first pointer and the second element pointed to by the second pointer.
[0118] According to another embodiment of the present disclosure, the merging result includes first movement information of the first element in the first merging array and second movement information of the second element in the second merging array; the device also includes: a marking module for marking in the merging result that there is a conflict between the first movement information and the second movement information in response to determining that the first movement information and the second movement information are different.
[0119] According to another embodiment of the present disclosure, the first movement information includes a first moving-out position and a first moving-in position, and the second movement information includes a second moving-out position and a second moving-in position; the marking module includes: a position determination submodule and a marking submodule. The position determination submodule is used to determine the first target moving-out position in the first movement information and the second target moving-out position in the second movement information, and the first target moving-out position and the second target moving-out position are the same. The marking submodule is used to mark the conflict between the first target moving-in position and the second target moving-in position in response to determining that the first target moving-in position and the second target moving-in position are different. The first target moving-in position is a first moving-in position corresponding to the first target moving-out position, and the second target moving-in position is a second moving-in position corresponding to the second target moving-out position.
[0120] According to another embodiment of the present disclosure, the first difference key value includes an initial key value in the initial code and a first key value in the first code, and the second difference key value includes the initial key value and the second key value in the second code; when the data types of the initial key value, the first key value and the second key value are not arrays, the device further includes: an adding module and a marking module. The adding module is used to add one of the first key value and the second key value to the merge result in response to determining that the first key value and the second key value are the same. The marking module is used to add the first key value and the second key value to the merge result in response to determining that the first key value and the second key value are different, and mark that there is a conflict between the first key value and the second key value.
[0121] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, comprising at least one processor; and a memory communicatively connected to the at least one processor; the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the above-mentioned code processing method.
[0122] According to an embodiment of the present disclosure, the present disclosure further provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the above-mentioned code processing method.
[0123] According to an embodiment of the present disclosure, the present disclosure further provides a computer program product, including a computer program, and the computer program implements the above code processing method when executed by a processor.
[0124] Figure 7 It is a block diagram of an electronic device for implementing the code processing method of an embodiment of the present disclosure. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0125] like Figure 7As shown, the device 700 includes a computing unit 701, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 702 or a computer program loaded from a storage unit 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the device 700 can also be stored. The computing unit 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0126] A number of components in the device 700 are connected to the I / O interface 705, including: an input unit 706, such as a keyboard, a mouse, etc.; an output unit 707, such as various types of displays, speakers, etc.; a storage unit 708, such as a disk, an optical disk, etc.; and a communication unit 709, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 709 allows the device 700 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0127] The computing unit 701 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 701 performs the various methods and processes described above, such as code processing methods. For example, in some embodiments, the code processing method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 700 via the ROM 702 and / or the communication unit 709. When the computer program is loaded into the RAM 703 and executed by the computing unit 701, one or more steps of the code processing method described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to execute the code processing method in any other appropriate manner (e.g., by means of firmware).
[0128] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0129] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0130] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0131] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0132] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0133] A computer system may include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other.
[0134] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0135] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A code processing method, comprising: Determine first difference information between an initial code and a first code for a target task, and second difference information between the initial code and the second code; wherein the first code and the second code are obtained based on the initial code, the first difference information includes a first key-value pair set, and the second difference information includes a second key-value pair set; Determine a first difference key value and a second difference key value according to the first key-value pair set and the second key-value pair set; wherein a first key name of the first difference key value in the first key-value pair set is the same as a second key name of the second difference key value in the second key-value pair set; A merging result of the first code and the second code is determined according to the first difference key value and the second difference key value, and is used to execute the target task.
2. The method according to claim 1, wherein: The first difference key value includes an initial key value in the initial code and a first key value in the first code, and the second difference key value includes the initial key value and a second key value in the second code; when the data types of the initial key value, the first key value, and the second key value are arrays, determining the merge result of the first code and the second code according to the first difference key value and the second difference key value includes: Determine a first merged array according to the initial key value and the first key value; Determine a second merged array according to the initial key value and the second key value; The merging result of the first code and the second code is determined according to the first element in the first merging array and the second element in the second merging array.
3. The method according to claim 2, wherein: The first element in the first merged array includes a first element name and a first element value, and the second element in the second merged array includes a second element name and a second element value; Determining the merging result of the first code and the second code according to the first element in the first merging array and the second element in the second merging array includes: For the first element pointed to by the first pointer and the second element pointed to by the second pointer, the merging result is determined according to the modification information of the first element value, the modification information of the second element value and whether the first element name and the second element name are the same, and at least one of the first pointer and the second pointer is updated.
4. The method according to claim 3, wherein: The determining the merging result according to the modification information of the first element value, the modification information of the second element value, and whether the first element name and the second element name are the same, and updating at least one of the first pointer and the second pointer comprises: When the first element name and the second element name are the same, and the first element value and the second element value have been modified, perform the following operations: In response to determining that the modification type of the second element value is deletion, adding a null value to the merge result; In response to determining that the modification type of the second element value is edit, adding the first element value and the second element value to the merge result and marking that the first element value and the second element value are in conflict; In response to determining that the modification type of the second element value is movement, adding first movement information of the first element and second movement information of the second element to the merged result; Update the first element pointed to by the first pointer and the second element pointed to by the second pointer.
5. The method according to claim 3, wherein: The determining the merging result according to the modification information of the first element value, the modification information of the second element value, and whether the first element name and the second element name are the same, and updating at least one of the first pointer and the second pointer comprises: When it is determined that the first element name and the second element name are the same, and the first element value has been modified, and the second element value has not been modified; or when it is determined that the first element name and the second element name are different, and the first element value has been modified, perform the following operations: In response to determining that the modification type of the first element value is movement, adding first movement information of the first element to the merge result; In response to determining that the modification type of the first element value is not a move, adding the original value of the first element value before modification to the merge result; The first element pointed to by the first pointer is updated, and the second element pointed to by the second pointer is kept unchanged.
6. The method according to claim 3, wherein: The determining the merging result according to the modification information of the first element value, the modification information of the second element value, and whether the first element name and the second element name are the same, and updating at least one of the first pointer and the second pointer comprises: When it is determined that the value of the first element has not been modified and the value of the second element has been modified, the following operations are performed: In response to determining that the modification type is movement, adding second movement information of the second element to the merged result; In response to determining that the modification type is not a move, adding the second element value to the merge result; The first element pointed to by the first pointer is kept unchanged, and the second element pointed to by the second pointer is updated.
7. The method according to claim 3, wherein: The determining the merging result according to the modification information of the first element value, the modification information of the second element value, and whether the first element name and the second element name are the same, and updating at least one of the first pointer and the second pointer comprises: In a case where it is determined that the first element value is not modified and the second element value is not modified, adding the element value of the first element and the second element value to the merged result; Update the first element pointed to by the first pointer and the second element pointed to by the second pointer.
8. The method according to any one of claims 3 to 7, wherein: The merging result includes first movement information of the first element in the first merging array and second movement information of the second element in the second merging array; The method further comprises: In response to determining that the first movement information and the second movement information are different, a conflict is marked in the merge result between the first movement information and the second movement information.
9. The method according to claim 8, wherein: The first movement information includes a first moving-out position and a first moving-in position, and the second movement information includes a second moving-out position and a second moving-in position; In response to determining that the first movement information and the second movement information are different, marking in the merge result that there is a conflict between the first movement information and the second movement information includes: Determine a first target moving-out position in the first movement information and a second target moving-out position in the second movement information, wherein the first target moving-out position and the second target moving-out position are the same; In response to determining that the first target moving-in position and the second target moving-in position are different, marking that the first target moving-in position and the second target moving-in position are in conflict; The first target moving-in position is a first moving-in position corresponding to the first target moving-out position, and the second target moving-in position is a second moving-in position corresponding to the second target moving-out position.
10. The method according to claim 1, wherein: The first difference key value includes an initial key value in the initial code and a first key value in the first code, and the second difference key value includes the initial key value and a second key value in the second code; In the case where the data types of the initial key value, the first key value, and the second key value are not arrays, the method further includes: In response to determining that the first key value and the second key value are the same, adding one of the first key value and the second key value to a merge result; In response to determining that the first key value and the second key value are different, the first key value and the second key value are added to the merge result, and a conflict between the first key value and the second key value is recorded.
11. A code processing device, comprising: a difference determination module, configured to determine first difference information between an initial code and a first code for a target task, and second difference information between the initial code and the second code; wherein the first code and the second code are obtained based on the initial code, the first difference information includes a first key-value pair set, and the second difference information includes a second key-value pair set; a key value determination module, configured to determine a first difference key value and a second difference key value according to the first key value pair set and the second key value pair set; wherein the first key name of the first difference key value in the first key value pair set is the same as the second key name of the second difference key value in the second key value pair set; A result determination module is used to determine a merging result of the first code and the second code according to the first difference key value and the second difference key value, so as to execute the target task.
12. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 10.
13. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 10.
14. A computer program product comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 10.