List of usage examples for org.eclipse.jgit.lib ObjectId equals
@SuppressWarnings({ "NonOverridingEquals", "AmbiguousMethodReference" }) public final boolean equals(AnyObjectId other)
From source file:org.gitective.core.BlobUtils.java
License:Open Source License
/** * Diff the blobs at the given object ids. * <p>/*from w ww .ja v a2 s . co m*/ * This method will return an empty list if the content of either blob is * binary. * * @param repository * @param blob1 * @param blob2 * @param comparator * @return list of edits, never null */ public static Collection<Edit> diff(final Repository repository, final ObjectId blob1, final ObjectId blob2, final RawTextComparator comparator) { if (repository == null) throw new IllegalArgumentException(Assert.formatNotNull("Repository")); if (blob1 == null) throw new IllegalArgumentException(Assert.formatNotNull("Blob id 1")); if (blob2 == null) throw new IllegalArgumentException(Assert.formatNotNull("Blob id 2")); if (comparator == null) throw new IllegalArgumentException(Assert.formatNotNull("Comparator")); if (blob1.equals(blob2)) return Collections.emptyList(); final byte[] data1; if (!blob1.equals(ObjectId.zeroId())) { data1 = getBytes(repository, blob1); if (RawText.isBinary(data1)) return Collections.emptyList(); } else data1 = new byte[0]; final byte[] data2; if (!blob2.equals(ObjectId.zeroId())) { data2 = getBytes(repository, blob2); if (RawText.isBinary(data2)) return Collections.emptyList(); } else data2 = new byte[0]; return new HistogramDiff().diff(comparator, // data1.length > 0 ? new RawText(data1) : EMPTY_TEXT, // data2.length > 0 ? new RawText(data2) : EMPTY_TEXT); }
From source file:org.gitective.core.BlobUtils.java
License:Open Source License
/** * Diff the blobs at the given object ids. * <p>//from ww w . j a v a 2 s .c o m * This method will return an empty list if the content of either blob is * binary. * * @param reader * @param blob1 * @param blob2 * @param comparator * @return list of edits, never null */ public static Collection<Edit> diff(final ObjectReader reader, final ObjectId blob1, final ObjectId blob2, final RawTextComparator comparator) { if (reader == null) throw new IllegalArgumentException(Assert.formatNotNull("Reader")); if (blob1 == null) throw new IllegalArgumentException(Assert.formatNotNull("Blob id 1")); if (blob2 == null) throw new IllegalArgumentException(Assert.formatNotNull("Blob id 2")); if (comparator == null) throw new IllegalArgumentException(Assert.formatNotNull("Comparator")); if (blob1.equals(blob2)) return Collections.emptyList(); final byte[] data1; if (!blob1.equals(ObjectId.zeroId())) { data1 = getBytes(reader, blob1); if (RawText.isBinary(data1)) return Collections.emptyList(); } else data1 = new byte[0]; final byte[] data2; if (!blob2.equals(ObjectId.zeroId())) { data2 = getBytes(reader, blob2); if (RawText.isBinary(data2)) return Collections.emptyList(); } else data2 = new byte[0]; return new HistogramDiff().diff(comparator, // data1.length > 0 ? new RawText(data1) : EMPTY_TEXT, // data2.length > 0 ? new RawText(data2) : EMPTY_TEXT); }
From source file:org.gitective.core.filter.commit.DuplicateTreeFilter.java
License:Open Source License
public boolean include(final RevWalk walker, final RevCommit commit) throws IOException { final TreeWalk walk = TreeUtils.diffWithParents(walker, commit); final MutableObjectId id = new MutableObjectId(); final ObjectId zero = ObjectId.zeroId(); final DuplicateContainer dupes = new DuplicateContainer(commit); while (walk.next()) { if (!walk.isSubtree()) continue; final String path = walk.getPathString(); for (int i = 0; i < walk.getTreeCount(); i++) { walk.getObjectId(id, i);// w w w . j av a 2s . c o m if (!zero.equals(id)) dupes.include(id.toObjectId(), path); } walk.enterSubtree(); } if (dupes.validate()) duplicates.put(commit, dupes); return true; }
From source file:org.gitective.tests.TreeUtilsTest.java
License:Open Source License
/** * Get id with commit id// w w w . j ava 2s. c o m * * @throws Exception */ @Test public void getIdWithCommit() throws Exception { Repository repo = new FileRepository(testRepo); RevCommit commit = add("d1/f1.txt", "content"); assertNull(TreeUtils.getId(repo, commit, "d2/f1.txt")); assertNull(TreeUtils.getId(repo, commit, "d1/f1.txt")); ObjectId treeId = TreeUtils.getId(repo, commit, "d1"); assertNotNull(treeId); assertFalse(treeId.equals(commit.getTree())); assertNull(BlobUtils.getId(repo, commit, "d1")); assertFalse(treeId.equals(BlobUtils.getId(repo, commit, "d1/f1.txt"))); }
From source file:org.gitective.tests.TreeUtilsTest.java
License:Open Source License
/** * Get id with revision// w w w .j ava 2 s. c o m * * @throws Exception */ @Test public void getIdWithRevision() throws Exception { Repository repo = new FileRepository(testRepo); RevCommit commit = add("d1/f1.txt", "content"); assertNull(TreeUtils.getId(repo, Constants.MASTER, "d2/f1.txt")); assertNull(TreeUtils.getId(repo, Constants.MASTER, "d1/f1.txt")); ObjectId treeId = TreeUtils.getId(repo, Constants.MASTER, "d1"); assertNotNull(treeId); assertFalse(treeId.equals(commit.getTree())); assertNull(BlobUtils.getId(repo, commit, "d1")); assertFalse(treeId.equals(BlobUtils.getId(repo, commit, "d1/f1.txt"))); }
From source file:org.jenkinsci.git.PollOperation.java
License:Open Source License
public PollingResult invoke(File file, VirtualChannel channel) throws IOException, InterruptedException { for (BuildRepository repo : repos) { Repository gitRepo = new FileRepositoryOperation(repo).invoke(file, channel); if (gitRepo == null) return PollingResult.BUILD_NOW; LsRemoteOperation op = new LsRemoteOperation(repo, gitRepo); ObjectId latest = op.call(); if (latest == null) return PollingResult.BUILD_NOW; ObjectId current = state.get(repo); if (current == null) return PollingResult.BUILD_NOW; if (!latest.equals(current)) return PollingResult.SIGNIFICANT; }//w w w . j av a2 s. co m return PollingResult.NO_CHANGES; }
From source file:org.kercoin.magrit.core.user.UserIdentityServiceImpl.java
License:Open Source License
@Override public UserIdentity find(String login) throws AccessControlException { try {//from www.j a va2 s. c o m open(); ObjectId v = datasource.resolve("HEAD:users.properties"); if (v == null) { throw new AccessControlException( String.format("User '%s' not found in authentication database.", login)); } if (!v.equals(lastVersion)) { data.clear(); data.load(new StringReader(gitUtils.show(datasource, "HEAD:users.properties"))); } String email = data.getProperty(String.format("user.%s.email", login)); String name = data.getProperty(String.format("user.%s.name", login)); if (email != null && name != null) { return new UserIdentity(email, name); } } catch (IOException e) { e.printStackTrace(); } finally { } return new UserIdentity(login + "@localhost", login); }
From source file:org.kuali.student.git.cleaner.RewriteFusionPluginData.java
License:Educational Community License
@Override protected boolean processCommitTree(RevCommit commit, GitTreeData tree) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { ObjectId fusionPluginDataBlobId = tree.find(getRepo(), "fusion-maven-plugin.dat"); boolean changesToBeCommitted = false; if (fusionPluginDataBlobId != null) { if (commit.getFullMessage().contains("@71661")) log.info("found target commit"); ObjectLoader loader = getRepo().newObjectReader().open(fusionPluginDataBlobId, Constants.OBJ_BLOB); // rewrite the data here List<ExternalModuleInfo> fusionData = ExternalModuleUtils .extractFusionMavenPluginData(loader.openStream()); for (ExternalModuleInfo fusion : fusionData) { ObjectId commitId = fusion.getBranchHeadId(); if (commitId == null) { log.warn("commit Id: " + commit.getId().name() + " is missing branch head for module: " + fusion.getModuleName() + " branch: " + fusion.getBranchPath()); continue; }//from w ww. ja v a 2 s . co m if (commitId.name().startsWith("8b608b677a5090080014374d11c0dba909")) log.info("target commit: " + commit.getId() + " refers to external: 8b608b677a5090080014374d11c0dba909"); // check where this originates from ObjectId newCommitId = this.translationService.translateObjectId(commitId); // will exist if the newCommitId from a previous rewite has been rewritted during the current rewrite ObjectId currentlyChangedId = this.originalCommitIdToNewCommitIdMap.get(newCommitId); if (currentlyChangedId != null) newCommitId = currentlyChangedId; if (newCommitId != null && !newCommitId.equals(commitId)) { fusion.setBranchHeadId(newCommitId); changesToBeCommitted = true; if (currentlyChangedId != null && !super.processedCommits.contains(newCommitId)) { log.warn("repo is missing a commit for " + newCommitId); } } else { // make sure that the commitId is still valid if its been changed if (super.originalCommitIdToNewCommitIdMap.keySet().contains(commitId) && !super.processedCommits.contains(commitId)) { log.warn("repo is missing a commit for " + commitId); } } } if (changesToBeCommitted) { // save it into the tree String updatedFusionData = ExternalModuleUtils.createFusionMavenPluginDataFileString(fusionData); ObjectId updatedBlobId = inserter.insert(Constants.OBJ_BLOB, updatedFusionData.getBytes()); tree.addBlob("fusion-maven-plugin.dat", updatedBlobId); return true; } else return false; } else return false; }
From source file:org.kuali.student.git.importer.GitImporterParseOptions.java
License:Educational Community License
private void flushPendingBranchCommits() { try {/*from w ww . j a v a 2 s.c om*/ RevWalk rw = new RevWalk(repo); List<GitBranchData> externalsAwareOrdering = ExternalsUtils .computeExternalsAwareOrdering(knownBranchMap.values()); for (GitBranchData data : externalsAwareOrdering) { String branchName = data.getBranchName(); if (data.getExternals().size() > 0) { ObjectInserter objectInserter = repo.newObjectInserter(); String fusionPluginDataString = ExternalModuleUtils.createFusionMavenPluginDataFileString( currentRevision, repo, data.getExternals(), revisionMapper); ObjectId id = objectInserter.insert(Constants.OBJ_BLOB, fusionPluginDataString.getBytes()); try { data.addBlob(data.getBranchPath() + "/" + "fusion-maven-plugin.dat", id, blobLog); } catch (VetoBranchException e) { // should never happen log.error("failed to add fusion-maven-plugin.dat to the branch skipping. branchName = " + data.getBranchName(), e); } objectInserter.flush(); objectInserter.release(); } else { // check for and remove if present. ObjectId blobId = data.findPath(repo, "fusion-maven-plugin.dat"); if (blobId != null) data.deletePath(data.getBranchPath() + "/" + "fusion-maven-plugin.dat", currentRevision); } Set<ObjectId> parentSet = new HashSet<ObjectId>(); ObjectId parentId = data.getParentId(); if (parentId != null) parentSet.add(parentId); parentSet.addAll(computeSvnMergeInfoParentIds(currentRevision, data)); parentSet.addAll(data.getMergeParentIds()); if (data.getBlobsAdded() == 0 && !data.isBlobsDeleted() && !data.isCreated() && !data.isTreeDirty()) { // check the parentId is the same Ref existingRef = repo.getRef(Constants.R_HEADS + data.getBranchName()); if (existingRef != null) { if (parentSet.size() > 0 && parentSet.contains(existingRef.getObjectId())) { /* * Directory changes can cause a branch data object * to be created but we really only want to save it * if blob's have been added or deleted. */ log.info("skipped commit on branch " + branchName + " at " + currentRevision + " due to no blob changes present."); continue; } } else { // existing Ref is null if (parentSet.size() == 0) { log.info("skipped commit on branch " + branchName + " at " + currentRevision + " due to no blob changes present."); continue; } // else fall through } // else fall through } // only flush if the branch has data to // commit for the current revision log.debug("branch = " + branchName + " has data to commit"); // create the commit CommitBuilder commitBuilder = new CommitBuilder(); ObjectInserter inserter = repo.newObjectInserter(); // create the tree ObjectId treeId = data.buildTree(inserter); log.debug("create new tree id = " + treeId.name()); commitBuilder.setTreeId(treeId); commitBuilder.setParentIds(Arrays.asList(parentSet.toArray(new ObjectId[] {}))); commitBuilder.setAuthor(commitData.getPersonIdent()); commitBuilder.setCommitter(commitData.getPersonIdent()); if (printGitSvnIds) { StringBuilder commitMessageBuilder = new StringBuilder(); commitMessageBuilder.append(commitData.getCommitMessage()); appendGitSvnId(commitMessageBuilder, repositoryBaseUrl, data.getBranchPath(), currentRevision, repositoryUUID); commitBuilder.setMessage(commitMessageBuilder.toString()); } else { // just the commit message commitBuilder.setMessage(commitData.getCommitMessage()); } ObjectId commitId = inserter.insert(commitBuilder); inserter.flush(); inserter.release(); // post commit update the branch reference. // create the branch in git String fullBranchNameReference = Constants.R_HEADS + data.getBranchName(); if (fullBranchNameReference.length() >= GitBranchUtils.FILE_SYSTEM_NAME_LIMIT) { fullBranchNameReference = Constants.R_HEADS + revisionMapper.storeLargeBranchName(fullBranchNameReference, currentRevision); } if (repo.getRefDatabase().isNameConflicting(fullBranchNameReference)) { log.warn(fullBranchNameReference + " is conflicting with an existing reference."); } Ref ref = GitRefUtils.createOrUpdateBranch(repo, fullBranchNameReference, commitId); ObjectId refObjectId = ref.getObjectId(); log.info(String.format("updated %s to %s", fullBranchNameReference, commitId.name())); if (!commitId.equals(refObjectId)) { log.warn("failed to update ref for " + branchName); } List<BranchMergeInfo> accumulatedMergeData = data.getAccumulatedBranchMergeData(); if (accumulatedMergeData.size() > 0) revisionMapper.createMergeData(currentRevision, data.getBranchPath(), accumulatedMergeData); repo.getRefDatabase().refresh(); } Map<String, Ref> headRefs = repo.getRefDatabase().getRefs(Constants.R_HEADS); List<Ref> refs = new ArrayList<Ref>(headRefs.values()); revisionMapper.createRevisionMap(currentRevision, refs); knownBranchMap.clear(); rw.release(); } catch (IOException e) { throw new RuntimeException("flushPendingBranchCommits failed on rev = " + currentRevision, e); } }
From source file:org.kuali.student.git.model.tree.GitTreeNodeData.java
License:Educational Community License
/** * Merge the content from the given node into ourself. * //from w ww .ja v a2s. c o m * If there is a collision then the merge will fail. * * @param node */ public boolean merge(GitTreeNodeData node) { // init ourself if needed. if (!initialized) initializeSubTrees(); // init the node to merge if needed if (!node.isInitialized()) { node.initializeSubTrees(); } boolean mergedSomething = false; // see if there are any new blobs to merge // skip over any overlapping blobs. for (Entry<String, ObjectId> entry : node.blobReferences.entrySet()) { String nodeBlobName = entry.getKey(); ObjectId nodeBlobId = entry.getValue(); ObjectId ourBlobId = this.blobReferences.get(nodeBlobName); if (ourBlobId == null) { // we don't have this blob this.blobReferences.put(nodeBlobName, nodeBlobId); mergedSomething = true; } else if (!ourBlobId.equals(nodeBlobId)) { // accept the overwrite this.blobReferences.put(nodeBlobName, nodeBlobId); log.warn(String.format( "blob collision during merge taking the node Blob data (name=%s, ourBlobId=%s, nodeBlobId=%s)", nodeBlobName, ourBlobId, nodeBlobId)); } } // check the subtrees. for (Entry<String, GitTreeNodeData> entry : node.subTreeReferences.entrySet()) { GitTreeNodeData nodeSubTree = entry.getValue(); GitTreeNodeData ourSubTree = this.subTreeReferences.get(nodeSubTree.getName()); if (ourSubTree == null) { // we don't have this tree this.subTreeReferences.put(nodeSubTree.getName(), nodeSubTree); mergedSomething = true; } else { if (ourSubTree.merge(nodeSubTree)) { mergedSomething = true; } } } // if something changed set the dirty flag // and transmit back up the path to the root. // so that the tree's touched by the change will // be persisted properly. if (mergedSomething) setDirty(true); return mergedSomething; }