+ if repo.common_ancestor(tipB, tipA) == nodeA:
+ # Case 1:
+ # * tipB
+ # |
+ # * <- can also be here!
+ # /|
+ # / |
+ # tipA * *
+ # | |
+ # The local branch has been recently updated,
+ # so we don't need to update yet again, but we need to
+ # merge down to default branch, even if there was
+ # no commit's since last update
+ repo.merge_revisions(tipA, tipB, \
+ request.user.username, form.cleaned_data['message'])
+ result = 'done'
+ elif any( p.branch()==nodeB.branch() for p in nodeA.parents()):
+ # Case 2:
+ #
+ # tipA * * tipB
+ # |\ |
+ # | \|
+ # | *
+ # | |
+ # Default has no changes, to update from this branch
+ # since the last merge of local to default.
+ if nodeB not in nodeA.parents():
+ repo.merge_revisions(tipA, tipB, \
+ request.user.username, form.cleaned_data['message'])
+ result = 'done'
+ else:
+ result = 'nothing-to-do'
+ elif repo.common_ancestor(tipA, tipB) == nodeB:
+ # Case 3:
+ # tipA *
+ # |
+ # * <- this case overlaps with previos one
+ # |\
+ # | \
+ # | * tipB
+ # | |
+ #
+ # There was a recent merge to the defaul branch and
+ # no changes to local branch recently.
+ #
+ # Use the fact, that user is prepared to see changes, to
+ # update his branch if there are any
+ if nodeB not in nodeA.parents():
+ repo.merge_revisions(tipB, tipA, \
+ request.user.username, 'Personal branch update during merge.')
+ local_modified = True
+ result = 'done'
+ else:
+ result = 'nothing-to-do'
+ else:
+ # both branches have changes made to them, so
+ # first do an update
+ repo.merge_revisions(tipB, tipA, \
+ request.user.username, 'Personal branch update during merge.')
+
+ local_modified = True
+
+ # fetch the new tip
+ tipB = repo.get_branch_tip( file_branch(path, request.user) )
+
+ # and merge back to the default
+ repo.merge_revisions(tipA, tipB, \
+ request.user.username, form.cleaned_data['message'])
+ result = 'done'
+ except hg.UncleanMerge, e:
+ errors = [e.message]
+ result = 'fatal-error'
+ except hg.RepositoryException, e:
+ errors = [e.message]
+ result = 'fatal-error'
+ finally:
+ wlock.release()
+
+ if result is None:
+ errors = [ form.errors['message'].as_text() ]
+ if len(errors) > 0:
+ result = 'fatal-error'
+
+ return HttpResponse( json.dumps({'result': result, 'errors': errors, 'localmodified': local_modified}) );
+
+ return HttpResponse( json.dumps({'result': 'fatal-error', 'errors': ['No data posted']}) )
+
+
+@ajax_login_required