comparison src/org/tmatesoft/hg/core/StatusCommand.java @ 68:0e499fed9b3d

StatusCommand with tests. Extra constants to indicate common revision cases
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sat, 22 Jan 2011 22:11:24 +0100
parents 19e9e220bf68
children 6f1b88693d48
comparison
equal deleted inserted replaced
67:64bddc2dcc0e 68:0e499fed9b3d
14 * the terms of a license other than GNU General Public License 14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@svnkit.com 15 * contact TMate Software at support@svnkit.com
16 */ 16 */
17 package org.tmatesoft.hg.core; 17 package org.tmatesoft.hg.core;
18 18
19 import static com.tmate.hgkit.ll.HgRepository.BAD_REVISION;
20 import static com.tmate.hgkit.ll.HgRepository.TIP;
21 import static com.tmate.hgkit.ll.HgRepository.WORKING_COPY;
22
19 import org.tmatesoft.hg.core.Path.Matcher; 23 import org.tmatesoft.hg.core.Path.Matcher;
24 import org.tmatesoft.hg.util.PathPool;
20 25
26 import com.tmate.hgkit.fs.FileWalker;
21 import com.tmate.hgkit.ll.HgRepository; 27 import com.tmate.hgkit.ll.HgRepository;
28 import com.tmate.hgkit.ll.LocalHgRepo;
29 import com.tmate.hgkit.ll.StatusCollector;
30 import com.tmate.hgkit.ll.WorkingCopyStatusCollector;
31 import com.tmate.hgkit.ll.StatusCollector.Record;
22 32
23 /** 33 /**
24 * 34 *
25 * @author Artem Tikhomirov 35 * @author Artem Tikhomirov
26 * @author TMate Software Ltd. 36 * @author TMate Software Ltd.
27 */ 37 */
28 public class StatusCommand { 38 public class StatusCommand {
29 private final HgRepository repo; 39 private final HgRepository repo;
30 40
31 private boolean needClean = false; 41 private boolean needModified;
32 private boolean needIgnored = false; 42 private boolean needAdded;
43 private boolean needRemoved;
44 private boolean needUnknown;
45 private boolean needMissing;
46 private boolean needClean;
47 private boolean needIgnored;
33 private Matcher matcher; 48 private Matcher matcher;
34 private int startRevision; 49 private int startRevision = TIP;
35 private Integer endRevision; // need three states, set, -1 or actual rev number 50 private int endRevision = WORKING_COPY;
36 private boolean visitSubRepo = true; 51 private boolean visitSubRepo = true;
37 52
38 public StatusCommand(HgRepository hgRepo) { 53 public StatusCommand(HgRepository hgRepo) {
39 this.repo = hgRepo; 54 repo = hgRepo;
55 defaults();
40 } 56 }
41 57
42 public StatusCommand all() { 58 public StatusCommand defaults() {
43 needClean = true; 59 needModified = needAdded = needRemoved = needUnknown = needMissing = true;
60 needClean = needIgnored = false;
44 return this; 61 return this;
45 } 62 }
63 public StatusCommand all() {
64 needModified = needAdded = needRemoved = needUnknown = needMissing = true;
65 needClean = needIgnored = true;
66 return this;
67 }
68
46 69
70 public StatusCommand modified(boolean include) {
71 needModified = include;
72 return this;
73 }
74 public StatusCommand added(boolean include) {
75 needAdded = include;
76 return this;
77 }
78 public StatusCommand removed(boolean include) {
79 needRemoved = include;
80 return this;
81 }
82 public StatusCommand deleted(boolean include) {
83 needMissing = include;
84 return this;
85 }
86 public StatusCommand unknown(boolean include) {
87 needUnknown = include;
88 return this;
89 }
47 public StatusCommand clean(boolean include) { 90 public StatusCommand clean(boolean include) {
48 needClean = include; 91 needClean = include;
49 return this; 92 return this;
50 } 93 }
51 public StatusCommand ignored(boolean include) { 94 public StatusCommand ignored(boolean include) {
52 needIgnored = include; 95 needIgnored = include;
53 return this; 96 return this;
54 } 97 }
55 98
56 // if set, either base:revision or base:workingdir 99 /**
100 * if set, either base:revision or base:workingdir
101 * to unset, pass {@link HgRepository#TIP} or {@link HgRepository#BAD_REVISION}
102 * @param revision
103 * @return
104 */
105
57 public StatusCommand base(int revision) { 106 public StatusCommand base(int revision) {
107 if (revision == WORKING_COPY) {
108 throw new IllegalArgumentException();
109 }
110 if (revision == BAD_REVISION) {
111 revision = TIP;
112 }
58 startRevision = revision; 113 startRevision = revision;
59 return this; 114 return this;
60 } 115 }
61 116
62 // revision without base == --change 117 /**
118 * Revision without base == --change
119 * Pass {@link HgRepository#WORKING_COPY} or {@link HgRepository#BAD_REVISION} to reset
120 * @param revision
121 * @return
122 */
63 public StatusCommand revision(int revision) { 123 public StatusCommand revision(int revision) {
64 // XXX how to clear endRevision, if needed. 124 if (revision == BAD_REVISION) {
65 // Perhaps, use of WC_REVISION or BAD_REVISION == -2 or Int.MIN_VALUE? 125 revision = WORKING_COPY;
66 endRevision = new Integer(revision); 126 }
127 // XXX negative values, except for predefined constants, shall throw IAE.
128 endRevision = revision;
67 return this; 129 return this;
68 } 130 }
69 131
70 public StatusCommand match(Path.Matcher pathMatcher) { 132 public StatusCommand match(Path.Matcher pathMatcher) {
71 matcher = pathMatcher; 133 matcher = pathMatcher;
75 public StatusCommand subrepo(boolean visit) { 137 public StatusCommand subrepo(boolean visit) {
76 visitSubRepo = visit; 138 visitSubRepo = visit;
77 throw HgRepository.notImplemented(); 139 throw HgRepository.notImplemented();
78 } 140 }
79 141
80 public void execute() { 142 public void execute(StatusCollector.Inspector inspector) {
81 throw HgRepository.notImplemented(); 143 StatusCollector sc = new StatusCollector(repo); // TODO from CommandContext
144 // StatusCollector.Record r = new StatusCollector.Record(); // XXX use own inspector not to collect entries that
145 // are not interesting or do not match name
146 if (endRevision == WORKING_COPY) {
147 WorkingCopyStatusCollector wcsc = new WorkingCopyStatusCollector(repo, ((LocalHgRepo) repo).createWorkingDirWalker());
148 wcsc.setBaseRevisionCollector(sc);
149 wcsc.walk(startRevision, inspector);
150 } else {
151 if (startRevision == TIP) {
152 sc.change(endRevision, inspector);
153 } else {
154 sc.walk(startRevision, endRevision, inspector);
155 }
156 }
157 // PathPool pathHelper = new PathPool(repo.getPathHelper()); // TODO from CommandContext
82 } 158 }
83 } 159 }