James Moger
2012-11-30 59b817a55b04b4bd8c5950a2d97998d3af6d44e3
src/com/gitblit/utils/JGitUtils.java
@@ -19,7 +19,6 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -30,8 +29,6 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.FetchCommand;
@@ -1720,72 +1717,6 @@
         }
      } catch (Throwable t) {
         error(t, repository, "Failed to create orphan branch {1} in repository {0}", branchName);
      }
      return success;
   }
   /**
    * Zips the contents of the tree at the (optionally) specified revision and
    * the (optionally) specified basepath to the supplied outputstream.
    *
    * @param repository
    * @param basePath
    *            if unspecified, entire repository is assumed.
    * @param objectId
    *            if unspecified, HEAD is assumed.
    * @param os
    * @return true if repository was successfully zipped to supplied output
    *         stream
    */
   public static boolean zip(Repository repository, String basePath, String objectId,
         OutputStream os) {
      RevCommit commit = getCommit(repository, objectId);
      if (commit == null) {
         return false;
      }
      boolean success = false;
      RevWalk rw = new RevWalk(repository);
      TreeWalk tw = new TreeWalk(repository);
      try {
         tw.addTree(commit.getTree());
         ZipOutputStream zos = new ZipOutputStream(os);
         zos.setComment("Generated by Gitblit");
         if (!StringUtils.isEmpty(basePath)) {
            PathFilter f = PathFilter.create(basePath);
            tw.setFilter(f);
         }
         tw.setRecursive(true);
         while (tw.next()) {
            if (tw.getFileMode(0) == FileMode.GITLINK) {
               continue;
            }
            ZipEntry entry = new ZipEntry(tw.getPathString());
            entry.setSize(tw.getObjectReader().getObjectSize(tw.getObjectId(0),
                  Constants.OBJ_BLOB));
            entry.setComment(commit.getName());
            zos.putNextEntry(entry);
            ObjectId entid = tw.getObjectId(0);
            FileMode entmode = tw.getFileMode(0);
            RevBlob blob = (RevBlob) rw.lookupAny(entid, entmode.getObjectType());
            rw.parseBody(blob);
            ObjectLoader ldr = repository.open(blob.getId(), Constants.OBJ_BLOB);
            byte[] tmp = new byte[4096];
            InputStream in = ldr.openStream();
            int n;
            while ((n = in.read(tmp)) > 0) {
               zos.write(tmp, 0, n);
            }
            in.close();
         }
         zos.finish();
         success = true;
      } catch (IOException e) {
         error(e, repository, "{0} failed to zip files from commit {1}", commit.getName());
      } finally {
         tw.release();
         rw.dispose();
      }
      return success;
   }