��c@s�ddlmZddlmZddlmZmZmZmZddl Z ddl
Z
defd��YZd�Z
d�Zd �Zddd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�ZdS(i�(t_(thex(tencodingterrortutiltobsoleteNtbmstorecBs eZdZd�Zd�ZRS(s�Storage 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.
cCs�tj|�||_y�x�|jd�D]�}|j�}|sGq)nd|krs|jjtd�|�q)n|jdd�\}}t j
|�}y|jj|�||<Wq)t
k
r�q)Xq)WWn+tk
r�|jtjkr�q�XdS(Nt bookmarkst s$malformed line in .hg/bookmarks: %r
i(tdictt__init__t_repotvfststriptuitwarnRtsplitRttolocalt changelogtlookuptLookupErrortIOErrorterrnotENOENT(tselftrepotlinetshatrefspectinst((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pyR
s(
cCs�|j}|j|kr(t|d�n|j�}z�|jdddt�}x@|j�D]2\}}|jdt |�t
j|�f�q\W|j�yt
j|jd�d�Wntk
r�nXWd|j�XdS(s
Write bookmarks
Write the given bookmark => 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(Rt_bookmarkcurrentt
setcurrenttNonetwlockRtTruet 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
cCs�d}y|jd�}Wn,tk
rG}|jtjkrC�ndSXzJtj|j�pcdgd�}|dks�||jkr�d}nWd|j �X|S(s�Get 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.pytreadcurrentPs"
cCs�|j}||krdS||jkr1d}n|j�}z<|jdddt�}|jtj|��|j�Wd|j �X||_dS(s�Set the name of the bookmark that we are currently on
Set the name of the bookmark that we are on (hg update <bookmark>).
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|jd��d|_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.pytunsetcurrent}s
cCsg|s|j}n|sDg|dj�D]}|j�^q)}n|j}||kof|||kS(s�Tell 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 iscurrent�s, cCsvyt|||j|��SWnRtjk
rq|dkrUt|||jd��Stjtd�|��nXdS(Ntdefaultttipsbranch %s not found(tupdatet branchtipRtRepoLookupErrorRRtAbortR(Rtoldnodet curbranch((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pytupdatecurrentbookmark�scCs�t}|j}g|D]8}|jdd�d|jdd�dkr|^q}xC|D];}|r[|||kr[||kr�||=t}q�q[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.pytdeletedivergent�s E
cCsN|}|j}t}|j}|s(tS|||kr|||}||}g|D]<} | jdd�d|jdd�dkrW|| ^qW}
|jj|j�g�}g|
D]0} | j�|ks�| |kr�| j�^q�}|j|�r|j�||<t }qnt
|||�r7t }n|rJ|j�n|S(NRKii(R7RLR RRt ancestorstrevR0t
descendantR$RRR&(RR>R0RMR@RDtcurtoldtnewRPtdivstanc((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pyRD�s*
<=
cCst|di�}i}|jj}xT|j�D]F\}}||�r1d|ksd|jd�r1t|�||<q1q1W|S(NR7RK(tgetattrRthasnodeR%tendswithR(RR@tdR\tktv((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pyt
listbookmarks�s'cCs�|j�}zw|j}t|j|d��|kr:tS|dkrP||=n$||kr`tS||j�||<|j�tSWd|j�XdS(NR4( R#R7RtgetRLR0R&R$R-(RtkeyRWRXRR@((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pytpushbookmark�s
cCs|jd�t}|j}x�t|�D]�}||kr�||||}}||kr�|} ||}
|
j�| j�kr�q)nt||
| �r�| j�||<t}|jt d�|�q�|dkr�}n|}x7t
dd�D]&}d||f}
|
|kr��Wx<|jd�D]+\}}||kr5d ||f}
q5q5W| j�||
<t}|jt d
�||
f�q�)|||kr)|||j�||<t}|jt d�|�q)q)W|r�j
�ndS(Nschecking for updated bookmarks
supdating bookmark %s
RKR4iids%s@%dtpathss%s@%ss#divergent bookmark %s stored as %s
sadding remote bookmark %s
(tdebugRLR7tsortedRTt validdestR0R$tstatusRtrangetconfigitemsRR&(RRtremotemarkstpathtchangedt
localmarksR_tnrtnltcrtcltkdtxtnR?tu((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pytupdatefromremote�sD
#cCs�|jtd��|jd�}|jd�}tt|�t|��}xF|D]>}|jrm||px||d }|jd||f�qTWt|�dkr�|jtd��dSdS(Ns searching for changed bookmarks
Ris %-25s %s
isno changed bookmarks found
i(RiRtlistkeysRgtsett debugflagR&tlen(RtdsttsrctsmarkstdmarkstdiffR_R8((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pyR�s
!cCse|j�}||krtS|s&tS|jrT|j�tj||j�g�kS|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"RARJRRRDRaRdRxR�Rh(((s7/sys/lib/python2.7/site-packages/mercurial/bookmarks.pyt<module>s "C
,
|