|
11 | 11 | var utils = require('./utils.js').Utils; |
12 | 12 | var Rematch = require('./rematch.js').Rematch; |
13 | 13 |
|
| 14 | + var separator = '/'; |
| 15 | + |
14 | 16 | function PrinterUtils() { |
15 | 17 | } |
16 | 18 |
|
|
32 | 34 | }; |
33 | 35 |
|
34 | 36 | PrinterUtils.prototype.getDiffName = function(file) { |
35 | | - var oldFilename = file.oldName; |
36 | | - var newFilename = file.newName; |
| 37 | + var oldFilename = unifyPath(file.oldName); |
| 38 | + var newFilename = unifyPath(file.newName); |
37 | 39 |
|
38 | 40 | if (oldFilename && newFilename && oldFilename !== newFilename && !isDevNullName(oldFilename) && !isDevNullName(newFilename)) { |
39 | | - return oldFilename + ' -> ' + newFilename; |
| 41 | + var prefixPaths = []; |
| 42 | + var suffixPaths = []; |
| 43 | + |
| 44 | + var oldFilenameParts = oldFilename.split(separator); |
| 45 | + var newFilenameParts = newFilename.split(separator); |
| 46 | + |
| 47 | + var oldFilenamePartsSize = oldFilenameParts.length; |
| 48 | + var newFilenamePartsSize = newFilenameParts.length; |
| 49 | + |
| 50 | + var i = 0; |
| 51 | + var j = oldFilenamePartsSize - 1; |
| 52 | + var k = newFilenamePartsSize - 1; |
| 53 | + |
| 54 | + while (i < j && i < k) { |
| 55 | + if (oldFilenameParts[i] === newFilenameParts[i]) { |
| 56 | + prefixPaths.push(newFilenameParts[i]); |
| 57 | + i += 1; |
| 58 | + } else { |
| 59 | + break; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + while (j > i && k > i) { |
| 64 | + if (oldFilenameParts[j] === newFilenameParts[k]) { |
| 65 | + suffixPaths.unshift(newFilenameParts[k]); |
| 66 | + j -= 1; |
| 67 | + k -= 1; |
| 68 | + } else { |
| 69 | + break; |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + var finalPrefix = prefixPaths.join(separator); |
| 74 | + var finalSuffix = suffixPaths.join(separator); |
| 75 | + |
| 76 | + var oldRemainingPath = oldFilenameParts.slice(i, j + 1).join(separator); |
| 77 | + var newRemainingPath = newFilenameParts.slice(i, k + 1).join(separator); |
| 78 | + |
| 79 | + if (finalPrefix.length && finalSuffix.length) { |
| 80 | + return finalPrefix + separator + '{' + oldRemainingPath + ' → ' + newRemainingPath + '}' + separator + finalSuffix; |
| 81 | + } else if (finalPrefix.length) { |
| 82 | + return finalPrefix + separator + '{' + oldRemainingPath + ' → ' + newRemainingPath + '}'; |
| 83 | + } else if (finalSuffix.length) { |
| 84 | + return '{' + oldRemainingPath + ' → ' + newRemainingPath + '}' + separator + finalSuffix; |
| 85 | + } |
| 86 | + |
| 87 | + return oldFilename + ' → ' + newFilename; |
| 88 | + |
40 | 89 | } else if (newFilename && !isDevNullName(newFilename)) { |
41 | 90 | return newFilename; |
42 | 91 | } else if (oldFilename) { |
43 | 92 | return oldFilename; |
44 | 93 | } |
45 | 94 |
|
46 | | - return 'Unknown filename'; |
| 95 | + return 'unknown/file/path'; |
47 | 96 | }; |
48 | 97 |
|
49 | 98 | PrinterUtils.prototype.diffHighlight = function(diffLine1, diffLine2, config) { |
|
128 | 177 | }; |
129 | 178 | }; |
130 | 179 |
|
| 180 | + function unifyPath(path) { |
| 181 | + if (path) { |
| 182 | + return path.replace('\\', '/'); |
| 183 | + } |
| 184 | + |
| 185 | + return path; |
| 186 | + } |
| 187 | + |
131 | 188 | function isDevNullName(name) { |
132 | 189 | return name.indexOf('dev/null') !== -1; |
133 | 190 | } |
|
0 commit comments