Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/RevlogChangeMonitor.java @ 607:66f1cc23b906
Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 07 May 2013 16:52:46 +0200 |
parents | |
children | 99ad1e3a4e4d |
comparison
equal
deleted
inserted
replaced
606:5daa42067e7c | 607:66f1cc23b906 |
---|---|
1 /* | |
2 * Copyright (c) 2013 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.internal; | |
18 | |
19 import java.io.File; | |
20 import java.util.WeakHashMap; | |
21 | |
22 /** | |
23 * Detect changes to revlog files. Not a general file change monitoring as we utilize the fact revlogs are append-only (and even in case | |
24 * of stripped-off tail revisions, with e.g. mq, detection approach is still valid). | |
25 * | |
26 * @author Artem Tikhomirov | |
27 * @author TMate Software Ltd. | |
28 */ | |
29 public class RevlogChangeMonitor { | |
30 | |
31 private final WeakHashMap<File, Long> lastKnownSize; | |
32 private final File soleFile; | |
33 private long soleFileLength = -1; | |
34 | |
35 // use single for multiple files. TODO repository/session context shall provide | |
36 // alternative (configurable) implementations, so that Java7 users may supply better one | |
37 public RevlogChangeMonitor() { | |
38 lastKnownSize = new WeakHashMap<File, Long>(); | |
39 soleFile = null; | |
40 } | |
41 | |
42 public RevlogChangeMonitor(File f) { | |
43 assert f != null; | |
44 lastKnownSize = null; | |
45 soleFile = f; | |
46 } | |
47 | |
48 public void touch(File f) { | |
49 assert f != null; | |
50 if (lastKnownSize == null) { | |
51 assert f == soleFile; | |
52 soleFileLength = f.length(); | |
53 } else { | |
54 lastKnownSize.put(f, f.length()); | |
55 } | |
56 } | |
57 | |
58 public boolean hasChanged(File f) { | |
59 assert f != null; | |
60 if (lastKnownSize == null) { | |
61 assert f == soleFile; | |
62 return soleFileLength != f.length(); | |
63 } else { | |
64 Long lastSize = lastKnownSize.get(f); | |
65 if (lastSize == null) { | |
66 return true; | |
67 } | |
68 return f.length() != lastSize; | |
69 } | |
70 } | |
71 } |