1
0
Fork 0
mirror of https://github.com/correl/codereview.git synced 2025-04-14 01:01:03 -09:00

Modified repository updating to use a queue rather than recursing

This commit is contained in:
Correl Roush 2010-12-23 12:19:11 -05:00
parent 4bc9c82c81
commit 6c6c316cc6

View file

@ -1,3 +1,4 @@
from collections import deque
from django.db import models
from codereview.browser import vcs
@ -15,6 +16,7 @@ class Repository(models.Model):
repo = vcs.create(self.type, self.path)
branches = repo.branches()
for branch, commit in branches.iteritems():
print 'Updating', branch
try:
head = Head.objects.get(repository=self, name=branch)
except:
@ -42,23 +44,37 @@ class Commit(models.Model):
parents = models.ManyToManyField('self')
def load(self, repo):
commit = repo.commit(self.ref)
self.message = commit.message
self.author = commit.author
self.author_email = commit.author_email
self.committer = commit.committer
self.committer_email = commit.committer_email
self.authored_date = commit.authored_date
self.committed_date = commit.committed_date
self.save()
for parent in commit.parents:
try:
p = Commit.objects.get(ref=parent, repository=self.repository)
except:
p = Commit(ref=parent, repository=self.repository)
p.load(repo)
self.parents.add(p)
self.save()
queue = deque([self])
while queue:
c = queue.popleft()
commit = repo.commit(c.ref)
c.message = commit.message
c.author = commit.author
c.author_email = commit.author_email
c.committer = commit.committer
c.committer_email = commit.committer_email
c.authored_date = commit.authored_date
c.committed_date = commit.committed_date
c.save()
print 'Loading', c.ref
for parent in commit.parents:
try:
p = Commit.objects.get(ref=parent, repository=c.repository)
except:
p = Commit(ref=parent, repository=c.repository)
parent = repo.commit(parent)
p.message = parent.message
p.author = parent.author
p.author_email = parent.author_email
p.committer = parent.committer
p.committer_email = parent.committer_email
p.authored_date = parent.authored_date
p.committed_date = parent.committed_date
p.save()
queue.append(p)
print 'Queuing', p.ref
c.parents.add(p)
c.save()
def __unicode__(self):
return self.ref