{"thread":{"id":"48160","subject":"How to `git blame` individual characters?","startedAt":"2018-03-27T00:19:06Z","lastAt":"2018-03-27T06:01:28Z","messageCount":2,"participants":["Jan Keromnes","Christian Couder"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"343092","messageId":"CAA6PgK7L04VoHT7A8M_mwq5kA+9BiQxrd6iPjPHOpa4=Z3futw@mail.gmail.com","threadId":"48160","inReplyTo":null,"subject":"How to `git blame` individual characters?","fromName":"Jan Keromnes","fromEmail":"janx@linux.com","sentAt":"2018-03-27T00:18:59Z","receivedAt":"2018-03-27T00:19:06Z","isPatch":false,"sender":{"key":"janx@linux.com","avatar":"https://gravatar.com/avatar/2d842511ba2875cc54f5434fb9c6a6ef813eb53bd511b6fe05b645f6c151e344?d=mp&s=160"},"body":"Dear Git developers,\n\nI'd like to understand what would be required to run `git blame` on\nindividual characters instead of full lines. Could you please point me\nin the right direction?\n\nSomeone asked a similar question about \"Word-by-word blame/annotate\"\non StackOverflow a few years ago, and one of the replies said:\n\n> Git tracks changes snapshot by snapshot. The line-based format is calculated on-the-fly, and it would also be possible to have a word-based format.\n\nSource: https://stackoverflow.com/q/17758008/3461173\n\nThis leaves me hopeful that a character-based format can somehow be\nachieved. Here is a fake example to illustrate what I'm looking for:\n\n        $ cat myscript.js\n        for (int foo = 0; foo <= 11; foo++) { console.log(foo); }\n        $ git blame --character-based --pseudo-json myscript.js\n        [\n            { \"commit\": \"abcd1234\", \"summary\": \"Implement loop\",\n\"characters\": \"for (int \" },\n            { \"commit\": \"bcd1234a\", \"summary\": \"Rename iterator\",\n\"characters\": \"foo\" },\n            { \"commit\": \"abcd1234\", \"summary\": \"Implement loop\",\n\"characters\": \" = 0; \" },\n            { \"commit\": \"bcd1234a\", \"summary\": \"Rename iterator\",\n\"characters\": \"foo\" },\n            { \"commit\": \"abcd1234\", \"summary\": \"Implement loop\",\n\"characters\": \" <= \" },\n            { \"commit\": \"cd1234ab\", \"summary\": \"Go up to 11\",\n\"characters\": \"11\" },\n            { \"commit\": \"abcd1234\", \"summary\": \"Implement loop\",\n\"characters\": \"; \" },\n            { \"commit\": \"bcd1234a\", \"summary\": \"Rename iterator\",\n\"characters\": \"foo\" },\n            { \"commit\": \"abcd1234\", \"summary\": \"Implement loop\",\n\"characters\": \"++) { console.log(\" },\n            { \"commit\": \"bcd1234a\", \"summary\": \"Rename iterator\",\n\"characters\": \"foo\" },\n            { \"commit\": \"abcd1234\", \"summary\": \"Implement loop\",\n\"characters\": \")\" },\n            { \"commit\": \"d1234abc\", \"summary\": \"Add missing\nsemicolon\", \"characters\": \";\" },\n            { \"commit\": \"abcd1234\", \"summary\": \"Implement loop\",\n\"characters\": \" }\" }\n        ]\n\nWhat would be the most direct way to achieve such a character-based\nblame/annotate? Should I write some sort of Git extension, or hack\ninto Git's source code?\n\nE.g. I looked for an option in `git-blame` or `git-annotate` to change\nthe \"next line boundary\" from \"carret return\" (line-based blame) to\n\"any whitespace\" (word-based blame) or \"character-by-character\"\n(character-based blame), but I didn't find it. Could this be\nimplemented in `blame.c`? If so, which methods would need tweaking?\n\nMany thanks!\nJan\n"},{"id":"343108","messageId":"CAP8UFD3TPfWtpT8RLGBL2V+M+nkpGEYVa8Y_c68u4Lw4zPyW5g@mail.gmail.com","threadId":"48160","inReplyTo":"CAA6PgK7L04VoHT7A8M_mwq5kA+9BiQxrd6iPjPHOpa4=Z3futw@mail.gmail.com","subject":"Re: How to `git blame` individual characters?","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2018-03-27T06:01:22Z","receivedAt":"2018-03-27T06:01:28Z","isPatch":false,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Hi,\n\nOn Tue, Mar 27, 2018 at 2:18 AM, Jan Keromnes <janx@linux.com> wrote:\n> Dear Git developers,\n>\n> I'd like to understand what would be required to run `git blame` on\n> individual characters instead of full lines. Could you please point me\n> in the right direction?\n\nYou might want to take a look at cregit\n(https://github.com/cregit/cregit) and maybe at other work from the\npeople who developed it.\n\nThere are links related to this tool in:\nhttps://git.github.io/rev_news/2017/05/17/edition-27/\n\n> Someone asked a similar question about \"Word-by-word blame/annotate\"\n> on StackOverflow a few years ago, and one of the replies said:\n>\n>> Git tracks changes snapshot by snapshot. The line-based format is calculated on-the-fly, and it would also be possible to have a word-based format.\n>\n> Source: https://stackoverflow.com/q/17758008/3461173\n>\n> This leaves me hopeful that a character-based format can somehow be\n> achieved. Here is a fake example to illustrate what I'm looking for:\n>\n>         $ cat myscript.js\n>         for (int foo = 0; foo <= 11; foo++) { console.log(foo); }\n>         $ git blame --character-based --pseudo-json myscript.js\n>         [\n>             { \"commit\": \"abcd1234\", \"summary\": \"Implement loop\",\n> \"characters\": \"for (int \" },\n>             { \"commit\": \"bcd1234a\", \"summary\": \"Rename iterator\",\n> \"characters\": \"foo\" },\n>             { \"commit\": \"abcd1234\", \"summary\": \"Implement loop\",\n> \"characters\": \" = 0; \" },\n>             { \"commit\": \"bcd1234a\", \"summary\": \"Rename iterator\",\n> \"characters\": \"foo\" },\n>             { \"commit\": \"abcd1234\", \"summary\": \"Implement loop\",\n> \"characters\": \" <= \" },\n>             { \"commit\": \"cd1234ab\", \"summary\": \"Go up to 11\",\n> \"characters\": \"11\" },\n>             { \"commit\": \"abcd1234\", \"summary\": \"Implement loop\",\n> \"characters\": \"; \" },\n>             { \"commit\": \"bcd1234a\", \"summary\": \"Rename iterator\",\n> \"characters\": \"foo\" },\n>             { \"commit\": \"abcd1234\", \"summary\": \"Implement loop\",\n> \"characters\": \"++) { console.log(\" },\n>             { \"commit\": \"bcd1234a\", \"summary\": \"Rename iterator\",\n> \"characters\": \"foo\" },\n>             { \"commit\": \"abcd1234\", \"summary\": \"Implement loop\",\n> \"characters\": \")\" },\n>             { \"commit\": \"d1234abc\", \"summary\": \"Add missing\n> semicolon\", \"characters\": \";\" },\n>             { \"commit\": \"abcd1234\", \"summary\": \"Implement loop\",\n> \"characters\": \" }\" }\n>         ]\n>\n> What would be the most direct way to achieve such a character-based\n> blame/annotate? Should I write some sort of Git extension, or hack\n> into Git's source code?\n\nI think the \"Token-based authorship information from Git\" article\n(https://lwn.net/Articles/698425/) is about that.\n\n> E.g. I looked for an option in `git-blame` or `git-annotate` to change\n> the \"next line boundary\" from \"carret return\" (line-based blame) to\n> \"any whitespace\" (word-based blame) or \"character-by-character\"\n> (character-based blame), but I didn't find it. Could this be\n> implemented in `blame.c`? If so, which methods would need tweaking?\n\nI don't think this is implemented in Git. Do you really need that in git itself?\n"}]}