<s> from __future__ import print_function <EOL> from pandas . compat import range , lrange , map <EOL> """<STR_LIT>""" <EOL> import logging <EOL> import re <EOL> import os <EOL> from collections import namedtuple <EOL> from pandas . compat import parse_date <EOL> try : <EOL> import sh <EOL> except ImportError : <EOL> raise ImportError ( "<STR_LIT>" ) <EOL> import argparse <EOL> desc = """<STR_LIT>""" . strip ( ) <EOL> argparser = argparse . ArgumentParser ( description = desc ) <EOL> argparser . add_argument ( '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> argparser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = [ "<STR_LIT>" ] , <EOL> help = '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> argparser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = [ ] , <EOL> help = '<STR_LIT>' ) <EOL> argparser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = [ ] , <EOL> help = '<STR_LIT>' ) <EOL> argparser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> argparser . add_argument ( '<STR_LIT>' , <EOL> default = "<STR_LIT>" , <EOL> help = '<STR_LIT>' ) <EOL> args = argparser . parse_args ( ) <EOL> lfmt = logging . Formatter ( fmt = '<STR_LIT>' , <EOL> datefmt = '<STR_LIT>' <EOL> ) <EOL> shh = logging . StreamHandler ( ) <EOL> shh . setFormatter ( lfmt ) <EOL> logger = logging . getLogger ( "<STR_LIT>" ) <EOL> logger . addHandler ( shh ) <EOL> Hit = namedtuple ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> HASH_LEN = <NUM_LIT:8> <EOL> def clean_checkout ( comm ) : <EOL> h , s , d = get_commit_vitals ( comm ) <EOL> if len ( s ) > <NUM_LIT> : <EOL> s = s [ : <NUM_LIT> ] + "<STR_LIT>" <EOL> s = s . split ( "<STR_LIT:\n>" ) [ <NUM_LIT:0> ] <EOL> logger . info ( "<STR_LIT>" % ( comm , s ) ) <EOL> sh . git ( '<STR_LIT>' , comm , _tty_out = False ) <EOL> sh . git ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def get_hits ( defname , files = ( ) ) : <EOL> cs = set ( ) <EOL> for f in files : <EOL> try : <EOL> r = sh . git ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' . format ( start = defname ) , f , _tty_out = False ) <EOL> except sh . ErrorReturnCode_128 : <EOL> logger . debug ( "<STR_LIT>" % f ) <EOL> continue <EOL> lines = r . strip ( ) . splitlines ( ) [ : - <NUM_LIT:1> ] <EOL> lines = [ x for x in lines if not re . search ( "<STR_LIT>" , x ) ] <EOL> hits = set ( map ( lambda x : x . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:0> ] , lines ) ) <EOL> cs . update ( set ( [ Hit ( commit = c , path = f ) for c in hits ] ) ) <EOL> return cs <EOL> def get_commit_info ( c , fmt , sep = '<STR_LIT:\t>' ) : <EOL> r = sh . git ( '<STR_LIT>' , "<STR_LIT>" . format ( fmt ) , '<STR_LIT>' . format ( c , c ) , "<STR_LIT>" , "<STR_LIT:1>" , _tty_out = False ) <EOL> return compat . text_type ( r ) . split ( sep ) <EOL> def get_commit_vitals ( c , hlen = HASH_LEN ) : <EOL> h , s , d = get_commit_info ( c , '<STR_LIT>' , "<STR_LIT:\t>" ) <EOL> return h [ : hlen ] , s , parse_date ( d ) <EOL> def file_filter ( state , dirname , fnames ) : <EOL> if args . dir_masks and not any ( [ re . search ( x , dirname ) for x in args . dir_masks ] ) : <EOL> return <EOL> for f in fnames : <EOL> p = os . path . abspath ( os . path . join ( os . path . realpath ( dirname ) , f ) ) <EOL> if any ( [ re . search ( x , f ) for x in args . file_masks ] ) or any ( [ re . search ( x , p ) for x in args . path_masks ] ) : <EOL> if os . path . isfile ( p ) : <EOL> state [ '<STR_LIT>' ] . append ( p ) <EOL> def search ( defname , head_commit = "<STR_LIT>" ) : <EOL> HEAD , s = get_commit_vitals ( "<STR_LIT>" ) [ : <NUM_LIT:2> ] <EOL> logger . info ( "<STR_LIT>" % ( HEAD , s ) ) <EOL> done_commits = set ( ) <EOL> files = [ ] <EOL> state = dict ( files = files ) <EOL> os . path . walk ( '<STR_LIT:.>' , file_filter , state ) <EOL> allhits = set ( get_hits ( defname , files = files ) ) <EOL> q = set ( [ HEAD ] ) <EOL> try : <EOL> while q : <EOL> h = q . pop ( ) <EOL> clean_checkout ( h ) <EOL> hits = get_hits ( defname , files = files ) <EOL> for x in hits : <EOL> prevc = get_commit_vitals ( x . commit + "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> if prevc not in done_commits : <EOL> q . add ( prevc ) <EOL> allhits . update ( hits ) <EOL> done_commits . add ( h ) <EOL> logger . debug ( "<STR_LIT>" % q ) <EOL> finally : <EOL> logger . info ( "<STR_LIT>" % HEAD ) <EOL> clean_checkout ( HEAD ) <EOL> return allhits <EOL> def pprint_hits ( hits ) : <EOL> SUBJ_LEN = <NUM_LIT:50> <EOL> PATH_LEN = <NUM_LIT:20> <EOL> hits = list ( hits ) <EOL> max_p = <NUM_LIT:0> <EOL> for hit in hits : <EOL> p = hit . path . split ( os . path . realpath ( os . curdir ) + os . path . sep ) [ - <NUM_LIT:1> ] <EOL> max_p = max ( max_p , len ( p ) ) <EOL> if max_p < PATH_LEN : <EOL> SUBJ_LEN += PATH_LEN - max_p <EOL> PATH_LEN = max_p <EOL> def sorter ( i ) : <EOL> h , s , d = get_commit_vitals ( hits [ i ] . commit ) <EOL> return hits [ i ] . path , d <EOL> print ( "<STR_LIT>" % args . funcname ) <EOL> for i in sorted ( lrange ( len ( hits ) ) , key = sorter ) : <EOL> hit = hits [ i ] <EOL> h , s , d = get_commit_vitals ( hit . commit ) <EOL> p = hit . path . split ( os . path . realpath ( os . curdir ) + os . path . sep ) [ - <NUM_LIT:1> ] <EOL> fmt = "<STR_LIT>" % ( HASH_LEN , SUBJ_LEN , PATH_LEN ) <EOL> if len ( s ) > SUBJ_LEN : <EOL> s = s [ : SUBJ_LEN - <NUM_LIT:5> ] + "<STR_LIT>" <EOL> print ( fmt . format ( h [ : HASH_LEN ] , d . isoformat ( ) [ : <NUM_LIT:10> ] , s , p [ - <NUM_LIT:20> : ] ) ) <EOL> print ( "<STR_LIT:\n>" ) <EOL> def main ( ) : <EOL> if not args . saw_the_warning : <EOL> argparser . print_help ( ) <EOL> print ( """<STR_LIT>""" ) <EOL> return <EOL> if isinstance ( args . file_masks , compat . string_types ) : <EOL> args . file_masks = args . file_masks . split ( '<STR_LIT:U+002C>' ) <EOL> if isinstance ( args . path_masks , compat . string_types ) : <EOL> args . path_masks = args . path_masks . split ( '<STR_LIT:U+002C>' ) <EOL> if isinstance ( args . dir_masks , compat . string_types ) : <EOL> args . dir_masks = args . dir_masks . split ( '<STR_LIT:U+002C>' ) <EOL> logger . setLevel ( getattr ( logging , args . debug_level ) ) <EOL> hits = search ( args . funcname ) <EOL> pprint_hits ( hits ) <EOL> pass <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import sys <EOL> sys . exit ( main ( ) ) </s>
