
    	^cW                         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 ddZ G d d	          Z	 dd
Zd ZddZd Zd Zd Zd ZdS )    N   )_)hexshort)
	bookmarks	branchmaperrorobsoletephasespycompatscmutilsetdiscoverytreediscoveryutilFc                   	
 |                     d          st          j        | |||          S |r,| j        j        
t          
fd|D                       r|d|fS t          j        | j        | || |          }|\  }}}|r)|s'| j        j        	t          	fd|D                       }t          |          ||pt          |          fS )a  Return a tuple (common, anyincoming, heads) used to identify the common
    subset of nodes between repo and remote.

    "common" is a list of (at least) the heads of the common subset.
    "anyincoming" is testable as a boolean indicating if any nodes are missing
      locally. If remote does not support getbundle, this actually is a list of
      roots of the nodes that would be incoming, to be supplied to
      changegroupsubset. No code except for pull should be relying on this fact
      any longer.
    "heads" is either the supplied heads, or else the remote's heads.
    "ancestorsof" if not None, restrict the discovery to a subset defined by
      these nodes. Changeset outside of this set won't be considered (but may
      still appear in "common").

    If you pass heads and they are all known locally, the response lists just
    these heads in "common" and in "heads".

    Please use findcommonoutgoing to compute the set of outgoing nodes to give
    extensions a good hook into outgoing.
    s	   getbundlec              3   .   K   | ]} |          V  d S N .0h	knownnodes     5/usr/lib/python3/dist-packages/mercurial/discovery.py	<genexpr>z%findcommonincoming.<locals>.<genexpr>:   s+      ++yy||++++++    F)abortwhenunrelatedancestorsofc              3   0   K   | ]} |           V  d S r   r   )r   nhas_nodes     r   r   z%findcommonincoming.<locals>.<genexpr>H   s-      44!_444444r   )capabler   findcommonincoming	changeloghasnodeallr   findcommonheadsuianylist)reporemoteheadsforcer   rescommonanyincsrvheadsr    r   s            @@r   r"   r"      s   , >>,'' L/feUKKK )N*	++++U+++++ 	)5%((

&$9  C  #FFH 5V 5>)4444e44444LL&%"94>>::r   c                   b    e Zd ZdZ	 ddZd Zej        d             Zej        d             Z	dS )outgoinga  Represents the result of a findcommonoutgoing() call.

    Members:

      ancestorsof is a list of the nodes whose ancestors are included in the
      outgoing operation.

      missing is a list of those ancestors of ancestorsof that are present in
      local but not in remote.

      common is a set containing revs common between the local and the remote
      repository (at least all of those that are ancestors of ancestorsof).

      commonheads is the list of heads of common.

      excluded is the list of missing changeset that shouldn't be sent
      remotely.

    Some members are computed on demand from the heads, unless provided upfront
    by discovery.Nc                    d ||fv sJ j         }||                                }|rug }|D ]6}|                    fd|                    |          D                        7|                    ||          \  }}	}
t          |          |
}fd|D             }n
|sj        g}|| _        || _        || _	        d | _
        d | _        g | _        d S )Nc                 *    g | ]}|j         k    |S r   )nullid)r   pr*   s     r   
<listcomp>z%outgoing.__init__.<locals>.<listcomp>m   s%    !O!O!Oa4;>N>N!>N>N>Nr   c                     g | ]}|v|	S r   r   )r   r   includeds     r   r8   z%outgoing.__init__.<locals>.<listcomp>t   s#    EEE1H3D3D13D3D3Dr   )r#   r,   extendparentsnodesbetweensetr6   commonheadsr   _revlog_common_missingexcluded)selfr*   r?   r   missingrootscl	discbasesr   csetsrootsr,   r:   s    `         @r   __init__zoutgoing.__init__b   s    \22222^((**K 	(I! Q Q  !O!O!O!ORZZ]]!O!O!OPPPP #%//,"L"LE5%5zzHKEEEEiEEEKK 	(;-K&&r   c                 n    | j                             | j        | j                  }|\  | _        | _        d S r   )r@   findcommonmissingr?   r   rA   rB   )rD   setss     r   _computecommonmissingzoutgoing._computecommonmissing~   s8    |--d.
 
 '+#dmmmr   c                 F    | j         |                                  | j         S r   )rA   rN   rD   s    r   r/   zoutgoing.common   s$    <&&(((|r   c                 F    | j         |                                  | j         S r   )rB   rN   rP   s    r   missingzoutgoing.missing   s$    = &&(((}r   )NNN)
__name__
__module____qualname____doc__rJ   rN   r   propertycacher/   rR   r   r   r   r3   r3   L   s         , FJ   8+ + + 
  
 
    r   r3   c                 v   t          | dd          }|t          | |||          }|\  |_        }}| j        j        t
          j                 p| j        }	|	s|p|                                 |_	        n=|Q| 
                    d                                          |_	        d |                     d          D             |_        n| j                            |j        |          }
|
\  |_        }g x|_        }g x|_        }|D ]k}| |         }|                                t
          j        k    s|                                r|                    |           V|                    |           lt)          |          t)          |          k    r|}nt          j        | ||          }||_	        |r|                                 | j        fd|j        D             }t                              |                    |z
  |_        t          |j                  fd|j	        D             |_	        |S )aN  Return an outgoing instance to identify the nodes present in repo but
    not in other.

    If onlyheads is given, only nodes ancestral to nodes in onlyheads
    (inclusive) are included. If you already know the local repo's heads,
    passing them in onlyheads is faster than letting them be recomputed here.

    If commoninc is given, it must be the result of a prior call to
    findcommonincoming(repo, other, force) to avoid recomputing it here.

    If portable is given, compute more conservative common and ancestorsof,
    to make bundles created from the instance more portable.N)r-   r   s   servedc                 6    g | ]}|                                 S r   noder   ctxs     r   r8   z&findcommonoutgoing.<locals>.<listcomp>   s     PPPcsxxzzPPPr   s   secret() or extinct()c                 :    h | ]}                     |          S r   rev)r   r   rF   s     r   	<setcomp>z%findcommonoutgoing.<locals>.<setcomp>   s#    666Qrvvayy666r   c                     g | ]}|v|	S r   r   )r   r   r?   s     r   r8   z&findcommonoutgoing.<locals>.<listcomp>   s#    LLLq7K7K!7K7K7Kr   )r3   r"   r?   _phasecache
phaserootsr   secretobsstorer,   r   filteredr>   rC   r#   rL   rA   rB   phaseextinctappendlennewheadsrN   	ancestors)r*   other	onlyheadsr-   	commonincportableog_any_hds
mayexcluderM   
allmissingrR   rC   r[   r]   r   missingrevsrF   r?   s                     @@r   findcommonoutgoingrx      s9     
$d	#	#B &%u)
 
 
	 "+BND$ !,V];Lt}J %"2djjll		y117799PPTXX6N-O-OPPP ~//	JJ!%
J ""g!##h 	% 	%Dt*Cyy{{fm++s{{}}+%%%%t$$$$w<<3z??**#KK /$	8DDK$ 	M 	  """^6666"+666k2233kA
".))LLLLR^LLLIr   c                    | j                                         }| j        }| j        }|j        }i }t                      }t                      }|j        D ]F}||         }	|                    |	           |                    |	                                           G|	                                5 }
|

                    di                                           }ddd           n# 1 swxY w Y   |j        }|                                D ]^\  }}||vr
g }g }|D ]8} ||          r|                    |           #|                    |           9|t          |          |f||<   _|D ]}||vrdg g f||<   t!          j        |d |                                D                       }|                    |d |D                        |                                D ]\  }}|||         d         dd<   |                                D ])\  }}|D ]}||                                 |g fz   ||<   *|j        r|j        j        fd|j        D             }|fd|j        D             z  }|j                            |d	          }t3          t5          j        |                    D ]L\  }}|\  }}}}t9          | ||          }|t3          |d
                   |t3          |d                   f||<   M|S )a  compute a summary of branch and heads status before and after push

    return {'branch': ([remoteheads], [newheads],
                       [unsyncedheads], [discardedheads])} mapping

    - branch: the branch name,
    - remoteheads: the list of remote heads known locally
                   None if the branch is new,
    - newheads: the new remote heads (known locally) with outgoing pushed,
    - unsyncedheads: the list of remote heads unknown locally,
    - discardedheads: the list of heads made obsolete by the push.
    	   branchmapNc              3   @   K   | ]\  }}|d          ||d         fV  dS )r   Nr   r   r   branchr,   s      r   r   z _headssummary.<locals>.<genexpr>  sE       	
 	
Qx# U1X####	
 	
r   c              3   >   K   | ]}|                                 V  d S r   r_   r\   s     r   r   z _headssummary.<locals>.<genexpr>  s*      99s999999r   r   c                 &    h | ]} |          S r   r   r   r   torevs     r   ra   z _headssummary.<locals>.<setcomp>  s!    >>>AuuQxx>>>r   c                 &    h | ]} |          S r   r   r   s     r   ra   z _headssummary.<locals>.<setcomp>  s!    ???Qa???r   T)	inclusiver   )r*   
unfilteredr+   r3   r#   r>   rR   addr}   commandexecutorcallcommandresultr$   itemsrj   r)   r   remotebranchcacheupdatesortrf   r`   r   r?   rm   sortedr   	iteritems_postprocessobsolete)pushopr*   r+   r3   rF   headssum
missingctxbranchesr   r]   e	remotemapr   r}   r,   knownunsyncedr   newmaprl   r   lfutureheadsallfuturecommonremoteheadsunsyncedheadsplaceholderr   r   s                               @r   _headssummaryr      s    ;!!##D]FH	BHJuuH # #1gsSZZ\\""""				!	! =QMM,33::<<	= = = = = = = = = = = = = = = 
I"** : :!! 	# 	#Ay|| #Q""""!4;;9  . .!! $b"~HV (	
 	
!)!1!1	
 	
 	
 F MM$99j999:::"LLNN * *!)AAA!)) ) ) 	 	A} B5= } ">>>>)=>>>????(*>????.22;$2OO#H$6x$@$@AA 	 	MFE@E=K=+)&/8LLFvay!!vay!!	 HV Os   0)C%%C),C)c                     | j         j        t          fd|D                       }|                     d||j                  }t          d |D                       }|rdg}ng }d|||g fiS )z;Compute branchmapsummary for repo without branchmap supportc              3   2   K   | ]} |          |V  d S r   r   r   s     r   r   z#_oldheadssummary.<locals>.<genexpr>.  s0      ==A		!=a======r   s   heads(%ln + %ln)c              3   >   K   | ]}|                                 V  d S r   rZ   )r   cs     r   r   z#_oldheadssummary.<locals>.<genexpr>5  s*      **1affhh******r   N)r#   r$   r   r>   rR   )	r*   r   r3   incoldheadsrrl   r   r   s	           @r   _oldheadssummaryr   '  s     &I=========H 	$h0@AAA*******H
 68Xx455r   c                    | j                                         }| j        }|j        |                                5 }|                    dddi                                          }d d d            n# 1 swxY w Y   t                      }fd| j        	                    dd          D             }D ]}|
                    |          }|rX||v rT||                  ||         }
}	t          j        ||
|	          r'|                    |	                                           q||v r||vr|                    |                    |S )Ns   listkeyss	   namespaces	   bookmarksc                 :    g | ]}                     |          S r   )
expandname)r   blocalbookmarkss     r   r8   z _nowarnheads.<locals>.<listcomp>O  s7        	!!!$$  r   s   pushing)r*   r   r+   
_bookmarksr   r   r   r>   r'   
configlistgetr   	validdestr   r[   )r   r*   r+   r   remotebookmarksbookmarkedheadsnewbookmarksbmrnodelctxrctxr   s              @r   _nowarnheadsr   >  s   ;!!##D]F_N				!	! Q--l
 

 &(( 	               eeO   %%lJ??  L
  8 8##B'' 	8Ud]]nR014;$D"4t44 1##DIIKK000\!!b&?&?##N2$6777s   +A44A8;A8c                 	   | j                                         }| j        }| j        }| j        }| j        }t          | j                  }||j        gk    rdS |	                    d          rt          |           }nt          ||||          }|| _        d |                                D             }|r|sd                    t          |                    }	t!                      }
|                                                                D ]\  }}}}|r|
                    |           |
t!          |          z  }
|
r"t)          d          |	t+          |
          fz  }nt)          d          |	z  }t)          d          }t-          j        ||          t1          |           }d}t          t3          j        |                    D ]\  }}|\  }}}}|t!                      }nt!          |          }|                    |           d}t!          |          }|                    |           |rd|v rd}nt9          j        ||          }|(|j                            t)          d	                     nY|+|j                            t)          d
          |z             n,|j                            t)          d          ||fz             |Ft+          |          dk    r2tA          |          }|!t)          d          |z  }t)          d          }n5t+          |          t+          |          k    rt          ||z
  |z
            }|rc||dvr(t)          d          tC          |d                   |fz  }n||d                  "                                rLt)          d          tC          |d                   ||d                  "                                d         fz  }n%t)          d          tC          |d                   z  }|rt)          d          }nt)          d          }|(|j        #                    t)          d                     n*|j        #                    t)          d          |z             |D ],}|j        #                    dtC          |          z             -|rt-          j        ||          dS )zpCheck that a push won't add any outgoing head

    raise StateError error and display ui message as needed.
    Nrz   c                 (    g | ]\  }}|d          |S )r   r   r|   s      r   r8   zcheckheads.<locals>.<listcomp>}  s,        65a8H8H8H8Hr   s   , s0   push creates new remote branches: %s (%d closed)s$   push creates new remote branches: %ss8   use 'hg push --new-branch' to create new remote branches)hints,   remote has heads that are not known locally
s0   remote has heads that are not known locally: %s
s?   remote has heads on branch '%s' that are not known locally: %s
r   s0   push creates new branch '%s' with multiple headss?   merge or see 'hg help push' for details about pushing new heads)s   defaultNs.   push creates new remote head %s on branch '%s'r   s2   push creates new remote head %s with bookmark '%s's   push creates new remote head %ssH   pull and merge or see 'hg help push' for details about pushing new headss   new remote heads:
s!   new remote heads on branch '%s':
s    %s
)$r*   r   r+   r3   r   	newbranchboolincomingr6   r!   r   r   pushbranchmapr   joinr   r>   r   iterbranchesr   r   rk   r	   
StateErrorr   r   r   r   r   nodesummariesr'   statusr)   r   r   note)r   r*   r+   r3   r   r   r   r   newbranchesbranchnamesclosedbranchestagr,   tipisclosederrmsgr   nowarnheadserrormsgr}   rl   r   discardedheadsoldhsdhsnewhsr   s                              r   
checkheadsr   a  sb    ;!!##D]FH$K I
v

C t{m##~~l## F ((#D+xEE#F $,NN$4$4  K  29 2jj!4!455)-)9)9)F)F)H)H 	( 	(%CX (""3''''#k*:*:: 	NJKKN##O FF
 >??+MFLMMvD1111 v&&K
 H 28 < <== U2 U2?D<X}nEEEE$$E]###H]### 	}$$-dMBB}FGG    JKK   
 3  uo	&   5zzA~~5kk#MNN !  . D
 ZZ#e**$$,u455C #	2!333 I    c!f HH #a&\++--  .    s1vSV(>(>(@(@(CD EHH
  !!CDDuAH H  H ! . DD . D
 ~Q5667777QDEENOOO 2 2Xa01111 4xd33334 4r   c                    | j         }|                                j        j        j        t
          j        j        j        fdfd}t          j
        t          j        |          j        j        }t                      }t                      }t                      }t                      }	|D ]r}
|
v r|                    |
           |                    |
          ,d}|j                            |t'          |
          z             |	                    |
           st)          |          dk    r |	t          |          z  t                      fS t+          j        d          }t/                    |z
  |rD|                                } |          }|                                         } |          s||vr|                    |           a                    d|||          }g }|D ]I}|         }|                                |k    r'|                    |                                           Jt;          fd|D                       s7t;          fd	|D                       st;          fd
|D                       r|                    |           n|                    |           |D||	z  }||fS )zpost process the list of new heads with obsolescence information

    Exists as a sub-function to contain the complexity and allow extensions to
    experiment with smarter logic.

    Returns (newheads, discarded_heads) tuple
    c                 $     |           k    S r   r   )r   getphasepublicunfis    r   <lambda>z&_postprocessobsolete.<locals>.<lambda>	  s    $**f4 r   c                      |           v S r   r   )r   futurecommonr   s    r   r   z&_postprocessobsolete.<locals>.<lambda>
  s    q\1 r   Ns=   checkheads: remote head unknown locally has local marker: %s
r   s   obsoletes   only(%n, (%ln+%ln))c              3   .   K   | ]} |          V  d S r   r   )r   r   ispublics     r   r   z'_postprocessobsolete.<locals>.<genexpr>@  s+      00000000r   c              3   2   K   | ]} |          v V  d S r   r   )r   r   futurenonobsoleter   s     r   r   z'_postprocessobsolete.<locals>.<genexpr>A  s1      FFQ558800FFFFFFr   c              3   0   K   | ]} |           V  d S r   r   )r   r   hasoutmarkers     r   r   z'_postprocessobsolete.<locals>.<genexpr>B  s.      <<1||A&<<<<<<r   )r*   r   r#   indexget_revr   r   rc   rh   	functoolspartialpushingmarkerforrf   
successorsr>   r   r   r'   debugr   rk   r
   getrevs	frozensetpopr}   revsrj   r[   r(   )r   r   candidate_newhsr*   ispushedsuccessorsmarkersr   	discardedlocalcandidateunknownheadsr   msgobsrevsnhr   current_branch
branchrevsbranchnodesr   r   r   r   r   r   r   r   s    `                 @@@@@@@r   r   r     s     ;D??DN (E]F%H444444H11111H$%5t}hOOL0EEEIUUN55L 
  
 99q!!!! $$Q''3+  cCFFl+++Q >ac/222CEE99t[11G!,//'9  $!!E"IIb**8A;; 	!7**IIbMMM YY"B
 

  	- 	-AQAxxzz^++""16688,,, 0000Z00000	FFFFF+FFFFF	 <<<<<<<<<	
 IIbMMMM MM"I  $J 
\E)r   c                 F   | j         }|g}t          |          }|r|                                } ||          rdS |                    |d          }|D ]I}|d         }	|	s
|d         pd}	|	D ]0}
|
|vr*|                    |
           |                    |
           1J|dS )a  true if some markers are to be pushed for node

    We cannot just look in to the pushed obsmarkers from the pushop because
    discovery might have filtered relevant markers. In addition listing all
    markers relevant to all changesets in the pushed set would be too expensive
    (O(len(repo)))

    (note: There are cache opportunity in this function. but it would requires
    a two dimensional stack.)
    Tr   r      F)r   r>   r   r   r   rj   )rf   r   r[   r   stackseencurrentmarkersmnextsr   s              r   r   r   O  s     !+FEu::D
 $))++8G 	4#''44 	$ 	$AaDE #!
 $ $D==HHQKKKLLOOO$  $ 5r   )NFN)NFNF)F)r   i18nr   r[   r   r    r   r   r	   r
   r   r   r   r   r   r   r"   r3   rx   r   r   r   r   r   r   r   r   r   <module>r     s                   
                       *; *; *; *;ZB B B B B B B BL HM= = = =@S S Sl6 6 6 6.     FP4 P4 P4fX X Xv    r   