o ]LbO@szdZddlmZddlZddlZddlZddlZddlmZddl m Z m Z ddl m Z mZmZmZmZmZmZmZmZmZmZmZmZddlmZmZmZiZeeZdZ dZ!d Z"d Z#e"ej$iZ%d d Z&d dZ'ddZ(ddZ)ddZ*ddZ+ddZ,ddZ-ddZ.ddZ/dd Z0Gd!d"d"e1d"d#Z2Gd$d%d%e3Z4d&Z5ed'd(d)gd*d+ej6Dd,ej7d-d.d/Z8dS)0ztrack previous positions of bookmarks (EXPERIMENTAL) This extension adds a new command: `hg journal`, which shows you where bookmarks were previously located. )absolute_importN)_)binhex) bookmarkscmdutildispatchencodingerror extensionshg localrepolock logcmdutilpycompat registrarutil)dateutilprocutil stringutilsships-with-hg-coresbookmarks wdirparentcCsNttdtttjdtttj dt tt dt tt dt dS)Ns runcommands_writedirstates postshares copystore)r wrapfunctionr runcommandrbmstorerecordbookmarks wrapfilecacher localrepository wrapdirstater wrappostshareunsharejournal)uir!//usr/lib/python3/dist-packages/hgext/journal.pyextsetupFsr#cCsH|r t||_|jdt|d\}}|r"t||dSdSdS)N namejournalr)localjournalstoragejournal_wlockfreeprefixaddr isfilecached_setupdirstate)r repodirstatecachedr!r!r" reposetupPs  r/cGs tj||||||g|RS)z;Track the command line options for recording in the journal)r& recordcommand)origluir,cmdfullargsargsr!r!r"r]s rcCs|j|_|dtdSNjournal)r'r&addparentchangecallbackrecorddirstateparents)r,r-r!r!r"r+csr+cCs"||}t|drt|||S)z5Make journal storage available to the dirstate objectr')r safehasattrr+)r1r,r-r!r!r"ris  rcCsvt|}t|}t|dr9|d|jjkr|ddn|}|d|jjkr,|ddn|}|jtd||dSdS)z3Records all dirstate parent changes in the journal.r&N.)listrr:_nodeconstantsnullidr&recordwdirparenttype)r-oldnew oldhashes newhashesr!r!r"r9qs   r9cCsb|j}t|dr,t|}t|D]\}}|||j}||kr+|j t |||q|||S)z,Records all bookmark changes in the journal.r') _reporr:rrr iteritemsgetr?r'r@ bookmarktype)r1storefpr,oldmarksmarkvalueoldvaluer!r!r"rs   rc CsPz t|jdWSty'}z|jtjkrtWYd}~Sd}~ww)z,A set of shared features for this repositorysharedN)setvfsread splitlinesIOErrorerrnoENOENT)r,instr!r!r"_readsharedfeaturess rYc os|dt}dd|D}i}t|D]\}}z t|||g||<Wqty,Yqw|rW|t|\}}}|Vz t|||d<Wn tyR||=Ynw|s/dSdS)zGiven a set of sorted iterables, yield the next entry in merged order Note that by default entries go from most recent to oldest. ordercSg|]}t|qSr!)iter).0itr!r!r" z%_mergeentriesiter..rN)popmax enumeratenext StopIterationr itervalues) iterableskwargsrZ iterable_mapkeyr^rNr!r!r"_mergeentriesiters&     rkc Ks|5|||fi||dd }|dWdn1s$wYWddSWddS1ssz!unsharejournal..)rr)rZ)pathsharedrr:r sharedreposourcerYrRexistsjoinrenamer'_openrkmin_write) r1r r,repopath sharedrepo journalpathstorager%r|entryr!rxr"rs*       rc@s.eZdZdZeddZddZeeZ dS) journalentryaIndividual journal entry * timestamp: a mercurial (time, timezone) tuple * user: the username that ran the command * namespace: the entry namespace, an opaque string * name: the name of the changed item, opaque string with meaning in the namespace * command: the hg command that triggered this record * oldhashes: a tuple of one or more binary hashes for the old location * newhashes: a tuple of one or more binary hashes for the new location Handles serialisation from and to the storage format. Fields are separated by newlines, hashes are written out in hex separated by commas, timestamp and timezone are separated by a space. c Cs~|d\}}}}}}}|\} } t| t| } } tdd|dD}tdd|dD}|| | f||||||S)N cs|]}t|VqdSrsrr]hashr!r!r"rzz+journalentry.fromstorage..,csrrsrrr!r!r"rzr)splitfloatinttuple) clslinetimeusercommandrunamerDrE timestamptzr!r!r" fromstorages,  zjournalentry.fromstoragec Cs`dttj|j}ddd|jD}ddd|jD}d||j|j|j |j ||fS)z bytes representation for storage rcSr[r!rrr!r!r"r_ r`z*journalentry.__bytes__..cSr[r!rrr!r!r"r_r`r) rmaprbytestrrrDrErrrur)selfrrDrEr!r!r" __bytes__ szjournalentry.__bytes__N) __name__ __module__ __qualname____doc__ classmethodrrr strmethod__str__r!r!r!r"rs  rz9timestamp user command namespace name oldhashes newhashesc@steZdZdZdZdZddZeddZe dd Z d d Z d d Z ddZ ddZdddZddZdddZdS)r&aeStorage for journal entries Entries are divided over two files; one with entries that pertain to the local working copy *only*, and one with entries that are shared across multiple working copies when shared using the share extension. Entries are stored with NUL bytes as separators. See the journalentry class for the per-entry structure. The file format starts with an integer version, delimited by a NUL. This storage uses a dedicated lock; this makes it easier to avoid issues with adding entries that added when the regular wlock is unlocked (e.g. the dirstate). r!NcCsnt|_|j|_|j|_d|_|_|r1t|}t |}|dur3d|vr5|j|_||_dSdSdSdSr6) rgetuserrr rRry sharedvfsr|rYr r})rr,featuresrr!r!r"__init__3s    zjournalstorage.__init__cCs2dttjtj}d|vr|ddd}|S)Nrrrs ...)rrr shellquoter&_currentcommand partition)r commandstrr!r!r"rBs  zjournalstorage.commandcGs ||_dS)z:Set the current hg arguments, stored with recorded entriesN)r)rr4r!r!r"r0Ls zjournalstorage.recordcommandcCs(|durdS|}|dus|jsdS|S)zoReturns the lock if it's held, or None if it's not. (This is copied from the localrepo class) N)held)rlockreflr!r!r" _currentlockSs zjournalstorage._currentlockc Cs||jdurttdtd|j}z tj|dd|d}Wn9tjyZ}z,|j td||j ftj|d|j dd |d}|j td |j WYd}~nd}~wwt ||_|S) z"Create a lock for the journal fileNs%journal lock does not support nestings journal of %ssnamejournal.lockr)descs"waiting for lock on %s held by %r suistimeoutsgot lock after %s seconds )r_lockrefr AbortrbaserLockHeldr warnlocker configintdelayweakrefref)rrRrrrXr!r!r"jlock_s( " zjournalstorage.jlockcCsrt|ts|g}t|ts|g}tt|j|j||||}|j}|jdur1t ||j vr1|j}| ||dS)aRecord a new journal entry * namespace: an opaque string; this can be used to filter on the type of recorded entries. * name: the name defining this entry; for bookmarks, this is the bookmark name. Can be filtered on when retrieving entries. * oldhashes and newhashes: each a single binary hash, or a list of binary hashes. These represent the old and new position of the named item. N) isinstancer=rrmakedaterrrRrrtrHryr)rrurrDrErrRr!r!r"r@us$   zjournalstorage.recordc Cs||t|dddU}|dtj|ddd}|r?|dtkr?|jt d| WdWddS|sJ| dtd|dtj | t |dWdn1sdwYWddSWddS1s|wYdS) Nr$sa+b)moder%ds&unsupported journal file version '%s' ) rseekosSEEK_SETrSrstorageversionr rrrnSEEK_ENDbytes)rrRrfversionr!r!r"rs&   "zjournalstorage._writeccsj|dur t|d}|durt|d}|D]}|dur%||js%q|dur/||js/q|VqdS)aUYield all journal entries with the given namespace or name Both the namespace and the name are optional; if neither is given all entries in the journal are produced. Matching supports regular expressions by using the `re:` prefix (use `literal:` to match names or namespaces that start with `re:`) N)r stringmatcherrur)rrurrr!r!r"filtereds zjournalstorage.filteredcs>j}jdur |SfddjD}t||S)zlIterate over the storage Yields journalentry instances for each contained journal record. Nc3s&|]}t|jjvr|VqdSrs)rtrHruryrvrr!r"rzsz*journalstorage.__iter__..)rrRrrk)rr%r|r!rr"__iter__s     zjournalstorage.__iter__r$Tc cs||sdS|| }|}Wdn1swY|d}|o*|d}|dtkr@|p6td}ttd||dd}|rLt|}|D] }|sSqNt |VqNdS)Nrrrs not availables!unknown journal file version '%s'r;) r~rSrrrr rreversedrr) rrRrqrrrrawlinesrrr!r!r"rs&        zjournalstorage._open)NN)r$T)rrrrrrrpropertyrrr0rrr@rrrrr!r!r!r"r&s    $ r&)s no-mergessgraphr7)allNsshow history for all names)ccommitsNsshow commit metadatacCsg|] }|dtvr|qS)r;) _ignoreopts)r]optr!r!r"r_sr_s[OPTION]... [BOOKMARKNAME]) helpcategoryc s(t|}d}|dr|rttdd}|r|d}|d|fdd}|d d krF|dur9td }nd |}|td |t |}d}| dt |j j |dD]\} }| |kren|jdd||jdd||j|jdd|j|dp|ddd|j|jdd|jddd|j|drrt|||} n tj||d|d} |jD]*} z || } | | Wqtjy} z d t!| WYd} ~ qd} ~ ww| "q[#|dur|td!dSdS)"azshow the previous position of bookmarks and the working copy The journal is used to see the previous commits that bookmarks and the working copy pointed to. By default the previous locations for the working copy. Passing a bookmark name will show all the previous positions of that bookmark. Use the --all switch to show previous locations for all bookmarks and the working copy; each line will then include the bookmark name, or '.' for the working copy, as well. If `name` starts with `re:`, the remainder of the name is treated as a regular expression. To match a name that actually starts with `re:`, use the prefix `literal:`. By default hg journal only shows the commit hash and the command that was running at that time. -v/--verbose will show the prior hash, the user, and the time at which it happened. Use -c/--commits to output log information on each commit hash; at this point you can use the usual `--patch`, `--git`, `--stat` and `--template` switches to alter the log output for these. `hg journal -T json` can be used to produce machine readable output. r<rs/You can't combine --all and filtering on a nameNrr7csjtj|dddS)Nsnoder)rsep) formatlistrhexfunc)nodesfmr!r" formatnodes'szjournal..formatnodesstemplatesjsonsthe working copy and bookmarkss'%s'sprevious locations of %s: )rsoldnodess%s -> snewnodess%ssusers %-8ssre:snames %-8ssdates %ss%Y-%m-%d %H:%M %1%2scommands %s rs changesets)diffoptss%s sno recorded locations )$r byteskwargsrHr rr formatterstatusrgetlimitpagerrcr'r startitem condwriteverboserDrnrEr startswithr formatdaterrisplainchangesetdisplayerchangesetformatternestedshowRepoLookupErrorplainrcloseend)r r,r5optsrr displaynamelimitrcount displayerrctxrwr!rr"r's| #           r')9r __future__r collectionsrVrrmercurial.i18nrmercurial.noderr mercurialrrrr r r r r rrrrrmercurial.utilsrrrcmdtabler testedwithrrIrAsharedbookmarksrtr#r/rr+rr9rrYrkrr namedtuplerobjectr&rlogoptsCATEGORY_CHANGE_ORGANIZATIONr'r!r!r!r"sb  <      DW