From 8993b4b45ef9e97f81f9418976a2f907ff8394d8 Mon Sep 17 00:00:00 2001
From: Shawn Pearce <sop@google.com>
Date: Sun, 24 May 2015 20:33:17 -0700
Subject: [PATCH] Update to JGit 4.0.0.201505191015-rc1.19-g1773002

Use try-with-resources to handle clean upreaders and walk
instances that now use close() instead of release().

Conflicts:
	gitiles-servlet/src/main/java/com/google/gitiles/DiffServlet.java
	gitiles-servlet/src/main/java/com/google/gitiles/RepositoryIndexServlet.java
	gitiles-servlet/src/main/java/com/google/gitiles/RevisionServlet.java
	gitiles-servlet/src/main/java/com/google/gitiles/blame/BlameServlet.java
	gitiles-servlet/src/test/java/com/google/gitiles/RefServletTest.java
	lib/jgit/BUCK

Change-Id: I884d87715bdd920f4e9ef82864d5b962a5b3b065
---
 .buckconfig                                        |  3 ++
 BUCK                                               |  1 -
 VERSION                                            |  2 +-
 bucklets                                           |  2 +-
 bucklets.defs                                      | 27 +++++++++++
 gitiles-servlet/BUCK                               |  5 +-
 .../java/com/google/gitiles/ArchiveServlet.java    |  5 +-
 .../main/java/com/google/gitiles/CommitData.java   | 10 +---
 .../main/java/com/google/gitiles/DiffServlet.java  | 23 ++++------
 .../main/java/com/google/gitiles/LogServlet.java   | 11 ++---
 .../main/java/com/google/gitiles/PathServlet.java  | 53 +++++++---------------
 .../main/java/com/google/gitiles/RefServlet.java   |  5 +-
 .../com/google/gitiles/RepositoryIndexServlet.java |  7 ++-
 .../java/com/google/gitiles/RevisionParser.java    |  5 +-
 .../java/com/google/gitiles/RevisionServlet.java   | 10 +---
 .../com/google/gitiles/blame/BlameCacheImpl.java   | 16 ++-----
 .../com/google/gitiles/blame/BlameServlet.java     |  5 +-
 .../java/com/google/gitiles/PaginatorTest.java     |  2 +-
 .../java/com/google/gitiles/TimeCacheTest.java     | 10 +---
 gitiles-war/BUCK                                   |  2 -
 lib/BUCK                                           |  2 -
 lib/guice/BUCK                                     |  2 -
 lib/jetty/BUCK                                     |  2 -
 lib/jgit/BUCK                                      | 12 ++---
 lib/slf4j/BUCK                                     |  2 -
 25 files changed, 85 insertions(+), 139 deletions(-)
 create mode 100644 bucklets.defs

diff --git a/.buckconfig b/.buckconfig
index f143d0e..01c79be 100644
--- a/.buckconfig
+++ b/.buckconfig
@@ -5,6 +5,9 @@
   mvn_install = //:install
   mvn_deploy = //:deploy
 
+[buildfile]
+  includes = //bucklets.defs
+
 [java]
   src_roots = java, resources
 
diff --git a/BUCK b/BUCK
index 4c72c31..16bf880 100644
--- a/BUCK
+++ b/BUCK
@@ -1,5 +1,4 @@
 include_defs('//VERSION')
-include_defs('//bucklets/maven_package.bucklet')
 
 DEPS = [
   '//gitiles-dev:dev',
diff --git a/VERSION b/VERSION
index 9725e30..0fb0940 100644
--- a/VERSION
+++ b/VERSION
@@ -4,4 +4,4 @@
 # we currently have no stable releases, we use the "build number" scheme
 # described at:
 # http://mojo.codehaus.org/versions-maven-plugin/version-rules.html
-GITILES_VERSION = '0.1-2'
+GITILES_VERSION = '0.1-2-internal'
diff --git a/bucklets b/bucklets
index 20b49d5..0dbb1ae 160000
--- a/bucklets
+++ b/bucklets
@@ -1 +1 @@
-Subproject commit 20b49d5ef6631a3634c8408b24e0b07ef153ba6d
+Subproject commit 0dbb1ae5b35a20a849bb185fea9721fc68c3ffa4
diff --git a/bucklets.defs b/bucklets.defs
new file mode 100644
index 0000000..1ba5e0c
--- /dev/null
+++ b/bucklets.defs
@@ -0,0 +1,27 @@
+import os
+import sys
+
+d = os.getcwd()
+while not os.path.lexists(os.path.join(d, '.buckversion')):
+  d = os.path.dirname(d)
+
+bd = os.path.join(d, 'bucklets')
+if not os.path.isdir(bd) or not os.listdir(bd):
+  sys.stderr.write(('Bucklets directory is missing or empty: %s\n'
+                    'Run `git submodule update --init`') % bd)
+  sys.exit(1)
+
+bucklets = [
+  'java_doc.bucklet',
+  'java_sources.bucklet',
+  'maven_jar.bucklet',
+  'maven_package.bucklet',
+  'war.bucklet',
+]
+
+for bucklet in bucklets:
+  path = os.path.join(bd, bucklet)
+  if not os.path.isfile(path):
+    sys.stderr.write('Missing bucklet: %s\n' % path)
+    sys.exit(1)
+  include_defs('//bucklets/%s' % bucklet)
diff --git a/gitiles-servlet/BUCK b/gitiles-servlet/BUCK
index 8ff8035..290524c 100644
--- a/gitiles-servlet/BUCK
+++ b/gitiles-servlet/BUCK
@@ -1,6 +1,3 @@
-include_defs('//bucklets/java_sources.bucklet')
-include_defs('//bucklets/java_doc.bucklet')
-
 SRCS = glob(['src/main/java/**/*.java'])
 RSRC = glob(['src/main/resources/**/*'])
 DEPS = [
@@ -65,7 +62,7 @@ java_doc(
   title = 'Gitiles API Documentation',
   pkg = 'com.google.gitiles',
   paths = ['gitiles-servlet/src/main/java'],
-  srcs = glob([n + '**/*.java' for n in SRCS]),
+  srcs = SRCS,
   deps = DEPS + [
     '//lib/guice:guice_library',
     '//lib/guice:guice-assistedinject',
diff --git a/gitiles-servlet/src/main/java/com/google/gitiles/ArchiveServlet.java b/gitiles-servlet/src/main/java/com/google/gitiles/ArchiveServlet.java
index 40777a0..7bc59af 100644
--- a/gitiles-servlet/src/main/java/com/google/gitiles/ArchiveServlet.java
+++ b/gitiles-servlet/src/main/java/com/google/gitiles/ArchiveServlet.java
@@ -79,8 +79,7 @@ public class ArchiveServlet extends BaseServlet {
   }
 
   private ObjectId getTree(GitilesView view, Repository repo, Revision rev) throws IOException {
-    RevWalk rw = new RevWalk(repo);
-    try {
+    try (RevWalk rw = new RevWalk(repo)) {
       RevTree tree = rw.parseTree(rev.getId());
       if (Strings.isNullOrEmpty(view.getPathPart())) {
         return tree;
@@ -92,8 +91,6 @@ public class ArchiveServlet extends BaseServlet {
       return tw.getObjectId(0);
     } catch (IncorrectObjectTypeException e) {
       return ObjectId.zeroId();
-    } finally {
-      rw.release();
     }
   }
 
diff --git a/gitiles-servlet/src/main/java/com/google/gitiles/CommitData.java b/gitiles-servlet/src/main/java/com/google/gitiles/CommitData.java
index 76f5273..a25f2c8 100644
--- a/gitiles-servlet/src/main/java/com/google/gitiles/CommitData.java
+++ b/gitiles-servlet/src/main/java/com/google/gitiles/CommitData.java
@@ -118,11 +118,8 @@ class CommitData {
         result.sha = c.copy();
       }
       if (fs.contains(Field.ABBREV_SHA)) {
-        ObjectReader reader = repo.getObjectDatabase().newReader();
-        try {
+        try (ObjectReader reader = repo.getObjectDatabase().newReader()) {
           result.abbrev = reader.abbreviate(c);
-        } finally {
-          reader.release();
         }
       }
       if (fs.contains(Field.URL)) {
@@ -230,14 +227,11 @@ class CommitData {
       }
       AbstractTreeIterator newTree = getTreeIterator(commit);
 
-      DiffFormatter diff = new DiffFormatter(NullOutputStream.INSTANCE);
-      try {
+      try (DiffFormatter diff = new DiffFormatter(NullOutputStream.INSTANCE)) {
         diff.setRepository(repo);
         diff.setDetectRenames(true);
         result.entries = diff.scan(oldTree, newTree);
         return result;
-      } finally {
-        diff.release();
       }
     }
   }
diff --git a/gitiles-servlet/src/main/java/com/google/gitiles/DiffServlet.java b/gitiles-servlet/src/main/java/com/google/gitiles/DiffServlet.java
index aa95dec..d605349 100644
--- a/gitiles-servlet/src/main/java/com/google/gitiles/DiffServlet.java
+++ b/gitiles-servlet/src/main/java/com/google/gitiles/DiffServlet.java
@@ -62,14 +62,12 @@ public class DiffServlet extends BaseServlet {
     GitilesView view = ViewFilter.getView(req);
     Repository repo = ServletUtils.getRepository(req);
 
-    RevWalk walk = new RevWalk(repo);
-    TreeWalk tw = null;
-    try {
+    try (RevWalk walk = new RevWalk(repo);
+        TreeWalk tw = newTreeWalk(walk, view)) {
       boolean showCommit, isFile;
       AbstractTreeIterator oldTree;
       AbstractTreeIterator newTree;
       try {
-        tw = newTreeWalk(walk, view);
         if (tw == null && !view.getPathPart().isEmpty()) {
           res.setStatus(SC_NOT_FOUND);
           return;
@@ -112,20 +110,14 @@ public class DiffServlet extends BaseServlet {
       res.setContentType(FormatType.HTML.getMimeType());
       res.setCharacterEncoding(Charsets.UTF_8.name());
       setCacheHeaders(res);
-
       OutputStream out = res.getOutputStream();
       try {
-        out.write(html[0].getBytes(Charsets.UTF_8));
-        formatHtmlDiff(out, view, repo, oldTree, newTree, view.getPathPart());
-        out.write(html[1].getBytes(Charsets.UTF_8));
+         out.write(html[0].getBytes(Charsets.UTF_8));
+         formatHtmlDiff(out, view, repo, oldTree, newTree, view.getPathPart());
+         out.write(html[1].getBytes(Charsets.UTF_8));
       } finally {
         out.close();
       }
-    } finally {
-      if (tw != null) {
-        tw.release();
-      }
-      walk.release();
     }
   }
 
@@ -180,8 +172,11 @@ public class DiffServlet extends BaseServlet {
       diff.setDetectRenames(true);
       diff.format(oldTree, newTree);
     } finally {
-      diff.release();
+      diff.close();
     }
+    diff.setRepository(repo);
+    diff.setDetectRenames(true);
+    diff.format(oldTree, newTree);
   }
 
   private static AbstractTreeIterator getTreeIterator(RevWalk walk, ObjectId id)
diff --git a/gitiles-servlet/src/main/java/com/google/gitiles/LogServlet.java b/gitiles-servlet/src/main/java/com/google/gitiles/LogServlet.java
index ff1fb7b..05d90ed 100644
--- a/gitiles-servlet/src/main/java/com/google/gitiles/LogServlet.java
+++ b/gitiles-servlet/src/main/java/com/google/gitiles/LogServlet.java
@@ -126,7 +126,7 @@ public class LogServlet extends BaseServlet {
       res.setStatus(SC_INTERNAL_SERVER_ERROR);
       return;
     } finally {
-      paginator.getWalk().release();
+      paginator.getWalk().close();
     }
   }
 
@@ -157,7 +157,7 @@ public class LogServlet extends BaseServlet {
       }
       renderJson(req, res, result, new TypeToken<Map<String, Object>>() {}.getType());
     } finally {
-      paginator.getWalk().release();
+      paginator.getWalk().close();
     }
   }
 
@@ -170,14 +170,11 @@ public class LogServlet extends BaseServlet {
     if (headRef == null) {
       return null;
     }
-    RevWalk walk = new RevWalk(repo);
-    try {
+    try (RevWalk walk = new RevWalk(repo)) {
       return GitilesView.log()
         .copyFrom(view)
         .setRevision(Revision.peel(Constants.HEAD, walk.parseAny(headRef.getObjectId()), walk))
         .build();
-    } finally {
-      walk.release();
     }
   }
 
@@ -230,7 +227,7 @@ public class LogServlet extends BaseServlet {
     try {
       start = getStart(view.getParameters(), walk.getObjectReader());
     } catch (IOException e) {
-      walk.release();
+      walk.close();
       throw e;
     }
     if (start == null) {
diff --git a/gitiles-servlet/src/main/java/com/google/gitiles/PathServlet.java b/gitiles-servlet/src/main/java/com/google/gitiles/PathServlet.java
index ff660b8..ac3dd97 100644
--- a/gitiles-servlet/src/main/java/com/google/gitiles/PathServlet.java
+++ b/gitiles-servlet/src/main/java/com/google/gitiles/PathServlet.java
@@ -123,10 +123,8 @@ public class PathServlet extends BaseServlet {
     GitilesView view = ViewFilter.getView(req);
     Repository repo = ServletUtils.getRepository(req);
 
-    RevWalk rw = new RevWalk(repo);
-    WalkResult wr = null;
-    try {
-      wr = WalkResult.forPath(rw, view);
+    try (RevWalk rw = new RevWalk(repo);
+        WalkResult wr = WalkResult.forPath(rw, view)) {
       if (wr == null) {
         res.setStatus(SC_NOT_FOUND);
         return;
@@ -152,11 +150,6 @@ public class PathServlet extends BaseServlet {
       }
     } catch (LargeObjectException e) {
       res.setStatus(SC_INTERNAL_SERVER_ERROR);
-    } finally {
-      if (wr != null) {
-        wr.release();
-      }
-      rw.release();
     }
   }
 
@@ -165,10 +158,8 @@ public class PathServlet extends BaseServlet {
     GitilesView view = ViewFilter.getView(req);
     Repository repo = ServletUtils.getRepository(req);
 
-    RevWalk rw = new RevWalk(repo);
-    WalkResult wr = null;
-    try {
-      wr = WalkResult.forPath(rw, view);
+    try (RevWalk rw = new RevWalk(repo);
+        WalkResult wr = WalkResult.forPath(rw, view)) {
       if (wr == null) {
         res.setStatus(SC_NOT_FOUND);
         return;
@@ -193,11 +184,6 @@ public class PathServlet extends BaseServlet {
       }
     } catch (LargeObjectException e) {
       res.setStatus(SC_INTERNAL_SERVER_ERROR);
-    } finally {
-      if (wr != null) {
-        wr.release();
-      }
-      rw.release();
     }
   }
 
@@ -240,10 +226,8 @@ public class PathServlet extends BaseServlet {
     GitilesView view = ViewFilter.getView(req);
     Repository repo = ServletUtils.getRepository(req);
 
-    RevWalk rw = new RevWalk(repo);
-    WalkResult wr = null;
-    try {
-      wr = WalkResult.forPath(rw, view);
+    try (RevWalk rw = new RevWalk(repo);
+        WalkResult wr = WalkResult.forPath(rw, view)) {
       if (wr == null) {
         res.setStatus(SC_NOT_FOUND);
         return;
@@ -258,11 +242,6 @@ public class PathServlet extends BaseServlet {
       }
     } catch (LargeObjectException e) {
       res.setStatus(SC_INTERNAL_SERVER_ERROR);
-    } finally {
-      if (wr != null) {
-        wr.release();
-      }
-      rw.release();
     }
   }
 
@@ -348,7 +327,7 @@ public class PathServlet extends BaseServlet {
    * Unlike {@link TreeWalk} itself, supports positioning at the root tree.
    * Includes information to help the auto-dive routine as well.
    */
-  private static class WalkResult {
+  private static class WalkResult implements AutoCloseable {
     private static WalkResult forPath(RevWalk rw, GitilesView view) throws IOException {
       RevTree root = getRoot(view, rw);
       String path = view.getPathPart();
@@ -377,7 +356,7 @@ public class PathServlet extends BaseServlet {
       } catch (IOException | RuntimeException e) {
         // Fallthrough.
       }
-      tw.release();
+      tw.close();
       return null;
     }
 
@@ -402,8 +381,9 @@ public class PathServlet extends BaseServlet {
       return tw.getObjectReader();
     }
 
-    private void release() {
-      tw.release();
+    @Override
+    public void close() {
+      tw.close();
     }
   }
 
@@ -525,12 +505,13 @@ public class PathServlet extends BaseServlet {
   private void showGitlink(HttpServletRequest req, HttpServletResponse res, WalkResult wr)
       throws IOException {
     GitilesView view = ViewFilter.getView(req);
-    SubmoduleWalk sw = SubmoduleWalk.forPath(ServletUtils.getRepository(req), wr.root,
-        view.getPathPart());
-
     String modulesUrl;
     String remoteUrl = null;
-    try {
+
+    try (SubmoduleWalk sw = SubmoduleWalk.forPath(
+          ServletUtils.getRepository(req),
+          wr.root,
+          view.getPathPart())) {
       modulesUrl = sw.getModulesUrl();
       if (modulesUrl != null && (modulesUrl.startsWith("./") || modulesUrl.startsWith("../"))) {
         String moduleRepo = Paths.simplifyPathUpToRoot(modulesUrl, view.getRepositoryName());
@@ -542,8 +523,6 @@ public class PathServlet extends BaseServlet {
       }
     } catch (ConfigInvalidException e) {
       throw new IOException(e);
-    } finally {
-      sw.release();
     }
 
     Map<String, Object> data = Maps.newHashMap();
diff --git a/gitiles-servlet/src/main/java/com/google/gitiles/RefServlet.java b/gitiles-servlet/src/main/java/com/google/gitiles/RefServlet.java
index bf0f75d..77d0091 100644
--- a/gitiles-servlet/src/main/java/com/google/gitiles/RefServlet.java
+++ b/gitiles-servlet/src/main/java/com/google/gitiles/RefServlet.java
@@ -62,12 +62,9 @@ public class RefServlet extends BaseServlet {
       res.setStatus(SC_NOT_FOUND);
       return;
     }
-    RevWalk walk = new RevWalk(ServletUtils.getRepository(req));
     List<Map<String, Object>> tags;
-    try {
+    try (RevWalk walk = new RevWalk(ServletUtils.getRepository(req))) {
       tags = getTagsSoyData(req, timeCache, walk, 0);
-    } finally {
-      walk.release();
     }
     renderHtml(req, res, "gitiles.refsDetail",
         ImmutableMap.of("branches", getBranchesSoyData(req, 0), "tags", tags));
diff --git a/gitiles-servlet/src/main/java/com/google/gitiles/RepositoryIndexServlet.java b/gitiles-servlet/src/main/java/com/google/gitiles/RepositoryIndexServlet.java
index 7dde342..bda8b80 100644
--- a/gitiles-servlet/src/main/java/com/google/gitiles/RepositoryIndexServlet.java
+++ b/gitiles-servlet/src/main/java/com/google/gitiles/RepositoryIndexServlet.java
@@ -63,10 +63,11 @@ public class RepositoryIndexServlet extends BaseServlet {
     Repository repo = ServletUtils.getRepository(req);
     GitilesAccess access = getAccess(req);
     RepositoryDescription desc = access.getRepositoryDescription();
-    RevWalk walk = new RevWalk(repo);
+
     List<Map<String, Object>> tags;
     Map<String, Object> data;
-    try {
+
+    try (RevWalk walk = new RevWalk(repo)) {
       tags = RefServlet.getTagsSoyData(req, timeCache, walk, REF_LIMIT);
       ObjectId headId = repo.resolve(Constants.HEAD);
       if (headId != null) {
@@ -83,8 +84,6 @@ public class RepositoryIndexServlet extends BaseServlet {
       } else {
         data = Maps.newHashMapWithExpectedSize(7);
       }
-    } finally {
-      walk.release();
     }
     if (!data.containsKey("entries")) {
       data.put("entries", ImmutableList.of());
diff --git a/gitiles-servlet/src/main/java/com/google/gitiles/RevisionParser.java b/gitiles-servlet/src/main/java/com/google/gitiles/RevisionParser.java
index 0ae93cd..7fd0f7c 100644
--- a/gitiles-servlet/src/main/java/com/google/gitiles/RevisionParser.java
+++ b/gitiles-servlet/src/main/java/com/google/gitiles/RevisionParser.java
@@ -107,8 +107,7 @@ class RevisionParser {
     if (path.startsWith("/")) {
       path = path.substring(1);
     }
-    RevWalk walk = new RevWalk(repo);
-    try {
+    try (RevWalk walk = new RevWalk(repo)) {
       Revision oldRevision = null;
 
       StringBuilder b = new StringBuilder();
@@ -192,8 +191,6 @@ class RevisionParser {
         first = false;
       }
       return null;
-    } finally {
-      walk.release();
     }
   }
 
diff --git a/gitiles-servlet/src/main/java/com/google/gitiles/RevisionServlet.java b/gitiles-servlet/src/main/java/com/google/gitiles/RevisionServlet.java
index d065a45..3cf1c63 100644
--- a/gitiles-servlet/src/main/java/com/google/gitiles/RevisionServlet.java
+++ b/gitiles-servlet/src/main/java/com/google/gitiles/RevisionServlet.java
@@ -72,8 +72,7 @@ public class RevisionServlet extends BaseServlet {
     Repository repo = ServletUtils.getRepository(req);
     GitilesAccess access = getAccess(req);
 
-    RevWalk walk = new RevWalk(repo);
-    try {
+    try (RevWalk walk = new RevWalk(repo)) {
       DateFormatter df = new DateFormatter(access, Format.DEFAULT);
       List<RevObject> objects = listObjects(walk, view.getRevision());
       List<Map<String, ?>> soyObjects = Lists.newArrayListWithCapacity(objects.size());
@@ -128,8 +127,6 @@ public class RevisionServlet extends BaseServlet {
           "title", view.getRevision().getName(),
           "objects", soyObjects,
           "hasBlob", hasBlob));
-    } finally {
-      walk.release();
     }
   }
 
@@ -138,8 +135,7 @@ public class RevisionServlet extends BaseServlet {
     GitilesView view = ViewFilter.getView(req);
     Repository repo = ServletUtils.getRepository(req);
 
-    RevWalk walk = new RevWalk(repo);
-    try {
+    try (RevWalk walk = new RevWalk(repo)) {
       DateFormatter df = new DateFormatter(getAccess(req), Format.DEFAULT);
       RevObject obj = walk.parseAny(view.getRevision().getId());
       switch (obj.getType()) {
@@ -154,8 +150,6 @@ public class RevisionServlet extends BaseServlet {
           res.setStatus(SC_NOT_FOUND);
           break;
       }
-    } finally {
-      walk.release();
     }
   }
 
diff --git a/gitiles-servlet/src/main/java/com/google/gitiles/blame/BlameCacheImpl.java b/gitiles-servlet/src/main/java/com/google/gitiles/blame/BlameCacheImpl.java
index 50b2d8f..6ef2af3 100644
--- a/gitiles-servlet/src/main/java/com/google/gitiles/blame/BlameCacheImpl.java
+++ b/gitiles-servlet/src/main/java/com/google/gitiles/blame/BlameCacheImpl.java
@@ -132,8 +132,7 @@ public class BlameCacheImpl implements BlameCache {
   public ObjectId findLastCommit(Repository repo, ObjectId commitId, String path)
       throws IOException {
     // Default implementation does no caching.
-    RevWalk rw = new RevWalk(repo);
-    try {
+    try (RevWalk rw = new RevWalk(repo)) {
       rw.markStart(rw.parseCommit(commitId));
       rw.setRewriteParents(false);
       // Don't use rename detection, even though BlameGenerator does. It is not
@@ -143,20 +142,13 @@ public class BlameCacheImpl implements BlameCache {
           PathFilterGroup.createFromStrings(path),
           TreeFilter.ANY_DIFF));
       return rw.next();
-    } finally {
-      rw.release();
     }
   }
 
   public static List<Region> loadBlame(Key key) throws IOException {
-    try {
-      BlameGenerator gen = new BlameGenerator(key.repo, key.path);
-      try {
-        gen.push(null, key.commitId);
-        return loadRegions(gen);
-      } finally {
-        gen.release();
-      }
+    try (BlameGenerator gen = new BlameGenerator(key.repo, key.path)) {
+      gen.push(null, key.commitId);
+      return loadRegions(gen);
     } finally {
       key.repo = null;
     }
diff --git a/gitiles-servlet/src/main/java/com/google/gitiles/blame/BlameServlet.java b/gitiles-servlet/src/main/java/com/google/gitiles/blame/BlameServlet.java
index 04e86a8..4e9adac 100644
--- a/gitiles-servlet/src/main/java/com/google/gitiles/blame/BlameServlet.java
+++ b/gitiles-servlet/src/main/java/com/google/gitiles/blame/BlameServlet.java
@@ -72,8 +72,7 @@ public class BlameServlet extends BaseServlet {
     GitilesView view = ViewFilter.getView(req);
     Repository repo = ServletUtils.getRepository(req);
 
-    RevWalk rw = new RevWalk(repo);
-    try {
+    try (RevWalk rw = new RevWalk(repo)) {
       GitilesAccess access = getAccess(req);
       RevCommit currCommit = rw.parseCommit(view.getRevision().getId());
       ObjectId currCommitBlobId = resolveBlob(view, rw, currCommit);
@@ -118,8 +117,6 @@ public class BlameServlet extends BaseServlet {
             "breadcrumbs", view.getBreadcrumbs(),
             "data", blobData));
       }
-    } finally {
-      rw.release();
     }
   }
 
diff --git a/gitiles-servlet/src/test/java/com/google/gitiles/PaginatorTest.java b/gitiles-servlet/src/test/java/com/google/gitiles/PaginatorTest.java
index 2ac3f96..a9269b4 100644
--- a/gitiles-servlet/src/test/java/com/google/gitiles/PaginatorTest.java
+++ b/gitiles-servlet/src/test/java/com/google/gitiles/PaginatorTest.java
@@ -47,7 +47,7 @@ public class PaginatorTest {
 
   @After
   public void tearDown() throws Exception {
-    walk.release();
+    walk.close();
   }
 
   @Test
diff --git a/gitiles-servlet/src/test/java/com/google/gitiles/TimeCacheTest.java b/gitiles-servlet/src/test/java/com/google/gitiles/TimeCacheTest.java
index 135614b..0d83312 100644
--- a/gitiles-servlet/src/test/java/com/google/gitiles/TimeCacheTest.java
+++ b/gitiles-servlet/src/test/java/com/google/gitiles/TimeCacheTest.java
@@ -113,13 +113,10 @@ public class TimeCacheTest {
     builder.setObjectId(commit);
     builder.setTag("tag");
     builder.setMessage("");
-    ObjectInserter ins = repo.getRepository().newObjectInserter();
     ObjectId id;
-    try {
+    try (ObjectInserter ins = repo.getRepository().newObjectInserter()) {
       id = ins.insert(builder);
       ins.flush();
-    } finally {
-      ins.release();
     }
     assertEquals(start + 1, getTime(commit));
     assertEquals(start + 1, getTime(id));
@@ -136,13 +133,10 @@ public class TimeCacheTest {
     builder.setObjectId(tag);
     builder.setTag("tagtag");
     builder.setMessage("");
-    ObjectInserter ins = repo.getRepository().newObjectInserter();
     ObjectId tagTagId;
-    try {
+    try (ObjectInserter ins = repo.getRepository().newObjectInserter()) {
       tagTagId = ins.insert(builder);
       ins.flush();
-    } finally {
-      ins.release();
     }
     assertEquals(start + 1, getTime(commit));
     assertEquals(start + 2, getTime(tag));
diff --git a/gitiles-war/BUCK b/gitiles-war/BUCK
index 0523e62..268321d 100644
--- a/gitiles-war/BUCK
+++ b/gitiles-war/BUCK
@@ -1,5 +1,3 @@
-include_defs('//bucklets/war.bucklet')
-
 war(
   name = 'gitiles',
   libs = ['//gitiles-servlet:servlet'],
diff --git a/lib/BUCK b/lib/BUCK
index abed916..0447694 100644
--- a/lib/BUCK
+++ b/lib/BUCK
@@ -1,5 +1,3 @@
-include_defs('//bucklets/maven_jar.bucklet')
-
 maven_jar(
   name = 'guava',
   id = 'com.google.guava:guava:16.0',
diff --git a/lib/guice/BUCK b/lib/guice/BUCK
index 1643150..eb2a260 100644
--- a/lib/guice/BUCK
+++ b/lib/guice/BUCK
@@ -1,5 +1,3 @@
-include_defs('//bucklets/maven_jar.bucklet')
-
 VERSION = '4.0-beta'
 EXCLUDE = [
   'META-INF/DEPENDENCIES',
diff --git a/lib/jetty/BUCK b/lib/jetty/BUCK
index 525f94c..5f394c8 100644
--- a/lib/jetty/BUCK
+++ b/lib/jetty/BUCK
@@ -1,5 +1,3 @@
-include_defs('//bucklets/maven_jar.bucklet')
-
 VERS = '8.1.7.v20120910'
 EXCLUDE = ['about.html']
 
diff --git a/lib/jgit/BUCK b/lib/jgit/BUCK
index 8a83a08..3df8752 100644
--- a/lib/jgit/BUCK
+++ b/lib/jgit/BUCK
@@ -1,12 +1,10 @@
-include_defs('//bucklets/maven_jar.bucklet')
-
 REPO = GERRIT
-VERS = '3.3.2.201404171909-r.128-g79448bc'
+VERS = '4.0.0.201505191015-rc1.19-g1773002'
 
 maven_jar(
   name = 'jgit',
   id = 'org.eclipse.jgit:org.eclipse.jgit:' + VERS,
-  sha1 = 'a06d48637aa2952d18909244fd96f7483f148b7c',
+  sha1 = '4db24b39dab8dc0e889807383728032945f461be',
   repository = REPO,
   unsign = True,
   deps = [':ewah'],
@@ -20,7 +18,7 @@ maven_jar(
 maven_jar(
   name = 'jgit-servlet',
   id = 'org.eclipse.jgit:org.eclipse.jgit.http.server:' + VERS,
-  sha1 = 'da9711d199d140a69d21eea70be2f13eca21935c',
+  sha1 = '7bfdbddea56a87f3f2687ae6abf2c5bdae649f0c',
   repository = REPO,
   deps = [':jgit'],
   unsign = True,
@@ -43,7 +41,7 @@ java_library(
 maven_jar(
   name = 'jgit-archive_library',
   id = 'org.eclipse.jgit:org.eclipse.jgit.archive:' + VERS,
-  sha1 = '8574d1080a71fdd8b0a07a9eb85e51beba39149c',
+  sha1 = '08fce6b89f6d1e78f99869d542d70899f3be9c9f',
   repository = REPO,
   deps = [':jgit'],
   unsign = True,
@@ -56,7 +54,7 @@ maven_jar(
 maven_jar(
   name = 'junit',
   id = 'org.eclipse.jgit:org.eclipse.jgit.junit:' + VERS,
-  sha1 = 'c4d232911178abfff65ba4b75cecd3ef31ad4211',
+  sha1 = 'a54c16076e6cbdb9113565a82cffa5f268ae8e3b',
   repository = REPO,
   unsign = True,
   deps = [':jgit'],
diff --git a/lib/slf4j/BUCK b/lib/slf4j/BUCK
index b04b670..4d43e55 100644
--- a/lib/slf4j/BUCK
+++ b/lib/slf4j/BUCK
@@ -1,5 +1,3 @@
-include_defs('//bucklets/maven_jar.bucklet')
-
 VERS = '1.6.1'
 
 maven_jar(
-- 
2.2.1

