Qc@sddlmZddlmZddlmZmZmZmZddl Z ddl Z de fdYZ dZ dZd Zddd Zd Zd Zd ZdZdZdZdZdZdS(i(t_(thex(tencodingterrortutiltobsoleteNtbmstorecBs eZdZdZdZRS(sStorage for bookmarks. This object should do all bookmark reads and writes, so that it's fairly simple to replace the storage underlying bookmarks without having to clone the logic surrounding bookmarks. This particular bmstore implementation stores bookmarks as {hash}\s{name} (the same format as localtags) in .hg/bookmarks. The mapping is stored as {name: nodeid}. This class does NOT handle the "current" bookmark state at this time. cCstj|||_yx|jdD]}|j}|sGq)nd|krs|jjtd|q)n|jdd\}}t j |}y|j j ||| hash dictionary to the .hg/bookmarks file in a format equal to those of localtags. We also store a backup of the previous state in undo.bookmarks that can be copied back on rollback. Rtwt atomictemps%s %s s 00changelog.iN(R t_bookmarkcurrentt setcurrenttNonetwlockR tTruet iteritemstwriteRRt fromlocaltclosetostutimetsjointOSErrortrelease(RRR#tfiletnametnode((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pyR&2s  *  (t__name__t __module__t__doc__R R&(((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pyR s  cCsd}y|jd}Wn,tk rG}|jtjkrCndSXzJtj|jpcdgd}|dks||jkrd}nWd|j X|S(sGet the current bookmark If we use gittish branches we have a current bookmark that we are on. This function returns the name of the bookmark. It is stored in .hg/bookmarks.current sbookmarks.currenttiN( R"topenerRRRRRt readlinest _bookmarksR((RtmarkR.R((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pyt readcurrentPs"  cCs|j}||krdS||jkr1d}n|j}z<|jdddt}|jtj||jWd|j X||_dS(sSet the name of the bookmark that we are currently on Set the name of the bookmark that we are on (hg update ). The name is recorded in .hg/bookmarks.current NR4sbookmarks.currentRR( R R7R#R5R$R&RR'R(R-(RR8tcurrentR#R.((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pyR!gs     cCss|j}zUy#tj|jdd|_Wn+tk r_}|jtjkr`q`nXWd|j XdS(Nsbookmarks.current( R#RtunlinktjoinR"R R,RRR-(RR#R((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pyt unsetcurrent}s  cCsg|s|j}n|sDg|djD]}|j^q)}n|j}||kof|||kS(sTell whether the current bookmark is also active I.e., the bookmark listed in .hg/bookmarks.current also points to a parent of the working directory. N(R R"tparentsR0R7(RR8R>tptmarks((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pyt iscurrents  , cCsvyt|||j|SWnRtjk rq|dkrUt|||jdStjtd|nXdS(Ntdefaultttipsbranch %s not found(tupdatet branchtipRtRepoLookupErrorRRtAbortR(Rtoldnodet curbranch((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pytupdatecurrentbookmarks  cCst}|j}g|D]8}|jddd|jdddkr|^q}xC|D];}|r[|||kr[||kr||=t}qq[q[W|S(sDelete divergent versions of bm on nodes in deletefrom. Return True if at least one bookmark was deleted, False otherwise.t@ii(tFalseR7RR$(Rt deletefromtbmtdeletedR@tbt divergentR8((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pytdeletedivergents E  c CsN|}|j}t}|j}|s(tS|||kr|||}||}g|D]<} | jddd|jdddkrW|| ^qW} |jj|jg} g| D]0} | j| ks| |kr| j^q}|j|r|j||R0RMR@RDtcurtoldtnewRPtdivstanc((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pyRDs*    <=   cCst|di}i}|jj}xT|jD]F\}}||r1d|ksd|jdr1t|||}|jrm||px||d }|jd||fqTWt|dkr|jtddSdS(Ns searching for changed bookmarks Ri s %-25s %s isno changed bookmarks found i(RiRtlistkeysRgtsett debugflagR&tlen(RtdsttsrctsmarkstdmarkstdiffR_R8((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pyRs !cCse|j}||krtS|s&tS|jrT|jtj||jgkS|j|SdS(s?Is the new bookmark destination a valid update from the old oneN(t unfilteredRLR$tobsstoreR0Rt foregroundRU(RRWRX((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pyRh!s   %(tmercurial.i18nRtmercurial.nodeRt mercurialRRRRRR)R RR9R!R=R"RARJRRRDRaRdRxRRh(((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pyts "C       ,