Java Code Examples for org.eclipse.jgit.lib.ObjectId#equals()
The following examples show how to use
org.eclipse.jgit.lib.ObjectId#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RevWalk.java From onedev with MIT License | 6 votes |
/** * Reads the "shallow" file and applies it by setting the parents of shallow * commits to an empty array. * <p> * There is a sequencing problem if the first commit being parsed is a * shallow commit, since {@link RevCommit#parseCanonical(RevWalk, byte[])} * calls this method before its callers add the new commit to the * {@link RevWalk#objects} map. That means a call from this method to * {@link #lookupCommit(AnyObjectId)} fails to find that commit and creates * a new one, which is promptly discarded. * <p> * To avoid that, {@link RevCommit#parseCanonical(RevWalk, byte[])} passes * its commit to this method, so that this method can apply the shallow * state to it directly and avoid creating the duplicate commit object. * * @param rc * the initial commit being parsed * @throws IOException * if the shallow commits file can't be read */ void initializeShallowCommits(RevCommit rc) throws IOException { if (shallowCommitsInitialized) { throw new IllegalStateException( JGitText.get().shallowCommitsAlreadyInitialized); } shallowCommitsInitialized = true; if (reader == null) { return; } for (ObjectId id : reader.getShallowCommits()) { if (id.equals(rc.getId())) { rc.parents = RevCommit.NO_PARENTS; } else { lookupCommit(id).parents = RevCommit.NO_PARENTS; } } }
Example 2
Source File: ResolveMerger.java From onedev with MIT License | 5 votes |
private RawText getRawText(ObjectId id, Attributes attributes) throws IOException, BinaryBlobException { if (id.equals(ObjectId.zeroId())) return new RawText(new byte[] {}); ObjectLoader loader = LfsFactory.getInstance().applySmudgeFilter( getRepository(), reader.open(id, OBJ_BLOB), attributes.get(Constants.ATTR_MERGE)); int threshold = PackConfig.DEFAULT_BIG_FILE_THRESHOLD; return RawText.load(loader, threshold); }
Example 3
Source File: MergePreview.java From onedev with MIT License | 5 votes |
public void syncRef(PullRequest request) { Project project = request.getTargetProject(); ObjectId mergedId = getMergeCommitHash()!=null? ObjectId.fromString(getMergeCommitHash()): null; RefUpdate refUpdate = GitUtils.getRefUpdate(project.getRepository(), request.getMergeRef()); if (mergedId != null && !mergedId.equals((project.getObjectId(request.getMergeRef(), false)))) { refUpdate.setNewObjectId(mergedId); GitUtils.updateRef(refUpdate); } else if (mergeCommitHash == null && project.getObjectId(request.getMergeRef(), false) != null) { GitUtils.deleteRef(refUpdate); } }
Example 4
Source File: PullRequest.java From onedev with MIT License | 5 votes |
private boolean contains(ObjectId commitId) { if (commitId.equals(getBaseCommit())) return true; for (PullRequestUpdate update: getUpdates()) { for (RevCommit commit: update.getCommits()) { if (commit.equals(commitId)) return true; } } return false; }
Example 5
Source File: TagCreateTrigger.java From onedev with MIT License | 5 votes |
@Override public SubmitReason matchesWithoutProject(ProjectEvent event, Job job) { if (event instanceof RefUpdated) { RefUpdated refUpdated = (RefUpdated) event; String updatedTag = GitUtils.ref2tag(refUpdated.getRefName()); ObjectId commitId = refUpdated.getNewCommitId(); Project project = event.getProject(); if (updatedTag != null && !commitId.equals(ObjectId.zeroId()) && (tags == null || PatternSet.parse(tags).matches(new PathMatcher(), updatedTag)) && (branches == null || project.isCommitOnBranches(commitId, branches))) { return new SubmitReason() { @Override public String getUpdatedRef() { return refUpdated.getRefName(); } @Override public PullRequest getPullRequest() { return null; } @Override public String getDescription() { return "Tag '" + updatedTag + "' is created"; } }; } } return null; }
Example 6
Source File: LastCommitsOfChildrenTest.java From onedev with MIT License | 5 votes |
@Test public void testWithCache() throws Exception { addFileAndCommit("initial", "", "initial commit"); git.checkout().setName("feature1").setCreateBranch(true).call(); addFileAndCommit("feature1", "", "add feature1"); git.checkout().setName("master").call(); addFileAndCommit("master", "", "add master"); git.merge().include(git.getRepository().resolve("feature1")).setCommit(true).call(); final ObjectId oldId = git.getRepository().resolve("master"); final LastCommitsOfChildren oldLastCommits = new LastCommitsOfChildren(git.getRepository(), oldId); Cache cache = new Cache() { @Override public Map<String, Value> getLastCommitsOfChildren(ObjectId commitId) { if (commitId.equals(oldId)) return oldLastCommits; else return null; } }; assertEquals(oldLastCommits, new LastCommitsOfChildren(git.getRepository(), oldId, cache)); git.checkout().setName("feature2").setCreateBranch(true).call(); addFileAndCommit("initial", "hello", "modify initial"); git.checkout().setName("master").call(); git.merge().include(git.getRepository().resolve("feature2")).setCommit(true).call(); ObjectId newId = git.getRepository().resolve("master"); assertEquals(new LastCommitsOfChildren(git.getRepository(), newId), new LastCommitsOfChildren(git.getRepository(), newId, cache)); }
Example 7
Source File: StatusCommand.java From netbeans with Apache License 2.0 | 5 votes |
private GitStatus.Status getGitlinkStatus (int mode1, ObjectId id1, int mode2, ObjectId id2) { if (mode1 == FileMode.TYPE_GITLINK || mode2 == FileMode.TYPE_GITLINK) { if (mode1 == FileMode.TYPE_MISSING) { return GitStatus.Status.STATUS_REMOVED; } else if (mode2 == FileMode.TYPE_MISSING) { return GitStatus.Status.STATUS_ADDED; } else if (!id1.equals(id2)) { return GitStatus.Status.STATUS_MODIFIED; } } return GitStatus.Status.STATUS_NORMAL; }
Example 8
Source File: PullRequest.java From onedev with MIT License | 4 votes |
public ObjectId getComparisonBase(ObjectId oldCommitId, ObjectId newCommitId) { if (isNew() || oldCommitId.equals(newCommitId)) return oldCommitId; PullRequestInfoManager infoManager = OneDev.getInstance(PullRequestInfoManager.class); ObjectId comparisonBase = infoManager.getComparisonBase(this, oldCommitId, newCommitId); if (comparisonBase != null) { try { if (!getTargetProject().getRepository().getObjectDatabase().has(comparisonBase)) comparisonBase = null; } catch (IOException e) { throw new RuntimeException(e); } } if (comparisonBase == null) { for (PullRequestUpdate update: getSortedUpdates()) { if (update.getCommits().contains(newCommitId)) { ObjectId targetHead = ObjectId.fromString(update.getTargetHeadCommitHash()); Repository repo = getTargetProject().getRepository(); ObjectId mergeBase1 = GitUtils.getMergeBase(repo, targetHead, newCommitId); if (mergeBase1 != null) { ObjectId mergeBase2 = GitUtils.getMergeBase(repo, mergeBase1, oldCommitId); if (mergeBase2.equals(mergeBase1)) { comparisonBase = oldCommitId; break; } else if (mergeBase2.equals(oldCommitId)) { comparisonBase = mergeBase1; break; } else { PersonIdent person = new PersonIdent("OneDev", ""); comparisonBase = GitUtils.merge(repo, oldCommitId, mergeBase1, false, person, person, "helper commit", true); break; } } else { return oldCommitId; } } } if (comparisonBase != null) infoManager.cacheComparisonBase(this, oldCommitId, newCommitId, comparisonBase); else throw new IllegalSelectorException(); } return comparisonBase; }
Example 9
Source File: Utils.java From netbeans with Apache License 2.0 | 4 votes |
public static RawText getRawText (ObjectId id, ObjectDatabase db) throws IOException { if (id.equals(ObjectId.zeroId())) { return RawText.EMPTY_TEXT; } return new RawText(db.open(id, Constants.OBJ_BLOB).getCachedBytes()); }