--- a/ForgeSCM/forgescm/model/artifacts.py
+++ b/ForgeSCM/forgescm/model/artifacts.py
@@ -1,4 +1,4 @@
-from time import sleep
+from datetime import datetime
from pylons import c
from pymongo.errors import OperationFailure
@@ -21,86 +21,74 @@
def index(self):
result = Artifact.index(self)
result.update(
- title_s='%s repository',
+ title_s='%s repository' % c.app.script_name,
type_s=self.type_s,
text=self.description)
+ return result
-class MyArtifactHistory(Snapshot):
+ def commits(self):
+ return Commit.m.find(dict(repository_id=self._id))
+
+ def clear_commits(self):
+ Patch.m.remove(dict(repository_id=self._id))
+ Commit.m.remove(dict(repository_id=self._id))
+
+class Commit(Artifact):
class __mongometa__:
- name='my_artifact_history'
- type_s='MyArtifact Snapshot'
+ name='commit'
+ type_s = 'ForgeSCM Commit'
- def original(self):
- return MyArtifact.m.get(_id=self.artifact_id)
+ def index(self):
+ result = Artifact.index(self)
+ result.update(
+ title_s='Commit %s by %s' % (self.hash, self.user),
+ text=self.summary)
+ return result
- def shorthand_id(self):
- return '%s#%s' % (self.original().shorthand_id(), self.version)
+ _id = Field(schema.ObjectId)
+ hash = Field(str)
+ repository_id = Field(schema.ObjectId)
+ summary = Field(str)
+ diff = Field(str)
+ date = Field(str)
+ parents = Field([str])
+ tags = Field([str])
+ user = Field(str)
+
+ @property
+ def repository(self):
+ return Repository.m.get(_id=self.repository_id)
+
+ @property
+ def patches(self):
+ return Patch.m.find(dict(commit_id=self._id))
def url(self):
- return self.original().url() + '?version=%d' % self.version
+ return self.repository.url() + self.hash + '/'
+
+class Patch(Artifact):
+ class __mongometa__:
+ name='diff'
+ type_s = 'ForgeSCM Patch'
+
+ _id = Field(schema.ObjectId)
+ repository_id = Field(schema.ObjectId)
+ commit_id = Field(schema.ObjectId)
+ filename = Field(str)
+ patch_text = Field(str)
def index(self):
- result = Snapshot.index(self)
+ result = Artifact.index(self)
result.update(
- title_s='Version %d of %s' % (
- self.version, self.original().shorthand_id()),
- type_s=self.type_s,
- text=self.data.text)
+ title_s='Commit %s: %s' % (self.commit.hash, self.filename),
+ text=self.patch_text)
return result
-
-class MyArtifact(VersionedArtifact):
- class __mongometa__:
- name='my_artifact'
- history_class = MyArtifactHistory
- type_s = 'MyArtifact'
-
- text = Field(str, if_missing='')
+
+
+ @property
+ def commit(self):
+ return Commit.m.get(_id=self.commit_id)
def url(self):
- return c.app.script_name + '/' + self._id.url_encode() + '/'
-
- def shorthand_id(self):
- return '%s/%s' % (self.type_s, self._id.url_encode())
+ return self.commit.url() + self._id.url_encode() + '/'
- def index(self):
- result = VersionedArtifact.index(self)
- result.update(type_s=self.type_s, text=self.text)
- return result
-
- def root_comments(self):
- return MyArtifactComment.m.find(dict(artifact_id=self._id, parent_id=None))
- def reply(self):
- while True:
- try:
- c = MyArtifactComment.make(dict(artifact_id=self._id))
- c.m.insert()
- return c
- except OperationFailure:
- sleep(0.1)
- continue
-
-class MyArtifactComment(Message):
- class __mongometa__:
- name='my_artifact_comment'
- type_s = 'MyArtifact Comment'
-
- artifact_id=Field(schema.ObjectId)
-
- def index(self):
- result = Message.index(self)
- author = self.author()
- result.update(
- title_s='Comment on %s by %s' % (
- self.artifact.shorthand_id(), author.display_name),
- type_s=self.type_s)
- return result
-
- @property
- def artifact(self):
- return MyArtifact.m.get(_id=self.artifact_id)
-
- def url(self):
- return self.artifact.url() + '#comment-' + self._id
-
- def shorthand_id(self):
- return '%s-%s' % (self.artifact.shorthand_id, self._id)