Naprawione galerie.
[redakcja.git] / lib / wlrepo / mercurial_backend / library.py
index ebb38d8..84e7654 100644 (file)
@@ -1,5 +1,8 @@
 # -*- encoding: utf-8 -*-
 
+import logging
+log = logging.getLogger('ral.mercurial')
+
 __author__= "Ɓukasz Rekucki"
 __date__ = "$2009-09-25 09:33:02$"
 __doc__ = "Module documentation."
@@ -92,19 +95,25 @@ class MercurialLibrary(wlrepo.Library):
         # every revision is a document
         return self._doccache[str(rev)]
 
-    def document(self, docid, user=None):       
-        return self.document_for_rev(self.fulldocid(docid, user))
+    def document(self, docid, user=None, rev=u'latest'):
+        rev = self._sanitize_string(rev)
+        
+        if rev != u'latest':
+            doc = self.document_for_rev(rev)
 
-    def get_revision(self, revid):
-        revid = self._sanitize_string(revid).decode('utf-8')
+            if doc.id != docid or (doc.owner != user):
+                raise wlrepo.RevisionMismatch(self.fulldocid(docid, user)+u'@'+unicode(rev))
+            
+            return doc
+        else:
+            return self.document_for_rev(self.fulldocid(docid, user))
 
-        print "Looking up rev %r (%s)" %(revid, type(revid))
+    def get_revision(self, revid):
+        revid = self._sanitize_string(revid)
 
-        try:
-            # THIS IS THE MOST BRAIN-DEAD API I EVER SEEN
-            # WHY DO ALL THE OTHER METHODS SIMPLY
-            # FAIL WHEN GIVEN UNICODE, WHEN THIS WORKS ONLY!! WITH IT
+        log.info("Looking up rev %r (%s)" %(revid, type(revid)) )
 
+        try:           
             ctx = self._changectx( revid )
         except mercurial.error.RepoError, e:
             raise wlrepo.RevisionNotFound(revid)
@@ -224,7 +233,7 @@ class MercurialLibrary(wlrepo.Library):
         name = self._sanitize_string(name)
         return self._hgrepo.branchtags()[name]    
 
-    def _create_branch(self, name, parent=None, before_commit=None):
+    def _create_branch(self, name, parent=None, before_commit=None, message=None):
         name = self._sanitize_string(name)
 
         if self._has_branch(name): return # just exit
@@ -235,11 +244,16 @@ class MercurialLibrary(wlrepo.Library):
             parentrev = parent.hgrev()
 
         self._checkout(parentrev)
-        self._hgrepo.dirstate.setbranch(name)
+        self._set_branchname(name)
 
         if before_commit: before_commit(self)
 
-        self._commit("$ADMN$ Initial commit for branch '%s'." % name, user='$library')        
+        message = message or "$ADMN$ Initial commit for branch '%s'." % name
+        self._commit(message, user='$library')
+
+    def _set_branchname(self, name):
+        name = self._sanitize_string(name)
+        self._hgrepo.dirstate.setbranch(name)
 
     def _switch_to_branch(self, branchname):
         current = self._hgrepo[None].branch()