{"action":"created","comment":{"url":"https://api.github.com/repos/kiegroup/appformer/pulls/comments/186939551","pull_request_review_id":118615400,"id":186939551,"diff_hunk":"@@ -54,35 +73,97 @@ public ListCommits(final GitImpl git,\n         this.git = git;\n         this.startRange = startRange;\n         this.endRange = endRange;\n-        this.ref = null;\n         this.path = null;\n     }\n \n-    public List<RevCommit> execute() throws IOException, GitAPIException {\n-        final List<RevCommit> list = new ArrayList<>();\n+    public CommitHistory execute() throws IOException, GitAPIException {\n         try (final RevWalk rw = buildWalk()) {\n-            if (ref == null) {\n-                rw.markStart(rw.parseCommit(endRange));\n-                if (startRange != null) {\n-                    rw.markUninteresting(rw.parseCommit(startRange));\n-                }\n-            }\n-            for (RevCommit rev : rw) {\n-                list.add(rev);\n+            if (path == null || path.isEmpty()) {\n+                return fullCommitHistory(rw);\n+            } else {\n+                return pathCommitHistory(rw);\n             }\n-            return list;\n         }\n     }\n \n-    private RevWalk buildWalk() throws GitAPIException, IncorrectObjectTypeException, MissingObjectException {\n-        if (ref != null) {\n-            final LogCommand logCommand = git._log().add(ref.getObjectId());\n-            if (path != null && !path.isEmpty()) {\n-                logCommand.addPath(path);\n+    private CommitHistory pathCommitHistory(final RevWalk rw) throws MissingObjectException, IncorrectObjectTypeException, IOException {\n+        final Map<AnyObjectId, String> pathByCommit = new HashMap<>();\n+        final List<RevCommit> commits = new ArrayList<>();\n+        final RenameCaptor renameCaptor = new RenameCaptor();\n+        /*\n+         * We have to go through all commits and filter ourselves so that we can use the\n+         * rename callback to map commits to path renames.\n+         */\n+        final TreeRevFilter revFilter = createTreeRevFilter(rw, path, renameCaptor);\n+        String curPath = path;\n+        for (RevCommit commit : rw) {\n+            if (revFilter.include(rw, commit)) {\n+                @SuppressWarnings(\"resource\")\n+                final TreeWalk tw = new TreeWalk(rw.getObjectReader());\n+                tw.setRecursive(true);\n+                tw.setFilter(PathFilter.create(curPath));\n+                tw.addTree(commit.getTree());\n+                // Checks for special case that path wasn't deleted in this commit\n+                if (tw.next()) {\n+                    commits.add(commit);\n+                    // There is a rename to track\n+                    pathByCommit.put(commit.getId(), curPath);\n+                    if (renameCaptor.hasCaptured()) {\n+                        curPath = renameCaptor.getAndReset().getOldPath();\n+                    }\n+                }\n             }\n-            return (RevWalk) logCommand.call();\n         }\n \n-        return new RevWalk(git.getRepository());\n+        return new CommitHistory(commits, pathByCommit, path);\n+    }\n+\n+    private CommitHistory fullCommitHistory(final RevWalk rw) {\n+        final List<RevCommit> commits = stream(rw.spliterator(), false).collect(toList());\n+        return new CommitHistory(commits, Collections.emptyMap(), null);\n+    }\n+\n+    private TreeRevFilter createTreeRevFilter(final RevWalk rw, String curPath, final RenameCallback renameCallback) {\n+        final FollowFilter followFilter = FollowFilter.create(curPath, git.getRepository().getConfig().get(DiffConfig.KEY));\n+        followFilter.setRenameCallback(renameCallback);\n+        final TreeRevFilter revFilter = new TreeRevFilter(rw, followFilter);\n+        return revFilter;\n+    }\n+\n+    private RevWalk buildWalk() throws GitAPIException, IOException {\n+        final RevWalk rw = new RevWalk(git.getRepository());\n+        rw.setTreeFilter(TreeFilter.ANY_DIFF);\n+        rw.markStart(rw.parseCommit(endRange));\n+        rw.sort(RevSort.TOPO);\n+        if (startRange != null) {\n+            rw.markUninteresting(rw.parseCommit(startRange));\n+        }\n+\n+        return rw;\n+    }\n+\n+    private static class RenameCaptor extends RenameCallback {\n+\n+        private DiffEntry captured;\n+\n+        @Override\n+        public void renamed(DiffEntry entry) {","path":"uberfire-nio2-backport/uberfire-nio2-impls/uberfire-nio2-jgit/src/main/java/org/uberfire/java/nio/fs/jgit/util/commands/ListCommits.java","position":158,"original_position":158,"commit_id":"c556bb49dfc3e54c1c82db5904e0584a76af30a4","original_commit_id":"c556bb49dfc3e54c1c82db5904e0584a76af30a4","user":{"login":"jomarko","id":8044780,"avatar_url":"https://avatars3.githubusercontent.com/u/8044780?v=4","gravatar_id":"","url":"https://api.github.com/users/jomarko","html_url":"https://github.com/jomarko","followers_url":"https://api.github.com/users/jomarko/followers","following_url":"https://api.github.com/users/jomarko/following{/other_user}","gists_url":"https://api.github.com/users/jomarko/gists{/gist_id}","starred_url":"https://api.github.com/users/jomarko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jomarko/subscriptions","organizations_url":"https://api.github.com/users/jomarko/orgs","repos_url":"https://api.github.com/users/jomarko/repos","events_url":"https://api.github.com/users/jomarko/events{/privacy}","received_events_url":"https://api.github.com/users/jomarko/received_events","type":"User","site_admin":false},"body":"Also here I would use final:\r\n```java\r\npublic void renamed(final DiffEntry entry) {\r\n...\r\n```","created_at":"2018-05-09T06:14:22Z","updated_at":"2018-05-09T06:26:59Z","html_url":"https://github.com/kiegroup/appformer/pull/336#discussion_r186939551","pull_request_url":"https://api.github.com/repos/kiegroup/appformer/pulls/336","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/kiegroup/appformer/pulls/comments/186939551"},"html":{"href":"https://github.com/kiegroup/appformer/pull/336#discussion_r186939551"},"pull_request":{"href":"https://api.github.com/repos/kiegroup/appformer/pulls/336"}}},"pull_request":{"url":"https://api.github.com/repos/kiegroup/appformer/pulls/336","id":186040715,"html_url":"https://github.com/kiegroup/appformer/pull/336","diff_url":"https://github.com/kiegroup/appformer/pull/336.diff","patch_url":"https://github.com/kiegroup/appformer/pull/336.patch","issue_url":"https://api.github.com/repos/kiegroup/appformer/issues/336","number":336,"state":"open","locked":false,"title":"AF-1186: Versions history is lost after asset rename","user":{"login":"mbarkley","id":4459888,"avatar_url":"https://avatars0.githubusercontent.com/u/4459888?v=4","gravatar_id":"","url":"https://api.github.com/users/mbarkley","html_url":"https://github.com/mbarkley","followers_url":"https://api.github.com/users/mbarkley/followers","following_url":"https://api.github.com/users/mbarkley/following{/other_user}","gists_url":"https://api.github.com/users/mbarkley/gists{/gist_id}","starred_url":"https://api.github.com/users/mbarkley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbarkley/subscriptions","organizations_url":"https://api.github.com/users/mbarkley/orgs","repos_url":"https://api.github.com/users/mbarkley/repos","events_url":"https://api.github.com/users/mbarkley/events{/privacy}","received_events_url":"https://api.github.com/users/mbarkley/received_events","type":"User","site_admin":false},"body":"Fixes `ListCommits` command to follow path name changes, and maps version records to correct paths of renamed files.\r\n\r\nNote that there are issues with some editors when trying to view previous versions of moved files. One that I encountered is with the data modeller. That editor produces two commits when moving a file. One renames the Java class and the other moves the file. If you try checking out the commit that renames the Java class, the data modeller cannot load the class, presumably because the class name and file name do not match. We might want to make a JIRA issue to ensure that rename operations are committed atomically. //cc @wmedvede ","created_at":"2018-05-04T16:59:23Z","updated_at":"2018-05-09T06:26:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ebc6a34e6c09b04ac8a06f1886baa3b70375e9f8","assignee":null,"assignees":[],"requested_reviewers":[{"login":"ederign","id":531351,"avatar_url":"https://avatars2.githubusercontent.com/u/531351?v=4","gravatar_id":"","url":"https://api.github.com/users/ederign","html_url":"https://github.com/ederign","followers_url":"https://api.github.com/users/ederign/followers","following_url":"https://api.github.com/users/ederign/following{/other_user}","gists_url":"https://api.github.com/users/ederign/gists{/gist_id}","starred_url":"https://api.github.com/users/ederign/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ederign/subscriptions","organizations_url":"https://api.github.com/users/ederign/orgs","repos_url":"https://api.github.com/users/ederign/repos","events_url":"https://api.github.com/users/ederign/events{/privacy}","received_events_url":"https://api.github.com/users/ederign/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/kiegroup/appformer/pulls/336/commits","review_comments_url":"https://api.github.com/repos/kiegroup/appformer/pulls/336/comments","review_comment_url":"https://api.github.com/repos/kiegroup/appformer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kiegroup/appformer/issues/336/comments","statuses_url":"https://api.github.com/repos/kiegroup/appformer/statuses/c556bb49dfc3e54c1c82db5904e0584a76af30a4","head":{"label":"mbarkley:AF-1186","ref":"AF-1186","sha":"c556bb49dfc3e54c1c82db5904e0584a76af30a4","user":{"login":"mbarkley","id":4459888,"avatar_url":"https://avatars0.githubusercontent.com/u/4459888?v=4","gravatar_id":"","url":"https://api.github.com/users/mbarkley","html_url":"https://github.com/mbarkley","followers_url":"https://api.github.com/users/mbarkley/followers","following_url":"https://api.github.com/users/mbarkley/following{/other_user}","gists_url":"https://api.github.com/users/mbarkley/gists{/gist_id}","starred_url":"https://api.github.com/users/mbarkley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbarkley/subscriptions","organizations_url":"https://api.github.com/users/mbarkley/orgs","repos_url":"https://api.github.com/users/mbarkley/repos","events_url":"https://api.github.com/users/mbarkley/events{/privacy}","received_events_url":"https://api.github.com/users/mbarkley/received_events","type":"User","site_admin":false},"repo":{"id":36258126,"name":"appformer","full_name":"mbarkley/appformer","owner":{"login":"mbarkley","id":4459888,"avatar_url":"https://avatars0.githubusercontent.com/u/4459888?v=4","gravatar_id":"","url":"https://api.github.com/users/mbarkley","html_url":"https://github.com/mbarkley","followers_url":"https://api.github.com/users/mbarkley/followers","following_url":"https://api.github.com/users/mbarkley/following{/other_user}","gists_url":"https://api.github.com/users/mbarkley/gists{/gist_id}","starred_url":"https://api.github.com/users/mbarkley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbarkley/subscriptions","organizations_url":"https://api.github.com/users/mbarkley/orgs","repos_url":"https://api.github.com/users/mbarkley/repos","events_url":"https://api.github.com/users/mbarkley/events{/privacy}","received_events_url":"https://api.github.com/users/mbarkley/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mbarkley/appformer","description":"A web platform to rapidly build forms for data management and business automation.","fork":true,"url":"https://api.github.com/repos/mbarkley/appformer","forks_url":"https://api.github.com/repos/mbarkley/appformer/forks","keys_url":"https://api.github.com/repos/mbarkley/appformer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mbarkley/appformer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mbarkley/appformer/teams","hooks_url":"https://api.github.com/repos/mbarkley/appformer/hooks","issue_events_url":"https://api.github.com/repos/mbarkley/appformer/issues/events{/number}","events_url":"https://api.github.com/repos/mbarkley/appformer/events","assignees_url":"https://api.github.com/repos/mbarkley/appformer/assignees{/user}","branches_url":"https://api.github.com/repos/mbarkley/appformer/branches{/branch}","tags_url":"https://api.github.com/repos/mbarkley/appformer/tags","blobs_url":"https://api.github.com/repos/mbarkley/appformer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mbarkley/appformer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mbarkley/appformer/git/refs{/sha}","trees_url":"https://api.github.com/repos/mbarkley/appformer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mbarkley/appformer/statuses/{sha}","languages_url":"https://api.github.com/repos/mbarkley/appformer/languages","stargazers_url":"https://api.github.com/repos/mbarkley/appformer/stargazers","contributors_url":"https://api.github.com/repos/mbarkley/appformer/contributors","subscribers_url":"https://api.github.com/repos/mbarkley/appformer/subscribers","subscription_url":"https://api.github.com/repos/mbarkley/appformer/subscription","commits_url":"https://api.github.com/repos/mbarkley/appformer/commits{/sha}","git_commits_url":"https://api.github.com/repos/mbarkley/appformer/git/commits{/sha}","comments_url":"https://api.github.com/repos/mbarkley/appformer/comments{/number}","issue_comment_url":"https://api.github.com/repos/mbarkley/appformer/issues/comments{/number}","contents_url":"https://api.github.com/repos/mbarkley/appformer/contents/{+path}","compare_url":"https://api.github.com/repos/mbarkley/appformer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mbarkley/appformer/merges","archive_url":"https://api.github.com/repos/mbarkley/appformer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mbarkley/appformer/downloads","issues_url":"https://api.github.com/repos/mbarkley/appformer/issues{/number}","pulls_url":"https://api.github.com/repos/mbarkley/appformer/pulls{/number}","milestones_url":"https://api.github.com/repos/mbarkley/appformer/milestones{/number}","notifications_url":"https://api.github.com/repos/mbarkley/appformer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mbarkley/appformer/labels{/name}","releases_url":"https://api.github.com/repos/mbarkley/appformer/releases{/id}","deployments_url":"https://api.github.com/repos/mbarkley/appformer/deployments","created_at":"2015-05-25T22:35:02Z","updated_at":"2016-12-13T18:05:27Z","pushed_at":"2018-05-08T14:14:59Z","git_url":"git://github.com/mbarkley/appformer.git","ssh_url":"git@github.com:mbarkley/appformer.git","clone_url":"https://github.com/mbarkley/appformer.git","svn_url":"https://github.com/mbarkley/appformer","homepage":null,"size":46362,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"kiegroup:master","ref":"master","sha":"d2d7ae0dfeba848c6183ed217334fe148c6a057b","user":{"login":"kiegroup","id":517980,"avatar_url":"https://avatars3.githubusercontent.com/u/517980?v=4","gravatar_id":"","url":"https://api.github.com/users/kiegroup","html_url":"https://github.com/kiegroup","followers_url":"https://api.github.com/users/kiegroup/followers","following_url":"https://api.github.com/users/kiegroup/following{/other_user}","gists_url":"https://api.github.com/users/kiegroup/gists{/gist_id}","starred_url":"https://api.github.com/users/kiegroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kiegroup/subscriptions","organizations_url":"https://api.github.com/users/kiegroup/orgs","repos_url":"https://api.github.com/users/kiegroup/repos","events_url":"https://api.github.com/users/kiegroup/events{/privacy}","received_events_url":"https://api.github.com/users/kiegroup/received_events","type":"Organization","site_admin":false},"repo":{"id":35297180,"name":"appformer","full_name":"kiegroup/appformer","owner":{"login":"kiegroup","id":517980,"avatar_url":"https://avatars3.githubusercontent.com/u/517980?v=4","gravatar_id":"","url":"https://api.github.com/users/kiegroup","html_url":"https://github.com/kiegroup","followers_url":"https://api.github.com/users/kiegroup/followers","following_url":"https://api.github.com/users/kiegroup/following{/other_user}","gists_url":"https://api.github.com/users/kiegroup/gists{/gist_id}","starred_url":"https://api.github.com/users/kiegroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kiegroup/subscriptions","organizations_url":"https://api.github.com/users/kiegroup/orgs","repos_url":"https://api.github.com/users/kiegroup/repos","events_url":"https://api.github.com/users/kiegroup/events{/privacy}","received_events_url":"https://api.github.com/users/kiegroup/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kiegroup/appformer","description":"A web platform to rapidly build forms for data management and business automation.","fork":false,"url":"https://api.github.com/repos/kiegroup/appformer","forks_url":"https://api.github.com/repos/kiegroup/appformer/forks","keys_url":"https://api.github.com/repos/kiegroup/appformer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kiegroup/appformer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kiegroup/appformer/teams","hooks_url":"https://api.github.com/repos/kiegroup/appformer/hooks","issue_events_url":"https://api.github.com/repos/kiegroup/appformer/issues/events{/number}","events_url":"https://api.github.com/repos/kiegroup/appformer/events","assignees_url":"https://api.github.com/repos/kiegroup/appformer/assignees{/user}","branches_url":"https://api.github.com/repos/kiegroup/appformer/branches{/branch}","tags_url":"https://api.github.com/repos/kiegroup/appformer/tags","blobs_url":"https://api.github.com/repos/kiegroup/appformer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kiegroup/appformer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kiegroup/appformer/git/refs{/sha}","trees_url":"https://api.github.com/repos/kiegroup/appformer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kiegroup/appformer/statuses/{sha}","languages_url":"https://api.github.com/repos/kiegroup/appformer/languages","stargazers_url":"https://api.github.com/repos/kiegroup/appformer/stargazers","contributors_url":"https://api.github.com/repos/kiegroup/appformer/contributors","subscribers_url":"https://api.github.com/repos/kiegroup/appformer/subscribers","subscription_url":"https://api.github.com/repos/kiegroup/appformer/subscription","commits_url":"https://api.github.com/repos/kiegroup/appformer/commits{/sha}","git_commits_url":"https://api.github.com/repos/kiegroup/appformer/git/commits{/sha}","comments_url":"https://api.github.com/repos/kiegroup/appformer/comments{/number}","issue_comment_url":"https://api.github.com/repos/kiegroup/appformer/issues/comments{/number}","contents_url":"https://api.github.com/repos/kiegroup/appformer/contents/{+path}","compare_url":"https://api.github.com/repos/kiegroup/appformer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kiegroup/appformer/merges","archive_url":"https://api.github.com/repos/kiegroup/appformer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kiegroup/appformer/downloads","issues_url":"https://api.github.com/repos/kiegroup/appformer/issues{/number}","pulls_url":"https://api.github.com/repos/kiegroup/appformer/pulls{/number}","milestones_url":"https://api.github.com/repos/kiegroup/appformer/milestones{/number}","notifications_url":"https://api.github.com/repos/kiegroup/appformer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kiegroup/appformer/labels{/name}","releases_url":"https://api.github.com/repos/kiegroup/appformer/releases{/id}","deployments_url":"https://api.github.com/repos/kiegroup/appformer/deployments","created_at":"2015-05-08T19:13:36Z","updated_at":"2018-05-08T19:44:55Z","pushed_at":"2018-05-09T04:48:49Z","git_url":"git://github.com/kiegroup/appformer.git","ssh_url":"git@github.com:kiegroup/appformer.git","clone_url":"https://github.com/kiegroup/appformer.git","svn_url":"https://github.com/kiegroup/appformer","homepage":null,"size":45966,"stargazers_count":36,"watchers_count":36,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":77,"mirror_url":null,"archived":false,"open_issues_count":4,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":77,"open_issues":4,"watchers":36,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kiegroup/appformer/pulls/336"},"html":{"href":"https://github.com/kiegroup/appformer/pull/336"},"issue":{"href":"https://api.github.com/repos/kiegroup/appformer/issues/336"},"comments":{"href":"https://api.github.com/repos/kiegroup/appformer/issues/336/comments"},"review_comments":{"href":"https://api.github.com/repos/kiegroup/appformer/pulls/336/comments"},"review_comment":{"href":"https://api.github.com/repos/kiegroup/appformer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kiegroup/appformer/pulls/336/commits"},"statuses":{"href":"https://api.github.com/repos/kiegroup/appformer/statuses/c556bb49dfc3e54c1c82db5904e0584a76af30a4"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"jomarko"}}