A code statistics method and system
By configuring code statistics parameters and periodic tasks in the project management system, updating branch revision numbers and adopting segmented statistics, the problems of duplication and omission in code statistics are solved, and statistical efficiency and accuracy are improved.
Patent Information
- Application Number
- CN202311839642.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-28
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2043-12-28
AI Technical Summary
Existing code statistics methods are prone to repeated statistics or missing statistics during the statistical process, resulting in low efficiency and accuracy.
Configure code statistics parameters and periodic tasks in the project management system (PMS), update the revision numbers of branches through branch synchronization and data statistics tasks, and use segmented statistics to count submission nodes between revision numbers to generate code Statistics to avoid repeated statistics.
It effectively solves the problems of repeated statistics and missing statistics, improves the efficiency and accuracy of code statistics, and ensures the latestness and accuracy of submitted nodes.
Smart Images

Figure CN117785272B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of project management, and in particular to a code statistics method and system. Background Art
[0002] A project is usually composed of a large amount of code. Counting the number of effective codes contributed by each developer in a stable project can reflect the coding efficiency and quality of the developers. Managers can refer to this kind of statistical data to evaluate their work. Developers can understand their own code quality and coding habits, and make adjustments and improvements. Therefore, as the project continues to expand, data statistics for project codes become more and more important. Git is an open source distributed version control system used to handle small or large projects agilely and efficiently. In Git, the file directory that needs to be version controlled is called a repository. Each repository can be simply understood as a directory. All files in this directory are version managed through Git. When managing project versions, the number of codes needs to be counted.
[0003] Code statistics are usually performed on the same branch, and the daily changes of the developer's code need to be counted, so each code branch has monitoring statistics. When counting the number of code submissions in each code branch every day, if branch A, which has not submitted code for a period of time, merges another code branch B, all the code submitted by branch B during this period will be counted repeatedly. At present, the existing code statistics methods have the problem of repeated statistics or missing statistics in the statistical process.
[0004] Therefore, providing a code statistics method and system that can effectively solve the above technical problems is an issue that needs to be urgently resolved by those skilled in the art. Summary of the invention
[0005] The purpose of the present invention is to provide a code statistics method, which has clear logic, is safe, effective, reliable and easy to operate, can effectively solve the technical problems of repeated statistics or omitted statistics, and improve the efficiency and accuracy of code statistics.
[0006] Based on the above objectives, the technical solution provided by the present invention is as follows:
[0007] A code statistics method comprises the following steps:
[0008] Configure code statistics parameters and periodic tasks in the PMS system;
[0009] Execute the branch synchronization task according to the first preset period, obtain the branch information of the code repository according to the code statistical parameter, and update the Nth revision number of each branch;
[0010] Execute the data statistics task according to the second preset period, and determine whether there is an N-1th revision number in each branch according to the branch information;
[0011] According to the judgment result, all the submitted nodes between the Nth revision number and the N-1th revision number are counted in a segmented manner to generate code statistics;
[0012] Wherein, the periodic tasks include: the branch synchronization task and the data statistics task.
[0013] Preferably, the code statistical parameters include: code repository name, associated information, code repository address, the first preset period and the second preset period;
[0014] The branch information of the code repository includes: branch name, Nth revision number of the current branch, and N-1th revision number of the current branch.
[0015] Preferably, executing the branch synchronization task according to the first preset period, obtaining the branch information of the code repository according to the code statistical parameter, and updating the Nth revision number of each branch includes the following steps:
[0016] The PMS system sends the branch synchronization task instruction to the code scanner according to the first preset period;
[0017] After receiving the instruction of the branch synchronization task, the code scanner obtains the branch information of the code warehouse according to the code warehouse address;
[0018] The PMS system determines whether the Nth commit node of each branch in the branch information of the code repository is consistent with the Nth revision number of each branch recorded in the PMS system;
[0019] If not, the PMS system updates the Nth revision number of each branch to the Nth commit node of each branch.
[0020] Preferably, after the PMS system determines whether the Nth commit node of each branch in the branch information of the code repository is consistent with the Nth revision number of each branch recorded in the PMS system, it also includes:
[0021] If so, jump to the next branch according to the branch information of the code repository, and re-execute the judgment process of whether the branch submission node is consistent with the revision number until each branch under all repositories completes the branch synchronization task.
[0022] Preferably, the performing of the data statistics task at the second preset period and judging whether there is an N-1th revision number in each branch according to the branch information comprises the following steps:
[0023] The PMS system sends the instruction of the data statistics task to the code scanner according to the second preset period;
[0024] After receiving the instruction of the data statistics task, the code scanner obtains modification record information of each branch according to the branch information of the code warehouse;
[0025] It is determined according to the modification record information whether each branch has the N-1th revision number.
[0026] Preferably, the step of correspondingly counting all the submission nodes between the Nth revision number and the N-1th revision number in a segmented manner according to the judgment result to generate code statistics data comprises the following steps:
[0027] If the judgment result is yes, the segmented statistics are directly executed to generate code statistics data;
[0028] If the judgment result is no, after creating the N-1th revision number, segmented statistics are performed to generate code statistical data;
[0029] The creation of the N-1th revision number is specifically:
[0030] Starting from the Nth commit node of the current branch, each commit node of the current branch that has been historically counted is traced back in chronological order until the corresponding commit node is determined according to the preset conditions and recorded as the N-1th revision number.
[0031] Preferably, the step of determining the corresponding submission node according to the preset conditions comprises the following steps:
[0032] Determine whether the i-th submission node has not been counted;
[0033] Determine whether the submission time corresponding to the i-th submission node is later than the earliest time corresponding to the submission nodes counted in history;
[0034] If the above judgment results of the i-th submission node are all yes, and any of the above judgment results of the i+1-th submission node is no, then the i-th submission node is defined as the corresponding submission node.
[0035] Preferably, the segmented counting of all the commit nodes between the Nth revision number and the N-1th revision number to generate code statistics data comprises the following steps:
[0036] Determine whether there is a branch merge operation for all commit nodes between the Nth revision number and the N-1th revision number;
[0037] If yes, take the Nth commit node of the current branch as the starting point and determine whether the kth commit node is a merge node or a counted commit node;
[0038] If the k-th submitted node is not the merged node and has not been counted, then the difference data between the k-th submitted node and the adjacent nodes are counted in segments;
[0039] If the k-th submission node is the merge node or a submission node that has been counted, skip the k-th submission node;
[0040] Repeat the judgment step of the kth commit node until the commit node corresponding to the N-1th revision number is counted, integrate the difference data counted in multiple segments, and generate code statistics data.
[0041] A code statistics system, comprising:
[0042] Configuration module, used to configure code statistics parameters and periodic tasks in the PMS system;
[0043] A branch synchronization module, used to perform branch synchronization tasks according to a first preset period, obtain branch information of the code repository according to the code statistical parameters, and update the Nth revision number of each branch;
[0044] A data statistics module, used to perform data statistics tasks according to a second preset period, and determine whether there is an N-1th revision number in each branch according to the branch information;
[0045] A code statistics module, used for correspondingly counting all the submitted nodes between the Nth revision number and the N-1th revision number in a segmented manner according to the judgment result, so as to generate code statistics data;
[0046] The periodic tasks include: the branch synchronization task and the data statistics task. The code statistics method disclosed in the present invention is to configure relevant parameters and periodic tasks in the PMS system, execute the branch synchronization task, update the Nth revision number of the branch in the PMS system; execute the data statistics task, and count the submission nodes in segments according to the Nth revision number and the N-1th revision number of each branch to generate code statistics data.
[0047] Compared with the existing technology, a periodic update of the Nth revision number is designed to ensure the latest submission node; a segmented statistical method is designed to count the submission nodes between the Nth revision number and the N-1th revision number, avoiding the problem of duplicate statistics due to merging branches, and improving the efficiency and accuracy of code statistics.
[0048] The present invention also discloses a code statistics system, which solves the same technical problem as the method, belongs to the same technical concept, and should have the same beneficial effects, so it will not be described in detail here. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0050] Figure 1 A flowchart of a code statistics method provided by an embodiment of the present invention;
[0051] Figure 2 A flowchart of step S2 provided in an embodiment of the present invention;
[0052] Figure 3 A flowchart of step S3 provided in an embodiment of the present invention;
[0053] Figure 4 Flow chart of the segmented statistics in step S4 provided in the embodiment of the present invention
[0054] Figure 5 An example schematic diagram of the logical idea of segmented statistics provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0055] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0056] The embodiments of the present invention are written in a progressive manner.
[0057] The embodiment of the present invention provides a code statistics method and system, which mainly solves the technical problem in the prior art that code statistics are inefficient and inaccurate due to repeated statistics or missing statistics in the statistics process.
[0058] In the actual application process, according to different usage requirements or required effects, each method step has specific usage details, and the specific equipment or components used in each step can be selected according to actual needs. In this embodiment, PMS system + code scanner (code-scanner) + gitlab code warehouse is used to implement it.
[0059] Among them, PMS (Project Management System) is a system that conducts real-time monitoring and management of the entire process of project development, realizes data management, information sharing, and resource allocation optimization. It adopts a multi-layer (specifically divided into data layer, service layer, and presentation layer) architecture system and distributed deployment in B / S mode, and has continuous, efficient, and reliable operation capabilities; Git: an open source distributed version control system that can effectively and quickly handle version management of projects from small to very large; Repository: a shared database of the revision history of all files under version control.
[0060] like Figure 1 As shown, a code statistics method includes the following steps:
[0061] S1. Configure code statistics parameters and periodic tasks in the PMS system;
[0062] S2. Execute the branch synchronization task according to the first preset cycle, obtain the branch information of the code repository according to the code statistical parameters, and update the Nth revision number of each branch;
[0063] S3. Execute the data statistics task according to the second preset cycle, and determine whether there is an N-1th revision number in each branch according to the branch information;
[0064] S4. According to the judgment result, all the submission nodes between the Nth revision number and the N-1th revision number are counted in a segmented manner to generate code statistics;
[0065] Among them, periodic tasks include: branch synchronization tasks and data statistics tasks.
[0066] Preferably, the code statistics parameters include: code repository name, associated information, code repository address, first preset period and second preset period;
[0067] The branch information of the code repository includes: branch name, Nth revision number of the current branch, and N-1th revision number of the current branch.
[0068] In step S1, code statistics parameters are configured in the PMS system for the code repository to be tracked, the branch synchronization task, and the data statistics task, including the code repository name, associated information, code repository address, the first preset period, and the second preset period;
[0069] In step S2, a branch synchronization task is executed according to a first preset period to request branch information of the warehouse, and the Nth revision number of each branch in the warehouse is updated according to the branch information;
[0070] In step S3, a data statistics task is performed according to a second preset period to count the code data. During the statistics process, it is first determined whether there is an N-1th revision number in each branch according to the branch information;
[0071] In this embodiment, the first preset period is ten minutes, and the second preset period is 24 hours;
[0072] In step S4, after corresponding processing is performed according to the judgment result of step S3, all the commit nodes between two revision numbers are counted in sections to generate code statistics.
[0073] Furthermore, after obtaining code statistics, it is also possible to associate employee information based on related information, assign weights to different file types, and generate visual data for display.
[0074] like Figure 2 As shown, preferably, step S2 includes the following steps:
[0075] A1. The PMS system sends branch synchronization task instructions to the code scanner according to the first preset cycle;
[0076] A2. After receiving the branch synchronization task instruction, the code scanner obtains the branch information of the code repository according to the code repository address;
[0077] A3. The PMS system determines whether the Nth commit node of each branch in the branch information of the code repository is consistent with the Nth revision number of each branch recorded in the PMS system;
[0078] A4. If not, the PMS system updates the Nth revision number of each branch to the Nth commit node of each branch.
[0079] It should be noted that Revision: represents a version status of the code. Git identifies different versions through IDs represented by the SHA1 hash algorithm;
[0080] In this embodiment, there are N revisions in total, and the Nth revision number is the latest revision number; the N-1th revision number is the last revision number;
[0081] In step A1, the PMS system sends branch synchronization task instructions to the code scanner in a cycle of ten minutes;
[0082] In step A2, after receiving the instruction, the code scanner calls the field information of the warehouse address, obtains the branch list of the current warehouse, and records the branch name, the latest revision number and the last revision number, where the latest revision number is the latest submitted node number corresponding to each branch, and the last revision number is the latest revision number in the last task statistics;
[0083] In step A3, the PMS system determines whether the latest commit node of each branch is consistent with the latest revision number of each branch recorded;
[0084] In step A4, if there is inconsistency, the PMS system updates the latest revision number of each branch to the corresponding latest submitted node;
[0085] Preferably, after step A3, the method further comprises:
[0086] If so, jump to the next branch according to the branch information of the code repository, and re-execute the judgment process of whether the branch submission node is consistent with the revision number until each branch under all repositories completes the branch synchronization task.
[0087] In actual application, if they are consistent, it means that the branch has not been pushed. Jump to the next branch according to the branch list of the current warehouse and re-execute step A3 until each branch under all warehouses completes the branch synchronization task.
[0088] like Figure 3 As shown, preferably, step S3 includes the following steps:
[0089] B1. The PMS system sends the data statistics task instructions to the code scanner according to the second preset cycle;
[0090] B2. After receiving the instruction of the data statistics task, the code scanner obtains the modification record information of each branch according to the branch information of the code repository;
[0091] B3. Determine whether each branch has the N-1th revision number based on the modification record information.
[0092] In step B1, the PMS system sends data statistics task instructions to the code scanner in a 24-hour cycle;
[0093] In step B2, after receiving the data statistics task instruction, the code scanner obtains the modification record information of each branch according to the branch information of the code repository and the update step of step A4;
[0094] In step B3, the modification records of each branch are queried to determine whether there is a last revision number in each branch.
[0095] Preferably, step S4 comprises the following steps:
[0096] If the judgment result is yes, the segmented statistics are directly executed to generate code statistics data;
[0097] If the judgment result is no, after creating the N-1th revision number, segmented statistics are performed to generate code statistics;
[0098] Among them, create the N-1th revision number, specifically:
[0099] Starting from the Nth commit node of the current branch, trace back each commit node of the current branch that has been historically counted in chronological order until the corresponding commit node is determined according to the preset conditions and recorded as the N-1th revision number.
[0100] It should be noted that if the last revision number exists in each branch, segmented statistics are directly performed to generate code statistics;
[0101] If the last revision number does not exist in one of the branches, it means that the code statistics are performed for the branch for the first time in this cycle. Then, after the last revision number is created, segmented statistics are performed to generate code statistics data.
[0102] The specific process of creating a revision number is: starting from the latest commit node of the current branch, trace back each commit node in chronological order, find the information of the historically counted commit nodes, until the corresponding commit node is determined according to the preset conditions, and record the commit node as the last revision number.
[0103] In this embodiment, each time a statistics task is initiated, the content of the latest revision number will be written into the last revision number. Because there is no last revision number when the first statistics is performed, special processing is done here for the first statistics to avoid ignoring the submitted code before the push operation in the conventional practice;
[0104] Preferably, determining the corresponding submission node according to the preset conditions includes the following steps:
[0105] Determine whether the i-th submission node has not been counted;
[0106] Determine whether the submission time corresponding to the i-th submission node is later than the earliest time corresponding to the submission node counted in history;
[0107] If the above judgment results of the i-th submission node are all yes, and any of the above judgment results of the i+1-th submission node is no, then the i-th submission node is defined as the corresponding submission node.
[0108] It should be noted that each statistical task will record all commit nodes in the interval into the database table. To check whether a node has been counted is to query whether there is a record of the node in the database table;
[0109] The purpose of judging that the submission time corresponding to the i-th submission node is after the earliest time corresponding to the submission node that has been historically counted is to ensure that the newly counted data are submitted after the nodes that have been counted.
[0110] In actual application, there is a situation: a branch originates from an earlier submission point. In the first statistics, because the previous nodes have not been counted, it will lead to over-counting of previous submissions in the code repository. In this step, a backup operation is performed to only count the submission time of the counted nodes.
[0111] In this embodiment, if the i-th submission node has not been counted and the submission time is after the earliest time in the historical statistical nodes, this submission node will be included in the statistical scope; the submission nodes that do not meet the above conditions are queried, and the ID of the last submission node that meets the above conditions is recorded as the last revision number.
[0112] like Figure 4 As shown, preferably, the segmented statistics in step S4 includes the following steps:
[0113] C1. Determine whether there is a branch merge operation for all commit nodes between the Nth revision number and the N-1th revision number;
[0114] C2. If yes, take the Nth commit node of the current branch as the starting point and determine whether the kth commit node is a merge node or a counted commit node;
[0115] C21. If the k-th submitted node is not a merge node and has not been counted, the difference data between the k-th submitted node and the adjacent nodes is counted in segments;
[0116] C22. If the kth submission node is a merge node or a submission node that has been counted, skip the kth submission node;
[0117] C3. Repeat steps C2 to C22 until the submission node corresponding to the N-1th revision number is counted, and the difference data of multiple segment statistics are integrated to generate code statistics data.
[0118] In step C1, it is determined whether there is a branch merge operation among all the commit nodes between the commit node corresponding to the latest revision number and the commit node corresponding to the last revision number;
[0119] In this embodiment, merging (Merge): connecting the changes on a branch to this trunk or another branch of the same trunk;
[0120] In step C2, if there is no merge operation, the difference files in the above interval can be directly counted normally to generate code statistics;
[0121] If there is a merge operation, start with the commit node corresponding to the latest revision number and end with the commit node corresponding to the last revision number, and determine whether each commit node between the two is a merge node or a counted commit node;
[0122] In step C21 and step C22, if the kth submission node is a merge node or a submission node that has been counted, then skip the submission node and continue searching; if the kth submission node is not a merge node and has not been counted, then query the previous adjacent node of the same branch of the node as the reference node to obtain the difference data between the kth submission node and the reference node;
[0123] In step C3, process according to step C21 or step C22: integrate multiple difference data of all commit nodes between the commit node corresponding to the latest revision number and the commit node corresponding to the previous revision number to generate code statistics.
[0124] Now, according to one of the embodiments designed in the present invention, the logical idea of implementing segmented statistics is described as follows:
[0125] like Figure 5 As shown in the figure, there are now two code branches, Develop and Feature. From top to bottom is the time direction. Each circle represents a submission record node. The direction of the arrow indicates the flow of code submission and merge operations. D2 and D4 are merge points.
[0126] First day statistics:
[0127] First, the last code statistics will record the benchmark nodes D0 and F0. When the statistics task is initiated on the first day, the Develop branch will read the latest submission point D1, and then determine that there is no merge point and no counted point in the interval from D0 to D1, then determine D1 as the comparison point and D0 as the benchmark point, and count the differences in the entire interval at one time; similarly, on the Feature branch, directly count the differences in the interval from F2 to F0 at one time; after the statistics, mark D1 and F2 as benchmark points;
[0128] Statistics for the second day:
[0129] When the statistics task was initiated on the second day, because the Feature branch had some code merged into the Develop branch on that day, if the difference between the latest comparison point and the benchmark point interval was directly counted according to the conventional method, the codes F1 and F2 merged from the Feature branch of the D2 node would be repeatedly counted on the Develop branch, thus resulting in the problem of repeated statistics caused by the branch merging operation;
[0130] The segmented statistics method is to first obtain the latest commit point D5 of the Develop branch, and then determine whether there is a merge point or a counted point between D5 and the base point D1. In the figure, there are two merge points D4 and D2, so the segmented statistics method is adopted, starting from the latest point D5. D5 is not a merge point and has not been counted, so the adjacent point D4 in the Develop branch with D5 is queried, and the changes between D5 and D4 are first counted; after D5 is counted, D5 is marked as a counted point, and then D4 is judged forward. Because D4 is a merge point, it is directly skipped. After D4, F6, F5, D3, F4, F3, D2, F2, and D1 are found in sequence. Similarly, F6 counts F6-F5, F5 counts F5-F4, D3 counts D3-D2, F4 counts F4-F3, and F3 counts F3-F2. F2 and D1 are both base points, and this cycle ends;
[0131] In the above process, F6, F5, F4, F3, and D3 can all count the changes of the time, and they are all marked as counted points after counting. At this point, the Develop branch has completed the statistics, and the Feature branch continues to be scanned. First, F7 is the latest commit point of the branch. There are counted points between F7 and F2, so segmented statistics are also required. Between F7 and F2, except F7, the rest have been marked as counted. Therefore, after counting F7-F6, the Feature branch is completed. Finally, the segmented statistical results are added up to get the statistical data of a task;
[0132] In the above implementation process, there is no need to distinguish the statistical order of Develop and Feature. The same result can be obtained if the Feature branch is counted first.
[0133] A code statistics system, comprising:
[0134] Configuration module, used to configure code statistics parameters and periodic tasks in the PMS system;
[0135] A branch synchronization module, used to execute the branch synchronization task according to the first preset period, obtain the branch information of the code repository according to the code statistical parameters, and update the Nth revision number of each branch;
[0136] A data statistics module, used to perform data statistics tasks according to a second preset period, and determine whether there is an N-1th revision number in each branch according to the branch information;
[0137] A code statistics module is used to count all the submission nodes between the Nth revision number and the N-1th revision number in a segmented manner according to the judgment result, so as to generate code statistics data;
[0138] Among them, periodic tasks include: branch synchronization tasks and data statistics tasks.
[0139] In the embodiments provided in the present application, it should be understood that the disclosed methods and systems can be implemented in other ways. The system embodiments described above are merely schematic. For example, the division of modules is only a logical function division. There may be other division methods in actual implementation, such as: multiple modules or components can be combined, or can be integrated into another system, or some features can be ignored, or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.
[0140] In addition, all functional modules in the embodiments of the present invention may be integrated into one processor, or each module may be a separate device, or two or more modules may be integrated into one device; each functional module in the embodiments of the present invention may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0141] A person of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by program instructions and related hardware. The aforementioned program instructions can be stored in a computer-readable storage medium. When the program instructions are executed, the steps of the above method embodiment are executed; and the aforementioned storage medium includes: a mobile storage device, a read-only memory (ROM), a magnetic disk or an optical disk, and other media that can store program codes.
[0142] It should be understood that the use of "system", "device", "unit" and / or "module" in this application is only a method for distinguishing different components, elements, parts, parts or assemblies at different levels. However, if other words can achieve the same purpose, the word can be replaced by other expressions.
[0143] As shown in this application and claims, unless the context clearly indicates an exception, the words "a", "an", "a kind" and / or "the" do not refer to the singular, but also include the plural. Generally speaking, the terms "include" and "comprise" only indicate the inclusion of clearly identified steps and elements, and these steps and elements do not constitute an exclusive list. The method or device may also include other steps or elements. The elements defined by the sentence "includes a..." do not exclude the existence of other identical elements in the process, method, commodity or device that includes the elements.
[0144] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features.
[0145] If a flow chart is used in the present application, the flow chart is used to illustrate the operations performed by the system according to the embodiment of the present application. It should be understood that the preceding or following operations are not necessarily performed accurately in order. On the contrary, each step can be processed in reverse order or simultaneously. At the same time, other operations can also be added to these processes, or a certain step or several steps of operations can be removed from these processes.
[0146] The above is a detailed introduction to a code statistics method and system provided by the present invention. The above description of the disclosed embodiments enables professionals and technicians in the field to implement or use the present invention. Various modifications to these embodiments will be obvious to professionals and technicians in the field, and the general principles defined in this article can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown in this article, but will conform to the widest range consistent with the principles and novel features disclosed in this article.
Claims
1. A code statistics method, characterized in that: The steps include: Configure code statistics parameters and periodic tasks in the project management system; Execute the branch synchronization task according to the first preset period, obtain the branch information of the code repository according to the code statistical parameter, and update the Nth revision number of each branch; Execute the data statistics task according to the second preset period, and determine whether there is an N-1th revision number in each branch according to the branch information; According to the judgment result, all the submitted nodes between the Nth revision number and the N-1th revision number are counted in a segmented manner to generate code statistics; Wherein, the periodic tasks include: the branch synchronization task and the data statistics task; The code statistics parameters include: code repository name, associated information, code repository address, the first preset period and the second preset period; The branch information of the code repository includes: branch name, Nth revision number of the current branch, and N-1th revision number of the current branch; The executing the branch synchronization task according to the first preset period, obtaining the branch information of the code repository according to the code statistical parameter, and updating the Nth revision number of each branch includes the following steps: The project management system sends the instruction of the branch synchronization task to the code scanner according to the first preset period; After receiving the instruction of the branch synchronization task, the code scanner obtains the branch information of the code warehouse according to the code warehouse address; The project management system determines whether the Nth commit node of each branch in the branch information of the code repository is consistent with the Nth revision number of each branch recorded in the project management system; If not, the project management system updates the Nth revision number of each branch to the Nth submission node of each branch; Among them, the project management system is specifically: a system that conducts real-time monitoring and management of the entire project development process, realizes data management, information sharing, and resource allocation optimization, and adopts a B / S model including a data layer, service layer, and presentation layer architecture system and distributed deployment.
2. The code statistics method according to claim 1, characterized in that: After the project management system determines whether the Nth commit node of each branch in the branch information of the code repository is consistent with the Nth revision number of each branch recorded in the project management system, the method further includes: If so, jump to the next branch according to the branch information of the code repository, and re-execute the judgment process of whether the branch submission node is consistent with the revision number until each branch under all repositories completes the branch synchronization task.
3. The code statistics method according to claim 1, characterized in that: The step of performing the data statistics task according to the second preset period and judging whether there is an N-1th revision number in each branch according to the branch information includes the following steps: The project management system sends the instruction of the data statistics task to the code scanner according to the second preset period; After receiving the instruction of the data statistics task, the code scanner obtains modification record information of each branch according to the branch information of the code warehouse; It is determined according to the modification record information whether each branch has the N-1th revision number.
4. The code statistics method according to claim 3, characterized in that: The step of correspondingly counting all the submitted nodes between the Nth revision number and the N-1th revision number in a segmented manner according to the judgment result to generate code statistics data includes the following steps: If the judgment result is yes, the segmented statistics are directly executed to generate code statistics data; If the judgment result is no, after creating the N-1th revision number, segmented statistics are performed to generate code statistical data; Among them, the creation of the N-1th revision number is specifically: starting from the Nth submission node of the current branch, tracing back each submission node of the current branch that has been historically counted in chronological order, until the corresponding submission node is determined according to preset conditions and recorded as the N-1th revision number.
5. The code statistics method according to claim 4, characterized in that: Determining the corresponding submission node according to the preset conditions includes the following steps: Determine whether the i-th submission node has not been counted; Determine whether the submission time corresponding to the i-th submission node is later than the earliest time corresponding to the submission nodes counted in history; If the above judgment results of the i-th submission node are all yes, and any of the above judgment results of the i+1-th submission node is no, then the i-th submission node is defined as the corresponding submission node.
6. The code statistics method according to claim 4, characterized in that: The segmented counting of all the commit nodes between the Nth revision number and the N-1th revision number to generate code statistics data includes the following steps: Determine whether there is a branch merge operation for all commit nodes between the Nth revision number and the N-1th revision number; If yes, take the Nth commit node of the current branch as the starting point and determine whether the kth commit node is a merge node or a counted commit node; If the k-th submitted node is not the merged node and has not been counted, then the difference data between the k-th submitted node and the adjacent nodes are counted in segments; If the k-th submission node is the merge node or a submission node that has been counted, skip the k-th submission node; Repeat the determination step of the kth commit node until the commit node corresponding to the N-1th revision number is counted, integrate the difference data of multiple segment statistics, and generate code statistics data.
7. A code statistics system, characterized in that: include: Configuration module, used to configure code statistics parameters and periodic tasks in the project management system; A branch synchronization module, used to perform branch synchronization tasks according to a first preset period, obtain branch information of the code repository according to the code statistical parameters, and update the Nth revision number of each branch; A data statistics module, used to perform data statistics tasks according to a second preset period, and determine whether there is an N-1th revision number in each branch according to the branch information; A code statistics module, used for correspondingly counting all the submitted nodes between the Nth revision number and the N-1th revision number in a segmented manner according to the judgment result, so as to generate code statistics data; Wherein, the periodic tasks include: the branch synchronization task and the data statistics task; The code statistics parameters include: code repository name, associated information, code repository address, the first preset period and the second preset period; The branch information of the code repository includes: branch name, Nth revision number of the current branch, and N-1th revision number of the current branch; The executing the branch synchronization task according to the first preset period, obtaining the branch information of the code repository according to the code statistical parameter, and updating the Nth revision number of each branch includes the following steps: The project management system sends the instruction of the branch synchronization task to the code scanner according to the first preset period; After receiving the instruction of the branch synchronization task, the code scanner obtains the branch information of the code warehouse according to the code warehouse address; The project management system determines whether the Nth commit node of each branch in the branch information of the code repository is consistent with the Nth revision number of each branch recorded in the project management system; If not, the project management system updates the Nth revision number of each branch to the Nth submission node of each branch; Among them, the project management system is specifically: a system that conducts real-time monitoring and management of the entire project development process, realizes data management, information sharing, and resource allocation optimization, and adopts a B / S model including a data layer, service layer, and presentation layer architecture system and distributed deployment.
Citation Information
Patent Citations
Code quantity statistics method and device, electronic equipment and storage medium
CN112416417A
Code workload statistical method and device and electronic equipment
CN114385188A
System to coordinate source code module changes
US20180260193A1
Apparatus and method for source code optimisation
US20210182039A1
