<s> from abc import ABCMeta <EOL> from abc import abstractmethod <EOL> from collections import Sequence <EOL> from git_upstream . lib . searchers import DiscardDuplicateGerritChangeId <EOL> from git_upstream . lib . searchers import DroppedCommitFilter <EOL> from git_upstream . lib . searchers import NoMergeCommitFilter <EOL> from git_upstream . lib . searchers import ReverseCommitFilter <EOL> from git_upstream . lib . searchers import SupersededCommitFilter <EOL> from git_upstream . lib . searchers import UpstreamMergeBaseSearcher <EOL> from git_upstream . lib . utils import GitMixin <EOL> class ImportStrategiesFactory ( object ) : <EOL> __strategies = None <EOL> @ classmethod <EOL> def create_strategy ( cls , type , * args , ** kwargs ) : <EOL> if type in cls . list_strategies ( ) : <EOL> return cls . __strategies [ type ] ( * args , ** kwargs ) <EOL> else : <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( type ) ) <EOL> @ classmethod <EOL> def list_strategies ( cls ) : <EOL> cls . __strategies = { <EOL> subclass . _strategy : subclass <EOL> for subclass in LocateChangesStrategy . __subclasses__ ( ) <EOL> if subclass . _strategy } <EOL> return cls . __strategies . keys ( ) <EOL> class LocateChangesStrategy ( GitMixin , Sequence ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = ABCMeta <EOL> @ abstractmethod <EOL> def __init__ ( self , git = None , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . data = None <EOL> self . filters = [ ] <EOL> super ( LocateChangesStrategy , self ) . __init__ ( * args , ** kwargs ) <EOL> def __getitem__ ( self , key ) : <EOL> if not self . data : <EOL> self . data = self . _popdata ( ) <EOL> return self . data [ key ] <EOL> def __len__ ( self ) : <EOL> if not self . data : <EOL> self . data = self . _popdata ( ) <EOL> return len ( self . data ) <EOL> @ classmethod <EOL> def get_strategy_name ( cls ) : <EOL> return cls . _strategy <EOL> def filtered_iter ( self ) : <EOL> commit_list = self <EOL> for f in self . filters : <EOL> commit_list = f . filter ( commit_list ) <EOL> return commit_list <EOL> def filtered_list ( self ) : <EOL> return list ( self . filtered_iter ( ) ) <EOL> def _popdata ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . searcher . list ( ) <EOL> class LocateChangesWalk ( LocateChangesStrategy ) : <EOL> _strategy = "<STR_LIT>" <EOL> def __init__ ( self , branch = "<STR_LIT>" , upstream = "<STR_LIT>" , <EOL> search_refs = None , * args , ** kwargs ) : <EOL> if not search_refs : <EOL> search_refs = [ ] <EOL> search_refs . insert ( <NUM_LIT:0> , upstream ) <EOL> self . searcher = UpstreamMergeBaseSearcher ( branch = branch , <EOL> patterns = search_refs ) <EOL> self . upstream = upstream <EOL> super ( LocateChangesWalk , self ) . __init__ ( * args , ** kwargs ) <EOL> def filtered_iter ( self ) : <EOL> self . filters . append ( <EOL> DiscardDuplicateGerritChangeId ( self . upstream , <EOL> limit = self . searcher . commit ) ) <EOL> self . filters . append ( NoMergeCommitFilter ( ) ) <EOL> self . filters . append ( ReverseCommitFilter ( ) ) <EOL> self . filters . append ( DroppedCommitFilter ( ) ) <EOL> self . filters . append ( <EOL> SupersededCommitFilter ( self . upstream , <EOL> limit = self . searcher . commit ) ) <EOL> return super ( LocateChangesWalk , self ) . filtered_iter ( ) </s>
