| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [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 | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 17 | import static com.google.gitiles.TestGitilesUrls.URLS; |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 18 | import static org.junit.Assert.assertEquals; |
| Dave Borowitz | 32ec5b9 | 2014-07-30 07:43:28 -0700 | [diff] [blame] | 19 | import static org.junit.Assert.assertNull; |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 20 | import static org.junit.Assert.assertTrue; |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 21 | |
| Dave Borowitz | 32ec5b9 | 2014-07-30 07:43:28 -0700 | [diff] [blame] | 22 | import com.google.common.collect.ImmutableList; |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 23 | import com.google.common.collect.ImmutableMap; |
| Dave Borowitz | 32ec5b9 | 2014-07-30 07:43:28 -0700 | [diff] [blame] | 24 | import com.google.common.net.HttpHeaders; |
| 25 | import com.google.gitiles.RefServlet.RefJsonData; |
| 26 | import com.google.gson.Gson; |
| 27 | import com.google.gson.reflect.TypeToken; |
| 28 | |
| Shawn Pearce | b43b2d5 | 2013-03-18 10:55:15 -0700 | [diff] [blame] | 29 | import org.eclipse.jgit.internal.storage.dfs.DfsRepository; |
| 30 | import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription; |
| 31 | import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository; |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 32 | import org.eclipse.jgit.junit.TestRepository; |
| 33 | import org.eclipse.jgit.lib.ObjectId; |
| 34 | import org.eclipse.jgit.lib.Repository; |
| 35 | import org.eclipse.jgit.revwalk.RevCommit; |
| 36 | import org.eclipse.jgit.revwalk.RevTag; |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 37 | import org.eclipse.jgit.revwalk.RevWalk; |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 38 | import org.junit.Before; |
| 39 | import org.junit.Test; |
| Dave Borowitz | 3dc854f | 2014-11-04 16:19:37 -0800 | [diff] [blame] | 40 | import org.junit.runner.RunWith; |
| 41 | import org.junit.runners.JUnit4; |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 42 | |
| 43 | import java.io.IOException; |
| Dave Borowitz | 32ec5b9 | 2014-07-30 07:43:28 -0700 | [diff] [blame] | 44 | import java.util.List; |
| 45 | import java.util.Map; |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 46 | |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 47 | import javax.servlet.http.HttpServletRequest; |
| 48 | |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 49 | /** Tests for {@link Linkifier}. */ |
| Dave Borowitz | 3dc854f | 2014-11-04 16:19:37 -0800 | [diff] [blame] | 50 | @RunWith(JUnit4.class) |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 51 | public class RefServletTest { |
| Dave Borowitz | 33d4fda | 2013-10-22 16:40:20 -0700 | [diff] [blame] | 52 | private TestRepository<DfsRepository> repo; |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 53 | private GitilesServlet servlet; |
| 54 | |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 55 | @Before |
| 56 | public void setUp() throws Exception { |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 57 | DfsRepository r = new InMemoryRepository(new DfsRepositoryDescription("test")); |
| Dave Borowitz | 96a6f47 | 2014-11-04 16:38:20 -0800 | [diff] [blame] | 58 | repo = new TestRepository<>(r); |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 59 | servlet = TestGitilesServlet.create(repo); |
| 60 | } |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 61 | |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 62 | private void setUpSimpleRefs() throws Exception { |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 63 | RevCommit commit = repo.branch("refs/heads/master").commit().create(); |
| 64 | repo.update("refs/heads/branch", commit); |
| 65 | repo.update("refs/tags/ctag", commit); |
| 66 | RevTag tag = repo.tag("atag", commit); |
| 67 | repo.update("refs/tags/atag", tag); |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 68 | repo.getRepository().updateRef("HEAD").link("refs/heads/master"); |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 71 | @Test |
| 72 | public void evilRefName() throws Exception { |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 73 | setUpSimpleRefs(); |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 74 | String evilRefName = "refs/evil/<script>window.close();</script>/&foo"; |
| 75 | assertTrue(Repository.isValidRefName(evilRefName)); |
| 76 | repo.branch(evilRefName).commit().create(); |
| 77 | |
| 78 | FakeHttpServletRequest req = FakeHttpServletRequest.newRequest(); |
| 79 | req.setPathInfo("/test/+refs/evil"); |
| 80 | req.setQueryString("format=TEXT"); |
| 81 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 82 | servlet.service(req, res); |
| 83 | |
| 84 | assertEquals( |
| 85 | id(evilRefName) + " refs/evil/<script>window.close();</script>/&foo\n", |
| 86 | res.getActualBodyString()); |
| 87 | } |
| 88 | |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 89 | @Test |
| 90 | public void getRefsTextAll() throws Exception { |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 91 | setUpSimpleRefs(); |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 92 | FakeHttpServletRequest req = FakeHttpServletRequest.newRequest(); |
| 93 | req.setPathInfo("/test/+refs"); |
| 94 | req.setQueryString("format=TEXT"); |
| 95 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 96 | servlet.service(req, res); |
| 97 | |
| 98 | assertEquals(200, res.getStatus()); |
| 99 | assertEquals( |
| 100 | id("HEAD") + " HEAD\n" |
| 101 | + id("refs/heads/branch") + " refs/heads/branch\n" |
| 102 | + id("refs/heads/master") + " refs/heads/master\n" |
| 103 | + id("refs/tags/atag") + " refs/tags/atag\n" |
| 104 | + peeled("refs/tags/atag") + " refs/tags/atag^{}\n" |
| 105 | + id("refs/tags/ctag") + " refs/tags/ctag\n", |
| 106 | res.getActualBodyString()); |
| 107 | } |
| 108 | |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 109 | @Test |
| 110 | public void getRefsTextAllTrailingSlash() throws Exception { |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 111 | setUpSimpleRefs(); |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 112 | FakeHttpServletRequest req = FakeHttpServletRequest.newRequest(); |
| 113 | req.setPathInfo("/test/+refs"); |
| 114 | req.setQueryString("format=TEXT"); |
| 115 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 116 | servlet.service(req, res); |
| 117 | |
| 118 | assertEquals(200, res.getStatus()); |
| 119 | assertEquals( |
| 120 | id("HEAD") + " HEAD\n" |
| 121 | + id("refs/heads/branch") + " refs/heads/branch\n" |
| 122 | + id("refs/heads/master") + " refs/heads/master\n" |
| 123 | + id("refs/tags/atag") + " refs/tags/atag\n" |
| 124 | + peeled("refs/tags/atag") + " refs/tags/atag^{}\n" |
| 125 | + id("refs/tags/ctag") + " refs/tags/ctag\n", |
| 126 | res.getActualBodyString()); |
| 127 | } |
| 128 | |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 129 | @Test |
| 130 | public void getRefsHeadsText() throws Exception { |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 131 | setUpSimpleRefs(); |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 132 | FakeHttpServletRequest req = FakeHttpServletRequest.newRequest(); |
| 133 | req.setPathInfo("/test/+refs/heads"); |
| 134 | req.setQueryString("format=TEXT"); |
| 135 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 136 | servlet.service(req, res); |
| 137 | |
| 138 | assertEquals(200, res.getStatus()); |
| 139 | assertEquals( |
| 140 | id("refs/heads/branch") + " refs/heads/branch\n" |
| 141 | + id("refs/heads/master") + " refs/heads/master\n", |
| 142 | res.getActualBodyString()); |
| 143 | } |
| 144 | |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 145 | @Test |
| 146 | public void getRefsHeadsTextTrailingSlash() throws Exception { |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 147 | setUpSimpleRefs(); |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 148 | FakeHttpServletRequest req = FakeHttpServletRequest.newRequest(); |
| 149 | req.setPathInfo("/test/+refs/heads/"); |
| 150 | req.setQueryString("format=TEXT"); |
| 151 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 152 | servlet.service(req, res); |
| 153 | |
| 154 | assertEquals(200, res.getStatus()); |
| 155 | assertEquals( |
| 156 | id("refs/heads/branch") + " refs/heads/branch\n" |
| 157 | + id("refs/heads/master") + " refs/heads/master\n", |
| 158 | res.getActualBodyString()); |
| 159 | } |
| 160 | |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 161 | @Test |
| 162 | public void noHeadText() throws Exception { |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 163 | setUpSimpleRefs(); |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 164 | FakeHttpServletRequest req = FakeHttpServletRequest.newRequest(); |
| 165 | req.setPathInfo("/test/+refs/HEAD"); |
| 166 | req.setQueryString("format=TEXT"); |
| 167 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 168 | servlet.service(req, res); |
| 169 | |
| 170 | assertEquals(200, res.getStatus()); |
| 171 | // /+refs/foo means refs/foo(/*), so this is empty. |
| 172 | assertEquals("", res.getActualBodyString()); |
| 173 | } |
| 174 | |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 175 | @Test |
| 176 | public void singleHeadText() throws Exception { |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 177 | setUpSimpleRefs(); |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 178 | FakeHttpServletRequest req = FakeHttpServletRequest.newRequest(); |
| 179 | req.setPathInfo("/test/+refs/heads/master"); |
| 180 | req.setQueryString("format=TEXT"); |
| 181 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 182 | servlet.service(req, res); |
| 183 | |
| 184 | assertEquals(200, res.getStatus()); |
| 185 | assertEquals( |
| 186 | id("refs/heads/master") + " refs/heads/master\n", |
| 187 | res.getActualBodyString()); |
| 188 | } |
| 189 | |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 190 | @Test |
| 191 | public void singlePeeledTagText() throws Exception { |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 192 | setUpSimpleRefs(); |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 193 | FakeHttpServletRequest req = FakeHttpServletRequest.newRequest(); |
| 194 | req.setPathInfo("/test/+refs/tags/atag"); |
| 195 | req.setQueryString("format=TEXT"); |
| 196 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 197 | servlet.service(req, res); |
| 198 | |
| 199 | assertEquals(200, res.getStatus()); |
| 200 | assertEquals( |
| 201 | id("refs/tags/atag") + " refs/tags/atag\n" |
| 202 | + peeled("refs/tags/atag") + " refs/tags/atag^{}\n", |
| 203 | res.getActualBodyString()); |
| 204 | } |
| Dave Borowitz | 32ec5b9 | 2014-07-30 07:43:28 -0700 | [diff] [blame] | 205 | |
| 206 | @Test |
| 207 | public void getRefsJsonAll() throws Exception { |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 208 | setUpSimpleRefs(); |
| Dave Borowitz | 32ec5b9 | 2014-07-30 07:43:28 -0700 | [diff] [blame] | 209 | Map<String, RefJsonData> result = buildJson("/test/+refs"); |
| 210 | List<String> keys = ImmutableList.copyOf(result.keySet()); |
| 211 | assertEquals(ImmutableList.of( |
| 212 | "HEAD", |
| 213 | "refs/heads/branch", |
| 214 | "refs/heads/master", |
| 215 | "refs/tags/atag", |
| 216 | "refs/tags/ctag"), |
| 217 | keys); |
| 218 | |
| 219 | RefJsonData head = result.get(keys.get(0)); |
| 220 | assertEquals(id("HEAD"), head.value); |
| 221 | assertNull(head.peeled); |
| 222 | assertEquals("refs/heads/master", head.target); |
| 223 | |
| 224 | RefJsonData branch = result.get(keys.get(1)); |
| 225 | assertEquals(id("refs/heads/branch"), branch.value); |
| 226 | assertNull(branch.peeled); |
| 227 | assertNull(branch.target); |
| 228 | |
| 229 | RefJsonData master = result.get(keys.get(2)); |
| 230 | assertEquals(id("refs/heads/master"), master.value); |
| 231 | assertNull(master.peeled); |
| 232 | assertNull(master.target); |
| 233 | |
| 234 | RefJsonData atag = result.get(keys.get(3)); |
| 235 | assertEquals(id("refs/tags/atag"), atag.value); |
| 236 | assertEquals(peeled("refs/tags/atag"), atag.peeled); |
| 237 | assertNull(atag.target); |
| 238 | |
| 239 | RefJsonData ctag = result.get(keys.get(4)); |
| 240 | assertEquals(id("refs/tags/ctag"), ctag.value); |
| 241 | assertNull(ctag.peeled); |
| 242 | assertNull(ctag.target); |
| 243 | } |
| 244 | |
| 245 | @Test |
| 246 | public void getRefsHeadsJson() throws Exception { |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 247 | setUpSimpleRefs(); |
| Dave Borowitz | 32ec5b9 | 2014-07-30 07:43:28 -0700 | [diff] [blame] | 248 | Map<String, RefJsonData> result = buildJson("/test/+refs/heads"); |
| 249 | List<String> keys = ImmutableList.copyOf(result.keySet()); |
| 250 | assertEquals(ImmutableList.of( |
| 251 | "branch", |
| 252 | "master"), |
| 253 | keys); |
| 254 | |
| 255 | RefJsonData branch = result.get(keys.get(0)); |
| 256 | assertEquals(id("refs/heads/branch"), branch.value); |
| 257 | assertNull(branch.peeled); |
| 258 | assertNull(branch.target); |
| 259 | |
| 260 | RefJsonData master = result.get(keys.get(1)); |
| 261 | assertEquals(id("refs/heads/master"), master.value); |
| 262 | assertNull(master.peeled); |
| 263 | assertNull(master.target); |
| 264 | } |
| 265 | |
| 266 | private Map<String, RefJsonData> buildJson(String path) throws Exception { |
| 267 | FakeHttpServletRequest req = FakeHttpServletRequest.newRequest(); |
| 268 | req.setPathInfo(path); |
| 269 | req.setQueryString("format=JSON"); |
| 270 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 271 | servlet.service(req, res); |
| 272 | |
| 273 | assertEquals(200, res.getStatus()); |
| 274 | assertEquals("application/json", res.getHeader(HttpHeaders.CONTENT_TYPE)); |
| 275 | String body = res.getActualBodyString(); |
| 276 | String magic = ")]}'\n"; |
| 277 | assertEquals(magic, body.substring(0, magic.length())); |
| 278 | return new Gson().fromJson(body.substring(magic.length()), new TypeToken<Map<String, RefJsonData>>() {}.getType()); |
| 279 | } |
| Dave Borowitz | 1d94e65 | 2014-07-30 12:45:09 -0700 | [diff] [blame] | 280 | |
| 281 | @Test |
| 282 | public void emptySoy() throws Exception { |
| 283 | assertEquals(ImmutableList.of(), buildBranchesSoyData()); |
| 284 | assertEquals(ImmutableList.of(), buildTagsSoyData()); |
| 285 | } |
| 286 | |
| 287 | @Test |
| 288 | public void branchesAndTagsSoy() throws Exception { |
| 289 | repo.branch("refs/heads/foo").commit().create(); |
| 290 | repo.branch("refs/heads/bar").commit().create(); |
| 291 | repo.branch("refs/tags/baz").commit().create(); |
| 292 | repo.branch("refs/nope/quux").commit().create(); |
| 293 | |
| 294 | assertEquals( |
| 295 | ImmutableList.of( |
| 296 | ref("/b/test/+/bar", "bar"), |
| 297 | ref("/b/test/+/foo", "foo")), |
| 298 | buildBranchesSoyData()); |
| 299 | assertEquals( |
| 300 | ImmutableList.of( |
| 301 | ref("/b/test/+/baz", "baz")), |
| 302 | buildTagsSoyData()); |
| 303 | } |
| 304 | |
| 305 | @Test |
| 306 | public void ambiguousBranchSoy() throws Exception { |
| 307 | repo.branch("refs/heads/foo").commit().create(); |
| 308 | repo.branch("refs/heads/bar").commit().create(); |
| 309 | repo.branch("refs/tags/foo").commit().create(); |
| 310 | |
| 311 | assertEquals( |
| 312 | ImmutableList.of( |
| 313 | ref("/b/test/+/bar", "bar"), |
| 314 | ref("/b/test/+/refs/heads/foo", "foo")), |
| 315 | buildBranchesSoyData()); |
| 316 | assertEquals( |
| 317 | ImmutableList.of( |
| 318 | // refs/tags/ is searched before refs/heads/, so this does not |
| 319 | // appear ambiguous. |
| 320 | ref("/b/test/+/foo", "foo")), |
| 321 | buildTagsSoyData()); |
| 322 | } |
| 323 | |
| 324 | @Test |
| 325 | public void ambiguousRelativeToNonBranchOrTagSoy() throws Exception { |
| 326 | repo.branch("refs/foo").commit().create(); |
| 327 | repo.branch("refs/heads/foo").commit().create(); |
| 328 | repo.branch("refs/tags/foo").commit().create(); |
| 329 | |
| 330 | assertEquals( |
| 331 | ImmutableList.of( |
| 332 | ref("/b/test/+/refs/heads/foo", "foo")), |
| 333 | buildBranchesSoyData()); |
| 334 | assertEquals( |
| 335 | ImmutableList.of( |
| 336 | ref("/b/test/+/refs/tags/foo", "foo")), |
| 337 | buildTagsSoyData()); |
| 338 | } |
| 339 | |
| 340 | @Test |
| 341 | public void refsHeadsSoy() throws Exception { |
| 342 | repo.branch("refs/heads/foo").commit().create(); |
| 343 | repo.branch("refs/heads/refs/heads/foo").commit().create(); |
| 344 | |
| 345 | assertEquals( |
| 346 | ImmutableList.of( |
| 347 | ref("/b/test/+/foo", "foo"), |
| 348 | ref("/b/test/+/refs/heads/refs/heads/foo", "refs/heads/foo")), |
| 349 | buildBranchesSoyData()); |
| 350 | } |
| 351 | |
| 352 | private HttpServletRequest buildSoyRequest() { |
| 353 | HttpServletRequest req = FakeHttpServletRequest.newRequest(repo.getRepository()); |
| 354 | ViewFilter.setView(req, GitilesView.repositoryIndex() |
| 355 | .setHostName(URLS.getHostName(req)) |
| 356 | .setServletPath(req.getServletPath()) |
| 357 | .setRepositoryName("test") |
| 358 | .build()); |
| 359 | return req; |
| 360 | } |
| 361 | |
| 362 | private List<?> buildBranchesSoyData() throws Exception { |
| 363 | return RefServlet.getBranchesSoyData(buildSoyRequest(), Integer.MAX_VALUE); |
| 364 | } |
| 365 | |
| 366 | private List<?> buildTagsSoyData() throws Exception { |
| 367 | RevWalk rw = new RevWalk(repo.getRepository()); |
| 368 | try { |
| 369 | return RefServlet.getTagsSoyData(buildSoyRequest(), |
| 370 | new TimeCache(TimeCache.defaultBuilder()), rw, Integer.MAX_VALUE); |
| 371 | } finally { |
| 372 | rw.release(); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | private String id(String refName) throws IOException { |
| 377 | return ObjectId.toString(repo.getRepository().getRef(refName).getObjectId()); |
| 378 | } |
| 379 | |
| 380 | private String peeled(String refName) throws IOException { |
| 381 | return ObjectId.toString(repo.getRepository().peel( |
| 382 | repo.getRepository().getRef(refName)).getPeeledObjectId()); |
| 383 | } |
| 384 | |
| 385 | private Map<String, String> ref(String url, String name) { |
| 386 | return ImmutableMap.of("url", url, "name", name); |
| 387 | } |
| Dave Borowitz | d0b7e18 | 2013-01-11 15:55:09 -0800 | [diff] [blame] | 388 | } |