- local = self.materialize()
- base = other.merge_parent.materialize()
- remote = other.apply_to(base)
-
- merge = simplemerge.Merge3Text(base, local, remote)
- result = ''.join(merge.merge_lines())
- patch = self.make_patch(local, result)
- return self.children.create(
- patch=patch, merge_parent=other, tree=self.tree,
- author=author, author_desc=author_desc,
- description=description)
-
- def revert(self, **kwargs):
- """ commit this version of a doc as new head """
- self.tree.commit(text=self.materialize(), **kwargs)
-
-
-class Document(models.Model):
- """
- File in repository.
- """
- creator = models.ForeignKey(User, null=True, blank=True, editable=False,
- related_name="created_documents")
- head = models.ForeignKey(Change,
- null=True, blank=True, default=None,
- help_text=_("This document's current head."),
- editable=False)
-
- user = models.ForeignKey(User, null=True, blank=True)
- stage = models.ForeignKey(Tag, null=True, blank=True)
-
- def __unicode__(self):
- return u"{0}, HEAD: {1}".format(self.id, self.head_id)
-
- @models.permalink
- def get_absolute_url(self):
- return ('dvcs.views.document_data', (), {
- 'document_id': self.id,
- 'version': self.head_id,
- })
-
- def materialize(self, change=None):
- if self.head is None:
- return u''
- if change is None:
- change = self.head
- elif not isinstance(change, Change):
- change = self.change_set.get(pk=change)
- return change.materialize()
-
- def commit(self, **kwargs):
- if 'parent' not in kwargs:
- parent = self.head