From 168d7089068652eb48f5196d45aa3318596dccea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Tue, 11 Oct 2022 18:25:40 +0200 Subject: [PATCH] Fix handling of old commits as new ones in new branches If a new branch is pushed in Git without new commits (the branch is created on a commit that already exists in the SCM-Manager repository and pushed without any further commit), all ancestors of the commit the branch points to have been treated as if they were new by the hook changeset provider. This led to severe errors like wrong push logs (by the pushlog plugin) or re-evaluated commit messages by the commit message checker plugin. This fixes this wrong behaviour. If new commits are not provided by the pack parser, no commit will be treated as a new one. --- gradle/changelog/fix_empty_branches.yaml | 2 ++ .../scm/web/CollectingPackParserListener.java | 25 ++++++------------- 2 files changed, 9 insertions(+), 18 deletions(-) create mode 100644 gradle/changelog/fix_empty_branches.yaml diff --git a/gradle/changelog/fix_empty_branches.yaml b/gradle/changelog/fix_empty_branches.yaml new file mode 100644 index 0000000000..1bfe7bf549 --- /dev/null +++ b/gradle/changelog/fix_empty_branches.yaml @@ -0,0 +1,2 @@ +- type: fixed + description: Handling of old commits as new ones in new branches ([#2130](https://github.com/scm-manager/scm-manager/pull/2130)) diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/CollectingPackParserListener.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/CollectingPackParserListener.java index 11dba9ce83..0cbda8c4ef 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/CollectingPackParserListener.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/CollectingPackParserListener.java @@ -123,21 +123,13 @@ public class CollectingPackParserListener implements PackParserListener if (newObjectIdMap != null) { newObjectIds = ImmutableSet.copyOf(newObjectIdMap); - } - else - { - logger.warn("pack parser returned no newObjectIds"); - newObjectIds = ImmutableSet.of(); - } - - if (newObjectIds.isEmpty()) - { - logger.debug("new object ids are empty, we treat every commit as new"); - } - else - { logger.debug("collected {} new object ids", newObjectIds.size()); } + else + { + logger.warn("pack parser returned no newObjectIds; no commit will be treated as a new one"); + newObjectIds = Set.of(); + } } /** @@ -161,10 +153,7 @@ public class CollectingPackParserListener implements PackParserListener //~--- get methods ---------------------------------------------------------- /** - * Returns {@code true} if the object is a new object. The method will also - * return {@code true}, if the pack parser does not return a list with new - * object ids. - * + * Returns {@code true} if the object is a new object. * * @param object rev object * @@ -174,7 +163,7 @@ public class CollectingPackParserListener implements PackParserListener { ensureAfterWasCalled(); - return newObjectIds.isEmpty() || newObjectIds.contains(object.getId()); + return newObjectIds.contains(object.getId()); } //~--- methods --------------------------------------------------------------