def find(query, components): conn = DB.getConn() c = conn.cursor() c.execute(query, components) commitrows = c.fetchall() commitfiles = [] if commitrows: allcommitids = ",".join([str(int(commit[0])) for commit in commitrows]) #This is poor practice, but we assured ourselves the value is composed only of ints first DB.execute(c, "SELECT * from " + DB.commitfile._table + " WHERE commitid IN (" + allcommitids + ")") commitfiles = c.fetchall() DB.execute(c, "SELECT * from " + DB.commitkeyword._table + " WHERE commitid IN (" + allcommitids + ")") commitkeywords = c.fetchall() commits = [] for i in commitrows: r = Repo() r.loadFromValues(i[DB.commit._numColumns + 0], i[DB.commit._numColumns + 1], i[DB.commit._numColumns + 2], i[DB.commit._numColumns + 3], i[DB.commit._numColumns + 4], i[DB.commit._numColumns + 5]) files = [file[DB.commitfile.file] for file in commitfiles if file[DB.commitfile.commitid] == i[DB.commit.id]] keywords = [keyword[DB.commitkeyword.keyword] for keyword in commitkeywords if keyword[DB.commitkeyword.commitid] == i[DB.commit.id]] c = Commit() c.loadFromDatabase(r, i, files, keywords) commits.append(c) return commits
def findByKeywords(keywords): conn = DB.getConn() c = conn.cursor() getcommitsSQL = "SELECT c.*, r.* " + \ "FROM " + DB.commit._table + " c " + \ "INNER JOIN " + DB.repo._table + " r " + \ " ON r.id = c.repoid " whereClause = " 1=1 " components = [] if keywords: keywordsTree = KeywordsParser(keywords) getcommitsSQL += "LEFT OUTER JOIN " + DB.commitkeyword._table + " ck " + \ " ON c.id = ck.commitid " whereClause, components = keywordsTree.getWhereClause("ck.keyword", "r.tagname", "r.maturity") getcommitsSQL += "WHERE " + whereClause getcommitsSQL += "ORDER BY c.date DESC " c.execute(getcommitsSQL, components) commitrows = c.fetchall() commitfiles = [] if commitrows: allcommitids = ",".join([str(int(commit[0])) for commit in commitrows]) #This is poor practice, but we assured ourselves the value is composed only of ints first c.execute("SELECT * from " + DB.commitfile._table + " WHERE commitid IN (" + allcommitids + ")") commitfiles = c.fetchall() commits = [] for i in commitrows: r = Repo() r.loadFromValues(i[DB.commit._numColumns + 0], i[DB.commit._numColumns + 1], i[DB.commit._numColumns + 2], i[DB.commit._numColumns + 3], i[DB.commit._numColumns + 4], i[DB.commit._numColumns + 5]) files = [file[DB.commitfile.file] for file in commitfiles if file[DB.commitfile.commitid] == i[DB.commit.id]] c = Commit() c.loadFromDatabase(r, i, files) commits.append(c) return commits
def find(query, components): conn = DB.getConn() c = conn.cursor() c.execute(query, components) commitrows = c.fetchall() commitfiles = [] if commitrows: allcommitids = ",".join([str(int(commit[0])) for commit in commitrows]) #This is poor practice, but we assured ourselves the value is composed only of ints first DB.execute(c, "SELECT * from " + DB.commitfile._table + " WHERE commitid IN (" + allcommitids + ")") commitfiles = c.fetchall() DB.execute(c, "SELECT * from " + DB.commitkeyword._table + " WHERE commitid IN (" + allcommitids + ")") commitkeywords = c.fetchall() DB.execute(c, "SELECT commitid, case when length(data) < 307200 then data else 'TOOLARGE' end as data from " + DB.commitdiffs._table + " WHERE commitid IN (" + allcommitids + ")") commitdata = c.fetchall() commits = [] for i in commitrows: r = Repo() r.loadFromValues(i[DB.commit._numColumns + DB.repo.id], i[DB.commit._numColumns + DB.repo.name], i[DB.commit._numColumns + DB.repo.repotypeid], i[DB.commit._numColumns + DB.repo.url], i[DB.commit._numColumns + DB.repo.viewlink], i[DB.commit._numColumns + DB.repo.tagname], i[DB.commit._numColumns + DB.repo.tagmaturity]) files = [file[DB.commitfile.file] for file in commitfiles if file[DB.commitfile.commitid] == i[DB.commit.id]] keywords = [keyword[DB.commitkeyword.keyword] for keyword in commitkeywords if keyword[DB.commitkeyword.commitid] == i[DB.commit.id]] data = [cdata[DB.commitdiffs.data] for cdata in commitdata if cdata[DB.commitdiffs.commitid] == i[DB.commit.id]][0] if i[DB.commit._numColumns + DB.repo.repotypeid] == Repo.Type.GIT: c = GitCommit() elif i[DB.commit._numColumns + DB.repo.repotypeid] == Repo.Type.SVN: c = SVNCommit() else: c = Commit() c.loadFromDatabase(r, i, files, keywords, data) commits.append(c) return commits
def findByIDs(project, uniqueid): conn = DB.getConn() c = conn.cursor() getcommitsSQL = "SELECT c.*, r.* " + \ "FROM " + DB.commit._table + " c " + \ "INNER JOIN " + DB.repo._table + " r " + \ " ON r.id = c.repoid " whereClause = " 1=1 " components = [] if project and uniqueid: whereClause += "AND r.tagname = %s AND c.uniqueid = %s " components = [project, uniqueid] getcommitsSQL += "WHERE " + whereClause getcommitsSQL += "ORDER BY c.date DESC " DB.execute(c, getcommitsSQL, components) commitrows = c.fetchall() commitfiles = [] if commitrows: allcommitids = ",".join([str(int(commit[0])) for commit in commitrows]) #This is poor practice, but we assured ourselves the value is composed only of ints first DB.execute(c, "SELECT * from " + DB.commitfile._table + " WHERE commitid IN (" + allcommitids + ")") commitfiles = c.fetchall() commits = [] for i in commitrows: r = Repo() r.loadFromValues(i[DB.commit._numColumns + 0], i[DB.commit._numColumns + 1], i[DB.commit._numColumns + 2], i[DB.commit._numColumns + 3], i[DB.commit._numColumns + 4], i[DB.commit._numColumns + 5]) files = [file[DB.commitfile.file] for file in commitfiles if file[DB.commitfile.commitid] == i[DB.commit.id]] c = Commit() c.loadFromDatabase(r, i, files) commits.append(c) return commits
def find(query, components): conn = DB.getConn() c = conn.cursor() c.execute(query, components) commitrows = c.fetchall() commitfiles = [] if commitrows: allcommitids = ",".join( [str(int(commit[0])) for commit in commitrows]) #This is poor practice, but we assured ourselves the value is composed only of ints first DB.execute( c, "SELECT * from " + DB.commitfile._table + " WHERE commitid IN (" + allcommitids + ")") commitfiles = c.fetchall() DB.execute( c, "SELECT * from " + DB.commitkeyword._table + " WHERE commitid IN (" + allcommitids + ")") commitkeywords = c.fetchall() DB.execute( c, "SELECT commitid, case when length(data) < 307200 then data else 'TOOLARGE' end as data from " + DB.commitdiffs._table + " WHERE commitid IN (" + allcommitids + ")") commitdata = c.fetchall() commits = [] for i in commitrows: r = Repo() r.loadFromValues(i[DB.commit._numColumns + DB.repo.id], i[DB.commit._numColumns + DB.repo.name], i[DB.commit._numColumns + DB.repo.repotypeid], i[DB.commit._numColumns + DB.repo.url], i[DB.commit._numColumns + DB.repo.viewlink], i[DB.commit._numColumns + DB.repo.tagname], i[DB.commit._numColumns + DB.repo.tagmaturity]) files = [ file[DB.commitfile.file] for file in commitfiles if file[DB.commitfile.commitid] == i[DB.commit.id] ] keywords = [ keyword[DB.commitkeyword.keyword] for keyword in commitkeywords if keyword[DB.commitkeyword.commitid] == i[DB.commit.id] ] data = [ cdata[DB.commitdiffs.data] for cdata in commitdata if cdata[DB.commitdiffs.commitid] == i[DB.commit.id] ][0] if i[DB.commit._numColumns + DB.repo.repotypeid] == Repo.Type.GIT: c = GitCommit() elif i[DB.commit._numColumns + DB.repo.repotypeid] == Repo.Type.SVN: c = SVNCommit() else: c = Commit() c.loadFromDatabase(r, i, files, keywords, data) commits.append(c) return commits
message = m.data['message'] paths = [p.path for p in m.data['changed_paths']] c = SVNCommit() alldiffs = c.getChangedTexts((m.data['revision'].number, repo)) c.loadFromSource(repo, message, date, paths, m.data['revision'].number, alldiffs) commits.append(c) return commits if __name__ == "__main__": parser = argparse.ArgumentParser( description= 'Given a repo url, a startdate and enddate, process the commits between.' ) parser.add_argument('repo') parser.add_argument('startdate') parser.add_argument('enddate') args = parser.parse_args() args.startdate, args.enddate = fixDates(args.startdate, args.enddate) r = Repo() r.loadFromValues(-1, "", Repo.Type.SVN, args.repo, '', '', '') commits = getCommits(r, args.startdate, args.enddate) for c in commits: print "=========================================" c.pprint() c.save()
for d in m.diff().iter_change_type('D'): #Deleted pass for d in m.diff().iter_change_type('R'): #Renamed pass c = Commit() c.loadFromSource(repo, m.message, m.committed_date, m.stats.files.keys(), m.__str__(), alldiffs) commits.append(c) return commits if __name__ == "__main__": parser = argparse.ArgumentParser( description= 'Given a repo url, a startdate and enddate, process the commits between.' ) parser.add_argument('repo') parser.add_argument('startdate') parser.add_argument('enddate') args = parser.parse_args() args.startdate, args.enddate = fixDates(args.startdate, args.enddate) r = Repo() r.loadFromValues(-1, Repo.Type.GIT, args.repo, '', '', '') commits = getCommits(r, args.startdate, args.enddate) for c in commits: c.pprint() c.save()
for d in m.diff().iter_change_type("A"): # Added pass for d in m.diff().iter_change_type("D"): # Deleted pass for d in m.diff().iter_change_type("R"): # Renamed pass c = Commit() c.loadFromSource(repo, m.message, m.committed_date, m.stats.files.keys(), m.__str__(), alldiffs) commits.append(c) return commits if __name__ == "__main__": parser = argparse.ArgumentParser( description="Given a repo url, a startdate and enddate, process the commits between." ) parser.add_argument("repo") parser.add_argument("startdate") parser.add_argument("enddate") args = parser.parse_args() args.startdate, args.enddate = fixDates(args.startdate, args.enddate) r = Repo() r.loadFromValues(-1, Repo.Type.GIT, args.repo, "", "", "") commits = getCommits(r, args.startdate, args.enddate) for c in commits: c.pprint() c.save()
c = pysvn.Client() commits = [] msgs = c.log(repo.url, revision_start=start_rev, revision_end=end_rev, discover_changed_paths=True) msgs.reverse() for m in msgs: date = m.data['revprops']['svn:date'] message = m.data['message'] paths = [p.path for p in m.data['changed_paths']] c = Commit() c.loadFromSource(repo, message, date, paths, m.data['revision'].number) commits.append(c) return commits if __name__ == "__main__": parser = argparse.ArgumentParser(description='Given a repo url, a startdate and enddate, process the commits between.') parser.add_argument('repo') parser.add_argument('startdate') parser.add_argument('enddate') args = parser.parse_args() args.startdate, args.enddate = fixDates(args.startdate, args.enddate) r = Repo() r.loadFromValues(-1, Repo.Type.SVN, args.repo, '', '', '') commits = getCommits(r, args.startdate, args.enddate) for c in commits: c.pprint() c.save()
for m in msgs: if m.committed_date > enddate: continue # TODO BUG: We are unable to get a git diff of the first commit. # http://osdir.com/ml/version-control.git/2005-05/msg01309.html # http://git.661346.n2.nabble.com/git-diff-tree-against-the-root-commit-td5685272.html if not m.parents: continue c = GitCommit() alldiffs = c.getChangedTexts(m) c.loadFromSource(repo, m.message, m.committed_date, m.stats.files.keys(), m.__str__(), alldiffs) commits.append(c) return commits if __name__ == "__main__": parser = argparse.ArgumentParser(description='Given a repo url, a startdate and enddate, process the commits between.') parser.add_argument('repo') parser.add_argument('startdate') parser.add_argument('enddate') args = parser.parse_args() args.startdate, args.enddate = fixDates(args.startdate, args.enddate) r = Repo() r.loadFromValues(-1, "", Repo.Type.GIT, args.repo, '', '', '') commits = getCommits(r, args.startdate, args.enddate) for c in commits: print "=========================================" c.pprint() c.save()