Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSoC-2020] Git Repository Size Estimation #931

Merged
merged 60 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
f477da8
[GSoC'20] Git Repository Size Estimation API
rishabhBudhouliya Jul 20, 2020
e217116
Add newline to EOF
rishabhBudhouliya Jul 20, 2020
2a879a8
Add Javadoc comments for better readability
rishabhBudhouliya Jul 20, 2020
008a126
Instead of providing null if no recommendation is provided, return
rishabhBudhouliya Jul 21, 2020
c2a82f0
Add two test cases for GitRepoSizeEstimator
rishabhBudhouliya Jul 21, 2020
14548cf
Rename methods for better consistency and readability
rishabhBudhouliya Jul 21, 2020
766d5f0
Improve assertion with containsString
rishabhBudhouliya Jul 21, 2020
0fbdf85
Add filter to channel only required extension when calling ExtensionList
rishabhBudhouliya Jul 23, 2020
5703a0c
Preserve older tests removed by mistake
rishabhBudhouliya Jul 23, 2020
58ca8e7
Rearrange class methods to improve readability
rishabhBudhouliya Jul 23, 2020
7a2caeb
[GSoC'20] Git Repository Size Estimation API
rishabhBudhouliya Jul 20, 2020
f0d4433
Add newline to EOF
rishabhBudhouliya Jul 20, 2020
c91f211
Add Javadoc comments for better readability
rishabhBudhouliya Jul 20, 2020
3747e65
Instead of providing null if no recommendation is provided, return
rishabhBudhouliya Jul 21, 2020
90aa2c5
Add two test cases for GitRepoSizeEstimator
rishabhBudhouliya Jul 21, 2020
b00c7c3
Rename methods for better consistency and readability
rishabhBudhouliya Jul 21, 2020
a7e25dd
Improve assertion with containsString
rishabhBudhouliya Jul 21, 2020
b9d6d5f
Add filter to channel only required extension when calling ExtensionList
rishabhBudhouliya Jul 23, 2020
af76286
Preserve older tests removed by mistake
rishabhBudhouliya Jul 23, 2020
a6b2d58
Rearrange class methods to improve readability
rishabhBudhouliya Jul 23, 2020
ab924c0
- Remove excessive branching
rishabhBudhouliya Jul 25, 2020
05abccc
Add test case scenarios:
rishabhBudhouliya Jul 25, 2020
7d25b4f
Merge branch 'size-estimator' of https://github.com/rishabhBudhouliya…
rishabhBudhouliya Jul 25, 2020
7408df2
Improve assertion
rishabhBudhouliya Jul 26, 2020
c2fc583
Return inline long instead of declaring it
rishabhBudhouliya Jul 28, 2020
6dfacf7
Change name from GitRepoSizeEstimator to GitToolChooser
rishabhBudhouliya Jul 28, 2020
b26e1b0
Remove duplicate code ->
rishabhBudhouliya Jul 30, 2020
6a9de6c
In the case of more than one implementer plugins accepting the remote…
rishabhBudhouliya Jul 30, 2020
97d6bf5
[change in design]
rishabhBudhouliya Aug 8, 2020
5506dbf
Remove second constructor which is not needed with the latest change …
rishabhBudhouliya Aug 8, 2020
5b14791
Remove unnecessary import statement
rishabhBudhouliya Aug 8, 2020
27afd3d
[change in design]
rishabhBudhouliya Aug 9, 2020
4f74c49
Add credentials to isApplicableTo for verification of remote url with…
rishabhBudhouliya Aug 11, 2020
69bac3c
[change in design]
rishabhBudhouliya Aug 12, 2020
a9b12cb
Access getCacheEntry from AbstractGitSCMSource directly as a static m…
rishabhBudhouliya Aug 12, 2020
fb4adc0
Replace wrong urls with applicable remote names
rishabhBudhouliya Aug 12, 2020
0c79f6b
Add a test case highlighting a scenario with cli git and jgitapache -…
rishabhBudhouliya Aug 13, 2020
f9cfcb2
Fix failing tests: Check if git exe is running on Windows or other pl…
rishabhBudhouliya Aug 17, 2020
9e2622e
Merge branch 'master' into size-estimator
rishabhBudhouliya Aug 17, 2020
589ce14
Silence javadoc warnings
rishabhBudhouliya Aug 17, 2020
f83cffa
Improve javadoc comment description
rishabhBudhouliya Aug 17, 2020
3484e78
Change version of git client plugin to reference UnsupportedCommand
rishabhBudhouliya Aug 17, 2020
3b26071
How a GitToolChooser would work within the Git Plugin
rishabhBudhouliya Aug 17, 2020
c3b2cb1
Add a new extension decoration method
rishabhBudhouliya Aug 17, 2020
6b8926a
Add support to determine if JGit can be used or not
rishabhBudhouliya Aug 17, 2020
71dba8e
Add UnsupportedCommand support to GitToolChooser
rishabhBudhouliya Aug 17, 2020
ff2060a
Add credentials to the GitToolChooser
rishabhBudhouliya Aug 20, 2020
119c84c
Add javadoc for GitToolChooser parameter
MarkEWaite Aug 21, 2020
990b7b9
Format rather than concatenate in logging
MarkEWaite Aug 21, 2020
d680ec3
Remove dead conditional
MarkEWaite Aug 21, 2020
efa286e
Add one more assertion to determineSwitchOnSize
MarkEWaite Aug 21, 2020
c55d3cb
Minor change in JGit not supported flag check
rishabhBudhouliya Aug 21, 2020
5f9245c
Add a global switch
rishabhBudhouliya Aug 22, 2020
5157fa5
Make SIZE_TO_SWITCH and JGIT_SUPPORTED private
rishabhBudhouliya Aug 22, 2020
5e679e7
Jelly changes for global switch: disableGitToolChooser
rishabhBudhouliya Aug 22, 2020
51e67a6
Update the git plugin README with a new global configuration setting:…
rishabhBudhouliya Aug 24, 2020
d057d23
Remove an additional check which was creating a bug
rishabhBudhouliya Aug 24, 2020
e5bff95
Update the README for disable gitoolchooser addition
rishabhBudhouliya Aug 24, 2020
be91682
Continue sentence per line formatting in README
MarkEWaite Aug 24, 2020
612f554
Require git client 3.4.2
MarkEWaite Aug 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ Hide credential identifier in job output::

If checked, the console log will not show the credential identifier used to clone a repository.

[[disable-performance-enhancements]]
Disable GitToolChooser which tries to suggest an optimal git implementation::

If checked, the plugin will disable a feature which recommends a git implementation on the basis of the size of a repository.
This switch may be used in case of a bug in the performance improvement feature.
If you enable this setting, please report a git plugin issue that describes why you needed to enable it.

[[preserve-second-fetch-during-checkout]]
Preserve second fetch during initial checkout::

Expand Down
Binary file modified images/git-global-configuration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git-client</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
85 changes: 58 additions & 27 deletions src/main/java/hudson/plugins/git/GitSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;
import com.google.common.collect.Iterables;

Expand All @@ -17,16 +18,8 @@
import hudson.FilePath;
import hudson.Launcher;
import hudson.init.Initializer;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.*;
import hudson.model.Descriptor.FormException;
import hudson.model.Items;
import hudson.model.Job;
import hudson.model.Node;
import hudson.model.Queue;
import hudson.model.Run;
import hudson.model.Saveable;
import hudson.model.TaskListener;
import hudson.plugins.git.browser.GitRepositoryBrowser;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.GitSCMExtensionDescriptor;
Expand Down Expand Up @@ -59,6 +52,7 @@
import hudson.util.ListBoxModel;
import jenkins.model.Jenkins;
import jenkins.plugins.git.GitSCMMatrixUtil;
import jenkins.plugins.git.GitToolChooser;
import net.sf.json.JSONObject;

import org.eclipse.jgit.errors.MissingObjectException;
Expand All @@ -68,13 +62,7 @@
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish;
import org.jenkinsci.plugins.gitclient.ChangelogCommand;
import org.jenkinsci.plugins.gitclient.CheckoutCommand;
import org.jenkinsci.plugins.gitclient.CliGitAPIImpl;
import org.jenkinsci.plugins.gitclient.CloneCommand;
import org.jenkinsci.plugins.gitclient.FetchCommand;
import org.jenkinsci.plugins.gitclient.Git;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.gitclient.*;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -448,6 +436,11 @@ public boolean isAllowSecondFetch() {
return (gitDescriptor != null && gitDescriptor.isAllowSecondFetch());
}

public boolean isDisableGitToolChooser() {
DescriptorImpl gitDescriptor = getDescriptor();
return (gitDescriptor != null && gitDescriptor.isDisableGitToolChooser());
}

@Whitelisted
public BuildChooser getBuildChooser() {
BuildChooser bc;
Expand Down Expand Up @@ -844,6 +837,25 @@ public GitClient createClient(TaskListener listener, EnvVars environment, Run<?,
/*package*/ GitClient createClient(TaskListener listener, EnvVars environment, Job project, Node n, FilePath ws) throws IOException, InterruptedException {

String gitExe = getGitExe(n, listener);

if (!isDisableGitToolChooser()) {
UnsupportedCommand unsupportedCommand = new UnsupportedCommand();
for (GitSCMExtension ext : extensions) {
ext.determineSupportForJGit(this, unsupportedCommand);
}
GitToolChooser chooser = null;
for (UserRemoteConfig uc : getUserRemoteConfigs()) {
String ucCredentialsId = uc.getCredentialsId();
String url = getParameterString(uc.getUrl(), environment);
chooser = new GitToolChooser(url, project, ucCredentialsId, gitExe, unsupportedCommand.determineSupportForJGit());
}
listener.getLogger().println("The recommended git tool is: " + chooser.getGitTool());
String updatedGitExe = chooser.getGitTool();

if (!updatedGitExe.equals("NONE")) {
gitExe = updatedGitExe;
}
}
Git git = Git.with(listener, environment).in(ws).using(gitExe);

GitClient c = git.getClient();
Expand All @@ -857,17 +869,7 @@ public GitClient createClient(TaskListener listener, EnvVars environment, Run<?,
listener.getLogger().println("No credentials specified");
} else {
String url = getParameterString(uc.getUrl(), environment);
List<StandardUsernameCredentials> urlCredentials = CredentialsProvider.lookupCredentials(
StandardUsernameCredentials.class,
project,
project instanceof Queue.Task
? ((Queue.Task) project).getDefaultAuthentication()
: ACL.SYSTEM,
URIRequirementBuilder.fromUri(url).build()
);
CredentialsMatcher ucMatcher = CredentialsMatchers.withId(ucCredentialsId);
CredentialsMatcher idMatcher = CredentialsMatchers.allOf(ucMatcher, GitClient.CREDENTIALS_MATCHER);
StandardUsernameCredentials credentials = CredentialsMatchers.firstOrNull(urlCredentials, idMatcher);
StandardUsernameCredentials credentials = lookupScanCredentials(project, url, ucCredentialsId);
if (credentials != null) {
c.addCredentials(url, credentials);
if(!isHideCredentials()) {
Expand All @@ -888,6 +890,30 @@ public GitClient createClient(TaskListener listener, EnvVars environment, Run<?,
return c;
}

private static StandardUsernameCredentials lookupScanCredentials(@CheckForNull Item project,
@CheckForNull String url,
@CheckForNull String ucCredentialsId) {
if (Util.fixEmpty(ucCredentialsId) == null) {
return null;
} else {
return CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(
StandardUsernameCredentials.class,
project,
project instanceof Queue.Task
? ((Queue.Task) project).getDefaultAuthentication()
: ACL.SYSTEM,
URIRequirementBuilder.fromUri(url).build()
),
CredentialsMatchers.allOf(CredentialsMatchers.withId(ucCredentialsId), GitClient.CREDENTIALS_MATCHER)
);
}
}

private static CredentialsMatcher gitScanCredentialsMatcher() {
return CredentialsMatchers.anyOf(CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class));
}

@NonNull
private BuildData fixNull(BuildData bd) {
ScmName sn = getExtensions().get(ScmName.class);
Expand Down Expand Up @@ -1537,6 +1563,7 @@ public static final class DescriptorImpl extends SCMDescriptor<GitSCM> {
private boolean showEntireCommitSummaryInChanges;
private boolean hideCredentials;
private boolean allowSecondFetch;
private boolean disableGitToolChooser;

public DescriptorImpl() {
super(GitSCM.class, GitRepositoryBrowser.class);
Expand Down Expand Up @@ -1672,6 +1699,10 @@ public void setAllowSecondFetch(boolean allowSecondFetch) {
this.allowSecondFetch = allowSecondFetch;
}

public boolean isDisableGitToolChooser() { return disableGitToolChooser; }

public void setDisableGitToolChooser(boolean disableGitToolChooser) { this.disableGitToolChooser = disableGitToolChooser; }

/**
* Old configuration of git executable - exposed so that we can
* migrate this setting to GitTool without deprecation warnings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@
import java.io.File;
import java.io.IOException;
import java.util.Map;
import org.jenkinsci.plugins.gitclient.CheckoutCommand;
import org.jenkinsci.plugins.gitclient.CloneCommand;
import org.jenkinsci.plugins.gitclient.FetchCommand;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.gitclient.MergeCommand;

import org.jenkinsci.plugins.gitclient.*;

/**
* Extension point to tweak the behaviour of {@link GitSCM}.
Expand Down Expand Up @@ -233,6 +230,15 @@ public GitClient decorate(GitSCM scm, GitClient git) throws IOException, Interru
return git;
}

/**
* Called when support of JGit for a particular or multiple extensions is to be determined
* @param scm GitSCM object
* @param unsupportedCommand UnsupportedCommand object
*/
public void determineSupportForJGit(GitSCM scm, UnsupportedCommand unsupportedCommand) {

}

/**
* Called before a {@link CloneCommand} is executed to allow extensions to alter its behaviour.
* @param scm GitSCM object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Objects;
import org.jenkinsci.plugins.gitclient.CheckoutCommand;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.gitclient.UnsupportedCommand;
import org.kohsuke.stapler.DataBoundConstructor;

/**
Expand Down Expand Up @@ -50,6 +51,11 @@ public void decorateCheckoutCommand(GitSCM scm, Run<?, ?> build, GitClient git,
cmd.timeout(timeout);
}

@Override
public void determineSupportForJGit(GitSCM scm, UnsupportedCommand cmd) {
cmd.timeout(timeout);
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jenkinsci.plugins.gitclient.CloneCommand;
import org.jenkinsci.plugins.gitclient.FetchCommand;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.gitclient.UnsupportedCommand;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
Expand Down Expand Up @@ -185,6 +186,13 @@ public void decorateFetchCommand(GitSCM scm, GitClient git, TaskListener listene
cmd.timeout(timeout);
}

@Override
public void determineSupportForJGit(GitSCM scm, UnsupportedCommand cmd) {
cmd.timeout(timeout);
cmd.shallow(shallow);
cmd.depth(depth);
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.eclipse.jgit.transport.RemoteConfig;
import org.jenkinsci.plugins.gitclient.CheckoutCommand;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.gitclient.UnsupportedCommand;
import org.kohsuke.stapler.DataBoundConstructor;

/**
Expand Down Expand Up @@ -44,6 +45,12 @@ public void decorateCheckoutCommand(GitSCM scm, Run<?, ?> build, GitClient git,
}
}

@Override
public void determineSupportForJGit(GitSCM scm, UnsupportedCommand cmd) {
List<RemoteConfig> repos = scm.getRepositories();
cmd.lfsRemote(repos.get(0).getName());
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.jenkinsci.plugins.gitclient.CheckoutCommand;
import org.jenkinsci.plugins.gitclient.CloneCommand;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.gitclient.UnsupportedCommand;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.kohsuke.stapler.DataBoundConstructor;

Expand Down Expand Up @@ -44,6 +45,11 @@ public void decorateCheckoutCommand(GitSCM scm, Run<?, ?> build, GitClient git,
cmd.sparseCheckoutPaths(Lists.transform(sparseCheckoutPaths, SparseCheckoutPath.SPARSE_CHECKOUT_PATH_TO_PATH));
}

@Override
public void determineSupportForJGit(GitSCM scm, UnsupportedCommand cmd) {
cmd.sparseCheckoutPaths(Lists.transform(sparseCheckoutPaths, SparseCheckoutPath.SPARSE_CHECKOUT_PATH_TO_PATH));
}

@Extension
public static class DescriptorImpl extends GitSCMExtensionDescriptor {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Objects;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.gitclient.SubmoduleUpdateCommand;
import org.jenkinsci.plugins.gitclient.UnsupportedCommand;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
Expand Down Expand Up @@ -181,6 +182,16 @@ public void onCheckoutCompleted(GitSCM scm, Run<?, ?> build, GitClient git, Task
}
}

@Override
public void determineSupportForJGit(GitSCM scm, UnsupportedCommand cmd) {
cmd.threads(threads);
cmd.depth(depth);
cmd.shallow(shallow);
cmd.timeout(timeout);
cmd.ref(reference);
cmd.parentCredentials(parentCredentials);
}

/**
* {@inheritDoc}
*/
Expand Down
Loading