def __process_finished_jobs(self, job_pool, write_cursor, db): # start = datetime.now() finished_job = job_pool.get_next_done(0) processed_jobs = 0 # commit_id is the commit ID. For some reason, the # documentation advocates tablename_id as the reference, # but in the source, these are referred to as commit IDs. # Don't ask me why! while finished_job is not None: file_contents = None if not Config().no_content: file_contents = str(finished_job.file_contents) query = """ insert into content(commit_id, file_id, content, loc, size) values(?,?,?,?,?)""" insert_statement = statement(query, db.place_holder) parameters = (finished_job.commit_id, finished_job.file_id, file_contents, finished_job.file_number_of_lines, finished_job.file_size) execute_statement(insert_statement, parameters, write_cursor, db, "Couldn't insert, duplicate record?", exception=ExtensionRunError) processed_jobs += 1 finished_job = job_pool.get_next_done(0) return processed_jobs
def _do_backout(self, repo, uri, db, backout_statement): connection = db.connect() repo_cursor = connection.cursor() repo_uri = get_repo_uri(uri, repo) try: repo_id = get_repo_id(repo_uri, repo_cursor, db) except RepoNotFound: # Repository isn't in there, so it's likely already backed out printerr("Repository not found, is it in the database?") return True finally: repo_cursor.close() update_cursor = connection.cursor() execute_statement(statement(backout_statement, db.place_holder), (repo_id,), update_cursor, db, "Couldn't backout extension", exception=ExtensionBackoutError) update_cursor.close() connection.commit() connection.close()
def __process_finished_jobs(self, job_pool, write_cursor, db): finished_job = job_pool.get_next_done() # scmlog_id is the commit ID. For some reason, the # documentaion advocates tablename_id as the reference, # but in the source, these are referred to as commit IDs. # Don't ask me why! while finished_job is not None: p = DBPatch (None, finished_job.commit_id, finished_job.data) execute_statement(statement(DBPatch.__insert__, self.db.place_holder), (p.id, p.commit_id, to_utf8(p.patch).decode("utf-8")), write_cursor, db, "Couldn't insert, duplicate patch?", exception=ExtensionRunError) finished_job = job_pool.get_next_done(0)
def __process_finished_jobs(self, job_pool, write_cursor, db): finished_job = job_pool.get_next_done(0) processed_jobs = 0 while finished_job is not None: query = """update scmlog set file_count = ? where id = ?""" insert_statement = statement(query, db.place_holder) parameters = (finished_job.ls_line_count, finished_job.row_id) execute_statement(insert_statement, parameters, write_cursor, db, "Couldn't update scmlog with ls line count", exception=ExtensionRunError) processed_jobs += 1 finished_job = job_pool.get_next_done(0) # print "Before return: %s"%(datetime.now()-start) return processed_jobs
s.repository_id = ? and p.patch is not NULL""", db.place_holder), (repo_id, )) nr_records = cursor.fetchone()[0] progress = Progress("[Extension PatchesLOC]", nr_records) patches = self.get_patches(repo, path or repo.get_uri(), repo_id, db, cursor) for commit_id, file_id, patch_content, rev in patches: (added, removed) = self.count_lines(patch_content) insert = """insert into patch_lines(file_id, commit_id, added, removed) values(?,?,?,?)""" execute_statement(statement(insert, db.place_holder), (file_id, commit_id, added, removed), cursor, db, "Couldn't insert patch, dup record?", exception=ExtensionRunError) connection.commit() progress.finished_one() cursor.close() connection.commit() connection.close() progress.done() profiler_stop("Running PatchLOC extension", delete=True) register_extension("PatchLOC", PatchLOC)
for row in read_cursor: row_id = row[0] commit_message = row[1] update = """update scmlog set is_bug_fix = ? where id = ?""" if self.fixes_bug(commit_message): is_bug_fix = 1 else: is_bug_fix = 0 execute_statement(statement(update, db.place_holder), (is_bug_fix, row_id), write_cursor, db, "Couldn't update scmlog", exception=ExtensionRunError) read_cursor.close() connection.commit() connection.close() # This turns off the profiler and deletes its timings profiler_stop("Running BugFixMessage extension", delete=True) def backout(self, repo, uri, db): backout_statement = """update scmlog set is_bug_fix = NULL where repository_id = ?"""
commit_id_new='%d' % commit_id commit_id -=1 #commit_id -1 can not equals zero #assert commit_id != 0, 'commit_id -1 can not equals zero' #when commit_id equals 1, means this patch was committed with first release version of the software #just record and skip this loop if(commit_id == 0): num_of_id1 +=1 new_cla, new_func = information_of_id1(record[3]) new_class = set_to_string(new_cla) new_function = set_to_string(new_func) execute_statement(statement(__insert__, self.db.place_holder), (patch_id, commit_id_new, file_id, 'NULL', new_class, 'NULL', new_function, 1), write_cursor, db, "\nCouldn't insert, I do not know the reason at present", exception=ExtensionRunError) continue commit_id_old='%d' % commit_id #get rev cursor.execute("SELECT rev from scmlog WHERE id="+commit_id_new) rev_new=cursor.fetchone()[0] cursor.execute("SELECT rev from scmlog WHERE id="+commit_id_old) rev_old=cursor.fetchone()[0] #get file_old and file_new patch = record[3]
progress = Progress("[Extension Hunks]", nr_records) patches = self.get_patches(repo, path or repo.get_uri(), repo_id, db, read_cursor) for commit_id, file_id, patch_content, rev in patches: for hunk in self.get_commit_data(patch_content): insert = """insert into hunks(file_id, commit_id, old_start_line, old_end_line, new_start_line, new_end_line) values(?,?,?,?,?,?)""" execute_statement(statement(insert, db.place_holder), (file_id, commit_id, hunk.old_start_line, hunk.old_end_line, hunk.new_start_line, hunk.new_end_line), write_cursor, db, "Couldn't insert hunk, dup record?", exception=ExtensionRunError) connection.commit() progress.finished_one() read_cursor.close() connection.commit() connection.close() progress.done() # This turns off the profiler and deletes its timings profiler_stop("Running hunks extension", delete=True)
patches = self.get_patches(repo, path or repo.get_uri(), repo_id, db, read_cursor) for commit_id, file_id, patch_content, rev in patches: for hunk in self.get_commit_data(patch_content): insert = """insert into hunks(file_id, commit_id, old_start_line, old_end_line, new_start_line, new_end_line) values(?,?,?,?,?,?)""" execute_statement(statement(insert, db.place_holder), (file_id, commit_id, hunk.old_start_line, hunk.old_end_line, hunk.new_start_line, hunk.new_end_line), write_cursor, db, "Couldn't insert hunk, dup record?", exception=ExtensionRunError) connection.commit() progress.finished_one() read_cursor.close() connection.commit() connection.close() progress.done() # This turns off the profiler and deletes its timings profiler_stop("Running hunks extension", delete=True)
p.patch is not NULL""", db.place_holder), (repo_id,)) nr_records = cursor.fetchone()[0] progress = Progress("[Extension PatchesLOC]", nr_records) patches = self.get_patches(repo, path or repo.get_uri(), repo_id, db, cursor) for commit_id, file_id, patch_content, rev in patches: (added, removed) = self.count_lines(patch_content) insert = """insert into patch_lines(file_id, commit_id, added, removed) values(?,?,?,?)""" execute_statement(statement(insert, db.place_holder), (file_id, commit_id, added, removed), cursor, db, "Couldn't insert patch, dup record?", exception=ExtensionRunError) connection.commit() progress.finished_one() cursor.close() connection.commit() connection.close() progress.done() profiler_stop("Running PatchLOC extension", delete=True) register_extension("PatchLOC", PatchLOC)