annotate src/org/tmatesoft/hg/core/HgAddRemoveCommand.java @ 614:1d1e96f5a908

Added tag v1.1m4 for changeset f41dd9a3b8af
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 10 May 2013 17:31:54 +0200
parents f41dd9a3b8af
children 65c01508f002
rev   line source
529
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.core;
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import java.util.LinkedHashSet;
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import org.tmatesoft.hg.internal.DirstateBuilder;
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import org.tmatesoft.hg.internal.DirstateReader;
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import org.tmatesoft.hg.internal.Internals;
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import org.tmatesoft.hg.repo.HgManifest.Flags;
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import org.tmatesoft.hg.repo.HgRepository;
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import org.tmatesoft.hg.repo.HgRuntimeException;
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
27 import org.tmatesoft.hg.util.CancelSupport;
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
28 import org.tmatesoft.hg.util.CancelledException;
529
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import org.tmatesoft.hg.util.Path;
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
30 import org.tmatesoft.hg.util.ProgressSupport;
529
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 /**
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 * Schedule files for addition and removal
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 * XXX and, perhaps, forget() functionality shall be here as well?
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 *
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 * @since 1.1
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 * @author Artem Tikhomirov
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 * @author TMate Software Ltd.
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 */
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 public class HgAddRemoveCommand extends HgAbstractCommand<HgAddRemoveCommand> {
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 private final HgRepository repo;
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 private final LinkedHashSet<Path> toAdd, toRemove;
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 public HgAddRemoveCommand(HgRepository hgRepo) {
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 repo = hgRepo;
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 toAdd = new LinkedHashSet<Path>();
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 toRemove = new LinkedHashSet<Path>();
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 }
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 /**
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 * Schedule specified files to get listed in dirstate as added
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 *
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 * @param paths files to mark as added, additive
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 * @return <code>this</code> for convenience
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 */
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 public HgAddRemoveCommand add(Path... paths) {
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 if (paths == null) {
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 throw new IllegalArgumentException();
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 }
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 for (Path p : paths) {
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 toRemove.remove(p);
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 toAdd.add(p);
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 }
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 return this;
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 }
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 /**
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 * Schedule specified files to be marked as removed
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 *
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 * @param paths files to mark as removed, additive
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 * @return <code>this</code> for convenience
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 */
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 public HgAddRemoveCommand remove(Path... paths) {
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 if (paths == null) {
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 throw new IllegalArgumentException();
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 }
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 for (Path p : paths) {
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 toAdd.remove(p);
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 toRemove.add(p);
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 }
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 return this;
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 }
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 public HgAddRemoveCommand addAll() {
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 throw Internals.notImplemented();
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 }
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 public HgAddRemoveCommand forget(Path path) {
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 throw Internals.notImplemented();
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 }
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 /**
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 * Perform scheduled addition/removal
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 *
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
96 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
97 * @throws CancelledException if execution of the command was cancelled
529
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 */
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
99 public void execute() throws HgException, CancelledException {
529
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 try {
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
101 final ProgressSupport progress = getProgressSupport(null);
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
102 final CancelSupport cancellation = getCancelSupport(null, true);
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
103 cancellation.checkCancelled();
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
104 progress.start(2 + toAdd.size() + toRemove.size());
529
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 Internals implRepo = Internals.getInstance(repo);
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 final DirstateBuilder dirstateBuilder = new DirstateBuilder(implRepo);
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 dirstateBuilder.fillFrom(new DirstateReader(implRepo, new Path.SimpleSource()));
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
108 progress.worked(1);
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
109 cancellation.checkCancelled();
529
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 for (Path p : toAdd) {
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 dirstateBuilder.recordAdded(p, Flags.RegularFile, -1);
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
112 progress.worked(1);
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
113 cancellation.checkCancelled();
529
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 }
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 for (Path p : toRemove) {
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 dirstateBuilder.recordRemoved(p);
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
117 progress.worked(1);
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
118 cancellation.checkCancelled();
529
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 }
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 dirstateBuilder.serialize();
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
121 progress.worked(1);
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 529
diff changeset
122 progress.done();
529
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 } catch (HgRuntimeException ex) {
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 throw new HgLibraryFailureException(ex);
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 }
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 }
95bdcf75e71e Command to schedule addition/removal of repository files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 }