Skip to content

Commit

Permalink
[FIXED JENKINS-15735] Group files together to improve cvs rlog effici…
Browse files Browse the repository at this point in the history
…ency
  • Loading branch information
mc1arke committed Mar 17, 2013
1 parent d781d28 commit 8155c0e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
40 changes: 35 additions & 5 deletions src/main/java/hudson/scm/AbstractCvs.java
Expand Up @@ -51,10 +51,23 @@
import org.netbeans.lib.cvsclient.connection.ConnectionIdentity;
import org.netbeans.lib.cvsclient.event.CVSListener;

import java.io.*;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.Reader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

Expand Down Expand Up @@ -277,10 +290,25 @@ public Boolean invoke(final File workspace, final VirtualChannel channel) throws
* @return a CVS client capable of connecting to the specified repository
*/
public Client getCvsClient(final CvsRepository repository, final EnvVars envVars, final TaskListener listener) {
return getCvsClient(repository, envVars, listener, true);
}

/**
* Gets an instance of the CVS client that can be used for connection to a repository. If the
* repository specifies a password then the client's connection will be set with this password.
* @param repository the repository to connect to
* @param envVars variables to use for macro expansion
* @param showAuthenticationInfo whether to log where the authentication details are being obtanied from
* @return a CVS client capable of connecting to the specified repository
*/
public Client getCvsClient(final CvsRepository repository, final EnvVars envVars,
final TaskListener listener, boolean showAuthenticationInfo) {
CVSRoot cvsRoot = CVSRoot.parse(envVars.expand(repository.getCvsRoot()));

if (repository.isPasswordRequired()) {
listener.getLogger().println("Using locally configured password for connection to " + cvsRoot.toString());
if (showAuthenticationInfo) {
listener.getLogger().println("Using locally configured password for connection to " + cvsRoot.toString());
}
cvsRoot.setPassword(Secret.toString(repository.getPassword()));
}
else {
Expand All @@ -290,8 +318,10 @@ public Client getCvsClient(final CvsRepository repository, final EnvVars envVars
if (authentication.getCvsRoot().equals(sanitisedRoot) && (cvsRoot.getUserName() == null || authentication.getUsername().equals(cvsRoot.getUserName()))) {
cvsRoot = CVSRoot.parse(":" + cvsRoot.getMethod() + ":" + (authentication.getUsername() != null ? authentication.getUsername() + "@" :"") + partialRoot);
cvsRoot.setPassword(authentication.getPassword().getPlainText());
listener.getLogger().println("Using globally configured password for connection to '" + sanitisedRoot
+ "' with username '" + authentication.getUsername() + "'");
if (showAuthenticationInfo) {
listener.getLogger().println("Using globally configured password for connection to '"
+ sanitisedRoot + "' with username '" + authentication.getUsername() + "'");
}
break;
}
}
Expand Down
29 changes: 26 additions & 3 deletions src/main/java/hudson/scm/cvstagging/CvsTagActionWorker.java
Expand Up @@ -16,6 +16,10 @@
import org.netbeans.lib.cvsclient.connection.AuthenticationException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CvsTagActionWorker extends TaskThread {

Expand All @@ -42,18 +46,36 @@ public CvsTagActionWorker(final CvsRevisionState revisionState,
@Override
public void perform(final TaskListener listener) throws IOException, InterruptedException, CommandException, AuthenticationException {
for (CvsRepository repository : revisionState.getModuleFiles().keySet()) {
boolean oneIterationComplete = false;
Map<String, List<String>> versionFileMap = new HashMap<String, List<String>>();

for (CvsFile file : revisionState.getModuleState(repository)) {

List<String> filesForVersion = versionFileMap.get(file.getRevision());

if (null == filesForVersion) {
filesForVersion = new ArrayList<String>();
versionFileMap.put(file.getRevision(), filesForVersion);
}

filesForVersion.add(file.getName());

}

for (Map.Entry<String, List<String>> versionEntry : versionFileMap.entrySet()) {
AbstractCvs owner = parent.getParent();
final Client cvsClient = owner.getCvsClient(repository, build.getEnvironment(listener), listener);
final Client cvsClient = owner.getCvsClient(repository, build.getEnvironment(listener), listener, !oneIterationComplete);
final GlobalOptions globalOptions = owner.getGlobalOptions(repository, build.getEnvironment(listener));

globalOptions.setCVSRoot(repository.getCvsRoot());

RtagCommand rtagCommand = new RtagCommand();

rtagCommand.setTag(tagName);
rtagCommand.setTagByRevision(file.getRevision());
rtagCommand.addModule(file.getName());
rtagCommand.setTagByRevision(versionEntry.getKey());
for (String fileName : versionEntry.getValue()) {
rtagCommand.addModule(fileName);
}
rtagCommand.setMakeBranchTag(createBranch);
rtagCommand.setOverrideExistingTag(moveTag);
cvsClient.getEventManager().addCVSListener(
Expand Down Expand Up @@ -81,6 +103,7 @@ public void perform(final TaskListener listener) throws IOException, Interrupted
listener.error("Could not close client connection: " + ex.getMessage());
}
}
oneIterationComplete = true;
}
}
}
Expand Down

0 comments on commit 8155c0e

Please sign in to comment.