use of net.nemerosa.ontrack.extension.svn.support.SVNLogEntryCollector in project ontrack by nemerosa.
the class SVNChangeLogServiceImpl method getChangeLogRevisions.
@Override
@Transactional
public SVNChangeLogRevisions getChangeLogRevisions(SVNChangeLog changeLog) {
// Reference
Collection<SVNChangeLogReference> references = changeLog.getChangeLogReferences();
// No difference?
if (references.isEmpty()) {
return SVNChangeLogRevisions.none();
}
// SVN transaction
try (Transaction ignored = transactionService.start()) {
List<SVNChangeLogRevision> revisions = new ArrayList<>();
for (SVNChangeLogReference reference : references) {
if (!reference.isNone()) {
SVNRepository repository = changeLog.getRepository();
// List of log entries
SVNLogEntryCollector logEntryCollector = new SVNLogEntryCollector();
// SVN change log
svnClient.log(repository, SVNUtils.toURL(repository.getUrl(reference.getPath())), SVNRevision.create(reference.getEnd()), SVNRevision.create(reference.getStart() + 1), SVNRevision.create(reference.getEnd()), // Stops on copy
true, // No path discovering (yet)
false, // no limit
0L, // Includes merged revisions
true, logEntryCollector);
// Loops through all SVN log entries, taking the merged revisions into account
int level = 0;
for (SVNLogEntry svnEntry : logEntryCollector.getEntries()) {
long revision = svnEntry.getRevision();
if (SVNRevision.isValidRevisionNumber(revision)) {
// Conversion
SVNChangeLogRevision entry = createChangeLogRevision(repository, reference.getPath(), level, svnEntry);
// Adds it to the list
revisions.add(entry);
// New parent?
if (svnEntry.hasChildren()) {
level++;
}
} else {
level--;
}
}
}
}
// Sorting the revisions
Collections.sort(revisions, // From the newest revision to the oldest
(o1, o2) -> Long.compare(o2.getRevision(), o1.getRevision()));
// OK
return new SVNChangeLogRevisions(revisions);
}
}
use of net.nemerosa.ontrack.extension.svn.support.SVNLogEntryCollector in project ontrack by nemerosa.
the class SVNClientImpl method getMergedRevisions.
@Override
public List<Long> getMergedRevisions(SVNRepository repository, SVNURL url, long revision) {
// Checks that the URL exists at both R-1 and R
SVNRevision rm1 = SVNRevision.create(revision - 1);
SVNRevision r = SVNRevision.create(revision);
boolean existRM1 = exists(repository, url, rm1);
boolean existR = exists(repository, url, r);
try {
// Both revisions must be valid in order to get some merges in between
if (existRM1 && existR) {
// Gets the changes in merge information
SVNDiffClient diffClient = getDiffClient(repository);
@SuppressWarnings("unchecked") Map<SVNURL, SVNMergeRangeList> before = diffClient.doGetMergedMergeInfo(url, rm1);
@SuppressWarnings("unchecked") Map<SVNURL, SVNMergeRangeList> after = diffClient.doGetMergedMergeInfo(url, r);
// Gets the difference between the two merge informations
Map<SVNURL, SVNMergeRangeList> change;
if (after != null && before != null) {
change = new HashMap<>();
for (Map.Entry<SVNURL, SVNMergeRangeList> entry : after.entrySet()) {
SVNURL source = entry.getKey();
SVNMergeRangeList afterMergeRangeList = entry.getValue();
SVNMergeRangeList beforeMergeRangeList = before.get(source);
if (beforeMergeRangeList != null) {
SVNMergeRangeList changeRangeList = afterMergeRangeList.diff(beforeMergeRangeList, false);
if (!changeRangeList.isEmpty()) {
change.put(source, changeRangeList);
}
} else {
change.put(source, afterMergeRangeList);
}
}
} else {
change = after;
}
if (change == null || change.isEmpty()) {
return Collections.emptyList();
} else {
SVNLogEntryCollector collector = new SVNLogEntryCollector();
for (Map.Entry<SVNURL, SVNMergeRangeList> entry : change.entrySet()) {
SVNURL source = entry.getKey();
SVNMergeRangeList mergeRangeList = entry.getValue();
SVNMergeRange[] mergeRanges = mergeRangeList.getRanges();
for (SVNMergeRange mergeRange : mergeRanges) {
SVNRevision endRevision = SVNRevision.create(mergeRange.getEndRevision());
SVNRevision startRevision = SVNRevision.create(mergeRange.getStartRevision());
log(repository, source, endRevision, startRevision, endRevision, true, false, 0, false, collector);
}
}
return collector.getEntries().stream().map(SVNLogEntry::getRevision).collect(Collectors.toList());
}
} else {
// One of the revisions (R-1 or R) is missing
return Collections.emptyList();
}
} catch (SVNException ex) {
throw translateSVNException(ex);
}
}
Aggregations