CN106406918B - Automatic source code merging method and automatic source code merging device - Google Patents

Automatic source code merging method and automatic source code merging device Download PDF

Info

Publication number
CN106406918B
CN106406918B CN201611055852.6A CN201611055852A CN106406918B CN 106406918 B CN106406918 B CN 106406918B CN 201611055852 A CN201611055852 A CN 201611055852A CN 106406918 B CN106406918 B CN 106406918B
Authority
CN
China
Prior art keywords
suspected
code
incompatible
code block
point
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201611055852.6A
Other languages
Chinese (zh)
Other versions
CN106406918A (en
Inventor
刘伟
贾桂芬
米建军
殷志梅
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
BEIJING VSETTAN DATA TECHNOLOGY CO.,LTD.
Original Assignee
Huasheng Xintai Information Industry Development Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huasheng Xintai Information Industry Development Co Ltd filed Critical Huasheng Xintai Information Industry Development Co Ltd
Priority to CN201611055852.6A priority Critical patent/CN106406918B/en
Publication of CN106406918A publication Critical patent/CN106406918A/en
Application granted granted Critical
Publication of CN106406918B publication Critical patent/CN106406918B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/72Code refactoring

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention provides a source code automatic merging method and a source code automatic merging device, wherein the source code automatic merging method comprises the following steps: finding suspected incompatible points in source codes of two different versions; judging whether suspected incompatible points in the two source codes are code blocks with substantial conflict or not according to a preset compatibility condition; if the suspected incompatible points in the two source codes are code blocks with conflict substantially, selecting a code branch according to the compatibility condition so as to use the code blocks in the selected code branch for merging; and if the suspected incompatible points in the two source codes are code blocks without collision, selecting any code block in the suspected incompatible points for combination. By the technical scheme of the invention, under the condition of not depending on a merging tool to merge the source codes, the problem of code incompatibility during source code merging is solved, and the merging efficiency of the source codes is improved.

Description

Automatic source code merging method and automatic source code merging device
Technical Field
The invention relates to the technical field of source code merging, in particular to a source code automatic merging method and a source code automatic merging device.
Background
Software program development is generally team collaboration, and the implementation of the same function often involves many different versions of source code files, e.g., two developers developing the same module. Thus, when different versions of source code are merged together, there may be some places where inconsistencies, i.e., conflicts, exist. The current source code merging scheme mainly comprises the steps of determining a source code to be merged through a merging tool, recording a conflict position and modification time in the source code merging process, and merging a code block which is modified most recently into the source code to be merged according to conflict position information. If the same source code is modified by different developers and the same code block is modified, namely the problem of code incompatibility occurs during source code merging, the source code merging work at the moment depends on manual intervention to a great extent, and the source code merging efficiency is reduced.
Therefore, how to solve the problem of code incompatibility during source code merging and avoid manual intervention, so that the improvement of the merging efficiency of the source codes becomes a technical problem to be solved urgently.
Disclosure of Invention
The present invention is directed to solving at least one of the problems of the prior art or the related art.
To this end, an object of the present invention is to provide an automatic source code merging method.
Another objective of the present invention is to provide an apparatus for automatically merging source codes.
To achieve at least one of the above objects, according to an embodiment of the first aspect of the present invention, there is provided a source code automatic merging method, including: finding suspected incompatible points in source codes of two different versions; judging whether the suspected incompatible points in the two source codes are code blocks with substantial conflict or not according to a preset compatibility condition; if the suspected incompatible points in the two source codes are code blocks with conflict substantially, selecting a code branch according to the compatibility condition so as to use the selected code blocks in the code branch for merging; and if the suspected incompatible points in the two source codes are code blocks without conflict substantially, selecting any one of the suspected incompatible points for merging.
In the foregoing technical solution, preferably, the step of finding suspected incompatible points in two different versions of source code includes: comparing the code content of corresponding lines between the source codes of two different versions; and if the code content of the corresponding line is different, taking the code content of the corresponding line as the suspected incompatible point.
In any of the above technical solutions, preferably, the compatibility condition includes one or more combinations of a keyword, a merge mode, a code modification time, and a value of an expression.
In any one of the above technical solutions, preferably, when the compatibility condition includes a keyword, the step of determining whether the suspected incompatible point in the two source codes is a code block with a substantial conflict includes: if the suspected incompatible point meets the keyword query condition, determining that the suspected incompatible point is a code block with substantial conflict; if the suspected incompatible point does not satisfy the keyword query condition, determining that the suspected incompatible point is not a code block with substantial conflict, wherein the keyword query condition includes: finding a first type keyword in one code block in the suspected incompatible point, and finding a second type keyword in another code block in the suspected incompatible point; or the first type key word is found in one code block in the suspected incompatible point, and the second type key word is not found in the other code block in the suspected incompatible point; or the second type key word is found in one code block in the suspected incompatible point, and the first type key word is not found in the other code block in the suspected incompatible point.
In any one of the above technical solutions, preferably, when the compatibility condition includes a merge mode, the step of determining whether the suspected incompatibility point in the two source codes is a code block with a substantial conflict includes: judging whether the suspected incompatible point has only one variable of a code block for display initialization; if the suspected incompatible point is judged to have only one code block variable for display initialization, the suspected incompatible point is judged to be a code block with collision substantially; if the suspected incompatible point is judged to be not the variable with only one code block for display initialization, judging whether the suspected incompatible point has only one key statement of the code block and then checking a return value; if the suspected incompatible point is judged to have a return value check after the key statement of only one code block, the suspected incompatible point is judged to be a code block with a substantial conflict, and if the suspected incompatible point is judged to have a return value check after the key statement of only one code block is not judged to have the collision, the suspected incompatible point is judged to be not a code block with a substantial conflict.
In any of the above technical solutions, preferably, the method for automatically merging source codes further includes: detecting whether the compatibility condition is correct; and if the compatibility condition is detected to be incorrect, prompting the user that the compatibility condition is incorrect and/or prompting the user to reset the compatibility condition.
According to an embodiment of the second aspect of the present invention, there is provided a source code automatic merging apparatus, including: the searching unit is used for searching suspected incompatible points in the source codes of the two different versions; a judging unit, configured to judge, according to a preset compatibility condition, whether the suspected incompatible point in the two source codes is a code block with a substantial conflict; a merging unit, configured to select a code branch according to the compatibility condition if the determining unit determines that the suspected incompatible point in the two source codes is a code block with a substantial conflict, so as to merge the code blocks in the selected code branch; and the merging unit is further configured to select any one of the suspected incompatible points for merging if the determining unit determines that the suspected incompatible points in the two source codes are code blocks with substantially no conflict.
In the above technical solution, preferably, the search unit includes: the comparison subunit is used for comparing the code content of the corresponding line between the source codes of the two different versions; and the determining subunit is configured to, if the code content of the corresponding line compared by the comparing subunit is different, take the code content of the corresponding line as the suspected incompatible point.
In any of the above technical solutions, preferably, the compatibility condition includes one or more combinations of a keyword, a merge mode, a code modification time, and a value of an expression.
In any one of the foregoing technical solutions, preferably, in a case that the compatibility condition includes a keyword, the determining unit is specifically configured to determine that the suspected incompatible point is a code block with a substantial conflict if the suspected incompatible point satisfies a keyword query condition; if the suspected incompatible point does not satisfy the keyword query condition, determining that the suspected incompatible point is not a code block with substantial conflict, wherein the keyword query condition includes: finding a first type keyword in one code block in the suspected incompatible point, and finding a second type keyword in another code block in the suspected incompatible point; or the first type key word is found in one code block in the suspected incompatible point, and the second type key word is not found in the other code block in the suspected incompatible point; or the second type key word is found in one code block in the suspected incompatible point, and the first type key word is not found in the other code block in the suspected incompatible point.
In any one of the foregoing technical solutions, preferably, when the compatibility condition includes a merge mode, the determining unit is specifically configured to determine whether only one variable of a code block is present in the suspected incompatible point for initialization; if the suspected incompatible point is judged to have only one code block variable for display initialization, the suspected incompatible point is judged to be a code block with collision substantially; if the suspected incompatible point is judged to be not the variable with only one code block for display initialization, judging whether the suspected incompatible point has only one key statement of the code block and then checking a return value; if the suspected incompatible point is judged to have a return value check after the key statement of only one code block, the suspected incompatible point is judged to be a code block with a substantial conflict, and if the suspected incompatible point is judged to have a return value check after the key statement of only one code block is not judged to have the collision, the suspected incompatible point is judged to be not a code block with a substantial conflict.
In any one of the above technical solutions, preferably, the source code automatic merging apparatus further includes: the detection unit is used for detecting whether the compatibility condition is correct or not; and the prompting unit is used for prompting the user that the compatibility condition is incorrect and/or prompting the user to reset the compatibility condition if the detection unit detects that the compatibility condition is incorrect.
By the technical scheme of the invention, under the condition of not depending on a merging tool to merge the source codes, the problem of code incompatibility during source code merging is solved, and meanwhile, the merging work of the source codes is avoided being interfered manually, so that the merging efficiency of the source codes is improved.
Drawings
FIG. 1 shows a flow diagram of a method for automatic source code merging according to one embodiment of the invention;
FIG. 2 is a flow diagram illustrating a process for determining whether a suspected incompatible point is a substantially conflicting code block based on a key according to one embodiment of the present invention;
FIG. 3 is a flowchart illustrating a method for determining whether a suspected incompatible point is a code block with a substantial conflict according to a merge condition according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of an automatic source code merging apparatus according to an embodiment of the present invention.
Detailed Description
So that the manner in which the above recited objects, features and advantages of the present invention can be understood in detail, a more particular description of the invention, briefly summarized above, may be had by reference to the embodiments thereof which are illustrated in the appended drawings. It should be noted that the embodiments and features of the embodiments of the present application may be combined with each other without conflict.
In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present invention, however, the present invention may be practiced in other ways than those specifically described herein, and therefore the scope of the present invention is not limited by the specific embodiments disclosed below.
Fig. 1 shows a flow diagram of a source code automatic merging method according to an embodiment of the present invention.
As shown in fig. 1, the method for automatically merging source codes according to an embodiment of the present invention includes:
at step 102, suspected incompatibility points in two different versions of source code are found.
Preferably, step 102 comprises: comparing the code content of corresponding lines between the source codes of two different versions; and if the code content of the corresponding line is different, taking the code content of the corresponding line as the suspected incompatible point.
If the code content of the corresponding line between the two source codes is the same, it is indicated that the code content of the corresponding line is a compatible point, and if the code content of the corresponding line between the two source codes is different, it is indicated that the code content of the corresponding line may be an incompatible point, i.e. a suspected incompatible point.
The suspected incompatible point is a plurality of lines of codes, for example, developers a and B submit a source code named test.c, the source code submitted by a has 80 lines, the source code submitted by B has 100 lines, if the code content of the first 30 lines of the source code submitted by a and the code content of the first 30 lines of the source code submitted by B are the same, the code content of the lines 31 to 50 in the source code submitted by a and the code content of the lines 31 to 70 in the source code submitted by B are different, the code content of the lines 51 to 80 in the source code submitted by a and the code content of the lines 71 to 100 in the source code submitted by B are the same, and the codes of the lines 31 to 50 in the source code submitted by a and the codes of the lines 31 to 70 in the source code submitted by B are regarded as a suspected incompatible point.
The following further describes the suspected incompatibility point by two examples.
For example, a is 5 in the source code developed by the developer a, and a is 4+1 in the corresponding line in the source code developed by the developer B, and it can be seen that the code contents of "a is 5" and "a is 4+ 1" are different, that is, "a is 5" and "a is 4+ 1" are suspected incompatible points.
For another example, the source code developed by the developer a has a value of 5, the source code developed by the developer B has a value of B equal to 5, and the code content of "a equal to 5" and "B equal to 5" are different, that is, "a equal to 5" and "B equal to 5" are suspected incompatible points.
Step 104, according to a preset compatibility condition, determining whether the suspected incompatible point in the two source codes is a code block with substantial conflict, if it is determined that the suspected incompatible point in the two source codes is a code block with substantial conflict, executing step 106, and if it is determined that the suspected incompatible point in the two source codes is a code block without substantial conflict, executing step 108.
Preferably, the compatibility condition includes one or more combinations of keywords, merge patterns, code modification time, and values of expressions.
By the compatibility condition, whether the suspected incompatible point is a code block with substantial conflict or not can be accurately judged.
In one embodiment, in the case that the compatibility condition includes a keyword, step 104 includes: if the suspected incompatible point meets the keyword query condition, determining that the suspected incompatible point is a code block with substantial conflict; if the suspected incompatible point does not satisfy the keyword query condition, determining that the suspected incompatible point is not a code block with substantial conflict, wherein the keyword query condition includes: finding a first type keyword in one code block in the suspected incompatible point, and finding a second type keyword in another code block in the suspected incompatible point; or the first type key word is found in one code block in the suspected incompatible point, and the second type key word is not found in the other code block in the suspected incompatible point; or the second type key word is found in one code block in the suspected incompatible point, and the first type key word is not found in the other code block in the suspected incompatible point.
The first type keywords and the second type keywords are preset keywords, for example, the first type keywords are expected keywords, and the second type keywords are undesired keywords. How to determine whether the suspected incompatible point is a code block with substantial conflict according to the keyword is further described below with reference to fig. 2. The method specifically comprises the following steps:
step 202, setting compatibility conditions as keywords, wherein the keywords comprise expected keywords and unexpected keywords. The desired keyword and the undesired keyword may be one or more keywords. For example, the desired keyword may be set to "ToprowMQ" and the undesired keyword may be set to "WebSphereMQ".
And step 204, comparing the two code blocks of the suspected incompatible point.
Step 206, judging whether the expected keyword is found in one code block of the two code blocks suspected to be incompatible points, and finding the unexpected keyword in the other code block, if so, executing step 208, and if not, executing step 210.
In step 208, the suspected incompatible point is determined to be a code block with substantial conflict.
Step 210, determining whether the expected keyword is found in one of the two code blocks of the suspected incompatible point, and the unexpected keyword is not found in the other code block, if yes, executing step 208, and if no, executing step 212.
In step 212, it is determined whether an unexpected keyword is found in one of the two code blocks of the suspected incompatible point, and the other code block does not find the expected keyword, if the determination result is yes, step 208 is executed, and if the determination result is no, step 214 is executed.
In step 214, the suspected incompatible point is determined as a code block where there is substantially no collision
And step 216, determining whether all the suspected incompatible points are determined, if yes, ending the process, and if no, re-executing step 204 to perform the above-mentioned steps on the next suspected incompatible point.
In one embodiment, in the case that the compatibility condition includes a merge mode, step 104 includes: judging whether the suspected incompatible point has only one variable of a code block for display initialization; if the suspected incompatible point is judged to have only one code block variable for display initialization, the suspected incompatible point is judged to be a code block with collision substantially; if the suspected incompatible point is judged to be not the variable with only one code block for display initialization, judging whether the suspected incompatible point has only one key statement of the code block and then checking a return value; if the suspected incompatible point is judged to have a return value check after the key statement of only one code block, the suspected incompatible point is judged to be a code block with a substantial conflict, and if the suspected incompatible point is judged to have a return value check after the key statement of only one code block is not judged to have the collision, the suspected incompatible point is judged to be not a code block with a substantial conflict.
How to determine whether the suspected incompatible point is a code block with substantial conflict according to the merge mode is further described below with reference to fig. 3. The method specifically comprises the following steps:
step 302, set the compatibility condition as a merge mode.
Step 304, comparing the two code blocks of the suspected incompatible point.
Step 306, judging that only one variable of the two code blocks of the suspected incompatible point is displayed and initialized, if the judgment result is yes, the step 308 is carried out, and if the judgment result is no, the step 310 is carried out.
In step 308, the suspected incompatible point is determined to be a code block with substantial conflict.
In step 310, a return value check is performed after the key statement of only one code block in the two code blocks of the suspected incompatible point is judged, if the judgment result is yes, the step 308 is performed, and if the judgment result is no, the step 312 is performed.
At step 312, the suspected incompatible point is determined to be a code block where there is substantially no collision.
And step 314, determining whether all the suspected incompatible points are determined, if yes, ending the process, and if no, re-executing step 304 to perform the processing of the above steps on the next suspected incompatible point.
In one embodiment, step 104 includes: if the positions of the two code blocks of the suspected incompatible point are different, the suspected incompatible point is determined to be a code block with substantial conflict.
In general, multiple pieces of code can be written within a line in any language (e.g., C, Java), such as:
int a;
a=5;a=a+1;
the above code block and the following code block are equivalent:
int a;
a=5;
a=a+1;
although the above two code blocks have the same meaning, the positions of the two code blocks are different from each other, and it is determined that the point of suspected incompatibility is a code block in which there is a substantial collision.
In one embodiment, where the compatibility condition comprises a code modification time, step 104 comprises: and if the modification time of the two code blocks of the suspected incompatible point is different, determining that the suspected incompatible point is a code block with substantial conflict. Even if the contents of two code blocks of a suspected incompatible point are completely identical, if the modification times are not identical, the suspected incompatible point is considered to be a code block in which there is a substantial conflict.
In one embodiment, where the compatibility condition comprises a value of an expression, step 104 comprises: and respectively calculating expressions in two code blocks in the suspected incompatible point, judging whether the values of the expressions in the two calculated code blocks are consistent, if so, judging that the suspected incompatible point is a code block without substantial conflict, and if not, judging that the suspected incompatible point is a code block with substantial conflict.
For example, one code block in a suspected incompatible point is int number-5; the other code block is 4+ 1; the values of these two expressions are identical, i.e., the suspected incompatibility point is considered to be a code block for which there is substantially no conflict.
And 106, selecting a code branch according to the compatibility condition so as to use the code block in the selected code branch for merging.
And if the suspected incompatible points in the two source codes are judged to be code blocks with conflict substantially, selecting a code branch according to the compatibility condition so as to use the code blocks in the selected code branch for combination. For example, when the compatibility condition is the code modification time, a code block with a new code modification time or an old code modification time may be selected; when the compatibility condition is a keyword, a code block containing "desired keyword" or a code block not containing "undesired keyword" may be selected; when the compatibility condition is a merge mode, a code block of a strict mode or a relaxed mode may be selected. For example, developers a and B both submit source code named test.c, the code content of lines 31 to 50 in the source code submitted by a is different from the code content of lines 31 to 70 in the source code submitted by B, only some operations are performed in lines 31 to 50 in the source code of a, and not only some operations but also return value check after a critical statement is performed in lines 31 to 70 in the source code of B. It can be seen that the code blocks of lines 31-70 in the source code of B belong to the strict mode, and the code blocks of lines 31-50 in the source code of a belong to the relaxed mode. When merging source codes, a code block may be selected according to whether a merging mode is a strict mode or a loose mode.
And step 108, selecting any code block in the suspected incompatible points for combination.
If the suspected incompatible points in the two source codes are determined to be code blocks with substantially no conflict, any one of the suspected incompatible points can be selected for merging.
In the technical solution, if a suspected incompatible point exists in two different versions of source codes, it is further determined that the suspected incompatible point is a code block that substantially has a conflict, a corresponding code branch is selected according to a preset compatibility condition, so as to use the code blocks in the selected code branch for merging. According to the scheme, under the condition that source code merging is carried out without depending on a merging tool, the problem of code incompatibility during source code merging is solved, meanwhile, merging work of manual intervention source codes is avoided, errors caused by manual intervention during source code merging are avoided, and therefore merging efficiency and merging accuracy of the source codes are improved.
The "source code", "code block", and "code branch" are explained below. "Source code" refers to all programs in a submission; "code block" refers to a portion of source code, e.g., lines of source code; "code branching" refers to different versions of a source code submission where a block of code is part of the source code.
In the foregoing technical solution, preferably, the method for automatically merging source codes further includes: detecting whether the compatibility condition is correct; and if the compatibility condition is detected to be incorrect, prompting the user that the compatibility condition is incorrect and/or prompting the user to reset the compatibility condition.
Because the set compatibility condition may be incorrect, it is necessary to detect whether the compatibility condition is correct, and further ensure the accuracy and reliability of the source code merging.
For example, the compatibility condition is a keyword, the item name of the value of the keyword is "ABC", but the keyword "ABC" is not present in the source code of two different versions, which indicates that the compatibility condition is set incorrectly. In addition, after the compatibility condition is set correctly, the source code merging executed thereafter generally does not have the condition that the compatibility condition is incorrect.
Fig. 4 is a schematic structural diagram of an automatic source code merging apparatus according to an embodiment of the present invention.
As shown in fig. 4, the source code automatic merging apparatus 400 according to an embodiment of the present invention includes: a lookup unit 402, a judgment unit 404 and a merging unit 406.
A finding unit 402 for finding suspected incompatible points in two different versions of the source code.
Preferably, the searching unit 402 comprises: a comparing subunit 4022, configured to compare code contents of a corresponding line between the source codes of the two different versions; a determining subunit 4024, configured to, if the code content of the corresponding line compared by the comparing subunit 4022 is different, take the code content of the corresponding line as the suspected incompatible point.
If the code content of the corresponding line between the two source codes is the same, it is indicated that the code content of the corresponding line is a compatible point, and if the code content of the corresponding line between the two source codes is different, it is indicated that the code content of the corresponding line may be an incompatible point, i.e. a suspected incompatible point.
A determining unit 404, configured to determine, according to a preset compatibility condition, whether the suspected incompatible point in the two source codes is a code block with a substantial conflict.
Preferably, the compatibility condition includes: the keyword, merge pattern code modification time, or value of an expression.
Preferably, in a case that the compatibility condition includes a keyword, the determining unit 404 is specifically configured to determine that the suspected incompatible point is a code block with a substantial conflict if the suspected incompatible point satisfies the keyword query condition; if the suspected incompatible point does not satisfy the keyword query condition, determining that the suspected incompatible point is not a code block with substantial conflict, wherein the keyword query condition includes: finding a first type keyword in one code block in the suspected incompatible point, and finding a second type keyword in another code block in the suspected incompatible point; or the first type key word is found in one code block in the suspected incompatible point, and the second type key word is not found in the other code block in the suspected incompatible point; or the second type key word is found in one code block in the suspected incompatible point, and the first type key word is not found in the other code block in the suspected incompatible point.
Preferably, when the compatibility condition includes a merge mode, the determining unit 404 is specifically configured to determine whether only one variable of a code block is present in the suspected incompatible point for initialization of display; if the suspected incompatible point is judged to have only one code block variable for display initialization, the suspected incompatible point is judged to be a code block with collision substantially; if the suspected incompatible point is judged to be not the variable with only one code block for display initialization, judging whether the suspected incompatible point has only one key statement of the code block and then checking a return value; if the suspected incompatible point is judged to have a return value check after the key statement of only one code block, the suspected incompatible point is judged to be a code block with a substantial conflict, and if the suspected incompatible point is judged to have a return value check after the key statement of only one code block is not judged to have the collision, the suspected incompatible point is judged to be not a code block with a substantial conflict.
A merging unit 406, configured to, if the determining unit 404 determines that the suspected incompatible points in the two source codes are code blocks with substantial conflicts, select a code branch according to the compatibility condition, so as to merge the code blocks in the selected code branch; and the merging unit 406 is further configured to select any one code block of the suspected incompatible points for merging if the determining unit 404 determines that the suspected incompatible points in the two source codes are code blocks with substantially no conflict.
In the technical solution, if a suspected incompatible point exists in two different versions of source codes, it is further determined that the suspected incompatible point is a code block that substantially has a conflict, a corresponding code branch is selected according to a preset compatibility condition, so as to use the code blocks in the selected code branch for merging. According to the scheme, under the condition that source code merging is carried out without depending on a merging tool, the problem of code incompatibility during source code merging is solved, meanwhile, merging work of manual intervention source codes is avoided, errors caused by manual intervention during source code merging are avoided, and therefore merging efficiency and merging accuracy of the source codes are improved.
In any of the above technical solutions, preferably, the apparatus 400 for automatically merging source codes further includes: a detecting unit 408, configured to detect whether the compatibility condition is correct; a prompting unit 410, configured to prompt the user that the compatibility condition is incorrect and/or prompt the user to reset the compatibility condition if the detecting unit 408 detects that the compatibility condition is incorrect.
Because the principle of solving the problem of the automatic source code merging device is similar to that of the automatic source code merging method, the implementation of the device can refer to the implementation of the method, and repeated details are not repeated.
The technical scheme of the invention is explained in detail in the above with reference to the attached drawings, and by the technical scheme of the invention, under the condition of not depending on a merging tool to merge the source codes, the problem of code incompatibility during source code merging is solved, and meanwhile, the merging work of manual intervention source codes is avoided, so that the merging efficiency of the source codes is improved.
In the present invention, the terms "first" and "second" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance. The specific meanings of the above terms in the present invention can be understood by those skilled in the art according to specific situations.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (8)

1. A method for automatically merging source codes is characterized by comprising the following steps:
finding suspected incompatible points in source codes of two different versions;
judging whether the suspected incompatible points in the two source codes are code blocks with substantial conflict or not according to a preset compatibility condition;
if the suspected incompatible points in the two source codes are code blocks with conflict substantially, selecting a code branch according to the compatibility condition so as to use the selected code blocks in the code branch for merging; and
if the suspected incompatible points in the two source codes are code blocks with substantially no conflict, selecting any code block in the suspected incompatible points for combination;
the compatibility condition comprises one or more combinations of keywords, merging modes, code modification time and values of expressions;
in a case where the compatibility condition includes a keyword, the step of determining whether the suspected incompatibility point in the two source codes is a code block with a substantial conflict includes:
if the suspected incompatible point meets the keyword query condition, determining that the suspected incompatible point is a code block with substantial conflict;
if the suspected incompatible point does not satisfy the keyword query condition, determining that the suspected incompatible point is not a code block with substantial conflict,
wherein the keyword query condition comprises: finding a first type keyword in one code block in the suspected incompatible point, and finding a second type keyword in another code block in the suspected incompatible point; or the first type key word is found in one code block in the suspected incompatible point, and the second type key word is not found in the other code block in the suspected incompatible point; or the second type key words are found in one code block in the suspected incompatible points, and the first type key words are not found in the other code block in the suspected incompatible points.
2. The method of claim 1, wherein the step of finding suspected incompatible points in two different versions of source code comprises:
comparing the code content of corresponding lines between the source codes of two different versions;
and if the code content of the corresponding line is different, taking the code content of the corresponding line as the suspected incompatible point.
3. The method according to claim 1, wherein in the case that the compatibility condition includes a merge mode, the step of determining whether the suspected incompatibility point in the two source codes is a code block with a substantial conflict comprises:
judging whether the suspected incompatible point has only one variable of a code block for display initialization;
if the suspected incompatible point is judged to have only one code block variable for display initialization, the suspected incompatible point is judged to be a code block with collision substantially;
if the suspected incompatible point is judged to be not the variable with only one code block for display initialization, judging whether the suspected incompatible point has only one key statement of the code block and then checking a return value;
if the suspected incompatible point is judged to have a return value check after the key statement of only one code block, the suspected incompatible point is judged to be a code block with a substantial conflict, and if the suspected incompatible point is judged to have a return value check after the key statement of only one code block is not judged to have the collision, the suspected incompatible point is judged to be not a code block with a substantial conflict.
4. The method of any of claims 1 to 3, wherein the method of automatic source code merging further comprises:
detecting whether the compatibility condition is correct;
and if the compatibility condition is detected to be incorrect, prompting the user that the compatibility condition is incorrect and/or prompting the user to reset the compatibility condition.
5. An apparatus for automatic source code merging, comprising:
the searching unit is used for searching suspected incompatible points in the source codes of the two different versions;
a judging unit, configured to judge, according to a preset compatibility condition, whether the suspected incompatible point in the two source codes is a code block with a substantial conflict;
a merging unit, configured to select a code branch according to the compatibility condition if the determining unit determines that the suspected incompatible point in the two source codes is a code block with a substantial conflict, so as to merge the code blocks in the selected code branch; and
the merging unit is further configured to select any one code block of the suspected incompatible points for merging if the determining unit determines that the suspected incompatible points in the two source codes are code blocks with substantially no conflict;
the compatibility condition comprises one or more combinations of keywords, merging modes, code modification time and values of expressions;
in case the compatibility condition comprises a keyword, the determining unit is specifically configured to,
if the suspected incompatible point meets the keyword query condition, determining that the suspected incompatible point is a code block with substantial conflict;
if the suspected incompatible point does not satisfy the keyword query condition, determining that the suspected incompatible point is not a code block with substantial conflict,
wherein the keyword query condition comprises: finding a first type keyword in one code block in the suspected incompatible point, and finding a second type keyword in another code block in the suspected incompatible point; or the first type key word is found in one code block in the suspected incompatible point, and the second type key word is not found in the other code block in the suspected incompatible point; or the second type key word is found in one code block in the suspected incompatible point, and the first type key word is not found in the other code block in the suspected incompatible point.
6. The apparatus according to claim 5, wherein the search unit comprises:
the comparison subunit is used for comparing the code content of the corresponding line between the source codes of the two different versions;
and the determining subunit is configured to, if the code content of the corresponding line compared by the comparing subunit is different, take the code content of the corresponding line as the suspected incompatible point.
7. The apparatus according to claim 5, wherein, in the case that the compatibility condition includes a merge mode, the determining unit is specifically configured to,
judging whether the suspected incompatible point has only one variable of a code block for display initialization;
if the suspected incompatible point is judged to have only one code block variable for display initialization, the suspected incompatible point is judged to be a code block with collision substantially;
if the suspected incompatible point is judged to be not the variable with only one code block for display initialization, judging whether the suspected incompatible point has only one key statement of the code block and then checking a return value;
if the suspected incompatible point is judged to have a return value check after the key statement of only one code block, the suspected incompatible point is judged to be a code block with a substantial conflict, and if the suspected incompatible point is judged to have a return value check after the key statement of only one code block is not judged to have the collision, the suspected incompatible point is judged to be not a code block with a substantial conflict.
8. The apparatus according to any one of claims 5 to 7, wherein the apparatus further comprises:
the detection unit is used for detecting whether the compatibility condition is correct or not;
and the prompting unit is used for prompting the user that the compatibility condition is incorrect and/or prompting the user to reset the compatibility condition if the detection unit detects that the compatibility condition is incorrect.
CN201611055852.6A 2016-11-25 2016-11-25 Automatic source code merging method and automatic source code merging device Active CN106406918B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201611055852.6A CN106406918B (en) 2016-11-25 2016-11-25 Automatic source code merging method and automatic source code merging device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201611055852.6A CN106406918B (en) 2016-11-25 2016-11-25 Automatic source code merging method and automatic source code merging device

Publications (2)

Publication Number Publication Date
CN106406918A CN106406918A (en) 2017-02-15
CN106406918B true CN106406918B (en) 2020-02-28

Family

ID=58082030

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201611055852.6A Active CN106406918B (en) 2016-11-25 2016-11-25 Automatic source code merging method and automatic source code merging device

Country Status (1)

Country Link
CN (1) CN106406918B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107329765B (en) * 2017-07-04 2020-09-04 武汉斗鱼网络科技有限公司 Program file processing method and device
CN109308253B (en) * 2017-07-27 2022-07-12 华为终端有限公司 Code detection method and device
US10671385B2 (en) 2018-04-24 2020-06-02 International Business Machines Corporation Dynamic code maturity determination for proactive code review and merge
CN111221566B (en) * 2019-12-28 2021-10-22 华为技术有限公司 Method and device for combining multiple and changeable versions of software code
CN113535206B (en) * 2021-07-23 2024-02-20 上海幻电信息科技有限公司 Multi-version code upgrading method and system

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1773506A (en) * 2004-11-12 2006-05-17 国际商业机器公司 Method and system for managing revisions to a file
CN1783093A (en) * 2004-12-01 2006-06-07 国际商业机器公司 Method and device for integrating multiple different versions of electronic files
CN1809818A (en) * 2003-06-20 2006-07-26 创道软件有限公司 Processing software for use in generating difference files
CN102279749A (en) * 2011-08-30 2011-12-14 大唐移动通信设备有限公司 Method and equipment for merging codes
CN104035772A (en) * 2014-06-09 2014-09-10 中国科学院软件研究所 Static analysis based source code multi-versionfunction call relation difference identification method
CN104407901A (en) * 2014-12-08 2015-03-11 北京国双科技有限公司 Code adding method and device
CN104461578A (en) * 2014-12-26 2015-03-25 广州唯品会信息科技有限公司 Automatic code merging method and system
CN105302533A (en) * 2014-07-25 2016-02-03 腾讯科技(深圳)有限公司 Code synchronizing method and apparatus

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9176828B2 (en) * 2012-09-04 2015-11-03 Opshub, Inc. System and method for merging results from multiple runs based on run inputs
US20150220331A1 (en) * 2014-02-05 2015-08-06 International Business Machines Corporation Resolving merge conflicts that prevent blocks of program code from properly being merged

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1809818A (en) * 2003-06-20 2006-07-26 创道软件有限公司 Processing software for use in generating difference files
CN1773506A (en) * 2004-11-12 2006-05-17 国际商业机器公司 Method and system for managing revisions to a file
CN1783093A (en) * 2004-12-01 2006-06-07 国际商业机器公司 Method and device for integrating multiple different versions of electronic files
CN102279749A (en) * 2011-08-30 2011-12-14 大唐移动通信设备有限公司 Method and equipment for merging codes
CN104035772A (en) * 2014-06-09 2014-09-10 中国科学院软件研究所 Static analysis based source code multi-versionfunction call relation difference identification method
CN105302533A (en) * 2014-07-25 2016-02-03 腾讯科技(深圳)有限公司 Code synchronizing method and apparatus
CN104407901A (en) * 2014-12-08 2015-03-11 北京国双科技有限公司 Code adding method and device
CN104461578A (en) * 2014-12-26 2015-03-25 广州唯品会信息科技有限公司 Automatic code merging method and system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
"离线模式下协同设计中对象版本的合并";王维丽 等;《计算机应用》;20050630;第25卷(第6期);第1467-1470页 *

Also Published As

Publication number Publication date
CN106406918A (en) 2017-02-15

Similar Documents

Publication Publication Date Title
CN106406918B (en) Automatic source code merging method and automatic source code merging device
EP3265916B1 (en) A method for identifying a cause for a failure of a test
US10019240B2 (en) Method and apparatus for detecting code change
US8627289B2 (en) Detecting configuration problems in an eclipse-based software application
US9329981B2 (en) Testing program, testing method, and testing device
US9383973B2 (en) Code suggestions
US7882495B2 (en) Bounded program failure analysis and correction
US20120167060A1 (en) System and Method for Software Immunization Based on Static and Dynamic Analysis
US9256512B1 (en) Quality analysis for embedded software code
CN105446723A (en) Method and device for identifying semantic difference between source code versions
US7721250B2 (en) System and method for interactive and integrated software development process and phases
CN107643893B (en) Program detection method and device
EP2778629A1 (en) Method and device for code change detection
US9921947B2 (en) Test selection method and test selection apparatus
CN101324856B (en) Method and system for upgrading data
JP5188421B2 (en) Source code analysis method and source code analysis support system
JP6451417B2 (en) Debug support device, debug support system, debug support method, and debug support program
Ueda et al. Mining source code improvement patterns from similar code review works
CN108804308B (en) Defect detection method and device for new version program
JP6369177B2 (en) Development support program, development support method, and development support apparatus
JP4763743B2 (en) Program operation comparison apparatus and method and program
JP2008020972A (en) Software analysis system
CN111124922A (en) Rule-based automatic program repair method, storage medium, and computing device
CN111782220A (en) File detection method and device
CN113805928A (en) Hot patch file generation and consistency detection method, device, equipment and medium

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20210901

Address after: Room 402, 4th floor, building 23, East District, yard 10, northwest Wangdong Road, Haidian District, Beijing 100095

Patentee after: VSETTAN INFORMATION INDUSTRY DEVELOPMENT Co.,Ltd.

Patentee after: BEIJING VSETTAN DATA TECHNOLOGY Co.,Ltd.

Address before: 100192 West Zone, 10 / F, block a, No. 8 Xueqing Road (Science and technology wealth center), Haidian District, Beijing

Patentee before: VSETTAN INFORMATION INDUSTRY DEVELOPMENT Co.,Ltd.

TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20220420

Address after: Room 403, 4th floor, building 23, East District, yard 10, Xibeiwang East Road, Haidian District, Beijing 100089

Patentee after: BEIJING VSETTAN DATA TECHNOLOGY CO.,LTD.

Address before: Room 402, 4th floor, building 23, East District, yard 10, northwest Wangdong Road, Haidian District, Beijing 100095

Patentee before: VSETTAN INFORMATION INDUSTRY DEVELOPMENT CO.,LTD.

Patentee before: Beijing Huasheng Xintai Data Technology Co., Ltd