- form = forms.BookForm()
- data = repo.get_file(rpath, file_branch(path, request.user))
- form.fields['content'].initial = data
- return HttpResponse( json.dumps({'result': 'ok', 'content': data}) )
-
-@ajax_login_required
-@with_repo
-def file_update_local(request, path, repo):
- result = None
- errors = None
-
- wlock = repo.write_lock()
- try:
- tipA = repo.get_branch_tip('default')
- tipB = repo.get_branch_tip( file_branch(path, request.user) )
-
- nodeA = repo.getnode(tipA)
- nodeB = repo.getnode(tipB)
-
- # do some wild checks - see file_commit() for more info
- if (repo.common_ancestor(tipA, tipB) == nodeA) \
- or (nodeB in nodeA.parents()):
- result = 'nothing-to-do'
- else:
- # Case 2+
- repo.merge_revisions(tipB, tipA, \
- request.user.username, 'Personal branch update.')
- 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:
- raise Exception("Ouch, this shouldn't happen!")
-
- return HttpResponse( json.dumps({'result': result, 'errors': errors}) );
-
-@ajax_login_required
-@with_repo
-def file_commit(request, path, repo):
- result = None
- errors = None
- local_modified = False
- if request.method == 'POST':
- form = forms.MergeForm(request.POST)
-
- if form.is_valid():
- wlock = repo.write_lock()
- try:
- tipA = repo.get_branch_tip('default')
- tipB = repo.get_branch_tip( file_branch(path, request.user) )
-
- nodeA = repo.getnode(tipA)
- nodeB = repo.getnode(tipB)
-
- print repr(nodeA), repr(nodeB), repo.common_ancestor(tipA, tipB), repo.common_ancestor(tipB, tipA)
-
- 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}) );