Beispiel #1
0
def zipTree(request):
	""" zip a tree of a commit """
	reposPath = request.GET['path']
	if not checkRepoAuthorization(request,reposPath):
		return redirect(forbidden)
	commitId = request.GET['commit']
	repo = GitRepo(getGitPath() + sep + reposPath)
	commit = repo.getCommit(commitId)
	tree = commit.getTree()
	content = tree.getRoot()
	rootFiles = []
	for c in content:
		if isinstance(c, GitDir):
			dirFiles(c, rootFiles)
		else:
			rootFiles.append(c)
	temp = tempfile.TemporaryFile()
	archive = zipfile.ZipFile(temp, 'w', zipfile.ZIP_DEFLATED)
	for f in rootFiles:
		archive.writestr(f.blob.path, f.getContent())
	archive.close()
	wrapper = FileWrapper(temp)
	response = HttpResponse(wrapper, content_type='application/zip')
	response['Content-Disposition'] = 'attachment; filename=' + reposPath.replace('/', '_').replace(".git", "") + ".zip"
	response['Content-Length'] = temp.tell()
	temp.seek(0)
	return response
Beispiel #2
0
def tree(request):
	""" View a tree of a commit """
	reposPath = request.GET['path']
	if not checkRepoAuthorization(request,reposPath):
		return redirect(forbidden)
	commitId = request.GET['commit']
	try:
		branch = request.GET['branch']
	except KeyError:
		branch = ''
	repo = GitRepo(getGitPath() + sep + reposPath)
	commit = repo.getCommit(commitId)
	tree = commit.getTree()
	content = tree.getRoot()
	treeContent = ""
	rootFiles = []
	for c in content:
		if isinstance(c, GitDir):
			treeContent += dir_to_ul(c, reposPath)
		else:
			rootFiles.append(c)
		#add files at the end
	for f in rootFiles:
		treeContent += "<li><span class=\"file\">"
		treeContent += "<a href='#' onclick=\"showContent('" + f.blob.path + "') \">"
		treeContent += f.blob.name + "</a></span></li>"
	return render_to_response("tree.html", RequestContext(request, {'repoPath': reposPath, 'commitId': commitId,
	                                                                'treeContent': treeContent, 'branch': branch}))
Beispiel #3
0
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}))
Beispiel #4
0
def rawContent(request):
	reposPath = request.GET['path']
	if not checkRepoAuthorization(request,reposPath):
		return redirect(forbidden)
	commitId = request.GET['commitId']
	filePath = request.GET['filePath']
	repo = GitRepo(getGitPath() + sep + reposPath)
	commit = repo.getCommit(commitId)
	gitFile = commit.getTree().getFile(filePath)
	response = HttpResponse(gitFile.getContent())
	response._headers['content-disposition'] = ('Content-Disposition', 'attachment; filename=' + gitFile.blob.name)
	return response
Beispiel #5
0
def fileContent(request):
	reposPath = request.GET['path']
	if not checkRepoAuthorization(request,reposPath):
		return redirect(forbidden)
	commitId = request.GET['commitId']
	filePath = request.GET['filePath']
	try:
		branch = request.GET['branch']
	except KeyError:
		branch = ''
	repo = GitRepo(getGitPath() + sep + reposPath)
	commit = repo.getCommit(commitId)
	gitFile = commit.getTree().getFile(filePath)
	return render_to_response("fileContent.html", RequestContext(request, {'repoPath': reposPath, 'commitId': commitId,
	                                                                       'gitFile': gitFile, 'branch': branch}))
Beispiel #6
0
def diff(request):
	reposPath = request.GET['path']
	if not checkRepoAuthorization(request,reposPath):
		return redirect(forbidden)
	commitId = request.GET['commit']
	oldSha = request.GET['oldSha']
	newSha = request.GET['newSha']
	try:
		request.GET['ghDiff']
		ghDiff = True
	except KeyError:
		ghDiff = False
	repo = GitRepo(getGitPath() + sep + reposPath)
	commit = repo.getCommit(commitId)
	change = GitChange(commit=commit, oldSha=oldSha, newSha=newSha)
	return render_to_response("diff.html", RequestContext(request, {'ghDiff': ghDiff, 'change': change}))
Beispiel #7
0
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}))
Beispiel #8
0
def view(request):
	""" View a single file of a commit """
	reposPath = request.GET['path']
	if not checkRepoAuthorization(request,reposPath):
		return redirect(forbidden)
	commitId = request.GET['commit']
	filePath = request.GET['filePath']
	try:
		branch = request.GET['branch']
	except KeyError:
		branch = ''
	repo = GitRepo(getGitPath() + sep + reposPath)
	commit = repo.getCommit(commitId)
	fileSha = commit.getTree().getFile(filePath).blob.hexsha
	return render_to_response("view.html", RequestContext(request, {'repoPath': reposPath, 'commitId': commitId,
	                                                                'fileName': filePath, 'fileSha': fileSha,
	                                                                'branch': branch}))