Cocoapods code pulling optimization method and system
By defining the preset code configuration protocol in the CocoaPods configuration file, the problem of slow code retrieval speed in iOS projects is solved, achieving an efficient balance between local and remote downloads and improving code retrieval speed.
Patent Information
- Application Number
- CN202010827149.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-08-17
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2040-08-17
AI Technical Summary
When using CocoaPods in an iOS project, switching back and forth between code fetch protocols can slow down the code fetching process.
By determining the preset code configuration protocol in the CocoaPods configuration file, when the local directory and the remote address are consistent, the code is switched to the local branch and the code from the remote branch is pulled. The preset code configuration protocol supports local and remote downloads, avoiding the need to switch protocols back and forth.
It reduced the cost of code retrieval and increased the speed of code retrieval.
Smart Images

Figure CN112114864B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer software application technology, and more specifically, to a cocoapods code pulling optimization method and system. Background Art
[0002] Currently, cocoapods is used to pull code in iOS projects. Cocoapods supports pulling code from remote git and importing code from local paths for project application development. When you need to import code from a local path, you need to use the following protocol implementation:
[0003] pod'abc',:path=>'.. / abc'.
[0004] When you need to pull code from a remote git, you need to use the following protocol:
[0005] pod'abc',:git=>'http: / / agc.git',:branch=>'master'.
[0006] When cocoapods needs to pull code from the remote git and introduce code from the local path, it will cause the pull protocol to switch back and forth, increase the cost of code pulling, and cause the speed of pulling code to be very slow.
[0007] Therefore, there is an urgent need to provide a cocoapods code pulling optimization method and system. Summary of the invention
[0008] In order to overcome the above problems or at least partially solve the above problems, an embodiment of the present invention provides a cocoapods code pulling optimization method and system.
[0009] In a first aspect, an embodiment of the present invention provides a cocoapods code pulling optimization method, comprising:
[0010] Determine that the code configuration protocol in the cocoapods configuration file is a preset code configuration protocol; the preset code configuration protocol includes a local code directory, a preset remote address, and a preset branch;
[0011] If it is determined that the local code directory is not empty and the remote address of the code in the local code directory is consistent with the preset remote address, the code in the local code directory is switched to the local branch pointed to by the specific content of the preset branch, and the code of the remote branch pointed to by the specific content of the preset branch is pulled to the local branch.
[0012] Preferably, determining that the code configuration protocol in the cocoapods configuration file is a preset code configuration protocol specifically includes:
[0013] If the code configuration protocol in the cocoapods configuration file is not the preset code configuration protocol, the code configuration protocol is converted into the preset code configuration protocol.
[0014] Preferably, the cocoapods code pulling optimization method further includes:
[0015] If it is determined that the local code directory is empty, or the local code directory is not empty and the remote address of the code in the local code directory is inconsistent with the preset remote address, the local code directory is deleted, the code of the preset remote address is obtained, and the code of the preset remote address is switched to the local branch.
[0016] Preferably, the code for obtaining the preset remote address specifically includes:
[0017] Based on git clone, obtain the code of the preset remote address.
[0018] Preferably, pulling the code of the remote branch to the local branch specifically includes:
[0019] Pull the code in the remote branch that is different from the code in the local branch to the local branch.
[0020] Preferably, pulling the code of the remote branch to the local branch specifically includes:
[0021] Based on git pull --rebase, pull the code of the remote branch to the local branch.
[0022] In a second aspect, an embodiment of the present invention provides a cocoapods code pull optimization system, including: a determination module and a pull module.
[0023] The determination module is used to determine that the code configuration protocol in the cocoapods configuration file is a preset code configuration protocol; the preset code configuration protocol includes a code local directory, a preset remote address and a preset branch;
[0024] The pulling module is used to switch the code of the local code directory to the local branch pointed to by the specific content of the preset branch if it is determined that the local code directory is not empty and the remote address of the code of the local code directory is consistent with the preset remote address, and pull the code of the remote branch pointed to by the specific content of the preset branch to the local branch.
[0025] Preferably, the determining module is specifically used for:
[0026] If the code configuration protocol in the cocoapods configuration file is not the preset code configuration protocol, the code configuration protocol is converted into the preset code configuration protocol.
[0027] Preferably, the pulling module is also used for:
[0028] If it is determined that the local code directory is empty, or the local code directory is not empty and the remote address of the code in the local code directory is inconsistent with the preset remote address, the local code directory is deleted, the code of the preset remote address is obtained, and the code of the preset remote address is switched to the local branch.
[0029] In a third aspect, an embodiment of the present invention provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the cocoapods code pulling optimization method described in the first aspect are implemented.
[0030] In a fourth aspect, an embodiment of the present invention provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the cocoapods code pulling optimization method as described in the first aspect.
[0031] The embodiment of the present invention provides a cocoapods code pulling optimization method and system, which first determines that the code configuration protocol in the cocoapods configuration file is a preset code configuration protocol, and then if it is determined that the local directory of the code is not empty, and the remote address of the code in the local directory of the code is consistent with the preset remote address, the code is switched to the local branch, and the code of the remote branch is pulled to the local branch. The preset code configuration protocol can support local development and remote downloading at the same time, taking into account both local developers and remote downloading. When cocoapods needs to pull code from the remote git and introduce code from the local path, it can be achieved without switching the pull protocol back and forth, which reduces the cost of code pulling and improves the speed of pulling code. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. 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.
[0033] Figure 1 A schematic diagram of a process flow of a cocoapods code pulling optimization method provided by an embodiment of the present invention;
[0034] Figure 2 A schematic diagram of the structure of a cocoapods code pulling optimization system provided by an embodiment of the present invention;
[0035] Figure 3 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0036] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are 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.
[0037] At present, when code is pulled through cocoapods, cocoapods supports pulling code from remote git and importing code from local path for engineering application development. When cocoapods needs to pull code from remote git and import code from local path, it will cause the pull protocol to switch back and forth, increase the cost of code pulling, and cause the speed of pulling code to be very slow. To this end, an embodiment of the present invention provides a cocoapods code pulling optimization method.
[0038] like Figure 1 As shown, the cocoapods code pulling optimization method provided by the embodiment of the present invention includes:
[0039] S1, determining that the code configuration protocol in the cocoapods configuration file is a preset code configuration protocol; the preset code configuration protocol includes a local code directory, a preset remote address, and a preset branch;
[0040] S2. If it is determined that the local directory of the code is not empty, and the remote address of the code in the local directory of the code is consistent with the preset remote address, the code in the local directory of the code is switched to the local branch pointed to by the specific content of the preset branch, and the code of the remote branch pointed to by the specific content of the preset branch is pulled to the local branch.
[0041] Specifically, in the embodiment of the present invention, when code pulling is implemented through cocoapods, step S1 is first performed. The cocoapods configuration file includes a code configuration protocol. For example, the code configuration protocol commonly used when cocoapods pulls code from a remote git is configuration protocol 1:
[0042] pod'abc',:path=>'.. / abc';
[0043] The commonly used code configuration protocol when cocoapods imports code from the local path is configuration protocol 2:
[0044] pod'abc',:git=>'http: / / agc.git',:branch=>'master'.
[0045] When determining that the code configuration protocol in the cocoapods configuration file is the preset code configuration protocol, this can be achieved by scanning the cocoapods configuration file.
[0046] In the embodiment of the present invention, the preset code configuration protocol is different from the above-mentioned configuration protocol 1 or configuration protocol 2. The preset code configuration protocol includes a code local directory, a preset remote address and a preset branch, and the specific form is:
[0047] pod'podname',:path=>'.. / podname',:sourceUrl=>'http: / / abc.git',:sourceBranch=>'master'
[0048] Among them, "pod" is the key field of cocoapods, "podname" is the name of the code component, ":path" is the local directory of the code, ".. / podname" is the specific content of the local directory of the code, ":sourceUrl" is the preset remote address, that is, the remote address of the code component, "http: / / abc.git" is the specific content of the preset remote address, ":sourceBranch" is the preset branch, "master" is the specific content of the preset branch, and ":sourceBranch" includes remote branches and local branches.
[0049] Then execute step S2. Determine whether the local code directory in the preset code configuration protocol is empty, that is, determine whether the directory ".. / podname" exists locally. If ".. / podname" exists locally, that is, the local code directory in the preset code configuration protocol is not empty, further determine whether the remote address of the code in the local code directory is consistent with the preset remote address in the preset code configuration protocol, that is, determine whether the remote address of the code in the local code directory is consistent with "http: / / abc.git". If they are consistent, the code in the local code directory can be switched to the ":sourceBranch" local branch, that is, the code in the local code directory points to the ":sourceBranch" local branch, and the code in the ":sourceBranch" local branch can be synchronized with the code in the local code directory. Then pull the code of the ":sourceBranch" remote branch to the local branch, and the local code directory also contains the pulled remote branch code.
[0050] The first half of the preset code configuration protocol is the same as configuration protocol 1, and can be recognized by cocoapods. Therefore, when cocoapods pulls code, it can identify the specific content of the local directory of the code in the preset code configuration protocol, that is, it can identify both local code and the pulled remote branch code. When cocoapods needs to pull code from the remote git and introduce code from the local path, it does not need to switch the pull protocol back and forth, which reduces the cost of code pulling and increases the speed of pulling code.
[0051] The cocoapods code pulling optimization method provided in the embodiment of the present invention first determines that the code configuration protocol in the cocoapods configuration file is a preset code configuration protocol, and then if it is determined that the local directory of the code is not empty, and the remote address of the code in the local directory of the code is consistent with the preset remote address, the code is switched to the local branch, and the code of the remote branch is pulled to the local branch. The preset code configuration protocol can support local development and remote downloading at the same time, taking into account both local developers and remote downloading. When cocoapods needs to pull code from the remote git and introduce code from the local path, it can be achieved without switching the pull protocol used back and forth, which reduces the cost of code pulling and improves the speed of pulling code.
[0052] On the basis of the above embodiment, the cocoapods code pulling optimization method provided in the embodiment of the present invention, wherein determining the code configuration protocol in the cocoapods configuration file as a preset code configuration protocol specifically includes:
[0053] If the code configuration protocol in the cocoapods configuration file is not the preset code configuration protocol, the code configuration protocol is converted into the preset code configuration protocol.
[0054] Specifically, in the embodiment of the present invention, when executing step S1, it is necessary to determine whether the code configuration protocol in the cocoapods configuration file is a preset code configuration protocol. If the code configuration protocol in the cocoapods configuration file is not a preset code configuration protocol, it needs to be converted into a preset code configuration protocol. If the code configuration protocol in the cocoapods configuration file is a preset code configuration protocol, then step S2 can be executed.
[0055] Taking the code configuration protocol in the cocoapods configuration file as the above configuration protocol 2 as an example, it is necessary to convert configuration protocol 2 into the preset code configuration protocol. The specific process of converting configuration protocol 2 into the preset code configuration protocol is as follows:
[0056] For each field in configuration protocol 2:
[0057] 1) "podname": remains unchanged and is the name of the code component;
[0058] 2) Add the ":path" field and set its value to ".. / podname" as the local directory for storing code components;
[0059] 3) ":git": extract the warehouse url value in ":git", add the ":sourceUrl" field, assign the extracted warehouse url value in ":git" to the ":sourceUrl" field, and remove the ":git" field;
[0060] 4) “:branch”: Take out the warehouse url value in “:branch”, add the “:sourceBranch” field, assign the warehouse url value taken out from “:branch” to the “:sourceBranch” field, and remove the “:branch” field.
[0061] On the basis of the above embodiment, the cocoapods code pulling optimization method provided in the embodiment of the present invention further includes:
[0062] If it is determined that the local code directory is empty, or the local code directory is not empty and the remote address of the code in the local code directory is inconsistent with the preset remote address, the local code directory is deleted, the code of the preset remote address is obtained, and the code of the preset remote address is switched to the local branch.
[0063] Specifically, in an embodiment of the present invention, when the local directory of code is empty, that is, the local directory of code ".. / podname" does not exist locally, or the local directory of code is not empty and the remote address of the code in the local directory of code is inconsistent with the preset remote address, the local directory of code is deleted. Then, the code of the preset remote address is obtained, that is, the code is obtained from "http: / / abc.git" pointed to by ":sourceUrl", and then the code of the preset remote address is switched to the local branch, that is, the code obtained from "http: / / abc.git" is switched to the local branch ":sourceBranch". After obtaining the code of the preset remote address and switching the code to the local branch ":sourceBranch", the local directory of code is automatically generated, that is, ".. / podname" is automatically generated. Therefore, the situation that the local directory of code is empty, or the local directory of code is not empty and the remote address of the code in the local directory of code is inconsistent with the preset remote address, will only occur when the cocoapods code is pulled for the first time, and the subsequent local directory of code will meet the condition that the local directory of code is not empty and the remote address of the code in the local directory of code is consistent with the preset remote address. Therefore, the code pulling speed can be greatly improved.
[0064] On the basis of the above-mentioned embodiment, the cocoapods code pulling optimization method provided in the embodiment of the present invention, the code for obtaining the preset remote address specifically includes:
[0065] Based on git clone, obtain the code of the preset remote address.
[0066] Specifically, in the embodiment of the present invention, when obtaining the code of the preset remote address, since the local directory of the code is empty at this time or is deleted because the remote address of the code is inconsistent with the preset remote address, git clone can be used to implement batch pulling to ensure the integrity of the code in the local directory of the code.
[0067] On the basis of the above embodiment, the cocoapods code pulling optimization method provided in the embodiment of the present invention, wherein the code of the remote branch is pulled to the local branch, specifically includes:
[0068] Pull the code in the remote branch that is different from the code in the local branch to the local branch.
[0069] Specifically, in an embodiment of the present invention, when pulling the code of the ":sourceBranch" remote branch to the ":sourceBranch" local branch, only the code contained in the remote branch but not in the local branch can be pulled, and there is no need to pull the entire library, which can save the time for code pulling and further improve the speed of code pulling. It improves the method in the prior art that only remote git can be used to pull code on the packager, so that cocoapods first pulls all remote branches of the remote git library and then switches to the corresponding local branch. The problem of low code pulling speed caused by this solution.
[0070] On the basis of the above embodiment, the cocoapods code pulling optimization method provided in the embodiment of the present invention, wherein the code of the remote branch is pulled to the local branch, specifically includes:
[0071] Based on git pull --rebase, pull the code of the remote branch to the local branch.
[0072] Specifically, in the embodiment of the present invention, when pulling the code of the remote branch to the local branch, git pull --rebase can be used to implement it. Git pull --rebase can be understood as a combination of git fetch and git rebase, which can obtain a neater submission history.
[0073] like Figure 2 As shown, based on the above embodiments, a cocoapods code pulling optimization system is provided in an embodiment of the present invention, including: a determination module 21 and a pulling module 22.
[0074] in,
[0075] The determination module 21 is used to determine that the code configuration protocol in the cocoapods configuration file is a preset code configuration protocol; the preset code configuration protocol includes a code local directory, a preset remote address and a preset branch;
[0076] The pulling module 22 is used to switch the code of the local directory of the code to the local branch pointed to by the specific content of the preset branch, and pull the code of the remote branch pointed to by the specific content of the preset branch to the local branch if it is determined that the local directory of the code is not empty and the remote address of the code of the local directory of the code is consistent with the preset remote address.
[0077] Specifically, the functions of each module in the cocoapods code pull optimization system provided in the embodiment of the present invention correspond one-to-one to the operation flow of each step in the above method class embodiment, and the effects achieved are also consistent. Please refer to the above embodiment for details, and no further description will be given in the embodiment of the present invention.
[0078] Based on the above embodiment, the determination module is specifically used for:
[0079] If the code configuration protocol in the cocoapods configuration file is not the preset code configuration protocol, the code configuration protocol is converted into the preset code configuration protocol.
[0080] Based on the above embodiment, the pulling module is further used for:
[0081] If it is determined that the local code directory is empty, or the local code directory is not empty and the remote address of the code in the local code directory is inconsistent with the preset remote address, the local code directory is deleted, the code of the preset remote address is obtained, and the code of the preset remote address is switched to the local branch.
[0082] Based on the above embodiment, the pulling module is specifically used for:
[0083] Based on git clone, obtain the code of the preset remote address.
[0084] Based on the above embodiment, the pulling module is specifically used for:
[0085] Pull the code in the remote branch that is different from the code in the local branch to the local branch.
[0086] Based on the above embodiment, the pulling module is specifically used for:
[0087] Based on git pull --rebase, pull the code of the remote branch to the local branch.
[0088] Figure 3 As shown, based on the above embodiment, an electronic device is provided in an embodiment of the present invention, including: a processor (processor) 301, a memory (memory) 302, a communication interface (Communications Interface) 303 and a communication bus 304; wherein,
[0089] The processor 301, memory 302, and communication interface 303 communicate with each other through a communication bus 304. The memory 302 stores program instructions that can be executed by the processor 301, and the processor 301 is used to call the program instructions in the memory 302 to execute the cocoapods code pulling optimization method provided by the above-mentioned method embodiments.
[0090] It should be noted that the electronic device in this embodiment can be a server, a PC, or other devices in specific implementation, as long as its structure includes the following: Figure 3 The processor 301, communication interface 303, memory 302 and communication bus 304 are shown, wherein the processor 301, communication interface 303 and memory 302 communicate with each other through the communication bus 304, and the processor 301 can call the logic instructions in the memory 302 to execute the above method. This embodiment does not limit the specific implementation form of the electronic device.
[0091] The logic instructions in the memory 302 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0092] Furthermore, an embodiment of the present invention discloses a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the cocoapods code pulling optimization method provided by the above-mentioned method embodiments.
[0093] On the basis of the above embodiments, an embodiment of the present invention further provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, it is implemented to execute the cocoapods code pulling optimization method provided in the above embodiments.
[0094] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they 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 scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0095] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0096] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A cocoapods code pulling optimization method, characterized in that: include: Make sure the code configuration protocol in the cocoapods configuration file is the preset code configuration protocol; The preset code configuration protocol includes a code local directory, a preset remote address and a preset branch; If it is determined that the local code directory is not empty and the remote address of the code in the local code directory is consistent with the preset remote address, the code in the local code directory is switched to the local branch pointed to by the specific content of the preset branch, so that the code of the local branch is synchronized with the code in the local code directory, and the code of the remote branch pointed to by the specific content of the preset branch is pulled to the local branch, so that the code of the remote branch is included in the local code directory.
2. The cocoapods code pulling optimization method according to claim 1, characterized in that: Determining that the code configuration protocol in the cocoapods configuration file is a preset code configuration protocol specifically includes: If the code configuration protocol in the cocoapods configuration file is not the preset code configuration protocol, the code configuration protocol is converted into the preset code configuration protocol.
3. The cocoapods code pulling optimization method according to claim 1, characterized in that: Also includes: If it is determined that the local code directory is empty, or the local code directory is not empty and the remote address of the code in the local code directory is inconsistent with the preset remote address, the local code directory is deleted, the code of the preset remote address is obtained, and the code of the preset remote address is switched to the local branch.
4. The cocoapods code pulling optimization method according to claim 3, characterized in that: The code for obtaining the preset remote address specifically includes: Based on git clone, obtain the code of the preset remote address.
5. The cocoapods code pulling optimization method according to claim 1, characterized in that: Pulling the code of the remote branch to the local branch specifically includes: Pull the code in the remote branch that is different from the code in the local branch to the local branch.
6. The cocoapods code extraction optimization method according to any one of claims 1 to 5, characterized in that: Pulling the code of the remote branch to the local branch specifically includes: Based on git pull --rebase, pull the code of the remote branch to the local branch.
7. A cocoapods code pull optimization system, characterized in that: include: A determination module is used to determine that the code configuration protocol in the cocoapods configuration file is a preset code configuration protocol; The preset code configuration protocol includes a code local directory, a preset remote address and a preset branch; A pulling module is used to switch the code of the local code directory to the local branch pointed to by the specific content of the preset branch if it is determined that the local code directory is not empty and the remote address of the code of the local code directory is consistent with the preset remote address, so as to synchronize the code of the local branch with the code in the local code directory, and pull the code of the remote branch pointed to by the specific content of the preset branch to the local branch, so as to include the code of the remote branch in the local code directory.
8. The cocoapods code pulling optimization system according to claim 7, characterized in that: The determination module is specifically used for: If the code configuration protocol in the cocoapods configuration file is not the preset code configuration protocol, the code configuration protocol is converted into the preset code configuration protocol.
9. An electronic device, comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the cocoapods code pulling optimization method as described in any one of claims 1 to 6 are implemented.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the cocoapods code pulling optimization method as described in any one of claims 1 to 6 are implemented.
