comparison src/com/tmate/hgkit/ll/LocalHgRepo.java @ 3:24bb4f365164

Rudimentary log functionality with basic infrastructure is in place
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 20 Dec 2010 02:50:36 +0100
parents a3576694a4d1
children a78c980749e3
comparison
equal deleted inserted replaced
2:08db726a0fb7 3:24bb4f365164
3 */ 3 */
4 package com.tmate.hgkit.ll; 4 package com.tmate.hgkit.ll;
5 5
6 import java.io.File; 6 import java.io.File;
7 import java.io.IOException; 7 import java.io.IOException;
8 import java.lang.ref.SoftReference;
9 import java.util.HashMap;
8 10
9 /** 11 /**
10 * @author artem 12 * @author artem
11 */ 13 */
12 public class LocalHgRepo extends HgRepository { 14 public class LocalHgRepo extends HgRepository {
28 30
29 @Override 31 @Override
30 public String getLocation() { 32 public String getLocation() {
31 return repoLocation; 33 return repoLocation;
32 } 34 }
35
36 private final HashMap<String, SoftReference<RevlogStream>> streamsCache = new HashMap<String, SoftReference<RevlogStream>>();
37
38 /**
39 * path - repository storage path (i.e. one usually with .i or .d)
40 */
41 @Override
42 protected RevlogStream resolve(String path) {
43 final SoftReference<RevlogStream> ref = streamsCache.get(path);
44 RevlogStream cached = ref == null ? null : ref.get();
45 if (cached != null) {
46 return cached;
47 }
48 File f = new File(repoDir, path);
49 if (f.exists()) {
50 RevlogStream s = new RevlogStream(f);
51 streamsCache.put(path, new SoftReference<RevlogStream>(s));
52 return s;
53 }
54 return null;
55 }
56
57 @Override
58 public HgDataFile getFileNode(String path) {
59 String nPath = normalize(path);
60 String storagePath = toStoragePath(nPath);
61 RevlogStream content = resolve(storagePath);
62 // XXX no content when no file? or HgDataFile.exists() to detect that? How about files that were removed in previous releases?
63 return new HgDataFile(this, nPath, content);
64 }
65
66 // FIXME much more to be done, see store.py:_hybridencode
67 private static String toStoragePath(String path) {
68 // XXX works for lowercase names only
69 return "store/data/" + path.replace('\\', '/') + ".i";
70 }
71
72 private static String normalize(String path) {
73 return path.replace('\\', '/');
74 }
33 } 75 }