@@ -673,6 +673,72 @@ Repository_merge_analysis(Repository *self, PyObject *py_id)
673673 return Py_BuildValue ("(ii)" , analysis , preference );
674674}
675675
676+ PyDoc_STRVAR (Repository_merge_analysis_for_ref__doc__ ,
677+ "merge_analysis_for_ref(our_ref, their_head) -> (Integer, Integer)\n"
678+ "\n"
679+ "Analyzes the given branch and determines the opportunities for\n"
680+ "merging it into a reference.\n"
681+ "\n"
682+ "Parameters:\n"
683+ "\n"
684+ "our_ref\n"
685+ " The reference name (String) to perform the analysis from\n"
686+ "\n"
687+ "their_head\n"
688+ " Head (commit Oid) to merge into\n"
689+ "\n"
690+ "The first returned value is a mixture of the GIT_MERGE_ANALYSIS_NONE, _NORMAL,\n"
691+ "_UP_TO_DATE, _FASTFORWARD and _UNBORN flags.\n"
692+ "The second value is the user's preference from 'merge.ff'" );
693+
694+ PyObject *
695+ Repository_merge_analysis_for_ref (Repository * self , PyObject * args )
696+ {
697+ char * our_ref_name = NULL ;
698+ PyObject * py_their_head ;
699+ PyObject * py_result = NULL ;
700+ git_oid head_id ;
701+ git_reference * our_ref ;
702+ git_annotated_commit * commit ;
703+ git_merge_analysis_t analysis ;
704+ git_merge_preference_t preference ;
705+ int err = 0 ;
706+
707+ if (!PyArg_ParseTuple (args , "zO" ,
708+ & our_ref_name ,
709+ & py_their_head ))
710+ return NULL ;
711+
712+ err = git_reference_lookup (& our_ref , self -> repo , our_ref_name );
713+ if (err < 0 ) {
714+ PyObject * py_err = Error_set_str (err , our_ref_name );
715+ return py_err ;
716+ }
717+
718+ err = py_oid_to_git_oid_expand (self -> repo , py_their_head , & head_id );
719+ if (err < 0 )
720+ goto out ;
721+
722+ err = git_annotated_commit_lookup (& commit , self -> repo , & head_id );
723+ if (err < 0 ) {
724+ py_result = Error_set (err );
725+ goto out ;
726+ }
727+
728+ err = git_merge_analysis_for_ref (& analysis , & preference , self -> repo , our_ref , (const git_annotated_commit * * ) & commit , 1 );
729+ git_annotated_commit_free (commit );
730+ if (err < 0 ) {
731+ py_result = Error_set (err );
732+ goto out ;
733+ }
734+
735+ py_result = Py_BuildValue ("(ii)" , analysis , preference );
736+
737+ out :
738+ git_reference_free (our_ref );
739+ return py_result ;
740+ }
741+
676742PyDoc_STRVAR (Repository_merge__doc__ ,
677743 "merge(id)\n"
678744 "\n"
@@ -1944,6 +2010,7 @@ PyMethodDef Repository_methods[] = {
19442010 METHOD (Repository , descendant_of , METH_VARARGS ),
19452011 METHOD (Repository , merge_base , METH_VARARGS ),
19462012 METHOD (Repository , merge_analysis , METH_O ),
2013+ METHOD (Repository , merge_analysis_for_ref , METH_VARARGS ),
19472014 METHOD (Repository , merge , METH_O ),
19482015 METHOD (Repository , cherrypick , METH_O ),
19492016 METHOD (Repository , apply , METH_O ),
0 commit comments