comparison src/org/tmatesoft/hg/core/HgOutgoingCommand.java @ 192:e5407b5a586a

Incoming and Outgoing commands are alive
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 15 Apr 2011 03:17:03 +0200
parents cd3371670f0b
children 344e8d7e4d6e
comparison
equal deleted inserted replaced
191:b777502a06f5 192:e5407b5a586a
16 */ 16 */
17 package org.tmatesoft.hg.core; 17 package org.tmatesoft.hg.core;
18 18
19 import java.util.List; 19 import java.util.List;
20 20
21 import org.tmatesoft.hg.internal.RepositoryComparator;
22 import org.tmatesoft.hg.repo.HgChangelog;
23 import org.tmatesoft.hg.repo.HgRemoteRepository;
21 import org.tmatesoft.hg.repo.HgRepository; 24 import org.tmatesoft.hg.repo.HgRepository;
22 import org.tmatesoft.hg.util.CancelledException; 25 import org.tmatesoft.hg.util.CancelledException;
23 26
24 /** 27 /**
25 * 28 * Command to find out changes made in a local repository and missing at remote repository.
29 *
26 * @author Artem Tikhomirov 30 * @author Artem Tikhomirov
27 * @author TMate Software Ltd. 31 * @author TMate Software Ltd.
28 */ 32 */
29 public class HgOutgoingCommand { 33 public class HgOutgoingCommand {
30 private final HgRepository repo; 34
35 private final HgRepository localRepo;
36 private HgRemoteRepository remoteRepo;
31 private boolean includeSubrepo; 37 private boolean includeSubrepo;
38 private RepositoryComparator comparator;
32 39
33 public HgOutgoingCommand(HgRepository hgRepo) { 40 public HgOutgoingCommand(HgRepository hgRepo) {
34 repo = hgRepo; 41 localRepo = hgRepo;
35 } 42 }
36 43
37 /** 44 /**
45 * @param hgRemote remoteRepository to compare against
46 * @return <code>this</code> for convenience
47 */
48 public HgOutgoingCommand against(HgRemoteRepository hgRemote) {
49 remoteRepo = hgRemote;
50 comparator = null;
51 return this;
52 }
53
54 /**
55 * PLACEHOLDER, NOT IMPLEMENTED YET.
56 *
38 * Select specific branch to pull 57 * Select specific branch to pull
39 * @return <code>this</code> for convenience 58 * @return <code>this</code> for convenience
40 */ 59 */
41 public HgOutgoingCommand branch(String branch) { 60 public HgOutgoingCommand branch(String branch) {
42 throw HgRepository.notImplemented(); 61 throw HgRepository.notImplemented();
43 } 62 }
44 63
45 /** 64 /**
65 * PLACEHOLDER, NOT IMPLEMENTED YET.
46 * 66 *
47 * @return <code>this</code> for convenience 67 * @return <code>this</code> for convenience
48 */ 68 */
49 public HgOutgoingCommand subrepo(boolean include) { 69 public HgOutgoingCommand subrepo(boolean include) {
50 includeSubrepo = include; 70 includeSubrepo = include;
51 throw HgRepository.notImplemented(); 71 throw HgRepository.notImplemented();
52 } 72 }
53 73
74 /**
75 * Lightweight check for outgoing changes.
76 *
77 * @param context
78 * @return list on local nodes known to be missing at remote server
79 */
54 public List<Nodeid> executeLite(Object context) throws HgException, CancelledException { 80 public List<Nodeid> executeLite(Object context) throws HgException, CancelledException {
55 throw HgRepository.notImplemented(); 81 return getComparator(context).getLocalOnlyRevisions();
56 } 82 }
57 83
58 public void executeFull(HgLogCommand.Handler handler) throws HgException, CancelledException { 84 /**
59 throw HgRepository.notImplemented(); 85 * Complete information about outgoing changes
86 *
87 * @param handler delegate to process changes
88 */
89 public void executeFull(final HgLogCommand.Handler handler) throws HgException, CancelledException {
90 if (handler == null) {
91 throw new IllegalArgumentException("Delegate can't be null");
92 }
93 getComparator(handler).visitLocalOnlyRevisions(new ChangesetTransformer(localRepo, handler));
94 }
95
96 private RepositoryComparator getComparator(Object context) throws HgException, CancelledException {
97 if (remoteRepo == null) {
98 throw new IllegalArgumentException("Shall specify remote repository to compare against");
99 }
100 if (comparator == null) {
101 HgChangelog.ParentWalker pw = localRepo.getChangelog().new ParentWalker();
102 pw.init();
103 comparator = new RepositoryComparator(pw, remoteRepo);
104 comparator.compare(context);
105 }
106 return comparator;
60 } 107 }
61 } 108 }