@@ -80,8 +80,18 @@ public class AccuRevRepository extends Repository {
80
80
= Pattern .compile ("^\\ s+(\\ d+\\ \\ \\ d+)\\ s+(\\ w+)\\ s+.*" ); // version, user, code line
81
81
private static final Pattern depotPattern
82
82
= Pattern .compile ("^Depot:\\ s+(\\ w+)" );
83
+ private static final Pattern parentPattern
84
+ = Pattern .compile ("^Basis:\\ s+(\\ w+)" );
83
85
private static final RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
84
86
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
+
85
95
public AccuRevRepository () {
86
96
type = "AccuRev" ;
87
97
datePatterns = new String []{
@@ -176,8 +186,7 @@ InputStream getHistoryGet(String parent, String basename, String rev) {
176
186
File directory = new File (parent );
177
187
178
188
/*
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
181
190
* an AccuRev 'stat'us command to get the element ID number for the
182
191
* subsequent 'cat' command. (Element ID's are unique for a file, unless
183
192
* 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) {
187
196
* <filePath> <elementID> <virtualVersion> (<realVersion>) (<status>)
188
197
*
189
198
* /./myFile e:17715 CP.73_Depot/2 (3220/2) (backed)
190
- *-----------------------------------------------------------------
191
199
*/
192
200
cmd .add (RepoCommand );
193
201
cmd .add ("stat" );
@@ -210,9 +218,7 @@ InputStream getHistoryGet(String parent, String basename, String rev) {
210
218
211
219
if (elementID != null ) {
212
220
/*
213
- * ------------------------------------------ This really gets the
214
- * contents of the file.
215
- *------------------------------------------
221
+ * This really gets the contents of the file.
216
222
*/
217
223
cmd .clear ();
218
224
cmd .add (RepoCommand );
@@ -257,64 +263,104 @@ public boolean fileHasAnnotation(File file) {
257
263
}
258
264
259
265
/**
260
- * Check if a given path is associated with an AccuRev workspace
266
+ * Expecting data of the form:
261
267
*
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
264
280
*
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.
267
287
*/
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 <>();
274
291
275
- cmd .add (RepoCommand );
276
- cmd .add ("info" );
292
+ cmd .add (RepoCommand );
293
+ cmd .add ("info" );
277
294
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 ();
280
301
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 ) {
284
305
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
+ }
286
311
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 ) ;
291
316
}
317
+ }
292
318
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 );
296
323
}
297
324
}
298
- } catch (IOException e ) {
299
- LOGGER .log (Level .SEVERE ,
300
- "Could not find AccuRev repository for {0}" , wsPath );
301
325
}
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 );
302
348
}
303
349
304
350
return status ;
305
351
}
306
352
307
353
public String getDepotRelativePath (File file ) {
308
354
309
- String path = File . separator + "." + File . separator ;
355
+ String path = depotRoot ;
310
356
311
357
try {
312
- path = env .getPathRelativeToSourceRoot (file );
358
+ path = env .getPathRelativeToSourceRoot (file , 0 );
313
359
314
360
if (path .startsWith (File .separator )) {
315
361
path = File .separator + "." + path ;
316
362
} else {
317
- path = File . separator + "." + File . separator + path ;
363
+ path = depotRoot + path ;
318
364
}
319
365
} catch (IOException e ) {
320
366
LOGGER .log (Level .WARNING ,
@@ -328,7 +374,11 @@ public String getDepotRelativePath(File file) {
328
374
@ Override
329
375
boolean isRepositoryFor (File sourceHome ) {
330
376
331
- return isInAccuRevDepot (sourceHome );
377
+ if (sourceHome .isDirectory ()) {
378
+ return isInAccuRevDepot (sourceHome );
379
+ }
380
+
381
+ return false ;
332
382
}
333
383
334
384
@ Override
@@ -354,7 +404,8 @@ History getHistory(File file) throws HistoryException {
354
404
355
405
@ Override
356
406
String determineParent () throws IOException {
357
- return null ;
407
+ getAccuRevInfo (new File (directoryName ));
408
+ return parent ;
358
409
}
359
410
360
411
@ Override
0 commit comments