a +bC@sddlmZddlmZddlmZmZmZmZddl m Z m Z m Z mZmZmZmZddlmZmZddlmZddlmZmZmZeZGd d d eZGd d d eZ Gd ddeZ GdddeZ!e"ej#GdddeZ$dS))absolute_import)_)binhexnullrevsha1nodeconstants)ancestor changelogdagopencodingerrormanifestpycompat) repositoryutil) stringutil)gitutilindexr c@s8eZdZdZddZddZddZdd Zd d Zd S) baselogz9Common implementations between changelog and manifestlog.cCs||_||_dSN)gitrepo_db)selfgrdbr6/usr/lib64/python3.9/site-packages/hgext/git/gitlog.py__init__%szbaselog.__init__cCst|jddS)NzSELECT COUNT(*) FROM changelogr)intrexecutefetchonerrrr__len__)szbaselog.__len__cCsJ|tjkrdS|jdt|f}|durBt|dt d|dS)Nz(SELECT rev FROM changelog WHERE node = ? 00changelog.is no node %dr) rnullidrr r togitnoder!r LookupErrorrrntrrrrev.s  z baselog.revcCsH|tkrtjS|jd|f}|durd$d%Zd?d&d'Zd(d)Zd@d*d+Zd,d-Zd.d/Zd0d1ZeZd2d3Zd4d5Zd6d7ZdAd8d9ZdS)Br sextracCs,z||WdStjy&YdS0dS)NTF)r.r r(rr,rrr __contains__ms  zchangelog.__contains__cCsttt|Sr)iterrxranger:r"rrr__iter__tszchangelog.__iter__cCstSr)setr"rrr filteredrevswszchangelog.filteredrevscCst|Sr)r5r"rrrr}szchangelog.indexcCs$dd|jdD}t|tj<|S)NcSsi|]}t|d|dqS)rrr).0vrrr sz%changelog.nodemap..zSELECT node, rev FROM changelog)rr rrr&)rr-rrrnodemaps   zchangelog.nodemapcCs&|jd}|r t|dStjS)Nz4SELECT node FROM changelog ORDER BY rev DESC LIMIT 1r)rr r!rrr&rr+rrrtips  z changelog.tiprNcCs0|dur|}|jd||f}dd|DS)NzFSELECT rev FROM changelog WHERE rev >= ? AND rev <= ? ORDER BY REV ASCcss|]}t|dVqdS)rNrrFr-rrr z!changelog.revs..)tiprevrr )rstartstopr+rrrrevsszchangelog.revscCs$|jd}|dur |dSdS)Nz3SELECT rev FROM changelog ORDER BY REV DESC LIMIT 1rr$)rr r!rJrrrrPs zchangelog.tiprevcCs|tj|rtjdd|jdt|dfD}tj |rN| tj t |dkrlt |dtd|rx|dSdS) NcSsg|]}t|dqSrrErFxrrr sz+changelog._partialmatch..z,SELECT node FROM changelog WHERE node LIKE ?%rr%sambiguous identifierr)rZwdirhex startswithr ZWdirUnsupportedrr rr/Znullhexappendr&r:ZAmbiguousPrefixLookupErrorr)ridZ candidatesrrr _partialmatchs"     zchangelog._partialmatchcCsdS)Nrrr>rrrflagsszchangelog.flagsrc Csht|}t|t|dD]F}|d|}t|jdt|dfd}|dkr|Sq|S)Nrz0SELECT COUNT(*) FROM changelog WHERE node LIKE ?rXr) rrrAr:rrr r/r!)rr.Z minlengthZnodehexZattempt candidatematchesrrrshortests  zchangelog.shortestcs8dd|jdD|r0tfdd|DStS)NcSsg|]}t|dqSrTrLrUrrrrWsz&changelog.headrevs..zISELECT rev FROM changelog INNER JOIN heads ON changelog.node = heads.nodecsg|]}|vr|qSrrrMZ realheadsrrrWrO)rr sortedrrSrrarheadrevsszchangelog.headrevsc Cst|tr||}n|}ddi}|tjkr.zBSELECT filename FROM changedfiles WHERE node = ? and filenode != ?cSsg|] }|dqSrTrrMrrrrWszASELECT filename FROM changedfiles WHERE node = ? and filenode = ?s%s <%s>utf8<)r userdatefiles filesremoved descriptionrf) isinstancerr.rr& hgchangelogZ_changelogrevisionrr'rr nullgitrZauthornameencodeemailtimeoffsetmessage)rZ nodeorrevr*rfhnrkrlcrrrchangelogrevisionsB      zchangelog.changelogrevisionFcCsHt|}||}|D]}||krtd|qtj|j|||dS)NsInvalid rev %r)stoprev inclusive)listr,rK IndexErrorrZ lazyancestorsr;)rrSrzr{rKr-rrr ancestorss zchangelog.ancestorscCst||j|jSr)r ZdescendantrevsrSr;rcrrr descendantsszchangelog.descendantscCs|durtg}t|j|S)aOReturn an object that can be used to incrementally compute the revision numbers of the ancestors of arbitrary sets that are not ancestors of common. This is an ancestor.incrementalmissingancestors object. 'common' is a list of revision numbers. If common is not supplied, uses nullrev. N)rrZincrementalmissingancestorsr;)rcommonrrrincrementalmissingrevss z changelog.incrementalmissingrevscsh|durtjg}|dur }fdd|D}fdd|D}j|d}fdd||DS)a.Return the ancestors of heads that are not ancestors of common. More specifically, return a list of nodes N such that every N satisfies the following constraints: 1. N is an ancestor of some node in 'heads' 2. N is not an ancestor of any node in 'common' The list is sorted by revision number, meaning it is topologically sorted. 'heads' and 'common' are both lists of node IDs. If heads is not supplied, uses all of the revlog's heads. If common is not supplied, uses nullid.Ncsg|]}|qSrr,rFr*r"rrrW3rOz)changelog.findmissing..csg|]}|qSrrrr"rrrW4rO)rcsg|]}|qSrr.rMr"rrrW7rO)rr&headsrZmissingancestors)rrrZincrr"r findmissings zchangelog.findmissingcCs|g}||}|j|ddD]X}dd||D}|r^|D]}||kr>|||q>q|tkr|||q|S)z!find the children of a given noder)rQcSsg|]}|tkr|qSr)r)rFprrrrrW>rOz&changelog.children..)r,rSr;rZr.r)rr.rxpr-Zprevsrrrrchildren9s zchangelog.childrencCst|j||||Sr)r Z_reachablerootspurer;)rZminrootrroots includepathrrrreachablerootsGs zchangelog.reachablerootscCs"||||}}|||Sr)r, isancestorrevrabrrr isancestorMszchangelog.isancestorcCs>|tkr dS||krdS||kr$dSt|j||g|gddS)NTF)r)rboolrrrrrrRszchangelog.isancestorrevcCs||}t|}|tjkr*|j|}nttfSt}}|jr||jdjj }t |jdkrlt dt |jdkr||jdjj }||fS)NrsTODO octopus merge handlingr) r.rr'rprrparentsr,r[rawr:r ZAbort)rr,r*rwrxp1p2rrrr;[s     zchangelog.parentrevscs4||}}fddtj||DS)Ncsg|]}|qSrrrr"rrrWrsz2changelog.commonancestorsheads..)r,rcommonancestorsheadsr;rrr"rrns zchangelog.commonancestorsheadscCsdS)zAGit doesn't do named branches, so just put everything on default.)reFrr>rrr branchinfowszchangelog.branchinfocCsdSrr)rtrrrr delayupdate{szchangelog.delayupdatec Csg}t|t|}}|tjkr.|||rF|tjkrF|||dusRJ|\}}ttt |tt |t |t |d }|j d|||t||}|j jjd|ddt|j |j|jS)Nrhzrefs/hg/internal/latest-commitT)force)rr'rr&rZpygit2Z Signaturer Z unifromlocalrZpersonrsrrZ create_commitZ referencesZcreaterZ _index_reporr)rr rkZdesc transactionrrrirjrfZp1copiesZp2copiesZ filesaddedrlrZhp1Zhp2Z timestampZtzZsigZoidrrradds,     z changelog.add)rN)r)N)rF)N)NN)F)NNNNNN) r1r2r3Z_copiesstorager?rBpropertyrDrrIrKrSrPr\r]r`rdryr~rrrrrrrr;Z_uncheckedparentrevsrrrrrrrrr hsJ       ,      r c@s eZdZeZddZddZdS) manifestlogcCs |d|SNrO)getrr.rrrr=szmanifestlog.__getitem__cCsf|tjkrt||S|jt|}|j}|rX|d}|D]}||}|j|j }q>t |j|S)N/) rr&r Zmemtreemanifestctxrrr'Ztreesplitr[ gitmanifestZgittreemanifestctx)rrelpathr.commitr+partsrterrrrs   zmanifestlog.getN)r1r2r3rZ nodeconstantsr=rrrrrrsrcsneZdZfddZddZddZddZdd d Zd d ZddZ ddZ ddZ ddZ ddZ ZS)filelogcs2tt|||t|ts J||_tj|_dSr)superrrrnbytespathrr&)rrrr __class__rrrszfilelog.__init__cCs |tjkrdS|jt|jSr)rr&rrr'datarrrrreads z filelog.readcCsnt|dvrt|}t|tr*ds*Jdt|dkr>t|}t|}||jvrV|St|j |t ddS)N)(Fstodo revnums for nodesrsno match found) r:rrnrrr'rr r(rr)rr.Zhnoderrrlookups      zfilelog.lookupcCs|||kS)z9Returns True if text is different than content at `node`.)r)rr.textrrrcmpsz filelog.cmpNcCs|rJ|j|jSr)rZ create_blobr)rrmetarlinkrrrrrrsz filelog.addccs0|jdt|jtjfD]}|dVqdS)Nz SELECT rev FROM changelog INNER JOIN changedfiles ON changelog.node = changedfiles.node WHERE changedfiles.filename = ? AND changedfiles.filenode != ? r)rr rfsdecoderrrp)rZclrevrrrrBs zfilelog.__iter__cCs|Srr)rfrrrrlinkrevszfilelog.linkrevcCsL|jdt|jt|f}|dur@t |j|t dt |dS)Nz SELECT rev FROM changelog INNER JOIN changedfiles ON changelog.node = changedfiles.node WHERE changedfiles.filename = ? AND changedfiles.filenode = ?s no such noder) rr rrrrr'r!r r(rr)rr.rowrrrr,sz filelog.revcCsD|jd|t|jf}|dur8td|j|ft|dS)NzSELECT filenode FROM changedfiles INNER JOIN changelog ON changelog.node = changedfiles.node WHERE changelog.rev = ? AND filename = ? zgitlog %r out of range %dr)rr rrrr!r}r)rr,mayberrrr.sz filelog.nodecCst|}t|j}g}|jd||fD]h}|dur|jd||fd}tjrf| d}t |j |j|||| |S|t|q0|S)NzTSELECT p1filenode, p2filenode FROM changedfiles WHERE filenode = ? AND filename = ? zASELECT node FROM changedfiles WHERE filenode = ? AND filename = ?rascii)rr'rrrrr r!Zispy3decoderZfill_in_filelogrrrZr)rr.ZgnZgpZpsrrrrrr s(    zfilelog.parentscCsdS)NFrrrrrrenamed#szfilelog.renamed)NN)r1r2r3rrrrrrBrr,r.rr __classcell__rrrrrs      rN)%Z __future__rZmercurial.i18nrZmercurial.noderrrrZ mercurialrr ror r r r rZmercurial.interfacesrrZ interfaceutilZmercurial.utilsrrrrZ get_pygit2robjectrr5rZ implementerZ ifilestoragerrrrrs  $  (H