Mercurial > hg4j
comparison src/com/tmate/hgkit/ll/LocalHgRepo.java @ 10:382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sat, 25 Dec 2010 21:50:12 +0100 |
parents | d6d2a630f4a6 |
children | 865bf07f381f |
comparison
equal
deleted
inserted
replaced
9:d6d2a630f4a6 | 10:382cfe9463db |
---|---|
1 /** | 1 /* |
2 * Copyright (c) 2010 Artem Tikhomirov | 2 * Copyright (c) 2010 Artem Tikhomirov |
3 */ | 3 */ |
4 package com.tmate.hgkit.ll; | 4 package com.tmate.hgkit.ll; |
5 | 5 |
6 import java.io.BufferedReader; | 6 import java.io.BufferedReader; |
11 import java.lang.ref.SoftReference; | 11 import java.lang.ref.SoftReference; |
12 import java.util.Arrays; | 12 import java.util.Arrays; |
13 import java.util.HashMap; | 13 import java.util.HashMap; |
14 import java.util.TreeSet; | 14 import java.util.TreeSet; |
15 | 15 |
16 import com.tmate.hgkit.fs.DataAccessProvider; | |
17 | |
16 /** | 18 /** |
17 * @author artem | 19 * @author artem |
18 */ | 20 */ |
19 public class LocalHgRepo extends HgRepository { | 21 public class LocalHgRepo extends HgRepository { |
20 | 22 |
21 private File repoDir; // .hg folder | 23 private File repoDir; // .hg folder |
22 private final String repoLocation; | 24 private final String repoLocation; |
25 private final DataAccessProvider dataAccess; | |
23 | 26 |
24 public LocalHgRepo(String repositoryPath) { | 27 public LocalHgRepo(String repositoryPath) { |
25 setInvalid(true); | 28 setInvalid(true); |
26 repoLocation = repositoryPath; | 29 repoLocation = repositoryPath; |
30 dataAccess = null; | |
27 } | 31 } |
28 | 32 |
29 public LocalHgRepo(File repositoryRoot) throws IOException { | 33 public LocalHgRepo(File repositoryRoot) throws IOException { |
30 assert ".hg".equals(repositoryRoot.getName()) && repositoryRoot.isDirectory(); | 34 assert ".hg".equals(repositoryRoot.getName()) && repositoryRoot.isDirectory(); |
31 setInvalid(false); | 35 setInvalid(false); |
32 repoDir = repositoryRoot; | 36 repoDir = repositoryRoot; |
33 repoLocation = repositoryRoot.getParentFile().getCanonicalPath(); | 37 repoLocation = repositoryRoot.getParentFile().getCanonicalPath(); |
38 dataAccess = new DataAccessProvider(); | |
34 parseRequires(); | 39 parseRequires(); |
35 } | 40 } |
36 | 41 |
37 @Override | 42 @Override |
38 public String getLocation() { | 43 public String getLocation() { |
39 return repoLocation; | 44 return repoLocation; |
45 } | |
46 | |
47 // 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) | |
48 public final HgDirstate loadDirstate() { | |
49 // XXX may cache in SoftReference if creation is expensive | |
50 return new HgDirstate(this, new File(repoDir, "dirstate")); | |
51 } | |
52 | |
53 /*package-local*/ DataAccessProvider getDataAccess() { | |
54 return dataAccess; | |
40 } | 55 } |
41 | 56 |
42 private final HashMap<String, SoftReference<RevlogStream>> streamsCache = new HashMap<String, SoftReference<RevlogStream>>(); | 57 private final HashMap<String, SoftReference<RevlogStream>> streamsCache = new HashMap<String, SoftReference<RevlogStream>>(); |
43 | 58 |
44 /** | 59 /** |
51 if (cached != null) { | 66 if (cached != null) { |
52 return cached; | 67 return cached; |
53 } | 68 } |
54 File f = new File(repoDir, path); | 69 File f = new File(repoDir, path); |
55 if (f.exists()) { | 70 if (f.exists()) { |
56 RevlogStream s = new RevlogStream(f); | 71 RevlogStream s = new RevlogStream(dataAccess, f); |
57 streamsCache.put(path, new SoftReference<RevlogStream>(s)); | 72 streamsCache.put(path, new SoftReference<RevlogStream>(s)); |
58 return s; | 73 return s; |
59 } | 74 } |
60 return null; | 75 return null; |
61 } | 76 } |