
                         ,    S r SSKJr  S rS rS rS rg)z<
Implementation of merge-base following the approach of git
    )dequec                 0  ^ / n0 nSnSnSmSnU4S jn[        5       n	XTU'   U	R                  U5        U H  n
XdU
'   U	R                  U
5        M     U" X5      (       a  U	R                  5       nXK   nXU-  :X  a'  X-  (       d  X-  nXU'   UR                  U5        UT-  nU " U5      nU(       a-  U H'  nX;   a
  XN   U-  XN'   OXU'   U	R                  U5        M)     U" X5      (       a  M  / nU H"  nXK   T-  (       a  M  UR                  U5        M$     U$ )N            c                 B   > U  H  nX!;   d  M
  X   T-  (       a  M    g   g)NTF )wlstcstatescmt_DNCs       lib/third_party/dulwich/graph.py_has_candidates#_find_lcas.<locals>._has_candidates'   s'    C~t++      )r   appendpopleft)lookup_parentsc1c2scandsr   	_ANC_OF_1	_ANC_OF_2_LCAr   r   c2r   flagsparentspcmtresultsr   s                   @r   
_find_lcasr!      s.   EG IIDD 7DBKKKOB  $
(
(lln*+L$S!  %?$+ME$9GM$)DMD!   $
(
(, Gt##NN3  Nr   c                     U(       d  / $ US   n[        U5      S:  d  U/$ USS nX#;   a  U/$ U R                  5       n[        UR                  X#5      $ )zFind lowest common ancestors of commit_ids[0] and *any* of commits_ids[1:]

Args:
  repo: Repository object
  commit_ids: list of commit ids
Returns:
  list of lowest common ancestor commit_ids
r   r   N)lenparents_providerr!   get_parents)repo
commit_idsr   r   r$   s        r   find_merge_baser(   U   sb     		ABz?Qt
QR.C	yt,,.&22B<<r   c                    U(       d  / $ [        U5      S::  a  [        X5      $ U R                  5       nUS   /nUSS nU H;  n/ nU H+  n[        UR                  XW/5      nUR                  U5        M-     USS nM=     U$ )zFind lowest common ancestors of *all* provided commit_ids

Args:
  repo: Repository
  commit_ids:  list of commit ids
Returns:
  list of lowest common ancestor commit_ids
r   r   r   N)r#   r(   r$   r!   r%   extend)	r&   r'   r$   lcasothersr   	next_lcascaress	            r   find_octopus_baser0   j   s     	
:!t00,,.qM?D^F	B-993ECS!  |  Kr   c                 f    X:X  a  gU R                  5       n[        UR                  X/5      nXA/:H  $ )zIs it possible to fast-forward from c1 to c2?

Args:
  repo: Repository to retrieve objects from
  c1: Commit id for first commit
  c2: Commit id for second commit
T)r$   r!   r%   )r&   r   r   r$   r+   s        r   can_fast_forwardr2      s<     
x ,,.&22B=D4<r   N)__doc__collectionsr   r!   r(   r0   r2   r
   r   r   <module>r5      s$   , 5p=*4r   