/** * Returns the branch commit with the given or {@code null} if it does not * exist. * * @param r the revision of a commit. * @return the branch commit or {@code null} if it doesn't exist. */ @Nullable BranchCommit getCommit(@NotNull Revision r) { return commits.get(checkNotNull(r).asBranchRevision()); }
/** * Checks if this branch contains a commit with the given revision. * * @param r the revision of a commit. * @return <code>true</code> if this branch contains a commit with the given * revision; <code>false</code> otherwise. */ boolean containsCommit(@NotNull Revision r) { return commits.containsKey(checkNotNull(r).asBranchRevision()); }
/** * Checks if this branch contains a commit with the given revision. * * @param r the revision of a commit. * @return <code>true</code> if this branch contains a commit with the given * revision; <code>false</code> otherwise. */ boolean containsCommit(@NotNull Revision r) { return commits.containsKey(checkNotNull(r).asBranchRevision()); }
/** * Returns the branch commit with the given or {@code null} if it does not * exist. * * @param r the revision of a commit. * @return the branch commit or {@code null} if it doesn't exist. */ @Nullable BranchCommit getCommit(@NotNull Revision r) { return commits.get(checkNotNull(r).asBranchRevision()); }
/** * Creates a tracker for the given commit revision. * * @param r a commit revision. * @param isBranchCommit whether this is a branch commit. * @return a _lastRev tracker for the given commit revision. */ LastRevTracker createTracker(final @NotNull Revision r, final boolean isBranchCommit) { if (isBranchCommit && !disableBranches) { Revision branchRev = r.asBranchRevision(); return branches.getBranchCommit(branchRev); } else { return new LastRevTracker() { @Override public void track(String path) { unsavedLastRevisions.put(path, r); } }; } }
/** * Returns the base revision for the given branch revision <code>r</code>. * * @param r revision of a commit in this branch. * @return the base revision for <code>r</code>. * @throws IllegalArgumentException if <code>r</code> is not a commit of * this branch. */ @NotNull RevisionVector getBase(@NotNull Revision r) { BranchCommit c = commits.get(checkNotNull(r).asBranchRevision()); if (c == null) { throw new IllegalArgumentException( "Revision " + r + " is not a commit in this branch"); } return c.getBase(); }
/** * Returns the base revision for the given branch revision <code>r</code>. * * @param r revision of a commit in this branch. * @return the base revision for <code>r</code>. * @throws IllegalArgumentException if <code>r</code> is not a commit of * this branch. */ @NotNull RevisionVector getBase(@NotNull Revision r) { BranchCommit c = commits.get(checkNotNull(r).asBranchRevision()); if (c == null) { throw new IllegalArgumentException( "Revision " + r + " is not a commit in this branch"); } return c.getBase(); }
void branchCommit(@NotNull Iterable<Revision> revisions) { if (!revisions.iterator().hasNext()) { return; } String branchCommits = (String) get(BRANCH_COMMITS); if (branchCommits == null) { branchCommits = ""; } for (Revision r : revisions) { if (branchCommits.length() > 0) { branchCommits += ","; } branchCommits += asId(r.asBranchRevision()); hasBranchCommits = true; } put(BRANCH_COMMITS, branchCommits); }
void branchCommit(@NotNull Iterable<Revision> revisions) { if (!revisions.iterator().hasNext()) { return; } String branchCommits = (String) get(BRANCH_COMMITS); if (branchCommits == null) { branchCommits = ""; } for (Revision r : revisions) { if (branchCommits.length() > 0) { branchCommits += ","; } branchCommits += asId(r.asBranchRevision()); hasBranchCommits = true; } put(BRANCH_COMMITS, branchCommits); }
/** * Add the given {@code revisions} to the list of referenced journal entries * that contain paths of documents that must be invalidated. * * @param revisions the references to invalidate-only journal entries. */ void invalidate(@NotNull Iterable<Revision> revisions) { String value = (String) get(INVALIDATE_ONLY); if (value == null) { value = ""; } for (Revision r : revisions) { if (value.length() > 0) { value += ","; } value += asId(r.asBranchRevision()); } put(INVALIDATE_ONLY, value); }
/** * Add the given {@code revisions} to the list of referenced journal entries * that contain paths of documents that must be invalidated. * * @param revisions the references to invalidate-only journal entries. */ void invalidate(@NotNull Iterable<Revision> revisions) { String value = (String) get(INVALIDATE_ONLY); if (value == null) { value = ""; } for (Revision r : revisions) { if (value.length() > 0) { value += ","; } value += asId(r.asBranchRevision()); } put(INVALIDATE_ONLY, value); }
void updateBranch(@Nullable Revision rev) { if (rev == null) { return; } rev = rev.asBranchRevision(); if (branch != null && branch.containsCommit(rev) && readRevision.getBranchRevision().compareRevisionTime(rev) >= 0) { branchRev = Utils.max(branchRev, rev); } }
void updateBranch(@Nullable Revision rev) { if (rev == null) { return; } rev = rev.asBranchRevision(); if (branch != null && branch.containsCommit(rev) && readRevision.getBranchRevision().compareRevisionTime(rev) >= 0) { branchRev = Utils.max(branchRev, rev); } }
/** * @return the branch if this is a branch commit, otherwise {@code null}. */ @Nullable private Branch getBranch() { if (baseRevision == null || !baseRevision.isBranch()) { return null; } if (b == null) { b = nodeStore.getBranches().getBranch( new RevisionVector(revision.asBranchRevision())); } return b; }
/** * @return the branch if this is a branch commit, otherwise {@code null}. */ @Nullable private Branch getBranch() { if (baseRevision == null || !baseRevision.isBranch()) { return null; } if (b == null) { b = nodeStore.getBranches().getBranch( new RevisionVector(revision.asBranchRevision())); } return b; }
@NotNull RevisionVector rebase(@NotNull RevisionVector branchHead, @NotNull RevisionVector base) { checkNotNull(branchHead); checkNotNull(base); if (disableBranches) { return branchHead; } // TODO conflict handling Branch b = getBranches().getBranch(branchHead); if (b == null) { // empty branch return base.asBranchRevision(getClusterId()); } if (b.getBase(branchHead.getBranchRevision()).equals(base)) { return branchHead; } // add a pseudo commit to make sure current head of branch // has a higher revision than base of branch Revision head = newRevision().asBranchRevision(); b.rebase(head, base); return base.update(head); }
@NotNull RevisionVector rebase(@NotNull RevisionVector branchHead, @NotNull RevisionVector base) { checkNotNull(branchHead); checkNotNull(base); if (disableBranches) { return branchHead; } // TODO conflict handling Branch b = getBranches().getBranch(branchHead); if (b == null) { // empty branch return base.asBranchRevision(getClusterId()); } if (b.getBase(branchHead.getBranchRevision()).equals(base)) { return branchHead; } // add a pseudo commit to make sure current head of branch // has a higher revision than base of branch Revision head = newRevision().asBranchRevision(); b.rebase(head, base); return base.update(head); }
@Test public void update() { Revision rev1 = new Revision(1, 0, 1); RevisionVector rv = new RevisionVector(rev1); assertEquals(1, Iterables.size(rv)); assertSame(rv, rv.update(rev1)); Revision rev2 = new Revision(2, 0, 1); rv = rv.update(rev2); assertEquals(newHashSet(rev2), newHashSet(rv)); Revision rev3 = new Revision(3, 0, 2); rv = rv.update(rev3); assertEquals(newHashSet(rev2, rev3), newHashSet(rv)); rev3 = rev3.asBranchRevision(); rv = rv.update(rev3); assertEquals(newHashSet(rev2, rev3), newHashSet(rv)); }
@Test public void branchCommit() { RevisionVector baseRev = ns.getHeadRevision() .update(ns.newRevision().asBranchRevision()); CommitBuilder builder = new CommitBuilder(ns, baseRev); builder.addNode("/foo"); Revision commitRev = ns.newRevision(); Commit c = builder.build(commitRev); UpdateOp up = c.getUpdateOperationForNode("/foo"); UpdateOp.Operation op = up.getChanges().get( new UpdateOp.Key("_bc", commitRev)); assertNotNull(op); }
@Test public void asBranchRevision3() { Revision r11 = new Revision(1, 0, 1); Revision br11 = r11.asBranchRevision(); RevisionVector rv = new RevisionVector(r11); assertEquals(new RevisionVector(br11), rv.asBranchRevision(1)); rv = rv.asTrunkRevision(); Revision r12 = new Revision(1, 0, 2); rv = rv.update(r12); assertEquals(new RevisionVector(br11, r12), rv.asBranchRevision(1)); }