Personal email: xiaokeweng@gmail.com
For detailed analysis of the Code, even if you do not understand python and look at the annotations, you can also understand the rough. Roughly speaking, the purpose of this repo bootstrap is to assemble the real repo directory, that is, when you want to pull code under a directory, you will enter: repoinit, in essence, it is to visit the website and go down the whole site. repo directory. The repohelp function is also available. Now let's start reading the code ~
1) as described in the previous article, it mainly implements the transition from shell to python, and the next step is to take over from python.
#!/bin/sh ## repo default configuration ## REPO_URL='https://gerrit.googlesource.com/git-repo' REPO_REV='stable' magic='--calling-python-from-/bin/sh--' """exec" python -E "$0" "$@" """#$magic"
2) whether this part of the actual judgment is actively executed, or is used as the famous library of other scripts, similar to being declared by other scripts, rather than being executed.
#if __name__ == '__main__': import sys if sys.argv[-1] == '#%s' % magic: del sys.argv[-1] del magic
3) all the parts of the last two rows will be function definitions, variable settings, and receiving rules for reading parameters in the script. The last two rows will make, let's start with the final main function:
If _ name _ = '_ main _': main (sys. argv [1:]) # All parameters are passed in. [1:] indicates
4) then, it is transferred to the main function. In the entire main function, it mainly performs basic configuration detection and parameter detection. In essence, it does not perform any functional operations, finally, the main. py. Each function is defined in this file.
############ MAIN ################ def main (orig_args): repo_main, rel_repo_dir = _ FindRepo () # (1) main. the absolute path of py (2 ). the absolute path of the repo is cmd, opt, args = _ ParseArguments (orig_args) # Return: cmd-the first parameter that does not start with "-" # opt-help = True/False # The parameter sequence wrapper_path = OS after arg-cmd. path. abspath (_ file _) # full path of this file: my_main, my_git = _ RunSelf (wrapper_path) # obtain main. py. git full path (ensure that 'git _ config. py ', 'Project. py', 'subcmds ') if not repo_main: if opt. help: _ Usage () if cmd = 'help': _ help (args) if not cmd: _ NotInstalled () # prompt "repo init" if cmd = 'init ': if my_git: _ SetDefaultsTo (my_git) # Save repo /. the branch value in git is REPO_REV: HEAD try: _ Init (args) failed t CloneFailure: for root, dirs, files in OS. walk (repodir, topdown = False): for name in files: OS. remove (OS. path. join (root, name) for name in dirs: OS. rmdir (OS. path. join (root, name) OS. rmdir (repodir) sys. exit (1) repo_main, rel_repo_dir = _ FindRepo () else: _ NoCommands (cmd) # Error Problem if my_main: repo_main = my_main ver_str = '. '. join (map (lambda x: str (x), VERSION) me = [repo_main, '-- repo-dir = % s' % rel_repo_dir, '-- wrapper-version = % s' % ver_str,' -- wrapper-path = % s' % wrapper_path, '--'] me. extend (orig_args) me. extend (extra_args) try: OS .exe cv (repo_main, me) # transfer the permission to main. py response t OSError as e: print> sys. stderr, "fatal: unable to start % s" % repo_main print> sys. stderr, "fatal: % s" % e sys. exit (148)
From here, it can be regarded as a truly functional part. The whole part includes all the functions. To be honest, there are not many commands or functions that can be used at ordinary times, I didn't view every file one by one.
We are here to take a look at the use of repo, first installed on the computer is a few hundred lines of bootstrap, generally placed in ~ /Bin, so that we can be accessed by our environment variables, and then whenever we want to use the repo function (generally, the first function should be to pull the project code ), first, we need to repoinit in a directory, that is, to go down to the full repo directory through bootstrap to the url specified by manfeast, so as to specify your remote target project file, when you reposync, the whole project will be accessed and down.
Repo is just a tool. It is generated by convenient management of android, and all functions are based on git, simply put, repo is the user interface for unified management and operation of git under the android project.
Ps: Sorry-I wanted to explain each function in detail. Later I was delayed for a while due to other things, and now I am a little new when I come back ~ Haha, old, useless... Let's analyze the repo at the end of Caocao ~, If you are interested, please email me. We can discuss and learn together.