a +bO@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 Z wrapfunctionr runcommandrbmstorerecordbookmarksZ wrapfilecacher Zlocalrepository wrapdirstater wrappostshareunsharejournal)uir3/usr/lib64/python3.9/site-packages/hgext/journal.pyextsetupFsr cCs@|rz%_mergeentriesiter..rN)popmax enumeratenext StopIterationrZ itervalues) iterableskwargsrMZ iterable_mapkeyrPrBrrr_mergeentriesiters   r[c Kst|X|||fi||dd}|dWdn1sH0YWdn1sf0YdS)z namespacerOesharedfeaturesrr sz!unsharejournal..)r_)rM)pathsharedrr3r sharedreposourcerLrEexistsjoinrenamer$_openr[min_write) r,rr'Zrepopath sharedrepoZ journalpathZstorager"rientryrrerrs,     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 css|]}t|VqdSr`rrOhashrrrrgrRz+journalentry.fromstorage..,css|]}t|VqdSr`rurvrrrrgrR)splitfloatinttuple) clslinetimeusercommandrbnamer<r= timestampZtzrrr fromstorages,  zjournalentry.fromstoragec Cs`dttj|j}ddd|jD}ddd|jD}d||j|j|j |j ||fS)z bytes representation for storage rxcSsg|] }t|qSrrrvrrrrQ rRz*journalentry.__bytes__..cSsg|] }t|qSrrrvrrrrQrRrt) rlmaprbytestrrr<r=rrrbr)selfrr<r=rrr __bytes__ szjournalentry.__bytes__N) __name__ __module__ __qualname____doc__ classmethodrrr Z strmethod__str__rrrrrss  rsz9timestamp 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). rNcCsbt|_|j|_|j|_d|_|_|r^t|}t |}|dur^d|vr^|j|_||_dSr0) rZgetuserrrrErf sharedvfsrirLr rj)rr'Zfeaturesrqrrr__init__3s   zjournalstorage.__init__cCs2dttjtj}d|vr.|ddd}|S)Nrrtrs ...)rlrrZ shellquoter#_currentcommand partition)rZ commandstrrrrrBs  zjournalstorage.commandcGs ||_dS)z:Set the current hg arguments, stored with recorded entriesN)r)r}r.rrrr+Lszjournalstorage.recordcommandcCs(|dur dS|}|dus |js$dS|S)zoReturns the lock if it's held, or None if it's not. (This is copied from the localrepo class) N)Zheld)rZlockreflrrr _currentlockSs zjournalstorage._currentlockc Cs||jdurttdtd|j}ztj|dd|d}Wnrtjy}zX|j td||j ftj|d|j dd |d}|j td |j WYd}~n d}~00t ||_|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 AbortrbaserZLockHeldrwarnZlockerZ configintZdelayweakrefref)rrErrrKrrrjlock_s$ , zjournalstorage.jlockcCsrt|ts|g}t|ts |g}tt|j|j||||}|j}|jdurbt ||j vrb|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) isinstancer6rsrZmakedaterrrErrar>rfrp)rrbrr<r=rrrErrrr8us$    zjournalstorage.recordc Cs|||ddd}|dtj|ddd}|r||dtkr||jt d|WdWddS|s| dtd|dtj | t |dWdn1s0YWdn1s0YdS) Nr!sa+b)moder%ds&unsupported journal file version '%s' ) rseekosSEEK_SETrFrstorageversionrrrr]SEEK_ENDbytes)rrErrfversionrrrrps  zjournalstorage._writeccsh|durt|d}|dur,t|d}|D]2}|durH||jsHq0|dur\||js\q0|Vq0dS)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)rZ stringmatcherrbr)rrbrrrrrrfiltereds zjournalstorage.filteredcs>j}jdur|SfddjD}t||S)zlIterate over the storage Yields journalentry instances for each contained journal record. Nc3s$|]}t|jjvr|VqdSr`)rar>rbrfrcrrrrgsz*journalstorage.__iter__..)rnrErr[)rr"rirrr__iter__s    zjournalstorage.__iter__r!Tc cs||sdS||}|}Wdn1s40Y|d}|oR|d}|dtkr~|pjtd}ttd||dd}|rt|}|D]}|sqt |VqdS)Nrrrs not availables!unknown journal file version '%s'r4) rkrFryrrr rreversedrsr) rrEr^r_rrawlinesrr~rrrrns   &     zjournalstorage._open)NN)r!T)rrrrrrrpropertyrrr+rrr8rprrrnrrrrr#s   $ r#)s no-mergessgraphr1)rRallNsshow history for all names)ccommitsNsshow commit metadatacCsg|]}|dtvr|qS)r4) _ignoreopts)rOoptrrrrQrRrQs[OPTION]... [BOOKMARKNAME])Z helpcategoryc s2t|}d}|dr.|r*ttdd}|r:|d}|d|fdd}|d d kr|durrtd }nd |}|td |t |}d}| dt |j j |dD]T\} }| |krq|jdd||jdd||j|jdd|j|dp.|ddd|j|jdd|jddd|j|drrt|||} ntj||d|d} |jD]Z} z|| } | | Wn<tjy} z d t!| WYd} ~ n d} ~ 00q| "q#|dur.|td!dS)"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. r5rs/You can't combine --all and filtering on a nameNrr1csjtj|dddS)Nsnoderx)rsep)Z formatlistrZhexfunc)ZnodesZfmrr 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)Zdiffoptss%s sno recorded locations )$rZ byteskwargsr>r rr formatterstatusrZgetlimitZpagerrUr$rZ startitemZ condwriteverboser<r]r=r startswithrZ formatdaterrZisplainZchangesetdisplayerZchangesetformatternestedZshowZRepoLookupErrorZplainrcloseend)rr'r/ZoptsrrZ displaynamelimitrrcountZ displayerrwctxrdrrrr$st#           .  r$)9rZ __future__r collectionsrIrrZmercurial.i18nrZmercurial.noderrZ mercurialrrrr r r r r rrrrrZmercurial.utilsrrrZcmdtablerZ testedwithrr?r9Zsharedbookmarksrar r*rr&rr2rrLr[rr namedtuplersobjectr#rZlogoptsZCATEGORY_CHANGE_ORGANIZATIONr$rrrrs`  <      DW