Code repeatability detection method and related device

By detecting code duplication before local code submission and before merging, and using dependency package tools to compare file types and generate visual reports, this technology solves the problems of limited code duplication detection and merging risks in existing technologies, thereby improving development efficiency and code quality.

CN121387699APending Publication Date: 2026-01-23AGRICULTURAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511728830.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-24
Publication Date
2026-01-23

AI Technical Summary

Technical Problem

Existing technologies for code duplication detection suffer from limitations such as single-angle detection, reliance on functional comments, and unreasonable detection timing. This leads to difficulties in manual review, high risks of code merging, and an inability to effectively reduce the problem of duplicate interface definitions when multiple developers are involved.

Method used

By obtaining a list of modified files based on status monitoring commands, identifying file types, and calling the corresponding duplication detection tools, a duplication detection report is generated. The detection is performed before local code commits and before merging. The dependency package tool is used to compare the abstract syntax tree and style file content to generate a visual report.

Benefits of technology

It enables real-time detection of code duplication before local code submission and merging, reducing code duplication for developers, guiding them to handle duplicate parts, and improving development efficiency and code quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121387699A_ABST
    Figure CN121387699A_ABST
Patent Text Reader

Abstract

The invention discloses a code repetition detection method and a related device, relates to the field of software development, and can obtain an online or local modified file list based on a state monitoring instruction. And identifying the type of each code file in the changed file list to obtain the file type of each code file. And according to a repetition degree detection strategy corresponding to the file type, detecting repeated contents of the code file and the target code file to obtain repetition detection result data representing the repeated contents of the code file. And finally, summarizing the repeated detection result data according to a preset generation template to obtain a repetition degree detection report. According to the method, checking can be carried out before local codes are submitted, and the code repetition degree of code changing of developers can be reduced so as to extract or quote public files in advance. And the codes are compared with the target branch codes before being merged, so that developers can be guided to process repeated parts, and the code repetition degree of front-end projects is reduced to a greater extent.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of software development, and particularly relates to a code repetition detection method and a related device. BACKGROUND

[0002] With the rapid development of Internet technology, various applications and systems are emerging in an endless stream. Software functions and version iterations are also becoming more and more frequent. Therefore, software development companies are paying more and more attention to the testing link to ensure the stability of software iteration. At present, various testing technologies have been mature and are implemented by relevant testers. For developers, it is necessary to ensure the robustness and easy modification of the code. The code repetition rate is an important indicator. The higher the value, the more time and effort it takes to maintain and update the code. In addition, a high code repetition rate will also increase the packaging time and loading time of the project. Therefore, how to detect the repetition of the code to assist developers in optimizing the code has become a problem to be solved. SUMMARY

[0003] In view of the above problems, the present application provides a code repetition detection method and related device to achieve the purpose of improving development efficiency. The specific scheme is as follows:

[0004] The first aspect of the present application provides a code repetition detection method, comprising:

[0005] Based on the state monitoring instruction, an online or local change file list is obtained;

[0006] The types of each code file in the change file list are identified to obtain the file type of each code file;

[0007] According to the repetition detection strategy corresponding to the file type, the repeated content of the code file and the target code file is detected to obtain the repetition detection result data representing the repeated content of the code file, and the target code file is a file with the same type as the code file in the online database or the local database;

[0008] Each repetition detection result data is summarized according to a preset generation template to obtain a repetition detection report.

[0009] In a possible implementation, the code repetition detection method comprises:

[0010] The type of the state monitoring instruction is identified. If the type of the state monitoring instruction is a local state monitoring, the local change file list is obtained from the local database;

[0011] If the type of the state monitoring instruction is online state monitoring, the list of changed files online is obtained from an online database.

[0012] In a possible implementation, when the file type is an interface registration file, the repeated content of the code file and the target code file is detected according to the repetition detection strategy corresponding to the file type, to obtain repetition detection result data representing the repeated content of the code file, including:

[0013] The first dependency package tool is called to convert the code file and the target code file into corresponding abstract syntax trees respectively;

[0014] The second dependency package tool is called to traverse and compare the two abstract syntax trees, to determine the same interface registration information and perform corresponding recording.

[0015] In a possible implementation, when the file type is a component file, the repeated content of the code file and the target code file is detected according to the repetition detection strategy corresponding to the file type, to obtain repetition detection result data representing the repeated content of the code file, including:

[0016] The code repetition detection tool is called to detect the repetition of the code file and the target code file, and when the repetition is not less than a first set threshold, the repeated code is recorded.

[0017] In a possible implementation, when the file type is a style file, the repeated content of the code file and the target code file is detected according to the repetition detection strategy corresponding to the file type, to obtain repetition detection result data representing the repeated content of the code file, including:

[0018] The third dependency package tool is called to detect the repetition of the file content corresponding to the target label in the code file and the target code file, and when the repetition is not less than a second set threshold, the repeated code is recorded.

[0019] In a possible implementation, the repeated content of the code file and the target code file is detected according to the repetition detection strategy corresponding to the file type, to obtain repetition detection result data representing the repeated content of the code file, and the method further includes:

[0020] If the function in the first content in the code file does not exist or is not called in the second content, the code file is split according to the first content and the second content, and corresponding tools are called to perform repetition detection, the first content is the content corresponding to the first label, and the second content is the content corresponding to the second label.

[0021] In a possible implementation, the code duplication detection method further includes:

[0022] detecting comment information in the code file, and when the comment information exists, no longer performing duplication detection on a code part associated with the comment information.

[0023] The second aspect of the present application provides a code duplication detection apparatus, including:

[0024] a changed file acquisition module configured to acquire a changed file list online or locally based on a state monitoring instruction;

[0025] a file type determination module configured to identify a type of each code file in the changed file list to obtain a file type of each code file;

[0026] a duplication result determination module configured to perform detection on duplication content of the code file and a target code file according to a duplication detection strategy corresponding to the file type to obtain duplication detection result data representing the duplication content of the code file, the target code file being a file of the same type as the code file in an online database or a local database; and

[0027] a duplication result summarization module configured to summarize each duplication detection result data according to a preset generation template to obtain a duplication detection report.

[0028] The third aspect of the present application provides a computer program product, including computer readable instructions, when the computer readable instructions run on an electronic device, the electronic device implements the code duplication detection method of the first aspect or any implementation manner of the first aspect.

[0029] The fourth aspect of the present application provides an electronic device, including at least one processor and a memory connected with the processor, wherein:

[0030] The memory is configured to store a computer program;

[0031] The processor is configured to execute the computer program, so that the electronic device can implement the code duplication detection method of the first aspect or any implementation manner of the first aspect.

[0032] The fifth aspect of the present application provides a computer storage medium, the storage medium carries one or more computer programs, when the one or more computer programs are executed by an electronic device, the electronic device can implement the code duplication detection method of the first aspect or any implementation manner of the first aspect.

[0033] By means of the technical solutions, the code repetition detection method provided by the application can obtain an online or local changed file list based on a state monitoring instruction. The types of each code file in the changed file list are identified to obtain the file type of each code file. According to a repetition detection strategy corresponding to the file type, the repeated contents of the code file and a target code file are detected to obtain repetition detection result data representing the repeated contents of the code file. Finally, each repetition detection result data is summarized according to a preset generation template to obtain a repetition detection report. The code repetition detection method can be used to check the code before the code is submitted locally, can reduce the code repetition of the code changed by the developer, and can extract or reference a public file in advance. The code is compared with target branch code before the code is merged, which can reduce the code difference between the submitted code and the target branch. The code repetition detection method can guide the developer to process the repeated part, and thus can greatly reduce the code repetition of the front-end project. BRIEF DESCRIPTION OF DRAWINGS

[0034] The above and other features, advantages, and aspects of the present disclosure will become more apparent by describing in detail the following specific embodiments thereof with reference to the attached drawings. Throughout the drawings, the same or similar reference numerals refer to the same or similar elements. It should be understood that the drawings are schematic, and the sizes of the components and elements are not necessarily drawn to scale.

[0035] Figure 1 An architecture diagram of a code repetition detection system provided by the application;

[0036] Figure 2 A flowchart of a code repetition detection method provided by the application;

[0037] Figure 3 An implementation process diagram of a code repetition detection method provided by the application;

[0038] Figure 4 A structure diagram of a code repetition detection device provided by the application;

[0039] Figure 5 A structure diagram of an electronic device provided by the application. DETAILED DESCRIPTION

[0040] The embodiments of the application are described below with reference to the accompanying drawings. The terms used in the embodiment part of the application are only used to explain the specific embodiments of the application, and are not intended to limit the application.

[0041] The embodiments of the application are described below with reference to the accompanying drawings. Those skilled in the art can know that, as technology develops and new scenarios appear, the technical solutions provided by the embodiments of the application are also applicable to similar technical problems.

[0042] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms are interchangeable where appropriate; this is merely a way of distinguishing objects with the same attributes in the embodiments of this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, so that a process, method, system, product, or apparatus that comprises a series of elements is not necessarily limited to those elements but may include other elements not explicitly listed or inherent to those processes, methods, products, or apparatuses.

[0043] See Figure 1 , Figure 1 A schematic diagram of the architecture of a code duplication detection system is shown. The system may include a terminal 100 and a server 200. The server 200 can provide the code duplication detection method provided in this embodiment to one or more terminals.

[0044] The terminal 100 may have a code duplication detection application installed. The application and webpage can provide an interface. The terminal 100 can receive relevant parameters input by the user on the code duplication detection interface and send the parameters to the server 200. The server 200 can obtain the processing result based on the received parameters and return the processing result to the terminal 100.

[0045] The following description Figure 1 The product form of the mid-terminal 100;

[0046] The terminal 100 in this application embodiment can be a tablet computer, a laptop computer, an ultra-mobile personal computer (UMPC), etc., and this application embodiment does not impose any restrictions on it.

[0047] Terminal 100 may include a radio frequency unit, memory, input unit, display unit, camera (optional), audio circuitry (optional), speaker (optional), microphone (optional), headphone jack (optional), processor, external interface, power supply, and other components. Those skilled in the art will understand that the above-mentioned components are merely examples and do not constitute a limitation on the terminal or multifunctional device; it may include more or fewer components, or a combination of certain components, or different components.

[0048] The input unit can be configured to receive inputted digital or character information, and to generate key signal inputs related to user settings and function controls of the portable multifunctional device. Specifically, the input unit can include a touch screen (optional) and / or other input devices. Specifically, the other input devices can include, but are not limited to, one or more of a physical keyboard, function keys (such as volume control buttons, switch buttons, etc.), a trackball, a mouse, a joystick, etc.

[0049] The input device can receive inputted data, etc.

[0050] The display unit can be configured to display information inputted by a user or provided to the user, various menus of the terminal, an interactive interface, file display, and / or playing of any kind of multimedia file. In embodiments of the present application, the display unit can be configured to display an interface for code repetition detection, processing results, etc.

[0051] The memory can be configured to store software code related to the code repetition detection method, and the processor can execute steps of the code repetition detection method, and can also dispatch other units (such as the input unit and the display unit) to implement corresponding functions.

[0052] The radio frequency unit (optional) can be configured to receive and send signals in the process of receiving or sending information or calls.

[0053] In embodiments of the present application, the radio frequency unit can send data to the server 200, and receive processing results sent by the server 200.

[0054] It should be understood that the radio frequency unit is optional, and can be replaced by other communication interfaces, such as a network interface.

[0055] The terminal 100 further includes a power supply (such as a battery) for supplying power to each component.

[0056] The terminal 100 further includes an external interface, which can be a standard Micro USB interface, or can be a multi-pin connector, and can be configured to connect the terminal 100 with other devices for communication, or can be configured to connect a charger to charge the terminal 100.

[0057] The server 200 includes a bus, a processor, a communication interface, and a memory. The processor, the memory, and the communication interface communicate with each other through the bus.

[0058] The memory can be configured to store software code related to the code repetition detection method, and the processor can execute steps of the code repetition detection method of the chip, and can also dispatch other units to implement corresponding functions.

[0059] The current code duplication detection mainly considers the code duplication problem from a single angle. The code duplication detection relies on the function annotation, and the difference between the related codes is not distinguished and displayed, which increases the difficulty of manual review. In addition, the detection timing is before release, but changing the code before packaging and releasing the test completed code is risky and may cause production problems. In addition, when multiple people develop at the same time, if the local project of the developer is used as a reference, the problem of repeated definition of interfaces cannot be solved as long as the developer is not synchronized with the code of others. If the tool updates the code in real time, it may introduce program errors or cause code conflict problems, which will also affect the development efficiency of the developer.

[0060] To solve the above problems, the code duplication detection method provided by the embodiments of the present application is provided. The code duplication detection method of the embodiments of the present application will be described in detail below with reference to the accompanying drawings.

[0061] Reference Figure 2 , Figure 2 The flow of the code duplication detection method provided by the embodiments of the present application is shown in FIG. 1. The code duplication detection method provided by the embodiments of the present application can include steps S201 to S204, which will be described in detail below. Figure 2

[0062] S201, based on a state monitoring instruction, obtaining an online or local change file list.

[0063] Specifically, the detection timing of the code duplication can be set in two places, one is before the local code is submitted (i.e. pre-commit), and the other is before the local code is merged into the target branch (i.e. pre-receive). The former is to reduce the unnecessary code duplication when the developer changes the code. The latter is to consider the scenario of multiple people developing: the timing of each person submitting the code is very random, but the code merging is in sequence. Therefore, checking before the code is merged into the target branch can ensure that the newly added code is compared with the latest code of the target branch. In this way, the code duplication between different developers can be reduced, and the code duplication of the project can be ensured within a controllable range.

[0064] The state monitoring instruction here can be a git command. The corresponding instruction can be executed according to the type of the state monitoring instruction, for example: if the type of the state monitoring instruction is local state monitoring, the local change file list is obtained from the local database. If the type of the state monitoring instruction is online state monitoring, the online change file list is obtained from the online database.

[0065] ​When using the corresponding git command, the detection before the local code submission can be performed by executing the git status command, and the detection before the merging can be performed by executing the git diff command to obtain the corresponding change file list.

[0066] S202, identify the type of each code file in the change file list to obtain the file type of each code file.

[0067] Specifically, after obtaining the change file list, the type of the change file in the change file list needs to be identified, which mainly includes interface registration file, component file, style file, etc.

[0068] The interface registration file is mainly to prevent the same interface url from being registered multiple times. In order to accurately extract information from this type of file, certain rules can be defined for the project files, such as placing the corresponding interface registration file in the same folder, or when collecting by module, it can be placed in a file named api. Once the user adds or modifies a file under the corresponding folder, the type of the file is determined as an api file.

[0069] The component file is to improve the reusability of the component as much as possible. In order to compare the component file more accurately, certain rules can be defined for the application project, such as defining the component file between files under the folder named components. When the content under the corresponding folder changes, file comparison needs to be performed.

[0070] The style file is mainly to reduce the repetition of style definition, which can be a pure style file such as css or scss, or the content in the style tag of the vue file. The public pure style file can be placed in the folder named assets. Once the file under the folder changes, only the style file under the folder is compared, and all pure style files in the project are not compared. This is because the front-end developer can see the page effect in real time during programming. At this time, the global style information is effective. Only when the style does not achieve the expected effect, the style writing will be performed. The style stored in the module generally serves the respective module. Of course, it is also possible to compare all the style files in the project, and related configuration parameters can be provided in the command for executing the script.

[0071] S203, according to the repetition detection strategy corresponding to the file type, detecting the repeated content of the code file and the target code file to obtain the repeated detection result data representing the repeated content of the code file, and the target code file is a file with the same type as the code file in the online database or the local database.

[0072] Specifically, by repeating the detection of the file type as needed, the corresponding repetition detection tool is called to perform corresponding repetition detection on the same type of file in the local database or online database, and the corresponding repetition detection result is obtained.

[0073] S204, the repetition detection result data is summarized according to the preset template, and the repetition detection report is obtained.

[0074] Finally, the obtained repetition detection results are summarized, and the information can be integrated in json format. The summarized information only needs to be transmitted to the specified HTML generation template, and the corresponding report generation operation is completed by the script execution generation instruction.

[0075] The code repetition detection method can intervene in the code repetition rate check from two occasions. The check before the local code is submitted can reduce the code repetition degree of the code changed by the developer this time, so as to extract or reference the public file in advance. The comparison with the target branch code before the code is merged can reduce the code difference degree between the submitted code and the target branch. If the target branch already exists corresponding code, the code can be modified to reduce the code repetition degree.

[0076] In some embodiments, when the file type is an interface registration file, the repetition detection strategy corresponding to the file type is used to detect the repeated content of the code file and the target code file, and the repetition detection result data representing the repeated content of the code file is obtained, including:

[0077] The first dependency package tool is called to convert the code file and the target code file into corresponding abstract syntax trees;

[0078] The second dependency package tool is called to traverse and compare the two abstract syntax trees, determine the same interface registration information, and record accordingly.

[0079] Specifically, for the analysis of the interface registration file, the two dependency packages @babel / parser and @babel / traverse are used. Once the same interface registration information (here mainly refers to the consistent interface url and request method) is detected in the changed file and the existing file, the information is recorded. @babel / parser and @babel / traverse: both are npm packages and can be used together. The former is used to convert the source code into the corresponding AST abstract syntax tree, and the latter is used to traverse and modify the input AST abstract syntax tree.

[0080] When the file type is a component file, the above repetition detection strategy corresponding to the file type is used to detect the repeated content of the code file and the target code file to obtain repetition detection result data representing the repeated content of the code file, which can specifically include:

[0081] The code repetition detection tool is called to detect the repetition of the code file and the target code file, and the repeated code is recorded when the repetition is not less than the first set threshold. When the file repetition reaches the predetermined threshold, information is recorded.

[0082] Specifically, for component files, the jscpd npm package can be used to compare the repetition of this type of vue file. Jscpd is an open-source code duplication detection tool that finds duplicate parts in code and generates corresponding reports. It supports various full-stack frameworks and languages, including HTML, CSS, Javascript, Vue, and other formats.

[0083] When the file type is a style file, the above repetition detection strategy corresponding to the file type is used to detect the repeated content of the code file and the target code file to obtain repetition detection result data representing the repeated content of the code file, which can specifically include:

[0084] The third dependent package tool is called to detect the repetition of the file content corresponding to the target tag in the code file and the target code file, and the repeated code is recorded when the repetition is not less than the second set threshold.

[0085] Specifically, for non-component vue files, only the style content is compared because of some characteristics of computer-side front-end projects. For example, the PC side of a management system often has a combination of search items and tables. If the template tag and script tag contents of the vue file are compared, there will be more repetition, which is not necessary for developers to pay attention to during code review. Therefore, only the style tag content of such vue files can be compared. Once the threshold is reached, information needs to be recorded, and then the developer determines whether to extract common styles.

[0086] When comparing, the corresponding dependent package can be used for comparison.

[0087] In some embodiments, considering that sometimes developers will cut the page code, and there may be unused functions are not deleted clean, so the user modified vue file needs to be processed additionally. At this time, the above-mentioned repeated detection strategy according to the file type corresponds to the repeated content detection of the code file and the target code file to obtain the repeated detection result data representing the repeated content of the code file, which can also specifically include:

[0088] If the function in the first content in the code file does not exist or is not called in the second content, the code file is segmented according to the first content and the second content, and the corresponding tool is called for repeated detection. The first content is the content corresponding to the first label, and the second content is the content corresponding to the second label.

[0089] Specifically, the user modified vue file is processed additionally. When the function extracted in the script tag of the vue file does not exist in the template or is not called in the function, the information needs to be recorded, and then processed by the developer. For this part of the processing, the vue processing method is used. First, the vue file is code segmented, the content in the template tag is processed by the vue-template-compiler dependency package, and the content in the script tag is processed by the babel dependency package mentioned in the above embodiment. The vue-template-compiler is an npm package that can be used for vue template parsing operation. The corresponding AST abstract syntax tree is returned after the template is input, and comparison is performed based on the corresponding abstract syntax tree.

[0090] Taking the vue-template-compiler parsing result as an example:

[0091]

[0092] One of the use cases of the function in the template tag is as a response function of a certain event of the tag. This case will be recorded in the events field. The specific value of the events field is [Object], and the object name is the specific event name. The value field in the corresponding value is the function name. By extracting the relevant information, if there is an unused function, it will be recorded.

[0093] In another embodiment, to facilitate the recording operation of the developer, the annotation information in the code file is detected, and when the annotation information exists, the repeated detection of the code part associated with the annotation information is not performed.

[0094] Specifically, all recorded information is displayed in a visual form for the user to view and process. For the part of code duplication checking using jscpd, the user can choose not to process. At this time, the developer only needs to add corresponding comment information in the code. The subsequent scanning will ignore this part and no longer perform code comparison. At the same time, in order to record and enable the code reviewer to clearly understand the reason for the developer's action, during the script parsing process before local code submission, once the corresponding comment information is found, it will check whether the required other information, i.e., the operator and the acceptance reason, exists in the adjacent node. Once the developer does not add these two pieces of information at the same time as adding the comment, it will be recorded as an error information.

[0095] Finally, the information obtained by each operation is summarized to generate a corresponding detection report. Since jscpd can directly generate a detection report, but can return in html or json format, the patent needs to set the return format of the report to json format, and then integrate the information according to the needs. The summarized information only needs to be transmitted into the specified HTML generation template, and the script execution generation instruction is completed to generate the corresponding report generation operation.

[0096] As a specific implementation process of the above code duplication detection method, with reference to Figure 3 , taking the detection before local code submission as an example, the changed file list is obtained by executing the git status command, and then the corresponding changed file type judgment is performed.

[0097] For js files (i.e., interface registration files), when the corresponding interface file is judged to exist, it is judged by executing the parsing script whether there is repeated registration information, and is recorded.

[0098] For component files (i.e., other vue files) other than interface registration files and style files, through the identification of component files, when the component file is identified, the script is used to detect the repeated code, and further judge whether there is a function that has not been deleted. For non-component files, the repeated degree detection can be performed by extracting the corresponding content of the style tag.

[0099] Similarly, for style files, the corresponding repeated degree comparison can be performed by the corresponding parsing script, and finally the corresponding detection report is generated.

[0100] The above introduces a code duplication detection method provided by the embodiment of the application. The device for executing the above code duplication detection method will be introduced below.

[0101] Please refer to Figure 4 , Figure 4 is a structural schematic diagram of a code duplication detection device provided by the embodiment of the application. As shown inFigure 4 As shown, the code duplication detection apparatus comprises:

[0102] The change file acquisition module 401 is configured to acquire a change file list online or locally based on the state monitoring instruction.

[0103] The file type determination module 402 is configured to identify the type of each code file in the change file list to obtain the file type of each code file.

[0104] The duplication result determination module 403 is configured to detect the duplicated content of the code file and a target code file according to a duplication detection strategy corresponding to the file type to obtain duplication detection result data representing the duplicated content of the code file, the target code file being a file of the same type as the code file in an online database or a local database.

[0105] The duplication result summary module 404 is configured to summarize each duplication detection result data according to a preset generation template to obtain a duplication detection report.

[0106] In a possible implementation, the process in which the change file acquisition module 401 acquires the change file list online or locally based on the state monitoring instruction comprises:

[0107] Identifying the type of the state monitoring instruction, if the type of the state monitoring instruction is local state monitoring, acquiring the change file list locally from a local database.

[0108] If the type of the state monitoring instruction is online state monitoring, acquiring the change file list online from an online database.

[0109] In a possible implementation, when the file type is an interface registration file, the process in which the duplication result determination module 403 detects the duplicated content of the code file and a target code file according to a duplication detection strategy corresponding to the file type to obtain duplication detection result data representing the duplicated content of the code file comprises:

[0110] Calling a first dependency package tool to convert the code file and the target code file into corresponding abstract syntax trees respectively.

[0111] Calling a second dependency package tool to traverse and compare the two abstract syntax trees to determine the same interface registration information and make corresponding records.

[0112] In a possible implementation, when the file type is a component file, the process in which the duplication result determination module 403 detects the duplicated content of the code file and a target code file according to a duplication detection strategy corresponding to the file type to obtain duplication detection result data representing the duplicated content of the code file comprises:

[0113] The code duplication detection tool is invoked to detect the duplication of the code file and the target code file, and the duplicated code is recorded when the duplication is not less than the first set threshold.

[0114] In a possible implementation, when the file type is a style file, the duplication result determination module 403 detects the duplicated content of the code file and the target code file according to the duplication detection strategy corresponding to the file type, to obtain the duplication detection result data representing the duplicated content of the code file.

[0115] The third dependency package tool is invoked to detect the duplication of the file content corresponding to the target tag in the code file and the target code file, and the duplicated code is recorded when the duplication is not less than the second set threshold.

[0116] In a possible implementation, the duplication result determination module 403 detects the duplicated content of the code file and the target code file according to the duplication detection strategy corresponding to the file type, to obtain the duplication detection result data representing the duplicated content of the code file.

[0117] If the function in the first content in the code file does not exist or is not called in the second content, the code file is segmented according to the first content and the second content, and the corresponding tool is invoked to detect the duplication, the first content is the content corresponding to the first tag, and the second content is the content corresponding to the second tag.

[0118] In a possible implementation, the duplication result determination module 403 is further configured to:

[0119] The annotation information in the code file is detected, and the duplicated code part associated with the annotation information is not detected when the annotation information exists.

[0120] The embodiment of the application further provides an electronic device. Referring to Figure 5 The electronic device shown in the figure shows a structure diagram suitable for realizing the electronic device in the embodiment of the application. The electronic device in the embodiment of the application can include but is not limited to fixed terminals such as notebook computers, desktop computers and the like. Figure 5 The electronic device shown in the figure is only an example, and should not bring any limitation to the function and use range of the embodiment of the application.

[0121] As Figure 5As shown, the electronic device can include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 501 that can perform various appropriate actions and processes according to programs stored in a read-only memory (ROM) 502 or loaded into a random access memory (RAM) 503 from a storage device 508. In a state in which the electronic device is powered on, various programs and data required for operation of the electronic device are also stored in the RAM 503. The processing device 501, the ROM 502, and the RAM 503 are connected to each other through a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0122] Generally, the following devices can be connected to the I / O interface 505: input devices 506 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 508 including, for example, a memory card, a hard disk, etc.; and communication devices 509. The communication devices 509 can allow the electronic device to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 5 The electronic device is shown with various devices, but it should be understood that not all of the shown devices are required to be implemented or present. More or fewer devices can alternatively be implemented or present.

[0123] The embodiment of the present application also provides a computer program product comprising computer readable instructions, which, when executed on an electronic device, cause the electronic device to implement any one of the code repetition degree detection methods provided by the embodiments of the present application.

[0124] The embodiment of the present application also provides a computer readable storage medium, which carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement any one of the code repetition degree detection methods provided by the embodiments of the present application.

[0125] In addition, it should be noted that the device embodiments described above are merely illustrative, wherein the units described as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, i.e., they can be located in one place, or distributed on multiple network units. Part or all of the modules can be selected according to actual needs to achieve the purpose of the embodiments. In addition, the connection relationship between the modules in the device embodiment provided by the present application indicates that there is a communication connection between them, which can be implemented as one or more communication buses or signal lines.

[0126] Those skilled in the art can clearly understand that the application can be implemented by means of software plus necessary universal hardware, and of course can also be implemented by means of dedicated hardware including special integrated circuit, special CPU, special memory, special component, etc. Generally, any function completed by computer program can be easily implemented by corresponding hardware, and the specific hardware structure for implementing the same function can also be various, such as analog circuit, digital circuit or special circuit, etc. However, for the application, software program implementation is a better embodiment. Based on such understanding, the technical solution of the application or the part of the application which makes contribution to the prior art can be embodied in the form of software product, which is stored in readable storage medium, such as computer floppy disk, U disk, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., and includes a plurality of instructions for making a computer device (which can be personal computer, training device or network device, etc.) execute the method described in various embodiments of the application.

[0127] In the above embodiments, the implementation can be achieved by software, hardware, firmware or any combination thereof, entirely or partially. When implemented by software, the implementation can be achieved in the form of a computer program product, entirely or partially.

[0128] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the flow or function described in the embodiments of the application is generated entirely or partially. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another, for example, the computer instructions can be transmitted from one website, computer, training device or data center to another website, computer, training device or data center through wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that can be stored by a computer or a data storage device such as a training device, a data center, etc. integrated with one or more available media sets. The available medium can be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (SSD)), etc.

Claims

1. A method of code repetition degree detection, characterized by, The method comprises the following steps: Based on the state monitoring instruction, the changed file list on line or locally is obtained; The type of each code file in the changed file list is identified to obtain the file type of each code file; According to the repetition detection strategy corresponding to the file type, the repeated content of the code file and the target code file is detected to obtain the repetition detection result data representing the repeated content of the code file, and the target code file is a file with the same type as the code file in the online database or the local database; According to the preset template, the repetition detection result data is summarized to obtain the repetition detection report.

2. The code repetition detection method of claim 1, wherein The method comprises the following steps: The type of the state monitoring instruction is identified, if the type of the state monitoring instruction is local state monitoring, the changed file list in the local database is obtained; If the type of the state monitoring instruction is online state monitoring, the changed file list in the online database is obtained.

3. The code repetition detection method of claim 1, wherein When the file type is an interface registration file, the repetition detection strategy corresponding to the file type is used to detect the repeated content of the code file and the target code file to obtain the repetition detection result data representing the repeated content of the code file, which comprises the following steps: A first dependent package tool is called to convert the code file and the target code file into corresponding abstract syntax trees respectively; A second dependent package tool is called to traverse and compare the two abstract syntax trees to determine the same interface registration information and make corresponding records.

4. The code repetition detection method of claim 1, wherein When the file type is a component file, the repetition detection strategy corresponding to the file type is used to detect the repeated content of the code file and the target code file to obtain the repetition detection result data representing the repeated content of the code file, which comprises the following steps: A code repetition detection tool is called to detect the repetition of the code file and the target code file, and when the repetition is not less than a first set threshold, the repeated code is recorded.

5. The code-repetition detection method of claim 1, wherein When the file type is a style file, the repetition detection strategy corresponding to the file type is used to detect the repeated content of the code file and the target code file to obtain the repetition detection result data representing the repeated content of the code file, which comprises the following steps: A third dependent package tool is called to detect the repetition of the file content corresponding to the target label in the code file and the target code file, and when the repetition is not less than a second set threshold, the repeated code is recorded.

6. The code repetition detection method of claim 5, wherein, The repetition detection strategy corresponding to the file type is used to detect the repeated content of the code file and the target code file to obtain the repetition detection result data representing the repeated content of the code file, which further comprises the following steps: If a function in the first content in the code file does not exist or is not called in the second content, the code file is split according to the first content and the second content, and then corresponding tools are called to perform the repetition detection, the first content is the content corresponding to the first label, and the second content is the content corresponding to the second label.

7. The method of code-repetition detection according to any one of claims 1 to 6, characterized in that, Also includes: The annotation information in the code file is detected, and when the annotation information exists, the code part associated with the annotation information is no longer subjected to the repetition detection.

8. A code repetition degree detection apparatus characterized by comprising: Includes: The change file acquisition module is configured to acquire a change file list online or locally based on a state monitoring instruction; The file type determination module is configured to identify the type of each code file in the change file list to obtain a file type of each code file; The repetition result determination module is configured to detect the repetition content of the code file and a target code file according to a repetition detection strategy corresponding to the file type to obtain repetition detection result data representing the repetition content of the code file, the target code file being a file with the same type as the code file in an online database or a local database; And, The repetition result summary module is configured to summarize each repetition detection result data according to a preset generation template to obtain a repetition detection report.

9. An electronic device, comprising: The electronic device includes at least one processor and a memory connected to the processor, wherein: The memory is configured to store a computer program; The processor is configured to execute the computer program to enable the electronic device to implement the code repetition detection method according to any one of claims 1 to 7.

10. A computer storage medium, characterized in that, The storage medium carries one or more computer programs, and when the one or more computer programs are executed by the electronic device, the electronic device can implement the code repetition detection method according to any one of claims 1 to 7.