{"id":17145832,"url":"https://github.com/soutaro/git_diff_map","last_synced_at":"2025-04-13T11:20:34.480Z","repository":{"id":56874260,"uuid":"65180989","full_name":"soutaro/git_diff_map","owner":"soutaro","description":"Line mapping between original and new","archived":false,"fork":false,"pushed_at":"2016-08-09T05:28:08.000Z","size":10,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-05T16:53:51.130Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soutaro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-08T07:06:30.000Z","updated_at":"2024-06-27T15:51:17.000Z","dependencies_parsed_at":"2022-08-20T10:11:09.078Z","dependency_job_id":null,"html_url":"https://github.com/soutaro/git_diff_map","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soutaro%2Fgit_diff_map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soutaro%2Fgit_diff_map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soutaro%2Fgit_diff_map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soutaro%2Fgit_diff_map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soutaro","download_url":"https://codeload.github.com/soutaro/git_diff_map/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239825015,"owners_count":19703199,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T21:06:59.683Z","updated_at":"2025-02-23T08:31:24.496Z","avatar_url":"https://github.com/soutaro.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GitDiffMap\n\nLine number mapping through `git diff` output.\n\n## What is *mapping*?\n\nIf the line is not changed in diff, there should be pair of numbers of:\n\n* A number to identify where the line was located in *original* file\n* A number to identify where the line is located in *new* file\n\nThis library is to compute the relation.\n\nThis is an example from GitDiffParser.\n\n```\n@@ -2,6 +2,7 @@ module Saddler\n   module Reporter\n     module Github\n       class CommitComment\n+        include Support\n         include Helper\n\n         # https://developer.github.com/v3/repos/comments/#create-a-commit-comment\n@@ -11,7 +12,7 @@ def report(messages, options)\n           data = parse(messages)\n\n           # build comment\n-          body = build_body(data)\n+          body = concat_body(data)\n           return if body.empty?\n           comment = Comment.new(sha1, body, nil, nil)\n\n@@ -25,20 +26,6 @@ def report(messages, options)\n           # create commit_comment\n           client.create_commit_comment(comment)\n         end\n-\n-        def build_body(data)\n-          buffer = []\n-          files = data['checkstyle']['file'] ||= []\n-          files.each do |file|\n-            errors = file['error'] ||= []\n-            errors.each do |error|\n-              severity = error['@severity'] \u0026\u0026 error['@severity'].upcase\n-              message = error['@message']\n-              buffer \u003c\u003c [severity, message].compact.join(': ')\n-            end\n-          end\n-          buffer.join(\"\\n\")\n-        end\n       end\n     end\n   end\n```\n\nWe can find some relations between lines:\n\n* Line 4 `class CommitComment` in *new* file was at line 4 in *original* file too\n* Line 5 `include Support` in *new* file is newly inserted\n* Line 6 `include Helper` in *new* file was at line 5 in *original* file\n* Line 14 `body = build_body(data)` in *original* file is not included in *new* file\n* Line 15 `body = concat_body(data)` in *new* file is not included in *original* file\n\nThese relations can be calculated by this library as:\n\n```rb\ndiff = \"...\"\nmap = GitDiffMap.parse(diff)\n\nmap.translate_new_to_original(4)   # =\u003e 4\nmap.translate_new_to_original(5)   # =\u003e nil\nmap.translate_new_to_original(6)   # =\u003e 6\nmap.translate_original_to_new(14)  # =\u003e nil\nmap.translate_new_to_original(15)  # =\u003e nil\n```\n\n## API\n\n* `GitDiffMap#translate_new_to_original(line)`\n* `GitDiffMap#translate_original_to_new(line)`\n* `GitDiffMap#translate_new_lines_to_original_lines([lines])` `lines` must be sorted in ascending order\n* `GitDiffMap#translate_original_lines_to_new_lines([lines])` `lines` must be sorted in ascending order\n\n# Install\n\n```\n$ gem install git_diff_map\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoutaro%2Fgit_diff_map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoutaro%2Fgit_diff_map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoutaro%2Fgit_diff_map/lists"}