Tag Archives: Python language

git clone appears fatal: index-pack failed problem solution

Problem 1.
When Git clone occurred, the following problems occurred:

fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

2. Steps to solve the problem:

git config --add core.compression -1

3. New problems
The terminal executes the previous sentence and then continues to pull the code. The problem appears as follows:

error: RPC failed; curl 18 transfer closed with outstanding read data remaining 
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

4. Problem-solving steps
This error may be caused by insufficient git memory. Modify the configuration to continue terminal processing:

[core] 
packedGitLimit = 512m 
packedGitWindowSize = 512m 
[pack] 
deltaCacheSize = 2047m 
packSizeLimit = 2047m 
windowMemory = 2047m

The statements in the above modified terminal are similar to those of eg:
git config --global core.com compression 0
After the above steps of processing, you can pull down the code!
Reference:
Technology blog: https://stackoverflow.com/questions/21277806/fatal-early-eof-fatal-index-pack-failed technology blog: https://vnzmi.com/2017/01/08/git-early-eof-index-pack-failed/ technology blog: https://blog.csdn.net/qq_32791023/article/details/83622283?depth_1-utm_source=distribute.pc_relevant.none-task& utm_source=distribute.pc_relevant.none-task
The above content is only on behalf of the individual summary if there are mistakes, please also criticize correct, welcome to study together!

Python recursively traverses all files in the directory to find the specified file

before I read someone on the Internet saying “os.path.isdir() determines that absolute path must be written”, I thought Python has an iteration context, why not?Therefore,

is verified in this paper


code section

Consider using a path variable to refer to the current traversal element’s absolute path (correct practice)

def search(root, target):
    items = os.listdir(root)
    for item in items:
        path = os.path.join(root, item)
        if os.path.isdir(path):
            print('[-]', path)
            search(path, target)
        elif path.split('/')[-1] == target:
            print('[+]', path)
        else:
            print('[!]', path)

normal traversal result

if I write it this way, I’m going to replace all the paths with item (iterative element)

def search(root, target):
    items = os.listdir(root)
    for item in items:
        if os.path.isdir(item):
            print('[-]', item)
            search(os.path.join(root, item), target)
        elif item == target:
            print('[+]', os.path.join(root,item))
        else:
            print('[!]', os.path.join(root, item))

can be seen that this does not work: if you use the item to iterate over the current path, you will recursively recursively refer to the current path only two levels further down (subfolders, subfolder files), you can see that the missing context management mechanism is completely ineffective here

reflection and summary

1) how would you react if you just changed the iteration mechanism of the passing element for each recursion based on the correct traversal writing?

In the above example, just change search(os.path.join(root, item), target) to search(item, target) :

this is easy to see because the first time you call search(..) is passed in an absolute path. If the relative path is passed in because there is no context, it cannot correctly locate the location of the file

2)os.path. Abspath (path) method can replace os.path. Join (root, current)?

(fog) original os.path. Abspath (..) means: relative path to the current working directory! (not the relative path to the system root!)

so, os.path. Abspath (..) and OS path. Join (..) is two completely different things that cannot be replaced by

3) what exactly is a Python file?

again, change each output to use type(..) function package form

let's look at another example

In line with the Python "everything is an object" belief, the path we enter (including its iteration version, and the variable used to accept it) is a string STR object, and the file handle (pointer) used to describe the file is a

object
In general, we search and filter folders and files horizontally, using the path description of STR type. However, to read or write a specific file (not a folder), we need to use the file handle of _io.TextIOWrapper type. Unlike Java, which is completely encapsulated as a File(String path) object, it reduces the role of the File path as a single individual -- but Python takes the path as a separate one, and many of our File operations (broadly defined as finding a specific File, not just a File IO) are based on the File path as

4) thinking: is there any way to traverse the file other than the method given at the beginning?

answer: yes

Chdir (path) os.chdir(path) path

but we do not recommend this method because it modifies the global variable, which is validated before and after the function call using the os.getcwd() function

First switch the working directory to the root directory, then execute the custom change() function

as you can see, by this time the global current working directory has changed