James Moger
2012-10-18 13417cf9c6eec555b51da49742e47939d2f5715b
src/com/gitblit/utils/JGitUtils.java
@@ -47,7 +47,6 @@
import org.eclipse.jgit.errors.StopWalkException;
import org.eclipse.jgit.lib.BlobBasedConfig;
import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
@@ -59,7 +58,6 @@
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.lib.TreeFormatter;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -212,11 +210,10 @@
         if (credentialsProvider != null) {
            clone.setCredentialsProvider(credentialsProvider);
         }
         clone.call();
         Repository repository = clone.call().getRepository();
         // Now we have to fetch because CloneCommand doesn't fetch
         // refs/notes nor does it allow manual RefSpec.
         File gitDir = FileKey.resolve(new File(repositoriesFolder, name), FS.DETECTED);
         FileRepository repository = new FileRepository(gitDir);
         result.createdRepository = true;
         result.fetchResult = fetchRepository(credentialsProvider, repository);
         repository.close();
@@ -747,17 +744,22 @@
            df.setDetectRenames(true);
            List<DiffEntry> diffs = df.scan(parent.getTree(), commit.getTree());
            for (DiffEntry diff : diffs) {
               String objectId = null;
               if (FileMode.GITLINK.equals(diff.getNewMode())) {
                  objectId = diff.getNewId().name();
               }
               if (diff.getChangeType().equals(ChangeType.DELETE)) {
                  list.add(new PathChangeModel(diff.getOldPath(), diff.getOldPath(), 0, diff
                        .getNewMode().getBits(), null, commit.getId().getName(), diff
                        .getNewMode().getBits(), objectId, commit.getId().getName(), diff
                        .getChangeType()));
               } else if (diff.getChangeType().equals(ChangeType.RENAME)) {
                  list.add(new PathChangeModel(diff.getOldPath(), diff.getNewPath(), 0, diff
                        .getNewMode().getBits(), null, commit.getId().getName(), diff
                        .getNewMode().getBits(), objectId, commit.getId().getName(), diff
                        .getChangeType()));
               } else {
                  list.add(new PathChangeModel(diff.getNewPath(), diff.getNewPath(), 0, diff
                        .getNewMode().getBits(), null, commit.getId().getName(), diff
                        .getNewMode().getBits(), objectId, commit.getId().getName(), diff
                        .getChangeType()));
               }
            }
@@ -1366,9 +1368,23 @@
    * @return all refs grouped by their referenced object id
    */
   public static Map<ObjectId, List<RefModel>> getAllRefs(Repository repository) {
      return getAllRefs(repository, true);
   }
   /**
    * Returns all refs grouped by their associated object id.
    *
    * @param repository
    * @param includeRemoteRefs
    * @return all refs grouped by their referenced object id
    */
   public static Map<ObjectId, List<RefModel>> getAllRefs(Repository repository, boolean includeRemoteRefs) {
      List<RefModel> list = getRefs(repository, org.eclipse.jgit.lib.RefDatabase.ALL, true, -1);
      Map<ObjectId, List<RefModel>> refs = new HashMap<ObjectId, List<RefModel>>();
      for (RefModel ref : list) {
         if (!includeRemoteRefs && ref.getName().startsWith(Constants.R_REMOTES)) {
            continue;
         }
         ObjectId objectid = ref.getReferencedObjectId();
         if (!refs.containsKey(objectid)) {
            refs.put(objectid, new ArrayList<RefModel>());
@@ -1709,24 +1725,6 @@
   }
   /**
    * Returns a StoredConfig object for the repository.
    *
    * @param repository
    * @return the StoredConfig of the repository
    */
   public static StoredConfig readConfig(Repository repository) {
      StoredConfig c = repository.getConfig();
      try {
         c.load();
      } catch (ConfigInvalidException cex) {
         error(cex, repository, "{0} configuration is invalid!");
      } catch (IOException cex) {
         error(cex, repository, "Could not open configuration for {0}!");
      }
      return c;
   }
   /**
    * Zips the contents of the tree at the (optionally) specified revision and
    * the (optionally) specified basepath to the supplied outputstream.
    * 
@@ -1758,6 +1756,9 @@
         }
         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));