| | |
| | | import java.io.IOException;
|
| | | import java.io.InputStream;
|
| | | import java.io.RandomAccessFile;
|
| | | import java.text.DateFormat;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | | import java.util.Date;
|
| | |
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
|
| | | import com.gitblit.wicket.models.Metric;
|
| | | import com.gitblit.wicket.models.PathModel;
|
| | | import com.gitblit.wicket.models.RefModel;
|
| | |
|
| | |
|
| | | public class JGitUtils {
|
| | |
|
| | |
| | |
|
| | | public static List<PathModel> getFilesInPath(Repository r, String basePath, RevCommit commit) {
|
| | | List<PathModel> list = new ArrayList<PathModel>();
|
| | | final TreeWalk walk = new TreeWalk(r); |
| | | final TreeWalk walk = new TreeWalk(r);
|
| | | try {
|
| | | walk.addTree(commit.getTree());
|
| | | if (basePath != null && basePath.length() > 0) {
|
| | |
| | | boolean foundFolder = false;
|
| | | while (walk.next()) {
|
| | | if (!foundFolder && walk.isSubtree()) {
|
| | | walk.enterSubtree(); |
| | | walk.enterSubtree();
|
| | | }
|
| | | if (walk.getPathString().equals(basePath)) {
|
| | | foundFolder = true;
|
| | |
| | | return list;
|
| | | }
|
| | |
|
| | | private static PathModel getPathModel(TreeWalk walk, String basePath, RevCommit commit) { |
| | | private static PathModel getPathModel(TreeWalk walk, String basePath, RevCommit commit) {
|
| | | String name;
|
| | | long size = 0;
|
| | | if (basePath == null) {
|
| | |
| | | return FileMode.TREE.equals(mode);
|
| | | }
|
| | |
|
| | | |
| | | public static List<RevCommit> getRevLog(Repository r, int maxCount) {
|
| | | List<RevCommit> list = new ArrayList<RevCommit>();
|
| | | try {
|
| | |
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | public static List<Metric> getDateMetrics(Repository r) {
|
| | | final Map<String, Metric> map = new HashMap<String, Metric>();
|
| | | try {
|
| | | DateFormat df = new SimpleDateFormat("yyyy-MM");
|
| | | Git git = new Git(r);
|
| | | Iterable<RevCommit> revlog = git.log().call();
|
| | | for (RevCommit rev : revlog) {
|
| | | Date d = getCommitDate(rev);
|
| | | String p = df.format(d);
|
| | | if (!map.containsKey(p))
|
| | | map.put(p, new Metric(p));
|
| | | map.get(p).count++;
|
| | | }
|
| | | } catch (Throwable t) {
|
| | | LOGGER.error("Failed to mine log history for metrics", t);
|
| | | }
|
| | | List<String> keys = new ArrayList<String>(map.keySet());
|
| | | Collections.sort(keys);
|
| | | List<Metric> metrics = new ArrayList<Metric>();
|
| | | for (String key:keys) {
|
| | | metrics.add(map.get(key));
|
| | | } |
| | | return metrics;
|
| | | }
|
| | | }
|