From bb6682ac0ecd9d413be449a371e67db6814e4be6 Mon Sep 17 00:00:00 2001 From: Philipp Czora Date: Tue, 22 Jan 2019 13:43:22 +0100 Subject: [PATCH 1/4] Fixed a bug causing problems with rev numbers > 999 --- .../sonia/scm/repository/spi/HgModificationsCommand.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgModificationsCommand.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgModificationsCommand.java index c67b9ff5d9..f9a67f8656 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgModificationsCommand.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgModificationsCommand.java @@ -4,8 +4,6 @@ import sonia.scm.repository.Modifications; import sonia.scm.repository.Repository; import sonia.scm.repository.spi.javahg.HgLogChangesetCommand; -import java.text.MessageFormat; - public class HgModificationsCommand extends AbstractCommand implements ModificationsCommand { HgModificationsCommand(HgCommandContext context, Repository repository) { @@ -17,8 +15,7 @@ public class HgModificationsCommand extends AbstractCommand implements Modificat public Modifications getModifications(String revision) { com.aragost.javahg.Repository repository = open(); HgLogChangesetCommand hgLogChangesetCommand = HgLogChangesetCommand.on(repository, getContext().getConfig()); - int hgRevision = hgLogChangesetCommand.rev(revision).singleRevision(); - Modifications modifications = hgLogChangesetCommand.rev(MessageFormat.format("{0}:{0}", hgRevision)).extractModifications(); + Modifications modifications = hgLogChangesetCommand.rev(revision).extractModifications(); modifications.setRevision(revision); return modifications; } From 13fa846d6a00f3ed0185981705f0b211713e164b Mon Sep 17 00:00:00 2001 From: Philipp Czora Date: Tue, 22 Jan 2019 13:43:49 +0100 Subject: [PATCH 2/4] Fixed bug caused by an unclosed InputStream --- .../spi/javahg/HgLogChangesetCommand.java | 167 ++++-------------- 1 file changed, 39 insertions(+), 128 deletions(-) diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/javahg/HgLogChangesetCommand.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/javahg/HgLogChangesetCommand.java index f57c2a63d9..45bd9fba4c 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/javahg/HgLogChangesetCommand.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/javahg/HgLogChangesetCommand.java @@ -1,19 +1,19 @@ /** * Copyright (c) 2010, Sebastian Sdorra * All rights reserved. - * + *

* Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + *

* 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. + * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. * 3. Neither the name of SCM-Manager; nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + *

* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -24,99 +24,64 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + *

* http://bitbucket.org/sdorra/scm-manager - * */ - package sonia.scm.repository.spi.javahg; -//~--- non-JDK imports -------------------------------------------------------- - import com.aragost.javahg.Repository; import com.aragost.javahg.internals.HgInputStream; import com.aragost.javahg.internals.Utils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import sonia.scm.repository.Changeset; import sonia.scm.repository.HgConfig; import sonia.scm.repository.Modifications; +import java.io.IOException; import java.util.List; -//~--- JDK imports ------------------------------------------------------------ - /** - * * @author Sebastian Sdorra */ -public class HgLogChangesetCommand extends AbstractChangesetCommand -{ +public class HgLogChangesetCommand extends AbstractChangesetCommand { - /** - * Constructs ... - * - * - * @param repository - * @param config - */ - private HgLogChangesetCommand(Repository repository, HgConfig config) - { + private final Logger log = LoggerFactory.getLogger(HgLogChangesetCommand.class); + + private HgLogChangesetCommand(Repository repository, HgConfig config) { super(repository, config); } - //~--- methods -------------------------------------------------------------- - /** - * Method description - * - * - * @param repository - * @param config - * - * @return - */ - public static HgLogChangesetCommand on(Repository repository, HgConfig config) - { + public static HgLogChangesetCommand on(Repository repository, HgConfig config) { return new HgLogChangesetCommand(repository, config); } - /** - * Method description - * - * - * @param branch - * - * @return - */ - public HgLogChangesetCommand branch(String branch) - { + + public HgLogChangesetCommand branch(String branch) { cmdAppend("-b", branch); return this; } - /** - * Method description - * - * - * @param files - * - * @return - */ - public List execute(String... files) - { + + public List execute(String... files) { return readListFromStream(getHgInputStream(files, CHANGESET_EAGER_STYLE_PATH)); } - /** - * Extract Modifications from the Repository files - * - * @param files repo files - * @return modifications - */ public Modifications extractModifications(String... files) { - return readModificationsFromStream(getHgInputStream(files, CHANGESET_EAGER_STYLE_PATH)); + HgInputStream hgInputStream = getHgInputStream(files, CHANGESET_EAGER_STYLE_PATH); + try { + return readModificationsFromStream(hgInputStream); + } finally { + try { + hgInputStream.close(); + } catch (IOException e) { + log.error("Could not close HgInputStream", e); + } + } } HgInputStream getHgInputStream(String[] files, String changesetStylePath) { @@ -124,93 +89,39 @@ public class HgLogChangesetCommand extends AbstractChangesetCommand return launchStream(files); } - /** - * Method description - * - * - * @param limit - * - * @return - */ - public HgLogChangesetCommand limit(int limit) - { + public HgLogChangesetCommand limit(int limit) { cmdAppend("-l", limit); return this; } - /** - * Method description - * - * - * @param files - * - * @return - */ - public List loadRevisions(String... files) - { + + public List loadRevisions(String... files) { return loadRevisionsFromStream(getHgInputStream(files, CHANGESET_LAZY_STYLE_PATH)); } - /** - * Method description - * - * - * @param rev - * - * @return - */ - public HgLogChangesetCommand rev(String... rev) - { + public HgLogChangesetCommand rev(String... rev) { cmdAppend("-r", rev); return this; } - /** - * Method description - * - * - * @param files - * - * @return - */ - public Changeset single(String... files) - { + public Changeset single(String... files) { return Utils.single(execute(files)); } - /** - * Method description - * - * - * @param files - * - * @return - */ - public int singleRevision(String... files) - { + public int singleRevision(String... files) { Integer rev = Utils.single(loadRevisions(files)); - if (rev == null) - { + if (rev == null) { rev = -1; } return rev; } - //~--- get methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @return - */ @Override - public String getCommandName() - { + public String getCommandName() { return "log"; } } From 5c4d2764ad7aa8f03109118c10d83ef55d25d56e Mon Sep 17 00:00:00 2001 From: Philipp Czora Date: Tue, 22 Jan 2019 14:20:54 +0100 Subject: [PATCH 3/4] Renamed logger constant --- .../scm/repository/spi/javahg/HgLogChangesetCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/javahg/HgLogChangesetCommand.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/javahg/HgLogChangesetCommand.java index 45bd9fba4c..12a77ac717 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/javahg/HgLogChangesetCommand.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/javahg/HgLogChangesetCommand.java @@ -48,7 +48,7 @@ import java.util.List; */ public class HgLogChangesetCommand extends AbstractChangesetCommand { - private final Logger log = LoggerFactory.getLogger(HgLogChangesetCommand.class); + private static final Logger LOG = LoggerFactory.getLogger(HgLogChangesetCommand.class); private HgLogChangesetCommand(Repository repository, HgConfig config) { super(repository, config); @@ -79,7 +79,7 @@ public class HgLogChangesetCommand extends AbstractChangesetCommand { try { hgInputStream.close(); } catch (IOException e) { - log.error("Could not close HgInputStream", e); + LOG.error("Could not close HgInputStream", e); } } } From 8a3fad1a3f034adb5b8986c1f215591fcede233a Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 22 Jan 2019 13:36:08 +0000 Subject: [PATCH 4/4] Close branch bugfix/hg_changeset_fixes