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