2929import hudson .model .TaskListener ;
3030import hudson .model .queue .Tasks ;
3131import hudson .plugins .git .browser .GitRepositoryBrowser ;
32+ import hudson .plugins .git .extensions .GitClientConflictException ;
33+ import hudson .plugins .git .extensions .GitClientType ;
34+ import hudson .plugins .git .extensions .GitSCMChangelogExtension ;
3235import hudson .plugins .git .extensions .GitSCMExtension ;
3336import hudson .plugins .git .extensions .GitSCMExtensionDescriptor ;
3437import hudson .plugins .git .extensions .impl .AuthorInChangelog ;
5962import hudson .util .ListBoxModel ;
6063import jenkins .model .Jenkins ;
6164import jenkins .plugins .git .GitSCMMatrixUtil ;
65+ import jenkins .plugins .git .LegacyGitSCMChangelogExtension ;
6266import net .sf .json .JSONObject ;
6367
6468import org .eclipse .jgit .errors .MissingObjectException ;
@@ -1247,7 +1251,7 @@ public void checkout(Run<?, ?> build, Launcher launcher, FilePath workspace, Tas
12471251
12481252 if (changelogFile != null ) {
12491253 computeChangeLog (git , revToBuild .revision , listener , previousBuildData , new FilePath (changelogFile ),
1250- new BuildChooserContextImpl ( build . getParent (), build , environment ) );
1254+ build );
12511255 }
12521256 }
12531257
@@ -1266,6 +1270,7 @@ private void printCommitMessageToLog(TaskListener listener, GitClient git, final
12661270 }
12671271 }
12681272
1273+ // TODO update JavaDoc
12691274 /**
12701275 * Build up change log from all the branches that we've merged into {@code revToBuild}.
12711276 *
@@ -1308,33 +1313,16 @@ private void printCommitMessageToLog(TaskListener listener, GitClient git, final
13081313 * Information that captures what we did during the last build. We need this for changelog,
13091314 * or else we won't know where to stop.
13101315 */
1311- private void computeChangeLog (GitClient git , Revision revToBuild , TaskListener listener , BuildData previousBuildData , FilePath changelogFile , BuildChooserContext context ) throws IOException , InterruptedException {
1316+ private void computeChangeLog (GitClient git , Revision revToBuild , TaskListener listener , BuildData previousBuildData , FilePath changelogFile , Run <?, ?> build ) throws IOException , InterruptedException {
13121317 boolean executed = false ;
13131318 ChangelogCommand changelog = git .changelog ();
1314- changelog .includes ( revToBuild . getSha1 ());
1319+ changelog .max ( MAX_CHANGELOG ); // default to allow override by extensions
13151320 try (Writer out = new OutputStreamWriter (changelogFile .write (),"UTF-8" )) {
1316- boolean exclusion = false ;
1317- ChangelogToBranch changelogToBranch = getExtensions ().get (ChangelogToBranch .class );
1318- if (changelogToBranch != null ) {
1319- listener .getLogger ().println ("Using 'Changelog to branch' strategy." );
1320- changelog .excludes (changelogToBranch .getOptions ().getRef ());
1321- exclusion = true ;
1322- } else {
1323- for (Branch b : revToBuild .getBranches ()) {
1324- Build lastRevWas = getBuildChooser ().prevBuildForChangelog (b .getName (), previousBuildData , git , context );
1325- if (lastRevWas != null && lastRevWas .revision != null && git .isCommitInRepo (lastRevWas .getSHA1 ())) {
1326- changelog .excludes (lastRevWas .getSHA1 ());
1327- exclusion = true ;
1328- }
1329- }
1330- }
1321+ GitSCMChangelogExtension ext = getGitSCMChangelogExtension ();
1322+ boolean decorated = ext .decorateChangelogCommand (this , build , git , listener , changelog , revToBuild );
13311323
1332- if (!exclusion ) {
1333- // this is the first time we are building this branch, so there's no base line to compare against.
1334- // if we force the changelog, it'll contain all the changes in the repo, which is not what we want.
1335- listener .getLogger ().println ("First time build. Skipping changelog." );
1336- } else {
1337- changelog .to (out ).max (MAX_CHANGELOG ).execute ();
1324+ if (decorated ) {
1325+ changelog .to (out ).execute ();
13381326 executed = true ;
13391327 }
13401328 } catch (GitException ge ) {
@@ -1344,6 +1332,13 @@ private void computeChangeLog(GitClient git, Revision revToBuild, TaskListener l
13441332 }
13451333 }
13461334
1335+ private GitSCMChangelogExtension getGitSCMChangelogExtension () {
1336+ GitSCMChangelogExtension ext = getExtensions ().get (GitSCMChangelogExtension .class );
1337+ if (ext == null )
1338+ ext = new LegacyGitSCMChangelogExtension ();
1339+ return ext ;
1340+ }
1341+
13471342 @ Override
13481343 @ Deprecated // Overrides a deprecated implementation, must also be deprecated
13491344 public void buildEnvVars (AbstractBuild <?, ?> build , Map <String , String > env ) {
0 commit comments