| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
package com.aragost.javahg.commands; |
| 27 | |
|
| 28 | |
import java.io.IOException; |
| 29 | |
import java.util.Collections; |
| 30 | |
import java.util.List; |
| 31 | |
|
| 32 | |
import com.aragost.javahg.Bookmark; |
| 33 | |
import com.aragost.javahg.HgVersion; |
| 34 | |
import com.aragost.javahg.Repository; |
| 35 | |
import com.aragost.javahg.commands.flags.BookmarksCommandFlags; |
| 36 | |
import com.aragost.javahg.internals.HgInputStream; |
| 37 | |
import com.aragost.javahg.internals.RuntimeIOException; |
| 38 | |
import com.aragost.javahg.log.Logger; |
| 39 | |
import com.aragost.javahg.log.LoggerFactory; |
| 40 | |
import com.google.common.collect.Lists; |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
public class BookmarksCommand extends BookmarksCommandFlags { |
| 46 | |
|
| 47 | 1 | private static final Logger LOG = LoggerFactory.getLogger(BookmarksCommand.class); |
| 48 | |
|
| 49 | 1 | private static final byte[] NO_BOOKMARKS = "no bookmarks set\n".getBytes(); |
| 50 | |
|
| 51 | 1 | private static final HgVersion ISSUE3263_FIXED = HgVersion.fromString("2.1.1"); |
| 52 | |
|
| 53 | |
public BookmarksCommand(Repository repository) { |
| 54 | 22 | super(repository); |
| 55 | 22 | withDebugFlag(); |
| 56 | 22 | } |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
public List<Bookmark> list() { |
| 63 | 20 | Repository repo = getRepository(); |
| 64 | 20 | HgInputStream stream = launchStream(); |
| 65 | |
try { |
| 66 | 20 | if (stream.match(NO_BOOKMARKS)) { |
| 67 | 3 | stream.consumeAll(); |
| 68 | 3 | return Collections.emptyList(); |
| 69 | |
} |
| 70 | 17 | List<Bookmark> result = Lists.newArrayList(); |
| 71 | 37 | while (stream.peek() != -1) { |
| 72 | 20 | stream.mustMatch(' '); |
| 73 | 20 | boolean active = stream.read() == '*'; |
| 74 | 20 | stream.mustMatch(' '); |
| 75 | 20 | String name = stream.textUpTo(' '); |
| 76 | 20 | stream.upTo(':'); |
| 77 | 20 | String node = stream.textUpTo('\n'); |
| 78 | 20 | Bookmark bookmark = new Bookmark(repo.changeset(node), name, active); |
| 79 | 20 | result.add(bookmark); |
| 80 | 20 | } |
| 81 | 17 | return result; |
| 82 | 0 | } catch (IOException e) { |
| 83 | 0 | throw new RuntimeIOException(e); |
| 84 | |
} |
| 85 | |
} |
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
public void create(String name) { |
| 93 | 7 | launchString(name); |
| 94 | 7 | if (getRepository().getHgVersion().isBefore(ISSUE3263_FIXED)) { |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | 7 | LOG.info("Issue3263 workaround: Executing 'bookmarks --list' as part of creating a bookmark"); |
| 99 | 7 | list(); |
| 100 | |
} |
| 101 | 7 | } |
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
public void delete(String name) { |
| 109 | 1 | launchString("--delete", name); |
| 110 | 1 | } |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
public void rename(String oldName, String newName) { |
| 119 | 1 | launchString("--rename", oldName, newName); |
| 120 | 1 | } |
| 121 | |
} |