Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/ManifestRevision.java @ 248:3fbfce107f94
Issue 8: Means to find out information about given file at specific changeset. Inner ManifestRevisionInspector got promoted to ManifestRevision
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 12 Aug 2011 18:48:57 +0200 |
parents | |
children | 6dbbc53fc46d |
comparison
equal
deleted
inserted
replaced
247:f052f40839ec | 248:3fbfce107f94 |
---|---|
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.internal; | |
18 | |
19 import java.util.Collection; | |
20 import java.util.TreeMap; | |
21 | |
22 import org.tmatesoft.hg.core.Nodeid; | |
23 import org.tmatesoft.hg.repo.HgManifest; | |
24 | |
25 /** | |
26 * Specific revision of the manifest. | |
27 * Note, suited to keep single revision only ({@link #changeset()}). | |
28 * | |
29 * @author Artem Tikhomirov | |
30 * @author TMate Software Ltd. | |
31 */ | |
32 public final class ManifestRevision implements HgManifest.Inspector { | |
33 private final TreeMap<String, Nodeid> idsMap; | |
34 private final TreeMap<String, String> flagsMap; | |
35 private final Pool<Nodeid> idsPool; | |
36 private final Pool<String> namesPool; | |
37 private Nodeid changeset; | |
38 private int changelogRev; | |
39 | |
40 // optional pools for effective management of nodeids and filenames (they are likely | |
41 // to be duplicated among different manifest revisions | |
42 public ManifestRevision(Pool<Nodeid> nodeidPool, Pool<String> filenamePool) { | |
43 idsPool = nodeidPool; | |
44 namesPool = filenamePool; | |
45 idsMap = new TreeMap<String, Nodeid>(); | |
46 flagsMap = new TreeMap<String, String>(); | |
47 } | |
48 | |
49 public Collection<String> files() { | |
50 return idsMap.keySet(); | |
51 } | |
52 | |
53 public Nodeid nodeid(String fname) { | |
54 return idsMap.get(fname); | |
55 } | |
56 | |
57 public String flags(String fname) { | |
58 return flagsMap.get(fname); | |
59 } | |
60 | |
61 /** | |
62 * @return identifier of the changeset this manifest revision corresponds to. | |
63 */ | |
64 public Nodeid changeset() { | |
65 return changeset; | |
66 } | |
67 | |
68 public int changesetLocalRev() { | |
69 return changelogRev; | |
70 } | |
71 | |
72 // | |
73 | |
74 public boolean next(Nodeid nid, String fname, String flags) { | |
75 if (namesPool != null) { | |
76 fname = namesPool.unify(fname); | |
77 } | |
78 if (idsPool != null) { | |
79 nid = idsPool.unify(nid); | |
80 } | |
81 idsMap.put(fname, nid); | |
82 if (flags != null) { | |
83 // TreeMap$Entry takes 32 bytes. No reason to keep null for such price | |
84 // Perhaps, Map<String, Pair<Nodeid, String>> might be better solution | |
85 flagsMap.put(fname, flags); | |
86 } | |
87 return true; | |
88 } | |
89 | |
90 public boolean end(int revision) { | |
91 // in fact, this class cares about single revision | |
92 return false; | |
93 } | |
94 | |
95 public boolean begin(int revision, Nodeid nid, int changelogRevision) { | |
96 if (changeset != null) { | |
97 idsMap.clear(); | |
98 flagsMap.clear(); | |
99 } | |
100 changeset = nid; | |
101 changelogRev = changelogRevision; | |
102 return true; | |
103 } | |
104 } |