1 | var utils = require("../utils");
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | function FilesContainer(logger) {
|
7 | this.logger = logger;
|
8 | this.partialToGitMap = {};
|
9 | }
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | FilesContainer.prototype.addFile = function(scmFile) {
|
21 | scmFile = utils.adjustPathSlashes(scmFile);
|
22 | var parts = scmFile.split("/");
|
23 | for (var i = parts.length; i > 0; i--) {
|
24 | var partsToSlice = parts.length - i;
|
25 | var key = parts.slice(partsToSlice).join("/");
|
26 | this.partialToGitMap[key] = this.partialToGitMap[key] || [];
|
27 | this.partialToGitMap[key].push(scmFile);
|
28 | }
|
29 | };
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | FilesContainer.prototype.getScmPath = function(partialPath){
|
38 | partialPath = utils.adjustPathSlashes(partialPath);
|
39 | var parts = partialPath.split("/");
|
40 | for (var i = parts.length; i > 0; i--) {
|
41 | var partsToSice = parts.length - i;
|
42 | var key = parts.slice(partsToSice).join("/");
|
43 | var gitPathArr = this.partialToGitMap[key];
|
44 | if(gitPathArr && gitPathArr.length === 1){
|
45 | break;
|
46 | }
|
47 | }
|
48 | if(gitPathArr == null){
|
49 | this.logger.warn(partialPath + " has no match to any git file, consider using SL_sourceRoot");
|
50 | return null;
|
51 | }
|
52 | return gitPathArr;
|
53 | }
|
54 | module.exports = FilesContainer; |
\ | No newline at end of file |