1
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3
* The contents of this file are subject to the Netscape Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/NPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
13
* The Original Code is Mozilla Communicator client code, released
16
* The Initial Developer of the Original Code is Netscape
17
* Communications Corporation. Portions created by Netscape are
18
* Copyright (C) 1998 Netscape Communications Corporation. All
23
* Patrick C. Beard <beard@netscape.com>
25
* Alternatively, the contents of this file may be used under the
26
* terms of the GNU Public License (the "GPL"), in which case the
27
* provisions of the GPL are applicable instead of those above.
28
* If you wish to allow use of your version of this file only
29
* under the terms of the GPL and not to allow others to use your
30
* version of this file under the NPL, indicate your decision by
31
* deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL. If you do not delete
33
* the provisions above, a recipient may use your version of this
34
* file under either the NPL or the GPL.
41
* Provides a way to map from a file path to its CVS revision number.
43
public class RevisionTable {
44
private Hashtable revisions = new Hashtable();
46
public String getRevision(String path) throws IOException {
47
String revision = (String) revisions.get(path);
48
if (revision == null) {
49
int lastSlash = path.lastIndexOf('/');
50
String dirPath = path.substring(0, lastSlash + 1);
51
if (!readEntries(dirPath))
52
revisions.put(path, "");
53
revision = (String) revisions.get(path);
59
* Reads all of the entries from a CVS Entries file, and populates
60
* the hashtable with the revisions, keyed by file paths.
62
private boolean readEntries(String dirPath) throws IOException {
63
File entriesFile = new File(dirPath + "CVS/Entries");
64
if (entriesFile.exists()) {
65
BufferedReader entries = new BufferedReader(new InputStreamReader(new FileInputStream(entriesFile)));
66
for (String line = entries.readLine(); line != null; line = entries.readLine()) {
67
if (line.charAt(0) == '/') {
68
int secondSlash = line.indexOf('/', 1);
69
String fileName = line.substring(1, secondSlash);
70
int thirdSlash = line.indexOf('/', secondSlash + 1);
71
String revision = line.substring(secondSlash + 1, thirdSlash);
72
revisions.put(dirPath + fileName, revision);