from django.db import models, transaction
from django.db.models.base import ModelBase
from django.utils.translation import string_concat, ugettext_lazy as _
-from mercurial import simplemerge
+import merge3
from django.conf import settings
from dvcs.signals import post_commit, post_publishable
abstract = True
ordering = ['ordering']
- def __unicode__(self):
+ def __str__(self):
return self.name
@classmethod
ordering = ('created_at',)
unique_together = ['tree', 'revision']
- def __unicode__(self):
+ def __str__(self):
return u"Id: %r, Tree %r, Parent %r, Data: %s" % (self.id, self.tree_id, self.parent_id, self.data)
def author_str(self):
f = self.data.storage.open(self.data)
text = f.read()
f.close()
- return unicode(text, 'utf-8')
+ return str(text, 'utf-8')
def merge_with(self, other, author=None,
author_name=None, author_email=None,
# immediate child - fast forward
return other
- local = self.materialize().encode('utf-8')
- base = other.parent.materialize().encode('utf-8')
- remote = other.materialize().encode('utf-8')
+ local = self.materialize().splitlines(True)
+ base = other.parent.materialize().splitlines(True)
+ remote = other.materialize().splitlines(True)
- merge = simplemerge.Merge3Text(base, local, remote)
+ merge = merge3.Merge3(base, local, remote)
result = ''.join(merge.merge_lines())
merge_node = self.children.create(
merge_parent=other, tree=self.tree,
return model
-class Document(models.Model):
+class Document(models.Model, metaclass=DocumentMeta):
"""File in repository. Subclass it to use version control in your app."""
- __metaclass__ = DocumentMeta
-
# default repository path
REPO_PATH = os.path.join(settings.MEDIA_ROOT, 'dvcs')
class Meta:
abstract = True
- def __unicode__(self):
+ def __str__(self):
return u"{0}, HEAD: {1}".format(self.id, self.head_id)
def materialize(self, change=None):
This will automatically merge the commit into the main branch,
if parent is not document's head.
- :param unicode text: new version of the document
+ :param str text: new version of the document
:param parent: parent revision (head, if not specified)
:type parent: Change or None
:param User author: the commiter
- :param unicode author_name: commiter name (if ``author`` not specified)
- :param unicode author_email: commiter e-mail (if ``author`` not specified)
+ :param str author_name: commiter name (if ``author`` not specified)
+ :param str author_email: commiter e-mail (if ``author`` not specified)
:param Tag[] tags: list of tags to apply to the new commit
:param bool publishable: set new commit as ready to publish
:returns: new head