| | |
| | | import java.io.File;
|
| | | import java.io.IOException;
|
| | | import java.io.InputStream;
|
| | | import java.io.OutputStream;
|
| | | import java.nio.charset.Charset;
|
| | | import java.text.DateFormat;
|
| | | import java.text.ParseException;
|
| | |
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | | import java.util.concurrent.atomic.AtomicInteger;
|
| | | import java.util.zip.ZipEntry;
|
| | | import java.util.zip.ZipOutputStream;
|
| | |
|
| | | import org.eclipse.jgit.api.Git;
|
| | | import org.eclipse.jgit.diff.DiffEntry;
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | public static boolean zip(Repository r, String basePath, String objectId, OutputStream os) throws Exception {
|
| | | RevCommit commit = getCommit(r, objectId);
|
| | | if (commit == null) {
|
| | | return false;
|
| | | }
|
| | | final RevWalk rw = new RevWalk(r);
|
| | | final TreeWalk walk = new TreeWalk(r);
|
| | | try {
|
| | | walk.addTree(commit.getTree());
|
| | | ZipOutputStream zos = new ZipOutputStream(os);
|
| | | zos.setComment("Generated by Git:Blit");
|
| | | if (basePath != null && basePath.length() > 0) {
|
| | | PathFilter f = PathFilter.create(basePath);
|
| | | walk.setFilter(f);
|
| | | }
|
| | | walk.setRecursive(true);
|
| | | while (walk.next()) {
|
| | | ZipEntry entry = new ZipEntry(walk.getPathString());
|
| | | entry.setSize(walk.getObjectReader().getObjectSize(walk.getObjectId(0), Constants.OBJ_BLOB));
|
| | | entry.setComment(commit.getName());
|
| | | zos.putNextEntry(entry);
|
| | |
|
| | | ObjectId entid = walk.getObjectId(0);
|
| | | FileMode entmode = walk.getFileMode(0);
|
| | | RevBlob blob = (RevBlob) rw.lookupAny(entid, entmode.getObjectType());
|
| | | rw.parseBody(blob);
|
| | |
|
| | | ObjectLoader ldr = r.open(blob.getId(), Constants.OBJ_BLOB);
|
| | | byte[] tmp = new byte[4096];
|
| | | InputStream in = ldr.openStream();
|
| | | int n;
|
| | | while ((n = in.read(tmp)) > 0) {
|
| | | zos.write(tmp, 0, n);
|
| | | }
|
| | | in.close();
|
| | | }
|
| | | zos.finish();
|
| | | return true;
|
| | | } catch (IOException e) {
|
| | | LOGGER.error("Failed to zip files from commit " + commit.getName(), e);
|
| | | } finally {
|
| | | walk.release();
|
| | | rw.dispose();
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | public static List<Metric> getDateMetrics(Repository r) {
|
| | | Metric total = new Metric("TOTAL");
|
| | | final Map<String, Metric> metricMap = new HashMap<String, Metric>();
|