| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 1 | // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package com.google.gitiles; |
| 16 | |
| Dave Borowitz | bcd753d | 2013-02-08 11:10:19 -0800 | [diff] [blame] | 17 | import static com.google.common.base.Preconditions.checkNotNull; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 18 | import static com.google.gitiles.TreeSoyData.resolveTargetUrl; |
| 19 | import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR; |
| 20 | import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND; |
| 21 | import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; |
| 22 | import static org.eclipse.jgit.lib.Constants.OBJ_COMMIT; |
| 23 | import static org.eclipse.jgit.lib.Constants.OBJ_TREE; |
| 24 | |
| 25 | import com.google.common.base.Joiner; |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 26 | import com.google.common.collect.ImmutableList; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 27 | import com.google.common.collect.ImmutableMap; |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 28 | import com.google.common.collect.Lists; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 29 | import com.google.common.collect.Maps; |
| Dave Borowitz | 387dd79 | 2014-03-14 20:21:35 -0700 | [diff] [blame] | 30 | import com.google.common.io.BaseEncoding; |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 31 | import com.google.common.primitives.Bytes; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 32 | |
| 33 | import org.eclipse.jgit.errors.ConfigInvalidException; |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 34 | import org.eclipse.jgit.errors.IncorrectObjectTypeException; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 35 | import org.eclipse.jgit.errors.LargeObjectException; |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 36 | import org.eclipse.jgit.errors.MissingObjectException; |
| 37 | import org.eclipse.jgit.errors.StopWalkException; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 38 | import org.eclipse.jgit.http.server.ServletUtils; |
| Shawn Pearce | 73e3453 | 2015-02-12 16:27:54 -0800 | [diff] [blame] | 39 | import org.eclipse.jgit.lib.Config; |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 40 | import org.eclipse.jgit.lib.Constants; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 41 | import org.eclipse.jgit.lib.FileMode; |
| 42 | import org.eclipse.jgit.lib.ObjectId; |
| 43 | import org.eclipse.jgit.lib.ObjectLoader; |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 44 | import org.eclipse.jgit.lib.ObjectReader; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 45 | import org.eclipse.jgit.lib.Repository; |
| 46 | import org.eclipse.jgit.revwalk.RevCommit; |
| 47 | import org.eclipse.jgit.revwalk.RevObject; |
| 48 | import org.eclipse.jgit.revwalk.RevTree; |
| 49 | import org.eclipse.jgit.revwalk.RevWalk; |
| 50 | import org.eclipse.jgit.submodule.SubmoduleWalk; |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 51 | import org.eclipse.jgit.treewalk.CanonicalTreeParser; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 52 | import org.eclipse.jgit.treewalk.TreeWalk; |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 53 | import org.eclipse.jgit.treewalk.filter.TreeFilter; |
| Dave Borowitz | 228f357 | 2014-05-02 14:26:25 -0700 | [diff] [blame] | 54 | import org.eclipse.jgit.util.QuotedString; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 55 | import org.eclipse.jgit.util.RawParseUtils; |
| Han-Wen Nienhuys | 8aefdb8 | 2016-05-02 16:49:35 +0200 | [diff] [blame] | 56 | import org.eclipse.jgit.util.StringUtils; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 57 | import org.slf4j.Logger; |
| 58 | import org.slf4j.LoggerFactory; |
| 59 | |
| 60 | import java.io.IOException; |
| Dave Borowitz | 387dd79 | 2014-03-14 20:21:35 -0700 | [diff] [blame] | 61 | import java.io.OutputStream; |
| Dave Borowitz | 673d198 | 2014-05-02 12:30:49 -0700 | [diff] [blame] | 62 | import java.io.Writer; |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 63 | import java.util.List; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 64 | import java.util.Map; |
| 65 | import java.util.regex.Pattern; |
| 66 | |
| 67 | import javax.servlet.http.HttpServletRequest; |
| 68 | import javax.servlet.http.HttpServletResponse; |
| 69 | |
| 70 | /** Serves an HTML page with detailed information about a path within a tree. */ |
| 71 | // TODO(dborowitz): Handle non-UTF-8 names. |
| 72 | public class PathServlet extends BaseServlet { |
| Chad Horohoe | ad23f14 | 2012-11-12 09:45:39 -0800 | [diff] [blame] | 73 | private static final long serialVersionUID = 1L; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 74 | private static final Logger log = LoggerFactory.getLogger(PathServlet.class); |
| 75 | |
| Dave Borowitz | 4f56870 | 2014-05-01 19:54:57 -0700 | [diff] [blame] | 76 | static final String MODE_HEADER = "X-Gitiles-Path-Mode"; |
| Robert Iannucci | e6dafdf | 2014-10-10 20:54:30 -0700 | [diff] [blame] | 77 | static final String TYPE_HEADER = "X-Gitiles-Object-Type"; |
| Dave Borowitz | 4f56870 | 2014-05-01 19:54:57 -0700 | [diff] [blame] | 78 | |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 79 | /** |
| 80 | * Submodule URLs where we know there is a web page if the user visits the |
| 81 | * repository URL verbatim in a web browser. |
| 82 | */ |
| 83 | private static final Pattern VERBATIM_SUBMODULE_URL_PATTERN = |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 84 | Pattern.compile( |
| 85 | "^(" |
| 86 | + Joiner.on('|') |
| 87 | .join( |
| 88 | "https?://[^.]+.googlesource.com/.*", |
| 89 | "https?://[^.]+.googlecode.com/.*", |
| 90 | "https?://code.google.com/p/.*", |
| 91 | "https?://github.com/.*") |
| 92 | + ")$", |
| 93 | Pattern.CASE_INSENSITIVE); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 94 | |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 95 | static final String AUTODIVE_PARAM = "autodive"; |
| 96 | static final String NO_AUTODIVE_VALUE = "0"; |
| 97 | |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 98 | static enum FileType { |
| 99 | TREE(FileMode.TREE), |
| 100 | SYMLINK(FileMode.SYMLINK), |
| 101 | REGULAR_FILE(FileMode.REGULAR_FILE), |
| 102 | EXECUTABLE_FILE(FileMode.EXECUTABLE_FILE), |
| 103 | GITLINK(FileMode.GITLINK); |
| 104 | |
| 105 | private final FileMode mode; |
| 106 | |
| 107 | private FileType(FileMode mode) { |
| 108 | this.mode = mode; |
| 109 | } |
| 110 | |
| 111 | static FileType forEntry(TreeWalk tw) { |
| 112 | int mode = tw.getRawMode(0); |
| 113 | for (FileType type : values()) { |
| 114 | if (type.mode.equals(mode)) { |
| 115 | return type; |
| 116 | } |
| 117 | } |
| 118 | return null; |
| 119 | } |
| 120 | } |
| 121 | |
| Dave Borowitz | bcd753d | 2013-02-08 11:10:19 -0800 | [diff] [blame] | 122 | private final GitilesUrls urls; |
| 123 | |
| Dave Borowitz | ded109a | 2014-03-03 15:25:39 -0500 | [diff] [blame] | 124 | public PathServlet(GitilesAccess.Factory accessFactory, Renderer renderer, GitilesUrls urls) { |
| Dave Borowitz | 8d6d687 | 2014-03-16 15:18:14 -0700 | [diff] [blame] | 125 | super(renderer, accessFactory); |
| Dave Borowitz | bcd753d | 2013-02-08 11:10:19 -0800 | [diff] [blame] | 126 | this.urls = checkNotNull(urls, "urls"); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | @Override |
| Dave Borowitz | 387dd79 | 2014-03-14 20:21:35 -0700 | [diff] [blame] | 130 | protected void doGetHtml(HttpServletRequest req, HttpServletResponse res) throws IOException { |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 131 | GitilesView view = ViewFilter.getView(req); |
| 132 | Repository repo = ServletUtils.getRepository(req); |
| 133 | |
| Shawn Pearce | b5ad0a0 | 2015-05-24 20:33:17 -0700 | [diff] [blame] | 134 | try (RevWalk rw = new RevWalk(repo); |
| Han-Wen Nienhuys | 0dc9387 | 2016-05-03 15:21:42 +0200 | [diff] [blame] | 135 | WalkResult wr = WalkResult.forPath(rw, view, false)) { |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 136 | if (wr == null) { |
| 137 | res.setStatus(SC_NOT_FOUND); |
| 138 | return; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 139 | } |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 140 | switch (wr.type) { |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 141 | case TREE: |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 142 | showTree(req, res, wr); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 143 | break; |
| 144 | case SYMLINK: |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 145 | showSymlink(req, res, wr); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 146 | break; |
| 147 | case REGULAR_FILE: |
| 148 | case EXECUTABLE_FILE: |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 149 | showFile(req, res, wr); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 150 | break; |
| 151 | case GITLINK: |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 152 | showGitlink(req, res, wr); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 153 | break; |
| 154 | default: |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 155 | log.error("Bad file type: {}", wr.type); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 156 | res.setStatus(SC_NOT_FOUND); |
| 157 | break; |
| 158 | } |
| 159 | } catch (LargeObjectException e) { |
| 160 | res.setStatus(SC_INTERNAL_SERVER_ERROR); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | |
| Dave Borowitz | 387dd79 | 2014-03-14 20:21:35 -0700 | [diff] [blame] | 164 | @Override |
| 165 | protected void doGetText(HttpServletRequest req, HttpServletResponse res) throws IOException { |
| 166 | GitilesView view = ViewFilter.getView(req); |
| 167 | Repository repo = ServletUtils.getRepository(req); |
| 168 | |
| Shawn Pearce | b5ad0a0 | 2015-05-24 20:33:17 -0700 | [diff] [blame] | 169 | try (RevWalk rw = new RevWalk(repo); |
| Han-Wen Nienhuys | 0dc9387 | 2016-05-03 15:21:42 +0200 | [diff] [blame] | 170 | WalkResult wr = WalkResult.forPath(rw, view, false)) { |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 171 | if (wr == null) { |
| Dave Borowitz | 387dd79 | 2014-03-14 20:21:35 -0700 | [diff] [blame] | 172 | res.setStatus(SC_NOT_FOUND); |
| 173 | return; |
| 174 | } |
| 175 | |
| Dave Borowitz | 228f357 | 2014-05-02 14:26:25 -0700 | [diff] [blame] | 176 | // Write base64 as plain text without modifying any other headers, under |
| 177 | // the assumption that any hint we can give to a browser that this is |
| 178 | // base64 data might cause it to try to decode it and render as HTML, |
| 179 | // which would be bad. |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 180 | switch (wr.type) { |
| Dave Borowitz | 387dd79 | 2014-03-14 20:21:35 -0700 | [diff] [blame] | 181 | case SYMLINK: |
| 182 | case REGULAR_FILE: |
| 183 | case EXECUTABLE_FILE: |
| Dave Borowitz | 228f357 | 2014-05-02 14:26:25 -0700 | [diff] [blame] | 184 | writeBlobText(req, res, wr); |
| 185 | break; |
| 186 | case TREE: |
| 187 | writeTreeText(req, res, wr); |
| Dave Borowitz | 679210d | 2014-03-17 15:27:43 -0700 | [diff] [blame] | 188 | break; |
| Dave Borowitz | 387dd79 | 2014-03-14 20:21:35 -0700 | [diff] [blame] | 189 | default: |
| 190 | renderTextError(req, res, SC_NOT_FOUND, "Not a file"); |
| 191 | break; |
| 192 | } |
| 193 | } catch (LargeObjectException e) { |
| 194 | res.setStatus(SC_INTERNAL_SERVER_ERROR); |
| Dave Borowitz | 387dd79 | 2014-03-14 20:21:35 -0700 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
| Robert Iannucci | e6dafdf | 2014-10-10 20:54:30 -0700 | [diff] [blame] | 198 | public static void setModeHeader(HttpServletResponse res, FileType type) { |
| Dave Borowitz | 228f357 | 2014-05-02 14:26:25 -0700 | [diff] [blame] | 199 | res.setHeader(MODE_HEADER, String.format("%06o", type.mode.getBits())); |
| 200 | } |
| 201 | |
| Robert Iannucci | e6dafdf | 2014-10-10 20:54:30 -0700 | [diff] [blame] | 202 | public static void setTypeHeader(HttpServletResponse res, int type) { |
| 203 | res.setHeader(TYPE_HEADER, Constants.typeString(type)); |
| 204 | } |
| 205 | |
| Dave Borowitz | 228f357 | 2014-05-02 14:26:25 -0700 | [diff] [blame] | 206 | private void writeBlobText(HttpServletRequest req, HttpServletResponse res, WalkResult wr) |
| 207 | throws IOException { |
| Robert Iannucci | e6dafdf | 2014-10-10 20:54:30 -0700 | [diff] [blame] | 208 | setTypeHeader(res, wr.type.mode.getObjectType()); |
| Dave Borowitz | 228f357 | 2014-05-02 14:26:25 -0700 | [diff] [blame] | 209 | setModeHeader(res, wr.type); |
| Shawn Pearce | ade620c | 2014-08-27 15:52:08 -0700 | [diff] [blame] | 210 | try (Writer writer = startRenderText(req, res); |
| Dave Borowitz | 228f357 | 2014-05-02 14:26:25 -0700 | [diff] [blame] | 211 | OutputStream out = BaseEncoding.base64().encodingStream(writer)) { |
| 212 | wr.getObjectReader().open(wr.id).copyTo(out); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | private void writeTreeText(HttpServletRequest req, HttpServletResponse res, WalkResult wr) |
| 217 | throws IOException { |
| Robert Iannucci | e6dafdf | 2014-10-10 20:54:30 -0700 | [diff] [blame] | 218 | setTypeHeader(res, wr.type.mode.getObjectType()); |
| Dave Borowitz | 228f357 | 2014-05-02 14:26:25 -0700 | [diff] [blame] | 219 | setModeHeader(res, wr.type); |
| 220 | |
| Shawn Pearce | ade620c | 2014-08-27 15:52:08 -0700 | [diff] [blame] | 221 | try (Writer writer = startRenderText(req, res); |
| Dave Borowitz | 228f357 | 2014-05-02 14:26:25 -0700 | [diff] [blame] | 222 | OutputStream out = BaseEncoding.base64().encodingStream(writer)) { |
| 223 | // Match git ls-tree format. |
| 224 | while (wr.tw.next()) { |
| 225 | FileMode mode = wr.tw.getFileMode(0); |
| 226 | out.write(Constants.encode(String.format("%06o", mode.getBits()))); |
| 227 | out.write(' '); |
| 228 | out.write(Constants.encode(Constants.typeString(mode.getObjectType()))); |
| 229 | out.write(' '); |
| 230 | wr.tw.getObjectId(0).copyTo(out); |
| 231 | out.write('\t'); |
| 232 | out.write(Constants.encode(QuotedString.GIT_PATH.quote(wr.tw.getNameString()))); |
| 233 | out.write('\n'); |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | |
| Dave Borowitz | 2387b14 | 2014-05-02 16:56:27 -0700 | [diff] [blame] | 238 | @Override |
| 239 | protected void doGetJson(HttpServletRequest req, HttpServletResponse res) throws IOException { |
| 240 | GitilesView view = ViewFilter.getView(req); |
| 241 | Repository repo = ServletUtils.getRepository(req); |
| 242 | |
| Han-Wen Nienhuys | 8aefdb8 | 2016-05-02 16:49:35 +0200 | [diff] [blame] | 243 | String longStr = req.getParameter("long"); |
| 244 | boolean includeSizes = |
| 245 | (longStr != null) |
| 246 | && (longStr.isEmpty() || Boolean.TRUE.equals(StringUtils.toBooleanOrNull(longStr))); |
| 247 | |
| Han-Wen Nienhuys | 0dc9387 | 2016-05-03 15:21:42 +0200 | [diff] [blame] | 248 | String recursiveStr = req.getParameter("recursive"); |
| 249 | boolean recursive = |
| 250 | (recursiveStr != null) |
| 251 | && (recursiveStr.isEmpty() |
| 252 | || Boolean.TRUE.equals(StringUtils.toBooleanOrNull(recursiveStr))); |
| 253 | |
| Shawn Pearce | b5ad0a0 | 2015-05-24 20:33:17 -0700 | [diff] [blame] | 254 | try (RevWalk rw = new RevWalk(repo); |
| Han-Wen Nienhuys | 0dc9387 | 2016-05-03 15:21:42 +0200 | [diff] [blame] | 255 | WalkResult wr = WalkResult.forPath(rw, view, recursive)) { |
| Dave Borowitz | 2387b14 | 2014-05-02 16:56:27 -0700 | [diff] [blame] | 256 | if (wr == null) { |
| 257 | res.setStatus(SC_NOT_FOUND); |
| 258 | return; |
| 259 | } |
| 260 | switch (wr.type) { |
| 261 | case TREE: |
| Han-Wen Nienhuys | 8aefdb8 | 2016-05-02 16:49:35 +0200 | [diff] [blame] | 262 | renderJson( |
| 263 | req, |
| 264 | res, |
| Han-Wen Nienhuys | 0dc9387 | 2016-05-03 15:21:42 +0200 | [diff] [blame] | 265 | TreeJsonData.toJsonData(wr.id, wr.tw, includeSizes, recursive), |
| Han-Wen Nienhuys | 8aefdb8 | 2016-05-02 16:49:35 +0200 | [diff] [blame] | 266 | TreeJsonData.Tree.class); |
| Dave Borowitz | 2387b14 | 2014-05-02 16:56:27 -0700 | [diff] [blame] | 267 | break; |
| 268 | default: |
| 269 | res.setStatus(SC_NOT_FOUND); |
| 270 | break; |
| 271 | } |
| 272 | } catch (LargeObjectException e) { |
| 273 | res.setStatus(SC_INTERNAL_SERVER_ERROR); |
| Dave Borowitz | 2387b14 | 2014-05-02 16:56:27 -0700 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | |
| Dave Borowitz | 387dd79 | 2014-03-14 20:21:35 -0700 | [diff] [blame] | 277 | private static RevTree getRoot(GitilesView view, RevWalk rw) throws IOException { |
| 278 | RevObject obj = rw.peel(rw.parseAny(view.getRevision().getId())); |
| 279 | switch (obj.getType()) { |
| 280 | case OBJ_COMMIT: |
| 281 | return ((RevCommit) obj).getTree(); |
| 282 | case OBJ_TREE: |
| 283 | return (RevTree) obj; |
| 284 | default: |
| 285 | return null; |
| 286 | } |
| 287 | } |
| 288 | |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 289 | private static class AutoDiveFilter extends TreeFilter { |
| Dave Borowitz | 33d4fda | 2013-10-22 16:40:20 -0700 | [diff] [blame] | 290 | /** @see GitilesView#getBreadcrumbs(List) */ |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 291 | List<Boolean> hasSingleTree; |
| 292 | |
| 293 | private final byte[] pathRaw; |
| 294 | private int count; |
| 295 | private boolean done; |
| 296 | |
| 297 | AutoDiveFilter(String pathStr) { |
| 298 | hasSingleTree = Lists.newArrayList(); |
| 299 | pathRaw = Constants.encode(pathStr); |
| 300 | } |
| 301 | |
| 302 | @Override |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 303 | public boolean include(TreeWalk tw) |
| 304 | throws MissingObjectException, IncorrectObjectTypeException, IOException { |
| Han-Wen Nienhuys | 0dc9387 | 2016-05-03 15:21:42 +0200 | [diff] [blame] | 305 | |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 306 | count++; |
| 307 | int cmp = tw.isPathPrefix(pathRaw, pathRaw.length); |
| 308 | if (cmp > 0) { |
| 309 | throw StopWalkException.INSTANCE; |
| 310 | } |
| 311 | boolean include; |
| 312 | if (cmp == 0) { |
| 313 | if (!isDone(tw)) { |
| 314 | hasSingleTree.add(hasSingleTreeEntry(tw)); |
| 315 | } |
| 316 | include = true; |
| 317 | } else { |
| 318 | include = false; |
| 319 | } |
| 320 | if (tw.isSubtree()) { |
| 321 | count = 0; |
| 322 | } |
| 323 | return include; |
| 324 | } |
| 325 | |
| 326 | private boolean hasSingleTreeEntry(TreeWalk tw) throws IOException { |
| 327 | if (count != 1 || !FileMode.TREE.equals(tw.getRawMode(0))) { |
| 328 | return false; |
| 329 | } |
| 330 | CanonicalTreeParser p = new CanonicalTreeParser(); |
| 331 | p.reset(tw.getObjectReader(), tw.getObjectId(0)); |
| 332 | p.next(); |
| 333 | return p.eof(); |
| 334 | } |
| 335 | |
| 336 | @Override |
| 337 | public boolean shouldBeRecursive() { |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 338 | return Bytes.indexOf(pathRaw, (byte) '/') >= 0; |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | @Override |
| 342 | public TreeFilter clone() { |
| 343 | return this; |
| 344 | } |
| 345 | |
| 346 | private boolean isDone(TreeWalk tw) { |
| 347 | if (!done) { |
| 348 | done = pathRaw.length == tw.getPathLength(); |
| 349 | } |
| 350 | return done; |
| 351 | } |
| 352 | } |
| 353 | |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 354 | /** |
| 355 | * Encapsulate the result of walking to a single tree. |
| 356 | * <p> |
| 357 | * Unlike {@link TreeWalk} itself, supports positioning at the root tree. |
| 358 | * Includes information to help the auto-dive routine as well. |
| 359 | */ |
| Shawn Pearce | b5ad0a0 | 2015-05-24 20:33:17 -0700 | [diff] [blame] | 360 | private static class WalkResult implements AutoCloseable { |
| Han-Wen Nienhuys | 0dc9387 | 2016-05-03 15:21:42 +0200 | [diff] [blame] | 361 | private static WalkResult recursivePath(RevWalk rw, GitilesView view) throws IOException { |
| 362 | RevTree root = getRoot(view, rw); |
| 363 | String path = view.getPathPart(); |
| 364 | |
| 365 | TreeWalk tw; |
| 366 | if (!path.isEmpty()) { |
| 367 | try (TreeWalk toRoot = TreeWalk.forPath(rw.getObjectReader(), path, root)) { |
| 368 | if (toRoot == null) { |
| 369 | return null; |
| 370 | } |
| 371 | |
| 372 | ObjectId treeSHA = toRoot.getObjectId(0); |
| 373 | |
| 374 | ObjectLoader treeLoader = rw.getObjectReader().open(treeSHA); |
| 375 | if (treeLoader.getType() != Constants.OBJ_TREE) { |
| 376 | return null; |
| 377 | } |
| 378 | |
| 379 | tw = new TreeWalk(rw.getObjectReader()); |
| 380 | tw.addTree(treeSHA); |
| 381 | } |
| 382 | } else { |
| 383 | tw = new TreeWalk(rw.getObjectReader()); |
| 384 | tw.addTree(root); |
| 385 | } |
| 386 | |
| 387 | tw.setRecursive(true); |
| 388 | return new WalkResult(tw, path, root, root, FileType.TREE, ImmutableList.<Boolean>of()); |
| 389 | } |
| 390 | |
| 391 | private static WalkResult forPath(RevWalk rw, GitilesView view, boolean recursive) |
| 392 | throws IOException { |
| 393 | if (recursive) { |
| 394 | return recursivePath(rw, view); |
| 395 | } |
| 396 | |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 397 | RevTree root = getRoot(view, rw); |
| 398 | String path = view.getPathPart(); |
| 399 | TreeWalk tw = new TreeWalk(rw.getObjectReader()); |
| 400 | try { |
| 401 | tw.addTree(root); |
| 402 | tw.setRecursive(false); |
| 403 | if (path.isEmpty()) { |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 404 | return new WalkResult(tw, path, root, root, FileType.TREE, ImmutableList.<Boolean>of()); |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 405 | } |
| 406 | AutoDiveFilter f = new AutoDiveFilter(path); |
| 407 | tw.setFilter(f); |
| 408 | while (tw.next()) { |
| 409 | if (f.isDone(tw)) { |
| 410 | FileType type = FileType.forEntry(tw); |
| 411 | ObjectId id = tw.getObjectId(0); |
| 412 | if (type == FileType.TREE) { |
| 413 | tw.enterSubtree(); |
| 414 | tw.setRecursive(false); |
| 415 | } |
| 416 | return new WalkResult(tw, path, root, id, type, f.hasSingleTree); |
| 417 | } else if (tw.isSubtree()) { |
| 418 | tw.enterSubtree(); |
| 419 | } |
| 420 | } |
| 421 | } catch (IOException | RuntimeException e) { |
| 422 | // Fallthrough. |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 423 | } |
| Shawn Pearce | b5ad0a0 | 2015-05-24 20:33:17 -0700 | [diff] [blame] | 424 | tw.close(); |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 425 | return null; |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 426 | } |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 427 | |
| 428 | private final TreeWalk tw; |
| 429 | private final String path; |
| 430 | private final RevTree root; |
| 431 | private final ObjectId id; |
| 432 | private final FileType type; |
| 433 | private final List<Boolean> hasSingleTree; |
| 434 | |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 435 | private WalkResult( |
| 436 | TreeWalk tw, |
| 437 | String path, |
| 438 | RevTree root, |
| 439 | ObjectId objectId, |
| 440 | FileType type, |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 441 | List<Boolean> hasSingleTree) { |
| 442 | this.tw = tw; |
| 443 | this.path = path; |
| 444 | this.root = root; |
| 445 | this.id = objectId; |
| 446 | this.type = type; |
| 447 | this.hasSingleTree = hasSingleTree; |
| 448 | } |
| 449 | |
| 450 | private ObjectReader getObjectReader() { |
| 451 | return tw.getObjectReader(); |
| 452 | } |
| 453 | |
| Shawn Pearce | b5ad0a0 | 2015-05-24 20:33:17 -0700 | [diff] [blame] | 454 | @Override |
| 455 | public void close() { |
| 456 | tw.close(); |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 457 | } |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 458 | } |
| 459 | |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 460 | private void showTree(HttpServletRequest req, HttpServletResponse res, WalkResult wr) |
| 461 | throws IOException { |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 462 | GitilesView view = ViewFilter.getView(req); |
| Shawn Pearce | 73e3453 | 2015-02-12 16:27:54 -0800 | [diff] [blame] | 463 | Config cfg = getAccess(req).getConfig(); |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 464 | List<String> autodive = view.getParameters().get(AUTODIVE_PARAM); |
| 465 | if (autodive.size() != 1 || !NO_AUTODIVE_VALUE.equals(autodive.get(0))) { |
| Dave Borowitz | dd3c3d9 | 2013-03-11 16:38:41 -0700 | [diff] [blame] | 466 | byte[] path = Constants.encode(view.getPathPart()); |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 467 | ObjectReader reader = wr.getObjectReader(); |
| 468 | CanonicalTreeParser child = getOnlyChildSubtree(reader, wr.id, path); |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 469 | if (child != null) { |
| 470 | while (true) { |
| 471 | path = new byte[child.getEntryPathLength()]; |
| 472 | System.arraycopy(child.getEntryPathBuffer(), 0, path, 0, child.getEntryPathLength()); |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 473 | CanonicalTreeParser next = getOnlyChildSubtree(reader, child.getEntryObjectId(), path); |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 474 | if (next == null) { |
| 475 | break; |
| 476 | } |
| 477 | child = next; |
| 478 | } |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 479 | res.sendRedirect( |
| 480 | GitilesView.path() |
| 481 | .copyFrom(view) |
| 482 | .setPathPart( |
| 483 | RawParseUtils.decode(child.getEntryPathBuffer(), 0, child.getEntryPathLength())) |
| 484 | .toUrl()); |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 485 | return; |
| 486 | } |
| 487 | } |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 488 | // TODO(sop): Allow caching trees by SHA-1 when no S cookie is sent. |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 489 | renderHtml( |
| 490 | req, |
| 491 | res, |
| 492 | "gitiles.pathDetail", |
| 493 | ImmutableMap.of( |
| 494 | "title", !view.getPathPart().isEmpty() ? view.getPathPart() : "/", |
| 495 | "breadcrumbs", view.getBreadcrumbs(wr.hasSingleTree), |
| 496 | "type", FileType.TREE.toString(), |
| 497 | "data", |
| Shawn Pearce | c68ad0b | 2016-05-28 16:52:47 -0700 | [diff] [blame] | 498 | new TreeSoyData(wr.getObjectReader(), view, cfg, wr.root, req.getRequestURI()) |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 499 | .setArchiveFormat(getArchiveFormat(getAccess(req))) |
| 500 | .toSoyData(wr.id, wr.tw))); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 503 | private CanonicalTreeParser getOnlyChildSubtree(ObjectReader reader, ObjectId id, byte[] prefix) |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 504 | throws IOException { |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 505 | CanonicalTreeParser p = new CanonicalTreeParser(prefix, reader, id); |
| Dave Borowitz | 4e8ffd8 | 2012-12-26 16:01:06 -0800 | [diff] [blame] | 506 | if (p.eof() || p.getEntryFileMode() != FileMode.TREE) { |
| 507 | return null; |
| 508 | } |
| 509 | p.next(1); |
| 510 | return p.eof() ? p : null; |
| 511 | } |
| 512 | |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 513 | private void showFile(HttpServletRequest req, HttpServletResponse res, WalkResult wr) |
| 514 | throws IOException { |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 515 | GitilesView view = ViewFilter.getView(req); |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 516 | Map<String, ?> data = new BlobSoyData(wr.getObjectReader(), view).toSoyData(wr.path, wr.id); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 517 | // TODO(sop): Allow caching files by SHA-1 when no S cookie is sent. |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 518 | renderHtml( |
| 519 | req, |
| 520 | res, |
| 521 | "gitiles.pathDetail", |
| 522 | ImmutableMap.of( |
| 523 | "title", ViewFilter.getView(req).getPathPart(), |
| 524 | "breadcrumbs", view.getBreadcrumbs(wr.hasSingleTree), |
| 525 | "type", wr.type.toString(), |
| 526 | "data", data)); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 529 | private void showSymlink(HttpServletRequest req, HttpServletResponse res, WalkResult wr) |
| 530 | throws IOException { |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 531 | GitilesView view = ViewFilter.getView(req); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 532 | Map<String, Object> data = Maps.newHashMap(); |
| 533 | |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 534 | ObjectLoader loader = wr.getObjectReader().open(wr.id, OBJ_BLOB); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 535 | String target; |
| 536 | try { |
| 537 | target = RawParseUtils.decode(loader.getCachedBytes(TreeSoyData.MAX_SYMLINK_SIZE)); |
| 538 | } catch (LargeObjectException.OutOfMemory e) { |
| 539 | throw e; |
| 540 | } catch (LargeObjectException e) { |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 541 | data.put("sha", ObjectId.toString(wr.id)); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 542 | data.put("data", null); |
| 543 | data.put("size", Long.toString(loader.getSize())); |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 544 | renderHtml( |
| 545 | req, |
| 546 | res, |
| 547 | "gitiles.pathDetail", |
| 548 | ImmutableMap.of( |
| 549 | "title", ViewFilter.getView(req).getPathPart(), |
| 550 | "breadcrumbs", view.getBreadcrumbs(wr.hasSingleTree), |
| 551 | "type", FileType.REGULAR_FILE.toString(), |
| 552 | "data", data)); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 553 | return; |
| 554 | } |
| 555 | |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 556 | String url = |
| 557 | resolveTargetUrl( |
| 558 | GitilesView.path().copyFrom(view).setPathPart(dirname(view.getPathPart())).build(), |
| 559 | target); |
| Dave Borowitz | dd3c3d9 | 2013-03-11 16:38:41 -0700 | [diff] [blame] | 560 | data.put("title", view.getPathPart()); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 561 | data.put("target", target); |
| 562 | if (url != null) { |
| 563 | data.put("targetUrl", url); |
| 564 | } |
| 565 | |
| 566 | // TODO(sop): Allow caching files by SHA-1 when no S cookie is sent. |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 567 | renderHtml( |
| 568 | req, |
| 569 | res, |
| 570 | "gitiles.pathDetail", |
| 571 | ImmutableMap.of( |
| 572 | "title", ViewFilter.getView(req).getPathPart(), |
| 573 | "breadcrumbs", view.getBreadcrumbs(wr.hasSingleTree), |
| 574 | "type", FileType.SYMLINK.toString(), |
| 575 | "data", data)); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | private static String dirname(String path) { |
| 579 | while (path.charAt(path.length() - 1) == '/') { |
| 580 | path = path.substring(0, path.length() - 1); |
| 581 | } |
| 582 | int lastSlash = path.lastIndexOf('/'); |
| 583 | if (lastSlash > 0) { |
| 584 | return path.substring(0, lastSlash - 1); |
| 585 | } else if (lastSlash == 0) { |
| 586 | return "/"; |
| 587 | } else { |
| 588 | return "."; |
| 589 | } |
| 590 | } |
| 591 | |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 592 | private void showGitlink(HttpServletRequest req, HttpServletResponse res, WalkResult wr) |
| 593 | throws IOException { |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 594 | GitilesView view = ViewFilter.getView(req); |
| Dave Borowitz | bcd753d | 2013-02-08 11:10:19 -0800 | [diff] [blame] | 595 | String modulesUrl; |
| 596 | String remoteUrl = null; |
| Shawn Pearce | b5ad0a0 | 2015-05-24 20:33:17 -0700 | [diff] [blame] | 597 | |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 598 | try (SubmoduleWalk sw = |
| 599 | SubmoduleWalk.forPath(ServletUtils.getRepository(req), wr.root, view.getPathPart())) { |
| Dave Borowitz | bcd753d | 2013-02-08 11:10:19 -0800 | [diff] [blame] | 600 | modulesUrl = sw.getModulesUrl(); |
| 601 | if (modulesUrl != null && (modulesUrl.startsWith("./") || modulesUrl.startsWith("../"))) { |
| Dave Borowitz | cfc1c53 | 2015-02-18 13:41:19 -0800 | [diff] [blame] | 602 | String moduleRepo = PathUtil.simplifyPathUpToRoot(modulesUrl, view.getRepositoryName()); |
| Dave Borowitz | bcd753d | 2013-02-08 11:10:19 -0800 | [diff] [blame] | 603 | if (moduleRepo != null) { |
| 604 | modulesUrl = urls.getBaseGitUrl(req) + moduleRepo; |
| 605 | } |
| 606 | } else { |
| 607 | remoteUrl = sw.getRemoteUrl(); |
| 608 | } |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 609 | } catch (ConfigInvalidException e) { |
| 610 | throw new IOException(e); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | Map<String, Object> data = Maps.newHashMap(); |
| Dave Borowitz | 7c0a833 | 2014-05-01 11:07:04 -0700 | [diff] [blame] | 614 | data.put("sha", ObjectId.toString(wr.id)); |
| Dave Borowitz | bcd753d | 2013-02-08 11:10:19 -0800 | [diff] [blame] | 615 | data.put("remoteUrl", remoteUrl != null ? remoteUrl : modulesUrl); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 616 | |
| Dave Borowitz | bcd753d | 2013-02-08 11:10:19 -0800 | [diff] [blame] | 617 | // TODO(dborowitz): Guess when we can put commit SHAs in the URL. |
| 618 | String httpUrl = resolveHttpUrl(remoteUrl); |
| 619 | if (httpUrl != null) { |
| 620 | data.put("httpUrl", httpUrl); |
| 621 | } |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 622 | |
| Dave Borowitz | bcd753d | 2013-02-08 11:10:19 -0800 | [diff] [blame] | 623 | // TODO(sop): Allow caching links by SHA-1 when no S cookie is sent. |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 624 | renderHtml( |
| 625 | req, |
| 626 | res, |
| 627 | "gitiles.pathDetail", |
| 628 | ImmutableMap.of( |
| 629 | "title", view.getPathPart(), |
| 630 | "type", FileType.GITLINK.toString(), |
| 631 | "data", data)); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | private static String resolveHttpUrl(String remoteUrl) { |
| Dave Borowitz | bcd753d | 2013-02-08 11:10:19 -0800 | [diff] [blame] | 635 | if (remoteUrl == null) { |
| 636 | return null; |
| 637 | } |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 638 | return VERBATIM_SUBMODULE_URL_PATTERN.matcher(remoteUrl).matches() ? remoteUrl : null; |
| 639 | } |
| 640 | } |