comparison src/org/tmatesoft/hg/core/HgPushCommand.java @ 652:cd77bf51b562

Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 02 Jul 2013 23:21:16 +0200
parents 3b275cc2d2aa
children 629a7370554c
comparison
equal deleted inserted replaced
651:6e98d34eaca8 652:cd77bf51b562
100 if (phaseHelper.isCapableOfPhases()) { 100 if (phaseHelper.isCapableOfPhases()) {
101 RevisionSet presentSecret = phaseHelper.allSecret(); 101 RevisionSet presentSecret = phaseHelper.allSecret();
102 RevisionSet presentDraft = phaseHelper.allDraft(); 102 RevisionSet presentDraft = phaseHelper.allDraft();
103 RevisionSet secretLeft, draftLeft; 103 RevisionSet secretLeft, draftLeft;
104 HgRemoteRepository.Phases remotePhases = remoteRepo.getPhases(); 104 HgRemoteRepository.Phases remotePhases = remoteRepo.getPhases();
105 RevisionSet remoteDrafts = knownRemoteDrafts(remotePhases, parentHelper, outgoing); 105 RevisionSet remoteDrafts = knownRemoteDrafts(remotePhases, parentHelper, outgoing, presentSecret);
106 if (remotePhases.isPublishingServer()) { 106 if (remotePhases.isPublishingServer()) {
107 // although it's unlikely outgoing would affect secret changesets, 107 // although it's unlikely outgoing would affect secret changesets,
108 // it doesn't hurt to check secret roots along with draft ones 108 // it doesn't hurt to check secret roots along with draft ones
109 secretLeft = presentSecret.subtract(outgoing); 109 secretLeft = presentSecret.subtract(outgoing);
110 draftLeft = presentDraft.subtract(outgoing); 110 draftLeft = presentDraft.subtract(outgoing);
134 * remote draft 134 * remote draft
135 * 135 *
136 * Local draft roots shall be updated 136 * Local draft roots shall be updated
137 */ 137 */
138 RevisionSet sharedDraft = presentDraft.intersect(remoteDrafts); // (I: ~presentDraft; II: ~remoteDraft 138 RevisionSet sharedDraft = presentDraft.intersect(remoteDrafts); // (I: ~presentDraft; II: ~remoteDraft
139 // XXX do I really need sharedDrafts here? why not ancestors(remoteDrafts)?
139 RevisionSet localDraftRemotePublic = presentDraft.ancestors(sharedDraft, parentHelper); // I: 0; II: those treated public on remote 140 RevisionSet localDraftRemotePublic = presentDraft.ancestors(sharedDraft, parentHelper); // I: 0; II: those treated public on remote
141 // remoteDrafts are local revisions known as draft@remote
142 // remoteDraftsLocalPublic - revisions that would cease to be listed as draft on remote
143 RevisionSet remoteDraftsLocalPublic = remoteDrafts.ancestors(sharedDraft, parentHelper);
144 RevisionSet remoteDraftsLeft = remoteDrafts.subtract(remoteDraftsLocalPublic);
140 // forget those deemed public by remote (drafts shared by both remote and local are ok to stay) 145 // forget those deemed public by remote (drafts shared by both remote and local are ok to stay)
141 draftLeft = presentDraft.subtract(localDraftRemotePublic); 146 RevisionSet combinedDraft = presentDraft.union(remoteDraftsLeft);
147 draftLeft = combinedDraft.subtract(localDraftRemotePublic);
142 } 148 }
143 final RevisionSet newDraftRoots = draftLeft.roots(parentHelper); 149 final RevisionSet newDraftRoots = draftLeft.roots(parentHelper);
144 final RevisionSet newSecretRoots = secretLeft.roots(parentHelper); 150 final RevisionSet newSecretRoots = secretLeft.roots(parentHelper);
145 phaseHelper.updateRoots(newDraftRoots.asList(), newSecretRoots.asList()); 151 phaseHelper.updateRoots(newDraftRoots.asList(), newSecretRoots.asList());
146 // 152 //
190 } finally { 196 } finally {
191 progress.done(); 197 progress.done();
192 } 198 }
193 } 199 }
194 200
195 private RevisionSet knownRemoteDrafts(HgRemoteRepository.Phases remotePhases, HgParentChildMap<HgChangelog> parentHelper, RevisionSet outgoing) { 201 private RevisionSet knownRemoteDrafts(HgRemoteRepository.Phases remotePhases, HgParentChildMap<HgChangelog> parentHelper, RevisionSet outgoing, RevisionSet localSecret) {
196 ArrayList<Nodeid> knownRemoteDraftRoots = new ArrayList<Nodeid>(); 202 ArrayList<Nodeid> knownRemoteDraftRoots = new ArrayList<Nodeid>();
197 for (Nodeid rdr : remotePhases.draftRoots()) { 203 for (Nodeid rdr : remotePhases.draftRoots()) {
198 if (parentHelper.knownNode(rdr)) { 204 if (parentHelper.knownNode(rdr)) {
199 knownRemoteDraftRoots.add(rdr); 205 knownRemoteDraftRoots.add(rdr);
200 } 206 }
201 } 207 }
202 // knownRemoteDraftRoots + childrenOf(knownRemoteDraftRoots) is everything remote may treat as Draft 208 // knownRemoteDraftRoots + childrenOf(knownRemoteDraftRoots) is everything remote may treat as Draft
203 RevisionSet remoteDrafts = new RevisionSet(knownRemoteDraftRoots); 209 RevisionSet remoteDrafts = new RevisionSet(knownRemoteDraftRoots);
204 remoteDrafts = remoteDrafts.union(remoteDrafts.children(parentHelper)); 210 RevisionSet localChildren = remoteDrafts.children(parentHelper);
211 // we didn't send any local secret revision
212 localChildren = localChildren.subtract(localSecret);
213 // draft roots are among remote drafts
214 remoteDrafts = remoteDrafts.union(localChildren);
205 // 1) outgoing.children gives all local revisions accessible from outgoing. 215 // 1) outgoing.children gives all local revisions accessible from outgoing.
206 // 2) outgoing.roots.children is equivalent with smaller intermediate set, the way we build 216 // 2) outgoing.roots.children is equivalent with smaller intermediate set, the way we build
207 // childrenOf doesn't really benefits from that. 217 // childrenOf doesn't really benefits from that.
208 RevisionSet localChildrenNotSent = outgoing.children(parentHelper).subtract(outgoing); 218 RevisionSet localChildrenNotSent = outgoing.children(parentHelper).subtract(outgoing);
209 // remote shall know only what we've sent, subtract revisions we didn't actually sent 219 // remote shall know only what we've sent, subtract revisions we didn't actually sent