Skip to content

Commit 7071eb4

Browse files
committed
[JENKINS-76004] Use git log instead of git whatchanged for changelog (jenkinsci#1326)
Command line git 2.51.0 has deprecated the "git whatchanged" command and recommends that it be replaced with "git log --raw". Refer to the blog post: https://github.blog/open-source/git/highlights-from-git-2-51/ Testing done: Interactive testing confirmed that without this change, the changelog that is usually displayed on a freestyle project will silently remain empty when using command line git 2.51.0. With this change, the changelog displays as expected. Automated tests pass on: * Debian 11 (Git 2.30) * Debian 12 (Git 2.39) * FreeBSD 14 (Git 2.50) * Red Hat 8 (Git 2.51, built from source code) * Ubuntu 22 (Git 2.34) * Ubuntu 24 (Git 2.43) * Windows 11 (Git 2.50.1) Those test combinations are a wide range of versions of command line git. (cherry picked from commit 9999864)
1 parent fc007a5 commit 7071eb4

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

CONTRIBUTING.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,4 @@ Run the benchmarks with the command:
8888

8989
* `mvn -P jmh-benchmark -Dbenchmark.run=true test`
9090

91-
The results can be reviewed visiually by pasting the resulting `jmh-report.json` file into the link:https://jmh.morethan.io/[online JMH visualizer].
91+
The results can be reviewed visually by pasting the resulting `jmh-report.json` file into the link:https://jmh.morethan.io/[online JMH visualizer].

src/main/java/org/jenkinsci/plugins/gitclient/ChangelogCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Command builder for generating changelog in the format {@code GitSCM} expects.
99
*
1010
* <p>
11-
* The output format is that of <code>git-whatchanged</code>, which looks something like this:
11+
* The output format is that of <code>git log --raw</code>, which looks something like this:
1212
*
1313
* <pre>
1414
* commit dadaf808d99c4c23c53476b0c48e25a181016300

src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ public void abort() {
12971297

12981298
@Override
12991299
public void execute() throws GitException, InterruptedException {
1300-
ArgumentListBuilder args = new ArgumentListBuilder(gitExe, "whatchanged", "--no-abbrev", "-M");
1300+
ArgumentListBuilder args = new ArgumentListBuilder(gitExe, "log", "--raw", "--no-abbrev", "-M");
13011301
if (isAtLeastVersion(1, 8, 3, 0)) {
13021302
args.add("--format=" + RAW);
13031303
} else {
@@ -1315,7 +1315,7 @@ public void execute() throws GitException, InterruptedException {
13151315
throw new IllegalStateException();
13161316
}
13171317

1318-
// "git whatchanged" std output gives us byte stream of data
1318+
// "git log" std output gives us byte stream of data
13191319
// Commit messages in that byte stream are UTF-8 encoded.
13201320
// We want to decode bytestream to strings using UTF-8 encoding.
13211321
try (WriterOutputStream w = new WriterOutputStream(out, StandardCharsets.UTF_8)) {

src/main/java/org/jenkinsci/plugins/gitclient/GitClient.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ void submoduleUpdate(boolean recursive, boolean remoteTracking, String reference
886886
void addNote(String note, String namespace) throws GitException, InterruptedException;
887887

888888
/**
889-
* Given a Revision, show it as if it were an entry from git whatchanged, so that it
889+
* Given a Revision, show it as if it were an entry from git log --raw, so that it
890890
* can be parsed by GitChangeLogParser.
891891
*
892892
* <p>
@@ -898,14 +898,14 @@ void submoduleUpdate(boolean recursive, boolean remoteTracking, String reference
898898
* behave differently from {@link #changelog()}.
899899
*
900900
* @param r a {@link org.eclipse.jgit.lib.ObjectId} object.
901-
* @return The git whatchanged output, in <code>raw</code> format.
901+
* @return The git log output, in <code>raw</code> format.
902902
* @throws hudson.plugins.git.GitException if underlying git operation fails.
903903
* @throws java.lang.InterruptedException if interrupted.
904904
*/
905905
List<String> showRevision(ObjectId r) throws GitException, InterruptedException;
906906

907907
/**
908-
* Given a Revision, show it as if it were an entry from git whatchanged, so that it
908+
* Given a Revision, show it as if it were an entry from git log --raw, so that it
909909
* can be parsed by GitChangeLogParser.
910910
*
911911
* <p>
@@ -918,14 +918,14 @@ void submoduleUpdate(boolean recursive, boolean remoteTracking, String reference
918918
*
919919
* @param from a {@link org.eclipse.jgit.lib.ObjectId} object.
920920
* @param to a {@link org.eclipse.jgit.lib.ObjectId} object.
921-
* @return The git whatchanged output, in <code>raw</code> format.
921+
* @return The git log output, in <code>raw</code> format.
922922
* @throws hudson.plugins.git.GitException if underlying git operation fails.
923923
* @throws java.lang.InterruptedException if interrupted.
924924
*/
925925
List<String> showRevision(ObjectId from, ObjectId to) throws GitException, InterruptedException;
926926

927927
/**
928-
* Given a Revision, show it as if it were an entry from git whatchanged, so that it
928+
* Given a Revision, show it as if it were an entry from <code>git log --raw</code>, so that it
929929
* can be parsed by GitChangeLogParser.
930930
*
931931
* <p>
@@ -943,7 +943,7 @@ void submoduleUpdate(boolean recursive, boolean remoteTracking, String reference
943943
* @param from a {@link org.eclipse.jgit.lib.ObjectId} object.
944944
* @param to a {@link org.eclipse.jgit.lib.ObjectId} object.
945945
* @param useRawOutput a {java.lang.Boolean} object.
946-
* @return The git whatchanged output, in <code>raw</code> format.
946+
* @return The git log output, in <code>raw</code> format.
947947
* @throws hudson.plugins.git.GitException if underlying git operation fails.
948948
* @throws java.lang.InterruptedException if interrupted.
949949
*/

src/main/java/org/jenkinsci/plugins/gitclient/JGitAPIImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,15 +1350,15 @@ public void execute() throws GitException {
13501350
this.includes("HEAD");
13511351
}
13521352
for (RevCommit commit : walk) {
1353-
// git whatachanged doesn't show the merge commits unless -m is given
1353+
// git log --raw doesn't show the merge commits unless -m is given
13541354
if (commit.getParentCount() > 1) {
13551355
continue;
13561356
}
13571357

13581358
formatter.format(commit, null, pw, true);
13591359
}
13601360
} catch (IOException e) {
1361-
throw new GitException("Error: jgit whatchanged in " + workspace + " " + e.getMessage(), e);
1361+
throw new GitException("Error: jgit log --raw in " + workspace + " " + e.getMessage(), e);
13621362
} finally {
13631363
closeResources();
13641364
}
@@ -1400,7 +1400,7 @@ private String statusOf(DiffEntry d) {
14001400
* Commit to format.
14011401
* @param parent
14021402
* Optional parent commit to produce the diff against. This only matters
1403-
* for merge commits, and git-log/git-whatchanged/etc behaves differently with respect to this.
1403+
* for merge commits, and git-log behaves differently with respect to this.
14041404
*/
14051405
@SuppressFBWarnings(
14061406
value = "VA_FORMAT_STRING_USES_NEWLINE",

0 commit comments

Comments
 (0)