annotate src/org/tmatesoft/hg/internal/Metadata.java @ 695:053bb4397bf9

Refactoring: nice Revlog.indexWalk() implementation
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 05 Aug 2013 18:45:16 +0200
parents 7efabe0cddcf
children
rev   line source
602
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.internal;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
694
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
19 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
602
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import static org.tmatesoft.hg.util.LogFacility.Severity.Error;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.io.ByteArrayOutputStream;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.io.IOException;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.util.ArrayList;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import java.util.Collection;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import org.tmatesoft.hg.core.SessionContext;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import org.tmatesoft.hg.repo.HgInvalidControlFileException;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import org.tmatesoft.hg.repo.HgInvalidStateException;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import org.tmatesoft.hg.util.LogFacility;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 /**
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 * Container for metadata recorded as part of file revisions
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 *
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 * @author Artem Tikhomirov
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 * @author TMate Software Ltd.
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 */
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 public final class Metadata {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 private static class Record {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 public final int offset;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 public final MetadataEntry[] entries;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 public Record(int off, MetadataEntry[] entr) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 offset = off;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 entries = entr;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 // XXX sparse array needed
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 private final IntMap<Metadata.Record> entries = new IntMap<Metadata.Record>(5);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 private final Metadata.Record NONE = new Record(-1, null); // don't want statics
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 private final LogFacility log;
694
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
54
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
55 private int lastRevRead = NO_REVISION;
602
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 public Metadata(SessionContext.Source sessionCtx) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 log = sessionCtx.getSessionContext().getLog();
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60
694
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
61 /**
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
62 * @return <code>true</code> when there's metadata for given revision
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
63 */
602
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 public boolean known(int revision) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 Metadata.Record i = entries.get(revision);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 return i != null && NONE != i;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68
694
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
69 /**
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
70 * @return <code>true</code> when revision has been checked for metadata presence.
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
71 */
602
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 public boolean checked(int revision) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 return entries.containsKey(revision);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 // true when revision has been checked and found not having any metadata
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 public boolean none(int revision) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 Metadata.Record i = entries.get(revision);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 return i == NONE;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 }
694
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
81
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
82 /**
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
83 * Get the greatest revision index visited so far.
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
84 * Note, doesn't imply all revisions up to this has been visited.
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
85 */
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
86 public int lastRevisionRead() {
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
87 return lastRevRead;
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
88 }
602
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 // mark revision as having no metadata.
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 void recordNone(int revision) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 Metadata.Record i = entries.get(revision);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 if (i == NONE) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 return; // already there
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 if (i != null) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 throw new HgInvalidStateException(String.format("Trying to override Metadata state for revision %d (known offset: %d)", revision, i));
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 entries.put(revision, NONE);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 // since this is internal class, callers are supposed to ensure arg correctness (i.e. ask known() before)
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 public int dataOffset(int revision) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 return entries.get(revision).offset;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 void add(int revision, int dataOffset, Collection<MetadataEntry> e) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 assert !entries.containsKey(revision);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 entries.put(revision, new Record(dataOffset, e.toArray(new MetadataEntry[e.size()])));
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 /**
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 * @return <code>true</code> if metadata has been found
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 */
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 public boolean tryRead(int revisionNumber, DataAccess data) throws IOException, HgInvalidControlFileException {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 final int daLength = data.length();
694
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
116 if (lastRevRead == NO_REVISION || revisionNumber > lastRevRead) {
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
117 lastRevRead = revisionNumber;
7efabe0cddcf Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 602
diff changeset
118 }
602
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 if (daLength < 4 || data.readByte() != 1 || data.readByte() != 10) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 recordNone(revisionNumber);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 return false;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 } else {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 ArrayList<MetadataEntry> _metadata = new ArrayList<MetadataEntry>();
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 int offset = parseMetadata(data, daLength, _metadata);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 add(revisionNumber, offset, _metadata);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 return true;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 public String find(int revision, String key) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 for (MetadataEntry me : entries.get(revision).entries) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
132 if (me.matchKey(key)) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133 return me.value();
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 return null;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 private int parseMetadata(DataAccess data, final int daLength, ArrayList<MetadataEntry> _metadata) throws IOException, HgInvalidControlFileException {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
140 int lastEntryStart = 2;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141 int lastColon = -1;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 // XXX in fact, need smth like ByteArrayBuilder, similar to StringBuilder,
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143 // which can't be used here because we can't convert bytes to chars as we read them
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 // (there might be multi-byte encoding), and we need to collect all bytes before converting to string
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145 ByteArrayOutputStream bos = new ByteArrayOutputStream();
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 String key = null, value = null;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
147 boolean byteOne = false;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148 boolean metadataIsComplete = false;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
149 for (int i = 2; i < daLength; i++) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150 byte b = data.readByte();
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 if (b == '\n') {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 if (byteOne) { // i.e. \n follows 1
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 lastEntryStart = i+1;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 metadataIsComplete = true;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 // XXX is it possible to have here incomplete key/value (i.e. if last pair didn't end with \n)
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156 // if yes, need to set metadataIsComplete to true in that case as well
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157 break;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
158 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
159 if (key == null || lastColon == -1 || i <= lastColon) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
160 log.dump(getClass(), Error, "Missing key in file revision metadata at index %d", i);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
162 value = new String(bos.toByteArray()).trim();
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
163 bos.reset();
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
164 _metadata.add(new MetadataEntry(key, value));
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165 key = value = null;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
166 lastColon = -1;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
167 lastEntryStart = i+1;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
168 continue;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 // byteOne has to be consumed up to this line, if not yet, consume it
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 if (byteOne) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 // insert 1 we've read on previous step into the byte builder
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 bos.write(1);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
174 byteOne = false;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175 // fall-through to consume current byte
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
176 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
177 if (b == (int) ':') {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
178 assert value == null;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
179 key = new String(bos.toByteArray());
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
180 bos.reset();
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
181 lastColon = i;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
182 } else if (b == 1) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
183 byteOne = true;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
184 } else {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
185 bos.write(b);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
186 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
187 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
188 // data.isEmpty is not reliable, renamed files of size==0 keep only metadata
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
189 if (!metadataIsComplete) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
190 // XXX perhaps, worth a testcase (empty file, renamed, read or ask ifCopy
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
191 throw new HgInvalidControlFileException("Metadata is not closed properly", null, null);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
192 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
193 return lastEntryStart;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
194 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
195
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
196 /**
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
197 * There may be several entries of metadata per single revision, this class captures single entry
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
198 */
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
199 private static class MetadataEntry {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
200 private final String entry;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
201 private final int valueStart;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
203 // key may be null
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
204 /* package-local */MetadataEntry(String key, String value) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
205 if (key == null) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
206 entry = value;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
207 valueStart = -1; // not 0 to tell between key == null and key == ""
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
208 } else {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
209 entry = key + value;
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
210 valueStart = key.length();
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
211 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
212 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
213
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
214 /* package-local */boolean matchKey(String key) {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
215 return key == null ? valueStart == -1 : key.length() == valueStart && entry.startsWith(key);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
216 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
217
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
218 // uncomment once/if needed
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
219 // public String key() {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
220 // return entry.substring(0, valueStart);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
221 // }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
222
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
223 public String value() {
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
224 return valueStart == -1 ? entry : entry.substring(valueStart);
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
225 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
226 }
e3717fc7d26f Refactor metadata parsing in HgDataFile, moved to standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
227 }