def commit(request): """ View a single commit :param request: """ reposPath = request.GET['path'] if not checkRepoAuthorization(request,reposPath): return redirect(forbidden) commitId = request.GET['id'] try: branch = request.GET['branch'] except KeyError: branch = '' repo = GitRepo(getGitPath() + sep + reposPath) commit = repo.getCommit(commitId) changes = commit.getChanges() issueSystem = settings.ISSUE_SYSTEM issuePanelContent = "" try: if issueSystem.lower() == 'mantis_1.7': issuePanelContent = Mantis1_7IssuePane(commit.commit.message, settings.MESSAGE_ID_PATTERN, settings.ISSUE_WSDL, settings.ISSUE_URL, settings.ISSUE_USERNAME, settings.ISSUE_PASSWORD).renderHtml() except AttributeError: issueSystem = "" except NoIssueFoundException: issueSystem = "" return render_to_response("commit.html", RequestContext(request, {'gitPath': getGitPath(), 'repoPath': reposPath, 'commit': commit, 'changes': changes, 'branch': branch, 'issueSystem': issueSystem, 'issuePanelContent': issuePanelContent}))
def compareCommit(request): """ Compare two commit""" reposPath = request.GET['path'] if not checkRepoAuthorization(request,reposPath): return redirect(forbidden) commitIds = request.GET.getlist('compareCommitId') repo = GitRepo(getGitPath() + sep + reposPath) commit1 = repo.getCommit(commitIds[0]) commit2 = repo.getCommit(commitIds[1]) if commit1.commit.committed_date > commit2.commit.committed_date: swp = commit1 commit1 = commit2 commit2 = swp changes = gitEngine.commitChanges(repo, commit1.commit.hexsha, commit2.commit.hexsha) return render_to_response("compareCommit.html", RequestContext(request, {'repoPath': reposPath, 'commit1': commit1, 'commit2': commit2, 'changes': changes}))
def graph(request): """ Generate a Page with the graph image and related map called by ajax """ repoPath = request.GET['path'] if not checkRepoAuthorization(request,repoPath): return redirect(forbidden) try: branch = request.GET['branch'] except KeyError: branch = '' if len(request.GET['since']) > 0: try: since = int(request.GET['since']) except ValueError: since = int(time.mktime(time.strptime(request.GET['since'], "%Y-%m-%d %H:%M"))) else: since = None if len(request.GET['until']) > 0: try: until = int(request.GET['until']) except ValueError: until = int(time.mktime(time.strptime(request.GET['until'], "%Y-%m-%d %H:%M"))) else: until = None try: cmtId = request.GET['id'] highlights = "highlightsCircle(stage,circlesLayer,circle_" + cmtId + ",width);" except KeyError: highlights = None repo = GitRepo(getGitPath() + sep + repoPath) commitUrl = reverse('gitview.views.commit') commitUrl += "?path=" + repoPath + '&branch=' + branch + "&id=$$" graph = GitGraphCanvas(repo, since=since, until=until, commitUrl=str(commitUrl)) (branches, commits) = graph.render() return render_to_response("graph.html", RequestContext(request, {'repoPath': repoPath, 'branch': branch, 'canvasCommit': commits, 'canvasBranchName': branches, 'branchNamesWidth': graph.branchNamesWidth, 'width': graph.getWidth(), 'height': graph.getHeight(), 'highlights': highlights}))
def commits(request): reposPath = request.GET['path'].replace("//", "/") if not checkRepoAuthorization(request,reposPath): return redirect(forbidden) repo = GitRepo(getGitPath() + sep + reposPath) until = None since = None try: branch = request.GET['branch'] if branch == '': branch = repo.head.commit.hexsha except KeyError: branch = repo.head.commit.hexsha try: filePath = request.GET['filePath'] except KeyError: filePath = None page = 1 num = 10 numPerPages = 15 if request.method == 'POST': filterForm = FilterForm(request.POST) if filterForm.is_valid(): num = filterForm.cleaned_data['number'] page = filterForm.cleaned_data['page'] if filterForm.cleaned_data['since'] is not None: since = int(time.mktime(filterForm.cleaned_data['since'].timetuple())) if filterForm.cleaned_data['until'] is not None: until = int(time.mktime(filterForm.cleaned_data['until'].timetuple())) commits = repo.getCommits(num=num, since=since, until=until, branch=branch, path=filePath) else: commits = repo.getCommits(num, branch=branch, path=filePath) else: filterForm = FilterForm() commits = repo.getCommits(num, branch=branch, path=filePath) #The page number is +1 page -= 1 if len(commits) > numPerPages: numPages = len(commits) / numPerPages if len(commits) % numPerPages > 0: numPages += 1 commits = commits[numPerPages * page:][:numPerPages] else: numPages = 1 if branch: branchForm = BranchForm(repo, request.GET) else: branchForm = BranchForm(repo) repoName = reposPath.split('/')[-1] if reposPath.rfind('/') > 0: moduleName = reposPath[:reposPath.rfind('/')] else: moduleName = '' if repo.bare: repoDesc = repo.getDescription() else: repoDesc = None return render_to_response("commits.html", RequestContext(request, { 'branchForm': branchForm, 'filterForm': filterForm, 'repoPath': reposPath, 'moduleName': moduleName, 'repoName': repoName, 'repoDesc': repoDesc, 'branch': branch, 'since': since, 'until': until, 'commits': commits, 'num': num, 'numPages': range(numPages + 1)[1:], 'page': page + 1, 'filePath': filePath, 'gitPath': getGitPath(), 'gitBasicUrl': settings.GIT_BASIC_URL }))