Naprawione galerie.
[redakcja.git] / lib / wlrepo / mercurial_backend / __init__.py
index 2815881..536d08c 100644 (file)
@@ -1,10 +1,17 @@
 # -*- encoding: utf-8 -*-
 
+import logging
+log = logging.getLogger('ral.mercurial')
+
 __author__= "Ɓukasz Rekucki"
 __date__ = "$2009-09-25 09:20:22$"
 __doc__ = "Module documentation."
 
 import wlrepo
+from mercurial.node import nullid
+
+from mercurial import encoding
+encoding.encoding = 'utf-8'
 
 class MercurialRevision(wlrepo.Revision):
 
@@ -20,18 +27,18 @@ class MercurialRevision(wlrepo.Revision):
             idx = branchname.find("$doc:")
             if(idx < 0):
                 raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
-            self._username = branchname[0:idx]
+            self._username = branchname[6:idx]
             self._docname = branchname[idx+5:]
         else:
             raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
         
     @property
     def document_name(self):
-        return self._docname
+        return self._docname and self._docname.decode('utf-8')
 
     @property
     def user_name(self):
-        return self._username
+        return self._username and self._username.decode('utf-8')
 
     def hgrev(self):
         return self._changectx.node()
@@ -42,9 +49,16 @@ class MercurialRevision(wlrepo.Revision):
     def hgbranch(self):
         return self._changectx.branch()
 
+    @property
+    def timestamp(self):
+        return self._changectx.date()[0]
+
     def __unicode__(self):
         return u"%s" % self._changectx.hex()
 
+    def __str__(self):
+        return self.__unicode__().encode('utf-8')
+
     def __repr__(self):
         return "%s" % self._changectx.hex()
 
@@ -64,12 +78,16 @@ class MercurialRevision(wlrepo.Revision):
         a = self._changectx.ancestor(other._changectx)       
         return (a.branch() == self._changectx.branch())
 
+    def has_children(self):
+        return bool(self._library._hgrepo.changelog.children(self.hgrev()))
+
     def merge_with(self, other, user, message):
-        lock = self._library._lock(True)
+        message = self._library._sanitize_string(message)
+        lock = self._library.lock(True)
         try:
             self._library._checkout(self._changectx.node())
             status = self._library._merge(other._changectx.node())
-            if status.is_clean():
+            if status.isclean():
                 self._library._commit(user=user, message=message)
                 return (True, True)
             else: