#NEWLINE# def upgrade( ) : #NEWLINE# #INDENT# op . create_table ( 'file' , sa . Column ( 'key' , sa . Integer ( ) , nullable = False ) , sa . Column ( 'revision_key' , sa . Integer ( ) , nullable = False , index = True ) , sa . Column ( 'path' , sa . Text ( ) , nullable = False , index = True ) , sa . Column ( 'old_path' , sa . Text ( ) , index = True ) , sa . Column ( 'status' , sa . String ( length = 1 ) ) , sa . Column ( 'inserted' , sa . Integer ( ) ) , sa . Column ( 'deleted' , sa . Integer ( ) ) , sa . PrimaryKeyConstraint ( 'key' ) ) #NEWLINE# pathre = re . compile ( '((.*?)\\{|^)(.*?) => (.*?)(\\}(.*)|$)' ) #NEWLINE# insert = sa . text ( 'insert into file (key, revision_key, path, old_path, status, inserted, deleted)  values (NULL, :revision_key, :path, :old_path, :status, :inserted, :deleted)' ) #NEWLINE# conn = op . get_bind ( ) #NEWLINE# countres = conn . execute ( 'select count(*) from revision' ) #NEWLINE# revisions = countres . fetchone ( ) [ 0 ] #NEWLINE# if ( revisions > 50 ) : #NEWLINE# #INDENT# print ( '' ) #NEWLINE# print ( 'Adding support for searching for changes by file modified.  This may take a while.' ) #NEWLINE# #UNINDENT# qres = conn . execute ( 'select p.name, c.number, c.status, r.key, r.number, r."commit", r.parent from project p, change c, revision r where r.change_key=c.key and c.project_key=p.key order by p.name' ) #NEWLINE# count = 0 #NEWLINE# for ( pname , cnumber , cstatus , rkey , rnumber , commit , parent ) in qres . fetchall ( ) : #NEWLINE# #INDENT# count += 1 #NEWLINE# sys . stdout . write ( ( 'Diffstat revision %s / %s\r' % ( count , revisions ) ) ) #NEWLINE# sys . stdout . flush ( ) #NEWLINE# ires = conn . execute ( insert , revision_key = rkey , path = '/COMMIT_MSG' , old_path = None , status = None , inserted = None , deleted = None ) #NEWLINE# repo = gertty . gitrepo . get_repo ( pname , context . config . gertty_app . config ) #NEWLINE# try : #NEWLINE# #INDENT# stats = repo . diffstat ( parent , commit ) #NEWLINE# #UNINDENT# except git . exc . GitCommandError : #NEWLINE# #INDENT# if ( cstatus not in [ 'MERGED' , 'ABANDONED' ] ) : #NEWLINE# #INDENT# print ( ( 'Unable to examine diff for %s %s change %s,%s' % ( cstatus , pname , cnumber , rnumber ) ) ) #NEWLINE# #UNINDENT# continue #NEWLINE# #UNINDENT# for stat in stats : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( added , removed , path ) = stat #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# if ( cstatus not in [ 'MERGED' , 'ABANDONED' ] ) : #NEWLINE# #INDENT# print ( ( 'Empty diffstat for %s %s change %s,%s' % ( cstatus , pname , cnumber , rnumber ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# m = pathre . match ( path ) #NEWLINE# status = gertty . db . File . STATUS_MODIFIED #NEWLINE# old_path = None #NEWLINE# if m : #NEWLINE# #INDENT# status = gertty . db . File . STATUS_RENAMED #NEWLINE# pre = ( m . group ( 2 ) or '' ) #NEWLINE# post = ( m . group ( 6 ) or '' ) #NEWLINE# old_path = ( ( pre + m . group ( 3 ) ) + post ) #NEWLINE# path = ( ( pre + m . group ( 4 ) ) + post ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# added = int ( added ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# added = None #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# removed = int ( removed ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# removed = None #NEWLINE# #UNINDENT# conn . execute ( insert , revision_key = rkey , path = path , old_path = old_path , status = status , inserted = added , deleted = removed ) #NEWLINE# #UNINDENT# #UNINDENT# print ( '' )