package org.dstadler.jgit.porcelain;

import org.dstadler.jgit.helper.CookbookHelper;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.blame.BlameResult;
import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.diff.RawTextComparator;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;

import java.io.File;
import java.io.IOException;

// Simple example that shows how to get the Blame-information for a file
public class BlameFile {
    public static void main(String[] args)
        throws IOException, GitAPIException {
        try (Repository repo = CookbookHelper.openJGitCookbookRepository()) {
            final String[] list = new File(".").list();
            if(list == null) {
                throw new IllegalStateException("Did not find any files at " + new File(".").getAbsolutePath());
            }

            for(String file : list) {
                if(new File(file).isDirectory()) {
                    continue;
                }

                System.out.println("Blaming " + file);
                final BlameResult result = new Git(repo).blame().setFilePath(file)
                    .setTextComparator(RawTextComparator.WS_IGNORE_ALL).call();
                final RawText rawText = result.getResultContents();
                for (int i = 0; i < rawText.size(); i++) {
                    final PersonIdent sourceAuthor = result.getSourceAuthor(i);
                    final RevCommit sourceCommit = result.getSourceCommit(i);
                    System.out.println(sourceAuthor.getName() +
                            (sourceCommit != null ? "/" + sourceCommit.getCommitTime() + "/" + sourceCommit.getName() : "") +
                            ": " + rawText.getString(i));
                }
            }
        }
    }
}

@@ -466,16 +466,51 @@
 ception;
+%0Aimport java.text.SimpleDateFormat;
 %0A%0A// Sim
@@ -643,24 +643,16 @@
 %5B%5D args)
-%0A       
  throws 
@@ -682,24 +682,18 @@
 ption %7B%0A
-        
+%09%09
 try (Rep
@@ -754,28 +754,19 @@
 ry()) %7B%0A
-            
+%09%09%09
 final St
@@ -801,30 +801,22 @@
 list();%0A
-            
+%09%09%09
 if
+ 
 (list ==
@@ -824,32 +824,20 @@
 null) %7B%0A
-                
+%09%09%09%09
 throw ne
@@ -929,38 +929,103 @@
 ));%0A
-            %7D%0A%0A            
+%09%09%09%7D%0A%0A%09%09%09final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(%22YYYY-MM-dd HH:mm%22);%0A%09%09%09
 for
+ 
 (Str
@@ -1047,26 +1047,15 @@
 ) %7B%0A
-                
+%09%09%09%09
 if
+ 
 (new
@@ -1087,73 +1087,34 @@
 ) %7B%0A
-                    continue;%0A                %7D%0A%0A                
+%09%09%09%09%09continue;%0A%09%09%09%09%7D%0A%0A%09%09%09%09
 Syst
@@ -1148,32 +1148,20 @@
  file);%0A
-                
+%09%09%09%09
 final Bl
@@ -1219,36 +1219,22 @@
 h(file)%0A
-                    
+%09%09%09%09%09%09
 .setText
@@ -1285,32 +1285,20 @@
 call();%0A
-                
+%09%09%09%09
 final Ra
@@ -1341,32 +1341,20 @@
 ents();%0A
-                
+%09%09%09%09
 for (int
@@ -1388,36 +1388,21 @@
  i++) %7B%0A
-                    
+%09%09%09%09%09
 final Pe
@@ -1453,36 +1453,21 @@
 hor(i);%0A
-                    
+%09%09%09%09%09
 final Re
@@ -1516,36 +1516,21 @@
 mit(i);%0A
-                    
+%09%09%09%09%09
 System.o
@@ -1569,36 +1569,15 @@
 ) +%0A
-                            
+%09%09%09%09%09%09%09
 (sou
@@ -1597,21 +1597,49 @@
 null ? %22
-/
+ - 
 %22 + 
+DATE_FORMAT.format(((long)
 sourceCo
@@ -1662,13 +1662,31 @@
 me()
- + %22/
+)*1000) +%0A%09%09%09%09%09%09%09%09%09%22 - 
 %22 + 
@@ -1720,36 +1720,15 @@
 ) +%0A
-                            
+%09%09%09%09%09%09%09
 %22: %22
@@ -1757,48 +1757,21 @@
 ));%0A
-                %7D%0A            %7D%0A        
+%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09
 %7D%0A  

Format date in output