You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2013/09/24 12:00:41 UTC

[2/3] git commit: Refactored changelog parsing to fix new changeset detection removing null changesets and removed the branch name parsing warning

Refactored changelog parsing to fix new changeset detection removing null changesets and removed the branch name parsing warning


Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/33bceaf3
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/33bceaf3
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/33bceaf3

Branch: refs/heads/master
Commit: 33bceaf310d9322ce34c865db635ecf0e3bf24e4
Parents: f9377e9
Author: Mads Mohr Christensen <hr...@gmail.com>
Authored: Sun Sep 22 12:37:48 2013 +0200
Committer: Mads Mohr Christensen <hr...@gmail.com>
Committed: Sun Sep 22 12:37:48 2013 +0200

----------------------------------------------------------------------
 .../command/changelog/HgChangeLogConsumer.java  | 107 +++++++------------
 1 file changed, 37 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-scm/blob/33bceaf3/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogConsumer.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogConsumer.java b/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogConsumer.java
index 5a92838..6375a6a 100644
--- a/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogConsumer.java
+++ b/maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogConsumer.java
@@ -32,6 +32,7 @@ import org.apache.maven.scm.provider.hg.command.HgConsumer;
 
 /**
  * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
+ * @author <a href="mailto:hr.mohr@gmail.com">Mads Mohr Christensen</a>
  *
  */
 public class HgChangeLogConsumer
@@ -40,21 +41,19 @@ public class HgChangeLogConsumer
 
     private static final String TIME_PATTERN = "yyyy-MM-dd HH:mm:ss Z";
 
-    private static final String REVNO_TAG = "changeset: ";
+    private static final String REVNO_TAG = "changeset:";
 
-    private static final String TAG_TAG = "tag:         ";
+    private static final String TAG_TAG = "tag:";
 
-    private static final String AUTHOR_TAG = "user: ";
+    private static final String BRANCH_TAG = "branch:";
 
-    private static final String TIME_STAMP_TOKEN = "date: ";
+    private static final String AUTHOR_TAG = "user:";
 
-    private static final String MESSAGE_TOKEN = "description:";
-
-    private static final String FILES_TOKEN = "files: ";
+    private static final String TIME_STAMP_TOKEN = "date:";
 
-    private String prevLine = "";
+    private static final String MESSAGE_TOKEN = "description:";
 
-    private String prevPrevLine = "";
+    private static final String FILES_TOKEN = "files:";
 
     private List<ChangeSet> logEntries = new ArrayList<ChangeSet>();
 
@@ -65,16 +64,14 @@ public class HgChangeLogConsumer
     @SuppressWarnings( "unused" )
     private String currentTag; // don't know what to do with this
 
-    private String userDatePattern;
-
-    private boolean spoolingComments;
+    @SuppressWarnings( "unused" )
+    private String currentBranch; // don't know what to do with this
 
-    private List<String> currentComment = null;
+    private String userDatePattern;
 
     public HgChangeLogConsumer( ScmLogger logger, String userDatePattern )
     {
         super( logger );
-
         this.userDatePattern = userDatePattern;
     }
 
@@ -86,81 +83,51 @@ public class HgChangeLogConsumer
     /** {@inheritDoc} */
     public void consumeLine( String line )
     {
-
         // override default behaviour which tries to pick through things for some standard messages.  that
         // does not apply here
-        doConsume( null, line );
+        String trimmedLine = line.trim();
+        doConsume( null, trimmedLine );
     }
 
     /** {@inheritDoc} */
     public void doConsume( ScmFileStatus status, String line )
     {
-        String tmpLine = line;
-        // If current status == null then this is a new entry
-        // If the line == "" and previous line was "", then this is also a new entry
-        if ( ( line.equals( "" ) && ( prevLine.equals( "" ) && prevPrevLine.equals( "" ) ) ) || currentComment == null )
-        {
-            if ( currentComment != null )
-            {
-                StringBuilder comment = new StringBuilder();
-                for ( int i = 0; i < currentComment.size() - 1; i++ )
-                {
-                    comment.append( currentComment.get( i ) );
-                    if ( i + 1 < currentComment.size() - 1 )
-                    {
-                        comment.append( '\n' );
-                    }
-                }
-                currentChange.setComment( comment.toString() );
-
-            }
-
-            spoolingComments = false;
+        String tmpLine;
 
+        // new changeset
+        if ( line.startsWith(REVNO_TAG) )
+        {
             //Init a new changeset
             currentChange = new ChangeSet();
             currentChange.setFiles( new ArrayList<ChangeFile>( 0 ) );
             logEntries.add( currentChange );
 
-            //Reset memeber vars
-            currentComment = new ArrayList<String>();
-            currentRevision = "";
-        }
-
-        if ( spoolingComments )
-        {
-            currentComment.add( line );
-        }
-        else if ( line.startsWith( MESSAGE_TOKEN ) )
-        {
-            spoolingComments = true;
-        }
-        else if ( line.startsWith( REVNO_TAG ) )
-        {
-            tmpLine = line.substring( REVNO_TAG.length() );
-            tmpLine = tmpLine.trim();
+            // parse revision
+            tmpLine = line.substring( REVNO_TAG.length() ).trim();
             currentRevision = tmpLine.substring( tmpLine.indexOf( ':' ) + 1 );
             currentChange.setRevision( currentRevision );
-
         }
-        else if ( line.startsWith( TAG_TAG ) )
+        else if ( line.startsWith( BRANCH_TAG ) )
         {
-            tmpLine = line.substring( TAG_TAG.length() ).trim();
-            currentTag = tmpLine;
+            tmpLine = line.substring( BRANCH_TAG.length() ).trim();
+            currentBranch = tmpLine;
         }
         else if ( line.startsWith( AUTHOR_TAG ) )
         {
-            tmpLine = line.substring( AUTHOR_TAG.length() );
-            tmpLine = tmpLine.trim();
+            tmpLine = line.substring( AUTHOR_TAG.length() ).trim();
             currentChange.setAuthor( tmpLine );
         }
         else if ( line.startsWith( TIME_STAMP_TOKEN ) )
         {
-            // TODO: FIX Date Parsing to match Mercurial or fix with template
             tmpLine = line.substring( TIME_STAMP_TOKEN.length() ).trim();
             Date date = parseDate( tmpLine, userDatePattern, TIME_PATTERN, Locale.ENGLISH );
             currentChange.setDate( date );
         }
+        else if ( line.startsWith( TAG_TAG ) )
+        {
+            tmpLine = line.substring( TAG_TAG.length() ).trim();
+            currentTag = tmpLine;
+        }
         else if ( line.startsWith( FILES_TOKEN ) )
         {
             tmpLine = line.substring( FILES_TOKEN.length() ).trim();
@@ -172,16 +139,16 @@ public class HgChangeLogConsumer
                 currentChange.addFile( changeFile );
             }
         }
-        else if ( line.length() > 0 )
+        else if ( line.startsWith( MESSAGE_TOKEN ) )
         {
-            if ( getLogger().isWarnEnabled() )
-            {
-                getLogger().warn( "Could not figure out: " + line );
-            }
+            currentChange.setComment("");
+        }
+        else
+        {
+            StringBuilder comment = new StringBuilder( currentChange.getComment() );
+            comment.append( line );
+            comment.append( '\n' );
+            currentChange.setComment( comment.toString() );
         }
-
-        // record previous line
-        prevLine = line;
-        prevPrevLine = prevLine;
     }
 }