Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 var fs = require("fs"); | 4 var fs = require("fs"); |
| 5 var http = require("http"); | 5 var http = require("http"); |
| 6 var path = require("path"); | 6 var path = require("path"); |
| 7 var parseURL = require("url").parse; | 7 var parseURL = require("url").parse; |
| 8 | 8 |
| 9 var utils = require("../utils"); | 9 var utils = require("../utils"); |
| 10 | 10 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 var commitHash = match[1]; | 109 var commitHash = match[1]; |
| 110 var proxyFileURL = proxyFilePathToURL[filePath](commitHash); | 110 var proxyFileURL = proxyFilePathToURL[filePath](commitHash); |
| 111 return proxyFileURL; | 111 return proxyFileURL; |
| 112 } | 112 } |
| 113 | 113 |
| 114 function onProxyFileURL(proxyFileURL) | 114 function onProxyFileURL(proxyFileURL) |
| 115 { | 115 { |
| 116 if (proxyFileCache.has(proxyFileURL)) | 116 if (proxyFileCache.has(proxyFileURL)) |
| 117 return Promise.resolve(proxyFileCache.get(proxyFileURL)); | 117 return Promise.resolve(proxyFileCache.get(proxyFileURL)); |
| 118 return utils.fetch(proxyFileURL) | 118 return utils.fetch(proxyFileURL) |
| 119 .then(cacheProxyFile.bind(null, proxyFileURL)); | 119 .then(cacheProxyFile.bind(null, proxyFileURL)) |
| 120 .catch(onMissingFile); | |
| 121 } | |
| 122 | |
| 123 function onMissingFile() { | |
| 124 var isFullCheckout = utils.shellOutput("git config --get remote.origin.u rl") === "https://chromium.googlesource.com/chromium/src.git"; | |
| 125 var earlierCommitHash; | |
| 126 var gitLogCommand = `git log --max-count=1 --grep="Cr-Commit-Position" - -before="12 hours ago"`; | |
| 127 if (isFullCheckout) { | |
| 128 earlierCommitHash = utils.shellOutput(`${gitLogCommand} --pretty=for mat:"%H"`); | |
| 129 } else { | |
| 130 var commitMessage = utils.shellOutput(`${gitLogCommand}`); | |
| 131 earlierCommitHash = commitMessage.match(/Cr-Mirrored-Commit: (.*)/)[ 1]; | |
|
lushnikov
2016/11/14 22:24:34
can we use this codepath for both full and github
chenwilliam
2016/11/14 23:47:30
unfortunately we can't, because "Cr-Mirrored-Commi
| |
| 132 } | |
| 133 var fallbackURL = proxyFilePathToURL[filePath](earlierCommitHash); | |
| 134 console.log("WARNING: Unable to fetch generated file based on browser's revision"); | |
| 135 console.log("Fetching earlier revision of same file as fallback"); | |
| 136 console.log("There may be a mismatch between the front-end and back-end" ); | |
| 137 console.log(fallbackURL, "\n"); | |
| 138 return utils.fetch(fallbackURL) | |
| 139 .then(cacheProxyFile.bind(null, fallbackURL)); | |
| 120 } | 140 } |
| 121 | 141 |
| 122 function cacheProxyFile(proxyFileURL, data) | 142 function cacheProxyFile(proxyFileURL, data) |
| 123 { | 143 { |
| 124 proxyFileCache.set(proxyFileURL, data); | 144 proxyFileCache.set(proxyFileURL, data); |
| 125 return data; | 145 return data; |
| 126 } | 146 } |
| 127 } | 147 } |
| OLD | NEW |