comparison src/com/tmate/hgkit/ll/LocalHgRepo.java @ 18:02ee376bee79

status operation against current working directory
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 03 Jan 2011 20:42:52 +0100
parents 865bf07f381f
children 11cfabe692b3
comparison
equal deleted inserted replaced
17:571e1b2cc3f7 18:02ee376bee79
9 import java.io.IOException; 9 import java.io.IOException;
10 import java.io.InputStreamReader; 10 import java.io.InputStreamReader;
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.LinkedList;
14 import java.util.TreeSet; 15 import java.util.TreeSet;
15 16
16 import com.tmate.hgkit.fs.DataAccessProvider; 17 import com.tmate.hgkit.fs.DataAccessProvider;
17 18
18 /** 19 /**
41 42
42 @Override 43 @Override
43 public String getLocation() { 44 public String getLocation() {
44 return repoLocation; 45 return repoLocation;
45 } 46 }
46 47
48 @Override
49 public void status(int rev1, int rev2, StatusInspector inspector) {
50 throw HgRepository.notImplemented();
51 }
52
53 public void statusLocal(int rev1, StatusInspector inspector) {
54 LinkedList<File> folders = new LinkedList<File>();
55 final File rootDir = repoDir.getParentFile();
56 folders.add(rootDir);
57 final HgDirstate dirstate = loadDirstate();
58 final HgIgnore hgignore = loadIgnore();
59 TreeSet<String> knownEntries = dirstate.all();
60 do {
61 File d = folders.removeFirst();
62 for (File f : d.listFiles()) {
63 if (f.isDirectory()) {
64 if (!".hg".equals(f.getName())) {
65 folders.addLast(f);
66 }
67 } else {
68 // FIXME path relative to rootDir
69 String fname = normalize(f.getPath().substring(rootDir.getPath().length() + 1));
70 if (hgignore.isIgnored(fname)) {
71 inspector.ignored(fname);
72 } else {
73 if (knownEntries.remove(fname)) {
74 // modified, added, removed, clean
75 HgDirstate.Record r;
76 if ((r = dirstate.checkNormal(fname)) != null) {
77 // either clean or modified
78 if (f.lastModified() / 1000 == r.time && r.size == f.length()) {
79 inspector.clean(fname);
80 } else {
81 // FIXME check actual content to avoid false modified files
82 inspector.modified(fname);
83 }
84 } else if ((r = dirstate.checkAdded(fname)) != null) {
85 if (r.name2 == null) {
86 inspector.added(fname);
87 } else {
88 inspector.copied(fname, r.name2);
89 }
90 } else if ((r = dirstate.checkRemoved(fname)) != null) {
91 inspector.removed(fname);
92 } else if ((r = dirstate.checkMerged(fname)) != null) {
93 inspector.modified(fname);
94 }
95 } else {
96 inspector.unknown(fname);
97 }
98 }
99 }
100 }
101 } while (!folders.isEmpty());
102 for (String m : knownEntries) {
103 inspector.missing(m);
104 }
105 }
106
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) 107 // 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() { 108 public final HgDirstate loadDirstate() {
49 // XXX may cache in SoftReference if creation is expensive 109 // XXX may cache in SoftReference if creation is expensive
50 return new HgDirstate(this, new File(repoDir, "dirstate")); 110 return new HgDirstate(this, new File(repoDir, "dirstate"));
51 } 111 }