Commits

Sebastian Sdorra  committed 5db5be4

added option to display revisions as part of the node id

  • Participants
  • Parent commits df2d77f
  • Branches issue-251

Comments (0)

Files changed (6)

File scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgConfig.java

    *
    * @return
    */
+  public boolean isShowRevisionInId()
+  {
+    return showRevisionInId;
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
   public boolean isUseOptimizedBytecode()
   {
     return useOptimizedBytecode;
    * Method description
    *
    *
+   * @param showRevisionInId
+   */
+  public void setShowRevisionInId(boolean showRevisionInId)
+  {
+    this.showRevisionInId = showRevisionInId;
+  }
+
+  /**
+   * Method description
+   *
+   *
    * @param useOptimizedBytecode
    */
   public void setUseOptimizedBytecode(boolean useOptimizedBytecode)
 
   /** Field description */
   private boolean useOptimizedBytecode = false;
+
+  /** Field description */
+  private boolean showRevisionInId = false;
 }

File scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgCommandContext.java

     return repository;
   }
 
+  //~--- get methods ----------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
+  public HgConfig getConfig()
+  {
+    return config;
+  }
+
   //~--- fields ---------------------------------------------------------------
 
   /** Field description */

File scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgLogCommand.java

     throws IOException, RepositoryException
   {
     com.aragost.javahg.Repository repository = open();
-    HgLogChangesetCommand cmd = HgLogChangesetCommand.on(repository);
+    HgLogChangesetCommand cmd = on(repository);
 
     return cmd.rev(id).single();
   }
 
       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)
           end = 0;
         }
 
-        List<Changeset> changesets =
-          HgLogChangesetCommand.on(repository).rev(start + ":" + end).execute();
+        List<Changeset> changesets = on(repository).rev(start + ":"
+                                       + end).execute();
 
         result = new ChangesetPagingResult(total, changesets);
       }
   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();
 
         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());
+  }
 }

File scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/javahg/HgLogChangesetCommand.java

 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;
 
    *
    *
    * @param repository
+   * @param config
    */
-  public HgLogChangesetCommand(Repository repository)
+  public HgLogChangesetCommand(Repository repository, HgConfig config)
   {
     super(repository);
+    this.config = config;
     withDebugFlag();
   }
 
    *
    *
    * @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);
   }
 
   /**
   public int singleRevision(String... files)
   {
     Integer rev = Utils.single(loadRevisions(files));
-    if ( rev == null ){
+
+    if (rev == null)
+    {
       rev = -1;
     }
+
     return rev;
   }
 
   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');
 
       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);
     }
    * @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
+   *
+   *
+   * @param in
+   *
+   * @return
    */
   private List<Changeset> readListFromStream(HgInputStream in)
   {
 
     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;
 }

File scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/hg.config.js

   configWizardLabelText: 'Start Configuration Wizard',
   encodingText: 'Encoding',
   disabledText: 'Disabled',
+  showRevisionInIdText: 'Show Revision',
 
   // helpText
   hgBinaryHelpText: 'Location of Mercurial binary.',
   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(){
 
         helpText: this.useOptimizedBytecodeHelpText
       },{
         xtype: 'checkbox',
+        name: 'showRevisionInId',
+        fieldLabel: this.showRevisionInIdText,
+        inputValue: 'true',
+        helpText: this.showRevisionInIdHelpText
+      },{
+        xtype: 'checkbox',
         name: 'disabled',
         fieldLabel: this.disabledText,
         inputValue: 'true',
     configWizardText: 'Konfigurations-Assistenten starten',
     configWizardLabelText: 'Konfigurations-Assistent',
     disabledText: 'Deaktivieren',
+    showRevisionInIdText: 'Zeige Revision an',
 
     // helpText
     hgBinaryHelpText: 'Pfad zum "hg" Befehl.',
     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.'
   });
 
 }

File scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/styles/changesets-eager.style

 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"