comparison hg4j/src/main/java/org/tmatesoft/hg/core/HgOutgoingCommand.java @ 213:6ec4af642ba8 gradle

Project uses Gradle for build - actual changes
author Alexander Kitaev <kitaev@gmail.com>
date Tue, 10 May 2011 10:52:53 +0200
parents
children
comparison
equal deleted inserted replaced
212:edb2e2829352 213:6ec4af642ba8
1 /*
2 * Copyright (c) 2011 TMate Software Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com
16 */
17 package org.tmatesoft.hg.core;
18
19 import java.util.List;
20 import java.util.Set;
21 import java.util.TreeSet;
22
23 import org.tmatesoft.hg.internal.RepositoryComparator;
24 import org.tmatesoft.hg.repo.HgChangelog;
25 import org.tmatesoft.hg.repo.HgRemoteRepository;
26 import org.tmatesoft.hg.repo.HgRepository;
27 import org.tmatesoft.hg.util.CancelledException;
28
29 /**
30 * Command to find out changes made in a local repository and missing at remote repository.
31 *
32 * @author Artem Tikhomirov
33 * @author TMate Software Ltd.
34 */
35 public class HgOutgoingCommand {
36
37 private final HgRepository localRepo;
38 private HgRemoteRepository remoteRepo;
39 @SuppressWarnings("unused")
40 private boolean includeSubrepo;
41 private RepositoryComparator comparator;
42 private HgChangelog.ParentWalker parentHelper;
43 private Set<String> branches;
44
45 public HgOutgoingCommand(HgRepository hgRepo) {
46 localRepo = hgRepo;
47 }
48
49 /**
50 * @param hgRemote remoteRepository to compare against
51 * @return <code>this</code> for convenience
52 */
53 public HgOutgoingCommand against(HgRemoteRepository hgRemote) {
54 remoteRepo = hgRemote;
55 comparator = null;
56 return this;
57 }
58
59 /**
60 * Select specific branch to pull.
61 * Multiple branch specification possible (changeset from any of these would be included in result).
62 * Note, {@link #executeLite(Object)} does not respect this setting.
63 *
64 * @param branch - branch name, case-sensitive, non-null.
65 * @return <code>this</code> for convenience
66 * @throws IllegalArgumentException when branch argument is null
67 */
68 public HgOutgoingCommand branch(String branch) {
69 if (branch == null) {
70 throw new IllegalArgumentException();
71 }
72 if (branches == null) {
73 branches = new TreeSet<String>();
74 }
75 branches.add(branch);
76 return this;
77 }
78
79 /**
80 * PLACEHOLDER, NOT IMPLEMENTED YET.
81 *
82 * @return <code>this</code> for convenience
83 */
84 public HgOutgoingCommand subrepo(boolean include) {
85 includeSubrepo = include;
86 throw HgRepository.notImplemented();
87 }
88
89 /**
90 * Lightweight check for outgoing changes.
91 * Reported changes are from any branch (limits set by {@link #branch(String)} are not taken into account.
92 *
93 * @param context
94 * @return list on local nodes known to be missing at remote server
95 */
96 public List<Nodeid> executeLite(Object context) throws HgException, CancelledException {
97 return getComparator(context).getLocalOnlyRevisions();
98 }
99
100 /**
101 * Complete information about outgoing changes
102 *
103 * @param handler delegate to process changes
104 */
105 public void executeFull(final HgChangesetHandler handler) throws HgException, CancelledException {
106 if (handler == null) {
107 throw new IllegalArgumentException("Delegate can't be null");
108 }
109 ChangesetTransformer inspector = new ChangesetTransformer(localRepo, handler, getParentHelper());
110 inspector.limitBranches(branches);
111 getComparator(handler).visitLocalOnlyRevisions(inspector);
112 }
113
114 private RepositoryComparator getComparator(Object context) throws HgException, CancelledException {
115 if (remoteRepo == null) {
116 throw new IllegalArgumentException("Shall specify remote repository to compare against");
117 }
118 if (comparator == null) {
119 comparator = new RepositoryComparator(getParentHelper(), remoteRepo);
120 comparator.compare(context);
121 }
122 return comparator;
123 }
124
125 private HgChangelog.ParentWalker getParentHelper() {
126 if (parentHelper == null) {
127 parentHelper = localRepo.getChangelog().new ParentWalker();
128 parentHelper.init();
129 }
130 return parentHelper;
131 }
132
133 }