예제 #1
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}))
예제 #2
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
예제 #3
0
def modDescription(request):
	repoPath = request.GET['path']
	repo = GitRepo(getGitPath() + sep + repoPath)
	if request.method == 'POST':
		repo.description = request.POST['description']
		return redirect(reverse('gitview.views.commits') + "?path=" + repoPath)
	return render_to_response("modDescription.html", RequestContext(request, {'repo': repo}))
예제 #4
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}))
예제 #5
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
예제 #6
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}))
예제 #7
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}))
예제 #8
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}))
예제 #9
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}))
예제 #10
0
def new(request):
	""" Add New repository Page """
	if not request.user.is_staff:
		return render_to_response("notAlowed.html", RequestContext(request))
	try:
		if settings.SECURITY_SYSTEM.lower() == 'gitolite':
			return redirect('gitview.gitolite.index')
	except AttributeError:
		pass
	if request.method == 'POST':
		newReposForm = NewReposForm(request.POST)
		if newReposForm.is_valid():
			newPath = newReposForm.data['path']
			if newPath[0] == '/':
				newPath = newPath[1:]
			GitRepo.create_bare(getGitPath() + sep + newPath, newReposForm.data['description'])
			return redirect('gitview.views.index')
	else:
		newReposForm = NewReposForm()
	return render_to_response("new.html",
	                          RequestContext(request, {'gitPath': getGitPath(), 'newReposForm': newReposForm}))
예제 #11
0
def index(request):
	gitPath = getGitPath()
	try:
		pathpar = request.GET['path']
	except KeyError:
		pathpar = ""
	currPath = getGitPath() + pathpar
	subDirs = []
	contents = listdir(currPath)
	for content in contents:
		fullPath = currPath + sep + content
		if isdir(fullPath):
			if not isdir(fullPath + sep + ".git") and not isdir(fullPath + sep + "refs"):
				toAdd = True
				for excl in settings.GIT_EXCLUDE_PATH:
					if re.match(excl, content):
						toAdd = False
				if toAdd:
					subDirs.append(content)
	subDirs = sorted(subDirs)
	repos = GitRepo.getRepos(currPath, False, settings.GIT_EXCLUDE_PATH)
	return render_to_response("index.html", RequestContext(request, {'gitPath': gitPath, 'currPath': currPath,
	                                                                 'gitBasicUrl': settings.GIT_BASIC_URL,
	                                                                 'subDirs': subDirs, 'repos': repos}))
예제 #12
0
	def createRepo(self):
		admRepo = GitRepo.init(self.path, True)
		admRepo.description = "Gitolite-Admin for GitDashboard"
		admRepo.create_remote('origin', self.url)
예제 #13
0
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
	}))