
    	^cpO                        d Z ddlZddlZddlZddlmZ ddlmZmZ ddl	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZ i Z ej        e          ZdZdZdZd	Z eej!        iZ"d
 Z#d Z$d Z%d Z&d Z'd Z(d Z)d Z*d Z+d Z,d Z- G d d ej.        dd                    Z/ G d d          Z0dZ1 edddgd ej2        D             z   dej3                   d!             Z4dS )"ztrack previous positions of bookmarks (EXPERIMENTAL)

This extension adds a new command: `hg journal`, which shows you where
bookmarks were previously located.

    N)_)binhex)	bookmarkscmdutildispatchencodingerror
extensionshg	localrepolock
logcmdutilpycompat	registrarutil)dateutilprocutil
stringutils   ships-with-hg-cores   bookmarks
   wdirparentc                 Z   t          j        t          dt                     t          j        t          j        dt                     t          j        t          j	        dt                     t          j        t          dt                     t          j        t          dt                     d S )Ns
   runcommands   _write   dirstates	   postshares	   copystore)r   wrapfunctionr   
runcommandr   bmstorerecordbookmarkswrapfilecacher   localrepositorywrapdirstater   wrappostshareunsharejournal)uis    //usr/lib/python3/dist-packages/hgext/journal.pyextsetupr#   D   s    HmZ@@@I-y/JJJ!;   Bm<<<Bn=====    c                     |                                 rZt          |          |_        |j                            d           t          j        |d          \  }}|rt          ||           d S d S d S )N   namejournalr   )localjournalstoragejournal_wlockfreeprefixaddr   isfilecached_setupdirstate)r!   repodirstatecacheds       r"   	reposetupr1   N   s    zz|| 	+%d++!!.111$1$DD& 	+ 4*****	+ 	+
	+ 	+r$   c                 6    t          j        |   | ||||g|R  S )z;Track the command line options for recording in the journal)r(   recordcommand)origluir.   cmdfullargsargss         r"   r   r   [   s.     (++4T3040000r$   c                 T    | j         |_        |                    dt                     d S N   journal)r)   r(   addparentchangecallbackrecorddirstateparents)r.   r/   s     r"   r-   r-   a   s)    "lH$$Z1FGGGGGr$   c                 f     | |          }t          j        |d          rt          ||           |S )z5Make journal storage available to the dirstate objectr)   )r   safehasattrr-   )r4   r.   r/   s      r"   r   r   g   s9    tDzzHi(( 'tX&&&Or$   c                 <   t          |          }t          |          }t          j        | d          rh|d         | j        j        k    r
|dd         n|}|d         | j        j        k    r
|dd         n|}| j                            t          d||           dS dS )z3Records all dirstate parent changes in the journal.r(      N   .)listr   r?   _nodeconstantsnullidr(   recordwdirparenttype)r/   oldnew	oldhashes	newhashess        r"   r=   r=   o   s    
s))C
s))C"233 
"1v)@)GGGCGGS	"1v)@)GGGCGGS	&&D)Y	
 	
 	
 	
 	
	
 
r$   c                 4   |j         }t          j        |d          rqt          j        |          }|                                D ]H\  }}|                    ||j                  }||k    r"|j        	                    t          |||           I | ||          S )z,Records all bookmark changes in the journal.r)   )_repor   r?   r   r   itemsgetrE   r)   rF   bookmarktype)r4   storefpr.   oldmarksmarkvalueoldvalues           r"   r   r   }   s    ;Di(( I$T** ;;== 	I 	IKD%||D$+66H  ##L$%HHH4r??r$   c                     	 t          | j                            d                                                    S # t          $ r t                      cY S w xY w)z,A set of shared features for this repository   shared)setvfsread
splitlinesFileNotFoundError)r.   s    r"   _readsharedfeaturesr^      sW    48==++6688999   uus   8; AAc               /     K   |                     dt                    }d | D             } i }t          |           D ]+\  }}	 t          |          ||g||<   # t          $ r Y (w xY w|rV ||                                          \  }}}|V  	 t          |          ||         d<   n# t          $ r ||= Y nw xY w|TdS dS )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).0its     r"   
<listcomp>z%_mergeentriesiter.<locals>.<listcomp>   s    ...bb...r$   r   N)popmax	enumeratenextStopIterationvalues)	iterableskwargsr`   iterable_mapkeyre   rU   s          r"   _mergeentriesiterrq      s'     
 JJw$$E..I...I
 LY''  R	!%b3 3L 	 	 	D	  "|224455sB	"#'88La   	" 	" 	"S!!!	"  " " " " "s$   A
A$#A$B( (B87B8c                     |                                 5   | ||fi | |                    dd          5 }|                    d           ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )z<Mark this shared working copy as sharing journal informationrX      as   journal
N)wlockrZ   write)r4   
sourcerepodestreporn   rR   s        r"   r   r      s   			 # #Z,,V,,,\\)T** 	#bHH\"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	## # # # # # # # # # # # # # # # # #s4   !A0AA0A	A0A	 A00A47A4c                 |  
 |j         |k    r#|                                rt          j        |d          rt	          j        |          }t          |          
|rԉ
dhk    r|j                            d          r2|j        	                    d          }t          j
        ||dz              |j        }|                    |j        dd          }
fd|                    |j        d	          D             }t          ||t          
          D ]}	|                    |j        |	            | |||          S )z9Copy shared journal entries into this repo when unsharingr)   r;   r&   s   .baks   namejournal.bakF)filename_newestfirstc              3   ^   K   | ]'}t                               |j                  v #|V  (d S N)sharednamespacesrO   	namespace)rd   esharedfeaturess     r"   	<genexpr>z!unsharejournal.<locals>.<genexpr>   sJ        #''44FF FFFF r$   )rz   )r`   )pathsharedr   r?   r   sharedreposourcer^   rZ   existsjoinrenamer)   _openrq   min_write)r4   r!   r.   repopath
sharedrepojournalpathstorager'   r   entryr   s             @r"   r    r       s]    		XKKMM 	T9-- 	 (..
,T22 	0.J<77 x~.. @"hmmN;;Kw)>???lGMM#5E "  E    z~EJJ  F
 +5&DDD 0 0tx////4D(###r$   c                   N    e Zd ZdZed             Zd Z ej        e          Z	dS )journalentrya  Individual 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          |
          }
}	t          d |                     d          D                       }t          d |                     d          D                       } | |	|
f||||||          S )N   
c              3   4   K   | ]}t          |          V  d S r|   r   rd   hashs     r"   r   z+journalentry.fromstorage.<locals>.<genexpr>   (      FF#d))FFFFFFr$      ,c              3   4   K   | ]}t          |          V  d S r|   r   r   s     r"   r   z+journalentry.fromstorage.<locals>.<genexpr>   r   r$   )splitfloatinttuple)clslinetimeusercommandr~   namerJ   rK   	timestamptzs              r"   fromstoragezjournalentry.fromstorage   s     JJu	


	2i((#b''2	FF	0E0EFFFFF	FF	0E0EFFFFF	sO
 
 	
r$   c           	      V   d                     t          t          j        | j                            }d                     d | j        D                       }d                     d | j        D                       }d                     || j        | j        | j	        | j
        ||f          S )z bytes representation for storage    r   c                 ,    g | ]}t          |          S rb   r   r   s     r"   rf   z*journalentry.__bytes__.<locals>.<listcomp>	      DDDTs4yyDDDr$   c                 ,    g | ]}t          |          S rb   r   r   s     r"   rf   z*journalentry.__bytes__.<locals>.<listcomp>
  r   r$   r   )r   mapr   bytestrr   rJ   rK   r   r   r~   r   )selfr   rJ   rK   s       r"   	__bytes__zjournalentry.__bytes__  s    yyX-t~>>??IIDDT^DDDEE	IIDDT^DDDEE	zz		

 

 
	
r$   N)
__name__
__module____qualname____doc__classmethodr   r   r	   	strmethod__str__rb   r$   r"   r   r      sV         " 
 
 [
0
 
 
" !h ++GGGr$   r   z9timestamp user command namespace name oldhashes newhashesc                   z    e Zd ZdZdZdZd Zed             Ze	d             Z
d Zd Zd	 Zd
 ZddZd ZddZdS )r(   ae  Storage 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).

    rb   Nc                 .   t          j                    | _        |j        | _        |j        | _        d x| _        | _        |                                r>t          |          }t          j
        |          }|d|v r|j        | _        || _        d S d S d S d S r:   )r   getuserr   r!   rZ   r   	sharedvfsr   r^   r   r   )r   r.   featuresr   s       r"   __init__zjournalstorage.__init__/  s    $&&	'8 043dn;;== 	/*400H,T22J%**@*@!+&.###	/ 	/ &%*@*@r$   c                     d                     t          t          j        t          j                            }d|v r|                    d          d         dz   }|S )Nr   r   r   s    ...)r   r   r   
shellquoter(   _currentcommand	partition)r   
commandstrs     r"   r   zjournalstorage.command>  sX    YY#^%CDD
 

 J#--e44Q7'AJr$   c                     || _         dS )z:Set the current hg arguments, stored with recorded entriesN)r   )r   r7   s     r"   r3   zjournalstorage.recordcommandH  s    
 'r$   c                 8    |dS  |            }||j         sdS |S )zoReturns the lock if it's held, or None if it's not.

        (This is copied from the localrepo class)
        N)held)r   lockrefls      r"   _currentlockzjournalstorage._currentlockO  s.    
 ?4GII9AF94r$   c           	      j   |                      | j                  !t          j        t	          d                    t	          d          |j        z  }	 t          j        |dd|          }n# t          j        $ r}| j        	                    t	          d          ||j
        fz             t          j        |d| j                            dd	          |          }| j        	                    t	          d
          |j        z             Y d}~nd}~ww xY wt          j        |          | _        |S )z"Create a lock for the journal fileNs%   journal lock does not support nestings   journal of %ss   namejournal.lockr   )descs"   waiting for lock on %s held by %r
s   uis   timeouts   got lock after %s seconds
)r   _lockrefr
   Abortr   baser   LockHeldr!   warnlocker	configintdelayweakrefref)r   rZ   r   r   insts        r"   jlockzjournalstorage.jlock[  s=   T]++7+a HIIJJJ!""SX-	F	#2ADAAAAA~ 	F 	F 	FGLL899T4;<OO   	#!!%44	  A GLL9::QWDEEEEEEEE	F  As   A- -D<BDDc           	      ^   t          |t                    s|g}t          |t                    s|g}t          t          j                    | j        | j        ||||          }| j        }| j        (t          
                    |          | j        v r| j        }|                     ||           dS )a  Record 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)
isinstancerC   r   r   makedater   r   rZ   r   r}   rO   r   r   )r   r~   r   rJ   rK   r   rZ   s          r"   rF   zjournalstorage.recordq  s     )T** 	$"I)T** 	$"IIL
 
 h>%  ##I..$2EEEnCr$   c                    |                      |          5   |dd          5 }|                    dt          j                   |                    d                              d          d         }|rQ|dt          z  k    rC| j                            t          d          |z             	 d d d            d d d            d S |s |
                    dt          z  dz              |                    dt          j                   |
                    t          |          dz              d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )	Nr&   s   a+b)moder             %ds&   unsupported journal file version '%s'
)r   seekosSEEK_SETr[   r   storageversionr!   r   r   ru   SEEK_ENDbytes)r   rZ   r   fversions        r"   r   zjournalstorage._write  s   ZZ__ 	. 	.^&111 .Qq"+&&& &&))--e44Q7 w%.*@@@
 GLLDEEO   . . . . . .	. 	. 	. 	. 	. 	. 	. 	.   >GGU^3u<===q"+&&&eu,---%. . . . . . . . . . . . . . .	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.sB   EB
D9.EA'D9-E9D=	=E D=	EEEc              #      K   |t          j        |          d         }|t          j        |          d         }| D ],}| ||j                  s| ||j                  s(|V  -dS )aU  Yield 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   )r   r~   r   r   s       r"   filteredzjournalstorage.filtered  s        "0;;B?I+D11"5D 	 	E$YYu-G-G$UZ(8(8KKKK	 	r$   c                                             j                  } j        |S  fd                       j                  D             }t          ||          S )zlIterate over the storage

        Yields journalentry instances for each contained journal record.

        Nc              3   h   K   | ],}t                               |j                  j        v (|V  -d S r|   )r}   rO   r~   r   )rd   r   r   s     r"   r   z*journalstorage.__iter__.<locals>.<genexpr>  sM       
 
##AK00D4GGG GGGG
 
r$   )r   rZ   r   rq   )r   r'   r   s   `  r"   __iter__zjournalstorage.__iter__  sm     

48$$>!L
 
 
 
ZZ//
 
 

 !///r$   r&   Tc              #     K   |                     |          sd S  ||          5 }|                                }d d d            n# 1 swxY w Y   |                    d          }|o|d         }|dt          z  k    r5|pt	          d          }t          j        t	          d          |z            |dd          }|rt          |          }|D ]!}|st          	                    |          V  "d S )Nr   r   r   s   not availables!   unknown journal file version '%s'rA   )
r   r[   r   r   r   r
   r   reversedr   r   )	r   rZ   ry   rz   r   rawlinesr   r   s	            r"   r   zjournalstorage._open  sQ     zz(## 	FS]] 	a&&((C	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 		%  $E!Hen,,,4#3!4!4G+a DEEOPPP
 abb	 	$UOOE 	1 	1D **4000000	1 	1s   AA
A
)NN)r&   T)r   r   r   r   r   r   r   propertyr   r   r3   r   r   rF   r   r   r   r   rb   r$   r"   r(   r(     s         " OH/ / /   X ' ' ['
 
 
  ,"  "  " H. . ..   *0 0 0(1 1 1 1 1 1r$   r(   )s	   no-mergess   graphr;   )r$      allNs   show history for all names)   c   commitsNs   show commit metadatac                 0    g | ]}|d          t           v|S )rA   )_ignoreopts)rd   opts     r"   rf   rf     s&    CCCsQ{)B)Bs)B)B)Br$   s   [OPTION]... [BOOKMARKNAME])helpcategoryc           
         t          j        |          }d}|                    d          r%|r!t          j        t          d                    d}|r|d         }|                     d|          fd}|                    d          d	k    r<|t          d
          }nd|z  }|                     t          d          |z             t          j	        |          }d}| 
                    d           t          |j                            |                    D ]\  }	}|	|k    r n                                                     | j        dd ||j                                                 dd ||j                                                 | j        dd|j                                       |                    d          p|                    d          dd|j                                       | j        dd                    |j        d                                         dd|j                   |                    d          r؉                                rt          j        | ||          }
n+t          j        | |                    d          |          }
|j        D ]f}	 ||         }|
                    |           !# t          j        $ r4}                     dt          j!        |          z             Y d}~_d}~ww xY w|
"                                 #                                 |$|                     t          d                      dS dS )!az  show 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.

    rB   r   s/   You can't combine --all and filtering on a nameNr   r;   c                 Z                         t          j        |           dd          S )Ns   noder   )r   sep)
formatlistr   hexfunc)nodesfms    r"   formatnodeszjournal.<locals>.formatnodes#  s'    }}SU33't}LLLr$   s   templates   jsons   the working copy and bookmarkss   '%s's   previous locations of %s:
)r   s   oldnodess   %s -> s   newnodess   %ss   users    %-8ss   re:s   names     %-8ss   dates    %ss   %Y-%m-%d %H:%M %1%2s   commands     %s
r   s
   changesets)diffoptss   %s

s   no recorded locations
)$r   byteskwargsrO   r
   r   r   	formatterstatusr   getlimitpagerri   r)   r   	startitem	condwriteverboserJ   ru   rK   r   
startswithr   
formatdater   r   isplainchangesetdisplayerchangesetformatternestedshowRepoLookupErrorplainr   closeend)r!   r.   r8   optsr   r  displaynamelimitr   count	displayerr   ctxr   r  s                 @r"   r)   r)     s   F %%DDxx  	+DEE    Aw	j$	'	'BM M M M M xx''<=>>KK!D.K
		!233kABBB%%EEHHZ!$,"7"7T"7"B"BCC & &uE>>E

JYEO0L0L	
 	
 	
 	e[[%A%ABBB
RZ(EJ???
HHV7 7 7J		
 	
 	
 	JMM%/+ABB		
 	
 	
 	Y66688J 	zz|| &9"dDII		&9bii66  	  > >>t*CNN3'''', > > >HHY)9!)<)<<========>OOFFHHH}
		!.//00000 }s    KL!-*LL!)5r   collectionsr   r   mercurial.i18nr   mercurial.noder   r   	mercurialr   r   r   r	   r
   r   r   r   r   r   r   r   r   mercurial.utilsr   r   r   cmdtabler   
testedwithr   rP   rG   sharedbookmarksr}   r#   r1   r   r-   r   r=   r   r^   rq   r   r    
namedtupler   r(   r   logoptsCATEGORY_CHANGE_ORGANIZATIONr)   rb   r$   r"   <module>r(     s        				              
                                       
)
H
%
% #
   "$ 
> > >
+ 
+ 
+1 1 1H H H  

 

 

	 	 	  " " ":# # #$ $ $>A, A, A, A, A,KC A, A, A,HQ1 Q1 Q1 Q1 Q1 Q1 Q1 Q1l ' 	:9 DCgoCCC	D
 "5	 	 	^1 ^1	 	^1 ^1 ^1r$   