Skip to content

Commit d3e647d

Browse files
MarkEWaitebasil
authored andcommitted
[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 8985389 commit d3e647d

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
@@ -1300,7 +1300,7 @@ public void abort() {
13001300

13011301
@Override
13021302
public void execute() throws GitException, InterruptedException {
1303-
ArgumentListBuilder args = new ArgumentListBuilder(gitExe, "whatchanged", "--no-abbrev", "-M");
1303+
ArgumentListBuilder args = new ArgumentListBuilder(gitExe, "log", "--raw", "--no-abbrev", "-M");
13041304
if (isAtLeastVersion(1, 8, 3, 0)) {
13051305
args.add("--format=" + RAW);
13061306
} else {
@@ -1318,7 +1318,7 @@ public void execute() throws GitException, InterruptedException {
13181318
throw new IllegalStateException();
13191319
}
13201320

1321-
// "git whatchanged" std output gives us byte stream of data
1321+
// "git log" std output gives us byte stream of data
13221322
// Commit messages in that byte stream are UTF-8 encoded.
13231323
// We want to decode bytestream to strings using UTF-8 encoding.
13241324
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
@@ -1394,15 +1394,15 @@ public void execute() throws GitException {
13941394
this.includes("HEAD");
13951395
}
13961396
for (RevCommit commit : walk) {
1397-
// git whatachanged doesn't show the merge commits unless -m is given
1397+
// git log --raw doesn't show the merge commits unless -m is given
13981398
if (commit.getParentCount() > 1) {
13991399
continue;
14001400
}
14011401

14021402
formatter.format(commit, null, pw, true);
14031403
}
14041404
} catch (IOException e) {
1405-
throw new GitException("Error: jgit whatchanged in " + workspace + " " + e.getMessage(), e);
1405+
throw new GitException("Error: jgit log --raw in " + workspace + " " + e.getMessage(), e);
14061406
} finally {
14071407
closeResources();
14081408
}
@@ -1444,7 +1444,7 @@ private String statusOf(DiffEntry d) {
14441444
* Commit to format.
14451445
* @param parent
14461446
* Optional parent commit to produce the diff against. This only matters
1447-
* for merge commits, and git-log/git-whatchanged/etc behaves differently with respect to this.
1447+
* for merge commits, and git-log behaves differently with respect to this.
14481448
*/
14491449
@SuppressFBWarnings(
14501450
value = "VA_FORMAT_STRING_USES_NEWLINE",

0 commit comments

Comments
 (0)