Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: appengine/chromium_rietveld/new_static/model/patch_file.js

Issue 992403002: Simplify and fix sorting of PatchFiles. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | appengine/chromium_rietveld/new_static/model/tests/patch_set_tests.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 "use strict"; 5 "use strict";
6 6
7 function PatchFile(patchset, name) 7 function PatchFile(patchset, name)
8 { 8 {
9 this.name = name || ""; 9 this.name = name || "";
10 this.prefix = name || "";
10 this.extension = ""; 11 this.extension = "";
11 this.prefix = "";
12 this.language = ""; 12 this.language = "";
13 this.containsEmbeddedLanguages = false; 13 this.containsEmbeddedLanguages = false;
14 this.status = ""; 14 this.status = "";
15 this.chunks = 0; 15 this.chunks = 0;
16 this.missingBaseFile = false; 16 this.missingBaseFile = false;
17 this.propertyChanges = ""; 17 this.propertyChanges = "";
18 this.added = 0; 18 this.added = 0;
19 this.removed = 0; 19 this.removed = 0;
20 this.id = 0; 20 this.id = 0;
21 this.patchset = patchset || null; // PatchSet 21 this.patchset = patchset || null; // PatchSet
22 this.isBinary = false; 22 this.isBinary = false;
23 this.messages = {}; // Map<line number, Array<PatchFileMessage>> 23 this.messages = {}; // Map<line number, Array<PatchFileMessage>>
24 this.messageCount = 0; 24 this.messageCount = 0;
25 this.drafts = []; // Array<PatchFileMessage> 25 this.drafts = []; // Array<PatchFileMessage>
26 this.draftCount = 0; 26 this.draftCount = 0;
27 this.diff = null; 27 this.diff = null;
28 this.isLayoutTest = this.name.startsWith("LayoutTests/"); 28 this.isLayoutTest = this.name.startsWith("LayoutTests/");
29 this.isHeader = false;
29 Object.preventExtensions(this); 30 Object.preventExtensions(this);
30 31
31 var dotIndex = this.name.lastIndexOf("."); 32 var dotIndex = this.name.lastIndexOf(".");
32 if (dotIndex != -1) { 33 if (dotIndex != -1) {
33 this.extension = this.name.from(dotIndex + 1); 34 this.extension = this.name.from(dotIndex + 1);
35 this.isHeader = PatchFile.HEADER_EXTENSIONS[this.extension] || false;
34 this.prefix = this.name.to(dotIndex); 36 this.prefix = this.name.to(dotIndex);
35 this.language = PatchFile.SYNTAX_LANGUAGES[this.extension] || ""; 37 this.language = PatchFile.SYNTAX_LANGUAGES[this.extension] || "";
36 this.containsEmbeddedLanguages = PatchFile.MIXED_LANGUAGES[this.language ]; 38 this.containsEmbeddedLanguages = PatchFile.MIXED_LANGUAGES[this.language ];
37 } 39 }
38 } 40 }
39 41
40 PatchFile.DIFF_URL = "/download/issue{1}_{2}_{3}.diff"; 42 PatchFile.DIFF_URL = "/download/issue{1}_{2}_{3}.diff";
41 PatchFile.CONTEXT_URL = "/{1}/diff_skipped_lines/{2}/{3}/{4}/{5}/a/2000"; 43 PatchFile.CONTEXT_URL = "/{1}/diff_skipped_lines/{2}/{3}/{4}/{5}/a/2000";
42 PatchFile.DRAFT_URL = "/api/{1}/{2}/{3}/draft_message"; 44 PatchFile.DRAFT_URL = "/api/{1}/{2}/{3}/draft_message";
43 PatchFile.IMAGE_URL = "/{1}/image/{2}/{3}/{4}"; 45 PatchFile.IMAGE_URL = "/{1}/image/{2}/{3}/{4}";
(...skipping 27 matching lines...) Expand all
71 "pl": "perl", 73 "pl": "perl",
72 "pm": "perl", 74 "pm": "perl",
73 "py": "python", 75 "py": "python",
74 "rb": "ruby", 76 "rb": "ruby",
75 "sh": "bash", 77 "sh": "bash",
76 "svg": "xml", 78 "svg": "xml",
77 "xhtml": "html", 79 "xhtml": "html",
78 "xml": "xml", 80 "xml": "xml",
79 }; 81 };
80 82
83 PatchFile.HEADER_EXTENSIONS = {
84 "h": true,
85 "hxx": true,
86 "hpp": true,
87 };
88
81 PatchFile.compare = function(a, b) 89 PatchFile.compare = function(a, b)
82 { 90 {
83 if (a.isLayoutTest && b.isLayoutTest) 91 if (a.isLayoutTest != b.isLayoutTest)
84 return a.name.localeCompare(b.name); 92 return b.isLayoutTest ? -1 : 1;
85 if (a.isLayoutTest)
86 return 1;
87 if (b.isLayoutTest)
88 return -1;
89 if (a.prefix != b.prefix) 93 if (a.prefix != b.prefix)
90 return a.name.localeCompare(b.name); 94 return a.prefix.localeCompare(b.prefix);
91 if (a.extension == "h" && (b.extension == "cpp" || b.extension == "cc")) 95 if (a.isHeader != b.isHeader)
92 return -1; 96 return a.isHeader ? -1 : 1;
93 if (b.extension == "h" && (a.extension == "cpp" || a.extension == "cc"))
94 return 1;
95 return a.extension.localeCompare(b.extension); 97 return a.extension.localeCompare(b.extension);
96 }; 98 };
97 99
98 PatchFile.prototype.shouldResetEmbeddedLanguage = function(language, text) 100 PatchFile.prototype.shouldResetEmbeddedLanguage = function(language, text)
99 { 101 {
100 if (!this.containsEmbeddedLanguages) 102 if (!this.containsEmbeddedLanguages)
101 return false; 103 return false;
102 if (language == "javascript" && text.startsWith("<\/script")) 104 if (language == "javascript" && text.startsWith("<\/script"))
103 return true; 105 return true;
104 if (language == "css" && text.startsWith("<\/style")) 106 if (language == "css" && text.startsWith("<\/style"))
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 while (text[numberStart] == " " && numberStart < text.length) 339 while (text[numberStart] == " " && numberStart < text.length)
338 ++numberStart; 340 ++numberStart;
339 var numberEnd = numberStart; 341 var numberEnd = numberStart;
340 while (text[numberEnd] != " " && numberEnd < text.length) 342 while (text[numberEnd] != " " && numberEnd < text.length)
341 ++numberEnd; 343 ++numberEnd;
342 return { 344 return {
343 lineNumber: parseInt(text.substring(numberStart, numberEnd), 10), 345 lineNumber: parseInt(text.substring(numberStart, numberEnd), 10),
344 text: text.from(numberEnd + 1), 346 text: text.from(numberEnd + 1),
345 }; 347 };
346 }; 348 };
OLDNEW
« no previous file with comments | « no previous file | appengine/chromium_rietveld/new_static/model/tests/patch_set_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698