osunix / opengrok-trunk

mirror of opengrok

Clone this repository (size: 5.0 MB): HTTPS / SSH
$ hg clone http://hg.pathscale.com/opengrok-trunk
commit 743: 2459459b1540
parent 742: 36a83c8415f4
branch: default
Made HistoryCache.store() take history for the full repository instead of per file. Moved logic from Repository to FileHistoryCache.
Knut...@Sun.COM
19 months ago

Changed (Δ2.8 KB):

Up to file-list src/org/opensolaris/opengrok/history/FileHistoryCache.java:

@@ -35,6 +35,10 @@ import java.io.File;
35
35
import java.io.FileInputStream;
36
36
import java.io.FileOutputStream;
37
37
import java.io.IOException;
38
import java.util.ArrayList;
39
import java.util.HashMap;
40
import java.util.List;
41
import java.util.Map;
38
42
import java.util.logging.Level;
39
43
import java.util.zip.GZIPInputStream;
40
44
import java.util.zip.GZIPOutputStream;
@@ -109,7 +113,7 @@ class FileHistoryCache implements Histor
109
113
        }
110
114
    }
111
115
    
112
    public void store(History history, File file, Repository repository)
116
    private void storeFile(History history, File file, Repository repository)
113
117
            throws HistoryException {
114
118
        
115
119
        File cache = getCachedFile(file);
@@ -161,6 +165,41 @@ class FileHistoryCache implements Histor
161
165
        }
162
166
    }
163
167
168
    public void store(History history, Repository repository)
169
            throws HistoryException {
170
171
        if (history.getHistoryEntries() == null) {
172
            return;
173
        }
174
175
        HashMap<String, List<HistoryEntry>> map =
176
                new HashMap<String, List<HistoryEntry>>();
177
178
        for (HistoryEntry e : history.getHistoryEntries()) {
179
            for (String s : e.getFiles()) {
180
                List<HistoryEntry> list = map.get(s);
181
                if (list == null) {
182
                    list = new ArrayList<HistoryEntry>();
183
                    map.put(s, list);
184
                }
185
                list.add(e);
186
            }
187
        }
188
189
        File root = RuntimeEnvironment.getInstance().getSourceRootFile();
190
        for (Map.Entry<String, List<HistoryEntry>> e : map.entrySet()) {
191
            for (HistoryEntry ent : e.getValue()) {
192
                ent.strip();
193
            }
194
            History hist = new History();
195
            hist.setHistoryEntries(e.getValue());
196
            File file = new File(root, e.getKey());
197
            if (!file.isDirectory()) {
198
                storeFile(hist, file, repository);
199
            }
200
        }
201
    }
202
164
203
    public History get(File file, Repository repository)
165
204
            throws HistoryException {
166
205
        File cache = getCachedFile(file);
@@ -205,7 +244,7 @@ class FileHistoryCache implements Histor
205
244
                        (cache.exists() ||
206
245
                             (time > env.getHistoryReaderTimeLimit()))) {
207
246
                // retrieving the history takes too long, cache it!
208
                store(history, file, repository);
247
                storeFile(history, file, repository);
209
248
            }
210
249
        }
211
250
        return history;

Up to file-list src/org/opensolaris/opengrok/history/HistoryCache.java:

@@ -48,14 +48,13 @@ interface HistoryCache {
48
48
    History get(File file, Repository repository) throws HistoryException;
49
49
50
50
    /**
51
     * Store the history for the given file.
51
     * Store the history for a repository.
52
52
     * 
53
53
     * @param history The history to store
54
     * @param file The file to store information for
55
     * @param repository The repository the file belongs to
54
     * @param repository The repository whose history to store
56
55
     * @throws HistoryException if the history cannot be stored
57
56
     */
58
    void store(History history, File file, Repository repository)
57
    void store(History history, Repository repository)
59
58
            throws HistoryException;
60
59
61
60
    /**

Up to file-list src/org/opensolaris/opengrok/history/JDBCHistoryCache.java:

@@ -281,6 +281,14 @@ class JDBCHistoryCache implements Histor
281
281
    private static PreparedQuery ADD_FILECHANGE = new PreparedQuery(
282
282
            "INSERT INTO FILECHANGES(FILE, CHANGESET) VALUES (?,?)");
283
283
284
    public void store(History history, Repository repository)
285
            throws HistoryException {
286
        // TODO
287
        throw new UnsupportedOperationException();
288
    }
289
290
    // TODO Remove next method as we should use store(History,Repository) now.
291
284
292
    // Assume that this file is never called concurrently from different
285
293
    // threads on files in the same repository.
286
294
    public void store(History history, File file, Repository repository)

Up to file-list src/org/opensolaris/opengrok/history/Repository.java:

@@ -26,11 +26,6 @@ package org.opensolaris.opengrok.history
26
26
import java.io.File;
27
27
import java.io.IOException;
28
28
import java.io.InputStream;
29
import java.util.ArrayList;
30
import java.util.HashMap;
31
import java.util.List;
32
import java.util.Map;
33
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
34
29
35
30
/**
36
31
 * An interface for an external repository. 
@@ -130,33 +125,8 @@ public abstract class Repository extends
130
125
        HistoryParser p = pClass.newInstance();
131
126
        File directory = new File(getDirectoryName());
132
127
        History history = p.parse(directory, this);
133
        if (history != null && history.getHistoryEntries() != null) {
134
            HashMap<String, List<HistoryEntry>> map =
135
                    new HashMap<String, List<HistoryEntry>>();
136
137
            for (HistoryEntry e : history.getHistoryEntries()) {
138
                for (String s : e.getFiles()) {
139
                    List<HistoryEntry> list = map.get(s);
140
                    if (list == null) {
141
                        list = new ArrayList<HistoryEntry>();
142
                        map.put(s, list);
143
                    }
144
                    list.add(e);
145
                }
146
            }
147
148
            File root = RuntimeEnvironment.getInstance().getSourceRootFile();
149
            for (Map.Entry<String, List<HistoryEntry>> e : map.entrySet()) {
150
                for (HistoryEntry ent : e.getValue()) {
151
                    ent.strip();
152
                }
153
                History hist = new History();
154
                hist.setHistoryEntries(e.getValue());
155
                File file = new File(root, e.getKey());
156
                if (!file.isDirectory()) {
157
                    cache.store(hist, file, this);
158
                }
159
            }
128
        if (history != null) {
129
            cache.store(history, this);
160
130
        }
161
131
    }
162
132