Generowanie pybundle z wymaganymi bibliotekami na komputerze lokalnym i przerzucanie...
[redakcja.git] / lib / wlrepo / mercurial_backend / document.py
index 6cf8a5b..a8f7adc 100644 (file)
@@ -5,13 +5,18 @@ __date__ = "$2009-09-25 09:35:06$"
 __doc__ = "Module documentation."
 
 import wlrepo
 __doc__ = "Module documentation."
 
 import wlrepo
+import mercurial.error
 
 class MercurialDocument(wlrepo.Document):
 
     def data(self, entry):
 
 class MercurialDocument(wlrepo.Document):
 
     def data(self, entry):
-        path = self._revision._docname + '.' + entry            
-        return self._library._filectx(path, \
-            self._revision.hgrev()).data()   
+        path = self._library._sanitize_string(self.id + u'.' + entry)
+        try:
+            return self._library._filectx(path, \
+                self._revision.hgrev()).data().decode('utf-8')
+        except mercurial.error.LookupError, e:
+            fl = [x.decode('utf-8') for x in self._revision._changectx]            
+            raise wlrepo.EntryNotFound(self._revision, path.decode('utf-8'), fl)
 
     def quickwrite(self, entry, data, msg, user=None):
         user = user or self.owner
 
     def quickwrite(self, entry, data, msg, user=None):
         user = user or self.owner
@@ -32,25 +37,29 @@ class MercurialDocument(wlrepo.Document):
             f.close()
             l._fileadd(r(entry))            
 
             f.close()
             l._fileadd(r(entry))            
 
-        return self.invoke_and_commit(write, lambda d: (msg, user))
+        return self.invoke_and_commit(write, lambda d: (msg, \
+                self._library._sanitize_string(self.owner)) )
 
 
-    def invoke_and_commit(self, ops,
-            before_commit, rollback=False):
+    def invoke_and_commit(self, ops, commit_info):
         lock = self._library.lock()
         try:            
             self._library._checkout(self._revision.hgrev())
 
             def entry_path(entry):
         lock = self._library.lock()
         try:            
             self._library._checkout(self._revision.hgrev())
 
             def entry_path(entry):
-                return self.id + '.' + entry
+                return self._library._sanitize_string(self.id + u'.' + entry)
             
             ops(self._library, entry_path)
             
             ops(self._library, entry_path)
-            message, user = before_commit(self)            
+            message, user = commit_info(self)
+
+            message = self._library._sanitize_string(message)
+            user = self._library._sanitize_string(user)
+
             self._library._commit(message, user)
             try:
                 return self._library.document(docid=self.id, user=user)
             except Exception, e:
                 # rollback the last commit
             self._library._commit(message, user)
             try:
                 return self._library.document(docid=self.id, user=user)
             except Exception, e:
                 # rollback the last commit
-                self._library.rollback()
+                self._library._rollback()
                 raise e
         finally:
             lock.release()
                 raise e
         finally:
             lock.release()
@@ -60,7 +69,7 @@ class MercurialDocument(wlrepo.Document):
     #    self.invoke_and_commit(message, user, lambda *a: True)
 
     def ismain(self):
     #    self.invoke_and_commit(message, user, lambda *a: True)
 
     def ismain(self):
-        return self._revision.user_name() is None
+        return self._revision.user_name is None
 
     def shared(self):
         if self.ismain():
 
     def shared(self):
         if self.ismain():
@@ -93,15 +102,21 @@ class MercurialDocument(wlrepo.Document):
                 return (True, False)
             
             if self._revision.has_children():
                 return (True, False)
             
             if self._revision.has_children():
+                print 'Update failed: has children.'
                 # can't update non-latest revision
                 return (False, False)
 
             sv = self.shared()
                 # can't update non-latest revision
                 return (False, False)
 
             sv = self.shared()
-            
-            if not sv.ancestorof(self) and not self.parentof(sv):
-                return self._revision.merge_with(sv._revision, user=user)
 
 
-            return (False, False)
+            if self.parentof(sv):
+                return (True, False)
+
+            if sv.ancestorof(self):
+                return (True, False)
+
+
+            return self._revision.merge_with(sv._revision, user=user,
+                message="$AUTO$ Personal branch update.")
         finally:
             lock.release()  
 
         finally:
             lock.release()  
 
@@ -111,7 +126,7 @@ class MercurialDocument(wlrepo.Document):
             if self.ismain():
                 return (True, False) # always shared
 
             if self.ismain():
                 return (True, False) # always shared
 
-            user = self._revision.user_name()
+            user = self._revision.user_name
             main = self.shared()._revision
             local = self._revision            
 
             main = self.shared()._revision
             local = self._revision            
 
@@ -146,6 +161,9 @@ class MercurialDocument(wlrepo.Document):
                 if not local.parentof(main):
                     success, changed = main.merge_with(local, user=user, message=message)
 
                 if not local.parentof(main):
                     success, changed = main.merge_with(local, user=user, message=message)
 
+                success = True
+                changed = False
+
             # Case 3:
             # main *
             #      |
             # Case 3:
             # main *
             #      |
@@ -165,6 +183,9 @@ class MercurialDocument(wlrepo.Document):
                 if not local.parentof(main):
                     success, changed = local.merge_with(main, user=user, \
                         message='$AUTO$ Local branch update during share.')
                 if not local.parentof(main):
                     success, changed = local.merge_with(main, user=user, \
                         message='$AUTO$ Local branch update during share.')
+
+                success = True
+                changed = False
                     
             else:
                 print "case 4"
                     
             else:
                 print "case 4"
@@ -175,7 +196,7 @@ class MercurialDocument(wlrepo.Document):
                     return False
 
                 if changed:
                     return False
 
                 if changed:
-                    local = local.latest()
+                    local = self.latest()._revision
                     
                 success, changed = main.merge_with(local, user=user,\
                     message=message)
                     
                 success, changed = main.merge_with(local, user=user,\
                     message=message)
@@ -184,9 +205,12 @@ class MercurialDocument(wlrepo.Document):
         finally:
             lock.release()     
 
         finally:
             lock.release()     
 
-    def __str__(self):
+    def __unicode__(self):
         return u"Document(%s:%s)" % (self.name, self.owner)
 
         return u"Document(%s:%s)" % (self.name, self.owner)
 
+    def __str__(self):
+        return self.__unicode__().encode('utf-8')
+    
     def __eq__(self, other):
         return (self._revision == other._revision) and (self.name == other.name)
 
     def __eq__(self, other):
         return (self._revision == other._revision) and (self.name == other.name)