Commits

Sebastian Sdorra committed edddb55

return added, deleted and modified files with a changeset, addresses #22

Comments (0)

Files changed (4)

src/main/java/com/aragost/javahg/Changeset.java

 import com.aragost.javahg.internals.Utils;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Function;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
         in.mustMatch(' '); // skip space part of {parents}
         Changeset parent1 = repository.changeset(p1);
         Changeset parent2 = repository.changeset(p2);
+        // read files
+        Builder<String> addedBuilder = ImmutableList.builder();
+        Builder<String> modifiedBuilder = ImmutableList.builder();
+        Builder<String> deletedBuilder = ImmutableList.builder();
+        
+        String line = in.textUpTo('\n');
+        while ( line.length() > 0 ) {
+          if ( line.startsWith("a ") ){
+            addedBuilder.add( line.substring(2) );
+          } else if ( line.startsWith("m ") ){
+            modifiedBuilder.add( line.substring(2) );
+          } else if ( line.startsWith("d ")){
+            deletedBuilder.add( line.substring(2) );
+          }
+          line = in.textUpTo('\n');
+        }
         String message = in.textUpTo('\0');
 
         if (cset == null) {
 
         ChangesetData data = cset.data;
         if (data == null) {
-            data = new ChangesetData(revision, user, timestamp, branch, parent1, parent2, message);
+            data = new ChangesetData(revision, user, timestamp, branch, parent1, parent2, 
+                       message, addedBuilder.build(), modifiedBuilder.build(), deletedBuilder.build());
             cset.data = data;
         } else if (revision != data.revision) {
             // Handle revision specially because revision is not part of the node
         ensureAllDataLoaded();
         return this.data.message;
     }
+    
+    public List<String> getAddedFiles(){
+        ensureAllDataLoaded();
+        return this.data.addedFiles;
+    }
+    
+    public List<String> getModifiedFiles(){
+        ensureAllDataLoaded();
+        return this.data.modifiedFiles;
+    }
+    
+    public List<String> getDeletedFiles(){
+        ensureAllDataLoaded();
+        return this.data.deletedFiles;
+    }
 
     private void ensureAllDataLoaded() {
         if (this.data != null) {
     public Changeset parent1;
     public Changeset parent2;
     public String message;
+    public List<String> addedFiles;
+    public List<String> modifiedFiles;
+    public List<String> deletedFiles;
 
     public ChangesetData(int revision, String user, DateTime timestamp, String branch, Changeset parent1,
-            Changeset parent2, String message) {
+            Changeset parent2, String message, List<String> addedFiles, List<String> modifiedFiles, List<String> deletedFiles) {
         this.revision = revision;
         this.user = user;
         this.timestamp = timestamp;
         this.parent1 = parent1;
         this.parent2 = parent2;
         this.message = message;
+        this.addedFiles = addedFiles;
+        this.modifiedFiles = modifiedFiles;
+        this.deletedFiles = deletedFiles;
     }
 }

src/main/resources/styles/changesets.style

 header = "%{pattern}"
-changeset = "{node}{rev}\n{author}\n{date|hgdate}\n{branch}\n{parents}{desc}\0"
+changeset = "{node}{rev}\n{author}\n{date|hgdate}\n{branch}\n{parents}{file_adds}{file_mods}{file_dels}\n{desc}\0"
+file_add = "a {file_add}\n"
+file_mod = "m {file_mod}\n"
+file_del = "d {file_del}\n"
 footer = "%{pattern}"

src/test/java/com/aragost/javahg/ChangesetTest.java

         Assert.assertEquals(d, c.getTimestamp());
         Assert.assertEquals("added a", c.getMessage());
         Assert.assertEquals("default", c.getBranch());
+        // test for files
+        Assert.assertEquals("a", c.getAddedFiles().get(0));
     }
 
     @Test

src/test/java/com/aragost/javahg/commands/LogCommandTest.java

         Changeset cs = changesets.get(1);
         Assert.assertEquals("user", cs.getUser());
         Assert.assertEquals("line1\nline2\nX", cs.getMessage());
+        Assert.assertEquals("x", cs.getAddedFiles().get(0));
 
         cs = changesets.get(0);
         Assert.assertEquals("USER", cs.getUser());
         Assert.assertEquals("Line1\nLine2", cs.getMessage());
-
+        Assert.assertEquals("x", cs.getModifiedFiles().get(0));
     }
 
     @Test