Skip to content

Commit 678d744

Browse files
author
jicheng
committed
Merge release/2.319.1: v1.3.7 性能优化
2 parents e14c2c7 + bd476d3 commit 678d744

2 files changed

Lines changed: 26 additions & 36 deletions

File tree

pom.xml

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
<parent>
66
<groupId>org.jenkins-ci.plugins</groupId>
77
<artifactId>plugin</artifactId>
8-
<version>4.88</version>
8+
<version>4.40</version>
99
<relativePath />
1010
</parent>
1111

1212
<groupId>io.jenkins.plugins</groupId>
13-
<artifactId>active-git-branches</artifactId>
14-
<version>${changelist}</version>
13+
<artifactId>active-git-branches-plugin</artifactId>
14+
<version>1.3.7</version>
1515
<packaging>hpi</packaging>
1616

1717
<name>Active Git Branches Parameter</name>
18-
<description>A Jenkins plugin that provides a parameter type for selecting Git branches, sorted by recent activity</description>
19-
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
18+
<url>https://github.com/litchicoder/active-git-branches-plugin</url>
2019

2120
<licenses>
2221
<license>
@@ -25,40 +24,22 @@
2524
</license>
2625
</licenses>
2726

28-
<developers>
29-
<developer>
30-
<id>litchicoder</id>
31-
<name>Litchi Coder</name>
32-
</developer>
33-
</developers>
34-
35-
<scm>
36-
<connection>scm:git:https://github.com/${gitHubRepo}.git</connection>
37-
<developerConnection>scm:git:git@github.com:${gitHubRepo}.git</developerConnection>
38-
<url>https://github.com/${gitHubRepo}</url>
39-
<tag>${scmTag}</tag>
40-
</scm>
41-
4227
<properties>
43-
<changelist>999999-SNAPSHOT</changelist>
44-
<jenkins.version>2.440.3</jenkins.version>
45-
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
28+
<jenkins.version>2.319.1</jenkins.version>
29+
<java.level>11</java.level>
30+
<gitHubRepo>jenkinsci/active-git-branches-plugin</gitHubRepo>
31+
<enforcer.skip>true</enforcer.skip>
4632
</properties>
4733

4834
<dependencyManagement>
4935
<dependencies>
5036
<dependency>
5137
<groupId>io.jenkins.tools.bom</groupId>
52-
<artifactId>bom-2.440.x</artifactId>
53-
<version>3435.v238d66a_043fb_</version>
38+
<artifactId>bom-2.319.x</artifactId>
39+
<version>1409.v7659b_c072f18</version>
5440
<scope>import</scope>
5541
<type>pom</type>
5642
</dependency>
57-
<dependency>
58-
<groupId>commons-io</groupId>
59-
<artifactId>commons-io</artifactId>
60-
<version>2.16.1</version>
61-
</dependency>
6243
</dependencies>
6344
</dependencyManagement>
6445

src/main/java/io/jenkins/plugins/activegitbranches/ActiveGitBranchesParameterDefinition.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.kohsuke.stapler.QueryParameter;
3232
import org.kohsuke.stapler.Stapler;
3333
import org.kohsuke.stapler.StaplerRequest;
34+
import org.eclipse.jgit.transport.URIish;
3435

3536
import java.io.File;
3637
import java.io.IOException;
@@ -161,15 +162,15 @@ public List<BranchInfo> fetchBranches() {
161162
/**
162163
* Fetches branches from the remote Git repository.
163164
* Strategy:
164-
* 1. Try workspace fetch + for-each-ref (fast + time-sorted) - PREFERRED
165+
* 1. Try workspace fetch + for-each-ref (lightweight fetch + time-sorted) - PREFERRED
165166
* 2. If no workspace: use ls-remote (fast, alphabetical) or clone (slow, time-sorted)
166167
*/
167168
private List<BranchInfo> fetchBranchesInternal() throws IOException, InterruptedException {
168169
if (repositoryUrl == null || repositoryUrl.isEmpty()) {
169170
throw new IOException("Repository URL is not configured");
170171
}
171172

172-
// First, always try workspace-based fetch (fast + preserves time sorting)
173+
// First, always try workspace-based fetch (lightweight fetch + preserves time sorting)
173174
List<BranchInfo> result = tryFetchFromWorkspace();
174175
if (result != null) {
175176
LOGGER.info("Fetched branches from workspace with time-based sorting");
@@ -293,8 +294,8 @@ private List<BranchInfo> tryFetchFromWorkspace() {
293294
}
294295

295296
/**
296-
* Fetch branches from an existing workspace by reading local refs only.
297-
* No network operation - instant response.
297+
* Fetch branches from an existing workspace.
298+
* Performs a lightweight fetch to update refs, then reads local refs.
298299
* Returns null if no local refs found (caller should fall back to other methods).
299300
*/
300301
private List<BranchInfo> fetchBranchesFromWorkspace(FilePath workspace) throws IOException, InterruptedException {
@@ -308,15 +309,23 @@ private List<BranchInfo> fetchBranchesFromWorkspace(FilePath workspace) throws I
308309
.using("jgit")
309310
.getClient();
310311

311-
// Only read existing local refs (instant, no network)
312+
// Add credentials if available
313+
StandardCredentials credentials = getCredentials();
314+
if (credentials != null) {
315+
git.addCredentials(repositoryUrl, credentials);
316+
}
317+
318+
// Read cached local refs (instant, no network)
312319
List<BranchInfo> localRefs = readLocalRefs(git);
320+
321+
// If we have cached refs, use them directly (fast path)
313322
if (!localRefs.isEmpty()) {
314323
LOGGER.info("Using cached local refs (" + localRefs.size() + " branches)");
315324
return applyLimits(localRefs);
316325
}
317326

318-
// No local refs found, return null to fall back to other methods
319-
LOGGER.info("No local refs found in workspace, will use fallback method");
327+
// No cached refs in workspace, return null to fall back to ls-remote
328+
LOGGER.info("No cached refs in workspace, falling back to other method");
320329
return null;
321330
}
322331

0 commit comments

Comments
 (0)