From 08ed6c99c7d762b32243bf3121f08b4229e98c8b Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Fri, 23 May 2014 01:44:41 +0200 Subject: [PATCH] [JENKINS-18574] Fixes for multiple locations in same repo --- .../hudson/scm/DirAwareSVNXMLLogHandler.java | 18 +++++++++-- .../hudson/scm/SubversionChangeLogSet.java | 31 ++++++++++++++++++- .../scm/SubversionChangeLogSet/index.jelly | 18 ++++++++++- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/main/java/hudson/scm/DirAwareSVNXMLLogHandler.java b/src/main/java/hudson/scm/DirAwareSVNXMLLogHandler.java index ab1c06bf9..d38ff300d 100644 --- a/src/main/java/hudson/scm/DirAwareSVNXMLLogHandler.java +++ b/src/main/java/hudson/scm/DirAwareSVNXMLLogHandler.java @@ -11,6 +11,7 @@ */ package hudson.scm; +import java.io.File; import java.util.Iterator; import java.util.LinkedList; @@ -108,8 +109,21 @@ protected void sendToHandler(SVNLogEntry logEntry) throws SAXException { String key = paths.next(); SVNLogEntryPath path = (SVNLogEntryPath) logEntry.getChangedPaths().get(key); addAttribute(ACTION_ATTR, path.getType() + ""); - String relativeWorkspacePath = context.moduleWorkspacePath + path.getPath().substring(context.url.length() - context.repoUrl.length()); - addAttribute(REL_PATH_ATTR, relativeWorkspacePath); + + // the path within the repo to the location checked out + String modulePath = context.url.substring(context.repoUrl.length()); + + if (path.getPath().startsWith(modulePath)) { + // this path is inside the locally checked out module location, so set relativePath attribute + String relativeWorkspacePath = context.moduleWorkspacePath + path.getPath().substring(context.url.length() - context.repoUrl.length()); + if (".".equals(context.moduleWorkspacePath)) { + // use 'foo', not './foo' + relativeWorkspacePath = relativeWorkspacePath.substring(2); // "./".length() + } + // use File/toString to get rid of duplicate separators + addAttribute(REL_PATH_ATTR, new File(relativeWorkspacePath).toString()); + } + if (path.getCopyPath() != null) { addAttribute(COPYFROM_PATH_ATTR, path.getCopyPath()); addAttribute(COPYFROM_REV_ATTR, path.getCopyRevision() + ""); diff --git a/src/main/java/hudson/scm/SubversionChangeLogSet.java b/src/main/java/hudson/scm/SubversionChangeLogSet.java index 65a8971e2..8f8b8af59 100644 --- a/src/main/java/hudson/scm/SubversionChangeLogSet.java +++ b/src/main/java/hudson/scm/SubversionChangeLogSet.java @@ -128,6 +128,24 @@ static List removePropertyOnlyChanges(List items) { */ static List removeDuplicatedEntries(List items) { Set entries = new HashSet(items); + for (LogEntry sourceEntry : items) { + // LogEntry equality does not consider paths, but some might have localPath attributes + // that would get lost by HashSet duplicate removal + for (LogEntry destinationEntry : entries) { + if (sourceEntry.equals(destinationEntry)) { + // get all local paths and set in destination + for (Path sourcePath : sourceEntry.getPaths()) { + if (sourcePath.localPath != null) { + for (Path destinationPath : destinationEntry.getPaths()) { + if (sourcePath.value.equals(destinationPath.value)) { + destinationPath.localPath = sourcePath.localPath; + } + } + } + } + } + } + } return new ArrayList(entries); } @@ -309,7 +327,14 @@ public List getPaths() { @Override public Collection getAffectedFiles() { - return paths; + Collection affectedFiles = new ArrayList(); + for (Path p : paths) { + if (p.hasLocalPath()) { + affectedFiles.add(p); + } + } + // FIXME backwards compatibility? + return affectedFiles; } void finish() { @@ -426,6 +451,10 @@ public String getPath() { public void setLocalPath(String path) { this.localPath = path; } + + public boolean hasLocalPath() { + return localPath != null; + } public void setValue(String value) { this.value = value; diff --git a/src/main/resources/hudson/scm/SubversionChangeLogSet/index.jelly b/src/main/resources/hudson/scm/SubversionChangeLogSet/index.jelly index b20a7aa32..4fcc2bc6e 100644 --- a/src/main/resources/hudson/scm/SubversionChangeLogSet/index.jelly +++ b/src/main/resources/hudson/scm/SubversionChangeLogSet/index.jelly @@ -37,7 +37,7 @@ THE SOFTWARE. - + + + + + + @@ -61,6 +67,16 @@ THE SOFTWARE. (diff) +
+
@@ -50,6 +50,12 @@ THE SOFTWARE.
${%Change Type}${%Path in Repository}${%Path in Workspace}
+ + + ${p.path} + + + ${%N/A} + + +