Content of the invention
It is contemplated that at least solving one of technical problem present in prior art or correlation technique.
For this reason, it is an object of the present invention to proposing a kind of automatic merging method of source code.
Further object is that proposing a kind of source code automatically merge device.
For realizing at least one purpose above-mentioned, embodiment according to the first aspect of the invention is it is proposed that a kind of source code
Automatically merging method, including:Find out the doubtful incompatible point in the source code of two different editions;According to default compatibility
Condition, judges whether the described doubtful incompatible point in two described source codes is the code block that there is essentially conflict;If two
Described doubtful incompatible point in individual described source code is the code block that there is essentially conflict, then according to described compatibility condition
Select code branch, merged with the code block in the described code branch using selection;And if two described source codes
In described doubtful incompatible point be the code block being created substantially absent conflict, then select arbitrary in described doubtful incompatible point
Code block merges.
It is preferable that doubtful incompatible in the described source code finding out two different editions in technique scheme
The step of point includes:The code content of corresponding row between the described source code of two different editions of contrast;If described corresponding row
Code content differs, then using the code content of described corresponding row as described doubtful incompatible point.
In any of the above-described technical scheme it is preferable that described compatibility condition include key word, merging patterns, described doubt
Seemingly one or more of the position of incompatible point, code revision time, the value of expression formula combination.
In any of the above-described technical scheme it is preferable that in the case that described compatibility condition includes key word, described sentence
Whether the described doubtful incompatible point in disconnected two described source codes is the step of the code block that there is essentially conflict, including:
If described doubtful incompatible point meets keyword query condition, judge described doubtful incompatible point as there is essentially conflict
Code block;If described doubtful incompatible point is unsatisfactory for keyword query condition, judge that described doubtful incompatible point is not essence
The upper code block that there is conflict, wherein, described keyword query condition includes:In one of described doubtful incompatible point code
Find first kind key word in block, and find Second Type in another code block in described doubtful incompatible point
Key word;Or find described first kind key word in one of described doubtful incompatible point code block, and in institute
State in another code block in doubtful incompatible point and do not find described Second Type key word;Or described doubtful not simultaneous
Hold in one of point code block and find described Second Type key word, and another generation in described doubtful incompatible point
Described first kind key word is not found in code block.
In any of the above-described technical scheme it is preferable that in the case that described compatibility condition includes merging patterns, described
Judge that whether the described doubtful incompatible point in two described source codes is the step of the code block that there is essentially conflict, bag
Include:Judge that the variable whether only having a code block in described doubtful incompatible point carries out display initialization;If it is determined that described doubt
Variable like an only code block in incompatible point carries out display initialization, then judge that described doubtful incompatible point is substantially
There is the code block of conflict;If it is determined that not being that to carry out display initial for the variable of an only code block in described doubtful incompatible point
Change, then have return value inspection after the key sentence judging in described doubtful incompatible point whether to only have a code block;If it is determined that
There is return value inspection after the key sentence only having a code block in described doubtful incompatible point, then judge described doubtful incompatible
Point is the code block that there is essentially conflict, if it is determined that not being the Key Words of an only code block in described doubtful incompatible point
There is return value inspection after sentence, then judge that described doubtful incompatible point is not the code block that there is essentially conflict.
It is preferable that the automatic merging method of described source code also includes in any of the above-described technical scheme:Detect described compatibility
Whether property condition is correct;If it is incorrect described compatibility condition is detected, point out user described in compatibility condition incorrect and/
Or prompting user resets described compatibility condition.
Embodiment according to the second aspect of the invention it is proposed that a kind of source code merges device automatically, including:Search single
Unit, for finding out the doubtful incompatible point in the source code of two different editions;Judging unit, for according to default compatibility
Property condition, judges whether the described doubtful incompatible point in two described source codes is the code block that there is essentially conflict;Close
And unit, if judging described doubtful incompatible point in two described source codes as there is essentially punching for described judging unit
Prominent code block, then select code branch according to described compatibility condition, with the code in the described code branch using selection
Block merges;And described combining unit is additionally operable to, if described judging unit described doubting of judging in two described source codes
It is the code block being created substantially absent conflict like incompatible point, then select the arbitrary code block in described doubtful incompatible point to carry out
Merge.
It is preferable that described searching unit includes in technique scheme:Contrast subunit, for contrasting two differences
The code content of corresponding row between the described source code of version;Determination subelement, if contrast institute for described contrast subunit
The code content stating corresponding row differs, then using the code content of described corresponding row as described doubtful incompatible point.
In any of the above-described technical scheme it is preferable that described compatibility condition include key word, merging patterns, described doubt
Seemingly one or more of the position of incompatible point, code revision time, the value of expression formula combination.
In any of the above-described technical scheme it is preferable that in the case that described compatibility condition includes key word, described sentence
Disconnected unit specifically for, if described doubtful incompatible point meets keyword query condition, judge described doubtful incompatible point as
There is essentially the code block of conflict;If described doubtful incompatible point is unsatisfactory for keyword query condition, judge described doubtful
Incompatible point is not the code block that there is essentially conflict, and wherein, described keyword query condition includes:Described doubtful not simultaneous
Hold in one of point code block and find first kind key word, and another code block in described doubtful incompatible point
In find Second Type key word;Or find the described first kind in one of described doubtful incompatible point code block
Type key word, and do not find described Second Type key word in another code block in described doubtful incompatible point;Or
Person finds described Second Type key word in one of described doubtful incompatible point code block, and described doubtful not simultaneous
Hold in another code block in point and do not find described first kind key word.
In any of the above-described technical scheme it is preferable that in the case that described compatibility condition includes merging patterns, described
Judging unit is specifically for judging that the variable whether only having a code block in described doubtful incompatible point carries out display initial
Change;If it is determined that the variable only having a code block in described doubtful incompatible point carries out display initialization, then judge described doubtful
Incompatible point is the code block that there is essentially conflict;If it is determined that not being only one code block in described doubtful incompatible point
Variable carries out display initialization, then return after the key sentence judging in described doubtful incompatible point whether to only have a code block
Return value to check;If it is determined that in described doubtful incompatible point only have a code block key sentence after have return value inspection, then sentence
Fixed described doubtful incompatible point is the code block that there is essentially conflict, if it is determined that not being only one in described doubtful incompatible point
There is return value inspection after the key sentence of individual code block, then judge that described doubtful incompatible point is not the generation that there is essentially conflict
Code block.
It is preferable that described source code merges device automatically also includes in any of the above-described technical scheme:Detector unit, uses
Whether correct in the described compatibility condition of detection;Tip element, if detect described compatibility condition for described detector unit
Incorrect, then compatibility condition described in prompting user is incorrect and/or prompting user resets described compatibility condition.
By technical scheme, do not relying in the case that merging instrument carries out source code merging, solving
When source code merges, the incompatible problem of the code that occurs, avoids the merging work of manual intervention source code, thus carrying simultaneously
The high combined efficiency of source code.
Specific embodiment
In order to the above objects, features and advantages of the present invention can be more clearly understood that, below in conjunction with the accompanying drawings and specifically real
Mode of applying is further described in detail to the present invention.It should be noted that in the case of not conflicting, the enforcement of the application
Feature in example and embodiment can be mutually combined.
Elaborate a lot of details in the following description in order to fully understand the present invention, but, the present invention also may be used
To be implemented different from other modes described here using other, therefore, protection scope of the present invention is not described below
Specific embodiment restriction.
Fig. 1 shows the schematic flow sheet of the automatic merging method of source code according to an embodiment of the invention.
As shown in figure 1, the automatic merging method of source code according to an embodiment of the invention, including:
Step 102, finds out the doubtful incompatible point in the source code of two different editions.
Preferably, step 102 includes:The code content of corresponding row between the described source code of two different editions of contrast;
If the code content of described corresponding row differs, using the code content of described corresponding row as described doubtful incompatible point.
If the code content of corresponding row is identical between two source codes, illustrate that the code content of this correspondence row is compatible
Point, if the code content of corresponding row differs between two source codes, illustrates that the code content of this correspondence row is not possibly simultaneous
Rong Dian, i.e. doubtful incompatible point, need to operate with carrying out next step to determine the code content of this correspondence row substantially whether
For incompatible point, thus than the substantial incompatible point more fully finding out in two source codes.
Wherein, doubtful incompatible point is some line codes, and for example, developer A and B have submitted an entitled test.c
Source code, the source code that A submits to has 80 row, and the source code that B submits to has 100 row, if the source that the source code submitted to of A and B submit to
The code content of front 30 row of code is the same, and the 31st row in the source code that A submits to carries to the code content of the 50th row and B
The code content of the 31st row to the 70th row in the source code handed over is different, and the 51st row in the source code that A submits to is to the 80th row
The 71st row in the source code that code content is submitted to B is identical to the code content of the 100th row, then in the source code submitted A to
The code of the 31st row to the 50th row and B submit to source code in the 31st row to the 70th row code as one doubtful not and
Rong Dian.
Further doubtful incompatible point is illustrated below by two examples.
For example, there is a=5 in the source code that developer A develops, corresponding row in the source code that developer B develops
There is a=4+1 it is seen that " a=5 " is different with the code content of " a=4+1 ", that is, " a=5 " and " a=4+1 " is doubtful incompatible point.
Again for example, there is a=5 in the source code that developer A develops, corresponding in the source code that developer B develops
Row has b=5 it is seen that " a=5 " is different with the code content of " b=5 ", and that is, " a=5 " and " b=5 " is doubtful incompatible point.
Step 104, according to default compatibility condition, judges that the described doubtful incompatible point in two described source codes is
The no code block for there is essentially conflict, the described doubtful incompatible point in judging two described source codes is as substantially depositing
In the code block of conflict, then execution step 106, the described doubtful incompatible point in judging two described source codes is as substantially
There is not the code block of conflict, then execution step 108.
Preferably, compatibility condition includes key word, merging patterns, the position of described doubtful incompatible point, code revision
One or more of time, the value of expression formula combine.
Can judge whether doubtful incompatible point is to there is essentially conflict exactly by above compatibility condition
Code block.
In one embodiment, in the case that described compatibility condition includes key word, step 104 includes:If described
Doubtful incompatible point meets keyword query condition, then judge described doubtful incompatible point as the code that there is essentially conflict
Block;If described doubtful incompatible point is unsatisfactory for keyword query condition, judge that described doubtful incompatible point is not substantially to deposit
In the code block of conflict, wherein, described keyword query condition includes:In one of described doubtful incompatible point code block
Find first kind key word, and it is crucial to find Second Type in another code block in described doubtful incompatible point
Word;Or find described first kind key word in one of described doubtful incompatible point code block, and doubt described
Do not find described Second Type key word like in another code block in incompatible point;Or in described doubtful incompatible point
One of find described Second Type key word, and another code block in described doubtful incompatible point in code block
In do not find described first kind key word.
Wherein, first kind key word and Second Type key word are all the key word pre-setting, the such as first kind
Key word is expectation key word, and Second Type key word is undesirable key word.Further illustrate how root with reference to Fig. 2
Judge whether doubtful incompatible point is the code block that there is essentially conflict according to key word.Specifically include:
Step 202, setting compatibility condition is key word, and key word includes expecting key word and undesirable key word.Phase
Hope that key word and undesirable key word can be one or more key words.For example, can arrange expectation key word is
" ToprowMQ ", the undesirable key word of setting is " WebSphereMQ ".
Step 204, contrasts two code blocks of doubtful incompatible point.
Step 206, judges whether to find expectation in one of two code blocks code block of doubtful incompatible point
Key word, finds undesirable key word in another code block, when judged result is to be, execution step 208, in judged result
For no when, execution step 210.
Step 208, judges doubtful incompatible point as the code block that there is essentially conflict.
Step 210, judges whether to find expectation in one of two code blocks code block of doubtful incompatible point
Key word, does not find undesirable key word in another code block, when judged result is to be, execution step 208, and sentencing
When disconnected result is no, execution step 212.
Step 212, judges whether to find the not phase in one of two code blocks code block of doubtful incompatible point
Hope key word, another code block does not find expectation key word, when judged result is to be, execution step 208, judging
When result is no, execution step 214.
Step 214, judges doubtful incompatible point as the code block being created substantially absent conflict
Step 216, judges whether all of doubtful incompatible point judges to finish, and when judged result is to be, terminates this
Flow process, judged result for no when, re-execute step 204, so that the doubtful incompatible point of the next one is carried out with the place of above-mentioned steps
Reason.
In one embodiment, in the case that described compatibility condition includes merging patterns, step 104 includes:Judge
The variable whether only having a code block in described doubtful incompatible point carries out display initialization;If it is determined that it is described doubtful incompatible
The variable only having a code block in point carries out display initialization, then judge that described doubtful incompatible point is to there is essentially conflict
Code block;If it is determined that in described doubtful incompatible point be not an only code block variable carry out display initialization, then sentence
There is return value inspection after the key sentence whether only having a code block in disconnected described doubtful incompatible point;If it is determined that it is described doubtful
There is return value inspection after the key sentence only having a code block in incompatible point, then judge that described doubtful incompatible point is essence
The upper code block that there is conflict, if it is determined that be not only to return after the key sentence of a code block in described doubtful incompatible point
Return value to check, then judge that described doubtful incompatible point is not the code block that there is essentially conflict.
Further illustrate how to judge whether doubtful incompatible point is substantially to deposit according to merging patterns with reference to Fig. 3
Code block in conflict.Specifically include:
Step 302, setting compatibility condition is merging patterns.
Step 304, contrasts two code blocks of doubtful incompatible point.
Step 306, at the beginning of judging that the variable of only one of which code block in two code blocks of doubtful incompatible point is shown
Beginningization, judged result be when, enter step 308, judged result for no when, enter step 310.
Step 308, judges doubtful incompatible point as the code block that there is essentially conflict.
Step 310, judges to return after the key sentence of only one of which code block in two code blocks of doubtful incompatible point
Return value check, judged result be when, enter step 308, judged result for no when, enter step 312.
Step 312, judges doubtful incompatible point as the code block being created substantially absent conflict.
Step 314, judges whether all of doubtful incompatible point judges to finish, and when judged result is to be, terminates this
Flow process, judged result for no when, re-execute step 304, so that the doubtful incompatible point of the next one is carried out with the place of above-mentioned steps
Reason.
In one embodiment, include the position of doubtful incompatible point in described compatibility condition in the case of, step 104
Including:If the position of two code blocks of doubtful incompatible point is different, judge that doubtful incompatible point is to there is essentially conflict
Code block.
Generally, many Codabar codes can be write, such as in a line of any language (such as C, Java):
int a;
A=5;A=a+1;
Above code block and following code block are equivalent:
int a;
A=5;
A=a+1;
Although above two code blocks is equivalent in meaning, the position of two code blocks is different, judges doubtful not simultaneous
Holding point is the code block that there is essentially conflict.
In one embodiment, in the case that described compatibility condition includes the code revision time, step 104 includes:
If the modification time of two code blocks of doubtful incompatible point is different, judge that doubtful incompatible point there is essentially conflict
Code block.Even if the content of two code blocks of doubtful incompatible point is completely the same, but if modification time is inconsistent, then
Think that doubtful incompatible point is the code block that there is essentially conflict.
In one embodiment, include the value of expression formula in described compatibility condition in the case of, step 104 includes:Point
Other expression formula in two code blocks in doubtful incompatible point is calculated, judge the table in two code blocks calculating
Whether the value reaching formula is consistent, if unanimously, judges that doubtful incompatible point is the code block being created substantially absent conflict, if differing
Cause, then judge that doubtful incompatible point is the code block that there is essentially conflict.
For example, one of doubtful incompatible point code block is int number=5;Another code block is int
Number=4+1;The value of this two expression formulas is consistent, you can think that changing doubtful incompatible point is the generation being created substantially absent conflict
Code block.
Step 106, selects code branch according to described compatibility condition, with the generation in the described code branch using selection
Code block merges.
If it is determined that the described doubtful incompatible point in two described source codes is the code block that there is essentially conflict, according to
Described compatibility condition selects code branch, is merged with the code block in the described code branch using selection.Illustrate,
When compatibility condition is for the code revision time, the code that the code revision time is new or the code revision time is old can be selected
Block;When compatibility condition is for key word, can select to include the code block of " expectation key word " or not comprise " undesirable
The code block of key word ";When compatibility condition is for the position of doubtful incompatible point, can select " multiple sentences are in a line " or
The code block of " multiple sentences are in multirow ";When compatibility condition is for merging patterns, rigorous pattern or loose mould can be selected
The code block of formula.For example, developer A and B two people submits the source code of entitled test.c to, the in the source code that A submits to
The code content of 31 row to the 50th row is different to the code content of the 70th row with the 31st row in the source code that B submits to, in the source of A
31-50 row in code, only performs certain operations, and the 31-70 row in the source code of B, not only perform certain operations,
Also has return value inspection after key sentence.It can be seen that, the code block of the 31-70 row in the source code of B belongs to rigorous pattern, A's
The code block of the 31-50 row in source code belongs to loose pattern.When merging source code, can be rigorous pattern according to merging patterns
Or loose pattern, to select code block.
Step 108, selects the arbitrary code block in described doubtful incompatible point to merge.
If it is determined that the described doubtful incompatible point in two described source codes is the code block being created substantially absent conflict, can
To select the arbitrary code block in described doubtful incompatible point to merge.
In this technical scheme, if in the case of there is doubtful incompatible point in the source code of two different editions, entering one
Step judges this doubtful incompatible point as the code block that there is essentially conflict, then selected corresponding according to default compatibility condition
Code branch, is merged with the code block in the described code branch using selection.Above scheme is not relying on merging work
In the case that tool carries out source code merging, solve the problems, such as that the code that source code occurs when merging is incompatible, avoid simultaneously
The merging work of manual intervention source code, also avoids the error bringing when manual intervention source code merges, thus improve
The combined efficiency of source code and merging accuracy rate.
Hereinafter " source code ", " code block " and " code branch " is illustrated." source code " refers in certain submission
All of program;" code block " refers to the part in source code, for example, several rows in source code;" code branch " refers to
Be source code submit to different editions, wherein, code block is a part for source code.
It is preferable that the automatic merging method of described source code also includes in technique scheme:Detection described compatibility bar
Whether part is correct;If it is incorrect described compatibility condition is detected, points out compatibility condition described in user incorrect and/or carry
Show that user resets described compatibility condition.
Compatibility condition due to setting may be incorrect, accordingly, it would be desirable to whether detection compatibility condition is correct, enters one
Ensure that to step accuracy and the reliability of source code merging.
For example, compatibility condition is key word, and the project name of the value of key word is " ABC ", but in two different editions
Source code in all there is no key word " ABC ", illustrate compatibility condition setting mistake.In addition, compatibility condition setting correct it
Afterwards, it is not in typically the incorrect situation of compatibility condition that the source code hereafter executing merges.
Fig. 4 shows that source code according to an embodiment of the invention merges the structural representation of device automatically.
As shown in figure 4, source code according to an embodiment of the invention merges device 400 automatically, including:Searching unit
402nd, judging unit 404 and combining unit 406.
Searching unit 402, for finding out the doubtful incompatible point in the source code of two different editions.
Preferably, described searching unit 402 includes:Contrast subunit 4022, for described in two different editions of contrast
The code content of corresponding row between source code;Determination subelement 4024, if contrast described for described contrast subunit 4022
The code content of corresponding row differs, then using the code content of described corresponding row as described doubtful incompatible point.
If the code content of corresponding row is identical between two source codes, illustrate that the code content of this correspondence row is compatible
Point, if the code content of corresponding row differs between two source codes, illustrates that the code content of this correspondence row is not possibly simultaneous
Rong Dian, i.e. doubtful incompatible point, need to operate with carrying out next step to determine the code content of this correspondence row substantially whether
For incompatible point, thus than the substantial incompatible point more fully finding out in two source codes.
Judging unit 404, for according to default compatibility condition, judge in two described source codes described doubtful not
Whether compatible point is the code block that there is essentially conflict.
Preferably, described compatibility condition includes:Key word, merging patterns, the position of described doubtful incompatible point, code
Modification time or the value of expression formula.
Preferably, in the case that described compatibility condition includes key word, described judging unit 404 specifically for, if
Described doubtful incompatible point meets keyword query condition, then judge described doubtful incompatible point as the generation that there is essentially conflict
Code block;If described doubtful incompatible point is unsatisfactory for keyword query condition, judge that described doubtful incompatible point is not substantially
There is the code block of conflict, wherein, described keyword query condition includes:In one of described doubtful incompatible point code block
In find first kind key word, and find in another code block in described doubtful incompatible point Second Type close
Keyword;Or find described first kind key word in one of described doubtful incompatible point code block, and described
Described Second Type key word is not found in another code block in doubtful incompatible point;Or described doubtful incompatible
Described Second Type key word, and another code in described doubtful incompatible point is found in one of point code block
Described first kind key word is not found in block.
Preferably, in the case that described compatibility condition includes merging patterns, described judging unit 404 specifically for,
Judge that the variable whether only having a code block in described doubtful incompatible point carries out display initialization;If it is determined that described doubtful not
In compatible point, the variable of an only code block carries out display initialization, then judge that described doubtful incompatible point is to there is essentially
The code block of conflict;If it is determined that in described doubtful incompatible point be not an only code block variable carry out display initialization,
There is return value inspection after the key sentence then judging in described doubtful incompatible point whether to only have a code block;If it is determined that it is described
There is return value inspection after the key sentence only having a code block in doubtful incompatible point, then judge that described doubtful incompatible point is
There is essentially the code block of conflict, if it is determined that not being only in described doubtful incompatible point after the key sentence of a code block
There is return value inspection, then judge that described doubtful incompatible point is not the code block that there is essentially conflict.
Combining unit 406, if judge described doubtful incompatible in two described source codes for described judging unit 404
Point is the code block that there is essentially conflict, then select code branch according to described compatibility condition, with using described in selection
Code block in code branch merges;And described combining unit 406 is additionally operable to, if described judging unit 404 judges two
Described doubtful incompatible point in individual described source code is the code block being created substantially absent conflict, then select described doubtful not simultaneous
The arbitrary code block holding in point merges.
In this technical scheme, if in the case of there is doubtful incompatible point in the source code of two different editions, entering one
Step judges this doubtful incompatible point as the code block that there is essentially conflict, then selected corresponding according to default compatibility condition
Code branch, is merged with the code block in the described code branch using selection.Above scheme is not relying on merging work
In the case that tool carries out source code merging, solve the problems, such as that the code that source code occurs when merging is incompatible, avoid simultaneously
The merging work of manual intervention source code, also avoids the error bringing when manual intervention source code merges, thus improve
The combined efficiency of source code and merging accuracy rate.
It is preferable that described source code merges device 400 automatically also includes in any of the above-described technical scheme:Detector unit
408, whether correct for detecting described compatibility condition;Tip element 410, if detect institute for described detector unit 408
State compatibility condition incorrect, then prompting user described in compatibility condition incorrect and/or prompting user reset described and
Capacitive condition.
Due to this source code automatically merge device solve problem principle similar to the automatic merging method of aforementioned source code, because
The enforcement of this this device may refer to the enforcement of preceding method, repeats no more in place of repetition.
Technical scheme is described in detail above in association with accompanying drawing, by technical scheme, is being independent of
In the case that merging instrument carries out source code merging, solve the problems, such as that the code that source code occurs when merging is incompatible, with
When avoid the merging work of manual intervention source code, thus improve the combined efficiency of source code.
In the present invention, term " first ", " second " are only used for the purpose describing, and it is not intended that instruction or hint phase
To importance.For the ordinary skill in the art, above-mentioned term can be understood as the case may be in the present invention
Concrete meaning.
The foregoing is only the preferred embodiments of the present invention, be not limited to the present invention, for the skill of this area
For art personnel, the present invention can have various modifications and variations.All within the spirit and principles in the present invention, made any repair
Change, equivalent, improvement etc., should be included within the scope of the present invention.