Commit ea86163b authored by Thomas Randolph's avatar Thomas Randolph

Mark diff files if they're part of broken symlinks

- Also begins moving Diff File-specific things to file
     just for Diff Files instead of dumping everything
    into the `utils.js` junk drawer.
parent fe93883e
...@@ -36,6 +36,9 @@ export const LENGTH_OF_AVATAR_TOOLTIP = 17; ...@@ -36,6 +36,9 @@ export const LENGTH_OF_AVATAR_TOOLTIP = 17;
export const LINES_TO_BE_RENDERED_DIRECTLY = 100; export const LINES_TO_BE_RENDERED_DIRECTLY = 100;
export const MAX_LINES_TO_BE_RENDERED = 2000; export const MAX_LINES_TO_BE_RENDERED = 2000;
export const DIFF_FILE_SYMLINK_MODE = '120000';
export const DIFF_FILE_DELETED_MODE = '0';
export const MR_TREE_SHOW_KEY = 'mr_tree_show'; export const MR_TREE_SHOW_KEY = 'mr_tree_show';
export const TREE_TYPE = 'tree'; export const TREE_TYPE = 'tree';
......
import { DIFF_FILE_SYMLINK_MODE, DIFF_FILE_DELETED_MODE } from './constants';
function fileSymlinkInformation(file, fileList) {
const duplicates = fileList.filter(iteratedFile => iteratedFile.file_hash === file.file_hash);
const includesSymlink = duplicates.some(iteratedFile => {
return [iteratedFile.a_mode, iteratedFile.b_mode].includes(DIFF_FILE_SYMLINK_MODE);
});
const brokenSymlinkScenario = duplicates.length > 1 && includesSymlink;
return (
brokenSymlinkScenario && {
replaced: file.b_mode === DIFF_FILE_DELETED_MODE,
wasSymbolic: file.a_mode === DIFF_FILE_SYMLINK_MODE,
isSymbolic: file.b_mode === DIFF_FILE_SYMLINK_MODE,
wasReal: ![DIFF_FILE_SYMLINK_MODE, DIFF_FILE_DELETED_MODE].includes(file.a_mode),
isReal: ![DIFF_FILE_SYMLINK_MODE, DIFF_FILE_DELETED_MODE].includes(file.b_mode),
}
);
}
/* eslint-disable-next-line import/prefer-default-export */
export function prepareRawDiffFile({ file, allFiles }) {
Object.assign(file, {
brokenSymlink: fileSymlinkInformation(file, allFiles),
});
return file;
}
...@@ -18,6 +18,7 @@ import { ...@@ -18,6 +18,7 @@ import {
SHOW_WHITESPACE, SHOW_WHITESPACE,
NO_SHOW_WHITESPACE, NO_SHOW_WHITESPACE,
} from '../constants'; } from '../constants';
import { prepareRawDiffFile } from '../diff_file';
export function findDiffFile(files, match, matchKey = 'file_hash') { export function findDiffFile(files, match, matchKey = 'file_hash') {
return files.find(file => file[matchKey] === match); return files.find(file => file[matchKey] === match);
...@@ -294,9 +295,10 @@ function cleanRichText(text) { ...@@ -294,9 +295,10 @@ function cleanRichText(text) {
return text ? text.replace(/^[+ -]/, '') : undefined; return text ? text.replace(/^[+ -]/, '') : undefined;
} }
function prepareLine(line) { function prepareLine(line, file) {
if (!line.alreadyPrepared) { if (!line.alreadyPrepared) {
Object.assign(line, { Object.assign(line, {
commentsDisabled: file.brokenSymlink,
rich_text: cleanRichText(line.rich_text), rich_text: cleanRichText(line.rich_text),
discussionsExpanded: true, discussionsExpanded: true,
discussions: [], discussions: [],
...@@ -330,7 +332,7 @@ export function prepareLineForRenamedFile({ line, diffViewType, diffFile, index ...@@ -330,7 +332,7 @@ export function prepareLineForRenamedFile({ line, diffViewType, diffFile, index
old_line: lineNumber, old_line: lineNumber,
}; };
prepareLine(cleanLine); // WARNING: In-Place Mutations! prepareLine(cleanLine, diffFile); // WARNING: In-Place Mutations!
if (diffViewType === PARALLEL_DIFF_VIEW_TYPE) { if (diffViewType === PARALLEL_DIFF_VIEW_TYPE) {
return { return {
...@@ -348,19 +350,19 @@ function prepareDiffFileLines(file) { ...@@ -348,19 +350,19 @@ function prepareDiffFileLines(file) {
const parallelLines = file.parallel_diff_lines; const parallelLines = file.parallel_diff_lines;
let parallelLinesCount = 0; let parallelLinesCount = 0;
inlineLines.forEach(prepareLine); inlineLines.forEach(line => prepareLine(line, file)); // WARNING: In-Place Mutations!
parallelLines.forEach((line, index) => { parallelLines.forEach((line, index) => {
Object.assign(line, { line_code: getLineCode(line, index) }); Object.assign(line, { line_code: getLineCode(line, index) });
if (line.left) { if (line.left) {
parallelLinesCount += 1; parallelLinesCount += 1;
prepareLine(line.left); prepareLine(line.left, file); // WARNING: In-Place Mutations!
} }
if (line.right) { if (line.right) {
parallelLinesCount += 1; parallelLinesCount += 1;
prepareLine(line.right); prepareLine(line.right, file); // WARNING: In-Place Mutations!
} }
}); });
...@@ -407,6 +409,7 @@ function deduplicateFilesList(files) { ...@@ -407,6 +409,7 @@ function deduplicateFilesList(files) {
export function prepareDiffData(diff, priorFiles = []) { export function prepareDiffData(diff, priorFiles = []) {
const cleanedFiles = (diff.diff_files || []) const cleanedFiles = (diff.diff_files || [])
.map((file, index, allFiles) => prepareRawDiffFile({ file, allFiles }))
.map(ensureBasicDiffFileLines) .map(ensureBasicDiffFileLines)
.map(prepareDiffFileLines) .map(prepareDiffFileLines)
.map(finalizeDiffFile); .map(finalizeDiffFile);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment