Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
commit_list = []
processed = set()
while stack:
sha1 = stack.pop()
if sha1 not in commits and not isreachable(sha1):
commits.add(sha1)
commit_list.append(sha1)
stack.extend([parent_sha1 for parent_sha1 in gitutils.Commit.fromSHA1(db, repository, sha1).parents if parent_sha1 not in processed])
processed.add(sha1)
branch = dbutils.Branch.fromName(db, repository, name)
review = dbutils.Review.fromBranch(db, branch)
if review:
if review.state != "open":
raise IndexException("""\
The review is closed and can't be extended. You need to reopen it at
%s
before you can add commits to it.""" % review.getURL(db, user, 2))
all_commits = [gitutils.Commit.fromSHA1(db, repository, sha1) for sha1 in reversed(commit_list)]
tails = CommitSet(all_commits).getTails()
if old not in tails:
raise IndexException("""\
Push rejected; would break the review.
assert repository.id == repository_id
if profiler: profiler.check("Branch.fromId: repository")
base_branch = (Branch.fromId(db, base_branch_id, repository=repository)
if base_branch_id is not None else None)
if profiler: profiler.check("Branch.fromId: base")
branch = Branch(branch_id, repository, branch_name, head_commit_sha1, base_branch, tail_commit_sha1, type, archived)
if load_review:
from dbutils import Review
branch.review = Review.fromBranch(db, branch)
if profiler: profiler.check("Branch.fromId: review")
return branch
def deleteBranch(db, user, repository, name, old):
try:
update(repository.path, "refs/heads/" + name, old, None)
except Reject as rejected:
raise IndexException(str(rejected))
except Exception:
pass
branch = dbutils.Branch.fromName(db, repository, name)
if branch:
review = dbutils.Review.fromBranch(db, branch)
if review:
raise IndexException("This is Critic refusing to delete a branch that belongs to a review.")
cursor = db.cursor()
cursor.execute("SELECT COUNT(*) FROM reachable WHERE branch=%s", (branch.id,))
ncommits = cursor.fetchone()[0]
if branch.base:
cursor.execute("UPDATE branches SET base=%s WHERE base=%s", (branch.base.id, branch.id))
cursor.execute("DELETE FROM branches WHERE id=%s", (branch.id,))
# Suppress the "user friendly" feedback if the push is performed by the
# Critic system user, since there wouldn't be a human being reading it.
@staticmethod
def fromName(db, repository, name):
return Review.fromBranch(db, Branch.fromName(db, repository, name))