Disclosure of Invention
In order to overcome the problems of low development efficiency and update errors caused by untimely update of the source code library or at least partially solve the problems, the invention provides a method and a device for updating the source code library.
According to a first aspect of the present invention, there is provided a source code library updating method, including:
s1, according to a preset threshold value in a pre-generated configuration file, obtaining each directory item with the depth less than or equal to the preset threshold value in the directory of the target source code library;
s2, obtaining the type of each directory entry according to the name of each directory entry;
s3, executing the command corresponding to the type of each directory entry, and updating the target source code library corresponding to each directory entry; wherein the type is stored in pre-association with the command.
Specifically, the step S1 is preceded by:
acquiring a directory of a target source code library according to input of a user or a document structure of the target source code library;
and generating a configuration file in a JSON format according to the directory of the target source code library and the preset threshold.
Specifically, the step S2 specifically includes:
s21, enumerating each directory entry allocated to each thread by using a listdir function in each pre-created thread;
and S22, judging whether the type of each directory entry is a preset type according to the name of each directory entry.
Specifically, the step S21 includes, before:
acquiring the number of logic CPUs on a computer running a thread;
multiplying the number by a preset constant to obtain the maximum number of threads;
and taking any integer from 1 to the maximum number of threads as the number of the threads.
Specifically, the step S22 specifically includes:
if the name suffix of each directory entry is SVN, acquiring that the directory entry is a directory entry of an SVN source code management tool; alternatively, the first and second electrodes may be,
if the name suffix of each directory entry is git, acquiring that the directory entry is the directory entry of the git source code management tool; alternatively, the first and second electrodes may be,
if the name suffix of each directory entry is hg, the directory entry is known to be a directory entry of the Mercurial source code management tool.
Specifically, the step S3 is followed by:
and storing the update information of the target source code library into a log cache, wherein the update information comprises update time, the directory entry of the updated target source code library and an update result.
According to a second aspect of the present invention, there is provided a source code library updating apparatus, including:
the first obtaining unit is used for obtaining each directory item with the depth smaller than or equal to a preset threshold value in a directory of a target source code library according to the preset threshold value in a pre-generated configuration file;
a second obtaining unit, configured to obtain a type of each directory entry according to a name of each directory entry;
and the execution unit is used for executing the command corresponding to the type of each directory entry and updating the source code library corresponding to each directory entry, wherein the type and the command are stored in a pre-associated manner.
Specifically, the system further comprises a generating unit, configured to:
acquiring a directory of the target source code library according to the input of a user or the document structure of the source code library;
and generating a configuration file in a JSON format according to the directory of the target source code library and the preset threshold.
The invention provides a method and a device for updating a source code library, wherein the method controls the depth of a retrieved directory entry through a preset threshold value, thereby controlling the range of the source code library needing to be updated, reducing unnecessary operation and improving the updating speed of the source code library; meanwhile, different commands are executed according to the types of the directory entries to update the target source code base, so that various types of target source code bases can be updated, the target source code base can be automatically updated, the development efficiency is improved, and the update error rate is reduced.
Detailed Description
The following detailed description of embodiments of the present invention is provided in connection with the accompanying drawings and examples. The following examples are intended to illustrate the invention but are not intended to limit the scope of the invention.
Fig. 1 is a schematic overall flow chart of a source code library updating method provided in an embodiment of the present invention, where the method includes: s1, according to a preset threshold value in a pre-generated configuration file, obtaining each directory item with the depth less than or equal to the preset threshold value in the directory of the target source code library; s2, acquiring the type of each directory entry according to the name of each directory entry; s3, executing the command corresponding to the type of each directory entry, and updating the target source code library corresponding to each directory entry; wherein the type is stored in pre-association with the command.
Specifically, in S1, the target source code library is a source code library that needs to be updated. The configuration file is a text file in a JSON format. Configuring the directory and the preset threshold of the target source code library in the defined configuration file. The directory comprises a plurality of directory entries, and the depth of each directory entry is determined according to the level of each directory entry, for example, the depth of a second-level directory entry is 1, the depth of a third-level directory entry is 2, and the like, wherein the second-level directory entry is a subdirectory entry of the first-level directory entry, and the third-level directory entry is a subdirectory entry of the second-level directory entry. The user can set the preset threshold value according to the updating requirement, so that only the source code base corresponding to the directory entry with the depth less than or equal to the preset threshold value is updated, the updating range is narrowed, and the updating speed is improved. In S2, the type of each directory entry is obtained according to the name of the directory entry. And determining the type of the directory entry according to the type of the source code library corresponding to the directory entry, and if the directory entry of the name contains SVN, acquiring that the type of the source code library corresponding to the directory entry is the source code library of the SVN source code management tool. The type of the directory entry is the directory entry of the SVN source code management tool. In S3, for different types of directory entries, different commands are executed to update the source code libraries corresponding to the directory entries. Each type corresponds to a command, and the type and the command are stored in a pre-association mode.
In the embodiment, the depth of the retrieved directory entry is controlled by a preset threshold value, so that the range of the source code library needing to be updated is controlled, unnecessary operations are reduced, and the updating speed of the source code library is increased; meanwhile, different commands are executed according to the types of the directory entries to update the target source code base, so that various types of target source code bases can be updated, the target source code base can be automatically updated, the development efficiency is improved, and the update error rate is reduced.
On the basis of the foregoing embodiment, step S1 in this embodiment further includes: acquiring a directory of a target source code library according to input of a user or a document structure of the target source code library; and generating a configuration file in a JSON format according to the directory of the target source code library and the preset threshold.
Specifically, the directory of the target source code library and the preset threshold may be manually filled by a user, and the directory of the target source code library may also be automatically generated according to a document structure of the target source code library, specifically, the directory of the target source code library is generated according to names of folders and files in the target source code library, and inclusion relationships between the folders and the files. Since the directory of the target source code library is a series of directory configuration lists, after the directory of the target source code library in the configuration file is read, the directory is represented by an array, wherein each element in the array represents a directory entry of the directory, so that the directory is mapped into the array. And the number of directory entries in the configuration file can be acquired through the length of the array.
In the embodiment, the configuration file in the JSON format is used for storing the directory of the target source code library and the preset threshold, so that on one hand, the expansion and the later maintenance are facilitated; on the other hand, the range of the source code base needing to be updated is controlled, unnecessary operation is reduced, and the updating speed of the source code base is improved.
On the basis of the foregoing embodiments, in this embodiment, the step S2 specifically includes: s21, enumerating each directory entry allocated to each thread by using a listdir function in each pre-created thread; and S22, judging whether the type of each directory entry is a preset type according to the name of each directory entry.
Specifically, in a pre-created thread, firstly, the directory entry allocated to the thread is read, and then the directory entry allocated to the thread is enumerated through a listdir function. And judging which directory entry of the source code management tool is each directory entry according to the name of each directory entry. The preset type is determined according to the type of the source code management tool.
On the basis of the foregoing embodiment, the step S21 in this embodiment includes: acquiring the number of logic CPUs on a computer running a thread; multiplying the number by a preset constant to obtain the maximum number of threads; and taking any integer from 1 to the maximum number of threads as the number of the threads, and creating the threads.
Specifically, a corresponding number of threads are created from the hardware information of the computer. Specifically, the number of threads to be created is determined according to the number of logical CPUs configured on a computer running the threads, and the number of the logical CPUs is obtained through multiprocessing. And multiplying the number of the logic CPUs on the computer by a preset constant to obtain the maximum number of threads. The number of creating threads is any integer from 1 to the maximum number of threads. For example, when the preset constant is 2, the number of created threads ranges from [1, multiprocessing. The directory is then read using the thread.
In this embodiment, since reading the directory of the target resource library needs to occupy a large amount of computer resources, when directory entries in the directory are too many, processing efficiency is low due to single-thread processing, and processing the directory by using multiple threads utilizes advantages of multiple CPUs of the computer on the one hand, and simultaneously, a thread for processing a task is independent from a UI (User Interface) thread, thereby avoiding a false death of a program and improving User experience.
On the basis of the foregoing embodiment, step S22 in this embodiment specifically includes: if the name suffix of each directory entry is SVN, acquiring that the directory entry is a directory entry of an SVN source code management tool; or if the name suffix of each directory entry is git, acquiring that the directory entry is the directory entry of the git source code management tool; or, if the name suffix of each directory entry is hg, the directory entry is known to be the directory entry of the Mercurial source code management tool.
Specifically, whether each directory entry is a directory entry of a certain source code tool is judged according to the name suffix of each directory entry. For example, if the name suffix of each directory entry is SVN, it is known that the directory entry is a directory entry of an SVN source code management tool, and the following command is executed to update the target source code library corresponding to the directory entry:
svn update;
if the suffix of the name of each directory entry is.git, knowing that the directory entry is the directory entry of the git source code management tool, executing the following command to update the target source code library corresponding to the directory entry:
for remote in git branch-r;
do git branch--track${remote#origin/}$remote;
done;
if the suffix of the name of each directory entry is hg, knowing that the directory entry is the directory entry of the Mercurial source code management tool, executing the following commands to update the target source code library corresponding to the directory entry:
hg update.
in this embodiment, the type of the directory entry is obtained through the name suffix of each directory entry, that is, the directory entry is the directory entry of which source code tool, so that multiple source code tools can be supported, different requirements are met, and different commands are executed according to the type of the directory to update the target source code library.
On the basis of the foregoing embodiments, in this embodiment, after the step S3, the method further includes: and storing the update information of the target source code library into a log cache, wherein the update information comprises update time, the directory entry of the updated target source code library and an update result.
Specifically, after the target source code library is updated, the update information of the target source code library is stored in a log cache. The update information is stored in the log cache in an array form, each element in the array represents an update operation record, and the structure of the update operation record is { time, dir, result }. Wherein, time is the update time of the target source code base, dir represents the directory entry of the updated target source code base, and result represents the update result. And after all threads are executed, reading the log cache, and writing the numerical value of the updated information in the date cache into a log file, so that the log file is convenient to view and warn in the future.
In another embodiment of the present invention, a source code library updating apparatus is provided, and fig. 2 is a schematic diagram of an overall structure of the source code library updating apparatus provided in the embodiment of the present invention, where the apparatus includes a first obtaining unit 1, a second obtaining unit 2, and an executing unit 3, where:
the first obtaining unit 1 is configured to obtain, according to a preset threshold in a pre-generated configuration file, each directory entry in a directory of a target source code library, where a depth of the directory entry is less than or equal to the preset threshold; the second obtaining unit 2 is configured to obtain a type of each directory entry according to a name of each directory entry; the execution unit 3 is configured to execute a command corresponding to a type of each directory entry, and update a source code library corresponding to each directory entry, where the type and the command are stored in association with each other in advance.
Specifically, the target source code library is a source code library that needs to be updated. The configuration file is a text file in a JSON format. Configuring the directory and the preset threshold of the target source code library in the defined configuration file. The directory comprises a plurality of directory entries, and the depth of each directory entry is determined according to the level of each directory entry, for example, the depth of a second-level directory entry is 1, the depth of a third-level directory entry is 2, and the like, wherein the second-level directory entry is a subdirectory entry of the first-level directory entry, and the third-level directory entry is a subdirectory entry of the second-level directory entry. The user can set the preset threshold value according to the updating requirement, so that only the source code base corresponding to the directory entry with the depth less than or equal to the preset threshold value is updated, the updating range is narrowed, and the updating speed is improved. The first obtaining unit 1 obtains each directory entry with a depth less than or equal to a preset threshold in a directory of a target source code library according to the preset threshold in a pre-generated configuration file. The second obtaining unit 2 obtains the type of each directory entry according to the name of the directory entry. And determining the type of the directory entry according to the type of the source code library corresponding to the directory entry, and if the directory entry of the name contains SVN, acquiring that the type of the source code library corresponding to the directory entry is the source code library of the SVN source code management tool. The type of the directory entry is the directory entry of the SVN source code management tool. For different types of directory entries, the execution unit 3 executes different commands to update the source code base corresponding to the directory entry. Each type corresponds to a command, and the type and the command are stored in a pre-association mode.
In the embodiment, the depth of the retrieved directory entry is controlled by a preset threshold value, so that the range of the source code library needing to be updated is controlled, unnecessary operations are reduced, and the updating speed of the source code library is increased; meanwhile, different commands are executed according to the types of the directory entries to update the target source code base, so that various types of target source code bases can be updated, the target source code base can be automatically updated, the development efficiency is improved, and the update error rate is reduced.
On the basis of the above embodiment, the present embodiment further includes a generating unit, configured to obtain a directory of a target source code library according to an input of a user or a document structure of the target source code library; and generating a configuration file in a JSON format according to the directory of the target source code library and the preset threshold.
Specifically, the directory of the target source code library and the preset threshold may be manually filled by a user, and the directory of the target source code library may also be automatically generated according to a document structure of the target source code library, specifically, the directory of the target source code library is generated according to names of folders and files in the target source code library, and inclusion relationships between the folders and the files. Since the directory of the target source code library is a series of directory configuration lists, after the directory of the target source code library in the configuration file is read, the directory is represented by an array, wherein each element in the array represents a directory entry of the directory, so that the directory is mapped into the array. And the number of directory entries in the configuration file can be acquired through the length of the array.
In the embodiment, the configuration file in the JSON format is used for storing the directory of the target source code library and the preset threshold, so that on one hand, the expansion and the later maintenance are facilitated; on the other hand, the range of the source code base needing to be updated is controlled, unnecessary operation is reduced, and the updating speed of the source code base is improved.
On the basis of the foregoing embodiment, in this embodiment, the second obtaining unit includes an enumeration subunit and a judgment subunit, where:
the enumeration subunit is configured to enumerate, in each pre-created thread, each directory entry allocated to each thread by using a listdir function; the judging subunit is configured to judge whether the type of each directory entry is a preset type according to the name of each directory entry.
On the basis of the above embodiments, the present embodiment further includes a creating unit, configured to obtain the number of logical CPUs on the computer running the thread; multiplying the number by a preset constant to obtain the maximum number of threads; and taking any integer from 1 to the maximum number of threads as the number of the threads, and creating the threads.
On the basis of the foregoing embodiment, in this embodiment, the determining subunit is specifically configured to: if the name suffix of each directory entry is SVN, acquiring that the directory entry is a directory entry of an SVN source code management tool; or if the name suffix of each directory entry is git, acquiring that the directory entry is the directory entry of the git source code management tool; or, if the name suffix of each directory entry is hg, the directory entry is known to be the directory entry of the Mercurial source code management tool.
On the basis of the foregoing embodiments, in this embodiment, the storage unit is further configured to store update information of the target source code library in a log cache, where the update information includes an update time, an updated directory entry of the target source code library, and an update result.
This embodiment provides a source code library updating device, and fig. 3 is a schematic diagram of an overall structure of the source code library updating device provided in this embodiment of the present invention, where the device includes: at least one processor 31, at least one memory 32, and a bus 33; wherein the content of the first and second substances,
the processor 31 and the memory 32 complete mutual communication through the bus 33;
the memory 32 stores program instructions executable by the processor 31, and the processor calls the program instructions to execute the methods provided by the method embodiments, for example, the method includes: s1, according to a preset threshold value in a pre-generated configuration file, obtaining each directory item with the depth less than or equal to the preset threshold value in the directory of the target source code library; s2, acquiring the type of each directory entry according to the name of each directory entry; s3, executing the command corresponding to the type of each directory entry, and updating the target source code library corresponding to each directory entry; wherein the type is stored in pre-association with the command.
The present embodiments provide a non-transitory computer-readable storage medium storing computer instructions that cause the computer to perform the methods provided by the above method embodiments, for example, including: s1, according to a preset threshold value in a pre-generated configuration file, obtaining each directory item with the depth less than or equal to the preset threshold value in the directory of the target source code library; s2, acquiring the type of each directory entry according to the name of each directory entry; s3, executing the command corresponding to the type of each directory entry, and updating the target source code library corresponding to each directory entry; wherein the type is stored in pre-association with the command.
Those of ordinary skill in the art will understand that: all or part of the steps for implementing the method embodiments may be implemented by hardware related to program instructions, and the program may be stored in a computer readable storage medium, and when executed, the program performs the steps including the method embodiments; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
The above-described embodiments of the source code library updating apparatus are merely illustrative, where the units illustrated as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, may be located in one place, or may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
Finally, the method of the present application is only a preferred embodiment and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.