Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def processFile(file_id):
components = dbutils.describe_file(db, file_id).split("/")
directories, files = root_directories, root_files
for directory_name in components[:-1]:
directories, files = directories.setdefault(directory_name, ({}, {}))
files[components[-1]] = file_id
Returns false if the creating a comment at the specified location is not
supported, typically because the commit is not being reviewed in the
review.
"""
assert first_line > 0
assert last_line >= first_line
if not review.containsCommit(self.db, commit, True):
return False
self.review = review
self.rebases = review.getReviewRebases(self.db)
self.initial_commit = commit
self.addressed_by = []
self.file_path = dbutils.describe_file(self.db, file_id)
self.file_id = file_id
self.location = Location(first_line, last_line)
self.active = True
file_entry = commit.getFileEntry(self.file_path)
if file_entry is None:
# File doesn't exist (in the given commit.)
return False
diff_file = diff.File(new_sha1=file_entry.sha1,
new_mode=file_entry.mode,
repository=review.repository)
diff_file.loadNewLines()
if last_line > diff_file.newCount():
def renderFiles(db, to_user, review, title, files_lines, commits=None, relevant_only=False, relevant_files=None, showcommit_link=False):
result = ""
if files_lines:
files = []
for file_id, delete_count, insert_count in files_lines:
if not relevant_only or file_id in relevant_files:
files.append((dbutils.describe_file(db, file_id), delete_count, insert_count))
if files:
paths = []
deleted = []
inserted = []
for path, delete_count, insert_count in sorted(files):
paths.append(path)
deleted.append(delete_count)
inserted.append(insert_count)
paths = diff.File.eliminateCommonPrefixes(paths, text=True)
len_paths = max(map(len, paths))
len_deleted = max(map(len, map(str, deleted)))
len_inserted = max(map(len, map(str, inserted)))
def moduleFromFile(file_id):
filename = dbutils.describe_file(db, file_id)
return getModuleFromFile(repository, filename) or filename
def formatFiles(files):
paths = sorted([dbutils.describe_file(db, file_id) for file_id in files])
if granularity == "file":
return diff.File.eliminateCommonPrefixes(paths)
else:
modules = set()
files = []
for path in paths:
match = re_module.match(path)
if match: modules.add(match.group(1))
else: files.append(path)
return sorted(modules) + diff.File.eliminateCommonPrefixes(files)
def renderCodeCommentChain(db, target, user, review, chain, context_lines=3, compact=False, tabify=False, original=False, changeset=None, linkify=False):
repository = review.repository
old_sha1 = None
new_sha1 = None
old = 1
new = 2
cursor = db.cursor()
file_id = chain.file_id
file_path = dbutils.describe_file(db, file_id)
if (chain.state != "addressed" or original) and chain.first_commit == chain.last_commit:
sha1 = chain.first_commit.getFileSHA1(file_path)
cursor.execute("SELECT first_line, last_line FROM commentchainlines WHERE chain=%s AND sha1=%s", (chain.id, sha1))
first_line, last_line = cursor.fetchone()
file = diff.File(file_id, file_path, sha1, sha1, review.repository, chunks=[])
file.loadNewLines(True)
start = max(1, first_line - context_lines)
end = min(file.newCount(), last_line + context_lines)
count = end + 1 - start
lines = file.newLines(True)
lines = [diff.Line(diff.Line.CONTEXT, start + index, lines[start + index - 1], start + index, lines[start + index - 1]) for index in range(count)]
"original": commit == parent,
"current": commit == child }
for commit in annotator.commits],
files=files)
except LineAnnotator.NotSupported:
blame = gitutils.Blame(parent, child)
paths = {}
for file in files:
file_id = file["id"]
path = paths.get(file_id)
if not path:
path = paths[file_id] = dbutils.describe_file(db, file_id)
for block in file["blocks"]:
block["lines"] = blame.blame(db, path, block["first"], block["last"])
return OperationResult(commits=blame.commits, files=files)
def renderFiles(title, cursor):
files = []
for file_id, delete_count, insert_count in cursor.fetchall():
files.append((dbutils.describe_file(db, file_id), delete_count, insert_count))
paths = []
deleted = []
inserted = []
for path, delete_count, insert_count in sorted(files):
paths.append(path)
deleted.append(delete_count)
inserted.append(insert_count)
if paths:
diff.File.eliminateCommonPrefixes(paths)
row = table.tr("line")
row.td("heading").text(title)