CN113485744A - Code synchronization method and device - Google Patents

Code synchronization method and device Download PDF

Info

Publication number
CN113485744A
CN113485744A CN202110841289.XA CN202110841289A CN113485744A CN 113485744 A CN113485744 A CN 113485744A CN 202110841289 A CN202110841289 A CN 202110841289A CN 113485744 A CN113485744 A CN 113485744A
Authority
CN
China
Prior art keywords
code
branch
revision
conflict
synchronization
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.)
Pending
Application number
CN202110841289.XA
Other languages
Chinese (zh)
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.)
Industrial and Commercial Bank of China Ltd ICBC
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
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 Industrial and Commercial Bank of China Ltd ICBC filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202110841289.XA priority Critical patent/CN113485744A/en
Publication of CN113485744A publication Critical patent/CN113485744A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/72Code refactoring
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The present disclosure provides a code synchronization method, which may be used in the financial field or other fields, the method including: receiving a task trigger instruction, wherein the task trigger instruction indicates a target branch of code synchronization to be executed and indicates a source branch for code synchronization; acquiring a first code submission record of the source branch in a development process, and generating a first revision list according to the first code submission record; determining a branch code range for code synchronization according to the first revision list; and synchronizing the source branch code in the branch code range to the target branch code to obtain an updated code file. The present disclosure also provides a code synchronization apparatus, an electronic device, and a computer storage medium.

Description

Code synchronization method and device
Technical Field
The present disclosure relates to the field of software technologies, and in particular, to a code synchronization method and apparatus.
Background
With the continuous expansion of software scale, in order to achieve the purposes of orderly proceeding of projects and flexible release of demands, code branch models are gradually diversified, branch types and branch numbers are gradually increased, and how to efficiently perform code synchronization among different branches becomes a problem of increasing attention.
In the process of implementing the technical scheme disclosed by the invention, the inventor finds that in the related art, when code synchronization among different branches is carried out, developers are required to frequently carry out operations of cloning/updating a code base, carrying out branch synchronization, pushing a code to change to a remote base and the like, and the defects of high manual operation cost, easiness in influencing the local area and high error rate when the number of code branches is large exist.
Disclosure of Invention
One aspect of the present disclosure provides a code synchronization method, including: receiving a task trigger instruction, wherein the task trigger instruction indicates a target branch of code synchronization to be executed and indicates a source branch for code synchronization; acquiring a first code submission record of the source branch in a development process, and generating a first revision list according to the first code submission record; determining a branch code range for code synchronization according to the first revision list; and synchronizing the source branch code in the branch code range to the target branch code to obtain an updated code file.
Optionally, the obtaining a first code submission record of the source branch in a development process, and generating a first revision list according to the first code submission record, includes: and determining N revision positions of the source branch code in the development process and revision time associated with the ith revision position according to the first code submission record to obtain the first revision list, wherein N is a positive integer, i is any integer in an interval [1, N ], and the revision position is the row number of a revision line in the source branch code.
Optionally, the determining a branch code range for code synchronization according to the first revision list includes: taking the initial revision line number in the first revision list as the initial revision line number of the branch code range; taking the ending revision line number or the stable revision line number in the first revision list as the ending revision line number of the branch code range; wherein the stable revision line number is the latest revision line number released by the test pass or version in the source branch.
Optionally, the synchronizing the source branch code in the branch code range to the target branch code to obtain an updated code file includes: according to the branch attribute of the target branch, taking the latest code line number in the target branch as the initial code line number of code synchronization operation; and based on the determined initial code line number of the code synchronization operation, synchronizing the source branch code in the branch code range to the target branch code according to the revision timing sequence indicated by the first revision list, so as to obtain an updated code file.
Optionally, the method further comprises: identifying change conflict information in the source branch code and the target branch code; determining a conflict type occurring in the code synchronization process based on the change conflict information; and processing conflicts occurring in the code synchronization process by adopting a processing mode matched with the conflict type according to a conflict processing strategy indicated by the task trigger instruction, wherein the conflict type comprises file conflicts and tree conflicts.
Optionally, the method further comprises: determining, based on the change conflict information, whether a conflict code associated with the change conflict information is of an automatically mergeable type; and generating alarm notifications with different conflict levels according to whether the conflict codes belong to the automatic combination type and the submission stage of the conflict codes.
Optionally, after synchronizing the source branch code in the branch code range to the target branch code, the method further includes: acquiring a second code submission record in the code synchronization process, and generating a second revision list according to the second code submission record; extracting revision difference information in the first revision list and the second revision list; generating an alert notification for the revision difference information for a user to process the revision difference information.
Optionally, the code synchronization method is used for a Gerrit code management platform.
Another aspect of the present disclosure provides a code synchronization apparatus, including: the system comprises a receiving module, a processing module and a processing module, wherein the receiving module is used for receiving a task triggering instruction, and the task triggering instruction indicates a target branch of code synchronization to be executed and indicates a source branch for the code synchronization; the first processing module is used for acquiring a first code submission record of the source branch in the development process and generating a first revision list according to the first code submission record; the second processing module is used for determining a branch code range for code synchronization according to the first revision list; and the third processing module is used for synchronizing the source branch code in the branch code range to the target branch code to obtain an updated code file.
Optionally, the first processing module includes: and the first processing submodule is used for determining N revision positions and revision time associated with the ith revision position of the source branch code in the development process according to the first code submission record to obtain the first revision list, wherein N is a positive integer, i is any integer in an interval [1, N ], and the revision positions are the line numbers of revision lines in the source branch code.
Optionally, the second processing module includes: a second processing submodule, configured to use a start revision line number in the first revision list as a start revision line number of the branch code range; and the third processing submodule is used for taking the ending revision line number or the stable revision line number in the first revision list as the ending revision line number of the branch code range, wherein the stable revision line number is the latest revision line number passed by the test or released by the version in the source branch.
Optionally, the third processing module includes: the fourth processing submodule is used for taking the latest code line number in the target branch as the initial code line number of the code synchronization operation according to the branch attribute of the target branch; and the fifth processing submodule is used for synchronizing the source branch code in the branch code range to the target branch code according to the revision timing sequence indicated by the first revision list based on the determined initial code line number of the code synchronization operation to obtain an updated code file.
Optionally, the apparatus further includes a fourth processing module, where the fourth processing module includes a sixth processing sub-module, and is configured to identify change conflict information in the source branch code and the target branch code; a seventh processing submodule, configured to determine a conflict type occurring in a code synchronization process based on the change conflict information; and the eighth processing submodule is used for processing conflicts occurring in the code synchronization process by adopting a processing mode matched with the conflict type according to the conflict processing strategy indicated by the task trigger instruction, wherein the conflict type comprises file conflicts and tree conflicts.
Optionally, the apparatus further includes a fifth processing module, where the fifth processing module includes a ninth processing sub-module, configured to determine, based on the change conflict information, whether a conflict code associated with the change conflict information belongs to an automatically mergeable type; and the tenth processing submodule is used for generating alarm notifications with different conflict levels according to whether the conflict codes belong to the automatic combination type or not and according to the submission stage of the conflict codes.
Optionally, the apparatus further includes a sixth processing module, where the sixth processing module includes an eleventh processing sub-module, and is configured to obtain a second code submission record in the code synchronization process, and generate a second revision list according to the second code submission record; a twelfth processing sub-module, configured to extract revision difference information in the first revision list and the second revision list; a thirteenth processing sub-module for generating an alert notification for the revised difference information for a user to process the revised difference information.
Optionally, the device is integrated in a Gerrit code management platform.
Another aspect of the present disclosure provides an electronic device comprising one or more processors; memory for storing one or more programs, wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the methods of embodiments of the present disclosure.
Another aspect of the present disclosure provides a computer-readable storage medium storing computer-executable instructions that, when executed, implement the method of embodiments of the present disclosure.
Another aspect of the present disclosure provides a computer program product comprising computer readable instructions, wherein the computer readable instructions are configured to perform the code synchronization method of the embodiments of the present disclosure when executed.
Drawings
For a more complete understanding of the present disclosure and the advantages thereof, reference is now made to the following descriptions taken in conjunction with the accompanying drawings, in which,
FIG. 1 schematically illustrates a system architecture of a code synchronization method and apparatus according to an embodiment of the present disclosure;
FIG. 2 schematically illustrates a flow diagram of a method of code synchronization in accordance with an embodiment of the present disclosure;
FIG. 3 schematically illustrates a flow diagram of another method of code synchronization in accordance with an embodiment of the present disclosure;
FIG. 4 schematically illustrates a flow chart of yet another code synchronization method according to an embodiment of the present disclosure;
FIG. 5 schematically illustrates a flow chart of yet another code synchronization method according to an embodiment of the disclosure;
fig. 6 schematically illustrates an operational flow diagram of code synchronization using a Gerrit code management platform according to an embodiment of the present disclosure;
FIG. 7 schematically illustrates a block diagram of a code synchronization apparatus according to an embodiment of the present disclosure;
FIG. 8 schematically shows a block diagram of an electronic device according to an embodiment of the disclosure.
Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It is to be understood that such description is merely illustrative and not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. Moreover, in the following description, descriptions of well-known structures and techniques are omitted so as to not unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and the like, as used herein, specify the presence of stated features, operations, and/or components, but do not preclude the presence or addition of one or more other features, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It is noted that the terms used herein should be interpreted as having a meaning that is consistent with the context of this specification and should not be interpreted in an idealized or overly formal sense.
Where a convention analogous to "at least one of A, B and C, etc." is used, in general such a construction is intended in the sense one having skill in the art would understand the convention (e.g., "a system having at least one of A, B and C" would include but not be limited to systems that have a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.).
Some block diagrams and/or flow diagrams are shown in the figures. It will be understood that some blocks of the block diagrams and/or flowchart illustrations, or combinations thereof, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable code synchronization apparatus such that the instructions, which execute via the processor, create means for implementing the functions/acts specified in the block diagrams and/or flowchart block or blocks. The techniques of this disclosure may be implemented in hardware and/or software (including firmware, microcode, etc.). In addition, the techniques of this disclosure may take the form of a computer program product on a computer-readable storage medium having instructions stored thereon for use by or in connection with an instruction execution system.
The embodiment of the disclosure provides a code synchronization method and a processing device capable of applying the method. The method comprises the steps of firstly, receiving a task trigger instruction, wherein the task trigger instruction indicates a target branch of code synchronization to be executed and indicates a source branch for code synchronization, then, obtaining a first code submission record of the source branch in the development process, generating a first revision list according to the first code submission record, then, determining a branch code range for code synchronization according to the first revision list, and finally, synchronizing the source branch code in the branch code range to the target branch code to obtain an updated code file.
Fig. 1 schematically shows a system architecture of a code synchronization method and apparatus according to an embodiment of the present disclosure. It should be noted that fig. 1 is only an example of a system architecture to which the embodiments of the present disclosure may be applied to help those skilled in the art understand the technical content of the present disclosure, and does not mean that the embodiments of the present disclosure may not be applied to other devices, systems, environments or scenarios.
As shown in fig. 1, the system architecture 100 may include a project development side (a number of which are shown, such as project development sides 101, 102, 103), a network 104, and a code management platform 105, the network 104 being a medium for providing a communication link between the project development sides 101, 102, 103 and the code management platform 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few. The code management platform 105 may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud computing, network services, and middleware services, as an execution subject of the present scheme.
The code management platform 105 receives a task triggering instruction from an item development end (such as the item development end 101), the task triggering instruction indicates a target branch of code synchronization to be executed and indicates a source branch for code synchronization, then the code management platform 105 obtains a first code submission record of the source branch in the development process, generates a first revision list according to the first code submission record, then determines a branch code range for code synchronization according to the first revision list, and finally, the code management platform 105 synchronizes the source branch codes in the branch code range to the target branch codes in the item development end (such as the item development end 103) to obtain an updated code file.
It should be noted that the code synchronization method and apparatus of the embodiments of the present disclosure may be used in the financial field, and may also be used in any field other than the financial field. The present disclosure will be described in detail below with reference to the drawings and specific embodiments.
Fig. 2 schematically shows a flowchart of a code synchronization method according to an embodiment of the present disclosure, and as shown in fig. 2, the method 200 may include operations S210 to S240.
In operation S210, a task trigger instruction is received, the task trigger instruction indicating a target branch for code synchronization to be performed and indicating a source branch for code synchronization.
Next, in operation S220, a first code submission record of the source branch during development is obtained, and a first revision list is generated according to the first code submission record.
Next, in operation S230, a branch code range for code synchronization is determined according to the first revision list.
Next, in operation S240, the source branch code within the branch code range is synchronized to the target branch code, resulting in an updated code file.
The specific flow of each step of the code synchronization method of the present embodiment is described in detail below.
In operation S210, a task trigger instruction is received, the task trigger instruction indicating a target branch for code synchronization to be performed and indicating a source branch for code synchronization.
In the embodiment, specifically, a task triggering instruction from a project development end is received, the task triggering instruction includes a synchronization parameter of a triggered code synchronization task, and the synchronization parameter indicates a target branch for code synchronization to be performed and indicates a source branch for code synchronization. In addition, the synchronization parameter may also indicate information such as a code synchronization frequency, a code synchronization range, a synchronization result submission policy, a default conflict resolution policy, a custom conflict resolution policy, a conflict submission policy, and the like.
As a feasible way, a Gerrit plug-in for performing code synchronization is generated by using a plug-in generation method officially provided by Gerrit (a free, open code source code management platform), and a corresponding Http service function is established based on the Gerrit plug-in. Project developers can provide synchronous parameters such as version library names, target branch names, source branch names, conflict processing strategies and the like in a conventional interface calling mode, and initiate online code synchronous requests.
When a plurality of iterations exist in the same project and need to be developed, in order to reduce the code change influence among different iterations in the development process, a plurality of duplicate branches can be created on the basis of the main branch of the project development for development. In addition, the application products in the same project may include a general basic function and different personalized functions, the general basic function of the application product may be developed by using a main branch, and the personalized functions of the application product may be developed by using different replica branches. The source branch for code synchronization can be a duplicate branch in project development, so that the code change condition in the duplicate branch is guaranteed to be merged into the main branch in the branch development mode. In addition, the source branch used for code synchronization can also be a main branch in project development, and the integrity of the code of the duplicate branch is ensured by periodically synchronizing the code update in the main branch to the duplicate branch.
Next, in operation S220, a first code submission record of the source branch during development is obtained, and a first revision list is generated according to the first code submission record.
In this embodiment, specifically, the branch code generates a code submission record during the development process, and the code submission record describes code change information of the branch code. The method comprises the steps of obtaining a first code submission record generated by a source branch in the development process, more specifically, obtaining the first code submission record of the source branch in the development process after the source branch is synchronized with the latest code of a target branch, and determining code change information of the source branch in the development process based on the obtained first code submission record. Specifically, all revision positions of the source branch code in the corresponding development process are determined according to the first code submission record, and the revision time associated with each revision position is determined, so that a first revision list is obtained, wherein the revision position is the line number of a revision line in the source branch code.
Next, in operation S230, a branch code range for code synchronization is determined according to the first revision list.
In this embodiment, specifically, a branch code range for performing code synchronization to the target branch is determined according to the code change information of the source branch in the development process. And further, determining a code line number to be subjected to synchronous operation in the source branch code according to the code revision line number of the source branch in the corresponding development process.
When the code is subjected to normative check and complexity analysis, the code block is taken as the minimum logic unit. Thus, as a practical approach, it may be determined whether the code revision lines in the target branch are contiguous, and if so, the contiguous code revision lines are merged into a modified block, and if not, the code revision lines are marked directly as modified blocks. And when the source branch contains more than one revision code block, taking the initial code line in each revision code block as the initial code line of the branch code range, and taking the final code line in each revision code block as the final code line of the branch code range.
Next, in operation S240, the source branch code within the branch code range is synchronized to the target branch code, resulting in an updated code file.
In the present embodiment, specifically, according to the branch attribute of the target branch, the latest revision line in the target branch is taken as the starting revision line of the code synchronization operation. And pulling a target branch code file and a source branch code file from the project development terminal, and synchronizing the source branch code in the branch code range to the target branch code according to the determined initial revision line of the code synchronization operation and the determined branch code range for code synchronization so as to complete the code synchronization operation aiming at the target branch.
By the embodiment of the disclosure, a task trigger instruction is received, wherein the task trigger instruction indicates a target branch of code synchronization to be executed and indicates a source branch for code synchronization; acquiring a first code submission record of a source branch in a development process, and generating a first revision list according to the first code submission record; determining a branch code range for code synchronization according to the first revision list; and synchronizing the source branch code in the branch code range to the target branch code to obtain an updated code file. The design effectively overcomes the defects of low code synchronization efficiency and high manual operation cost caused by frequent operation of developers for code synchronization in the related technology, is beneficial to improving the code development progress, controls the error rate of code synchronization operation when the development branch number is large, and can effectively improve the version release efficiency of application products.
Fig. 3 schematically illustrates a flowchart of another code synchronization method according to an embodiment of the present disclosure, and as shown in fig. 3, the method 300 may include operations S210, S320 to S340.
In operation S210, a task trigger instruction is received, the task trigger instruction indicating a target branch for code synchronization to be performed and indicating a source branch for code synchronization.
Next, in operation S320, a first code submission record of the source branch in the development process is obtained, and according to the first code submission record, N revision positions of the source branch code in the development process and revision time associated with the ith revision position are determined, so as to obtain a first revision list, where N is a positive integer, i is an arbitrary integer within the interval [1, N ], and the revision position is a line number of a revision line in the source branch code.
Next, in operation S330, the start revision line number in the first revision list is used as the start revision line number of the branch code range for code synchronization, and the end revision line number or the stable revision line number in the first revision list is used as the end revision line number of the branch code range for code synchronization, wherein the stable revision line number is the latest revision line number of the test pass or version release in the source branch.
Next, in operation S340, according to the branch attribute of the target branch, the latest code line number in the target branch is used as the start code line number of the code synchronization operation, and based on the determined start code line number of the code synchronization operation, the source branch code in the branch code range is synchronized to the target branch code according to the revision timing indicated by the first revision list, so as to obtain an updated code file.
The specific flow of each step of the code synchronization method of the present embodiment is described in detail below.
In this embodiment, specifically, during development of the branch code, the project development end (e.g., the SVN system) may generate several code submission records for the branch code. And after the development of the branch code is finished, acquiring a code submission record of the branch code in the development process, and determining code change information of the branch code in the development process according to the code submission record. And acquiring a code submission record of the source branch in the development process after the last code synchronization with the target branch, namely acquiring a first code submission record of the source branch in the development process. Analyzing the first code submission record, and determining N revision positions of the source branch code in the corresponding development process and revision time associated with the ith revision position to obtain a first revision list, wherein N is a positive integer, i is any integer in the interval [1, N ], and the revision position is the line number of a revision line in the source branch code.
When determining the branch code range for code synchronization in the source branch, the start revision line number in the first revision list is taken as the start revision line number of the branch code range, and the end revision line number in the first revision list is taken as the end revision line number of the branch code range. In the development process of the branch code, different code change contents may be continuously introduced, and the code change contents continuously introduced cannot guarantee the normalization and the accuracy of the branch code. Thus, the latest revision line number after a test pass or version release in the source branch may be used as the stable revision line number in the source branch, and the stable revision line number in the source branch may be used as the ending revision line number for the branch code range.
In the default case, the latest code line number in the target branch is used as the initial code line number of the code synchronization operation, and in practical application, any code line number of the target branch can be specified according to the service requirement and used as the initial code line number of the code synchronization operation. Because the first revision list describes the revision time associated with each revision line in the source branch, the code content of each revision line in the branch code range is sequentially merged into the target branch code according to the revision time sequence indicated by the first revision list, and an updated code file is obtained.
After all code content in the branch code range is merged to the target branch, a code submission record for the code synchronization process is generated and submitted. In addition, the hash value of the code submission record can be obtained, and the hash value is returned to the business personnel at the project development end, so that the business personnel can trace the code synchronization process based on the hash value.
Fig. 4 schematically illustrates a flowchart of yet another code synchronization method according to an embodiment of the present disclosure, and as shown in fig. 4, the method 400 may further include operations S410 to S430 in addition to operations S210 to S240 (omitted from fig. 4).
In operation S410, change conflict information in the source branch code and the target branch code is identified.
Next, in operation S420, a type of conflict occurring in the code synchronization process is determined based on the change conflict information.
Next, in operation S430, according to the conflict handling policy indicated by the task triggering instruction, a handling manner matching the conflict type is adopted to handle conflicts occurring in the code synchronization process, where the conflict type includes a file conflict and a tree conflict.
The specific flow of each step of the code synchronization method of the present embodiment is described in detail below.
In this embodiment, specifically, the source branch code file and the target branch code file are pulled from the project development end, and the difference portion in the two branch code files is identified by traversing the source branch code file and the target branch code file, so as to obtain the change conflict information in the source branch code and the target branch code. The change conflict information includes, for example, conflicts caused by modifications to the same code line or adjacent code lines of the same code subfile by different developers in the same code subfile of the source branch and the target branch, or conflicts caused by moving, deleting, renaming operations to code lines or even code subfiles by different developers in the same code subfile of the source branch and the target branch.
And determining conflict types occurring in the code synchronization process based on the identified change conflict information, wherein the conflict types comprise file conflicts and tree conflicts, file conflicts are formed by conflicts caused by modifying the same code line or adjacent code lines of the same code subfile by different developers, and tree conflicts are formed by conflicts caused by moving, deleting and renaming the code lines or even the code subfiles by different developers.
And then, according to a conflict processing strategy indicated by the task trigger instruction, adopting a processing mode matched with the conflict type to process conflicts occurring in the code synchronization process. The conflict processing strategy comprises a default conflict processing strategy and a custom conflict processing strategy, and in practical application, the conflict processing strategy comprises an outputs strategy, a third strategy and a gitttribute strategy, wherein the outputs strategy is that under the condition that a conflict occurs in the code synchronization process, a conflict code takes a code version on a target branch as a reference, and the synchronization logic of non-conflict code segments is kept unchanged; the theirs policy is that under the condition that conflict occurs in the code synchronization process, the conflict code takes the code version on the source branch as the standard, and the synchronization logic of the non-conflict code segments is kept unchanged; the gittatribute file specifies the use of either the sources or the theirs policies for a certain code file, where the format of the gittatribute file is defined as follows: the file path merge is xxx, where xxx is a conflict handling policy and may have a value of either outputs or theirs.
Optionally, the synchronization parameter in the task trigger instruction may further include a conflict submission policy, and when it is determined that the conflict alert notification needs to be submitted according to the conflict submission policy, it may be determined whether a conflict code associated with the change conflict information belongs to an automatically mergeable type based on the change conflict information, and the alert notifications at different conflict levels are generated according to whether the conflict code belongs to the automatically mergeable type and the submission stage in which the conflict code is located. When the conflict code belongs to the type capable of being automatically merged, generating an alarm notice of a first level; when the conflict code belongs to the type which can not be automatically merged and is not submitted, generating an alarm notice of a second level; and when the conflict code belongs to the type which can not be automatically merged and is submitted, generating an alarm notice of a third level.
The alarm notification contains conflict related information, such as conflict code file path, conflict code content and line number, and last historical submission information of the conflict code in the target branch and the source branch. The alarm notifications in different levels are beneficial for developers to quickly master the code conflict situation, and the developers can conveniently track the code conflict information. By providing the on-line conflict automatic processing function, a developer does not need to perform conflict processing on the code files one by one in a local version library, so that the manual operation cost in the code synchronization process is reduced, the time consumption of the code synchronization operation is reduced, the code synchronization efficiency is greatly improved, and the error rate in the code synchronization process is reduced.
Fig. 5 schematically illustrates a flowchart of a further code synchronization method according to an embodiment of the present disclosure, and as shown in fig. 5, the method 500 may further include operations S510 to S530 in addition to operations S210 to S240 (omitted from fig. 5).
In operation S510, a second code submission record in the code synchronization process is acquired, and a second revision list is generated according to the second code submission record.
Next, revision difference information in the first revision list and the second revision list is extracted in operation S520.
Next, an alarm notification for the revised difference information is generated for the user to process the revised difference information in operation S530.
The specific flow of each step of the code synchronization method of the present embodiment is described in detail below.
In the present embodiment, specifically, the first revision list describes code change information of the source branch during development after the last code synchronization with the target branch, and the second revision list describes code change information of the target branch during code synchronization with the source branch. And comparing the first revision list with the second revision list to identify the difference part in the two revision lists. Specifically, in the process of comparing the first revision list and the second revision list, the same revision information therein is deleted, and the different revision information therein is extracted. And generating an alarm notification based on the difference revision information, and sending the alarm notification to a user for a developer to search and solve conflicts generated in the merging process, so that the error rate of the code synchronization process is reduced, and the problem of non-standard code synchronization process is solved.
Fig. 6 schematically illustrates an operation flow diagram of performing code synchronization by using a Gerrit code management platform according to an embodiment of the present disclosure, and as shown in fig. 6, the operation flow 600 includes operations S601 to S606.
In operation S601, a task trigger instruction initiated by a service caller is received.
The service caller (a third party system or a user) can initiate a service calling request to the Gerrit code management platform by writing interface calling code (for example, writing an httpparent interface calling toolkit by using Java language) or by using an interface calling tool (for example, using a Postman tool) to generate a task triggering instruction for a code synchronization task. The service caller needs to provide synchronization parameters such as version library name, source branch, target branch, etc. in the service call request. In addition, if the conflict needs to be automatically processed in the code synchronization process, the service caller needs to provide the conflict processing policy in the service call request.
Next, in operation S602, a code synchronization operation for the target branch is performed according to the synchronization parameter in the task trigger instruction, and a conflict occurring in the code synchronization process is automatically handled according to a conflict handling policy in the task trigger instruction.
And the Gerrit code management platform automatically performs code synchronization operation on the target branch of the specified version library based on the received task trigger instruction. And under the condition that the task trigger instruction contains conflict processing strategy parameters, automatically processing conflicts in the code synchronization process based on the conflict processing strategies, and returning contents such as conflict code information, solved conflict code information, unresolved conflict code information and the like to the service caller.
Next, in operation S603, it is determined whether there is a conflict in the code synchronization process that has not been automatically resolved.
If not, executing operation S604, continuing to execute the code synchronization operation, generating a code submission record after the code synchronization operation is completed, and returning the hash value of the code submission record to the service caller, ending the process.
If not, operation S605 is executed, the execution of the code synchronization operation is suspended, and unresolved conflicting code information is returned to the service caller. The conflict code information includes, for example, a conflict code file path, conflict code content and line number, and last past commit information of the conflict code in the target branch and the source branch.
Next, in operation S606, if the service caller initiates the synchronous service request again, or provides another conflict handling policy to attempt to continue resolving the conflict, operation S601 is entered, otherwise, the process ends.
By providing an Http service function, code synchronization operation can be completed in a Gerrit code management platform, and a user can automatically perform branch code synchronization of a version library without additionally deploying a server. The Gerrit code management platform is easily integrated into a third-party system by using a branch code synchronization service in a conventional interface calling mode, and code synchronization operation in a confluence development mode is easily realized.
Fig. 7 schematically shows a block diagram of a code synchronization apparatus according to an embodiment of the present disclosure.
As shown in fig. 7, the apparatus 700 includes a receiving module 701, a first processing module 702, a second processing module 703 and a third processing module 704.
The receiving module 701 is configured to receive a task triggering instruction, where the task triggering instruction indicates a target branch for code synchronization to be performed and indicates a source branch for code synchronization; the first processing module 702 is configured to obtain a first code submission record of the source branch in the development process, and generate a first revision list according to the first code submission record; a second processing module 703 for determining a branch code range for code synchronization according to the first revision list; the third processing module 704 is configured to synchronize the source branch code within the branch code range to the target branch code, so as to obtain an updated code file.
By the embodiment of the disclosure, a task trigger instruction is received, wherein the task trigger instruction indicates a target branch of code synchronization to be executed and indicates a source branch for code synchronization; acquiring a first code submission record of a source branch in a development process, and generating a first revision list according to the first code submission record; determining a branch code range for code synchronization according to the first revision list; and synchronizing the source branch code in the branch code range to the target branch code to obtain an updated code file. The design effectively overcomes the defects of low code synchronization efficiency and high manual operation cost caused by frequent operation of developers for code synchronization in the related technology, is beneficial to improving the code development progress, controls the error rate of code synchronization operation when the development branch number is large, and can effectively improve the version release efficiency of application products.
As a possible way, the first processing module includes: and the first processing submodule is used for determining N revision positions and revision time associated with the ith revision position of the source branch code in the development process according to the first code submission record to obtain a first revision list, wherein N is a positive integer, i is any integer in the interval [1, N ], and the revision position is the line number of a revision line in the source branch code.
As a possible way, the second processing module includes: the second processing submodule is used for taking the initial revision line number in the first revision list as the initial revision line number of the branch code range; and the third processing submodule is used for taking the ending revision line number or the stable revision line number in the first revision list as the ending revision line number of the branch code range, wherein the stable revision line number is the latest revision line number passed by the test or released by the version in the source branch.
As a possible way, the third processing module includes: the fourth processing submodule is used for taking the latest code line number in the target branch as the initial code line number of the code synchronous operation according to the branch attribute of the target branch; and the fifth processing submodule is used for synchronizing the source branch codes in the branch code range to the target branch codes according to the revision time sequence indicated by the first revision list based on the determined initial code line number of the code synchronization operation to obtain the updated code file.
As a feasible way, the device further comprises a fourth processing module, wherein the fourth processing module comprises a sixth processing submodule for identifying change conflict information in the source branch code and the target branch code; the seventh processing submodule is used for determining the conflict type in the code synchronization process based on the change conflict information; and the eighth processing submodule is used for processing conflicts occurring in the code synchronization process by adopting a processing mode matched with conflict types according to the conflict processing strategy indicated by the task trigger instruction, wherein the conflict types comprise file conflicts and tree conflicts.
As a feasible mode, the device further comprises a fifth processing module, wherein the fifth processing module comprises a ninth processing submodule for determining whether the conflict code associated with the change conflict information belongs to an automatic mergeable type based on the change conflict information; and the tenth processing submodule is used for generating alarm notifications with different conflict levels according to whether the conflict codes belong to the automatic combination type and the submission stage of the conflict codes.
As a feasible way, the device further comprises a sixth processing module, wherein the sixth processing module comprises an eleventh processing submodule, and is used for acquiring a second code submission record in the code synchronization process and generating a second revision list according to the second code submission record; the twelfth processing submodule is used for extracting revision difference information in the first revision list and the second revision list; and the thirteenth processing sub-module is used for generating an alarm notice aiming at the revision difference information so as to enable the user to process the revision difference information.
As a feasible mode, the device is integrated in a Gerrit code management platform.
It should be noted that, in the embodiments of the present disclosure, the implementation of the apparatus portion is the same as or similar to the implementation of the method portion, and is not described herein again.
Any of the modules according to embodiments of the present disclosure, or at least part of the functionality of any of them, may be implemented in one module. Any one or more of the modules according to the embodiments of the present disclosure may be implemented by being split into a plurality of modules. Any one or more of the modules according to the embodiments of the present disclosure may be implemented at least in part as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or may be implemented in any other reasonable manner of hardware or firmware by integrating or packaging the circuit, or in any one of three implementations, or in any suitable combination of any of the software, hardware, and firmware. Or one or more of the modules according to embodiments of the disclosure, may be implemented at least partly as computer program modules which, when executed, may perform corresponding functions.
For example, any number of the receiving module 701, the first processing module 702, the second processing module 703 and the third processing module 704 may be combined into one module to be implemented, or any one of them may be split into a plurality of modules. Alternatively, at least part of the functionality of one or more of these modules may be combined with at least part of the functionality of the other modules and implemented in one module. According to an embodiment of the present disclosure, at least one of the receiving module 701, the first processing module 702, the second processing module 703 and the third processing module 704 may be implemented at least partially as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or may be implemented by hardware or firmware in any other reasonable manner of integrating or packaging a circuit, or implemented by any one of three implementations of software, hardware and firmware, or implemented by a suitable combination of any of them. At least one of the receiving module 701, the first processing module 702, the second processing module 703 and the third processing module 704 may be at least partly implemented as a computer program module, which when executed may perform a corresponding function.
Fig. 8 schematically shows a block diagram of an electronic device 800 suitable for implementing a processing method and a processing arrangement according to embodiments of the disclosure. The electronic device 800 illustrated in fig. 8 is only an example and should not bring any limitations to the functionality or scope of use of the embodiments of the present disclosure.
As shown in fig. 8, an electronic device 800 according to an embodiment of the present disclosure includes a processor 801 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)802 or a program loaded from a storage section 808 into a Random Access Memory (RAM) 803. The processor 801 may include, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor and/or associated chipset, and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), among others. The processor 801 may also include onboard memory for caching purposes. The processor 801 may include a single processing unit or multiple processing units for performing different actions of the method flows according to embodiments of the present disclosure.
In the RAM 803, various programs and data necessary for the operation of the electronic apparatus 800 are stored. The processor 801, the ROM 802, and the RAM 803 are connected to each other by a bus 804. The processor 801 performs various operations of the method flows according to the embodiments of the present disclosure by executing programs in the ROM 802 and/or RAM 803. Note that the programs may also be stored in one or more memories other than the ROM 802 and RAM 803. The processor 801 may also perform various operations of method flows according to embodiments of the present disclosure by executing programs stored in the one or more memories.
Electronic device 800 may also include input/output (I/O) interface 805, input/output (I/O) interface 805 also connected to bus 804, according to an embodiment of the present disclosure. Electronic device 800 may also include one or more of the following components connected to I/O interface 805: an input portion 806 including a keyboard, a mouse, and the like; an output section 807 including a signal such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 808 including a hard disk and the like; and a communication section 809 including a network interface card such as a LAN card, a modem, or the like. The communication section 809 performs communication processing via a network such as the internet. A drive 810 is also connected to the I/O interface 805 as necessary. A removable medium 811 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 810 as necessary, so that a computer program read out therefrom is mounted on the storage section 808 as necessary.
According to embodiments of the present disclosure, method flows according to embodiments of the present disclosure may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable storage medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 809 and/or installed from the removable medium 811. The computer program, when executed by the processor 801, performs the above-described functions defined in the system of the embodiments of the present disclosure. The systems, devices, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
The present disclosure also provides a computer-readable storage medium, which may be contained in the apparatus/device/system described in the above embodiments; or may exist separately and not be assembled into the device/apparatus/system. The computer-readable storage medium carries one or more programs which, when executed, implement the method according to an embodiment of the disclosure.
According to embodiments of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example but is not limited to: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. For example, according to embodiments of the present disclosure, a computer-readable storage medium may include the ROM 802 and/or RAM 803 described above and/or one or more memories other than the ROM 802 and RAM 803.
Embodiments of the present disclosure also include a computer program product comprising a computer program containing program code for performing the method provided by the embodiments of the present disclosure, when the computer program product runs on an electronic device, the program code is configured to enable the electronic device to implement the method for detecting a file upload vulnerability provided by the embodiments of the present disclosure.
The computer program, when executed by the processor 801, performs the above-described functions defined in the system/apparatus of the embodiments of the present disclosure. The systems, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
In one embodiment, the computer program may be hosted on a tangible storage medium such as an optical storage device, a magnetic storage device, or the like. In another embodiment, the computer program may also be transmitted in the form of a signal on a network medium, distributed, downloaded and installed via communication section 809, and/or installed from removable media 811. The computer program containing program code may be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
In accordance with embodiments of the present disclosure, program code for executing computer programs provided by embodiments of the present disclosure may be written in any combination of one or more programming languages, and in particular, these computer programs may be implemented using high level procedural and/or object oriented programming languages, and/or assembly/machine languages. The programming language includes, but is not limited to, programming languages such as Java, C + +, python, the "C" language, or the like. The program code may execute entirely on the user computing device, partly on the user device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., through the internet using an internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The embodiments of the present disclosure have been described above. However, these examples are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Various alternatives and modifications can be devised by those skilled in the art without departing from the scope of the present disclosure, and such alternatives and modifications are intended to be within the scope of the present disclosure.

Claims (12)

1. A method of code synchronization, comprising:
receiving a task trigger instruction, wherein the task trigger instruction indicates a target branch of code synchronization to be executed and indicates a source branch for code synchronization;
acquiring a first code submission record of the source branch in a development process, and generating a first revision list according to the first code submission record;
determining a branch code range for code synchronization according to the first revision list;
and synchronizing the source branch code in the branch code range to the target branch code to obtain an updated code file.
2. The method of claim 1, wherein the obtaining a first code submission record of the source branch during development and generating a first revision list from the first code submission record comprises:
determining N revision positions and revision time associated with the ith revision position of the source branch code in the development process according to the first code submission record to obtain the first revision list,
wherein, N is a positive integer, i is any integer in the interval [1, N ], and the revision position is the line number of the revision line in the source branch code.
3. The method of claim 2, wherein said determining a range of branching codes for code synchronization from the first revision inventory comprises:
taking the initial revision line number in the first revision list as the initial revision line number of the branch code range;
taking the ending revision line number or the stable revision line number in the first revision list as the ending revision line number of the branch code range,
wherein the stable revision line number is the latest revision line number released by the test pass or version in the source branch.
4. The method of claim 3, wherein synchronizing source branch code within the branch code range to target branch code results in an updated code file comprising:
according to the branch attribute of the target branch, taking the latest code line number in the target branch as the initial code line number of code synchronization operation;
and based on the determined initial code line number of the code synchronization operation, synchronizing the source branch code in the branch code range to the target branch code according to the revision timing sequence indicated by the first revision list, so as to obtain an updated code file.
5. The method of claim 1, further comprising:
identifying change conflict information in the source branch code and the target branch code;
determining a conflict type occurring in the code synchronization process based on the change conflict information;
processing the conflict in the code synchronization process by adopting a processing mode matched with the conflict type according to the conflict processing strategy indicated by the task trigger instruction,
wherein the conflict types include file conflicts and tree conflicts.
6. The method of claim 5, further comprising:
determining, based on the change conflict information, whether a conflict code associated with the change conflict information is of an automatically mergeable type;
and generating alarm notifications with different conflict levels according to whether the conflict codes belong to the automatic combination type and the submission stage of the conflict codes.
7. The method of claim 1, after synchronizing source branch code within the branch code range to the target branch code, further comprising:
acquiring a second code submission record in the code synchronization process, and generating a second revision list according to the second code submission record;
extracting revision difference information in the first revision list and the second revision list;
generating an alert notification for the revision difference information for a user to process the revision difference information.
8. The method of any of claims 1 to 7, wherein the code synchronization method is for a Gerrit code management platform.
9. A code synchronization apparatus, comprising:
the system comprises a receiving module, a processing module and a processing module, wherein the receiving module is used for receiving a task triggering instruction, and the task triggering instruction indicates a target branch of code synchronization to be executed and indicates a source branch for the code synchronization;
the first processing module is used for acquiring a first code submission record of the source branch in the development process and generating a first revision list according to the first code submission record;
the second processing module is used for determining a branch code range for code synchronization according to the first revision list;
and the third processing module is used for synchronizing the source branch code in the branch code range to the target branch code to obtain an updated code file.
10. An electronic device, comprising:
one or more processors; and
a memory for storing one or more programs,
wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method of any of claims 1-8.
11. A computer readable storage medium having stored thereon executable instructions which, when executed by a processor, cause the processor to carry out the method of any one of claims 1 to 8.
12. A computer program product comprising a computer program which, when executed by a processor, implements the method of any one of claims 1 to 8.
CN202110841289.XA 2021-07-23 2021-07-23 Code synchronization method and device Pending CN113485744A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110841289.XA CN113485744A (en) 2021-07-23 2021-07-23 Code synchronization method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110841289.XA CN113485744A (en) 2021-07-23 2021-07-23 Code synchronization method and device

Publications (1)

Publication Number Publication Date
CN113485744A true CN113485744A (en) 2021-10-08

Family

ID=77943487

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110841289.XA Pending CN113485744A (en) 2021-07-23 2021-07-23 Code synchronization method and device

Country Status (1)

Country Link
CN (1) CN113485744A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114661339A (en) * 2022-05-26 2022-06-24 浙江所托瑞安科技集团有限公司 Method and device for automatically submitting local data to remote server
CN116226066A (en) * 2023-04-28 2023-06-06 京东科技控股股份有限公司 Low code platform code synchronization method and device, electronic equipment and storage medium

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114661339A (en) * 2022-05-26 2022-06-24 浙江所托瑞安科技集团有限公司 Method and device for automatically submitting local data to remote server
CN116226066A (en) * 2023-04-28 2023-06-06 京东科技控股股份有限公司 Low code platform code synchronization method and device, electronic equipment and storage medium
CN116226066B (en) * 2023-04-28 2023-09-01 京东科技控股股份有限公司 Low code platform code synchronization method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
US10331440B2 (en) Effective defect management across multiple code branches
US9483284B2 (en) Version compatibility determination
US9454363B1 (en) Mobile application development system and method
US8495612B2 (en) Systems and methods for upgrading a version of software
US20120180024A1 (en) Synchronizing development code and deployed executable versioning within distributed systems
US10416973B2 (en) Analysis of source code for deployment
US10877846B2 (en) Performing a closure merge operation
CN113485744A (en) Code synchronization method and device
US20200004528A1 (en) Formalized propagation and approval of code changes in a tightly coupled environment
US10255065B1 (en) Automatically building software projects
CN110990023A (en) aar file dependency uploading method and device, storage medium and electronic equipment
CN111338944B (en) Remote Procedure Call (RPC) interface testing method, device, medium and equipment
US9436460B2 (en) Regression alerts
US9075679B1 (en) Creating a prerequisite checklist corresponding to a software application
CN110580216B (en) Application lifting method and device
US9396239B2 (en) Compiling method, storage medium and compiling apparatus
CN115543967A (en) Data migration method and device, electronic equipment and computer readable medium
CN115167822A (en) Branch code merging method, device, equipment and storage medium
CN114721943A (en) Method and device for determining test range
CN111382057A (en) Test case generation method, test method and device, server and storage medium
US11775291B2 (en) Automated updates to code deployment pipelines
US20240012636A1 (en) Git-based delta rpm
CN115993981A (en) Data processing method, device, electronic equipment and computer readable medium
CN117435203A (en) Code synchronization method, device, apparatus, storage medium, and program
CN113094083A (en) Version construction method, version construction device, electronic equipment and readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination