List<Transaction> workspaceHistory = Collections.emptyList();
List<FileDifference> streamDifferences = Collections.emptyList();
StringBuilder errorMessage = new StringBuilder();
AccuRev accurev = repository.getAccuRev();
Stream changelogStream = accurev.showStream( stream );
if ( changelogStream == null )
{
errorMessage.append( "Unknown accurev stream -" ).append( stream ).append( "." );
}
else
{
String message =
"Changelog on stream " + stream + "(" + changelogStream.getStreamType() + ") from " + fromTranId + " ("
+ startDate + "), to " + toTranId + " (" + endDate + ")";
if ( startDate != null && startDate.after( endDate ) || fromTranId >= toTranId )
{
getLogger().warn( "Skipping out of range " + message );
}
else
{
getLogger().info( message );
// In 4.7.2 and higher we have a diff command that will list all the file differences in a stream
// and thus can be used to detect upstream changes
// Unfortunately diff -v -V -t does not work in workspaces.
Stream diffStream = changelogStream;
if ( changelogStream.isWorkspace() )
{
workspaceHistory =
accurev.history( stream, Long.toString( fromTranId + 1 ), Long.toString( toTranId ), 0, false,
false );
if ( workspaceHistory == null )
{
errorMessage.append( "history on workspace " + stream + " from " + fromTranId + 1 + " to "
+ toTranId + " failed." );
}
// do the diff/hist on the basis stream instead.
stream = changelogStream.getBasis();
diffStream = accurev.showStream( stream );
}
if ( AccuRevCapability.DIFF_BETWEEN_STREAMS.isSupported( accurev.getClientVersion() ) )
{
if ( startDate.before( diffStream.getStartDate() ) )
{
getLogger().warn( "Skipping diff of " + stream + " due to start date out of range" );
}
else
{
streamDifferences =
accurev.diff( stream, Long.toString( fromTranId ), Long.toString( toTranId ) );
if ( streamDifferences == null )
{
errorMessage.append( "Diff " + stream + "- " + fromTranId + " to " + toTranId + "failed." );
}
}
}
// History needs to start from the transaction after our starting transaction
streamHistory =
accurev.history( stream, Long.toString( fromTranId + 1 ), Long.toString( toTranId ), 0, false,
false );
if ( streamHistory == null )
{
errorMessage.append( "history on stream " + stream + " from " + fromTranId + 1 + " to " + toTranId
+ " failed." );
}
}
}
String errorString = errorMessage.toString();
if ( StringUtils.isBlank( errorString ) )
{
ChangeLogSet changeLog =
getChangeLog( changelogStream, streamDifferences, streamHistory, workspaceHistory, startDate, endDate );
changeLog.setEndVersion( endVersion );
changeLog.setStartVersion( startVersion );
return new ChangeLogScmResult( accurev.getCommandLines(), changeLog );
}
else
{
return new ChangeLogScmResult( accurev.getCommandLines(), "AccuRev errors: " + errorMessage,
accurev.getErrorOutput(), false );
}
}