diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgConfig.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgConfig.java index 1ff338a7fd..b9bd650925 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgConfig.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgConfig.java @@ -101,6 +101,17 @@ public class HgConfig extends SimpleRepositoryConfig return pythonPath; } + /** + * Method description + * + * + * @return + */ + public boolean isShowRevisionInId() + { + return showRevisionInId; + } + /** * Method description * @@ -171,6 +182,17 @@ public class HgConfig extends SimpleRepositoryConfig this.pythonPath = pythonPath; } + /** + * Method description + * + * + * @param showRevisionInId + */ + public void setShowRevisionInId(boolean showRevisionInId) + { + this.showRevisionInId = showRevisionInId; + } + /** * Method description * @@ -198,4 +220,7 @@ public class HgConfig extends SimpleRepositoryConfig /** Field description */ private boolean useOptimizedBytecode = false; + + /** Field description */ + private boolean showRevisionInId = false; } diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgCommandContext.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgCommandContext.java index a4d11900ad..65adf9b2c7 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgCommandContext.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgCommandContext.java @@ -148,6 +148,19 @@ public class HgCommandContext implements Closeable return repository; } + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + public HgConfig getConfig() + { + return config; + } + //~--- fields --------------------------------------------------------------- /** Field description */ diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgLogCommand.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgLogCommand.java index 9c08ca0c09..af485d19df 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgLogCommand.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgLogCommand.java @@ -87,7 +87,7 @@ public class HgLogCommand extends AbstractCommand implements LogCommand throws IOException, RepositoryException { com.aragost.javahg.Repository repository = open(); - HgLogChangesetCommand cmd = HgLogChangesetCommand.on(repository); + HgLogChangesetCommand cmd = on(repository); return cmd.rev(id).single(); } @@ -127,19 +127,16 @@ public class HgLogCommand extends AbstractCommand implements LogCommand if (!Strings.isNullOrEmpty(startChangeset)) { - start = HgLogChangesetCommand.on(repository).rev( - startChangeset).singleRevision(); + start = on(repository).rev(startChangeset).singleRevision(); } else if (!Strings.isNullOrEmpty(endChangeset)) { - end = HgLogChangesetCommand.on(repository).rev( - endChangeset).singleRevision(); + end = on(repository).rev(endChangeset).singleRevision(); } if (start < 0) { - start = - HgLogChangesetCommand.on(repository).rev("tip").singleRevision(); + start = on(repository).rev("tip").singleRevision(); } if (start >= 0) @@ -162,8 +159,8 @@ public class HgLogCommand extends AbstractCommand implements LogCommand end = 0; } - List changesets = - HgLogChangesetCommand.on(repository).rev(start + ":" + end).execute(); + List changesets = on(repository).rev(start + ":" + + end).execute(); result = new ChangesetPagingResult(total, changesets); } @@ -192,7 +189,7 @@ public class HgLogCommand extends AbstractCommand implements LogCommand private ChangesetPagingResult collectSafely( com.aragost.javahg.Repository repository, LogCommandRequest request) { - HgLogChangesetCommand cmd = HgLogChangesetCommand.on(repository); + HgLogChangesetCommand cmd = on(repository); String startChangeset = request.getStartChangeset(); String endChangeset = request.getEndChangeset(); @@ -265,9 +262,22 @@ public class HgLogCommand extends AbstractCommand implements LogCommand revs[i] = sublist.get(i).toString(); } - changesets = HgLogChangesetCommand.on(repository).rev(revs).execute(); + changesets = on(repository).rev(revs).execute(); } return new ChangesetPagingResult(total, changesets); } + + /** + * Method description + * + * + * @param repository + * + * @return + */ + private HgLogChangesetCommand on(com.aragost.javahg.Repository repository) + { + return HgLogChangesetCommand.on(repository, getContext().getConfig()); + } } 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 a79e6a76f6..07dddf4883 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 @@ -46,6 +46,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import sonia.scm.repository.Changeset; +import sonia.scm.repository.HgConfig; import sonia.scm.repository.Modifications; import sonia.scm.repository.Person; @@ -94,10 +95,12 @@ public class HgLogChangesetCommand extends AbstractCommand * * * @param repository + * @param config */ - public HgLogChangesetCommand(Repository repository) + public HgLogChangesetCommand(Repository repository, HgConfig config) { super(repository); + this.config = config; withDebugFlag(); } @@ -108,12 +111,13 @@ public class HgLogChangesetCommand extends AbstractCommand * * * @param repository + * @param config * * @return */ - public static HgLogChangesetCommand on(Repository repository) + public static HgLogChangesetCommand on(Repository repository, HgConfig config) { - return new HgLogChangesetCommand(repository); + return new HgLogChangesetCommand(repository, config); } /** @@ -219,9 +223,12 @@ public class HgLogChangesetCommand extends AbstractCommand public int singleRevision(String... files) { Integer rev = Utils.single(loadRevisions(files)); - if ( rev == null ){ + + if (rev == null) + { rev = -1; } + return rev; } @@ -254,10 +261,8 @@ public class HgLogChangesetCommand extends AbstractCommand private Changeset createFromInputStream(HgInputStream in) throws IOException { Changeset changeset = new Changeset(); - byte[] node = in.next(40); - String nodeString = new String(node); - changeset.setId(nodeString); + changeset.setId(readId(in)); String user = in.textUpTo('\n'); @@ -274,20 +279,16 @@ public class HgLogChangesetCommand extends AbstractCommand changeset.getBranches().add(branch); } - in.upTo(':'); + String p1 = readId(in); - String p1 = in.nextAsText(40); - - if (!NULL_ID.equals(p1)) + if (!isNullId(p1)) { changeset.getParents().add(p1); } - in.upTo(':'); + String p2 = readId(in); - String p2 = in.nextAsText(40); - - if (!NULL_ID.equals(p2)) + if (!isNullId(p2)) { changeset.getParents().add(p2); } @@ -361,6 +362,45 @@ public class HgLogChangesetCommand extends AbstractCommand return revisions; } + /** + * Method description + * + * + * @param in + * + * @return + * + * @throws IOException + */ + private String readId(HgInputStream in) throws IOException + { + String nodeString = null; + + if (config.isShowRevisionInId()) + { + Integer rev = in.readDecimal(); + + if (rev != null) + { + nodeString = String.valueOf(rev); + } + else + { + nodeString = "-1"; + } + + in.upTo(':'); + nodeString = nodeString.concat(":").concat(in.nextAsText(40)); + } + else + { + in.upTo(':'); + nodeString = in.nextAsText(40); + } + + return nodeString; + } + /** * Method description * @@ -402,4 +442,25 @@ public class HgLogChangesetCommand extends AbstractCommand return changesets; } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param id + * + * @return + */ + private boolean isNullId(String id) + { + return ((id != null) && id.equals("-1:".concat(NULL_ID))) + || id.equals(NULL_ID); + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private HgConfig config; } diff --git a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/hg.config.js b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/hg.config.js index 8c6900fd74..65ce24a614 100644 --- a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/hg.config.js +++ b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/hg.config.js @@ -45,6 +45,7 @@ Sonia.hg.ConfigPanel = Ext.extend(Sonia.config.ConfigForm, { configWizardLabelText: 'Start Configuration Wizard', encodingText: 'Encoding', disabledText: 'Disabled', + showRevisionInIdText: 'Show Revision', // helpText hgBinaryHelpText: 'Location of Mercurial binary.', @@ -55,6 +56,8 @@ Sonia.hg.ConfigPanel = Ext.extend(Sonia.config.ConfigForm, { encodingHelpText: 'Repository Encoding.', disabledHelpText: 'Enable or disable the Mercurial plugin. \n\ Note you have to reload the page, after changing this value.', + showRevisionInIdHelpText: 'Show revision as part of the node id. Note: \n\ + You have to restart the ApplicationServer to affect cached changesets.', initComponent: function(){ @@ -95,6 +98,12 @@ Sonia.hg.ConfigPanel = Ext.extend(Sonia.config.ConfigForm, { fieldLabel: this.useOptimizedBytecodeText, inputValue: 'true', helpText: this.useOptimizedBytecodeHelpText + },{ + xtype: 'checkbox', + name: 'showRevisionInId', + fieldLabel: this.showRevisionInIdText, + inputValue: 'true', + helpText: this.showRevisionInIdHelpText },{ xtype: 'checkbox', name: 'disabled', @@ -200,6 +209,7 @@ if ( i18n != null && i18n.country == 'de' ){ configWizardText: 'Konfigurations-Assistenten starten', configWizardLabelText: 'Konfigurations-Assistent', disabledText: 'Deaktivieren', + showRevisionInIdText: 'Zeige Revision an', // helpText hgBinaryHelpText: 'Pfad zum "hg" Befehl.', @@ -208,7 +218,10 @@ if ( i18n != null && i18n.country == 'de' ){ repositoryDirectoryHelpText: 'Verzeichnis der Mercurial-Repositories.', useOptimizedBytecodeHelpText: 'Optimierten Bytecode verwenden (python -O).', disabledHelpText: 'Aktivieren oder deaktivieren des Mercurial Plugins.\n\ - Die Seite muss neu geladen werden wenn dieser Wert geändert wird.' + Die Seite muss neu geladen werden wenn dieser Wert geändert wird.', + showRevisionInIdHelpText: 'Zeige die Revision als teil der NodeId an. \n\ + Der ApplicationServer muss neugestartet werden um zwischengespeicherte\n\ + Changesets zuändern.' }); } diff --git a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/styles/changesets-eager.style b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/styles/changesets-eager.style index b87d9ee379..93b0b04e27 100644 --- a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/styles/changesets-eager.style +++ b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/styles/changesets-eager.style @@ -1,5 +1,5 @@ header = "%{pattern}" -changeset = "{node}{author}\n{date|hgdate}\n{branch}\n{parents}{tags}{file_adds}{file_mods}{file_dels}\n{desc}\0" +changeset = "{rev}:{node}{author}\n{date|hgdate}\n{branch}\n{parents}{tags}{file_adds}{file_mods}{file_dels}\n{desc}\0" tag = "t {tag}\n" file_add = "a {file_add}\n" file_mod = "m {file_mod}\n"