
    d                     :    d Z ddlmZ ddlmZ d Zd Zd Zd ZdS )	z<
Implementation of merge-base following the approach of git
    )deque)Dequec                 P   g }i }d}d}dd}fd}t                      }	|||<   |	                    |           |D ]}
|||
<   |	                    |
            ||	|          r|	                                }||         }|||z  k    r)||z  s$||z  }|||<   |                    |           |z  } | |          }|r2|D ]/}||v r||         |z  ||<   n|||<   |	                    |           0 ||	|          g }|D ]"}||         z  s|                    |           #|S )N            c                 6    | D ]}||v r||         z  s dS dS )NTF )wlstcstatescmt_DNCs      Q/home/feoh/.local/pipx/venvs/poetry/lib/python3.11/site-packages/dulwich/graph.py_has_candidatesz#_find_lcas.<locals>._has_candidates'   s9     	  	 Cg~~t+  44u    )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     wwDGBKKKOOO  B /$
(
( "llnnY*++DL %$S!!!  .%% 	" " "7??$+DME$9GDMM$)GDMD!!!!' /$
(
( ", G    t# 	 NN3Nr   c                     |sg S |d         }t          |          dk    s|gS |dd         }||v r|gS |                                 }t          |j        ||          S )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   sw      		ABz??Qt
QRR.C	Syyt,,..&2B<<<r   c                 &   |sg S t          |          dk    rt          | |          S |                                 }|d         g}|dd         }|D ]?}g }|D ].}t          |j        ||g          }|                    |           /|dd         }@|S )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      	
:!tZ000,,..qM?D^F  	 	" 	"B-93EECS!!!!|Kr   c                 v    ||k    rdS |                                  }t          |j        ||g          }||gk    S )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      sI     
Rxxt ,,..&2B==DB4<r   N)	__doc__collectionsr   typingr   r!   r(   r0   r2   r   r   r   <module>r6      s|   *             5 5 5p= = =*  4    r   