blob: 2ccae2c8cd40cc72fb0f066a20da5763a0405b7f [file] [log] [blame]
<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script>
(function(window) {
'use strict';
/** @polymerBehavior Gerrit.PathListBehavior */
const PathListBehavior = {
specialFilePathCompare(a, b) {
// The commit message always goes first.
const COMMIT_MESSAGE_PATH = '/COMMIT_MSG';
if (a === COMMIT_MESSAGE_PATH) {
return -1;
}
if (b === COMMIT_MESSAGE_PATH) {
return 1;
}
// The merge list always comes next.
const MERGE_LIST_PATH = '/MERGE_LIST';
if (a === MERGE_LIST_PATH) {
return -1;
}
if (b === MERGE_LIST_PATH) {
return 1;
}
const aLastDotIndex = a.lastIndexOf('.');
const aExt = a.substr(aLastDotIndex + 1);
const aFile = a.substr(0, aLastDotIndex) || a;
const bLastDotIndex = b.lastIndexOf('.');
const bExt = b.substr(bLastDotIndex + 1);
const bFile = b.substr(0, bLastDotIndex) || b;
// Sort header files above others with the same base name.
const headerExts = ['h', 'hxx', 'hpp'];
if (aFile.length > 0 && aFile === bFile) {
if (headerExts.includes(aExt) && headerExts.includes(bExt)) {
return a.localeCompare(b);
}
if (headerExts.includes(aExt)) {
return -1;
}
if (headerExts.includes(bExt)) {
return 1;
}
}
return aFile.localeCompare(bFile) || a.localeCompare(b);
},
};
window.Gerrit = window.Gerrit || {};
window.Gerrit.PathListBehavior = PathListBehavior;
})(window);
</script>