git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* How to `git blame` individual characters?
@ 2018-03-27  0:18 Jan Keromnes
  2018-03-27  6:01 ` Christian Couder
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Keromnes @ 2018-03-27  0:18 UTC (permalink / raw)
  To: git

Dear Git developers,

I'd like to understand what would be required to run `git blame` on
individual characters instead of full lines. Could you please point me
in the right direction?

Someone asked a similar question about "Word-by-word blame/annotate"
on StackOverflow a few years ago, and one of the replies said:

> 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.

Source: https://stackoverflow.com/q/17758008/3461173

This leaves me hopeful that a character-based format can somehow be
achieved. Here is a fake example to illustrate what I'm looking for:

        $ cat myscript.js
        for (int foo = 0; foo <= 11; foo++) { console.log(foo); }
        $ git blame --character-based --pseudo-json myscript.js
        [
            { "commit": "abcd1234", "summary": "Implement loop",
"characters": "for (int " },
            { "commit": "bcd1234a", "summary": "Rename iterator",
"characters": "foo" },
            { "commit": "abcd1234", "summary": "Implement loop",
"characters": " = 0; " },
            { "commit": "bcd1234a", "summary": "Rename iterator",
"characters": "foo" },
            { "commit": "abcd1234", "summary": "Implement loop",
"characters": " <= " },
            { "commit": "cd1234ab", "summary": "Go up to 11",
"characters": "11" },
            { "commit": "abcd1234", "summary": "Implement loop",
"characters": "; " },
            { "commit": "bcd1234a", "summary": "Rename iterator",
"characters": "foo" },
            { "commit": "abcd1234", "summary": "Implement loop",
"characters": "++) { console.log(" },
            { "commit": "bcd1234a", "summary": "Rename iterator",
"characters": "foo" },
            { "commit": "abcd1234", "summary": "Implement loop",
"characters": ")" },
            { "commit": "d1234abc", "summary": "Add missing
semicolon", "characters": ";" },
            { "commit": "abcd1234", "summary": "Implement loop",
"characters": " }" }
        ]

What would be the most direct way to achieve such a character-based
blame/annotate? Should I write some sort of Git extension, or hack
into Git's source code?

E.g. I looked for an option in `git-blame` or `git-annotate` to change
the "next line boundary" from "carret return" (line-based blame) to
"any whitespace" (word-based blame) or "character-by-character"
(character-based blame), but I didn't find it. Could this be
implemented in `blame.c`? If so, which methods would need tweaking?

Many thanks!
Jan

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to `git blame` individual characters?
  2018-03-27  0:18 How to `git blame` individual characters? Jan Keromnes
@ 2018-03-27  6:01 ` Christian Couder
  0 siblings, 0 replies; 2+ messages in thread
From: Christian Couder @ 2018-03-27  6:01 UTC (permalink / raw)
  To: Jan Keromnes; +Cc: git

Hi,

On Tue, Mar 27, 2018 at 2:18 AM, Jan Keromnes <janx@linux.com> wrote:
> Dear Git developers,
>
> I'd like to understand what would be required to run `git blame` on
> individual characters instead of full lines. Could you please point me
> in the right direction?

You might want to take a look at cregit
(https://github.com/cregit/cregit) and maybe at other work from the
people who developed it.

There are links related to this tool in:
https://git.github.io/rev_news/2017/05/17/edition-27/

> Someone asked a similar question about "Word-by-word blame/annotate"
> on StackOverflow a few years ago, and one of the replies said:
>
>> 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.
>
> Source: https://stackoverflow.com/q/17758008/3461173
>
> This leaves me hopeful that a character-based format can somehow be
> achieved. Here is a fake example to illustrate what I'm looking for:
>
>         $ cat myscript.js
>         for (int foo = 0; foo <= 11; foo++) { console.log(foo); }
>         $ git blame --character-based --pseudo-json myscript.js
>         [
>             { "commit": "abcd1234", "summary": "Implement loop",
> "characters": "for (int " },
>             { "commit": "bcd1234a", "summary": "Rename iterator",
> "characters": "foo" },
>             { "commit": "abcd1234", "summary": "Implement loop",
> "characters": " = 0; " },
>             { "commit": "bcd1234a", "summary": "Rename iterator",
> "characters": "foo" },
>             { "commit": "abcd1234", "summary": "Implement loop",
> "characters": " <= " },
>             { "commit": "cd1234ab", "summary": "Go up to 11",
> "characters": "11" },
>             { "commit": "abcd1234", "summary": "Implement loop",
> "characters": "; " },
>             { "commit": "bcd1234a", "summary": "Rename iterator",
> "characters": "foo" },
>             { "commit": "abcd1234", "summary": "Implement loop",
> "characters": "++) { console.log(" },
>             { "commit": "bcd1234a", "summary": "Rename iterator",
> "characters": "foo" },
>             { "commit": "abcd1234", "summary": "Implement loop",
> "characters": ")" },
>             { "commit": "d1234abc", "summary": "Add missing
> semicolon", "characters": ";" },
>             { "commit": "abcd1234", "summary": "Implement loop",
> "characters": " }" }
>         ]
>
> What would be the most direct way to achieve such a character-based
> blame/annotate? Should I write some sort of Git extension, or hack
> into Git's source code?

I think the "Token-based authorship information from Git" article
(https://lwn.net/Articles/698425/) is about that.

> E.g. I looked for an option in `git-blame` or `git-annotate` to change
> the "next line boundary" from "carret return" (line-based blame) to
> "any whitespace" (word-based blame) or "character-by-character"
> (character-based blame), but I didn't find it. Could this be
> implemented in `blame.c`? If so, which methods would need tweaking?

I don't think this is implemented in Git. Do you really need that in git itself?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-03-27  6:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-27  0:18 How to `git blame` individual characters? Jan Keromnes
2018-03-27  6:01 ` Christian Couder

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).