Skip to content

Commit 0ba7200

Browse files
vladakVladimir Kotal
authored andcommitted
make Subversion repository determine current version
1 parent af90e00 commit 0ba7200

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,17 @@ private void initSaxParser() throws HistoryException {
150150
* revision we want, or {@code null} to fetch the entire history
151151
* @return object representing the file's history
152152
*/
153-
History parse(File file, SubversionRepository repos, String sinceRevision)
153+
History parse(File file, SubversionRepository repos, String sinceRevision,
154+
int numEntries)
154155
throws HistoryException {
155156

156157
initSaxParser();
157158
handler = new Handler(repos.getDirectoryName(), repos.reposPath,
158159
RuntimeEnvironment.getInstance().getSourceRootPath().length(),
159160
repos.getDateFormat());
160161

161-
Executor executor = repos.getHistoryLogExecutor(file, sinceRevision);
162+
Executor executor = repos.getHistoryLogExecutor(file, sinceRevision,
163+
numEntries);
162164
int status = executor.exec(true, this);
163165

164166
if (status != 0) {

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,12 @@ public void setDirectoryName(String directoryName) {
170170
* @param sinceRevision the revision number immediately preceding the first
171171
* revision we want, or {@code null} to fetch the entire
172172
* history
173+
* @param numEntries number of entries to return. If 0, return all.
173174
* @return An Executor ready to be started
174175
*/
175-
Executor getHistoryLogExecutor(final File file, String sinceRevision) {
176+
Executor getHistoryLogExecutor(final File file, String sinceRevision,
177+
int numEntries) {
178+
176179
String abs;
177180
try {
178181
abs = file.getCanonicalPath();
@@ -194,6 +197,9 @@ Executor getHistoryLogExecutor(final File file, String sinceRevision) {
194197
cmd.addAll(getAuthCommandLineParams());
195198
cmd.add("--xml");
196199
cmd.add("-v");
200+
if (numEntries > 0) {
201+
cmd.add("-l" + numEntries);
202+
}
197203
if (sinceRevision != null) {
198204
cmd.add("-r");
199205
// We would like to use sinceRevision+1 here, but if no new
@@ -252,9 +258,14 @@ History getHistory(File file) throws HistoryException {
252258
}
253259

254260
@Override
255-
History getHistory(File file, String sinceRevision)
261+
History getHistory(File file, String sinceRevision) throws HistoryException {
262+
return getHistory(file, sinceRevision, 0);
263+
}
264+
265+
private History getHistory(File file, String sinceRevision, int numEntries)
256266
throws HistoryException {
257-
return new SubversionHistoryParser().parse(file, this, sinceRevision);
267+
return new SubversionHistoryParser().parse(file, this, sinceRevision,
268+
numEntries);
258269
}
259270

260271
private String escapeFileName(String name) {
@@ -475,4 +486,21 @@ String determineBranch() throws IOException {
475486

476487
return branch;
477488
}
489+
490+
@Override
491+
public String determineCurrentVersion() throws IOException {
492+
String curVersion = null;
493+
494+
try {
495+
History hist = getHistory(new File(getDirectoryName()), null, 1);
496+
HistoryEntry he = hist.getHistoryEntries().get(0);
497+
curVersion = he.getDate() + ": " + he.getRevision() +
498+
" " + he.getAuthor() + " " + he.getMessage();
499+
} catch (HistoryException ex) {
500+
LOGGER.log(Level.WARNING, "cannot get current version info for {0}",
501+
getDirectoryName());
502+
}
503+
504+
return curVersion;
505+
}
478506
}

0 commit comments

Comments
 (0)