diff options
author | Stefan Lay <stefan.lay@sap.com> | 2011-04-06 14:08:25 +0200 |
---|---|---|
committer | Stefan Lay <stefan.lay@sap.com> | 2011-04-06 15:00:22 +0200 |
commit | fbf35fea4ec254339f9b0eee7865eb6ccfe22700 (patch) | |
tree | b9c1ef896e2058a66cb4f8bb9f17dda5b7679df5 /org.eclipse.jgit | |
parent | 792b93bc62bb3714eb04ccf6e0c800d3b5b85f5b (diff) | |
download | jgit-fbf35fea4ec254339f9b0eee7865eb6ccfe22700.tar.gz jgit-fbf35fea4ec254339f9b0eee7865eb6ccfe22700.zip |
Add parameters for timeout and branches to clone
The timeout is also used in the FetchCommand called by the
CloneCommand.
The possibility to provide a list of branches to fetch initially is a
feature offered by EGit. To implement it here is a prerequisite for
EGit to be able to use the CloneCommand.
Change-Id: I21453de22e9ca61919a7c3386fcc526024742f5f
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java index 52d9e21b09..39652306b0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java @@ -45,6 +45,9 @@ package org.eclipse.jgit.api; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import java.util.concurrent.Callable; import org.eclipse.jgit.api.errors.InvalidRemoteException; @@ -91,6 +94,12 @@ public class CloneCommand implements Callable<Git> { private CredentialsProvider credentialsProvider; + private int timeout; + + private boolean cloneAllBranches; + + private Collection<String> branchesToClone; + /** * Executes the {@code Clone} command. * @@ -146,11 +155,32 @@ public class CloneCommand implements Callable<Git> { command.setRemote(remote); command.setProgressMonitor(monitor); command.setTagOpt(TagOpt.FETCH_TAGS); + command.setTimeout(timeout); if (credentialsProvider != null) command.setCredentialsProvider(credentialsProvider); + + List<RefSpec> specs = calculateRefSpecs(dst); + command.setRefSpecs(specs); + return command.call(); } + private List<RefSpec> calculateRefSpecs(final String dst) { + RefSpec wcrs = new RefSpec(); + wcrs = wcrs.setForceUpdate(true); + wcrs = wcrs.setSourceDestination(Constants.R_HEADS + "*", dst + "/*"); //$NON-NLS-1$ //$NON-NLS-2$ + List<RefSpec> specs = new ArrayList<RefSpec>(); + if (cloneAllBranches) + specs.add(wcrs); + else if (branchesToClone != null + && branchesToClone.size() > 0) { + for (final String selectedRef : branchesToClone) + if (wcrs.matchSource(selectedRef)) + specs.add(wcrs.expandFromSource(selectedRef)); + } + return specs; + } + private void checkout(Repository repo, FetchResult result) throws JGitInternalException, MissingObjectException, IncorrectObjectTypeException, IOException { @@ -306,4 +336,36 @@ public class CloneCommand implements Callable<Git> { return this; } + /** + * @param timeout + * the timeout used for the fetch step + * @return {@code this} + */ + public CloneCommand setTimeout(int timeout) { + this.timeout = timeout; + return this; + } + + /** + * @param cloneAllBranches + * true when all branches have to be fetched (indicates wildcard + * in created fetch refspec), false otherwise. + * @return {@code this} + */ + public CloneCommand setCloneAllBranches(boolean cloneAllBranches) { + this.cloneAllBranches = cloneAllBranches; + return this; + } + + /** + * @param branchesToClone + * collection of branches to clone. Ignored when allSelected is + * true. + * @return {@code this} + */ + public CloneCommand setBranchesToClone(Collection<String> branchesToClone) { + this.branchesToClone = branchesToClone; + return this; + } + } |