Skip to content

Commit c9be3c3

Browse files
shaehnVladimir Kotal
authored andcommitted
Improvements to AccuRev Repository
Added code to indicate parent stream of user's Accurev workspace. This will be seen on OpenGrok home page.
1 parent ea56524 commit c9be3c3

File tree

1 file changed

+91
-40
lines changed

1 file changed

+91
-40
lines changed

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

Lines changed: 91 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,18 @@ public class AccuRevRepository extends Repository {
8080
= Pattern.compile("^\\s+(\\d+\\\\\\d+)\\s+(\\w+)\\s+.*"); // version, user, code line
8181
private static final Pattern depotPattern
8282
= Pattern.compile("^Depot:\\s+(\\w+)");
83+
private static final Pattern parentPattern
84+
= Pattern.compile("^Basis:\\s+(\\w+)");
8385
private static final RuntimeEnvironment env = RuntimeEnvironment.getInstance();
8486

87+
private String depotName = null;
88+
private String parent = null;
89+
/**
90+
* This will be /./ on Unix and \.\ on Windows
91+
*/
92+
private static final String depotRoot
93+
= String.format( "%s.%s", File.separator, File.separator );
94+
8595
public AccuRevRepository() {
8696
type = "AccuRev";
8797
datePatterns = new String[]{
@@ -176,8 +186,7 @@ InputStream getHistoryGet(String parent, String basename, String rev) {
176186
File directory = new File(parent);
177187

178188
/*
179-
* ----------------------------------------------------------------- The
180-
* only way to guarantee getting the contents of a file is to fire off
189+
* Only way to guarantee getting the contents of a file is to fire off
181190
* an AccuRev 'stat'us command to get the element ID number for the
182191
* subsequent 'cat' command. (Element ID's are unique for a file, unless
183192
* evil twins are present) This is because it is possible that the file
@@ -187,7 +196,6 @@ InputStream getHistoryGet(String parent, String basename, String rev) {
187196
* <filePath> <elementID> <virtualVersion> (<realVersion>) (<status>)
188197
*
189198
* /./myFile e:17715 CP.73_Depot/2 (3220/2) (backed)
190-
*-----------------------------------------------------------------
191199
*/
192200
cmd.add(RepoCommand);
193201
cmd.add("stat");
@@ -210,9 +218,7 @@ InputStream getHistoryGet(String parent, String basename, String rev) {
210218

211219
if (elementID != null) {
212220
/*
213-
* ------------------------------------------ This really gets the
214-
* contents of the file.
215-
*------------------------------------------
221+
* This really gets the contents of the file.
216222
*/
217223
cmd.clear();
218224
cmd.add(RepoCommand);
@@ -257,64 +263,104 @@ public boolean fileHasAnnotation(File file) {
257263
}
258264

259265
/**
260-
* Check if a given path is associated with an AccuRev workspace
266+
* Expecting data of the form:
261267
*
262-
* The AccuRev 'info' command provides a Depot name when in a known
263-
* workspace. Otherwise, the Depot name will be missing.
268+
* Principal: shaehn
269+
* Host: waskly
270+
* Server name: lean.machine.com
271+
* Port: 5050
272+
* DB Encoding: Unicode
273+
* ACCUREV_BIN: C:\Program Files (x86)\AccuRev\bin
274+
* Client time: 2017/08/02 13:30:31 Eastern Daylight Time (1501695031)
275+
* Server time: 2017/08/02 13:30:54 Eastern Daylight Time (1501695054)
276+
* Depot: bread_and_butter
277+
* Workspace/ref: BABS_2_shaehn
278+
* Basis: BABS2
279+
* Top: C:\Users\shaehn\workspaces\BABS_2
264280
*
265-
* @param path The presumed path to an AccuRev workspace directory.
266-
* @return true if the given path is in the depot, false otherwise
281+
* Output would be similar on Unix boxes, but with '/' appearing
282+
* in path names instead of '\'. The 'Basis' (BABS2) is the parent
283+
* stream of the user workspace (BABS_2_shaehn). The 'Top' is the
284+
* path to the user workspace/repository. The elements below
285+
* 'Server time' will be missing when current working directory
286+
* is not within a known AccuRev workspace/repository.
267287
*/
268-
private boolean isInAccuRevDepot(File wsPath) {
269-
270-
boolean status = false;
271-
272-
if (isWorking()) {
273-
ArrayList<String> cmd = new ArrayList<>();
288+
private void getAccuRevInfo( File wsPath ) {
289+
290+
ArrayList<String> cmd = new ArrayList<>();
274291

275-
cmd.add(RepoCommand);
276-
cmd.add("info");
292+
cmd.add(RepoCommand);
293+
cmd.add("info");
277294

278-
Executor executor = new Executor(cmd, wsPath);
279-
executor.exec(true);
295+
// Desired AccuRev attributes
296+
depotName = null;
297+
parent = null;
298+
299+
Executor executor = new Executor(cmd, wsPath);
300+
executor.exec();
280301

281-
try (BufferedReader info = new BufferedReader(executor.getOutputReader())) {
282-
String line;
283-
while ((line = info.readLine()) != null) {
302+
try (BufferedReader info = new BufferedReader(executor.getOutputReader())) {
303+
String line;
304+
while ((line = info.readLine()) != null) {
284305

285-
Matcher depotMatch = depotPattern.matcher(line);
306+
if (line.contains("not logged in")) {
307+
LOGGER.log(
308+
Level.SEVERE, "Not logged into AccuRev server");
309+
break;
310+
}
286311

287-
if (line.contains("not logged in")) {
288-
LOGGER.log(
289-
Level.SEVERE, "Not logged into AccuRev server");
290-
break;
312+
if (line.startsWith("Depot")) {
313+
Matcher depotMatch = depotPattern.matcher(line);
314+
if (depotMatch.find()) {
315+
depotName = depotMatch.group(1);
291316
}
317+
}
292318

293-
if (depotMatch.find()) {
294-
status = true;
295-
break;
319+
if (line.startsWith("Basis")) {
320+
Matcher parentMatch = parentPattern.matcher(line);
321+
if (parentMatch.find()) {
322+
parent = parentMatch.group(1);
296323
}
297324
}
298-
} catch (IOException e) {
299-
LOGGER.log(Level.SEVERE,
300-
"Could not find AccuRev repository for {0}", wsPath);
301325
}
326+
} catch (IOException e) {
327+
LOGGER.log(Level.SEVERE,
328+
"Could not find AccuRev repository for {0}", wsPath);
329+
}
330+
}
331+
332+
/**
333+
* Check if a given path is associated with an AccuRev workspace
334+
*
335+
* The AccuRev 'info' command provides a Depot name when in a known
336+
* workspace. Otherwise, the Depot name will be missing.
337+
*
338+
* @param wsPath The presumed path to an AccuRev workspace directory.
339+
* @return true if the given path is in the depot, false otherwise
340+
*/
341+
private boolean isInAccuRevDepot(File wsPath) {
342+
343+
boolean status = false;
344+
345+
if (isWorking()) {
346+
getAccuRevInfo( wsPath );
347+
status = (depotName != null);
302348
}
303349

304350
return status;
305351
}
306352

307353
public String getDepotRelativePath(File file) {
308354

309-
String path = File.separator + "." + File.separator;
355+
String path = depotRoot;
310356

311357
try {
312-
path = env.getPathRelativeToSourceRoot(file);
358+
path = env.getPathRelativeToSourceRoot(file, 0);
313359

314360
if (path.startsWith(File.separator)) {
315361
path = File.separator + "." + path;
316362
} else {
317-
path = File.separator + "." + File.separator + path;
363+
path = depotRoot + path;
318364
}
319365
} catch (IOException e) {
320366
LOGGER.log(Level.WARNING,
@@ -328,7 +374,11 @@ public String getDepotRelativePath(File file) {
328374
@Override
329375
boolean isRepositoryFor(File sourceHome) {
330376

331-
return isInAccuRevDepot(sourceHome);
377+
if (sourceHome.isDirectory()) {
378+
return isInAccuRevDepot(sourceHome);
379+
}
380+
381+
return false;
332382
}
333383

334384
@Override
@@ -354,7 +404,8 @@ History getHistory(File file) throws HistoryException {
354404

355405
@Override
356406
String determineParent() throws IOException {
357-
return null;
407+
getAccuRevInfo(new File(directoryName));
408+
return parent;
358409
}
359410

360411
@Override

0 commit comments

Comments
 (0)