##// END OF EJS Templates
vcs: Minimal change to expose the shadow repository...
vcs: Minimal change to expose the shadow repository Based on my original research, this was the "minimal" starting point. It shows that three concepts are needed for the "repo_name": * From the security standpoint we think of the shadow repository having the same ACL as the target repository of the pull request. This is because the pull request itself is considered to be a part of the target repository. Out of this thought, the variable "acl_repo_name" is used whenever we want to check permissions or when we need the database configuration of the repository. An alternative name would have been "db_repo_name", but the usage for ACL checking is the most important one. * From the web interaction perspective, we need the URL which was originally used to get to the repository. This is because based on this base URL commands can be identified. Especially for Git this is important, so that the commands are correctly recognized. Since the URL is in the focus, this is called "url_repo_name". * Finally we have to deal with the repository on the file system. This is what the VCS layer deal with normally, so this name is called "vcs_repo_name". The original repository interaction is a special case where all three names are the same. When interacting with a pull request, these three names are typically all different. This change is minimal in a sense that it just makes the interaction with a shadow repository barely work, without checking any special constraints yet. This was the starting point for further work on this topic.

File last commit:

r1:854a839a default
r887:175782be default
Show More
graphmod.py
148 lines | 4.4 KiB | text/x-python | PythonLexer
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
# Copyright (C) 2010-2016 RhodeCode GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
"""
Modified mercurial DAG graph functions that re-uses VCS structure
It allows to have a shared codebase for DAG generation for hg and git repos
"""
nullrev = -1
def grandparent(parent_idx_func, lowest_idx, roots, head):
"""
Return all ancestors of head in roots which commit is
greater or equal to lowest_idx.
"""
pending = set([head])
seen = set()
kept = set()
llowestrev = max(nullrev, lowest_idx)
while pending:
r = pending.pop()
if r >= llowestrev and r not in seen:
if r in roots:
kept.add(r)
else:
pending.update(parent_idx_func(r))
seen.add(r)
return sorted(kept)
def _dagwalker(repo, commits):
if not commits:
return
# TODO: johbo: Use some sort of vcs api here
if repo.alias == 'hg':
def get_parent_indexes(idx):
return repo._remote.ctx_parents(idx)
elif repo.alias in ['git', 'svn']:
def get_parent_indexes(idx):
return [commit.idx for commit in repo[idx].parents]
indexes = [commit.idx for commit in commits]
lowest_idx = min(indexes)
known_indexes = set(indexes)
gpcache = {}
for commit in commits:
parents = sorted(set([p.idx for p in commit.parents
if p.idx in known_indexes]))
mpars = [p.idx for p in commit.parents if
p.idx != nullrev and p.idx not in parents]
for mpar in mpars:
gp = gpcache.get(mpar)
if gp is None:
gp = gpcache[mpar] = grandparent(
get_parent_indexes, lowest_idx, indexes, mpar)
if not gp:
parents.append(mpar)
else:
parents.extend(g for g in gp if g not in parents)
yield (commit.idx, parents)
def _colored(dag):
"""annotates a DAG with colored edge information
For each DAG node this function emits tuples::
((col, color), [(col, nextcol, color)])
with the following new elements:
- Tuple (col, color) with column and color index for the current node
- A list of tuples indicating the edges between the current node and its
parents.
"""
seen = []
colors = {}
newcolor = 1
for commit_idx, parents in dag:
# Compute seen and next_
if commit_idx not in seen:
seen.append(commit_idx) # new head
colors[commit_idx] = newcolor
newcolor += 1
col = seen.index(commit_idx)
color = colors.pop(commit_idx)
next_ = seen[:]
# Add parents to next_
addparents = [p for p in parents if p not in next_]
next_[col:col + 1] = addparents
# Set colors for the parents
for i, p in enumerate(addparents):
if i == 0:
colors[p] = color
else:
colors[p] = newcolor
newcolor += 1
# Add edges to the graph
edges = []
for ecol, eid in enumerate(seen):
if eid in next_:
edges.append((ecol, next_.index(eid), colors[eid]))
elif eid == commit_idx:
total_parents = len(parents)
edges.extend([
(ecol, next_.index(p),
_get_edge_color(p, total_parents, color, colors))
for p in parents])
# Yield and move on
yield ((col, color), edges)
seen = next_
def _get_edge_color(parent, total_parents, color, colors):
if total_parents <= 1:
return color
return colors.get(parent, color)