^cpOdZddlZddlZddlZddlmZddlmZmZddl m Z m Z m Z m Z mZmZmZmZmZmZmZmZmZddlmZmZmZiZejeZdZdZdZd Z eej!iZ"d Z#d Z$d Z%d Z&dZ'dZ(dZ)dZ*dZ+dZ,dZ-Gddej.ddZ/GddZ0dZ1edddgde j2Dzdej3 d!Z4dS)"ztrack previous positions of bookmarks (EXPERIMENTAL) This extension adds a new command: `hg journal`, which shows you where bookmarks were previously located. N)_)binhex) bookmarkscmdutildispatchencodingerror extensionshg localrepolock logcmdutilpycompat registrarutil)dateutilprocutil stringutilsships-with-hg-coresbookmarks wdirparentcZtjtdttjtjdt tjtj dttjtdttjtdtdS)Ns runcommands_writedirstates postshares copystore)r wrapfunctionr runcommandrbmstorerecordbookmarks wrapfilecacher localrepository wrapdirstater wrappostshareunsharejournal)uis //usr/lib/python3/dist-packages/hgext/journal.pyextsetupr#DsHmZ@@@I-y/JJJ!; B m<<<B n=====c|rZt||_|jdt j|d\}}|rt||dSdSdS)N namejournalr)localjournalstoragejournal_wlockfreeprefixaddr isfilecached_setupdirstate)r!repodirstatecacheds r" reposetupr1Ns zz|| +%d++  !!.111$1$ DD&  + 4 * * * * * + +  + +r$c6tj||||||g|RS)z;Track the command line options for recording in the journal)r( recordcommand)origluir.cmdfullargsargss r"rr[s. (++ 4T3 04 0 0 00r$cT|j|_|dtdSNjournal)r)r(addparentchangecallbackrecorddirstateparents)r.r/s r"r-r-as)"lH $$Z1FGGGGGr$cf||}tj|drt|||S)z5Make journal storage available to the dirstate objectr))r safehasattrr-)r4r.r/s r"rrgs9tDzzH i(('tX&&& Or$c<t|}t|}tj|drh|d|jjkr |ddn|}|d|jjkr |ddn|}|jtd||dSdS)z3Records all dirstate parent changes in the journal.r(N.)listrr?_nodeconstantsnullidr(recordwdirparenttype)r/oldnew oldhashes newhashess r"r=r=os s))C s))C "233 "1v)@)GGGCGGS "1v)@)GGGCGGS && D)Y       r$c4|j}tj|drqtj|}|D]H\}}|||j}||kr"|j t|||I|||S)z,Records all bookmark changes in the journal.r)) _reporr?rritemsgetrEr)rF bookmarktype)r4storefpr.oldmarksmarkvalueoldvalues r"rr}s ;D i((I$T** ;;== I IKD%||D$+66H   ##L$%HHH 4r??r$c t|jdS#t$rtcYSwxYw)z,A set of shared features for this repositoryshared)setvfsread splitlinesFileNotFoundError)r.s r"_readsharedfeaturesr^sW48==++6688999 uu s8;AAc/K|dt}d|D}i}t|D]+\}} t|||g||<#t$rY(wxYw|rV||\}}}|V t|||d<n#t$r||=YnwxYw|TdSdS)zGiven a set of sorted iterables, yield the next entry in merged order Note that by default entries go from most recent to oldest. orderc,g|]}t|S)iter).0its r" z%_mergeentriesiter..s...bb...r$rN)popmax enumeratenext StopIterationvalues) iterableskwargsr` iterable_mapkeyrerUs r"_mergeentriesiterrqs' JJw $ $E..I...I LY''R !%b3 3L      D  "|224455sB  "#'88L a  " " "S!!! " """""s$A A$#A$B(( B87B8c |5|||fi||dd5}|ddddn #1swxYwYddddS#1swxYwYdS)zz!unsharejournal..sJ#'' 44FFFFFFr$)rz)r`)pathsharedrr?r sharedreposourcer^rZexistsjoinrenamer)_openrqmin_write) r4r!r.repopath sharedrepo journalpathstorager'rentryrs @r"r r s] X KKMM   T9 - - (.. ,T22  0.J<77x~.. @"hmmN;;  Kw)>???lGMM#5E"E z~EJJF +5&DDD 0 0tx//// 4D( # ##r$cNeZdZdZedZdZejeZ 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 ||d\}}}}}}}|\} } t| t| } } td|dD}td|dD}|| | f||||||S)N c34K|]}t|VdSr|rrdhashs r"rz+journalentry.fromstorage..(FF#d))FFFFFFr$,c34K|]}t|VdSr|rrs r"rz+journalentry.fromstorage..rr$)splitfloatinttuple) clslinetimeusercommandr~namerJrK timestamptzs r" fromstoragezjournalentry.fromstorages JJu          2i((#b''2 FF 0E0EFFFFF FF 0E0EFFFFF s O         r$c Vdttj|j}dd|jD}dd|jD}d||j|j|j |j ||fS)z bytes representation for storage rc,g|]}t|Srbrrs r"rfz*journalentry.__bytes__.. DDDTs4yyDDDr$c,g|]}t|Srbrrs r"rfz*journalentry.__bytes__.. rr$r) rmaprbytestrrrJrKrrr~r)selfrrJrKs r" __bytes__zjournalentry.__bytes__syyX-t~>>??IIDDT^DDDEE IIDDT^DDDEE zz       r$N) __name__ __module__ __qualname____doc__ classmethodrrr strmethod__str__rbr$r"rrsV "  [ 0   "!h ++GGGr$rz9timestamp user command namespace name oldhashes newhashesczeZdZdZdZdZdZedZe dZ dZ dZ d Z d Zdd Zd ZddZdS)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). rbNc.tj|_|j|_|j|_dx|_|_|r>t|}tj |}|d|vr|j|_||_dSdSdSdSr:) rgetuserrr!rZr sharedvfsrr^r r)rr.featuresrs r"__init__zjournalstorage.__init__/s$&& '8043dn ;;== /*400H,T22J%**@*@!+&.###  / /&%*@*@r$cdttjtj}d|vr|dddz}|S)Nrrrs ...)rrr shellquoter(_currentcommand partition)r commandstrs r"rzjournalstorage.command>sXYY #^%C D D   J  #--e44Q7'AJr$c||_dS)z:Set the current hg arguments, stored with recorded entriesN)r)rr7s r"r3zjournalstorage.recordcommandHs 'r$c8|dS|}||jsdS|S)zoReturns the lock if it's held, or None if it's not. (This is copied from the localrepo class) N)held)rlockrefls r" _currentlockzjournalstorage._currentlockOs. ?4 GII 9AF94r$c j||j!tjt dt d|jz} t j|dd|}n#tj$r}|j t d||j fzt j|d|j dd |}|j t d |j zYd}~nd}~wwxYwtj||_|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)rrZrrinsts r"jlockzjournalstorage.jlock[s=   T] + + 7+a HIIJJ J!""SX- F #2ADAAAAA~ F F F GLL899T4; % ##I..$2EEEn Cr$c||5|dd5}|dtj|ddd}|rQ|dt zkrC|jtd|z dddddddS|s | dt zdz|dtj | t|dzdddn #1swxYwYddddS#1swxYwYdS) Nr&sa+b)moder%ds&unsupported journal file version '%s' ) rseekosSEEK_SETr[rstorageversionr!rrruSEEK_ENDbytes)rrZrfversions r"rzjournalstorage._writes ZZ__ . .^&111 .Qq"+&&&&&))--e44Q7w%.*@@@ GLLDEEO . . . . . . . . . . . . . . >GGU^3u<===q"+&&&e u,---% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .sBEB D9. EA'D9- E9D= =ED= EEEc#K|tj|d}|tj|d}|D],}|||js|||js(|V-dS)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 stringmatcherr~r)rr~rrs r"filteredzjournalstorage.filtereds  "0;;B?I  +D11"5D  E$YYu-G-G$UZ(8(8KKKK   r$cj}j|SfdjD}t||S)zlIterate over the storage Yields journalentry instances for each contained journal record. Nc3hK|],}t|jjv(|V-dSr|)r}rOr~r)rdrrs r"rz*journalstorage.__iter__..sM  ##AK00D4GGG GGGG  r$)rrZrrq)rr'rs` r"__iter__zjournalstorage.__iter__sm  48$$ > !L    ZZ//    !///r$r&Tc#K||sdS||5}|}dddn #1swxYwY|d}|o|d}|dtzkr5|pt d}t jt d|z|dd}|rt|}|D]!}|st |V"dS)Nrrrs not availables!unknown journal file version '%s'rA) rr[rrrr rreversedrr) rrZryrzrrawlinesrrs r"rzjournalstorage._opensQzz(##  F S]] a&&((C                %  $E!H en, , ,4#3!4!4G+a DEEOPP P abb   $UOOE 1 1D **400 0 0 0 0 1 1sAA  A )NN)r&T)rrrrrrrpropertyrrr3rrrFrrrrrbr$r"r(r(s"OH / / /X''['   ," " " H....*000(111111r$r()s no-mergessgraphr;)r$allNsshow history for all names)ccommitsNsshow commit metadatac0g|]}|dtv|S)rA) _ignoreopts)rdopts r"rfrfs&CCCsQ{)B)Bs)B)B)Br$s[OPTION]... [BOOKMARKNAME]) helpcategoryc tj|}d}|dr%|r!tjt dd}|r|d}|d|fd}|dd kr<|t d }nd |z}|t d |ztj |}d}| dt|j | D]\} }| |krn |jdd||jdd||j|jdd|j|dp|ddd|j|jdd|jddd|j|dr؉rtj|||} n+tj||d|} |jD]f} || } | | !#tj$r4}  dtj!| zYd} ~ _d} ~ wwxYw| "#|$|t d 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. rBrs/You can't combine --all and filtering on a nameNrr;cZtj|ddS)Nsnoder)rsep) formatlistrhexfunc)nodesfms r" formatnodeszjournal..formatnodes#s'}}SU33't}LLLr$stemplatesjsonsthe 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 byteskwargsrOr rr formatterstatusrgetlimitpagerrir)r startitem condwriteverboserJrurKr startswithr formatdaterrisplainchangesetdisplayerchangesetformatternestedshowRepoLookupErrorplainrcloseend)r!r.r8optsrr displaynamelimitrcount displayerrctxrrs @r"r)r)sF   % %D D xx  +DEE  Aw j$ ' 'BMMMMM xx '' <=>>KK!D.K !233kABBB   % %E EHHZ!$,"7"7T"7"B"BCC&& u E>> E  J Y EO0L0L    e[[%A%ABBB RZ(EJ??? HHV   7 7 7   J     J   MM%/+A B B    Y 666 88J   zz|| &9"dDII &9bii 66  > >>t*CNN3'''',>>>HHY)9!)<)<<========> OO   FFHHH } !.//00000}sKL!-*LL!)5r collectionsrrmercurial.i18nrmercurial.noderr mercurialrrrr r r r r rrrrrmercurial.utilsrrrcmdtabler testedwithrrPrGsharedbookmarksr}r#r1rr-rr=rr^rqrr namedtuplerr(rlogoptsCATEGORY_CHANGE_ORGANIZATIONr)rbr$r"r(s    ) H % % #  "$ >>> + + +111 HHH        """:###$$$>A,A,A,A,A,KCA,A,A,HQ1Q1Q1Q1Q1Q1Q1Q1l'  :9DCgoCCC D "5   ^1^1  ^1^1^1r$