List of usage examples for org.eclipse.jgit.lib Constants R_HEADS
String R_HEADS
To view the source code for org.eclipse.jgit.lib Constants R_HEADS.
Click Source Link
From source file:org.kuali.student.git.model.NodeProcessor.java
License:Educational Community License
private void applyBlobAdd(GitBranchData data, String path, long currentRevision, Map<String, String> nodeProperties) throws IOException, VetoBranchException { /*/* w w w. j av a2 s . c om*/ * Part A: determine the merge branch */ String copyFromPath = nodeProperties.get(SvnDumpFilter.SVN_DUMP_KEY_NODE_COPYFROM_PATH); BranchData copyFromBranchData = null; if (copyFromPath != null) { long copyFromRevision = Long.valueOf(nodeProperties.get(SvnDumpFilter.SVN_DUMP_KEY_NODE_COPYFROM_REV)); try { copyFromBranchData = branchDetector.parseBranch(copyFromRevision, copyFromPath); } catch (VetoBranchException e1) { // check the default branch List<SvnRevisionMapResults> copyFromBranches = revisionMapper.getRevisionBranches(copyFromRevision, copyFromPath); if (copyFromBranches.size() == 1) { SvnRevisionMapResults results = copyFromBranches.get(0); copyFromBranchData = new BranchData(copyFromRevision, results.getRevMap().getBranchPath().substring(Constants.R_HEADS.length()), results.getSubPath()); } else { if (copyFromBranches.size() == 0) { log.warn("no copyfrom branch found for: " + copyFromPath); vetoLog.println(String.format( "no copyfrom branch fround at blob add CurrentRevision: %s, Branch: %s, CopyFromRevision: %s, CopyFromPath: %s", String.valueOf(currentRevision), data.getBranchName(), copyFromRevision, copyFromPath)); } else if (copyFromBranches.size() > 1) { log.warn("multiple copyfrom branches found for " + copyFromPath); vetoLog.println(String.format( "multiple copyfrom branch fround at blob add CurrentRevision: %s, Branch: %s, CopyFromRevision: %s, CopyFromPath: %s", String.valueOf(currentRevision), data.getBranchName(), copyFromRevision, copyFromPath)); } return; } } if (!copyFromBranchData.getBranchPath().equals(data.getBranchPath())) { String copyFromBranchName = GitBranchUtils.getCanonicalBranchName( copyFromBranchData.getBranchPath(), copyFromRevision, largeBranchNameProvider); // register the merge ObjectId head = revisionMapper.getRevisionBranchHead(copyFromRevision, copyFromBranchName); if (head == null) { /* * We don't have a branch for the copy from file so skip the * merge on this one. */ this.copyFromSkippedLog.println( String.format("no branch for (path=%s, revision = %d", copyFromPath, copyFromRevision)); } else { data.addMergeParentId(head); } } } /* * Step B: store the blob or find the copy from blob and add it into the * current branch at the current path. */ log.debug("branch = " + data.getBranchPath() + ", path = " + path + ", at revision " + currentRevision); try { ObjectId id = storeBlob(data, path, copyFromBranchData, nodeProperties); if (id != null) { data.addBlob(path, id, blobLog); } else { log.warn("failed to store blob at path = " + path); } } catch (InvalidBlobChangeException e) { // this is ok but lets log to make sure we are getting all of them. log.warn("invalid blob change occured at " + currentRevision + " on path: " + path); } }
From source file:org.kuali.student.git.model.NodeProcessor.java
License:Educational Community License
private void applyDirectoryAdd(final GitBranchData data, final String path, final long currentRevision, Map<String, String> nodeProperties) { /*//from w w w.j a v a 2 s .co m * A directory add can occur within a branch * * but it can also take place above, in which case we need to look at * the path in relationship to the branches that it matches and apply * the blobs accordingly. * * It can also take place within an existing branch in which case we * need to navigate the subtree to find the blobs. */ try { CopyFromOperation copyFromOperation = computeTargetBranches(data, path, currentRevision); computeCopyFromBranches(copyFromOperation, nodeProperties); for (GitBranchData targetBranch : copyFromOperation.getTargetBranches()) { List<SvnRevisionMapResults> copyFromBranches = copyFromOperation.getCopyFromBranches(); if (copyFromOperation.getType().equals(OperationType.SINGLE_NEW)) { /* * If the parent exists then this is the same as a delete * and copy. * * We are no longer connected to the old parent only the * copyfrom data. */ if (data.getParentId() != null) { deleteBranch(data.getBranchName(), currentRevision); data.reset(); } if (copyFromBranches.size() == 1) { // this is a new branch copied from the old branch // copy the svn:externals and svn:mergeinfo data aswell. SvnRevisionMapResults results = copyFromBranches.get(0); if (results != null && results.getSubPath() != null && results.getSubPath().length() == 0) { GitBranchDataUtils.extractAndStoreBranchMerges(results.getRevMap().getRevision(), results.getRevMap().getBranchName(), data, revisionMapper); ObjectId parentId = ObjectId.fromString(results.getRevMap().getCommitId()); // make a shallow copy of the parent tree. only the // blobs in the root directory GitTreeData parentTreeData = treeProcessor.extractExistingTreeDataFromCommit(parentId); // shallow because this method extract the externals from a // fusion-maven-plugin.dat file at the root of the // tree. // then it will set the details into the target branch. GitBranchDataUtils.extractExternalModules(repo, parentTreeData, data, treeProcessor); } } else if (copyFromBranches.size() > 1) { log.warn("multiple copy from case at rev = " + currentRevision + " path = " + path); } } else if (copyFromOperation.getType().equals(OperationType.INVALID_SINGLE_NEW)) { if (copyFromBranches.size() > 0) { /* * Normally we would not store into the path given but * because it is a copy from we will do it. */ String branchName = GitBranchUtils.getCanonicalBranchName(path, currentRevision, largeBranchNameProvider); if (targetBranch != null) { log.warn( "overriting target branch at rev = " + currentRevision + " and path = " + path); } targetBranch = getBranchData(branchName, currentRevision); } } /* * In this case the number of copyfrom branches can be very * high. * * And we need an efficient way to perform the copy. * * To start with we will ignore the possible child branches and * just use the existing git tree objects represented by the * copyfrom branches. */ for (SvnRevisionMapResults revisionMapResults : copyFromBranches) { ObjectId copyFromBranchCommitId = ObjectId .fromString(revisionMapResults.getRevMap().getCommitId()); String copyFromPath = revisionMapResults.getCopyFromPath(); String copyFromBranchPath = revisionMapResults.getRevMap().getBranchPath() .substring(Constants.R_HEADS.length()); String copyFromBranchSubPath = revisionMapResults.getSubPath(); String targetPath = GitBranchUtils.convertToTargetPath(path, copyFromPath, new BranchData(currentRevision, copyFromBranchPath, copyFromBranchSubPath)); try { BranchData adjustedBranch = branchDetector.parseBranch(currentRevision, targetPath); String branchName = GitBranchUtils.getCanonicalBranchName(adjustedBranch.getBranchPath(), currentRevision, largeBranchNameProvider); GitBranchData adjustedTargetBranch = getBranchData(branchName, currentRevision); applyCopy(adjustedTargetBranch, targetPath, copyFromBranchSubPath, copyFromBranchCommitId); // create the new branch Ref ref = repo.getRef(Constants.R_HEADS + branchName); if (ref == null || copyFromOperation.getType().equals(OperationType.INVALID_SINGLE_NEW) || copyFromOperation.getType().equals(OperationType.SINGLE_NEW)) { adjustedTargetBranch.setCreated(true); // copy over any svn merge data GitBranchDataUtils.extractAndStoreBranchMerges( revisionMapResults.getRevMap().getRevision(), revisionMapResults.getRevMap().getBranchName(), adjustedTargetBranch, revisionMapper); ObjectId parentId = ObjectId.fromString(revisionMapResults.getRevMap().getCommitId()); // make a shallow copy of the parent tree. only the // blobs in the root directory GitTreeData parentTreeData = treeProcessor.extractExistingTreeDataFromCommit(parentId); // shallow because this method will insert a // fusion-maven-plugin.dat file at the root of the // tree. GitBranchDataUtils.extractExternalModules(repo, parentTreeData, adjustedTargetBranch, treeProcessor); } adjustedTargetBranch.addMergeParentId(copyFromBranchCommitId); } catch (VetoBranchException e) { // add the branch tree into the target branch applyCopy(targetBranch, targetPath, copyFromBranchSubPath, copyFromBranchCommitId); targetBranch.setCreated(true); targetBranch.addMergeParentId(copyFromBranchCommitId); } } if (copyFromOperation.getType().equals(OperationType.SINGLE_NEW) || copyFromOperation.getType().equals(OperationType.INVALID_SINGLE_NEW)) { if (targetBranch != null && (targetBranch.getBlobsAdded() > 0 || targetBranch.isTreeDirty())) targetBranch.setCreated(true); } } } catch (IOException e) { log.error(String.format("failed to process directory add %s at %d", path, currentRevision), e); } }
From source file:org.kuali.student.git.model.NodeProcessor.java
License:Educational Community License
private String normalizeBranchName(String branchName) { if (branchName.startsWith(Constants.R_HEADS)) branchName = branchName.substring(Constants.R_HEADS.length()); return branchName; }
From source file:org.kuali.student.git.model.NodeProcessor.java
License:Educational Community License
private CopyFromOperation computeTargetBranches(GitBranchData data, String path, long currentRevision) throws IOException { CopyFromOperation copyOp = null;/*from www . j a v a2 s . c om*/ List<SvnRevisionMapResults> targetBranches = revisionMapper.getRevisionBranches(currentRevision - 1, path); if (targetBranches.size() == 1) { SvnRevisionMap revMap = targetBranches.get(0).getRevMap(); String adjustedBranchPath = revMap.getBranchPath().substring(Constants.R_HEADS.length()); if (adjustedBranchPath.length() < path.length()) { copyOp = new CopyFromOperation(OperationType.SUBTREE); } else { copyOp = new CopyFromOperation(OperationType.SINGLE); } copyOp.setTargetBranches(Arrays.asList(new GitBranchData[] { getBranchData(revMap, currentRevision) })); } else { if (targetBranches.size() == 0) { if (data == null) { /* * target is not a branch but is a copy op. */ copyOp = new CopyFromOperation(OperationType.INVALID_SINGLE_NEW); } else { if (data.getBranchPath().equals(path)) { // new single branch copyOp = new CopyFromOperation(OperationType.SINGLE_NEW); } else { // existing single branch copyOp = new CopyFromOperation(OperationType.SINGLE); } } copyOp.setTargetBranches(Arrays.asList(new GitBranchData[] { data })); } else { copyOp = new CopyFromOperation(OperationType.MULTI); copyOp.setTargetBranches(getBranchDataList(getRevMapList(targetBranches), currentRevision)); } } return copyOp; }
From source file:org.kuali.student.git.model.ref.utils.GitRefUtils.java
License:Educational Community License
public static Ref archiveBranch(Repository repo, ILargeBranchNameProvider largeBranchNameProvider, PersonIdent refLogIdent, String currentBranchName, long currentRevision) throws IOException { String archivedBranchName = Constants.R_HEADS + currentBranchName + "@" + (currentRevision - 1); Ref existingBranchRef = repo.getRef(Constants.R_HEADS + currentBranchName); if (existingBranchRef == null) { log.warn("trying to rename branch: " + currentBranchName + " to " + archivedBranchName + " but it doesn't exist."); return null; }/*from www . j av a 2 s . co m*/ if (archivedBranchName.length() >= GitBranchUtils.FILE_SYSTEM_NAME_LIMIT) { archivedBranchName = Constants.R_HEADS + largeBranchNameProvider.storeLargeBranchName(archivedBranchName, currentRevision); } return renameRef(repo, refLogIdent, existingBranchRef.getName(), archivedBranchName); }
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. jav a2s . 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 ww . ja v a 2s. c o m * 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.TestKSRevision65409To65443.java
License:Educational Community License
@Test public void testImport() throws IOException, BranchRefExistsException { runImporter(repository, 65409);// www.ja v a 2s . c o m // test that the ks-ap/trunk branch was created GitTestUtils.assertRefNotNull(repository, "enrollment_ks-ap_trunk", "ks-ap trunk should exist"); GitTestUtils.assertPathsExist(repository, "enrollment_ks-ap_trunk", Arrays.asList(new String[] { "ks-ap-ui/src/main/resources", "ks-ap-web" })); // inject copyfrom data for enrollment/ks-ap/trunk from 65424 runImporter(repository, 65425); // ks-ap trunk should have been deleted GitTestUtils.assertRefNull(repository, "enrollment_ks-ap_trunk", "ks-ap trunk should be null (deleted)"); GitTestUtils.assertRefNotNull(repository, "enrollment_ks-ap_branches_inactive_KSAP", "enrollment_ks-ap_branches_inactive_KSAP should exist"); GitTestUtils.assertRefNotNull(repository, "enrollment_ks-ap_trunk@65424", "enrollment_ks-ap_trunk@65424 should exist"); GitTestUtils.assertPathsExist(repository, "enrollment_ks-ap_trunk@65424", Arrays.asList(new String[] { "ks-ap-ui/src/main/resources", "ks-ap-web" })); /* * thinking about creating a branch here for ks-ap/branches/inactive/KSAP-M8 */ GitTestUtils.createBranch(repository, Constants.R_HEADS + "enrollment_ks-ap_branches_inactive_KSAP-M8", "pom.xml", "some text"); GitTestUtils.assertRefNotNull(repository, "enrollment_ks-ap_branches_inactive_KSAP-M8", "enrollment_ks-ap_branches_inactive_KSAP-M8 should exist"); GitTestUtils.assertPathsExist(repository, "enrollment_ks-ap_branches_inactive_KSAP-M8", Arrays.asList(new String[] { "pom.xml" })); // 65430 runImporter(repository, 65431); GitTestUtils.assertRefNotNull(repository, Constants.R_HEADS + "enrollment_ks-ap_trunk", "expected ks-ap trunk to exist"); GitTestUtils.assertPathsExist(repository, "enrollment_ks-ap_trunk", Arrays .asList(new String[] { "KSAP", "KSAP-M8", "KSAP/ks-ap-ui/src/main/resources", "KSAP-M8/pom.xml" })); GitTestUtils.assertRefNull(repository, Constants.R_HEADS + "enrollment_ks-ap_branches_inactive_KSAP", "expected ks-ap inactive KSAP to not exist"); GitTestUtils.assertRefNull(repository, Constants.R_HEADS + "enrollment_ks-ap_branches_inactive_KSAP-M8", "expected ks-ap inactive KSAP-M8 to not exist"); runImporter(repository, 65434); // we expect nothing to happen because its just a directory add. (not a copy from) GitTestUtils.createBranch(repository, Constants.R_HEADS + "enrollment_ks-ap_branches_KSAP-M7", "pom.xml", "some text"); runImporter(repository, 65435); GitTestUtils.assertRefNotNull(repository, Constants.R_HEADS + "enrollment_ks-ap_branches_inactive_KSAP-M7", "expected ks-ap trunk to exist"); GitTestUtils.assertPathsExist(repository, "enrollment_ks-ap_branches_inactive_KSAP-M7", Arrays.asList(new String[] { "pom.xml" })); GitTestUtils.assertRefNull(repository, Constants.R_HEADS + "enrollment_ks-ap_branches_KSAP-M7", "expected ks-ap KSAP-M7 to not exist"); GitTestUtils.createBranch(repository, Constants.R_HEADS + "enrollment_ks-ap_branches_KSAP-archived-2013-09-25", "pom.xml", "some text"); runImporter(repository, 65437); GitTestUtils.assertRefNotNull(repository, Constants.R_HEADS + "enrollment_ks-ap_branches_inactive_KSAP-archived-2013-09-25", "expected ks-ap braches inactive KSAP-2013-09-25 to exist"); GitTestUtils.assertRefNull(repository, Constants.R_HEADS + "enrollment_ks-ap_branches_KSAP-archived-2013-09-25", "expected ks-ap KSAP-archived-2013-09-25 to not exist"); runImporter(repository, 65439); GitTestUtils.assertRefNotNull(repository, Constants.R_HEADS + "enrollment_ks-ap_inactive", "expected ks-ap inactive to exist"); // assert file does not exist in a specific branch // assertRefNull(repository, "enrollment, notNullMessage); runImporter(repository, 65440); GitTestUtils.assertRefNotNull(repository, Constants.R_HEADS + "enrollment_ks-ap_branches_KSAP", "expected ks-ap branches KSAP to exist"); GitTestUtils.assertRefNull(repository, Constants.R_HEADS + "enrollment_ks-ap_inactive", "expected ks-ap inactive to not exist"); runImporter(repository, 65441); GitTestUtils.assertRefNotNull(repository, Constants.R_HEADS + "enrollment_ks-ap_branches_KSAP-M8", "expected ks-ap branches KSAP-M8 to exist"); GitTestUtils.assertPathsExist(repository, "enrollment_ks-ap_branches_KSAP-M8", Arrays.asList(new String[] { "pom.xml" })); // check that the // assertRefNull(repository, Constants.R_HEADS + "enrollment_ks-ap_inactive", "expected ks-ap inactive to not exist"); runImporter(repository, 65442); GitTestUtils.assertRefNull(repository, Constants.R_HEADS + "enrollment_ks-ap_trunk", "expected ks-ap trunk to not exist"); runImporter(repository, 65443); GitTestUtils.assertRefNotNull(repository, Constants.R_HEADS + "enrollment_ks-ap_trunk", "expected ks-ap trunk to exist"); GitTestUtils.assertRefNull(repository, Constants.R_HEADS + "enrollment_ks-ap_branches_KSAP", "expected ks-ap branches KSAP to not exist"); }
From source file:org.kuali.student.git.model.TestSvnRevisionMapper.java
License:Educational Community License
@Test public void testTwoRevisions() throws IOException { List<Ref> branchHeads = new ArrayList<Ref>(repo.getRefDatabase().getRefs(Constants.R_HEADS).values()); for (int i = 0; i < 500; i++) { createRevision(i, branchHeads);/*www. j av a 2 s .c o m*/ } Random r = new Random(); for (int i = 0; i < 500; i++) { int randomRevision = r.nextInt(499); testRevision(randomRevision, branchHeads); } revisionMapper.repackMapFile(); for (int i = 0; i < 500; i++) { int randomRevision = r.nextInt(499); testRevision(randomRevision, branchHeads); } for (int i = 500; i < 1000; i++) { createRevision(i, branchHeads); } for (int i = 0; i < 1000; i++) { int randomRevision = r.nextInt(999); testRevision(randomRevision, branchHeads); } ObjectId head = revisionMapper.getRevisionBranchHead(98, "master"); Assert.assertNotNull("name should never be null", head); List<SvnRevisionMap> heads = revisionMapper.getRevisionHeads(650); Assert.assertEquals(1, heads.size()); revisionMapper.shutdown(); revisionMapper = new SvnRevisionMapper(repo); revisionMapper.initialize(); for (int i = 0; i < 1000; i++) { int randomRevision = r.nextInt(999); testRevision(randomRevision, branchHeads); } for (int i = 1000; i < 1500; i++) { createRevision(i, branchHeads); } revisionMapper.repackMapFile(); for (int i = 0; i < 1499; i++) { int randomRevision = r.nextInt(1499); testRevision(randomRevision, branchHeads); } }
From source file:org.kuali.student.git.model.TestSvnRevisionMapper.java
License:Educational Community License
@Test public void testTruncate() throws IOException { List<Ref> branchHeads = new ArrayList<Ref>(repo.getRefDatabase().getRefs(Constants.R_HEADS).values()); // create 500 revs for (int i = 0; i < 500; i++) { createRevision(i, branchHeads);/*from w ww .ja va 2 s. co m*/ } Random r = new Random(); // test 500 revs for (int i = 0; i < 500; i++) { int randomRevision = r.nextInt(499); testRevision(randomRevision, branchHeads); } revisionMapper.truncateTo(250); // test first 250 still work for (int i = 0; i < 250; i++) { int randomRevision = r.nextInt(250); testRevision(randomRevision, branchHeads); } // confirm 251 does not exist boolean expectToFail = testRevisionHead(251, branchHeads); Assert.assertEquals(false, expectToFail); // insert another 250 (total is now 500) for (int i = 250; i < 500; i++) { createRevision(i, branchHeads); } // test that all 500 revs work again. for (int i = 0; i < 500; i++) { int randomRevision = r.nextInt(499); testRevision(randomRevision, branchHeads); } }