Skip to content

Commit

Permalink
Merge pull request #40 from linzhp/feature/commit_graph
Browse files Browse the repository at this point in the history
Added commit graph
  • Loading branch information
andygrunwald committed Apr 8, 2014
2 parents ce7ad15 + 3aa31bd commit 97a605d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
.idea
MANIFEST
dist/
config
config
10 changes: 9 additions & 1 deletion pycvsanaly2/DBContentHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ContentHandler import ContentHandler
from Database import (DBRepository, DBLog, DBFile, DBFileLink, DBAction,
DBFileCopy, DBBranch, DBPerson, DBTag, DBTagRev,
statement)
DBGraph, statement)
from profile import profiler_start, profiler_stop
from utils import printdbg, printout, to_utf8, cvsanaly_cache_dir
from cPickle import dump, load
Expand Down Expand Up @@ -640,6 +640,14 @@ def commit(self, commit):
tag_revs.append((db_tagrev.id, tag_id, log.id))

self.cursor.executemany(statement(DBTagRev.__insert__, self.db.place_holder), tag_revs)

# Commit Graph
if len(commit.parents) > 0:
edges = []
for p in commit.parents:
edges.append((log.id, self.revision_cache[p]))

self.cursor.executemany(statement(DBGraph.__insert__, self.db.place_holder), edges)

if len(self.actions) >= self.MAX_ACTIONS:
printdbg("DBContentHandler: %d actions inserting", (len(self.actions),))
Expand Down
17 changes: 17 additions & 0 deletions pycvsanaly2/Database.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@


class DBRepository:

id_counter = 1

__insert__ = "INSERT INTO repositories (id, uri, name, type) values (?, ?, ?, ?)"
Expand Down Expand Up @@ -56,6 +57,10 @@ def __init__(self, id, commit):
self.author_date = commit.author_date
self.message = to_unicode(commit.message)
self.composed_rev = commit.composed_rev

class DBGraph:

__insert__ = "INSERT INTO commit_graph (commit_id, parent_id) values (?, ?)"


class DBFile:
Expand Down Expand Up @@ -445,7 +450,13 @@ def create_tables(self, cursor):
"tag_id integer, " +
"commit_id integer" +
")")
cursor.execute("CREATE TABLE commit_graph (" +
"commit_id integer," +
"parent_id integer" +
")")
cursor.execute("CREATE index files_file_name on files(file_name)")
cursor.execute("CREATE index commit_id on commit_graph(commit_id)")
cursor.execute("CREATE index parent_id on commit_graph(parent_id)")
self._create_views(cursor)
except sqlite3.OperationalError:
raise TableAlreadyExists
Expand Down Expand Up @@ -592,6 +603,12 @@ def create_tables(self, cursor):
"FOREIGN KEY (commit_id) REFERENCES scmlog(id)" +
") ENGINE=MyISAM" +
" CHARACTER SET=utf8")
cursor.execute("CREATE TABLE commit_graph (" +
"commit_id integer REFERENCES scmlog(id)," +
"parent_id integer REFERENCES scmlog(id)" +
")")
cursor.execute("CREATE index commit_id on commit_graph(commit_id)")
cursor.execute("CREATE index parent_id on commit_graph(parent_id)")
self._create_views(cursor)
except _mysql_exceptions.OperationalError, e:
if e.args[0] == 1050:
Expand Down
1 change: 1 addition & 0 deletions pycvsanaly2/GitParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def _parse_line(self, line):
parents = match.group(3)
if parents:
parents = parents.split()
self.commit.parents = parents
git_commit = self.GitCommit(self.commit, parents)

decorate = match.group(5)
Expand Down
3 changes: 2 additions & 1 deletion pycvsanaly2/Repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def __init__(self):
'branch': None,
'tags': None,
'message': "",
'composed_rev': False}
'composed_rev': False,
'parents': []}

def __getinitargs__(self):
return ()
Expand Down

0 comments on commit 97a605d

Please sign in to comment.