U v_6@sddlmZddlZddlZddlZddlmZddl mZ ddl m Z ddl mZmZddlmZmZddlmZddlmZdd lmZdd lmZmZmZmZerdd lmZm Z dd lm!Z!dd lm"Z"m#Z#e j$Z$e j%Z%e&e'Z(e)dZ*ddZ+GdddeZ,e-e,dS))absolute_importN)parse)request) BadCommandSubProcessError) display_pathhide_url) make_command) TempDirectory)MYPY_CHECK_RUNNING)RemoteNotFoundErrorVersionControl!find_path_to_setup_from_repo_rootvcs)OptionalTuple) HiddenText)AuthInfo RevOptionsz^[a-fA-F0-9]{40}$cCstt|SN)bool HASH_REGEXmatch)shar/builddir/build/BUILDROOT/alt-python38-pip-20.2.4-1.el7.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_internal/vcs/git.pylooks_like_hash*srcseZdZdZdZdZdZdZdZe ddZ d d Z d d Z e d dZddZe ddZe ddZe ddZddZddZddZe ddZe d*d d!Ze d"d#Ze fd$d%Ze d&d'Ze fd(d)ZZS)+Gitgitz.gitclone)rzgit+httpz git+httpszgit+sshzgit+gitzgit+file)GIT_DIR GIT_WORK_TREEHEADcCs|gSrrrevrrrget_base_rev_args:szGit.get_base_rev_argscCsJ|t|\}}|jsdS|||js.dSt|||jd}| S)NFr)get_url_rev_optionsrr$is_commit_id_equalrget_revision_sha)selfurldest_ rev_optionsis_tag_or_branchrrris_immutable_rev_checkout>szGit.is_immutable_rev_checkoutcCsXd}|dg}||r4|t|dd}nd}d|ddd}t|S)Nz git version versionr.) run_command startswithlensplitjoin parse_version)r) VERSION_PFXr0rrrget_git_versionOs  zGit.get_git_versioncCs@dddg}|j|d|d}|}|dr<|tddSdS)zl Return the current branch, or None if HEAD isn't at a branch (e.g. detached HEAD). z symbolic-ref-qr"extra_ok_returncodescwdz refs/heads/N)r4stripr5r6)clslocationargsoutputrefrrrget_current_branch\s  zGit.get_current_branchc CsV|ds|d}tdd0}|j|j|d|jdddd|g|jd W5QRXd S) z@Export the Git repository at the url to the destination location/export)kind)r*zcheckout-indexz-az-fz--prefixrAN)endswithr unpackpathr4)r)rDr*temp_dirrrrrJqs   z Git.exportc Csd}z|jd|g|d}Wntk r.YnXi}|D]@}z|\}}Wn"tk rvtd|YnX|||<q@d|}d|} ||}|dk r|dfS|| }|d fS) z Return (sha_or_none, is_branch), where sha_or_none is a commit hash if the revision names a remote branch or tag, otherwise None. Args: dest: the repository directory. rev: the revision name. r1zshow-refrLzunexpected show-ref line: {!r}zrefs/remotes/origin/{}z refs/tags/{}NTF)r4rrB splitlinesr7 ValueErrorformatget) rCr+r$rFrefslinerrG branch_reftag_refrrrr(~s&      zGit.get_revision_shacCs|j}|dk st|||\}}|dk rF||}|r<|nd|_|St|sZtd||dsh|S|j t dd|| |d|j |dd}||}|S) z Resolve a revision to a new RevOptions object with the SHA1 of the branch, tag, or ref if found. Args: rev_options: a RevOptions object. Nz:Did not find branch or tag '%s', assuming revision or ref.zrefs/fetchr<rL FETCH_HEADr#) arg_revAssertionErrorr(make_new branch_namerloggerwarningr5r4r to_args get_revision)rCr+r*r-r$r is_branchrrrresolve_revisions*     zGit.resolve_revisioncCs|sdS|||kS)z Return whether the current commit hash equals the given name. Args: dest: the repository directory. name: a string name. F)rb)rCr+namerrrr's zGit.is_commit_id_equalcCs|}td||t||tdd|||jr||||}t|dd}|dkr| ||jstdd| }|j||dn4| ||krd |}dd|d |g}|j||d| |dS) NzCloning %s%s to %srr<r^checkoutrLz origin/{}z-bz--track) to_displayr_inforr4r r$rdgetattrr'rarHrSupdate_submodules)r)r+r*r- rev_displayr^cmd_args track_branchrrr fetch_news0  z Git.fetch_newcCsB|jtdd||dtdd|}|j||d||dS)Nconfigzremote.origin.urlrLrfr<)r4r rarjr)r+r*r-rlrrrswitchs z Git.switchcCst|tdkr&|jdddg|dn|jddg|d||||}tddd|}|j||d||dS)Nz1.9.0rYr<z--tagsrLresetz--hard)r;r9r4rdr rarjrprrrupdate sz Git.updatecCsv|jdddgd|d}|}z |d}Wntk rBtYnX|D]}|drH|}q`qH|dd }|S) z Return URL of the first remote encountered. Raises RemoteNotFoundError if the repository does not have a remote url configured. roz --get-regexpzremote\..*\.urlr=r?rzremote.origin.url  r>)r4rQ IndexErrorr r5r7rB)rCrDstdoutremotes found_remoteremoter*rrrget_remote_urls    zGit.get_remote_urlNcCs&|dkr d}|jd|g|d}|S)Nr" rev-parserL)r4rB)rCrDr$ current_revrrrrb5szGit.get_revisioncCsP|jddg|d}tj|s0tj||}tjtj|d}t||S)z~ Return the path to setup.py, relative to the repo root. Return None if setup.py is in the repo root. r{z --git-dirrLz..)r4rBosrOisabsr8abspathr)rCrDgit_dir repo_rootrrrget_subdirectory>s  zGit.get_subdirectoryc st|\}}}}}|dr|dt|d }|t|ddd}t|||||f}|dd} |d| t|| d||||f}d|krd|kst |d d }t t | |\}} } |d d }nt t | |\}} } || | fS) a9 Prefixes stub URLs like 'user@hostname:user/repo.git' with 'ssh://'. That's required because although they use SSH they sometimes don't work with a ssh:// scheme (e.g. GitHub). But we need a scheme for parsing. Hence we remove it again afterwards and return it as a stub. fileNrI\+r>z://zfile:zgit+z git+ssh://zssh://r1) urlsplitrMr6lstripurllib_request url2pathnamereplace urlunsplitfindr\superrget_url_rev_and_auth) rCr*schemenetlocrOqueryfragmentinitial_slashesnewpath after_plusr$ user_pass __class__rrrMs0      zGit.get_url_rev_and_authcCs6tjtj|dsdS|jdddddg|ddS)Nz .gitmodules submodulersz--initz --recursiver<rL)r}rOexistsr8r4)rCrDrrrrjps  zGit.update_submodulescsztt||}|r|Sz|jddg|dd}Wn6tk rRtd|YdStk rfYdSXtj | dS)Nr{z--show-toplevelF)rAlog_failed_cmdzKcould not determine if %s is under git control because git is not availablez ) rrget_repository_rootr4rr_debugrr}rOnormpathrstrip)rCrDlocrrrrrys" zGit.get_repository_root)N)__name__ __module__ __qualname__redirname repo_nameschemes unset_environdefault_arg_rev staticmethodr%r/r; classmethodrHrJr(rdr'rnrqrsrzrbrrrjr __classcell__rrrrr.sD     ' ,     " r). __future__rloggingos.pathr}repip._vendor.packaging.versionrr9Zpip._vendor.six.moves.urllib urllib_parserrpip._internal.exceptionsrrpip._internal.utils.miscrrpip._internal.utils.subprocessr pip._internal.utils.temp_dirr pip._internal.utils.typingr pip._internal.vcs.versioncontrolr r rrtypingrrrrrrr getLoggerrr_compilerrrregisterrrrrs2          a