Invention content
For overcome the problems, such as it is above-mentioned due to source code library update cause development efficiency low not in time and update mistake or extremely
It partially solves the above problems, the present invention provides a kind of source code library update method and devices.
According to the first aspect of the invention, a kind of source code library update method is provided, including:
It is small to obtain depth in the catalogue of target source code library according to the predetermined threshold value in the configuration file being generated in advance by S1
In or equal to the predetermined threshold value each directory entry;
S2 obtains each directory entry type according to the title of each directory entry;
S3 executes the corresponding order of type of each directory entry, target source code library corresponding to each directory entry
It is updated;Wherein, the type and the advance associated storage of order.
Specifically, further include before the step S1:
According to the input of user or the file structure of target source code library, the catalogue of the target source code library is obtained;
According to the catalogue of the target source code library and the predetermined threshold value, the configuration file of JSON formats is generated.
Specifically, the step S2 is specifically included:
S21, in each thread being pre-created, using listdir functions enumerate each thread be assigned it is each described
Directory entry;
S22 judges whether the type of each directory entry is preset kind according to the title of each directory entry.
Specifically, include before the step S21:
Obtain the number of logic CPU on the computer of active thread;
The number is multiplied by preset constant, obtains maximum number of threads;
Using 1 to any integer in the maximum number of threads as the number of the thread.
Specifically, the step S22 is specifically included:
If the title suffix of each directory entry is .svn, know that the directory entry is SVN Source code management tools
Directory entry;Alternatively,
If the title suffix of each directory entry is .git, know that the directory entry is git Source code management tools
Directory entry;Alternatively,
If the title suffix of each directory entry is .hg, know that the directory entry is Mercurial Source code management works
The directory entry of tool.
Specifically, further include after the step S3:
The fresh information of the target source code library is stored in log buffer, when the fresh information includes update
Between, the directory entry of the newer target source code library and update result.
According to the second aspect of the invention, a kind of source code library updating device is provided, including:
First acquisition unit, for according to the predetermined threshold value in the configuration file being generated in advance, obtaining target source code library
Catalogue in depth be less than or equal to the predetermined threshold value each directory entry;
Second acquisition unit obtains the type of each directory entry for the title according to each directory entry;
Execution unit, the corresponding order of type for executing each directory entry, source corresponding to each directory entry
Code library is updated, the type and the advance associated storage of order.
Specifically, further include generation unit, be used for:
According to the input of user or the file structure of source code library, the catalogue of the target source code library is obtained;
According to the catalogue of the target source code library and the predetermined threshold value, the configuration file of JSON formats is generated.
A kind of source code library update method of present invention offer and device, this method pass through the catalogue of predetermined threshold value control retrieval
The depth of item reduces unnecessary operation to control the range for needing newer source code library, and it is newer to improve source code library
Speed;Meanwhile different orders is executed according to the type of each directory entry, the target source code library is updated, to
Realization is updated a plurality of types of target source code libraries, and the update of target source code library can carry out automatically, improve out
Efficiency is sent out, newer error rate is reduced.
Specific implementation mode
With reference to the accompanying drawings and examples, the specific implementation mode of the present invention is described in further detail.Implement below
Example is not limited to the scope of the present invention for illustrating the present invention.
A kind of source code library update method is provided in one embodiment of the invention, and Fig. 1 provides for the embodiment of the present invention
Source code library update method overall flow schematic diagram, this method includes:S1, according to default in the configuration file being generated in advance
Threshold value obtains each directory entry that depth in the catalogue of target source code library is less than or equal to the predetermined threshold value;S2, according to each institute
The title of directory entry is stated, the type of each directory entry is obtained;S3 executes the corresponding order of type of each directory entry, right
The corresponding target source code library of each directory entry is updated;Wherein, the type and the advance associated storage of order.
Specifically, in S1, the target source code library is the source code library for needing to be updated.The configuration file is one
The text file of a JSON formats.The catalogue of the good target source code library and pre- is configured in the configuration file defined
If threshold value.The catalogue includes multiple directory entries, and the depth of each directory entry is determined according to the rank of each directory entry,
If the depth of second-level directory item is 1, the depth of three-level directory entry is 2 etc., and wherein second-level directory item is the specific item of first class catalogue item
Item is recorded, three-level directory entry is the subdirectory item of second-level directory item.The predetermined threshold value that user needs to be arranged according to update, to
The corresponding source code library of directory entry for being only less than or equal to the predetermined threshold value to depth is updated, and reduces more new range,
Improve renewal speed.In S2, according to the title of each directory entry, the type of the directory entry is obtained.The directory entry
Type is determined according to the type of the corresponding source code library of the directory entry, and the directory entry of .svn is such as included for title, then is known
The type of the corresponding source code library of the directory entry is the source code library of SVN Source code management tools.The type of the directory entry
For the directory entry of SVN Source code management tools.In S3, for different types of directory entry, different orders is executed to the mesh
The corresponding source code library of record item is updated.Each type corresponds to a kind of order, and the type is associated with the order and deposits in advance
Storage.
The present embodiment needs newer source code library by the depth of the directory entry of predetermined threshold value control retrieval to control
Range, reduce unnecessary operation, improve the newer speed of source code library;Meanwhile it being held according to the type of each directory entry
The different order of row is updated the target source code library, is carried out more to a plurality of types of target source code libraries to realize
Newly, and the update of target source code library can carry out automatically, improve development efficiency, reduce newer error rate.
On the basis of the above embodiments, further include before step S1 described in the present embodiment:According to the input of user or
The file structure of target source code library obtains the catalogue of the target source code library;According to the catalogue of the target source code library
With the predetermined threshold value, the configuration file of JSON formats is generated.
Specifically, the catalogue and the predetermined threshold value of the target source code library can be that user fills in manually, the mesh
The catalogue of mark source code library can also be automatically generated according to the file structure of the target source code library, with specific reference to the target
In source code library between file and the title and file of file, the inclusion relation between file and file generates institute
State the catalogue of target source code library.Since the catalogue of the target source code library is a series of catalogue configured list,
It reads in the configuration file after the catalogue of target source code library, by the catalogue array representation, wherein each of array
One directory entry of catalogue described in element representation, to which the catalogue is mapped as array.It, can be with by the length of the array
Obtain the number of directory entry in configuration file.
The present embodiment stores the catalogue of the target source code library and described pre- by using the configuration file of JSON formats
If threshold value, on the one hand, convenient for extension and later maintenance;On the other hand, control needs the range of newer source code library, reduces not
Necessary operation improves the newer speed of source code library.
On the basis of the various embodiments described above, step S2 described in the present embodiment specifically includes:S21, what is be pre-created
In each thread, the assigned each directory entry of each thread is enumerated using listdir functions;S22, according to each catalogue
The title of item, judges whether the type of each directory entry is preset kind.
Specifically, in the thread being pre-created, the assigned directory entry of the thread is read first, is then passed through
Listdir functions enumerate the assigned directory entry of the thread.According to the title of each directory entry, each directory entry is judged
It is the directory entry of which kind of Source code management tool.The preset kind is determined according to the type of Source code management tool.
On the basis of the above embodiments, include before step S21 described in the present embodiment:Obtain the calculating of active thread
The number of logic CPU on machine;The number is multiplied by preset constant, obtains maximum number of threads;By 1 to the maximum thread
Number of any integer as the thread in number, creates the thread.
Specifically, the thread of respective numbers is created according to the hardware information of computer.With specific reference to the calculating of active thread
The number of the logic CPU configured on machine determines the quantity for the thread for needing to create, and passes through multiprocessing.cpu_count
() obtains the number of the logic CPU.The number of logic CPU on the computer is multiplied by preset constant, obtains maximum thread
Number.The number of thread is created as 1 to any integer in the maximum number of threads.For example, when the preset constant is 2
When, create the number ranging from [1, multiprocessing.cpu_count () * 2] of thread.Then it is read using the thread
Take the catalogue.
Since the catalogue for reading the target resource library needs to occupy a large amount of computer resource in the present embodiment, when described
When directory entry in catalogue is excessive, the processing of single thread can cause treatment effeciency low, with multithreading to the catalogue at
On the one hand reason utilizes the advantage of computer multi -CPU, while handling the thread and UI (User Interface, user interface) of task
Thread is independent, avoids program seemingly-dead, promotes user experience.
On the basis of the above embodiments, step S22 described in the present embodiment specifically includes:If the name of each directory entry
Suffix is referred to as .svn, then knows that the directory entry is the directory entry of SVN Source code management tools;If alternatively, each directory entry
Title suffix be .git, then know the directory entry be git Source code management tools directory entry;If alternatively, each mesh
The title suffix for recording item is .hg, then knows that the directory entry is the directory entry of Mercurial Source code management tools.
Specifically, judge whether each directory entry is certain source code tool according to the title suffix of each directory entry
Directory entry.For example, if the title suffix of each directory entry is .svn, know that the directory entry is SVN Source code managements
The directory entry of tool, execution, which is such as issued orders, is updated the corresponding target source code library of the directory entry:
svn update;
If the title suffix of each directory entry is .git, know that the directory entry is git Source code management tools
Directory entry, execution, which is such as issued orders, is updated the corresponding target source code library of the directory entry:
for remote in git branch-r;
do git branch--track${remote#origin/}$remote;
done;
If the title suffix of each directory entry is .hg, know that the directory entry is Mercurial Source code management works
The directory entry of tool, execution, which is such as issued orders, is updated the corresponding target source code library of the directory entry:
hg update.
The present embodiment obtains the type of the directory entry by the title suffix of each directory entry, i.e., the described directory entry is
The directory entry of which kind of source code tool can support a variety of source code tools, meet the needs of different, be held according to the type of catalogue
The different order of row is updated the target source code library.
On the basis of the various embodiments described above, further include after step S3 described in the present embodiment:By the target source generation
The fresh information in code library is stored in log buffer, and the fresh information includes renewal time, the newer target source code
The directory entry and update result in library.
Specifically, after being updated to the target source code library, the fresh information of the target source code library is deposited
It is put into log buffer.The fresh information is stored in the log buffer with array form, each member in array
Element indicates a update operation note, and the structure of the update operation note is { time, dir, result }.Wherein, time is
The renewal time of the target source code library, dir indicate that the directory entry of the newer target source code library, result indicate more
New result.After all threads are finished, the log buffer is read, the numerical value of fresh information is write during the date is cached
Enter journal file, it is convenient to check and alert in the future.
A kind of source code library updating device is provided in another embodiment of the present invention, and Fig. 2 carries for the embodiment of the present invention
The source code library updating device overall structure diagram of confession, the device include first acquisition unit 1, second acquisition unit 2 and hold
Row unit 3, wherein:
The first acquisition unit 1 is used to, according to the predetermined threshold value in the configuration file being generated in advance, obtain target source generation
Depth is less than or equal to each directory entry of the predetermined threshold value in the catalogue in code library;The second acquisition unit 2 is used for according to each
The title of the directory entry obtains the type of each directory entry;The execution unit 3 is used to execute the class of each directory entry
The corresponding order of type is updated the corresponding source code library of each directory entry, and the type is associated in advance with the order
Storage.
Specifically, the target source code library is the source code library for needing to be updated.The configuration file is one
The text file of JSON formats.The catalogue of the good target source code library is configured in the configuration file defined and is preset
Threshold value.The catalogue includes multiple directory entries, the depth of each directory entry is determined according to the rank of each directory entry, such as
The depth of second-level directory item is 1, and the depth of three-level directory entry is 2 etc., and wherein second-level directory item is the subdirectory of first class catalogue item
, three-level directory entry is the subdirectory item of second-level directory item.The predetermined threshold value that user needs to be arranged according to update, to only
The corresponding source code library of directory entry for being less than or equal to the predetermined threshold value to depth is updated, and is reduced more new range, is carried
High renewal speed.The first acquisition unit 1 obtains target source generation according to the predetermined threshold value in the configuration file being generated in advance
Depth is less than or equal to each directory entry of the predetermined threshold value in the catalogue in code library.The second acquisition unit 2 is according to each described
The title of directory entry obtains the type of the directory entry.The type of the directory entry is according to the corresponding source code of the directory entry
The type in library determines, the directory entry of .svn is such as included for title, then knows the type of the corresponding source code library of the directory entry
For the source code library of SVN Source code management tools.The type of the directory entry is the directory entry of SVN Source code management tools.It is right
In different types of directory entry, the execution unit 3 executes different orders and is carried out to the corresponding source code library of the directory entry
Update.Each type corresponds to a kind of order, the type and the advance associated storage of order.
The present embodiment needs newer source code library by the depth of the directory entry of predetermined threshold value control retrieval to control
Range, reduce unnecessary operation, improve the newer speed of source code library;Meanwhile it being held according to the type of each directory entry
The different order of row is updated the target source code library, is carried out more to a plurality of types of target source code libraries to realize
Newly, and the update of target source code library can carry out automatically, improve development efficiency, reduce newer error rate.
On the basis of the above embodiments, in the present embodiment further include generation unit, be used for the input according to user or mesh
The file structure for marking source code library, obtains the catalogue of the target source code library;According to the catalogue of the target source code library and
The predetermined threshold value generates the configuration file of JSON formats.
Specifically, the catalogue and the predetermined threshold value of the target source code library can be that user fills in manually, the mesh
The catalogue of mark source code library can also be automatically generated according to the file structure of the target source code library, with specific reference to the target
In source code library between file and the title and file of file, the inclusion relation between file and file generates institute
State the catalogue of target source code library.Since the catalogue of the target source code library is a series of catalogue configured list,
It reads in the configuration file after the catalogue of target source code library, by the catalogue array representation, wherein each of array
One directory entry of catalogue described in element representation, to which the catalogue is mapped as array.It, can be with by the length of the array
Obtain the number of directory entry in configuration file.
The present embodiment stores the catalogue of the target source code library and described pre- by using the configuration file of JSON formats
If threshold value, on the one hand, convenient for extension and later maintenance;On the other hand, control needs the range of newer source code library, reduces not
Necessary operation improves the newer speed of source code library.
On the basis of the above embodiments, second acquisition unit described in the present embodiment includes enumerating subelement and judging sub
Unit, wherein:
The subelement of enumerating is in each thread being pre-created, each thread to be enumerated using listdir functions
Assigned each directory entry;The judgment sub-unit is used for the title according to each directory entry, judges each catalogue
Whether the type of item is preset kind.
Further include creating unit in the present embodiment, by obtaining based on active thread on the basis of the various embodiments described above
The number of logic CPU on calculation machine;The number is multiplied by preset constant, obtains maximum number of threads;By 1 to the maximum thread
Number of any integer as the thread in number, creates the thread.
On the basis of the above embodiments, judgment sub-unit described in the present embodiment is specifically used for:If each directory entry
Title suffix be .svn, then know the directory entry be SVN Source code management tools directory entry;If alternatively, each mesh
The title suffix for recording item is .git, then knows that the directory entry is the directory entry of git Source code management tools;If alternatively, each institute
The title suffix for stating directory entry is .hg, then knows that the directory entry is the directory entry of Mercurial Source code management tools.
Further include storage unit in the present embodiment on the basis of the various embodiments described above, is used for the target source code
The fresh information in library is stored in log buffer, and the fresh information includes renewal time, the newer target source code library
Directory entry and update result.
The present embodiment provides a kind of source code library more new equipment, Fig. 3 updates for source code library provided in an embodiment of the present invention
Equipment overall structure schematic diagram, the equipment include:At least one processor 31, at least one processor 32 and bus 33;Wherein,
The processor 31 and memory 32 complete mutual communication by the bus 33;
The memory 32 is stored with the program instruction that can be executed by the processor 31, and the processor calls the journey
Sequence instruction is able to carry out the method that above-mentioned each method embodiment is provided, such as including:S1, according to the configuration file being generated in advance
In predetermined threshold value, obtain target source code library catalogue in depth be less than or equal to the predetermined threshold value each directory entry;S2,
According to the title of each directory entry, the type of each directory entry is obtained;S3, the type for executing each directory entry are corresponding
Order is updated the corresponding target source code library of each directory entry;Wherein, the type is associated in advance with the order
Storage.
The present embodiment provides a kind of non-transient computer readable storage medium, the non-transient computer readable storage medium
Computer instruction is stored, the computer instruction makes the computer execute the method that above-mentioned each method embodiment is provided, example
Such as include:S1 obtains depth in the catalogue of target source code library and is less than according to the predetermined threshold value in the configuration file being generated in advance
Or each directory entry equal to the predetermined threshold value;S2 obtains the class of each directory entry according to the title of each directory entry
Type;S3 executes the corresponding order of type of each directory entry, is carried out more to the corresponding target source code library of each directory entry
Newly;Wherein, the type and the advance associated storage of order.
One of ordinary skill in the art will appreciate that:Realize that all or part of step of above method embodiment can pass through
The relevant hardware of program instruction is completed, and program above-mentioned can be stored in a computer read/write memory medium, the program
When being executed, step including the steps of the foregoing method embodiments is executed;And storage medium above-mentioned includes:ROM, RAM, magnetic disc or light
The various media that can store program code such as disk.
Source code library update apparatus embodiments described above are only schematical, wherein described be used as separating component
The unit of explanation may or may not be physically separated, and the component shown as unit can be or can also
It is not physical unit, you can be located at a place, or may be distributed over multiple network units.It can be according to actual
It needs that some or all of module therein is selected to achieve the purpose of the solution of this embodiment.Those of ordinary skill in the art are not
In the case of paying performing creative labour, you can to understand and implement.
Through the above description of the embodiments, those skilled in the art can be understood that each embodiment can
It is realized by the mode of software plus required general hardware platform, naturally it is also possible to pass through hardware.Based on this understanding, on
Stating technical solution, substantially the part that contributes to existing technology can be expressed in the form of software products in other words, should
Computer software product can store in a computer-readable storage medium, such as ROM/RAM, magnetic disc, CD, including several fingers
It enables and using so that a computer equipment (can be personal computer, server or the network equipment etc.) executes each implementation
Method described in certain parts of example or embodiment.
Finally, the present processes are only preferable embodiment, are not intended to limit the scope of the present invention.It is all
Within the spirit and principles in the present invention, any modification, equivalent replacement, improvement and so on should be included in the protection of the present invention
Within the scope of.