| | |
| | | import java.io.File;
|
| | | import java.io.IOException;
|
| | | import java.io.InputStream;
|
| | | import java.nio.charset.Charset;
|
| | | import java.text.DateFormat;
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collection;
|
| | | import java.util.Collections;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | |
| | | import org.eclipse.jgit.revwalk.filter.RevFilter;
|
| | | import org.eclipse.jgit.treewalk.TreeWalk;
|
| | | import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
|
| | | import org.eclipse.jgit.treewalk.filter.OrTreeFilter;
|
| | | import org.eclipse.jgit.treewalk.filter.PathFilter;
|
| | | import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
|
| | | import org.eclipse.jgit.treewalk.filter.PathSuffixFilter;
|
| | | import org.eclipse.jgit.treewalk.filter.TreeFilter;
|
| | | import org.eclipse.jgit.util.io.DisabledOutputStream;
|
| | | import org.slf4j.Logger;
|
| | |
| | | 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;
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | public static String getRawContentAsString(Repository r, RevBlob blob) {
|
| | | return new String(getRawContent(r, blob));
|
| | | byte [] content = getRawContent(r, blob);
|
| | | 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);
|
| | | return new String(getRawContent(r, (RevBlob) obj));
|
| | | byte [] content = getRawContent(r, (RevBlob) obj);
|
| | | return new String(content, Charset.forName(Constants.CHARACTER_ENCODING));
|
| | | }
|
| | |
|
| | | public static List<PathModel> getFilesInPath(Repository r, String basePath, String objectId) {
|
| | |
| | | } catch (Throwable t) {
|
| | | LOGGER.error("failed to determine files in commit!", t);
|
| | | }
|
| | | return list;
|
| | | }
|
| | | |
| | | public static List<PathModel> getDocuments(Repository r, List<String> extensions) {
|
| | | List<PathModel> list = new ArrayList<PathModel>();
|
| | | RevCommit commit = getCommit(r, Constants.HEAD); |
| | | final TreeWalk walk = new TreeWalk(r);
|
| | | try {
|
| | | walk.addTree(commit.getTree());
|
| | | if (extensions != null && extensions.size() > 0) {
|
| | | Collection<TreeFilter> suffixFilters = new ArrayList<TreeFilter>();
|
| | | for (String extension:extensions) {
|
| | | if (extension.charAt(0) == '.') {
|
| | | suffixFilters.add(PathSuffixFilter.create(extension));
|
| | | } else {
|
| | | // escape the . since this is a regexp filter
|
| | | suffixFilters.add(PathSuffixFilter.create("\\." + extension));
|
| | | }
|
| | | }
|
| | | TreeFilter filter = OrTreeFilter.create(suffixFilters);
|
| | | walk.setFilter(filter);
|
| | | walk.setRecursive(true);
|
| | | while (walk.next()) {
|
| | | list.add(getPathModel(walk, null, commit));
|
| | | }
|
| | | } else {
|
| | | while (walk.next()) {
|
| | | list.add(getPathModel(walk, null, commit));
|
| | | }
|
| | | }
|
| | | } catch (IOException e) {
|
| | | LOGGER.error("Failed to get files for commit " + commit.getName(), e);
|
| | | } finally {
|
| | | walk.release();
|
| | | }
|
| | | Collections.sort(list);
|
| | | return list;
|
| | | }
|
| | |
|
| | |
| | | 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 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 getRepositoryUseNamedUsers(Repository r) {
|
| | | return getRepositoryConfigBoolean(r, "useNamedUsers", false);
|
| | | }
|
| | | |
| | | public static void setRepositoryUseNamedUsers(Repository r, boolean value) {
|
| | | setRepositoryConfigBoolean(r, "useNamedUsers", 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 {
|
| | |
| | | metrics.add(0, total);
|
| | | return metrics;
|
| | | }
|
| | |
|
| | | |
| | | public static RefModel getTicketsBranch(Repository r) {
|
| | | RefModel ticgitBranch = null;
|
| | | try {
|