#NEWLINE# def nextSourceVersion( targetBranch , revision , existingVersionList ) : #NEWLINE# #INDENT# "\n        Returns the correct source version on the branch given\n        with the revision number specified given the list of\n        existing versions.\n        @param targetBranch: the branch to create the version on\n        @param revision: a revision object that contains the desired upstream\n        version and source count to use in the version.\n        This may be or modified to fit the target branch (for example,\n        if it has too many .'s in it for the branch it is being moved to).\n        @param existingVersionList: list of version objects that are the other\n        source versions for this package on this branch.\n    " #NEWLINE# revision = revision . copy ( ) #NEWLINE# desiredVersion = targetBranch . createVersion ( revision ) . copy ( ) #NEWLINE# if ( desiredVersion . shadowLength ( ) < revision . shadowCount ( ) ) : #NEWLINE# #INDENT# revision . getSourceCount ( ) . truncateShadowCount ( desiredVersion . shadowLength ( ) ) #NEWLINE# desiredVersion = targetBranch . createVersion ( revision ) #NEWLINE# #UNINDENT# if ( [ x for x in revision . getSourceCount ( ) . iterCounts ( ) ] [ ( - 1 ) ] == 0 ) : #NEWLINE# #INDENT# desiredVersion . incrementSourceCount ( ) #NEWLINE# #UNINDENT# matchingUpstream = [ x . trailingRevision ( ) for x in existingVersionList if ( x . trailingRevision ( ) . getVersion ( ) == revision . getVersion ( ) ) ] #NEWLINE# if ( ( revision in matchingUpstream ) and ( desiredVersion . shadowLength ( ) > revision . shadowCount ( ) ) ) : #NEWLINE# #INDENT# desiredVersion . incrementSourceCount ( ) #NEWLINE# revision = desiredVersion . trailingRevision ( ) #NEWLINE# #UNINDENT# if matchingUpstream : #NEWLINE# #INDENT# def _sourceCounts( revision ) : #NEWLINE# #INDENT# return list ( revision . getSourceCount ( ) . iterCounts ( ) ) #NEWLINE# #UNINDENT# shadowCounts = _sourceCounts ( revision ) #NEWLINE# matchingShadowCounts = [ x for x in matchingUpstream if ( _sourceCounts ( x ) [ : ( - 1 ) ] == shadowCounts [ : ( - 1 ) ] ) ] #NEWLINE# if matchingShadowCounts : #NEWLINE# #INDENT# latest = sorted ( matchingShadowCounts , key = _sourceCounts ) [ ( - 1 ) ] #NEWLINE# if ( ( revision in matchingShadowCounts ) or ( _sourceCounts ( latest ) > _sourceCounts ( revision ) ) ) : #NEWLINE# #INDENT# revision = latest . copy ( ) #NEWLINE# desiredVersion = targetBranch . createVersion ( revision ) #NEWLINE# desiredVersion . incrementSourceCount ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# assert ( not ( desiredVersion in existingVersionList ) ) #NEWLINE# return desiredVersion