osunix / opengrok-trunk

mirror of opengrok

Clone this repository (size: 5.0 MB): HTTPS / SSH
$ hg clone http://hg.pathscale.com/opengrok-trunk
commit 742: 36a83c8415f4
parent 741: 2faad378fe00
branch: default
Removed createCache() and directory history parser from RazorRepository The cache will probably not speed up history access for Razor repositories, as the history is already available locally, so remove it to simplify the code. Also removed RazorDirectoryHistoryParser since there's no efficient way to obtain the full history of a directory in a Razor repository, and the current implementation would always return a single entry only.
Knut...@Sun.COM
19 months ago

Changed (Δ3.9 KB):

raw changeset »

src/org/opensolaris/opengrok/history/RazorDirectoryHistoryParser.java

src/org/opensolaris/opengrok/history/RazorRepository.java (1 lines added, 113 lines removed)

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

@@ -25,15 +25,10 @@ import java.io.File;
25
25
import java.io.FileInputStream;
26
26
import java.io.IOException;
27
27
import java.io.InputStream;
28
import java.util.ArrayList;
29
import java.util.HashMap;
30
import java.util.List;
31
import java.util.Map;
32
28
import java.util.logging.Level;
33
29
import java.util.zip.GZIPInputStream;
34
30
35
31
import org.opensolaris.opengrok.OpenGrokLogger;
36
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
37
32
38
33
/**
39
34
 * Adds access to to a Razor Repository
@@ -204,7 +199,7 @@ public class RazorRepository extends Rep
204
199
205
200
    @Override
206
201
    Class<? extends HistoryParser> getDirectoryHistoryParser() {
207
        return RazorDirectoryHistoryParser.class;
202
        return null;
208
203
    }
209
204
210
205
    @Override
@@ -297,113 +292,6 @@ public class RazorRepository extends Rep
297
292
        throw new UnsupportedOperationException("Not supported yet.");
298
293
    }
299
294
300
    @Override
301
    void createCache(HistoryCache cache) throws HistoryException {
302
        try {
303
            createCacheHelper(cache);
304
        } catch (IOException ioe) {
305
            throw new HistoryException(ioe);
306
        } catch (InstantiationException ie) {
307
            throw new HistoryException(ie);
308
        } catch (IllegalAccessException iae) {
309
            throw new HistoryException(iae);
310
        }
311
    }
312
313
    /**
314
     * Helper method which performs the work for
315
     * {@link #createCache(HistoryCache)} without converting checked
316
     * exceptions to {@code HistoryException}
317
     *
318
     * @throws HistoryException if accessing the history cache fails
319
     * @throws IOException if an I/O error occurs
320
     * @throws InstantiationException if the parser class cannot be instatiated
321
     * @throws IllegalAccessException if the method does not have access to
322
     * the constructor of the parser class
323
     */
324
    private void createCacheHelper(HistoryCache cache)
325
            throws HistoryException, IOException,
326
            InstantiationException, IllegalAccessException
327
    {
328
329
        Class<? extends HistoryParser> dhpClass = getDirectoryHistoryParser();
330
        Class<? extends HistoryParser> fhpClass = getHistoryParser();
331
332
        // If we don't have a directory parser, we can't create the cache
333
        // this way. Just give up and return.
334
        if (dhpClass == null) {
335
            return;
336
        }
337
338
        HistoryParser directoryHistoryParser = dhpClass.newInstance();
339
        HistoryParser fileHistoryParser = null;
340
341
        if (fhpClass != null) {
342
            fileHistoryParser = fhpClass.newInstance();
343
        }
344
345
        File directory = new File(getDirectoryName());
346
347
        History history = directoryHistoryParser.parse(directory, this);
348
349
        if (history != null && history.getHistoryEntries() != null) {
350
            HashMap<String, List<HistoryEntry>> map =
351
                    new HashMap<String, List<HistoryEntry>>();
352
353
            for (HistoryEntry e : history.getHistoryEntries()) {
354
                createCacheForEntry(e, map, fileHistoryParser);
355
            }
356
357
            File root = RuntimeEnvironment.getInstance().getSourceRootFile();
358
            for (Map.Entry<String, List<HistoryEntry>> e : map.entrySet()) {
359
                for (HistoryEntry ent : e.getValue()) {
360
                    ent.strip();
361
                }
362
                History hist = new History();
363
                hist.setHistoryEntries(e.getValue());
364
                File file = new File(root, e.getKey());
365
                if (!file.isDirectory()) {
366
                    cache.store(hist, file, this);
367
                }
368
            }
369
        }
370
    }
371
372
    private void createCacheForEntry(
373
            HistoryEntry e, Map<String, List<HistoryEntry>> map,
374
            HistoryParser fileHistoryParser) throws HistoryException
375
    {
376
        for (String fileName : e.getFiles()) {
377
            List<HistoryEntry> list = map.get(fileName);
378
            if (list == null) {
379
                list = getHistoryEntries(fileHistoryParser, fileName);
380
                if (list == null) {
381
                    list = new ArrayList<HistoryEntry>();
382
                }
383
                map.put(fileName, list);
384
            }
385
386
            if (e.getDate() != null) {
387
                list.add(e);
388
            }
389
        }
390
    }
391
392
    private List<HistoryEntry> getHistoryEntries(
393
            HistoryParser fileHistoryParser, String fileName)
394
            throws HistoryException
395
    {
396
        List<HistoryEntry> list = null;
397
        if (fileHistoryParser != null) {
398
            File file = getSourceNameForOpenGrokName(fileName);
399
            History fileHistory = fileHistoryParser.parse(file, this);
400
            if (fileHistory != null) {
401
                list = fileHistory.getHistoryEntries();
402
            }
403
        }
404
        return list;
405
    }
406
407
295
    private File pathTranslation(File file, String intermediateElements, String filePrefix, String fileSuffix) throws IOException {
408
296
        
409
297
        File f = file;