@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(
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({
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({
# if revision == 'latest':
# doc = lib.document(docid)
# else:
-# doc = lib.document_for_rev(revision)
+# doc = lib.document_for_revision(revision)
#
#
# if document.id != docid:
# 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({
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:
"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
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"
# *
# /|
# | |
# 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
# / |
# main * *
# | |
+ shared = self.shared()
+
if shared.ancestorof(self):
success = shared._revision.merge_with(self._revision, user=self.owner, message=message)
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)
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):
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)
# doesn't exist
self._create_branch(self._sanitize_string(fullid))
- return self.document_for_rev(fullid)
+ return self.document_for_revision(fullid)
#
# Private methods
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()
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')) )
{