def run (self, repo, uri, db): self.db = db self.repo = repo path = uri_to_filename (uri) if path is not None: repo_uri = repo.get_uri_for_path (path) else: repo_uri = uri path = uri_to_filename (uri) self.repo_uri = path or repo.get_uri () cnn = self.db.connect () cursor = cnn.cursor () cursor.execute (statement ("SELECT id from repositories where uri = ?", db.place_holder), (repo_uri,)) repo_id = cursor.fetchone ()[0] # If table does not exist, the list of commits is empty, # otherwise it will be filled within the except block below commits = [] try: self.__create_table (cnn) except TableAlreadyExists: cursor.execute (statement ("SELECT max(id) from patches", db.place_holder)) id = cursor.fetchone ()[0] if id is not None: DBPatch.id_counter = id + 1 commits = self.__get_patches_for_repository (repo_id, cursor) except Exception, e: raise ExtensionRunError (str (e))
def run(self, repo, uri, db): profiler_start("Running HunkBlame extension") self.db = db cnn = self.db.connect() read_cursor = cnn.cursor() write_cursor = cnn.cursor() try: path = uri_to_filename(uri) if path is not None: repo_uri = repo.get_uri_for_path(path) else: repo_uri = uri read_cursor.execute( statement("SELECT id from repositories where uri = ?", db.place_holder), (repo_uri, )) repoid = read_cursor.fetchone()[0] except NotImplementedError: raise ExtensionRunError( "HunkBlame extension is not supported for %s repositories" % (repo.get_type())) except Exception, e: raise ExtensionRunError( "Error creating repository %s. Exception: %s" % (repo.get_uri(), str(e)))
def run(self, repo, uri, db): # Start the profiler, per every other extension profiler_start("Running FileCount extension") # Open a connection to the database and get cursors self.db = db connection = self.db.connect() read_cursor = connection.cursor() write_cursor = connection.cursor() # Try to get the repository and get its ID from the database try: path = uri_to_filename(uri) if path is not None: repo_uri = repo.get_uri_for_path(path) else: repo_uri = uri read_cursor.execute(statement( \ "SELECT id from repositories where uri = ?", \ db.place_holder), (repo_uri,)) repo_id = read_cursor.fetchone()[0] except NotImplementedError: raise ExtensionRunError( \ "FileCount extension is not supported for %s repos" % \ (repo.get_type())) except Exception, e: raise ExtensionRunError( \ "Error creating repository %s. Exception: %s" % \ (repo.get_uri(), str(e)))
def run(self, repo, uri, db): profiler_start("Running PatchLOC extension") # Open a connection to the database and get cursors self.db = db connection = self.db.connect() cursor = connection.cursor() path = uri_to_filename(uri) if path is not None: repo_uri = repo.get_uri_for_path(path) else: repo_uri = uri cursor.execute( statement("SELECT id from repositories where uri = ?", db.place_holder), (repo_uri, )) repo_id = cursor.fetchone()[0] try: self.__create_table(connection) except TableAlreadyExists: pass except Exception, e: raise ExtensionRunError(str(e))
def run(self, repo, uri, db): profiler_start("Running Blame extension") self.db = db cnn = self.db.connect() read_cursor = cnn.cursor() write_cursor = cnn.cursor() blames = [] try: path = uri_to_filename(uri) if path is not None: repo_uri = repo.get_uri_for_path(path) else: repo_uri = uri read_cursor.execute(statement("SELECT id from repositories " + \ "where uri = ?", db.place_holder), (repo_uri,)) repoid = read_cursor.fetchone()[0] except NotImplementedError: raise ExtensionRunError("Blame extension is not supported for " + \ "%s repositories" % (repo.get_type())) except Exception, e: raise ExtensionRunError("Error creating repository %s. " + \ "Exception: %s" % (repo.get_uri(), str(e)))
def run(self, repo, uri, db): self.db = db path = uri_to_filename(uri) if path is not None: repo_uri = repo.get_uri_for_path(path) else: repo_uri = uri cnn = self.db.connect() cursor = cnn.cursor() cursor.execute( statement("SELECT id from repositories where uri = ?", db.place_holder), (repo_uri, )) repo_id = cursor.fetchone()[0] files = [] try: self.__create_table(cnn) except TableAlreadyExists: cursor.execute( statement("SELECT max(id) from file_types", db.place_holder)) id = cursor.fetchone()[0] if id is not None: DBFileType.id_counter = id + 1 files = self.__get_files_for_repository(repo_id, cursor) except Exception, e: raise ExtensionRunError(str(e))
def run(self, repo, uri, db): self.db = db path = uri_to_filename(uri) if path is not None: repo_uri = repo.get_uri_for_path(path) else: repo_uri = uri cnn = self.db.connect() cursor = cnn.cursor() cursor.execute(statement("SELECT id from repositories where uri = ?", db.place_holder), (repo_uri,)) repo_id = cursor.fetchone()[0] files = [] try: self.__create_table(cnn) except TableAlreadyExists: cursor.execute(statement("SELECT max(id) from file_types", db.place_holder)) id = cursor.fetchone()[0] if id is not None: DBFileType.id_counter = id + 1 files = self.__get_files_for_repository(repo_id, cursor) except Exception, e: raise ExtensionRunError(str(e))
def _get_repo_id(self, repo, uri): """Get repository id from repositories table""" path = uri_to_filename(uri) if path is not None: repo_uri = repo.get_uri_for_path(path) else: repo_uri = uri self.cursor.execute("SELECT id FROM repositories WHERE uri = '%s'" % repo_uri) return self.cursor.fetchone()[0]
def _get_repo_id(self, repo, uri): """Get repository id from repositories table""" path = uri_to_filename(uri) if path is not None: repo_uri = repo.get_uri_for_path(path) else: repo_uri = uri self.cursor.execute("SELECT id FROM repositories WHERE uri = '%s'" % repo_uri) return (self.cursor.fetchone()[0])
def run(self, repo, uri, db): """ Parses all the commit messages from the WordPress repository to identify code contributions made by developers without access to the repository. """ self.db = db self.db_content_handler = DBContentHandler(self.db) self.db_content_handler.begin() path = uri_to_filename(uri) if path is not None: repo_uri = repo.get_uri_for_path(path) else: repo_uri = uri cnn = self.db.connect() cursor = cnn.cursor() cursor.execute( statement("SELECT id from repositories where uri = ?", db.place_holder), (repo_uri, )) repo_id = cursor.fetchone()[0] self.db_content_handler.repo_id = repo_id self.__maybe_create_column(cnn) cursor.execute( statement("SELECT id, message from scmlog where repository_id = ?", db.place_holder), (repo_id, )) write_cursor = cnn.cursor() rs = cursor.fetchmany() while rs: for scmlog_id, message in rs: person_id = self.__get_person_id_from_message(message) if person_id: write_cursor.execute( statement( "UPDATE scmlog SET wordpress_author_id = ? WHERE id = ?", db.place_holder), (person_id, scmlog_id)) rs = cursor.fetchmany() cnn.commit() write_cursor.close() cursor.close() cnn.close()
def patch_generator(repo, repo_uri, repo_id, db, cursor): icursor = ICursor(cursor, self.INTERVAL_SIZE) icursor.execute( statement("SELECT id, rev, composed_rev " + "from scmlog where repository_id = ?", db.place_holder), (repo_id,), ) rs = icursor.fetchmany() while rs: for commit_id, revision, composed_rev in rs: # Get the patch pj = PatchJob(revision, commit_id) path = uri_to_filename(repo_uri) pj.run(repo, path or repo.get_uri()) # Yield the patch to hunks yield (pj.commit_id, pj.data, pj.rev) rs = icursor.fetchmany()
def patch_generator(repo, repo_uri, repo_id, db, cursor): icursor = ICursor(cursor, self.INTERVAL_SIZE) icursor.execute(statement("SELECT id, rev, composed_rev " + \ "from scmlog where repository_id = ?", db.place_holder), (repo_id,)) rs = icursor.fetchmany() while rs: for commit_id, revision, composed_rev in rs: # Get the patch pj = PatchJob(revision, commit_id) path = uri_to_filename(repo_uri) pj.run(repo, path or repo.get_uri()) p = DBPatch(db, commit_id, pj.data) # Yield the patch to hunks for file_id, patch in p.file_patches(): yield (pj.commit_id, file_id, patch, pj.rev) rs = icursor.fetchmany()
def run(self, repo, uri, db): profiler_start("Running PatchLOC extension") # Open a connection to the database and get cursors self.db = db connection = self.db.connect() cursor = connection.cursor() path = uri_to_filename(uri) if path is not None: repo_uri = repo.get_uri_for_path(path) else: repo_uri = uri cursor.execute(statement("SELECT id from repositories where uri = ?", db.place_holder), (repo_uri,)) repo_id = cursor.fetchone()[0] try: self.__create_table(connection) except TableAlreadyExists: pass except Exception, e: raise ExtensionRunError(str(e))
def run(self, repo, uri, db): #record how many patches contains different file name function_name_change_count = 0 #only suitable for my computer, user can change according to your own settings prefix = r'/home/moqi/Downloads/voldemort' #old file name f_of_old = open('/home/moqi/Downloads/voldemort/old', 'w') #new file name f_of_new = open('/home/moqi/Downloads/voldemort/new', 'w') #store information returns by search_lines search_result={} #number of exception #such as /null and file has been deleted so that can not open #not accurate num_of_exception = 0 #number of file which do not belong to source files non_source_file = 0 #number of patch which commit_id = 1 num_of_id1 = 0 #number of files can not be recovered num_of_unrecovered = 0 #old_cla contains class definition in old file old_cla = sets.Set() new_cla = sets.Set() old_func = sets.Set() new_func = sets.Set() #max id in table patches id_max = 0 #patch_id patch_id = 0 #file_id file_id = 0 ##old_class, new_class, old_function, new_function old_class = '' new_class = '' old_function = '' new_function = '' __insert__ = """INSERT INTO analyse_patch (patch_id, commit_id, file_id, old_class, new_class, old_function, new_function, if_id1) values (?, ?, ?, ?, ?, ?, ?, ?)""" start = time.time() profiler_start("Running analyse_patch extension") self.db = db self.repo = repo path = uri_to_filename(uri) if path is not None: repo_uri = repo.get_uri_for_path(path) ##added by me prefix = path else: repo_uri = uri path = uri_to_filename(uri) self.repo_uri = path or repo.get_uri() cnn = self.db.connect() cursor = cnn.cursor() write_cursor = cnn.cursor() cursor.execute(statement("SELECT id from repositories where uri = ?", db.place_holder), (repo_uri,)) repo_id = cursor.fetchone()[0] try: printdbg("Creating analyse_patch table") self.__create_table(cnn) except TableAlreadyExists: pass except Exception, e: raise ExtensionRunError(str(e))