Method and system for calculating code quantity based on svn log
Through the method and system based on svn logs, the difficulty of filtering the effective code quantity during the code statistics process is solved, and fast and accurate code quantity statistics are achieved, which improves work efficiency.
Patent Information
- Application Number
- CN202510052897.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-14
- Publication Date
- 2025-05-23
AI Technical Summary
In the prior art, it is difficult to screen out the effective code amount of specific developers or the effective code amount within a certain range or date in a certain period of time and effort.
It provides a method and system for calculating the code quantity based on svn logs. By receiving the statistical conditions of svn logs, it determines the specified log, filters the target file, recognizes the file change attributes, exports the target file, reads and records the code line change data, performs data balance, and counts the total code line change data.
It can quickly and accurately count the effective code amount under specific conditions, such as staff, a certain date, and a certain version of the effective code amount, which improves the efficiency and accuracy of code statistics.
Smart Images

Figure CN120029657A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data statistics, and in particular to a method and system for calculating code volume based on SVN logs. Background Art
[0002] With the development of information systems in the era of big data, when enterprises process business, the business scale continues to increase, the data processing scale gradually becomes huge, and the amount of data continues to increase. Code staff will constantly update and modify the code to meet different business needs.
[0003] However, in the current code statistics process for code workers, it is difficult to screen and count the codes. For example, it is also difficult to screen out the effective code volume of a specific developer, or the effective code volume within a certain range or date, which is time-consuming and labor-intensive. Summary of the invention
[0004] In view of the problems existing in the prior art, an embodiment of the present invention provides a method and system for calculating the amount of code based on SVN logs.
[0005] An embodiment of the present invention provides a method for calculating the amount of code based on SVN logs, the method comprising: Receive statistical conditions of SVN logs, the statistical conditions including range conditions and basic information, determine a specified log according to the range conditions, and filter target files in the specified log according to the basic information; Identify the file change attribute of the target file, and export the target file based on the file change attribute; Read and record the code lines that generate file changes for each target file, and record the change data of the code lines based on the file change attributes, perform data balancing on the change data, and count the total change data of the code lines of the target file.
[0006] In one embodiment, the method further comprises: When the range condition is a version number, all SVN logs within the version number range are extracted; When the range condition is a timestamp, the version number update log within the timestamp is obtained, and all SVN logs within the version number range are extracted based on the version number update log.
[0007] In one embodiment, the method further comprises: Identify newly added files, deleted files, and modified files in the target file; Export the newly added files and deleted files, define a new counter corresponding to the newly added files and a deletion counter corresponding to the deleted files; The modified file is exported, and the modified code is recorded.
[0008] In one embodiment, the method further comprises: Read the code characters of the newly added file, and when a new symbol is read, increase the count of the new counter; Read the code character of the deletion file, and when the deletion symbol is read, increase the deletion counter; The code characters of the modification file are read, and when the modification symbol is read, the modification counter is increased.
[0009] In one embodiment, the method further comprises: When the end of the file or a new character block is detected, it is determined whether the count of the added counter corresponding to the fixed code character is equal to the count of the deleted counter; When the count of the newly added counter is equal to the count of the deleted counter, the count of the newly added counter and the count of the deleted counter of the fixed code character are reset and added to the count of the modified counter.
[0010] In one embodiment, the method further comprises: The count of the new counter, the count of the deleted counter, the count of the modified counter and the total change data of each target file are saved accordingly.
[0011] An embodiment of the present invention provides a system for calculating the amount of code based on SVN logs, the system comprising: A receiving module is used to receive statistical conditions of SVN logs, wherein the statistical conditions include range conditions and basic information, determine a designated log according to the range conditions, and filter a target file in the designated log according to the basic information; An export module, used for identifying a file change attribute of the target file, and exporting the target file based on the file change attribute; The recording module is used to read and record the code lines that generate file changes for each target file, and record the change data of the code lines based on the file change attributes, perform data balancing on the change data, and count the total change data of the code lines of the target file.
[0012] In one embodiment, the system further comprises: A detection module, used for determining whether the count of the new addition counter and the count of the deletion counter corresponding to the fixed code character are equal when the end of the file or a new character block is detected; The balancing module is used for resetting the count of the new addition counter and the count of the deletion counter of the fixed code character and adding them to the count of the modification counter when the count of the new addition counter is equal to the count of the deletion counter.
[0013] An embodiment of the present invention provides an electronic device, including a processor and a memory; The processor is connected to the memory; The memory is used to store executable program code; The processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the method described in one or more embodiments.
[0014] An embodiment of the present invention provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for calculating the amount of code based on the SVN log are implemented.
[0015] In view of the above, in one or more embodiments of the present specification, the statistical conditions of the SVN log are received, the statistical conditions include the range conditions and basic information, the designated log is determined according to the range conditions, the target file in the designated log is filtered according to the basic information; the file change attribute of the target file is identified, and the target file is exported based on the file change attribute; the code line of each target file that generates the file change is read and recorded, and the change data of the code line is recorded respectively based on the file change attribute, the change data is balanced, and the total change data of the code line of the target file is counted. In this way, according to the code change data of the SNV log, the effective code amount of specific conditions can be quickly counted, such as the effective code amount of staff, a certain date, and a certain version, which can be quickly and accurately counted. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the embodiments of the present invention 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 some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0017] Figure 1 This is a flowchart of a method for calculating the amount of code based on SVN logs provided by an embodiment of this specification.
[0018] Figure 2 It is a structural diagram of a system for calculating the amount of code based on SVN logs provided by an embodiment of this specification.
[0019] Figure 3 It is a structural schematic diagram of an electronic device provided by an embodiment of this specification. DETAILED DESCRIPTION
[0020] The subject matter described herein will now be discussed with reference to example embodiments. It should be understood that the discussion of these embodiments is only to enable those skilled in the art to better understand and implement the subject matter described herein, and is not a limitation of the scope of protection, applicability or examples set forth in the claims. The functions and arrangements of the elements discussed can be changed without departing from the scope of protection of the contents of this specification. Various examples can omit, replace or add various processes or components as needed. For example, the described method can be performed in an order different from the described order, and various steps can be added, omitted or combined. In addition, the features described relative to some examples can also be combined in other examples.
[0021] As used herein, the term "including" and its variations represent open terms, meaning "including but not limited to". The term "based on" means "based at least in part on". The terms "one embodiment" and "an embodiment" mean "at least one embodiment". The term "another embodiment" means "at least one other embodiment". The terms "first", "second", etc. may refer to different or the same objects. Other definitions may be included below, whether explicit or implicit. Unless the context clearly indicates otherwise, the definition of a term is consistent throughout the specification.
[0022] like Figure 1 As shown, an embodiment of the present invention provides a method for calculating the amount of code based on SVN logs, including: Step S101, receiving a statistical condition of an SVN log, the statistical condition including a range condition and basic information, determining a designated log according to the range condition, and filtering a target file in the designated log according to the basic information.
[0023] Specifically, when the SVN (Subversion) system manages file and directory changes, it detects detailed records of uploaded code and stores them in the SVN log. The information of uploaded code includes the uploader's account information, log information, and file change information, among which the log information may include the information of the code modifier. Among them, for the amount of code in a single upload record, each uploaded code will be different from the previous code. The number of different lines of all code files in one upload record is the amount of code in this upload record, including the newly added, deleted, and modified parts. The effective code volume is the amount of code after removing blank lines, comment lines, and invalid modified lines (for example, only the space character, line break character, tab character, etc. are modified, and there is no actual code modification). After receiving the request for statistical code volume, determine the statistical conditions, such as the SVN address, start time, end time (or start version number, end version number), and statistical result file. Among them, the statistical conditions include but are not limited to range conditions and basic information. The range conditions may include but are not limited to date range and version range. When the range condition is a version range, all SVN logs within the version number range are extracted; when the range condition is a time range, the version number update log within the time range is obtained, and all SVN logs within the version number range are extracted based on the version number update log.
[0024] Furthermore, after determining the SVN log, the specified file type and the difference file corresponding to the developer are selected from the log record and saved in the memory. For example, the changes involving the file type (such as .java) submitted by the developer (such as "zhangsan" Zhang San) are selected from the SVN log to determine the target file.
[0025] Step S102: identifying the file change attributes of the target file, and exporting the target file based on the file change attributes.
[0026] Specifically, identify the developer's processing of the target file and determine the file change attributes, such as adding, deleting or other types of modifications to the file. And there are different file export schemes for different file change attributes. For new files or deleted files, the export scheme can use the svn Export command to download these difference files and files before deletion to the local directory in the naming method of original file name + version number, read and process the exported files, and prepare for line-level analysis. For specific analysis, for example, the following quantities can be defined respectively: addLines (addition counter) = 0, modifyLines (modification counter) = 0, deleteLines (deletion counter) = 0; if a new file is added, addLines++, if a file is deleted, deleteLines++. For modified files, use the svn diff command to download these difference files to the local directory in the naming method of original file name + version number, that is, for non-new / deleted files, obtain specific change details.
[0027] Step S103, reading and recording the code lines that generate file changes for each target file, and recording the change data of the code lines based on the file change attributes, performing data balancing on the change data, and counting the total change data of the code lines of the target file.
[0028] Specifically, after all relevant difference files are read and downloaded, for the defined addLines (addition counter) = 0, modifyLines (modification counter) = 0, deleteLines (deletion counter) = 0, read and record the code lines that generate file changes for each target file. Specifically, for example, read from the first "@@ - (file start)" identifier, and when encountering '+' or '>' (addition symbol), addLines++ is used; when encountering '-' or '<' (deletion symbol), deleteLines++ is used; when encountering '!' (modification symbol), modifyLines++ is used.
[0029] Furthermore, in order to distinguish between true modifications (i.e., both deletions and additions at the same position) and other types of changes (such as pure additions or deletions), when the end of the file or a new character block, such as "@@ -", is detected, the count of the added counter corresponding to the fixed code character is determined to be equal to the count of the deleted counter; when the count of the added counter is equal to the count of the deleted counter, the count of the added counter and the count of the deleted counter of the fixed code character are reset and added to the count of the modified counter, that is, by checking whether the number of addLines and deleteLines is equal, it is determined whether this change is a modification operation. If it is a modification operation, I merge these line counts into modifyLines instead of adding them to addLines or deleteLines, so that more accurate statistics can be obtained.
[0030] Furthermore, addLines, deleteLines, and modifyLines in each file are gradually accumulated into global variables F_addLines, F_deleteLines, and F_modifyLines. The total changes in the entire project or the specified range are gradually accumulated to form an overall statistical result, and then the counts of the added counters, deleted counters, modified counters, and total changes of each target file are correspondingly saved.
[0031] Furthermore, for the above steps, examples are given to further explain them. The actual method of calculating the amount of code based on SVN logs includes but is not limited to the following schemes: 1. The statistical conditions for receiving SVN logs include SVN address: http: / / svn.example.com, start time: November 1, 2024, end time: November 30, 2024, statistical result file: code_stats_202411.xlsx, file type: .java, developer: zhangsan.
[0032] 2. Query the SVN log and confirm that the corresponding version number on November 1, 2024 is r12345, and the corresponding version number on November 30, 2024 is r12789.
[0033] 3. Use the command svn log -r 12345:12789 to obtain all commit records within the time range.
[0034] 4. Filter out the changes involving .java files submitted by zhangsan from the log.
[0035] 5. Identify which files are newly added, deleted or modified.
[0036] 6. For newly added files, such as src / com / example / NewFeature.java@r12400, use the svnexport command to download them to the local computer. For deleted files, such as src / com / example / OldFeature.java@r12700, also export the version before deletion.
[0037] 7. Initialize the counters addLines=0, deleteLines=0, modifyLines=0, and update the counters according to the file type.
[0038] 8. For modified files, such as src / com / example / Updated.java, use the svn diff -r 12450:12789 command to obtain the specific changes and save them locally.
[0039] 9. Initialize the global counters F_addLines=0, F_deleteLines=0, F_modifyLines=0, and start parsing the difference file line by line.
[0040] 10. When encountering a new block or the end of a file, compare the number of addLines and deleteLines to determine whether it is a modification operation.
[0041] 11. If it is confirmed to be a modification operation, addLines is added to modifyLines, and addLines and deleteLines are reset.
[0042] 12. Gradually accumulate addLines, deleteLines, modifyLines in each file to the global variables F_addLines, F_deleteLines, F_modifyLines.
[0043] 13. Save the final statistical data corresponding to each file to code_stats_202411.xlsx.
[0044] The embodiment of the present invention provides a method for calculating the amount of code based on an SVN log. The method receives the statistical conditions of the SVN log, wherein the statistical conditions include a range condition and basic information, determines a specified log according to the range condition, and filters a target file in the specified log according to the basic information; identifies the file change attribute of the target file, and exports the target file based on the file change attribute; reads and records the code line of each target file that generates a file change, and records the change data of the code line based on the file change attribute, performs data balancing on the change data, and counts the total change data of the code line of the target file. In this way, according to the code change data of the SVN log, the effective code amount of specific conditions can be quickly counted, such as the effective code amount of a staff member, a certain date, and a certain version, which can be quickly and accurately counted.
[0045] See also Figure 2 , Figure 2 Schematic diagram of a system for calculating the amount of code based on SVN logs provided in an embodiment of the present application. Figure 2 As shown, the system comprises: The receiving module S201 is used to receive the statistical conditions of the SVN log, the statistical conditions including the range conditions and basic information, determine the designated log according to the range conditions, and filter the target file in the designated log according to the basic information; An export module S202 is used to identify a file change attribute of the target file and export the target file based on the file change attribute; The recording module S203 is used to read and record the code lines that generate file changes for each target file, and record the change data of the code lines based on the file change attributes, perform data balancing on the change data, and count the total change data of the code lines of the target file.
[0046] In another embodiment, a system for calculating the amount of code based on SVN logs further includes: A detection module, used for determining whether the count of the new addition counter and the count of the deletion counter corresponding to the fixed code character are equal when the end of the file or a new character block is detected; The balancing module is used for resetting the count of the new addition counter and the count of the deletion counter of the fixed code character and adding them to the count of the modification counter when the count of the new addition counter is equal to the count of the deletion counter.
[0047] Those skilled in the art can clearly understand that the technical solutions of the embodiments of the present application can be implemented with the help of software and / or hardware. The "unit" and "module" in this specification refer to software and / or hardware that can independently complete or cooperate with other components to complete specific functions, where the hardware can be, for example, a field programmable gate array (FPGA), an integrated circuit (IC), etc.
[0048] Each processing unit and / or module of the embodiments of the present application may be implemented by an analog circuit that implements the functions described in the embodiments of the present application, or may be implemented by software that executes the functions described in the embodiments of the present application.
[0049] See also Figure 3 , which shows a schematic diagram of the structure of an electronic device involved in an embodiment of the present application, the electronic device can be used to implement Figure 1 The method in the embodiment shown. Figure 3 As shown, the electronic device 300 may include: at least one processor 301 , at least one network interface 304 , a user interface 303 , a memory 305 , and at least one communication bus 302 .
[0050] The communication bus 302 is used to realize the connection and communication between these components.
[0051] The user interface 303 may include a display screen (Display) and a camera (Camera). Optionally, the user interface 303 may also include a standard wired interface and a wireless interface.
[0052] The network interface 304 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).
[0053] Among them, the processor 301 may include one or more processing cores. The processor 301 uses various interfaces and lines to connect various parts of the entire electronic device 300, and executes various functions and processes data of the terminal 300 by running or executing instructions, programs, code sets or instruction sets stored in the memory 305, and calling data stored in the memory 305. Optionally, the processor 301 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 301 can integrate one or a combination of a processor (Central Processing Unit, CPU), an image processor (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 301, and it can be implemented separately through a chip.
[0054] Among them, the memory 305 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory). Optionally, the memory 305 includes a non-transitory computer-readable storage medium. The memory 305 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 305 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 305 may also be optionally at least one storage device located away from the aforementioned processor 301. As Figure 3 As shown, the memory 305 as a computer storage medium may include an operating system, a network communication module, a user interface module, and program instructions.
[0055] exist Figure 3In the electronic device 300 shown, the user interface 303 is mainly used to provide an input interface for the user and obtain the data input by the user; and the processor 301 can be used to call the interactive application generated based on the image stored in the memory 305, and specifically perform the following operations: receiving the statistical conditions of the SVN log, the statistical conditions include the range conditions and basic information, determining the specified log according to the range conditions, and filtering the target file in the specified log according to the basic information; identifying the file change attributes of the target file, and exporting the target file based on the file change attributes; reading and recording the code lines that generate file changes for each target file, and recording the change data of the code lines respectively based on the file change attributes, performing data balancing on the change data, and counting the total change data of the code lines of the target file.
[0056] The present application also provides a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, the steps of the above method are implemented. The computer-readable storage medium may include, but is not limited to, any type of disk, including a floppy disk, an optical disk, a DVD, a CD-ROM, a micro drive, and a magneto-optical disk, a ROM, a RAM, an EPROM, an EEPROM, a DRAM, a VRAM, a flash memory device, a magnetic card or an optical card, a nanosystem (including a molecular memory IC), or any type of medium or device suitable for storing instructions and / or data.
[0057] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0058] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0059] In the several embodiments provided in the present application, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of the units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some service interfaces, and the indirect coupling or communication connection of devices or units can be electrical or other forms.
[0060] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0061] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0062] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a memory, including a number of instructions to enable a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned memory includes: U disk, read-only memory (ROM), random access memory (RAM), mobile hard disk, disk or optical disk and other media that can store program codes.
[0063] A person skilled in the art may understand that all or part of the steps in the various methods of the above embodiments may be completed by entering a program to instruct related hardware, and the program may be stored in a computer-readable memory, which may include a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0064] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
Claims
1. A method for calculating the amount of code based on SVN logs, the method comprising: Receive statistical conditions of SVN logs, the statistical conditions including range conditions and basic information, determine a specified log according to the range conditions, and filter target files in the specified log according to the basic information; Identify the file change attribute of the target file, and export the target file based on the file change attribute; Read and record the code lines that generate file changes for each target file, and record the change data of the code lines based on the file change attributes, perform data balancing on the change data, and count the total change data of the code lines of the target file.
2. The method according to claim 1, characterized in that: The determining the designated log according to the range condition includes: When the range condition is a version number, all SVN logs within the version number range are extracted; When the range condition is a timestamp, the version number update log within the timestamp is obtained, and all SVN logs within the version number range are extracted based on the version number update log.
3. The method according to claim 1, characterized in that The step of identifying the file change attribute of the target file and exporting the target file based on the file change attribute includes: Identify newly added files, deleted files, and modified files in the target file; Export the newly added files and deleted files, define a new counter corresponding to the newly added files and a deletion counter corresponding to the deleted files; The modified file is exported, and the modified code is recorded.
4. The method according to claim 3, characterized in that The recording of the change data of the code lines based on the file change attributes respectively includes: Read the code characters of the newly added file, and when a new symbol is read, increase the count of the new counter; Read the code character of the deletion file, and when the deletion symbol is read, increase the deletion counter; The code characters of the modification file are read, and when the modification symbol is read, the modification counter is increased.
5. The method according to claim 4, characterized in that The performing data balancing on the changed data includes: When the end of the file or a new character block is detected, it is determined whether the count of the added counter corresponding to the fixed code character is equal to the count of the deleted counter; When the count of the newly added counter is equal to the count of the deleted counter, the count of the newly added counter and the count of the deleted counter of the fixed code character are reset and added to the count of the modified counter.
6. The method according to claim 4, characterized in that The method further comprises: The count of the new counter, the count of the deleted counter, the count of the modified counter and the total change data of each target file are saved accordingly.
7. A system for calculating the amount of code based on SVN logs, characterized in that: The system comprises: A receiving module is used to receive statistical conditions of SVN logs, wherein the statistical conditions include range conditions and basic information, determine a designated log according to the range conditions, and filter a target file in the designated log according to the basic information; An export module, used for identifying a file change attribute of the target file, and exporting the target file based on the file change attribute; The recording module is used to read and record the code lines that generate file changes for each target file, and record the change data of the code lines based on the file change attributes, perform data balancing on the change data, and count the total change data of the code lines of the target file.
8. The system according to claim 7, characterized in that The system further comprises: A detection module, used for determining whether the count of the new addition counter and the count of the deletion counter corresponding to the fixed code character are equal when the end of the file or a new character block is detected; The balancing module is used for resetting the count of the new addition counter and the count of the deletion counter of the fixed code character and adding them to the count of the modification counter when the count of the new addition counter is equal to the count of the deletion counter.
9. An electronic device comprising a processor and a memory; The processor is connected to the memory; The memory is used to store executable program code; The processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the method according to any one of claims 1 to 6.
10. A computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the method according to any one of claims 1 to 6 when executed by a processor.