James Moger
2011-04-27 166e6a131d0693d20b3cc08f252705608d24d5f0
src/com/gitblit/utils/JGitUtils.java
@@ -94,9 +94,10 @@
            File gitFolder = new File(file, Constants.DOT_GIT);
            boolean isGitRepository = gitFolder.exists() && gitFolder.isDirectory();
            
            // then look for folder.git/HEAD
            // then look for folder.git/HEAD or folder/HEAD and folder/config
            if (!isGitRepository) {
               if (file.getName().endsWith(Constants.DOT_GIT_EXT) && new File(file, Constants.HEAD).exists()) {
               if ((file.getName().endsWith(Constants.DOT_GIT_EXT) && new File(file, Constants.HEAD).exists())
                     || (new File(file, "config").exists() && new File(file, Constants.HEAD).exists())) {
                  gitFolder = file;
                  isGitRepository = true;
               }
@@ -266,13 +267,13 @@
   public static String getRawContentAsString(Repository r, RevBlob blob) {
      byte [] content = getRawContent(r, blob);
      return new String(content, Charset.forName("UTF-8"));
      return new String(content, Charset.forName(Constants.CHARACTER_ENCODING));
   }
   public static String getRawContentAsString(Repository r, RevCommit commit, String blobPath) {
      RevObject obj = getRevObject(r, commit.getTree(), blobPath);
      byte [] content = getRawContent(r, (RevBlob) obj);
      return new String(content, Charset.forName("UTF-8"));
      return new String(content, Charset.forName(Constants.CHARACTER_ENCODING));
   }
   public static List<PathModel> getFilesInPath(Repository r, String basePath, String objectId) {
@@ -775,98 +776,7 @@
      return r.toString();
   }
   public static String getRepositoryDescription(Repository r) {
      return getRepositoryConfigString(r, "description");
   }
   public static void setRepositoryDescription(Repository r, String value) {
      setRepositoryConfigString(r, "description", value);
   }
   public static String getRepositoryOwner(Repository r) {
      return getRepositoryConfigString(r, "owner");
   }
   public static void setRepositoryOwner(Repository r, String owner) {
      setRepositoryConfigString(r, "owner", owner);
   }
   public static String getRepositoryGroup(Repository r) {
      return getRepositoryConfigString(r, "group");
   }
   public static void setRepositoryGroup(Repository r, String group) {
      setRepositoryConfigString(r, "group", group);
   }
   public static boolean getRepositoryUseTickets(Repository r) {
      return getRepositoryConfigBoolean(r, "useTickets", false);
   }
   public static void setRepositoryUseTickets(Repository r, boolean value) {
      setRepositoryConfigBoolean(r, "useTickets", value);
   }
   public static boolean getRepositoryUseDocs(Repository r) {
      return getRepositoryConfigBoolean(r, "useDocs", false);
   }
   public static void setRepositoryUseDocs(Repository r, boolean value) {
      setRepositoryConfigBoolean(r, "useDocs", value);
   }
   public static boolean getRepositoryRestrictedAccess(Repository r) {
      return getRepositoryConfigBoolean(r, "restrictedAccess", false);
   }
   public static void setRepositoryRestrictedAccess(Repository r, boolean value) {
      setRepositoryConfigBoolean(r, "restrictedAccess", value);
   }
   public static String getRepositoryConfigString(Repository r, String field) {
      StoredConfig c = readConfig(r);
      if (c == null) {
         return "";
      }
      String o = c.getString("gitblit", null, field);
      return o == null ? "" : o;
   }
   public static void setRepositoryConfigString(Repository r, String field, String value) {
      StoredConfig c = readConfig(r);
      if (c == null) {
         throw new RuntimeException("Can't find stored config for " + r);
      }
      c.setString("gitblit", null, field, value);
      try {
         c.save();
      } catch (IOException e) {
         LOGGER.error("Failed to save repository config field " + field, e);
      }
   }
   public static boolean getRepositoryConfigBoolean(Repository r, String field, boolean defaultValue) {
      StoredConfig c = readConfig(r);
      if (c == null) {
         return defaultValue;
      }
      return c.getBoolean("gitblit", null, field, defaultValue);
   }
   public static void setRepositoryConfigBoolean(Repository r, String field, boolean value) {
      StoredConfig c = readConfig(r);
      if (c == null) {
         throw new RuntimeException("Can't find stored config for " + r);
      }
      c.setBoolean("gitblit", null, field, value);
      try {
         c.save();
      } catch (IOException e) {
         LOGGER.error("Failed to save repository config field " + field, e);
      }
   }
   private static StoredConfig readConfig(Repository r) {
   public static StoredConfig readConfig(Repository r) {
      StoredConfig c = r.getConfig();
      if (c != null) {
         try {