CN106406918A - Source code automatic merging method and apparatus - Google Patents

Source code automatic merging method and apparatus Download PDF

Info

Publication number
CN106406918A
CN106406918A CN201611055852.6A CN201611055852A CN106406918A CN 106406918 A CN106406918 A CN 106406918A CN 201611055852 A CN201611055852 A CN 201611055852A CN 106406918 A CN106406918 A CN 106406918A
Authority
CN
China
Prior art keywords
code
doubtful
code block
incompatible point
incompatible
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.)
Granted
Application number
CN201611055852.6A
Other languages
Chinese (zh)
Other versions
CN106406918B (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

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 apparatus. The source code automatic merging method comprises the steps of finding out suspected incompatible points from source codes of two different versions; determining whether the suspected incompatible points in two source codes are code blocks with actual conflicts or not according to a preset compatibility condition; if the suspected incompatible points in the two source codes are code blocks with actual conflicts, selecting a code branch according to the compatibility condition so as to merge by using the code block in the selected code branch; and if the suspected incompatible points in the two source codes are code blocks without actual conflicts, selecting any one code block from the suspected incompatible points to perform merging. By adoption of the technical scheme of the source code automatic merging method and apparatus, the problem of incompatibility of codes existing in source code merging is solved while the source code merging efficiency is also improved under the condition without depending on a merging tool to perform the source code merging.

Description

The automatic merging method of source code and source code merge device automatically
Technical field
The present invention relates to source code folding field, in particular to a kind of automatic merging method of source code and one Plant source code and automatically merge device.
Background technology
Software program development is usually team unity, and the realization of same function often relates to the source of a lot of different editions Code file, such as two developers develop same module.So, can when the source code of different editions is merged together Can there is conflict in the inconsistent phenomenon of some local generations.Current source code Merge Scenarios is mainly, by merging Instrument determines source code to be combined, the collision position in record source code merging process and modification time, according to conflict position The code block of the last modification is merged in source code to be combined confidence breath.If same source code is by different exploit persons Member's modification, and all have modified identical code block, code incompatible problem occurs when source code merges, now Source code merging work will be largely dependent upon manual intervention, reduce the efficiency of source code merging.
Therefore, the code how solving to occur when source code merges is incompatible, avoids manual intervention, thus improving source simultaneously The combined efficiency of code becomes technical problem urgently to be resolved hurrily.
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.
Brief description
Fig. 1 shows the schematic flow sheet of the automatic merging method of source code according to an embodiment of the invention;
Fig. 2 shows and according to an embodiment of the invention judges that whether doubtful incompatible point is essence according to keyword The schematic flow sheet of the upper code block that there is conflict;
Fig. 3 shows whether according to an embodiment of the invention be real according to the merging doubtful incompatible point of conditional judgment The schematic flow sheet of the code block of conflict is existed on matter;
Fig. 4 shows that source code according to an embodiment of the invention merges the structural representation of device automatically.
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.

Claims (12)

1. a kind of automatic merging method of source code is it is characterised in that include:
Find out the doubtful incompatible point in the source code of two different editions;
According to default compatibility condition, judge whether the described doubtful incompatible point in two described source codes is substantially to deposit Code block in conflict;
If the described doubtful incompatible point in two described source codes is the code block that there is essentially conflict, according to described simultaneous Capacitive condition selects code branch, is merged with the code block in the described code branch using selection;And
If the described doubtful incompatible point in two described source codes is the code block being created substantially absent conflict, select described Arbitrary code block in doubtful incompatible point merges.
2. the automatic merging method of source code according to claim 1 is it is characterised in that described find out two different editions Source code in the step of doubtful incompatible point include:
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.
3. the automatic merging method of source code according to claim 1 it is characterised in that
Described compatibility condition includes key word, merging patterns, the position of described doubtful incompatible point, code revision time, table Reach the combination of one or more of value of formula.
4. the automatic merging method of source code according to claim 3 is it is characterised in that include closing in described compatibility condition In the case of keyword, whether the described described doubtful incompatible point judging in two described source codes is to there is essentially conflict The step of code block, including:
If described doubtful incompatible point meets keyword query condition, judge described doubtful incompatible point as there is essentially punching Prominent code 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:Find first in one of described doubtful incompatible point code block Type key word, and find Second Type key word in another code block in described doubtful incompatible point;Or Described first kind key word is found in one of described doubtful incompatible point code block, and in described doubtful incompatible point In another code block in do not find described Second Type key word;Or in one of described doubtful incompatible point generation Find described Second Type key word in code block, in another code block in described doubtful incompatible point, do not find institute State first kind key word.
5. the automatic merging method of source code according to claim 3 is it is characterised in that include closing in described compatibility condition And in the case of pattern, whether the described described doubtful incompatible point judging in two described source codes is to there is essentially conflict Code block step, including:
Judge that the variable whether only having a code block in described doubtful incompatible point carries out display initialization;
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 that the variable of an only code block carries out display initialization in described doubtful incompatible point, then judge described There is return value inspection after the key sentence whether only having a code block in doubtful incompatible point;
If it is determined that having return value inspection after only having the key sentence of 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 only one code in described doubtful incompatible point There is return value inspection after the key sentence of block, then judge that described doubtful incompatible point is not the code block that there is essentially conflict.
6. the automatic merging method of source code according to any one of claim 1 to 5 is it is characterised in that described source code Automatically merging method also includes:
Detect whether described compatibility condition is correct;
If it is incorrect described compatibility condition is detected, point out compatibility condition described in user incorrect and/or prompting user Reset described compatibility condition.
7. a kind of source code merges device automatically it is characterised in that including:
Searching unit, for finding out the doubtful incompatible point in the source code of two different editions;
Judging unit, for according to default compatibility condition, judging the described doubtful incompatible point in two described source codes Whether it is the code block that there is essentially conflict;
Combining unit, if judge described doubtful incompatible point in two described source codes as substantially for described judging unit There is the code block of conflict, then code branch is selected according to described compatibility condition, with the described code branch using selection Code block merge;And
Described combining unit is additionally operable to, if described judging unit judge described doubtful incompatible point in two described source codes as It is created substantially absent the code block of conflict, then select the arbitrary code block in described doubtful incompatible point to merge.
8. source code according to claim 7 merges device automatically it is characterised in that described searching unit includes:
Contrast subunit, for the code content of row corresponding between the described source code of two different editions of contrast;
Determination subelement, if the code content contrasting described corresponding row for described contrast subunit differs, will be described The code content of corresponding row is as described doubtful incompatible point.
9. source code according to claim 7 automatically merge device it is characterised in that
Described compatibility condition includes key word, merging patterns, the position of described doubtful incompatible point, code revision time, table Reach the combination of one or more of value of formula.
10. source code according to claim 9 merges device automatically it is characterised in that including in described compatibility condition In the case of key word, described judging unit specifically for,
If described doubtful incompatible point meets keyword query condition, judge described doubtful incompatible point as there is essentially punching Prominent code 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:Find first in one of described doubtful incompatible point code block Type key word, and find Second Type key word in another code block in described doubtful incompatible point;Or Described first kind key word is found in one of described doubtful incompatible point code block, and in described doubtful incompatible point In another code block in do not find described Second Type key word;Or in one of described doubtful incompatible point generation Find described Second Type key word in code block, and do not find in another code block in described doubtful incompatible point Described first kind key word.
11. source codes according to claim 9 merge device automatically it is characterised in that including in described compatibility condition In the case of merging patterns, described judging unit 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 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 that the variable of an only code block carries out display initialization in described doubtful incompatible point, then judge described There is return value inspection after the key sentence whether only having a code block in doubtful incompatible point;
If it is determined that having return value inspection after only having the key sentence of 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 only one code in described doubtful incompatible point There is return value inspection after the key sentence of block, then judge that described doubtful incompatible point is not the code block that there is essentially conflict.
12. source codes according to any one of claim 7 to 11 automatically merge device it is characterised in that described source generation Code automatically merges device and also includes:
Whether detector unit is correct for detecting described compatibility condition;
Tip element, if it is incorrect described compatibility condition is detected for described detector unit, points out compatible described in user Property condition incorrect and/or prompting user reset described compatibility condition.
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 true CN106406918A (en) 2017-02-15
CN106406918B 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)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107329765A (en) * 2017-07-04 2017-11-07 武汉斗鱼网络科技有限公司 Program file processing method and processing device
CN109308253A (en) * 2017-07-27 2019-02-05 华为终端(东莞)有限公司 A kind of 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
CN111221566A (en) * 2019-12-28 2020-06-02 华为技术有限公司 Method and device for combining multiple and changeable versions of software code
CN113535206A (en) * 2021-07-23 2021-10-22 上海幻电信息科技有限公司 Multi-version code upgrading method and system

Citations (10)

* 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
US20140068564A1 (en) * 2012-09-04 2014-03-06 Opshub, Inc. System and method for merging results from multiple runs based on run inputs
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
US20150220332A1 (en) * 2014-02-05 2015-08-06 International Business Machines Corporation Resolving merge conflicts that prevent blocks of program code from properly being merged
CN105302533A (en) * 2014-07-25 2016-02-03 腾讯科技(深圳)有限公司 Code synchronizing method and apparatus

Patent Citations (10)

* 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
US20140068564A1 (en) * 2012-09-04 2014-03-06 Opshub, Inc. System and method for merging results from multiple runs based on run inputs
US20150220332A1 (en) * 2014-02-05 2015-08-06 International Business Machines Corporation Resolving merge conflicts that prevent blocks of program code from properly being merged
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
王维丽 等: ""离线模式下协同设计中对象版本的合并"", 《计算机应用》 *

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107329765A (en) * 2017-07-04 2017-11-07 武汉斗鱼网络科技有限公司 Program file processing method and processing device
CN107329765B (en) * 2017-07-04 2020-09-04 武汉斗鱼网络科技有限公司 Program file processing method and device
CN109308253A (en) * 2017-07-27 2019-02-05 华为终端(东莞)有限公司 A kind of code detection 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
CN111221566A (en) * 2019-12-28 2020-06-02 华为技术有限公司 Method and device for combining multiple and changeable versions of software code
WO2021128973A1 (en) * 2019-12-28 2021-07-01 华为技术有限公司 Combination method and apparatus for multiple change versions of software codes
CN111221566B (en) * 2019-12-28 2021-10-22 华为技术有限公司 Method and device for combining multiple and changeable versions of software code
US12001838B2 (en) 2019-12-28 2024-06-04 Huawei Cloud Computing Technology Co., Ltd. Method and apparatus for merging a plurality of software code change versions
CN113535206A (en) * 2021-07-23 2021-10-22 上海幻电信息科技有限公司 Multi-version code upgrading method and system

Also Published As

Publication number Publication date
CN106406918B (en) 2020-02-28

Similar Documents

Publication Publication Date Title
CN106406918A (en) Source code automatic merging method and apparatus
CN102521121B (en) Page testing method and page testing device
US7603393B1 (en) Software merging utility
WO2020215563A1 (en) Training sample generation method and device for text classification, and computer apparatus
US9632754B2 (en) Auto generation and linkage of source code to test cases
JP2007094753A (en) Logic extraction support device
JP4201701B2 (en) Synthesis of verification language
CN104268083B (en) Automatic software test method and device
JP2012208830A (en) Program test device, program test method and program
TW201321968A (en) Test method for handheld electronic device application
JP2015232847A (en) Detector, correction system, detection method and program
CN109101410A (en) A kind of risk driven test method and device and computer readable storage medium
CN105022692B (en) A kind of Deadlock Detection verification method
CN106815147A (en) A kind of test script generation method and device
Tsilionis et al. Unifying behavior driven development templates
McMaster et al. An extensible heuristic-based framework for gui test case maintenance
CN111651368B (en) User graphical interface testing method and computer readable storage medium
CN109783837A (en) Emulator, analogue system, emulation mode and simulated program
CN107861779A (en) Page object localization method and device, storage medium, electronic equipment
US20210117616A1 (en) Screen discrimination apparatus, screen discrimination method and program
Moghadam et al. Resolving conflict and dependency in refactoring to a desired design
TW201732648A (en) Source code error detection device and method thereof
CN109815152A (en) Program crashing type prediction method and system
JP2009169573A (en) Analysis result output device and analysis result output method
TWI676906B (en) Prompt method and computer system thereof

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

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

TR01 Transfer of patent right