Mercurial > hg4j
comparison cmdline/org/tmatesoft/hg/console/Tags.java @ 234:b2cfbe46f9b6
HgTags got TagInfo to access tags. Tags are read from all branches/revisions now, not only working copy
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 07 Jun 2011 04:28:32 +0200 |
parents | |
children | 45dc79e545f5 |
comparison
equal
deleted
inserted
replaced
233:1d389c0cb0a5 | 234:b2cfbe46f9b6 |
---|---|
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.console; | |
18 | |
19 import java.util.Comparator; | |
20 import java.util.HashMap; | |
21 import java.util.Map; | |
22 import java.util.TreeSet; | |
23 | |
24 import org.tmatesoft.hg.repo.HgChangelog; | |
25 import org.tmatesoft.hg.repo.HgRepository; | |
26 import org.tmatesoft.hg.repo.HgTags; | |
27 import org.tmatesoft.hg.repo.HgTags.TagInfo; | |
28 | |
29 /** | |
30 * | |
31 * @author Artem Tikhomirov | |
32 * @author TMate Software Ltd. | |
33 */ | |
34 public class Tags { | |
35 | |
36 public static void main(String[] args) throws Exception { | |
37 Options cmdLineOpts = Options.parse(args); | |
38 HgRepository hgRepo = cmdLineOpts.findRepository(); | |
39 if (hgRepo.isInvalid()) { | |
40 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); | |
41 return; | |
42 } | |
43 HgTags tags = hgRepo.getTags(); | |
44 final HgChangelog clog = hgRepo.getChangelog(); | |
45 final Map<TagInfo, Integer> ti2index = new HashMap<TagInfo, Integer>(); | |
46 final TreeSet<TagInfo> sorted = new TreeSet<HgTags.TagInfo>(new Comparator<TagInfo>() { | |
47 | |
48 public int compare(TagInfo o1, TagInfo o2) { | |
49 // reverse, from newer to older (bigger indexes first); | |
50 // never ==, tags from same revision in any order, just next to each other | |
51 int x1 = ti2index.get(o1); | |
52 int x2 = ti2index.get(o2); | |
53 return x1 < x2 ? 1 : -1; | |
54 } | |
55 }); | |
56 for (TagInfo ti : tags.getTags().values()) { | |
57 int x = clog.getLocalRevision(ti.revision()); // XXX in fact, performance hog. Need batch localRevision or another improvement | |
58 ti2index.put(ti, x); | |
59 sorted.add(ti); | |
60 } | |
61 for (TagInfo ti : sorted) { | |
62 int x = ti2index.get(ti); | |
63 System.out.printf("%-30s%8d:%s\n", ti.name(), x, ti.revision().shortNotation()); | |
64 } | |
65 } | |
66 } |