3 ”Re¡6ã@sddlmZddlZddlZddlZddlmZddl mZ ddl m Z ddl mZmZddlmZmZddlmZddlmZdd lmZdd lmZmZmZmZerÔdd lmZm Z dd lm!Z!dd lm"Z"m#Z#e j$Z$e j%Z%ej&e'ƒZ(ej)dƒZ*dd„Z+Gdd„deƒZ,ej-e,ƒdS)é)Úabsolute_importN)Úparse)Úrequest)Ú BadCommandÚSubProcessError)Ú display_pathÚhide_url)Ú make_command)Ú TempDirectory)ÚMYPY_CHECK_RUNNING)ÚRemoteNotFoundErrorÚVersionControlÚ!find_path_to_setup_from_repo_rootÚvcs)ÚOptionalÚTuple)Ú HiddenText)ÚAuthInfoÚ RevOptionsz^[a-fA-F0-9]{40}$cCsttj|ƒƒS)N)ÚboolÚ HASH_REGEXÚmatch)Úsha©rú„/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el8.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_internal/vcs/git.pyÚlooks_like_hash*srcsæeZdZdZdZdZd/Zd0Zd Ze d d „ƒZ dd„Z dd„Z e dd„ƒZdd„Ze dd„ƒZe dd„ƒZe dd„ƒZdd„Zdd„Zd d!„Ze d"d#„ƒZe d1d%d&„ƒZe d'd(„ƒZe ‡fd)d*„ƒZe d+d,„ƒZe ‡fd-d.„ƒZ‡ZS)2ÚGitÚgitz.gitÚcloneúgit+httpú git+httpsúgit+sshúgit+gitúgit+fileÚGIT_DIRÚ GIT_WORK_TREEÚHEADcCs|gS)Nr)ÚrevrrrÚget_base_rev_args:szGit.get_base_rev_argscCsJ|jt|ƒƒ\}}|jsdS|j||jƒs.dSt|j||jƒdƒ}| S)NFr)Úget_url_rev_optionsrr'Úis_commit_id_equalrÚget_revision_sha)ÚselfÚurlÚdestÚ_Ú rev_optionsÚis_tag_or_branchrrrÚis_immutable_rev_checkout>szGit.is_immutable_rev_checkoutcCsXd}|jdgƒ}|j|ƒr4|t|ƒd…jƒd}nd}dj|jdƒdd…ƒ}t|ƒS)Nz git version ÚversionrÚÚ.é)Ú run_commandÚ startswithÚlenÚsplitÚjoinÚ parse_version)r,Ú VERSION_PFXr3rrrÚget_git_versionOs  zGit.get_git_versioncCs@dddg}|j|d|d�}|jƒ}|jdƒr<|tdƒd…SdS) zl Return the current branch, or None if HEAD isn't at a branch (e.g. detached HEAD). z symbolic-refz-qr&é)Úextra_ok_returncodesÚcwdz refs/heads/N)r?)r7Ústripr8r9)ÚclsÚlocationÚargsÚoutputÚrefrrrÚget_current_branch\s   zGit.get_current_branchc CsV|jdƒs|d}tdd��0}|j|j|d�|jdddd|g|jd �Wd QRXd S) z@Export the Git repository at the url to the destination locationú/Úexport)Úkind)r-zcheckout-indexz-az-fz--prefix)rAN)Úendswithr ÚunpackÚpathr7)r,rDr-Útemp_dirrrrrJqs   z Git.exportc CsÆd}y|jd|g|d�}Wntk r.YnXi}xP|jƒjƒD]@}y|jƒ\}}Wn"tk rxtdj|ƒƒ‚YnX|||<qBWdj|ƒ}dj|ƒ} |j|ƒ}|dk r´|dfS|j| ƒ}|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. r4zshow-ref)rAzunexpected show-ref line: {!r}zrefs/remotes/origin/{}z refs/tags/{}NTF)r7rrBÚ splitlinesr:Ú ValueErrorÚformatÚget) rCr.r'rFÚrefsÚlinerrGÚ branch_refÚtag_refrrrr+~s&      zGit.get_revision_shacCs |j}|dk st‚|j||ƒ\}}|dk rF|j|ƒ}|r<|nd|_|St|ƒsZtjd|ƒ|jdƒsh|S|j t dd||j ƒƒ|d�|j |dd�}|j|ƒ}|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/Úfetchz-q)rAÚ FETCH_HEAD)r') Úarg_revÚAssertionErrorr+Úmake_newÚ branch_namerÚloggerÚwarningr8r7r Úto_argsÚ get_revision)rCr.r-r0r'rÚ is_branchrrrÚresolve_revision¦s&     zGit.resolve_revisioncCs|sdS|j|ƒ|kS)z§ Return whether the current commit hash equals the given name. Args: dest: the repository directory. name: a string name. F)ra)rCr.Únamerrrr*Ós zGit.is_commit_id_equalcCsÈ|jƒ}tjd||t|ƒƒ|jtdd||ƒƒ|jrº|j|||ƒ}t|ddƒ}|dkr†|j ||jƒsºtdd|j ƒƒ}|j||d�n4|j |ƒ|krºdj |ƒ}dd|d |g}|j||d�|j |ƒdS) NzCloning %s%s to %srz-qr]Úcheckout)rAz origin/{}z-bz--track)Ú to_displayr^Úinforr7r r'rcÚgetattrr*r`rHrRÚupdate_submodules)r,r.r-r0Ú rev_displayr]Úcmd_argsÚ track_branchrrrÚ fetch_newâs   z Git.fetch_newcCsB|jtdd|ƒ|d�tdd|jƒƒ}|j||d�|j|ƒdS)NÚconfigzremote.origin.url)rArez-q)r7r r`ri)r,r.r-r0rkrrrÚswitchs  z Git.switchcCst|jƒtdƒkr&|jdddg|d�n|jddg|d�|j|||ƒ}tddd|jƒƒ}|j||d�|j|ƒdS)Nz1.9.0rXz-qz--tags)rAÚresetz--hard)r>r<r7rcr r`ri)r,r.r-r0rkrrrÚupdate sz Git.updatec Csx|jdddgd |d�}|jƒ}y |d}Wntk rBt‚YnXx|D]}|jdƒrJ|}PqJW|jdƒd}|jƒS) z¢ Return URL of the first remote encountered. Raises RemoteNotFoundError if the repository does not have a remote url configured. rnz --get-regexpzremote\..*\.urlr?)r@rArzremote.origin.url ú )r?)r7rPÚ IndexErrorr r8r:rB)rCrDÚstdoutÚremotesÚ found_remoteÚremoter-rrrÚget_remote_urls      zGit.get_remote_urlNcCs&|dkr d}|jd|g|d�}|jƒS)Nr&z rev-parse)rA)r7rB)rCrDr'Ú current_revrrrra5s zGit.get_revisioncCsP|jddg|d�jƒ}tjj|ƒs0tjj||ƒ}tjjtjj|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. z rev-parsez --git-dir)rAz..)r7rBÚosrNÚisabsr;Úabspathr)rCrDÚgit_dirÚ repo_rootrrrÚget_subdirectory>s  zGit.get_subdirectoryc sút|ƒ\}}}}}|jdƒr–|dt|jdƒƒ …}|tj|ƒjddƒjdƒ}t|||||fƒ}|jdƒd} |d| …t|| d…||||fƒ}d|krÚd|ksªt ‚|jd d ƒ}t t |ƒj |ƒ\}} } |jd d ƒ}nt t |ƒj |ƒ\}} } || | 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://r4) ÚurlsplitrLr9ÚlstripÚurllib_requestÚ url2pathnameÚreplaceÚ urlunsplitÚfindr[ÚsuperrÚget_url_rev_and_auth) rCr-ÚschemeÚnetlocrNÚqueryÚfragmentÚinitial_slashesÚnewpathÚ after_plusr'Ú user_pass)Ú __class__rrr‹Ms"      zGit.get_url_rev_and_authcCs6tjjtjj|dƒƒsdS|jdddddg|d�dS)Nz .gitmodulesÚ submodulerqz--initz --recursivez-q)rA)rzrNÚexistsr;r7)rCrDrrrrips  zGit.update_submodulesc svtt|ƒj|ƒ}|r|Sy|jddg|dd�}Wn2tk rPtjd|ƒdStk rbdSXtj j |j dƒƒS)Nz rev-parsez--show-toplevelF)rAÚlog_failed_cmdzKcould not determine if %s is under git control because git is not availablez ) rŠrÚget_repository_rootr7rr^ÚdebugrrzrNÚnormpathÚrstrip)rCrDÚlocÚr)r”rrr˜ys zGit.get_repository_root)rrr r!r"r#)r$r%)N)Ú__name__Ú __module__Ú __qualname__rdÚdirnameÚ repo_nameÚschemesÚ unset_environÚdefault_arg_revÚ staticmethodr(r2r>Ú classmethodrHrJr+rcr*rmrorqrxrarr‹rir˜Ú __classcell__rr)r”rr.s0   ( -     # r).Ú __future__rÚloggingÚos.pathrzÚreÚpip._vendor.packaging.versionrr<Zpip._vendor.six.moves.urllibÚ urllib_parserr…Úpip._internal.exceptionsrrÚpip._internal.utils.miscrrÚpip._internal.utils.subprocessr Úpip._internal.utils.temp_dirr Úpip._internal.utils.typingr Ú pip._internal.vcs.versioncontrolr r rrÚtypingrrrrrrƒrˆÚ getLoggerržr^ÚcompilerrrÚregisterrrrrÚs2          a