List of usage examples for org.eclipse.jgit.lib ObjectId name
public final String name()
name.
From source file:org.kuali.student.git.model.branch.large.LargeBranchNameProviderMapImpl.java
License:Educational Community License
@Override public String storeLargeBranchName(String branchName, long revision) { ObjectId largeBranchNameId = GitBranchUtils.getBranchNameObjectId(branchName); this.largeBranchNameMap.put(largeBranchNameId.name(), branchName); return largeBranchNameId.name(); }
From source file:org.kuali.student.git.model.ExternalModuleUtils.java
License:Educational Community License
/** * Don't make any adjustments just render the externals into the fusion-maven-plugin.dat format as given. * /*from w ww .ja va 2 s .com*/ * @param externals * @return fusion-maven-plugin.dat formatted string. */ public static String createFusionMavenPluginDataFileString(List<ExternalModuleInfo> externals) { StringBuilder builder = new StringBuilder(); for (ExternalModuleInfo external : externals) { String moduleName = external.getModuleName(); String externalBranchPath = external.getBranchPath(); long externalRevision = external.getRevision(); builder.append("# module = " + moduleName + " branch Path = " + externalBranchPath + " revision = " + externalRevision + "\n"); String branchName = external.getBranchName(); if (branchName == null) { log.warn("branchName is null for module = " + moduleName); } ObjectId branchHead = external.getBranchHeadId(); String subTreePath = external.getSubTreePath(); builder.append( moduleName + "::" + branchName + "::" + (branchHead == null ? "UNKNOWN" : branchHead.name()) + (subTreePath == null ? "" : "::" + subTreePath) + "\n"); } return builder.toString(); }
From source file:org.kuali.student.git.model.SvnRevisionMapper.java
License:Educational Community License
@Override public String storeLargeBranchName(String branchName, long revision) { try {//w w w.j a va 2s . c o m ObjectId largeBranchNameId = GitBranchUtils.getBranchNameObjectId(branchName); String existingBranchName = getBranchName(largeBranchNameId.name(), revision); if (existingBranchName != null) return largeBranchNameId.getName(); File revisionFile = new File(revisonMappings, "r" + revision + "-large-branches"); PrintWriter pw = new PrintWriter(new FileOutputStream(revisionFile, true)); pw.println(largeBranchNameId.name() + "::" + branchName); pw.flush(); pw.close(); return largeBranchNameId.name(); } catch (FileNotFoundException e) { log.warn("storeLargeBranchName: failed to open r" + revision + "-large-branches"); return null; } }
From source file:org.kuali.student.git.model.TestSampleImport.java
License:Educational Community License
@Test public void testSampleImport() throws IOException { runImporter(repository, 0);/*from w w w .j a v a2 s .c o m*/ runImporter(repository, 1); GitTestUtils.assertRefNotNull(repository, "trunk", "expected trunk to exist"); GitTestUtils.assertPathsExist(repository, "trunk", Arrays.asList(new String[] { "pom.xml", "module/pom.xml", "module/src/main/resources/test.txt" })); GitTestUtils.assertFileContentEquals(repository, "trunk", "pom.xml", "test file\n"); GitTestUtils.assertFileContentEquals(repository, "trunk", "module/src/main/resources/test.txt", " test resource file\n"); runImporter(repository, 2); GitTestUtils.assertRefNotNull(repository, "branches_branch1", "expected branch1 to exist"); GitTestUtils.assertPathsExist(repository, "branches_branch1", Arrays.asList(new String[] { "pom.xml", "module/pom.xml", "module/src/main/resources/test.txt" })); runImporter(repository, 3); GitTestUtils.assertPathsExist(repository, "trunk", Arrays.asList(new String[] { "pom.xml", "module1/pom.xml", "module1/src/main/resources/test.txt", "module2/pom.xml", "module2/src/main/resources/test.txt" })); runImporter(repository, 4); GitTestUtils.assertRefNotNull(repository, "branches_branch2", "expected branch2 to exist"); runImporter(repository, 5); GitTestUtils.assertRefNotNull(repository, "branches_inactive", "expected branches_inactive to exist"); GitTestUtils.assertPathsExist(repository, "branches_inactive", Arrays.asList(new String[] { "branch1/pom.xml", "branch1/module/pom.xml", "branch2/module1/src/main/resources/test.txt", "branch2/module2/pom.xml", "branch2/module2/src/main/resources/test.txt" })); runImporter(repository, 6); GitTestUtils.assertRefNotNull(repository, "branches_branch1", "expected branch1 to exist"); GitTestUtils.assertRefNotNull(repository, "branches_branch2", "expected branch2 to exist"); runImporter(repository, 7); GitTestUtils.assertPathsExist(repository, "trunk", Arrays.asList(new String[] { "module3/pom.xml", "module3/src/main/resources/test.txt" })); runImporter(repository, 8); GitTestUtils.assertFileContentEquals(repository, "trunk", "pom.xml", "another pom file only change\n"); runImporter(repository, 9); GitTestUtils.assertPathsExist(repository, "trunk", Arrays.asList( new String[] { "module3/src/main/resources/test.txt", "module3/src/main/resources/A.txt", "module3/src/main/resources/B.txt", "module3/src/main/resources/C.txt" })); runImporter(repository, 10); GitTestUtils.assertPathsExist(repository, "trunk", Arrays.asList(new String[] { "module4/pom.xml", "module4/src/main/resources/test.txt" })); runImporter(repository, 11); GitTestUtils.assertPathsDontExist(repository, "trunk", Arrays.asList(new String[] { "module3/src/main/resources/A.txt", "module3/src/main/resources/B.txt", "module3/src/main/resources/test.txt" })); GitTestUtils.assertPathsExist(repository, "trunk", Arrays.asList(new String[] { "module3/src/main/resources/C.txt" })); /* * test deleting a path ending in tags from trunk. */ runImporter(repository, 12); GitTestUtils.assertPathsExist(repository, "trunk", Arrays.asList(new String[] { "tags/test-tag/test.txt" })); runImporter(repository, 13); GitTestUtils.assertPathsDontExist(repository, "trunk", Arrays.asList(new String[] { "tags/test-tag/test.txt" })); /* * Test copyfrom nested trunk to trunk scenario */ runImporter(repository, 14); GitTestUtils.assertPathsExist(repository, "trunk_maven_trunk", Arrays.asList(new String[] { "kuali/test.txt" })); runImporter(repository, 15); GitTestUtils.assertPathsExist(repository, "trunk", Arrays.asList(new String[] { "maven/kuali/test.txt" })); /* * Test that a copyfrom an invalid branch works. */ runImporter(repository, 16); GitTestUtils.assertRefNotNull(repository, "invalid-branch-name", "expected invalid-branch-name to exist"); runImporter(repository, 17); GitTestUtils.assertPathsExist(repository, "trunk", Arrays.asList(new String[] { "invalid-branch-name-resource.txt" })); runImporter(repository, 18); GitTestUtils.assertFileContentEquals(repository, "trunk", "module5/pom.xml", " module pom file\n"); runImporter(repository, 19); GitTestUtils.assertPathsExist(repository, "aggregate_trunk", Arrays.asList(new String[] { "fusion-maven-plugin.dat" })); ObjectLoader fusionDataFileLoader = GitTestUtils.loadFileContents(repository, "aggregate_trunk", "fusion-maven-plugin.dat"); List<ExternalModuleInfo> externals = ExternalModuleUtils .extractFusionMavenPluginData(fusionDataFileLoader.openStream()); for (ExternalModuleInfo externalModuleInfo : externals) { if (externalModuleInfo.getModuleName().equals("branch1")) { ObjectId branch1ExpectedHeadId = externalModuleInfo.getBranchHeadId(); String branchPath = externalModuleInfo.getBranchPath(); Assert.assertEquals("branches/branch1", branchPath); String branchName = externalModuleInfo.getBranchName(); Assert.assertEquals("branches_branch1", branchName); Ref actualBranchRef = repository.getRef("branches_branch1"); Assert.assertEquals("expected branch 1 external head id to match repo head id", branch1ExpectedHeadId, actualBranchRef.getObjectId()); } else if (externalModuleInfo.getModuleName().equals("branch2")) { ObjectId branch2ExpectedHeadId = externalModuleInfo.getBranchHeadId(); String branchPath = externalModuleInfo.getBranchPath(); Assert.assertEquals("branches/branch2", branchPath); String branchName = externalModuleInfo.getBranchName(); Assert.assertEquals("branches_branch2", branchName); Ref actualBranchRef = repository.getRef("branches_branch2"); Assert.assertEquals("expected branch 2 external head id to match repo head id", branch2ExpectedHeadId, actualBranchRef.getObjectId()); } else { Assert.fail("expected branch1 or branch 2"); } } GitTreeProcessor processor = new GitTreeProcessor(repository); Ref aggregateTrunkRef = repository.getRef("aggregate_trunk"); GitTreeData treeAtR19 = processor.extractExistingTreeDataFromCommit(aggregateTrunkRef.getObjectId()); ObjectId fusionMavenPluginDatAtR19 = treeAtR19.find(repository, "fusion-maven-plugin.dat"); Assert.assertNotNull( "Expected the fusion-maven-plugin.dat file to exist in the base of the aggregate_trunk branch at r19", fusionMavenPluginDatAtR19); runImporter(repository, 20); aggregateTrunkRef = repository.getRef("aggregate_trunk"); GitTreeData treeAtR20 = processor.extractExistingTreeDataFromCommit(aggregateTrunkRef.getObjectId()); ObjectId fusionMavenPluginDatAtR20 = treeAtR20.find(repository, "fusion-maven-plugin.dat"); Assert.assertEquals("Expected the fusion-maven-plugin.dat file to stay the same between rev 19 and rev 20", fusionMavenPluginDatAtR19, fusionMavenPluginDatAtR20); ObjectId expectedTrunkCommitId = repository.getRef("trunk").getObjectId(); runImporter(repository, 21); // there should not be a commit because all of the changes should be skipped. Assert.assertEquals(expectedTrunkCommitId.name(), repository.getRef("trunk").getObjectId().name()); // somne of these files had the property set on them make sure they are not of size zero GitTestUtils.assertFileContentEquals(repository, "trunk", "invalid-branch-name-resource.txt", " test resource file\n"); GitTestUtils.assertFileContentEquals(repository, "trunk", "maven/kuali/test.txt", "test file\n"); GitTestUtils.assertFileContentEquals(repository, "trunk", "module1/pom.xml", " module pom file\n"); // there should be no commit with rev 21 ObjectId preR22FusionData = GitTestUtils.findObjectIdInRefByPath(repository, "aggregate_trunk", "fusion-maven-plugin.dat"); runImporter(repository, 22); ObjectId postR22FusionData = GitTestUtils.findObjectIdInRefByPath(repository, "aggregate_trunk", "fusion-maven-plugin.dat"); Assert.assertNotEquals("fusion-maven-plugin.dat should change between r21 and r22", preR22FusionData.name(), postR22FusionData.name()); runImporter(repository, 23); GitTestUtils.assertRefNotNull(repository, "sandbox_CM", "Expected the sandbox_CM branch to exist"); GitTestUtils.assertPathsExist(repository, "sandbox_CM", Arrays.asList(new String[] { "branch1/pom.xml", "branch1/module/pom.xml" })); runImporter(repository, 24); GitTestUtils.assertRefNotNull(repository, "contrib_CM_branch1_trunk", "Expected the contrib_CM_branch1_trunk branch to exist"); }
From source file:org.modeshape.connector.git.GitBranches.java
License:Apache License
@Override public Document execute(Repository repository, Git git, CallSpecification spec, DocumentWriter writer, Values values) throws GitAPIException, IOException { if (spec.parameterCount() == 0) { // This is the top-level "/branches" node writer.setPrimaryType(GitLexicon.BRANCHES); // Generate the child references to the branches ... addBranchesAsChildren(git, spec, writer); } else if (spec.parameterCount() == 1) { // This is a particular branch node ... writer.setPrimaryType(GitLexicon.BRANCH); String branchName = spec.parameter(0); String branchRefName = branchRefForName(branchName); // Get the Ref, which doesn't directly know about the commit SHA1, so we have to parse the commit ... Ref ref = repository.getRef(branchRefName); if (ref == null) return null; // invalid branch RevWalk walker = new RevWalk(repository); try {/*w w w.jav a2s . c om*/ RevCommit commit = walker.parseCommit(ref.getObjectId()); // Construct the references to other nodes in this source ... ObjectId objId = commit.getId(); writer.addProperty(GitLexicon.OBJECT_ID, objId.name()); writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, objId.name(), values)); writer.addProperty(GitLexicon.HISTORY, GitHistory.referenceToHistory(objId, branchName, values)); writer.addProperty(GitLexicon.DETAIL, GitCommitDetails.referenceToCommit(objId, values)); } finally { walker.dispose(); } } else { return null; } return writer.document(); }
From source file:org.modeshape.connector.git.GitCommitDetails.java
License:Apache License
@Override public Document execute(Repository repository, Git git, CallSpecification spec, DocumentWriter writer, Values values) throws GitAPIException, IOException { if (spec.parameterCount() == 0) { // This is the top-level "/commit" node writer.setPrimaryType(GitLexicon.DETAILS); // Generate the child references to the branches, tags, and commits in the history ... addBranchesAsChildren(git, spec, writer); addTagsAsChildren(git, spec, writer); addCommitsAsChildren(git, spec, writer, pageSize); } else if (spec.parameterCount() == 1) { // This is the top-level "/commit/{branchOrTagNameOrObjectId}" node writer.setPrimaryType(GitLexicon.DETAILED_COMMIT); // Add the properties describing this commit ... RevWalk walker = new RevWalk(repository); walker.setRetainBody(true);/*from ww w . ja v a2s . c o m*/ try { String branchOrTagOrCommitId = spec.parameter(0); ObjectId objId = resolveBranchOrTagOrCommitId(repository, branchOrTagOrCommitId); RevCommit commit = walker.parseCommit(objId); writer.addProperty(GitLexicon.OBJECT_ID, objId.name()); writer.addProperty(GitLexicon.AUTHOR, authorName(commit)); writer.addProperty(GitLexicon.COMMITTER, commiterName(commit)); writer.addProperty(GitLexicon.COMMITTED, values.dateFrom(commit.getCommitTime())); writer.addProperty(GitLexicon.TITLE, commit.getShortMessage()); writer.addProperty(GitLexicon.MESSAGE, commit.getFullMessage().trim());// removes trailing whitespace writer.addProperty(GitLexicon.PARENTS, GitCommitDetails.referencesToCommits(commit.getParents(), values)); writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, objId.name(), values)); // Compute the difference between the commit and it's parent(s), and generate the diff/patch file ... List<DiffEntry> differences = computeDifferences(commit, walker, repository); String patchFile = computePatch(differences, repository); writer.addProperty(GitLexicon.DIFF, patchFile); } finally { walker.dispose(); } } else { return null; } return writer.document(); }
From source file:org.modeshape.connector.git.GitHistory.java
License:Apache License
@Override public Document execute(Repository repository, Git git, CallSpecification spec, DocumentWriter writer, Values values) throws GitAPIException, IOException { if (spec.parameterCount() == 0) { // This is the top-level "/commits" node writer.setPrimaryType(GitLexicon.COMMITS); // Generate the child references to the branches, tags, and commits in the history ... addBranchesAsChildren(git, spec, writer); addTagsAsChildren(git, spec, writer); addCommitsAsChildren(git, spec, writer, pageSize); } else if (spec.parameterCount() == 1) { // This is the top-level "/commits/{branchOrTagNameOrObjectId}" node writer.setPrimaryType(GitLexicon.OBJECT); // Generate the child references to the (latest) commits on this branch/tag ... String branchOrTagNameOrObjectId = spec.parameter(0); ObjectId objId = resolveBranchOrTagOrCommitId(repository, branchOrTagNameOrObjectId); RevWalk walker = new RevWalk(repository); try {//from w w w. ja v a2s.co m RevCommit commit = walker.parseCommit(objId); LogCommand command = git.log(); command.add(commit.getId()); command.setMaxCount(pageSize); for (RevCommit rev : command.call()) { String commitId = rev.getId().getName(); writer.addChild(spec.childId(commitId), commitId); } // Handle paging ... writer.addPage(spec.getParentId(), pageSize, pageSize, PageWriter.UNKNOWN_TOTAL_SIZE); } finally { walker.dispose(); } } else if (spec.parameterCount() == 2) { // This is a specific commit in the history, via "/commits/{branchOrTagNameOrObjectId}/{objectId}" writer.setPrimaryType(GitLexicon.COMMIT); // so we need to show the commit information ... RevWalk walker = new RevWalk(repository); try { String commitId = spec.parameter(1); ObjectId objId = repository.resolve(commitId); RevCommit commit = walker.parseCommit(objId); writer.addProperty(GitLexicon.OBJECT_ID, objId.name()); writer.addProperty(GitLexicon.AUTHOR, authorName(commit)); writer.addProperty(GitLexicon.COMMITTER, commiterName(commit)); writer.addProperty(GitLexicon.COMMITTED, values.dateFrom(commit.getCommitTime())); writer.addProperty(GitLexicon.TITLE, commit.getShortMessage()); writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, objId.name(), values)); writer.addProperty(GitLexicon.DETAIL, GitCommitDetails.referenceToCommit(objId, values)); // And there are no children } finally { walker.dispose(); } } else { return null; } return writer.document(); }
From source file:org.modeshape.connector.git.GitTags.java
License:Apache License
@Override public Document execute(Repository repository, Git git, CallSpecification spec, DocumentWriter writer, Values values) throws GitAPIException, IOException { if (spec.parameterCount() == 0) { // This is the top-level "/branches" node writer.setPrimaryType(GitLexicon.TAGS); // Generate the child references to the branches ... addTagsAsChildren(git, spec, writer); } else if (spec.parameterCount() == 1) { // This is a particular branch node ... writer.setPrimaryType(GitLexicon.TAG); String tagName = spec.parameter(0); // Get the Ref, which doesn't directly know about the commit SHA1, so we have to parse the commit ... Ref ref = repository.getRef(tagName); if (ref == null) return null; // invalid tag name RevWalk walker = new RevWalk(repository); try {// w w w .ja v a 2 s . com RevCommit commit = walker.parseCommit(ref.getObjectId()); // Construct the references to other nodes in this source ... ObjectId objId = commit.getId(); writer.addProperty(GitLexicon.OBJECT_ID, objId.name()); writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, objId.name(), values)); writer.addProperty(GitLexicon.HISTORY, GitHistory.referenceToHistory(objId, tagName, values)); writer.addProperty(GitLexicon.DETAIL, GitCommitDetails.referenceToCommit(objId, values)); } finally { walker.dispose(); } } else { return null; } return writer.document(); }
From source file:org.modeshape.connector.git.GitTree.java
License:Apache License
@Override public Document execute(Repository repository, Git git, CallSpecification spec, DocumentWriter writer, Values values) throws GitAPIException, IOException { if (spec.parameterCount() == 0) { // This is the top-level "/branches" node writer.setPrimaryType(GitLexicon.TREES); // Generate the child references to the branches and tags. Branches are likely used more often, so list them first... addBranchesAsChildren(git, spec, writer); addTagsAsChildren(git, spec, writer); addCommitsAsChildren(git, spec, writer, pageSize); } else if (spec.parameterCount() == 1) { // This is a particular branch/tag/commit node ... String branchOrTagOrObjectId = spec.parameter(0); ObjectId objId = resolveBranchOrTagOrCommitId(repository, branchOrTagOrObjectId); RevWalk walker = new RevWalk(repository); walker.setRetainBody(true); // we need to parse the commit for the top-level try {/* w w w .j a va2 s .c o m*/ RevCommit commit = walker.parseCommit(objId); // could happen if not enough permissions, for example if (commit != null) { // Add the properties for this node ... String committer = commiterName(commit); String author = authorName(commit); DateTime committed = values.dateFrom(commit.getCommitTime()); writer.setPrimaryType(GitLexicon.FOLDER); writer.addProperty(JcrLexicon.CREATED, committed); writer.addProperty(JcrLexicon.CREATED_BY, committer); writer.addProperty(GitLexicon.OBJECT_ID, objId.name()); writer.addProperty(GitLexicon.AUTHOR, author); writer.addProperty(GitLexicon.COMMITTER, committer); writer.addProperty(GitLexicon.COMMITTED, committed); writer.addProperty(GitLexicon.TITLE, commit.getShortMessage()); writer.addProperty(GitLexicon.HISTORY, GitHistory.referenceToHistory(objId, branchOrTagOrObjectId, values)); writer.addProperty(GitLexicon.DETAIL, GitCommitDetails.referenceToCommit(objId, values)); } // Add the top-level children of the directory ... addInformationForPath(repository, git, writer, commit, "", spec, values); } finally { walker.dispose(); } } else { // This is a folder or file within the directory structure ... String branchOrTagOrObjectId = spec.parameter(0); String path = spec.parametersAsPath(1); ObjectId objId = resolveBranchOrTagOrCommitId(repository, branchOrTagOrObjectId); RevWalk walker = new RevWalk(repository); walker.setRetainBody(false); // we don't need top-level commit information try { // Get the commit information ... RevCommit commit = walker.parseCommit(objId); // Add the top-level children of the directory ... addInformationForPath(repository, git, writer, commit, path, spec, values); } finally { walker.dispose(); } } return writer.document(); }
From source file:org.nbgit.client.CommitBuilderTest.java
License:Open Source License
private void refCommit(Commit commit) throws Exception { refCommitLine("commit", commit.getCommitId().name()); refCommitLine("tree", commit.getTreeId().name()); for (ObjectId id : commit.getParentIds()) refCommitLine("parent", id.name()); refCommitLine("author", commit.getAuthor().toExternalString()); refCommitLine("committer", commit.getCommitter().toExternalString()); ref("");/*from w w w . j a v a2s. com*/ for (String line : commit.getMessage().split("\n")) { ref(" " + line); } if (commit.getTree().memberCount() > 0) ref(""); refTree(commit.getTree()); }