| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | 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();
|
| | |
| | | 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()));
|
| | | }
|
| | | }
|
| | |
| | | * @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>());
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 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.
|
| | | *
|
| | |
| | | }
|
| | | 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));
|