comparison src/org/tmatesoft/hg/internal/RevlogChangeMonitor.java @ 621:99ad1e3a4e4d

RevlogStream: be aware of existence (not HgDataFile), facilitate use of an added HgDataFile over a commit; Rollback: be more sensitive about file changes (file size is not enough: write/rollback leaves it intact); tests
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sat, 18 May 2013 22:23:57 +0200
parents 66f1cc23b906
children
comparison
equal deleted inserted replaced
620:272ecffccc8a 621:99ad1e3a4e4d
27 * @author TMate Software Ltd. 27 * @author TMate Software Ltd.
28 */ 28 */
29 public class RevlogChangeMonitor { 29 public class RevlogChangeMonitor {
30 30
31 private final WeakHashMap<File, Long> lastKnownSize; 31 private final WeakHashMap<File, Long> lastKnownSize;
32 private final WeakHashMap<File, Long> lastKnownTime;
32 private final File soleFile; 33 private final File soleFile;
33 private long soleFileLength = -1; 34 private long soleFileSize = -1;
35 private long soleFileTime = -1;
34 36
35 // use single for multiple files. TODO repository/session context shall provide 37 // use single for multiple files. TODO [1.2] repository/session context shall provide
36 // alternative (configurable) implementations, so that Java7 users may supply better one 38 // alternative (configurable) implementations, so that Java7 users may supply better one
37 public RevlogChangeMonitor() { 39 public RevlogChangeMonitor() {
38 lastKnownSize = new WeakHashMap<File, Long>(); 40 lastKnownSize = new WeakHashMap<File, Long>();
41 lastKnownTime= new WeakHashMap<File, Long>();
39 soleFile = null; 42 soleFile = null;
40 } 43 }
41 44
42 public RevlogChangeMonitor(File f) { 45 public RevlogChangeMonitor(File f) {
43 assert f != null; 46 assert f != null;
44 lastKnownSize = null; 47 lastKnownSize = lastKnownTime = null;
45 soleFile = f; 48 soleFile = f;
46 } 49 }
47 50
48 public void touch(File f) { 51 public void touch(File f) {
49 assert f != null; 52 assert f != null;
50 if (lastKnownSize == null) { 53 if (lastKnownSize == null) {
51 assert f == soleFile; 54 assert f == soleFile;
52 soleFileLength = f.length(); 55 soleFileSize = f.length();
56 soleFileTime = f.lastModified();
53 } else { 57 } else {
54 lastKnownSize.put(f, f.length()); 58 lastKnownSize.put(f, f.length());
59 lastKnownTime.put(f, f.lastModified());
55 } 60 }
56 } 61 }
57 62
58 public boolean hasChanged(File f) { 63 public boolean hasChanged(File f) {
59 assert f != null; 64 assert f != null;
60 if (lastKnownSize == null) { 65 if (lastKnownSize == null) {
61 assert f == soleFile; 66 assert f == soleFile;
62 return soleFileLength != f.length(); 67 return soleFileSize != f.length() || soleFileTime != f.lastModified();
63 } else { 68 } else {
64 Long lastSize = lastKnownSize.get(f); 69 Long lastSize = lastKnownSize.get(f);
65 if (lastSize == null) { 70 Long lastTime = lastKnownTime.get(f);
71 if (lastSize == null || lastTime == null) {
66 return true; 72 return true;
67 } 73 }
68 return f.length() != lastSize; 74 return f.length() != lastSize || f.lastModified() != lastTime;
69 } 75 }
70 } 76 }
71 } 77 }