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