mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-06-15 00:21:56 +02:00
Merged in bugfix/hg_changeset_fixes (pull request #156)
Bugfixes regarding Mercurial commands
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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.
|
||||
*
|
||||
* <p>
|
||||
* 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 static 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<Changeset> execute(String... files)
|
||||
{
|
||||
|
||||
public List<Changeset> 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<Integer> loadRevisions(String... files)
|
||||
{
|
||||
|
||||
public List<Integer> 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";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user