James Moger
2014-02-28 115551c76c3af879b49447dce64d7a6c29049c40
src/main/java/com/gitblit/utils/JGitUtils.java
@@ -15,10 +15,8 @@
 */
package com.gitblit.utils;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.util.ArrayList;
@@ -706,6 +704,7 @@
         return null;
      }
      RevCommit commit = null;
      RevWalk walk = null;
      try {
         // resolve object id
         ObjectId branchObject;
@@ -714,12 +713,18 @@
         } else {
            branchObject = repository.resolve(objectId);
         }
         RevWalk walk = new RevWalk(repository);
         if (branchObject == null) {
            return null;
         }
         walk = new RevWalk(repository);
         RevCommit rev = walk.parseCommit(branchObject);
         commit = rev;
         walk.dispose();
      } catch (Throwable t) {
         error(t, repository, "{0} failed to get commit {1}", objectId);
      } finally {
         if (walk != null) {
            walk.dispose();
         }
      }
      return commit;
   }
@@ -755,18 +760,8 @@
            ObjectId entid = tw.getObjectId(0);
            FileMode entmode = tw.getFileMode(0);
            if (entmode != FileMode.GITLINK) {
               RevObject ro = rw.lookupAny(entid, entmode.getObjectType());
               rw.parseBody(ro);
               ByteArrayOutputStream os = new ByteArrayOutputStream();
               ObjectLoader ldr = repository.open(ro.getId(), Constants.OBJ_BLOB);
               byte[] tmp = new byte[4096];
               InputStream in = ldr.openStream();
               int n;
               while ((n = in.read(tmp)) > 0) {
                  os.write(tmp, 0, n);
               }
               in.close();
               content = os.toByteArray();
               ObjectLoader ldr = repository.open(entid, Constants.OBJ_BLOB);
               content = ldr.getCachedBytes();
            }
         }
      } catch (Throwable t) {
@@ -810,17 +805,8 @@
      byte[] content = null;
      try {
         RevBlob blob = rw.lookupBlob(ObjectId.fromString(objectId));
         rw.parseBody(blob);
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         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) {
            os.write(tmp, 0, n);
         }
         in.close();
         content = os.toByteArray();
         content = ldr.getCachedBytes();
      } catch (Throwable t) {
         error(t, repository, "{0} can't find blob {1}", objectId);
      } finally {
@@ -1470,23 +1456,6 @@
      String target = null;
      try {
         target = repository.getFullBranch();
         if (!target.startsWith(Constants.R_HEADS)) {
            // refers to an actual commit, probably a tag
            // find latest tag that matches the commit, if any
            List<RefModel> tagModels = getTags(repository, true, -1);
            if (tagModels.size() > 0) {
               RefModel tag = null;
               Date lastDate = new Date(0);
               for (RefModel tagModel : tagModels) {
                  if (tagModel.getReferencedObjectId().getName().equals(target) &&
                        tagModel.getDate().after(lastDate)) {
                     tag = tagModel;
                     lastDate = tag.getDate();
                  }
               }
               target = tag.getName();
            }
         }
      } catch (Throwable t) {
         error(t, repository, "{0} failed to get symbolic HEAD target");
      }