Mercurial > jhg
comparison src/org/tmatesoft/hg/core/HgAddRemoveCommand.java @ 529:95bdcf75e71e
Command to schedule addition/removal of repository files
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Mon, 21 Jan 2013 19:41:51 +0100 |
| parents | |
| children | 0890628ed51e |
comparison
equal
deleted
inserted
replaced
| 528:f7fbf48b9383 | 529:95bdcf75e71e |
|---|---|
| 1 /* | |
| 2 * Copyright (c) 2013 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.LinkedHashSet; | |
| 20 | |
| 21 import org.tmatesoft.hg.internal.DirstateBuilder; | |
| 22 import org.tmatesoft.hg.internal.DirstateReader; | |
| 23 import org.tmatesoft.hg.internal.Experimental; | |
| 24 import org.tmatesoft.hg.internal.Internals; | |
| 25 import org.tmatesoft.hg.repo.HgManifest.Flags; | |
| 26 import org.tmatesoft.hg.repo.HgRepository; | |
| 27 import org.tmatesoft.hg.repo.HgRuntimeException; | |
| 28 import org.tmatesoft.hg.util.Path; | |
| 29 | |
| 30 /** | |
| 31 * WORK IN PROGRESS | |
| 32 * | |
| 33 * Schedule files for addition and removal | |
| 34 * XXX and, perhaps, forget() functionality shall be here as well? | |
| 35 * | |
| 36 * @since 1.1 | |
| 37 * @author Artem Tikhomirov | |
| 38 * @author TMate Software Ltd. | |
| 39 */ | |
| 40 @Experimental(reason="Work in progress") | |
| 41 public class HgAddRemoveCommand extends HgAbstractCommand<HgAddRemoveCommand> { | |
| 42 | |
| 43 private final HgRepository repo; | |
| 44 private final LinkedHashSet<Path> toAdd, toRemove; | |
| 45 | |
| 46 public HgAddRemoveCommand(HgRepository hgRepo) { | |
| 47 repo = hgRepo; | |
| 48 toAdd = new LinkedHashSet<Path>(); | |
| 49 toRemove = new LinkedHashSet<Path>(); | |
| 50 } | |
| 51 | |
| 52 /** | |
| 53 * Schedule specified files to get listed in dirstate as added | |
| 54 * | |
| 55 * @param paths files to mark as added, additive | |
| 56 * @return <code>this</code> for convenience | |
| 57 */ | |
| 58 public HgAddRemoveCommand add(Path... paths) { | |
| 59 if (paths == null) { | |
| 60 throw new IllegalArgumentException(); | |
| 61 } | |
| 62 for (Path p : paths) { | |
| 63 toRemove.remove(p); | |
| 64 toAdd.add(p); | |
| 65 } | |
| 66 return this; | |
| 67 } | |
| 68 | |
| 69 /** | |
| 70 * Schedule specified files to be marked as removed | |
| 71 * | |
| 72 * @param paths files to mark as removed, additive | |
| 73 * @return <code>this</code> for convenience | |
| 74 */ | |
| 75 public HgAddRemoveCommand remove(Path... paths) { | |
| 76 if (paths == null) { | |
| 77 throw new IllegalArgumentException(); | |
| 78 } | |
| 79 for (Path p : paths) { | |
| 80 toAdd.remove(p); | |
| 81 toRemove.add(p); | |
| 82 } | |
| 83 return this; | |
| 84 } | |
| 85 | |
| 86 public HgAddRemoveCommand addAll() { | |
| 87 throw Internals.notImplemented(); | |
| 88 } | |
| 89 | |
| 90 public HgAddRemoveCommand forget(Path path) { | |
| 91 throw Internals.notImplemented(); | |
| 92 } | |
| 93 | |
| 94 /** | |
| 95 * Perform scheduled addition/removal | |
| 96 * | |
| 97 * @throws HgException | |
| 98 */ | |
| 99 public void execute() throws HgException { | |
| 100 try { | |
| 101 Internals implRepo = Internals.getInstance(repo); | |
| 102 final DirstateBuilder dirstateBuilder = new DirstateBuilder(implRepo); | |
| 103 dirstateBuilder.fillFrom(new DirstateReader(implRepo, new Path.SimpleSource())); | |
| 104 for (Path p : toAdd) { | |
| 105 dirstateBuilder.recordAdded(p, Flags.RegularFile, -1); | |
| 106 } | |
| 107 for (Path p : toRemove) { | |
| 108 dirstateBuilder.recordRemoved(p); | |
| 109 } | |
| 110 dirstateBuilder.serialize(); | |
| 111 } catch (HgRuntimeException ex) { | |
| 112 throw new HgLibraryFailureException(ex); | |
| 113 } | |
| 114 } | |
| 115 } |
