Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-19653] expand branch name during poll
  • Loading branch information
mc1arke committed Oct 20, 2013
1 parent 3268e14 commit e1be536
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/main/java/hudson/scm/AbstractCvs.java
Expand Up @@ -602,7 +602,7 @@ protected List<CvsFile> calculateRepositoryState(final Date startTime, final Dat

// use the parser to build up a list of changed files and add it to
// the list we've been creating
files.addAll(logContents.mapCvsLog(envVars.expand(repository.getCvsRoot()), item.getLocation(), repository).getFiles());
files.addAll(logContents.mapCvsLog(envVars.expand(repository.getCvsRoot()), item.getLocation(), repository, envVars).getFiles());

}
}
Expand Down Expand Up @@ -767,7 +767,7 @@ protected List<CVSChangeLogSet.CVSChangeLog> calculateChangeLog(final Date start

// use the parser to build up a list of changes and add it to the
// list we've been creating
changes.addAll(logContents.mapCvsLog(envVars.expand(repository.getCvsRoot()), item.getLocation(), repository).getChanges());
changes.addAll(logContents.mapCvsLog(envVars.expand(repository.getCvsRoot()), item.getLocation(), repository, envVars).getChanges());
}
}
return changes;
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/hudson/scm/CvsLog.java
@@ -1,5 +1,6 @@
package hudson.scm;

import hudson.EnvVars;
import hudson.scm.CVSChangeLogSet.CVSChangeLog;
import org.netbeans.lib.cvsclient.CVSRoot;

Expand Down Expand Up @@ -49,7 +50,8 @@ private static enum Status {
*/
protected abstract void dispose();

public CvsChangeSet mapCvsLog(final String cvsRoot, final CvsRepositoryLocation location, final CvsRepository repository) throws IOException {
public CvsChangeSet mapCvsLog(final String cvsRoot, final CvsRepositoryLocation location,
final CvsRepository repository, final EnvVars envVars) throws IOException {
final List<CVSChangeLog> changes = new ArrayList<CVSChangeLog>();
final Map<String, CvsFile> files = new HashMap<String, CvsFile>();
CVSChangeLogSet.File file = null;
Expand Down Expand Up @@ -90,7 +92,7 @@ public CvsChangeSet mapCvsLog(final String cvsRoot, final CvsRepositoryLocation
break;

case CHANGE_COMMENT:
status = processComment(line, file, change, status, branches, previousLine, changes, files, location, prePreviousLine);
status = processComment(line, file, change, status, branches, previousLine, changes, files, location, prePreviousLine, envVars);
break;

}
Expand All @@ -102,12 +104,12 @@ public CvsChangeSet mapCvsLog(final String cvsRoot, final CvsRepositoryLocation
// given the way the comments are parsed (initially skip what looks like a divider line, then re-parse it if it
// the following lines don't aren't empty and contain 'RCS file:' (or are null) respectively
if (status == Status.CHANGE_COMMENT) {
status = processComment(null, file, change, Status.CHANGE_COMMENT, branches, line, changes, files, location, previousLine);
status = processComment(null, file, change, Status.CHANGE_COMMENT, branches, line, changes, files, location, previousLine, envVars);
}

if (status == Status.CHANGE_COMMENT) {
//we don't care about the return status now - so don't save it
processComment(null, file, change, Status.CHANGE_COMMENT, branches, null, changes, files, location, line);
processComment(null, file, change, Status.CHANGE_COMMENT, branches, null, changes, files, location, line, envVars);
}
reader.close();
dispose();
Expand Down Expand Up @@ -276,15 +278,16 @@ private Status parseChangeHeader(final String line, final CVSChangeLogSet.File f
*/
private void parsePreviousChangeVersion(final String line, final CVSChangeLogSet.File file, final CVSChangeLog change,
final Map<String, String> branches, final List<CVSChangeLog> changes,
final Map<String, CvsFile> files, final CvsRepositoryLocation location) {
final Map<String, CvsFile> files, final CvsRepositoryLocation location,
final EnvVars envVars) {
if (!line.startsWith("revision")) {
throw new IllegalStateException("Unexpected line from CVS log: " + line);
}

final String revision = line.substring(9);
file.setPrevrevision(revision);

saveChange(file, change, branches, changes, files, location);
saveChange(file, change, branches, changes, files, location, envVars);

file.setRevision(revision);
}
Expand All @@ -307,7 +310,7 @@ private void parsePreviousChangeVersion(final String line, final CVSChangeLogSet
private Status processComment(final String line, final CVSChangeLogSet.File file, final CVSChangeLog change,
final Status currentStatus, final Map<String, String> branches,
final String previousLine, final List<CVSChangeLog> changes, final Map<String, CvsFile> files,
final CvsRepositoryLocation location, final String prePreviousLine) {
final CvsRepositoryLocation location, final String prePreviousLine, final EnvVars envVars) {
if (line != null && line.startsWith(FILE_DIVIDER)) {
if (previousLine.equals(CHANGE_DIVIDER)) {
updateChangeMessage(change, previousLine);
Expand All @@ -325,7 +328,7 @@ private Status processComment(final String line, final CVSChangeLogSet.File file
// and start processing the next file
if ((previousLine == null || previousLine.isEmpty())
&& (line == null || line.startsWith("RCS file:"))) {
saveChange(file, change, branches, changes, files, location);
saveChange(file, change, branches, changes, files, location, envVars);
return Status.FILE_NAME_PREVIOUS_LINE;
} else {
updateChangeMessage(change, prePreviousLine);
Expand All @@ -336,7 +339,7 @@ private Status processComment(final String line, final CVSChangeLogSet.File file
if (line != null && line.startsWith("revision")) {
// the previous commit line has ended and we're now in a new commit.
// Add the current change to our changeset and start processing the next commit
parsePreviousChangeVersion(line, file, change, branches, changes, files, location);
parsePreviousChangeVersion(line, file, change, branches, changes, files, location, envVars);
return Status.CHANGE_HEADER;
} else {
// see next else if line - we may have skipped a line that contains '-------'.
Expand Down Expand Up @@ -384,7 +387,8 @@ private void updateChangeMessage(final CVSChangeLog change, final String line) {
* @param location the CVS Repository location (head/branch/tag) the CVS RLOG was retrieved from
*/
private void saveChange(final CVSChangeLogSet.File file, final CVSChangeLog change, final Map<String, String> branches,
final List<CVSChangeLog> changes, final Map<String, CvsFile> files, final CvsRepositoryLocation location) {
final List<CVSChangeLog> changes, final Map<String, CvsFile> files, final CvsRepositoryLocation location,
final EnvVars envVars) {

final String branch = getBranchNameForRevision(file.getRevision(), branches);

Expand All @@ -399,7 +403,7 @@ private void saveChange(final CVSChangeLogSet.File file, final CVSChangeLog chan

// Check the branch/tag name matches the retrieved branch name
if (!(location instanceof CvsRepositoryLocation.HeadRepositoryLocation)
&& !location.getLocationName().equals(branch)) {
&& !envVars.expand(location.getLocationName()).equals(branch)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/scm/CvsTagsParamDefinition.java
Expand Up @@ -186,7 +186,7 @@ public void dispose() {
};

// we don't care about the repository that's passed to CVS log
changeSet = parser.mapCvsLog(cvsRoot, new CvsRepositoryLocation.HeadRepositoryLocation(), null);
changeSet = parser.mapCvsLog(cvsRoot, new CvsRepositoryLocation.HeadRepositoryLocation(), null, new EnvVars());

}
catch(IOException ex) {
Expand Down
Expand Up @@ -83,7 +83,7 @@ public void perform(final TaskListener listener) throws IOException, Interrupted
listener.getLogger()));

try {
isSuccess = isSuccess || cvsClient.executeCommand(rtagCommand, globalOptions);
isSuccess |= cvsClient.executeCommand(rtagCommand, globalOptions);
} catch (CommandAbortedException e) {
e.printStackTrace(listener
.error("The CVS rtag command was aborted"));
Expand Down

0 comments on commit e1be536

Please sign in to comment.