List of usage examples for org.eclipse.jgit.lib ObjectId fromString
public static ObjectId fromString(String str)
From source file:org.kuali.student.git.model.NodeProcessor.java
License:Educational Community License
private void applyDirectoryCopy(long currentRevision, String path, OperationType operationType, String copyFromPath, GitBranchData targetBranch, OperationType type, SvnRevisionMapResults revisionMapResults) { ObjectId commitId = ObjectId.fromString(revisionMapResults.getRevMap().getCommitId()); try {/*from w w w . j av a 2s .c om*/ boolean fallbackOnTargetBranch = false; if (operationType.equals(OperationType.INVALID_SINGLE_NEW)) fallbackOnTargetBranch = true; treeProcessor.visitBlobs(commitId, new CopyFromTreeBlobVisitor(currentRevision, path, targetBranch, type, copyFromPath, fallbackOnTargetBranch, revisionMapResults, largeBranchNameProvider, branchDetector, this, vetoLog, blobLog), createPathFilter(revisionMapResults)); } catch (Exception e) { log.error("failed to visit blobs", e); } }
From source file:org.kuali.student.git.model.SvnRevisionMapper.java
License:Educational Community License
/** * Get the object id of the commit refered to by the branch at the revision * given./* ww w. j av a2 s . c o m*/ * * @param revision * @param branchName * @return * @throws IOException */ public ObjectId getRevisionBranchHead(long revision, String branchName) throws IOException { InputStream inputStream = getRevisionInputStream(revision); if (inputStream == null) return null; List<String> lines = IOUtils.readLines(inputStream, "UTF-8"); inputStream.close(); String revisionString = String.valueOf(revision); String adjustedBranchName = branchName; if (!adjustedBranchName.startsWith(Constants.R_HEADS)) adjustedBranchName = Constants.R_HEADS + branchName; for (String line : lines) { String[] parts = line.split("::"); if (!parts[0].equals(revisionString)) { log.warn("incorrect version"); continue; } if (parts[1].equals(adjustedBranchName)) { ObjectId id = ObjectId.fromString(parts[2]); return id; } } // this is actually an exceptional case // if not found it means that the reference can't be found. return null; }
From source file:org.kuali.student.git.model.SvnRevisionMapper.java
License:Educational Community License
private SvnRevisionMapResults findResults(SvnRevisionMap revMap, String copyFromPath) { /*/*from w w w . ja va 2 s . c om*/ * In most cases the match is because the copyFromPath is an actual * branch. * * In other cases it is a prefix that can match several branches * * In a few cases it will refer to a branch and then a subpath within it * it. */ String candidateBranchPath = revMap.getBranchPath().substring(Constants.R_HEADS.length()); String candidateBranchParts[] = candidateBranchPath.split("\\/"); String copyFromPathParts[] = copyFromPath.split("\\/"); int smallestLength = Math.min(candidateBranchParts.length, copyFromPathParts.length); boolean allEquals = true; for (int i = 0; i < smallestLength; i++) { String candidatePart = candidateBranchParts[i]; String copyFromPart = copyFromPathParts[i]; if (!copyFromPart.equals(candidatePart)) { allEquals = false; break; } } if (allEquals) { if (copyFromPathParts.length > smallestLength) { // check inside of the branch for the rest of the path ObjectId commitId = ObjectId.fromString(revMap.getCommitId()); String insidePath = StringUtils.join(copyFromPathParts, "/", smallestLength, copyFromPathParts.length); try { if (treeProcessor.treeContainsPath(commitId, insidePath)) { return new SvnRevisionMapResults(revMap, copyFromPath, insidePath); } // fall through } catch (Exception e) { log.error("Failed to find paths for commit {}", commitId); // fall through } } else { return new SvnRevisionMapResults(revMap, copyFromPath); } } return null; }
From source file:org.kuali.student.git.model.TestKSRevision27974.java
License:Educational Community License
@Test public void testRevision27974() throws IOException { File gitRepository = new File("target/ks-r27974"); FileUtils.deleteDirectory(gitRepository); Repository repository = GitRepositoryUtils.buildFileRepository(gitRepository, true); GitImporterMain/* w w w . ja v a 2s. c o m*/ .main(new String[] { "src/test/resources/ks-r27974.dump.bz2", gitRepository.getAbsolutePath(), "target/ks-r27974-ks-veto.log", "target/ks-r27974-ks-copyFrom-skipped.log", "target/ks-r27974-blob.log", "0", "https://svn.kuali.org/repos/student", "uuid" }); // get the fusion-maven-plugin.dat file and check its contents are what we expect. SvnRevisionMapper revisionMapper = new SvnRevisionMapper(repository); revisionMapper.initialize(); List<SvnRevisionMap> heads = revisionMapper.getRevisionHeads(27974L); Assert.assertNotNull(heads); Assert.assertEquals(1, heads.size()); SvnRevisionMap revMap = heads.get(0); ObjectId branchHead = ObjectId.fromString(revMap.getCommitId()); RevWalk rw = new RevWalk(repository); RevCommit commit = rw.parseCommit(branchHead); TreeWalk tw = new TreeWalk(repository); tw.addTree(commit.getTree().getId()); Assert.assertTrue("should have been one file", tw.next()); Assert.assertEquals(FileMode.REGULAR_FILE, tw.getFileMode(0)); ObjectId blobId = tw.getObjectId(0); ObjectLoader loader = repository.newObjectReader().open(blobId, Constants.OBJ_BLOB); List<String> lines = IOUtils.readLines(loader.openStream(), "UTF-8"); Assert.assertEquals(2, lines.size()); String firstLine = lines.get(0); Assert.assertEquals( "# module = ks-api branch Path = sandbox/ks-1.3-core-slice-demo/modules/ks-api/trunk revision = 27974", firstLine); String secondLine = lines.get(1); Assert.assertEquals("ks-api::sandbox_ks-1.3-core-slice-demo_modules_ks-api_trunk::UNKNOWN", secondLine); tw.release(); rw.release(); revisionMapper.shutdown(); }
From source file:org.kuali.student.git.tools.ShowTree.java
License:Educational Community License
/** * @param args/*from ww w . j av a 2 s . com*/ */ public static void main(String[] args) { if (args.length != 3) { usage(); } try { Repository repo = GitRepositoryUtils.buildFileRepository(new File(args[0]), false); String mode = args[1]; String objectId = args[2]; TreeWalk tw = new TreeWalk(repo); if (mode.equals("tree")) { tw.addTree(ObjectId.fromString(args[2].trim())); processTreeWalk(tw); } else if (mode.equals("follow-commit")) { RevWalk rw = new RevWalk(repo); RevCommit currentCommit = rw.parseCommit(ObjectId.fromString(objectId)); while (currentCommit != null) { log.info("current commit id = " + currentCommit.getId()); log.info("current commit message = " + currentCommit.getFullMessage()); tw.reset(currentCommit.getTree().getId()); processTreeWalk(tw); currentCommit = currentCommit.getParent(0); } rw.release(); } else { usage(); } tw.release(); } catch (IOException e) { log.error("unexpected Exception ", e); } }
From source file:org.modeshape.connector.git.GitConnector.java
License:Apache License
@Override public ExternalBinaryValue getBinaryValue(String id) { try {/*from ww w.j a v a 2s . co m*/ ObjectId fileObjectId = ObjectId.fromString(id); ObjectLoader fileLoader = repository.open(fileObjectId); return new GitBinaryValue(fileObjectId, fileLoader, getSourceName(), null, getMimeTypeDetector()); } catch (IOException e) { throw new DocumentStoreException(id, e); } }
From source file:org.obiba.git.command.CommitLogCommand.java
License:Open Source License
@Override public CommitInfo execute(Git git) { Repository repository = git.getRepository(); RevWalk walk = new RevWalk(repository); try {// w w w .j a v a2 s .c o m RevCommit commit = walk.parseCommit(ObjectId.fromString(commitId)); if (TreeWalk.forPath(repository, path, commit.getTree()) != null) { // There is indeed the path in this commit PersonIdent personIdent = commit.getAuthorIdent(); return new CommitInfo.Builder().authorName(personIdent.getName()) // .authorEmail(personIdent.getEmailAddress()) // .date(personIdent.getWhen()) // .comment(commit.getFullMessage()) // .commitId(commit.getName()) // .head(GitUtils.isHead(repository, commitId)).build(); } } catch (IOException e) { throw new GitException(e); } throw new GitException(String.format("Path '%s' was not found in commit '%s'", path, commitId)); }
From source file:org.srcdeps.core.impl.scm.JGitScm.java
License:Apache License
/** * Walks back through the history of the {@code advertisedRefs} and tries to find the given {@code commitSha1}. * * @param repository/* w ww . j a va 2s . c o m*/ * the current {@link Repository} to search in * @param advertisedRefs * the list of refs that were fetched and whose histories should be searched through * @param commitSha1 * the commit to find * @param url * the URL that was used to fetch * @throws ScmException * if the given {@code commitSha1} could not be found in the history of any of the * {@code advertisedRefs} */ private void assertRevisionFetched(Repository repository, Collection<Ref> advertisedRefs, String commitSha1, String url) throws ScmException { ObjectId needle = ObjectId.fromString(commitSha1); try { for (Ref ref : advertisedRefs) { try (RevWalk walk = new RevWalk(repository)) { walk.markStart(walk.parseCommit(ref.getTarget().getObjectId())); walk.setRetainBody(false); for (RevCommit commit : walk) { if (commit.getId().equals(needle)) { return; } } } } } catch (IOException e) { new ScmException(String.format("Could not fetch ref [%s] from [%s]", commitSha1, url), e); } throw new ScmException(String.format("Could not fetch ref [%s] from [%s]", commitSha1, url)); }
From source file:org.uberfire.java.nio.fs.jgit.util.commands.GetRef.java
License:Apache License
public Ref execute() { try {/*from www . ja v a 2s . c o m*/ final Ref value = repo.getRefDatabase().getRef(name); if (value != null) { return value; } final ObjectId treeRef = repo.resolve(name + "^{tree}"); if (treeRef != null) { final ObjectLoader loader = repo.getObjectDatabase().newReader().open(treeRef); if (loader.getType() == OBJ_TREE) { return new ObjectIdRef.PeeledTag(Ref.Storage.NEW, name, ObjectId.fromString(name), treeRef); } } } catch (final Exception ignored) { } return null; }
From source file:org.uberfire.java.nio.fs.jgit.util.commands.ResolveObjectIds.java
License:Apache License
public List<ObjectId> execute() { final List<ObjectId> result = new ArrayList<>(); for (final String id : ids) { try {/*from ww w . j a va2 s. co m*/ final Ref refName = git.getRef(id); if (refName != null) { result.add(refName.getObjectId()); continue; } try { final ObjectId _id = ObjectId.fromString(id); if (git.getRepository().getObjectDatabase().has(_id)) { result.add(_id); } } catch (final IllegalArgumentException ignored) { } } catch (final java.io.IOException ignored) { } } return result; }