annotate src/org/tmatesoft/hg/repo/HgRepository.java @ 104:54562de502f7

Preliminary tags implementation
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 28 Jan 2011 17:51:54 +0100
parents a3a2e5deb320
children 46291ec605a0
rev   line source
10
382cfe9463db Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 9
diff changeset
1 /*
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
2 * Copyright (c) 2010-2011 TMate Software Ltd
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
3 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
4 * This program is free software; you can redistribute it and/or modify
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
5 * it under the terms of the GNU General Public License as published by
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
6 * the Free Software Foundation; version 2 of the License.
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
7 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
8 * This program is distributed in the hope that it will be useful,
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
11 * GNU General Public License for more details.
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
12 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
13 * For information on how to redistribute this software under
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
14 * the terms of a license other than GNU General Public License
102
a3a2e5deb320 Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 97
diff changeset
15 * contact TMate Software at support@hg4j.com
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
17 package org.tmatesoft.hg.repo;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
18
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
19 import java.io.File;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
20 import java.io.IOException;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
21 import java.lang.ref.SoftReference;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
22 import java.util.HashMap;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
24 import org.tmatesoft.hg.core.Path;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
25 import org.tmatesoft.hg.internal.DataAccessProvider;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
26 import org.tmatesoft.hg.internal.RequiresFile;
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
27 import org.tmatesoft.hg.internal.RevlogStream;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
28 import org.tmatesoft.hg.util.FileWalker;
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
29 import org.tmatesoft.hg.util.PathRewrite;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
30
1
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 0
diff changeset
31
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
32
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 /**
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 55
diff changeset
34 * Shall be as state-less as possible, all the caching happens outside the repo, in commands/walkers
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
35 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
36 * @author Artem Tikhomirov
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
37 * @author TMate Software Ltd.
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 */
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
39 public final class HgRepository {
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
41 public static final int TIP = -1;
68
0e499fed9b3d StatusCommand with tests. Extra constants to indicate common revision cases
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 64
diff changeset
42 public static final int BAD_REVISION = Integer.MIN_VALUE;
0e499fed9b3d StatusCommand with tests. Extra constants to indicate common revision cases
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 64
diff changeset
43 public static final int WORKING_COPY = -2;
5
fc265ddeab26 File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
44
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
45 // temp aux marker method
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
46 public static IllegalStateException notImplemented() {
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
47 return new IllegalStateException("Not implemented");
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
48 }
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
49
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
50 private final File repoDir; // .hg folder
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
51 private final String repoLocation;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
52 private final DataAccessProvider dataAccess;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
53 private final PathRewrite normalizePath = new PathRewrite() {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
54
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
55 public String rewrite(String path) {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
56 // TODO handle . and .. (although unlikely to face them from GUI client)
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
57 path = path.replace('\\', '/').replace("//", "/");
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
58 if (path.startsWith("/")) {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
59 path = path.substring(1);
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
60 }
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
61 return path;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
62 }
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
63 };
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
64 private final PathRewrite dataPathHelper;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
65 private final PathRewrite repoPathHelper;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
66
97
ee2c750b036d Changelog to HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
67 private HgChangelog changelog;
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
68 private HgManifest manifest;
50
f1db8610da62 Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 45
diff changeset
69 private HgTags tags;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
70 // XXX perhaps, shall enable caching explicitly
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
71 private final HashMap<Path, SoftReference<RevlogStream>> streamsCache = new HashMap<Path, SoftReference<RevlogStream>>();
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
72
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
73 private final org.tmatesoft.hg.internal.Internals impl = new org.tmatesoft.hg.internal.Internals();
91
c2ce1cfaeb9e ignore file with regex and 'honest' glob support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
74 private HgIgnore ignore;
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
75
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
76 HgRepository(String repositoryPath) {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
77 repoDir = null;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
78 repoLocation = repositoryPath;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
79 dataAccess = null;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
80 dataPathHelper = repoPathHelper = null;
1
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 0
diff changeset
81 }
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 0
diff changeset
82
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
83 HgRepository(File repositoryRoot) throws IOException {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
84 assert ".hg".equals(repositoryRoot.getName()) && repositoryRoot.isDirectory();
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
85 repoDir = repositoryRoot;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
86 repoLocation = repositoryRoot.getParentFile().getCanonicalPath();
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
87 dataAccess = new DataAccessProvider();
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
88 parseRequires();
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
89 dataPathHelper = impl.buildDataFilesHelper();
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
90 repoPathHelper = impl.buildRepositoryFilesHelper();
1
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 0
diff changeset
91 }
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
93
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
94 public String getLocation() {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
95 return repoLocation;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
96 }
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
97
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
98 public boolean isInvalid() {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
99 return repoDir == null || !repoDir.exists() || !repoDir.isDirectory();
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
100 }
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
101
97
ee2c750b036d Changelog to HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
102 public HgChangelog getChangelog() {
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 if (this.changelog == null) {
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
104 String storagePath = repoPathHelper.rewrite("00changelog.i");
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
105 RevlogStream content = resolve(Path.create(storagePath));
97
ee2c750b036d Changelog to HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
106 this.changelog = new HgChangelog(this, content);
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 }
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 return this.changelog;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 }
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
110
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
111 public HgManifest getManifest() {
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
112 if (this.manifest == null) {
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
113 RevlogStream content = resolve(Path.create(repoPathHelper.rewrite("00manifest.i")));
13
df8c67f3006a Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 10
diff changeset
114 this.manifest = new HgManifest(this, content);
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
115 }
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
116 return this.manifest;
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
117 }
50
f1db8610da62 Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 45
diff changeset
118
f1db8610da62 Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 45
diff changeset
119 public final HgTags getTags() {
f1db8610da62 Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 45
diff changeset
120 if (tags == null) {
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
121 tags = new HgTags();
104
54562de502f7 Preliminary tags implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
122 try {
54562de502f7 Preliminary tags implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
123 tags.readGlobal(new File(repoDir.getParentFile(), ".hgtags"));
54562de502f7 Preliminary tags implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
124 tags.readLocal(new File(repoDir, "localtags"));
54562de502f7 Preliminary tags implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
125 } catch (IOException ex) {
54562de502f7 Preliminary tags implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
126 ex.printStackTrace(); // FIXME log or othewise report
54562de502f7 Preliminary tags implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
127 }
50
f1db8610da62 Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 45
diff changeset
128 }
f1db8610da62 Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 45
diff changeset
129 return tags;
f1db8610da62 Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 45
diff changeset
130 }
f1db8610da62 Log to consult (placeholder, for now) class to find out associated tags
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 45
diff changeset
131
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
132 public HgDataFile getFileNode(String path) {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
133 String nPath = normalizePath.rewrite(path);
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
134 String storagePath = dataPathHelper.rewrite(nPath);
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
135 RevlogStream content = resolve(Path.create(storagePath));
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
136 return new HgDataFile(this, Path.create(nPath), content);
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
137 }
1
a3576694a4d1 Repository detection from local/specified directory
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 0
diff changeset
138
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
139 public HgDataFile getFileNode(Path path) {
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
140 String storagePath = dataPathHelper.rewrite(path.toString());
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
141 RevlogStream content = resolve(Path.create(storagePath));
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
142 // XXX no content when no file? or HgDataFile.exists() to detect that? How about files that were removed in previous releases?
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
143 return new HgDataFile(this, path, content);
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
144 }
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
145
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
146 public PathRewrite getPathHelper() { // Really need to be public?
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
147 return normalizePath;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
148 }
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
149
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
150 /*package-local*/ File getRepositoryRoot() {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
151 return repoDir;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
152 }
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
153
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
154 // XXX package-local, unless there are cases when required from outside (guess, working dir/revision walkers may hide dirstate access and no public visibility needed)
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
155 /*package-local*/ final HgDirstate loadDirstate() {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
156 return new HgDirstate(getDataAccess(), new File(repoDir, "dirstate"));
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
157 }
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
158
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
159 // package-local, see comment for loadDirstate
91
c2ce1cfaeb9e ignore file with regex and 'honest' glob support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
160 /*package-local*/ final HgIgnore getIgnore() {
c2ce1cfaeb9e ignore file with regex and 'honest' glob support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
161 // TODO read config for additional locations
c2ce1cfaeb9e ignore file with regex and 'honest' glob support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
162 if (ignore == null) {
c2ce1cfaeb9e ignore file with regex and 'honest' glob support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
163 ignore = new HgIgnore();
c2ce1cfaeb9e ignore file with regex and 'honest' glob support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
164 try {
c2ce1cfaeb9e ignore file with regex and 'honest' glob support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
165 File ignoreFile = new File(repoDir.getParentFile(), ".hgignore");
c2ce1cfaeb9e ignore file with regex and 'honest' glob support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
166 ignore.read(ignoreFile);
c2ce1cfaeb9e ignore file with regex and 'honest' glob support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
167 } catch (IOException ex) {
c2ce1cfaeb9e ignore file with regex and 'honest' glob support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
168 ex.printStackTrace(); // log warn
c2ce1cfaeb9e ignore file with regex and 'honest' glob support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
169 }
c2ce1cfaeb9e ignore file with regex and 'honest' glob support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
170 }
c2ce1cfaeb9e ignore file with regex and 'honest' glob support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
171 return ignore;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
172 }
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
173
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
174 /*package-local*/ DataAccessProvider getDataAccess() {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
175 return dataAccess;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
176 }
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
177
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
178 // FIXME not sure repository shall create walkers
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
179 /*package-local*/ FileWalker createWorkingDirWalker() {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
180 return new FileWalker(repoDir.getParentFile());
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
181 }
9
d6d2a630f4a6 Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 5
diff changeset
182
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
183 /**
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
184 * Perhaps, should be separate interface, like ContentLookup
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
185 * path - repository storage path (i.e. one usually with .i or .d)
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 1
diff changeset
186 */
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
187 /*package-local*/ RevlogStream resolve(Path path) {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
188 final SoftReference<RevlogStream> ref = streamsCache.get(path);
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
189 RevlogStream cached = ref == null ? null : ref.get();
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
190 if (cached != null) {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
191 return cached;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
192 }
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
193 File f = new File(repoDir, path.toString());
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
194 if (f.exists()) {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
195 RevlogStream s = new RevlogStream(dataAccess, f);
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
196 streamsCache.put(path, new SoftReference<RevlogStream>(s));
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
197 return s;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
198 }
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
199 return null; // XXX empty stream instead?
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
200 }
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
201
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
202 private void parseRequires() {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
203 new RequiresFile().parse(impl, new File(repoDir, "requires"));
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
204 }
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
205 }