Skip to content

Commit

Permalink
[JENKINS-18574] Fixes for multiple locations in same repo
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-beck committed May 22, 2014
1 parent 6745bfb commit 08ed6c9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/main/java/hudson/scm/DirAwareSVNXMLLogHandler.java
Expand Up @@ -11,6 +11,7 @@
*/
package hudson.scm;

import java.io.File;
import java.util.Iterator;
import java.util.LinkedList;

Expand Down Expand Up @@ -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() + "");
Expand Down
31 changes: 30 additions & 1 deletion src/main/java/hudson/scm/SubversionChangeLogSet.java
Expand Up @@ -128,6 +128,24 @@ static List<LogEntry> removePropertyOnlyChanges(List<LogEntry> items) {
*/
static List<LogEntry> removeDuplicatedEntries(List<LogEntry> items) {
Set<LogEntry> entries = new HashSet<LogEntry>(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<LogEntry>(entries);
}

Expand Down Expand Up @@ -309,7 +327,14 @@ public List<Path> getPaths() {

@Override
public Collection<Path> getAffectedFiles() {
return paths;
Collection<Path> affectedFiles = new ArrayList<Path>();
for (Path p : paths) {
if (p.hasLocalPath()) {
affectedFiles.add(p);
}
}
// FIXME backwards compatibility?
return affectedFiles;
}

void finish() {
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 17 additions & 1 deletion src/main/resources/hudson/scm/SubversionChangeLogSet/index.jelly
Expand Up @@ -37,7 +37,7 @@ THE SOFTWARE.
<table class="pane" style="border:none">
<j:forEach var="cs" items="${it.logs}" varStatus="loop">
<tr class="pane">
<td colspan="2" class="changeset">
<td colspan="3" class="changeset">
<a name="detail${loop.index}"></a>
<div class="changeset-message">
<b>
Expand All @@ -50,6 +50,12 @@ THE SOFTWARE.
</td>
</tr>

<tr>
<th style="text-align: left;">${%Change Type}</th>
<th style="text-align: left;">${%Path in Repository}</th>
<th style="text-align: left;">${%Path in Workspace}</th>
</tr>

<j:forEach var="p" items="${cs.paths}">
<tr>
<td><t:editTypeIcon type="${p.editType}" /></td>
Expand All @@ -61,6 +67,16 @@ THE SOFTWARE.
<a href="${diff}">(diff)</a>
</j:if>
</td>
<td>
<j:choose>
<j:when test="${p.hasLocalPath()}">
${p.path}
</j:when>
<j:otherwise>
<span style="color:grey;">${%N/A}</span>
</j:otherwise>
</j:choose>
</td>
</tr>
</j:forEach>
</j:forEach>
Expand Down

0 comments on commit 08ed6c9

Please sign in to comment.