@@ -10,6 +10,9 @@ This project aims to introduce CodeTracker, a refactoring-aware tool that can ge
1010 * [ Eclipse IDE] ( #eclipse-ide )
1111 * [ IntelliJ IDEA] ( #intellij-idea )
1212 * [ How to add as a Maven dependency] ( #how-to-add-as-a-maven-dependency )
13+ * [ Refactoring-aware Blame] ( #refactoring-aware-blame )
14+ * [ How to blame a single line] ( #how-to-blame-a-single-line )
15+ * [ How to blame an entire file] ( #how-to-blame-an-entire-file )
1316 * [ How to Track Blocks] ( #how-to-track-blocks )
1417 * [ How to Track Methods] ( #how-to-track-methods )
1518 * [ How to Track Variables] ( #how-to-track-variables )
@@ -193,6 +196,43 @@ In order to use CodeTracker as a maven dependency in your project, add the follo
193196
194197 implementation 'io.github.jodavimehran:code-tracker:2.6'
195198
199+ # Refactoring-aware Blame
200+
201+ ## How to blame a single line
202+ ``` java
203+ import static org.codetracker.blame.util.Utils.getOwner ;
204+ import static org.codetracker.blame.util.Utils.getProject ;
205+
206+ // REPOS_PATH is the directory where the repository is locally cloned
207+ String url = " https://github.com/checkstyle/checkstyle/commit/119fd4fb33bef9f5c66fc950396669af842c21a3" ;
208+ String filePath = " src/main/java/com/puppycrawl/tools/checkstyle/Checker.java" ;
209+ int lineNumber = 69 ;
210+ String commitId = URLHelper . getCommit(url);
211+ Repository repository = new GitServiceImpl (). cloneIfNotExists(REPOS_PATH + " /" + getOwner(url) + " /" + getProject(url), URLHelper . getRepo(url));
212+
213+ History . HistoryInfo<? extends CodeElement > lineBlame =
214+ new CodeTrackerBlame (). getLineBlame(repository, commitId, filePath, lineNumber);
215+ LineBlameResult lineBlameResult = LineBlameResult . of(lineBlame, lineNumber);
216+ ```
217+
218+ ## How to blame an entire file
219+ ``` java
220+ import static org.codetracker.blame.util.Utils.getOwner ;
221+ import static org.codetracker.blame.util.Utils.getProject ;
222+
223+ // REPOS_PATH is the directory where the repository is locally cloned
224+ String url = " https://github.com/checkstyle/checkstyle/commit/119fd4fb33bef9f5c66fc950396669af842c21a3" ;
225+ String filePath = " src/main/java/com/puppycrawl/tools/checkstyle/Checker.java" ;
226+ String commitId = URLHelper . getCommit(url);
227+ Repository repository = new GitServiceImpl (). cloneIfNotExists(REPOS_PATH + " /" + getOwner(url) + " /" + getProject(url), URLHelper . getRepo(url));
228+
229+ FileTrackerImpl fileTracker = new FileTrackerImpl (repository, commitId, filePath);
230+ fileTracker. blame();
231+ BlameFormatter blameFormatter = new BlameFormatter (fileTracker. getLines());
232+ List<String []> results = blameFormatter. make(fileTracker. getBlameInfo());
233+ String actual = TabularPrint . make(results);
234+ ```
235+
196236# How to Track Blocks
197237CodeTracker can track the history of code blocks in git repositories.
198238
0 commit comments