Another pull/push fix.
authorLukasz <lreqc@debian.(none)>
Fri, 23 Oct 2009 10:27:40 +0000 (06:27 -0400)
committerLukasz <lreqc@debian.(none)>
Fri, 23 Oct 2009 10:27:40 +0000 (06:27 -0400)
apps/api/handlers/library_handlers.py
lib/wlrepo/mercurial_backend/document.py
lib/wlrepo/mercurial_backend/library.py
lib/wlrepo/mercurial_backend/revision.py
platforma/static/js/models.js

index 562ed1b..0a45a0b 100755 (executable)
@@ -207,8 +207,8 @@ class DiffHandler(BaseHandler):
     @hglibrary
     def read(self, request, source_revision, target_revision, lib):
         '''Return diff between source_revision and target_revision)'''
-        source_document = lib.document_for_rev(source_revision)
-        target_document = lib.document_for_rev(target_revision)
+        source_document = lib.document_for_revision(source_revision)
+        target_document = lib.document_for_revision(target_revision)
         print source_document,
         print target_document
         diff = difflib.unified_diff(
@@ -261,7 +261,7 @@ class DocumentHandler(BaseHandler):
                 elif is_prq(user):
                     prq = prq_for_user(user)
                     # commiter's document
-                    prq_doc = lib.document_for_rev(prq.source_revision)
+                    prq_doc = lib.document_for_revision(prq.source_revision)
                     doc = prq_doc.take(user)
                 else:
                     return response.EntityNotFound().django_response({
@@ -310,7 +310,7 @@ class DocumentHTMLHandler(BaseHandler):
         try:
             revision = form.cleaned_data['revision']
             user = form.cleaned_data['user'] or request.user.username
-            document = lib.document_for_rev(revision)
+            document = lib.document_for_revision(revision)
 
             if document.id != docid:
                 return response.BadRequest().django_response({
@@ -412,7 +412,7 @@ class DocumentGalleryHandler(BaseHandler):
 #            if revision == 'latest':
 #                doc = lib.document(docid)
 #            else:
-#                doc = lib.document_for_rev(revision)
+#                doc = lib.document_for_revision(revision)
 #
 #
 #            if document.id != docid:
@@ -437,7 +437,7 @@ class DocumentGalleryHandler(BaseHandler):
 #                msg = u"$AUTO$ Dublin core update."
 #
 #            current = lib.document(docid, request.user.username)
-#            orig = lib.document_for_rev(revision)
+#            orig = lib.document_for_revision(revision)
 #
 #            if current != orig:
 #                return response.EntityConflict().django_response({
@@ -482,7 +482,7 @@ class MergeHandler(BaseHandler):
         doc = lib.document(docid)
 
         # fetch the base document
-        user_doc = lib.document_for_rev(revision)
+        user_doc = lib.document_for_revision(revision)
         base_doc = user_doc.latest()
 
         if base_doc != user_doc:
@@ -512,9 +512,11 @@ class MergeHandler(BaseHandler):
                     "message": "You must first update your branch to the latest version."
                 })
 
-            if not base_doc.would_share():
+            anwser, info = base_doc.would_share()
+                
+            if not anwser:
                 return response.SuccessAllOk().django_response({
-                    "result": "no-op"
+                    "result": "no-op", "message": info
                 })
 
             # check for unresolved conflicts            
index 3bd26a6..35779d8 100755 (executable)
@@ -168,13 +168,13 @@ class MercurialDocument(wlrepo.Document):
 
     def would_share(self):
         if self.ismain():
-            return False
+            return False, "Main version is always shared"
 
         shared = self.shared()
 
         # we just did this - move on
         if self.parentof(shared):
-            return False
+            return False, "Document has been recetly shared - no changes"
 
         #     *
         #    /|
@@ -191,13 +191,17 @@ class MercurialDocument(wlrepo.Document):
         #   | |
         # We want to prevent stuff like this.
         if self.parent().parentof(shared):
-            return False
+            return False, "Preventing zig-zag"
+
+        return True, "OK"
+
 
     def share(self, message):
         lock = self.library.lock()
         try:
+            result, info = self.would_share()
 
-            if not self.would_share():
+            if not result:
                 return self.shared()          
       
             # The good situation
@@ -209,6 +213,8 @@ class MercurialDocument(wlrepo.Document):
             #       / |
             # main *  *
             #      |  |
+            shared = self.shared()
+
             if shared.ancestorof(self):               
                 success = shared._revision.merge_with(self._revision, user=self.owner, message=message)
 
index 316800f..5535a88 100755 (executable)
@@ -99,14 +99,14 @@ class MercurialLibrary(wlrepo.Library):
         rev = self._sanitize_string(rev)
         
         if rev != u'latest':
-            doc = self.document_for_rev(rev)
+            doc = self.document_for_revision(rev)
 
             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))
+            return self.document_for_revision(self.fulldocid(docid, user))
 
     def get_revision(self, revid):
         revid = self._sanitize_string(revid)
@@ -121,9 +121,12 @@ class MercurialLibrary(wlrepo.Library):
         if ctx is None:
             raise wlrepo.RevisionNotFound(revid)
 
+        return self._revision(ctx)       
+
+    def _revision(self, ctx):
         if self._revcache.has_key(ctx):
             return self._revcache[ctx]
-
+        
         return MercurialRevision(self, ctx)
 
     def fulldocid(self, docid, user=None):                
@@ -140,8 +143,7 @@ class MercurialLibrary(wlrepo.Library):
         except mercurial.error.RepoError:
             return False
 
-    def document_create(self, docid):
-        
+    def document_create(self, docid):       
         
         # check if it already exists
         fullid = self.fulldocid(docid)
@@ -151,7 +153,7 @@ class MercurialLibrary(wlrepo.Library):
 
         # doesn't exist
         self._create_branch(self._sanitize_string(fullid))
-        return self.document_for_rev(fullid)
+        return self.document_for_revision(fullid)
 
     #
     # Private methods
index 80b761f..5b1b820 100755 (executable)
@@ -103,9 +103,12 @@ class MercurialRevision(wlrepo.Revision):
         parents = self._changectx.parents()
 
         if len(parents) == 1:
-            return parents[0]
-
-        return parents[0] if (parents[0].branch() == self.branch()) else parents[1]
+            return self._library._revision(parents[0])
+        
+        if parents[0].branch() == self.branch():
+            return self._library._revision(parents[0])
+        else:
+            return self._library._revision(parents[1]) 
         
     def __eq__(self, other):
         return self._changectx.node() == other._changectx.node()
index ffaf999..7fdca39 100755 (executable)
@@ -596,10 +596,13 @@ Editor.DocumentModel = Editor.Model.extend({
     mergeCompleted: function(xhr, textStatus) {
         console.log(xhr.status, xhr.responseText);
         var response = parseXHRResponse(xhr);
-        if(response.success)
-        {
-            if( (response.data.result == 'no-op')
-             || (response.data.shared_timestamp == response.data.shared_parent_timestamp))
+        
+        if(response.success) {
+        
+            if( (response.data.result == 'no-op') ||             
+             ( response.data.shared_parent_timestamp
+               && response.data.shared_timestamp
+               && (response.data.shared_timestamp == response.data.shared_parent_timestamp)) )
             {
                 if( (response.data.revision) && (response.data.revision != this.get('revision')) )
                 {